@or-sdk/flows 0.26.1-beta.424.0 → 0.27.0-beta.427.0
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/CHANGELOG.md +9 -0
- package/dist/cjs/Flows.js +361 -158
- package/dist/cjs/Flows.js.map +1 -1
- package/dist/cjs/constants.js +2 -3
- package/dist/cjs/constants.js.map +1 -1
- package/dist/esm/Flows.js +276 -123
- package/dist/esm/Flows.js.map +1 -1
- package/dist/esm/constants.js +1 -8
- package/dist/esm/constants.js.map +1 -1
- package/dist/types/Flows.d.ts +91 -15
- package/dist/types/constants.d.ts +1 -2
- package/dist/types/types.d.ts +22 -4
- package/package.json +9 -6
- package/src/Flows.ts +432 -147
- package/src/constants.ts +1 -8
- package/src/types.ts +26 -6
- package/tsconfig.dev.json +8 -0
package/src/Flows.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { Base, List } from '@or-sdk/base';
|
|
2
|
+
import { Flow, StepTemplateRaw } from '@or-sdk/deployer';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import {v4 as uuidV4} from 'uuid';
|
|
5
|
+
import { SERVICE_KEY } from './constants';
|
|
6
|
+
import { FlowsConfig, ListFlowsParams, StepTemplateToDelete, ActivateFlowParams, DeactivageFlowParams } from './types';
|
|
7
|
+
import { deleteUnusedStepTemplates, listUnusedStepTemplates } from './utils';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* OneReach Flows service client
|
|
@@ -13,10 +13,10 @@ import { listUnusedStepTemplates, deleteUnusedStepTemplates } from './utils';
|
|
|
13
13
|
* $ npm i @or-sdk/flows
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
|
-
export class Flows
|
|
17
|
-
private readonly dataHub: DataHub;
|
|
18
|
-
private readonly deployer: Deployer;
|
|
19
|
-
private readonly tags: Tags;
|
|
16
|
+
export class Flows extends Base {
|
|
17
|
+
// private readonly dataHub: DataHub;
|
|
18
|
+
// private readonly deployer: Deployer;
|
|
19
|
+
// private readonly tags: Tags;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* ```typescript
|
|
@@ -25,35 +25,45 @@ export class Flows implements Taggable<Flow> {
|
|
|
25
25
|
* await flows.init();
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
+
sdkApiUrl?: string;
|
|
29
|
+
deployerUrl?: string;
|
|
28
30
|
constructor(params: FlowsConfig) {
|
|
29
|
-
const { discoveryUrl, token, accountId,
|
|
30
|
-
|
|
31
|
-
this.dataHub = new DataHub({
|
|
32
|
-
token,
|
|
33
|
-
discoveryUrl,
|
|
34
|
-
accountId,
|
|
35
|
-
dataHubUrl,
|
|
36
|
-
});
|
|
37
|
-
this.deployer = new Deployer({
|
|
31
|
+
const { discoveryUrl, token, accountId, dataHub2Url, deployerUrl, sdkApiUrl } = params;
|
|
32
|
+
super({
|
|
38
33
|
token,
|
|
39
34
|
discoveryUrl,
|
|
35
|
+
serviceKey: SERVICE_KEY,
|
|
40
36
|
accountId,
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
this.tags = new Tags({
|
|
44
|
-
token,
|
|
45
|
-
discoveryUrl,
|
|
46
|
-
accountId,
|
|
47
|
-
dataHubUrl,
|
|
37
|
+
serviceUrl: dataHub2Url,
|
|
48
38
|
});
|
|
39
|
+
this.deployerUrl = deployerUrl;
|
|
40
|
+
this.sdkApiUrl = sdkApiUrl;
|
|
41
|
+
// this.dataHub = new DataHub({
|
|
42
|
+
// token,
|
|
43
|
+
// discoveryUrl,
|
|
44
|
+
// accountId,
|
|
45
|
+
// dataHubUrl,
|
|
46
|
+
// });
|
|
47
|
+
// this.deployer = new Deployer({
|
|
48
|
+
// token,
|
|
49
|
+
// discoveryUrl,
|
|
50
|
+
// accountId,
|
|
51
|
+
// deployerUrl,
|
|
52
|
+
// });
|
|
53
|
+
// this.tags = new Tags({
|
|
54
|
+
// token,
|
|
55
|
+
// discoveryUrl,
|
|
56
|
+
// accountId,
|
|
57
|
+
// dataHubUrl,
|
|
58
|
+
// });
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
async init() {
|
|
52
|
-
await Promise.all([
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
]);
|
|
62
|
+
// await Promise.all([
|
|
63
|
+
// this.dataHub.init(),
|
|
64
|
+
// this.deployer.init(),
|
|
65
|
+
// this.tags.init(),
|
|
66
|
+
// ]);
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
/**
|
|
@@ -64,73 +74,169 @@ export class Flows implements Taggable<Flow> {
|
|
|
64
74
|
* const flowsList = await flows.listFlows('bot-id');
|
|
65
75
|
* ```
|
|
66
76
|
*/
|
|
67
|
-
public async listFlows(botId?: string, params?: ListFlowsParams): Promise<List<Flow>> {
|
|
68
|
-
const requestParams = {
|
|
69
|
-
// defaults
|
|
70
|
-
includeDeleted: false,
|
|
71
|
-
includeExisting: true,
|
|
72
|
-
projection: [
|
|
73
|
-
'id',
|
|
74
|
-
'version',
|
|
75
|
-
'botId',
|
|
76
|
-
'data.label',
|
|
77
|
-
'data.color',
|
|
78
|
-
'data.description',
|
|
79
|
-
'data.isHidden',
|
|
80
|
-
'tags',
|
|
81
|
-
'dateModified',
|
|
82
|
-
],
|
|
83
|
-
|
|
84
|
-
// overrides
|
|
85
|
-
...params,
|
|
86
|
-
};
|
|
87
77
|
|
|
88
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Delete flow
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const result = await flows.deleteFlow(flowSource, flowAlias);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async deleteFlow(flow: {id: string;}, flowAlias = 'dev', temporarily = true) {
|
|
85
|
+
return this.callApiV2({
|
|
86
|
+
route: `/flows/${flow.id}`,
|
|
87
|
+
data: {
|
|
88
|
+
flowAlias,
|
|
89
|
+
temporarily,
|
|
90
|
+
},
|
|
91
|
+
method: 'delete',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
89
94
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Recover deleted flow
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const result = await flows.recoverFlow(flowSource);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
async recoverFlow(flow: {id: string;}) {
|
|
102
|
+
return this.callApiV2({
|
|
103
|
+
route: `/flows/${flow.id}`,
|
|
104
|
+
method: 'patch',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
94
107
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Get flow by id
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const result = await flows.getFlowById(id, projection, sandbox);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
async getFlowById(id: string, projection?: string[], sandbox = false): Promise<Flow> {
|
|
115
|
+
return this.callApiV2({
|
|
116
|
+
route: `/flows/${id}`,
|
|
117
|
+
params: {
|
|
118
|
+
projection,
|
|
119
|
+
sandbox,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Get flows
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const result = await flows.getFlows({query, projection, includeDeleted, includeExisting, sandbox, limit,offset});
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
async getFlows({ query = {}, projection, includeDeleted = false, includeExisting = true, sandbox = false, limit, offset }: ListFlowsParams = {}): Promise<List<Flow>> {
|
|
131
|
+
if (typeof query.id === 'string') query.id = query.id.split('.');
|
|
132
|
+
if (includeDeleted && !includeExisting) query.isDeleted = true;
|
|
133
|
+
if (!includeDeleted && includeExisting) query.isDeleted = false;
|
|
134
|
+
return this.callApiV2({
|
|
135
|
+
route: '/flows',
|
|
136
|
+
params: {
|
|
137
|
+
projection,
|
|
138
|
+
query,
|
|
139
|
+
sandbox,
|
|
140
|
+
limit,
|
|
141
|
+
offset,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get flow events
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const result = await flows.getFlowEvents({flowId, alias});
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
async getFlowEvents({ flowId, alias = 'prod' }: {flowId: string; alias: string;}) {
|
|
152
|
+
return this.callApiV2({
|
|
153
|
+
url: this.sdkApiUrl,
|
|
154
|
+
route: `${this.sdkApiUrl}/event-manager/get-flow-events/${flowId}/${alias}`,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
106
157
|
|
|
107
|
-
|
|
108
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Get trigger flows
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const result = await flows.getTriggerFlows(triggers);
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
async getTriggerFlows(triggers = []) {
|
|
165
|
+
return this.callApiV2({
|
|
166
|
+
url: this.sdkApiUrl,
|
|
167
|
+
route: `${this.sdkApiUrl}event-manager/get-trigger-flows`,
|
|
168
|
+
data: { triggers },
|
|
169
|
+
method: 'post',
|
|
170
|
+
});
|
|
109
171
|
|
|
110
|
-
|
|
172
|
+
}
|
|
111
173
|
|
|
112
|
-
|
|
174
|
+
/**
|
|
175
|
+
* List versions
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const result = await flows.listVersions({flowId, botId});
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
async listVersions(query: {flowId?: string; botId?: string;version?: string;}): Promise<any[]> {
|
|
181
|
+
return this.callApiV2({
|
|
182
|
+
route: '/flows/versions',
|
|
183
|
+
params: { query },
|
|
184
|
+
});
|
|
113
185
|
}
|
|
114
186
|
|
|
115
187
|
/**
|
|
116
|
-
* Get
|
|
188
|
+
* Get version
|
|
117
189
|
* ```typescript
|
|
118
|
-
* const
|
|
190
|
+
* const result = await flows.getVersion({flowId, version});
|
|
119
191
|
* ```
|
|
120
192
|
*/
|
|
121
|
-
|
|
122
|
-
const
|
|
193
|
+
async getVersion(params: {flowId: string; version: string;}) {
|
|
194
|
+
const data = await this.listVersions(params);
|
|
195
|
+
return data[0];
|
|
196
|
+
}
|
|
123
197
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
198
|
+
/**
|
|
199
|
+
* List flow versions by bot id
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const result = await flows.listFlowVersionsByBotId({botId});
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
async listFlowVersionsByBotId(params: { botId: string; }) {
|
|
205
|
+
return this.listVersions(params);
|
|
206
|
+
}
|
|
129
207
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Load flow logs
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const result = await flows.loadLogs({flowId, next, startTime, endTime, limit, filter, relativeTime});
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
async loadLogs(params: { flowId: string; next: string; startTime: number; endTime: number; limit: number; filter: string; relativeTime: boolean; }) {
|
|
215
|
+
const { flowId, next, startTime, endTime, limit, filter, relativeTime } = params;
|
|
216
|
+
const queryParams: {[key: string]: any;} = { skipOriginal: true };
|
|
217
|
+
|
|
218
|
+
if (next) {
|
|
219
|
+
queryParams.next = next;
|
|
220
|
+
}
|
|
221
|
+
if (startTime) {
|
|
222
|
+
queryParams.start = startTime;
|
|
223
|
+
}
|
|
224
|
+
if (endTime) {
|
|
225
|
+
queryParams.end = endTime;
|
|
226
|
+
}
|
|
227
|
+
if (limit) {
|
|
228
|
+
queryParams.limit = limit;
|
|
229
|
+
}
|
|
230
|
+
if (filter) {
|
|
231
|
+
queryParams.filter = filter;
|
|
232
|
+
}
|
|
233
|
+
if (relativeTime) {
|
|
234
|
+
queryParams.relativeTime = relativeTime;
|
|
235
|
+
}
|
|
236
|
+
return this.callApiV2({
|
|
237
|
+
url: this.deployerUrl,
|
|
238
|
+
route: `/flows/${flowId}/logs`,
|
|
239
|
+
params: queryParams,
|
|
134
240
|
});
|
|
135
241
|
}
|
|
136
242
|
|
|
@@ -139,60 +245,209 @@ export class Flows implements Taggable<Flow> {
|
|
|
139
245
|
*
|
|
140
246
|
* If source contains existing id - existing flow will be updated
|
|
141
247
|
* ```typescript
|
|
142
|
-
* const savedFlow = await flows.saveFlow(flowSource);
|
|
248
|
+
* const savedFlow = await flows.saveFlow(flowSource, { previousVersion });
|
|
143
249
|
* ```
|
|
144
250
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
251
|
+
async saveFlow(flow: Flow, { previousVersion }: {previousVersion?: string;} = {}) {
|
|
252
|
+
flow.id = flow.id || 'new';
|
|
253
|
+
const { id, version } = await this.callApiV2({
|
|
254
|
+
route: `/flows/${flow.id}`,
|
|
255
|
+
data: {
|
|
256
|
+
flow,
|
|
257
|
+
previousVersion,
|
|
258
|
+
},
|
|
259
|
+
method: 'post',
|
|
260
|
+
});
|
|
261
|
+
return {
|
|
262
|
+
...flow,
|
|
263
|
+
id,
|
|
264
|
+
version,
|
|
151
265
|
};
|
|
266
|
+
}
|
|
152
267
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
268
|
+
/**
|
|
269
|
+
* Get flows by bot id
|
|
270
|
+
*
|
|
271
|
+
* ```typescript
|
|
272
|
+
* const flows = await flows.getFlowsByBotId(botId, projection);
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
getFlowsByBotId(botId: string, projection: string[]) {
|
|
276
|
+
return this.getFlows({
|
|
277
|
+
query: { botId },
|
|
278
|
+
projection,
|
|
157
279
|
});
|
|
158
280
|
}
|
|
159
281
|
|
|
160
282
|
/**
|
|
161
|
-
*
|
|
283
|
+
* Get remote data outs by bot id
|
|
284
|
+
*
|
|
162
285
|
* ```typescript
|
|
163
|
-
* const
|
|
286
|
+
* const data = await flows.getRemoteDataOutsByBotId(id);
|
|
164
287
|
* ```
|
|
165
288
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
289
|
+
async getRemoteDataOutsByBotId(id: string) {
|
|
290
|
+
const flows: any = await this.getFlows({
|
|
291
|
+
query: {
|
|
292
|
+
botId: id,
|
|
293
|
+
isDeleted: false,
|
|
294
|
+
},
|
|
295
|
+
projection: ['id', 'data.label'],
|
|
296
|
+
});
|
|
170
297
|
|
|
171
|
-
const
|
|
172
|
-
|
|
298
|
+
const dataOuts = await this.callApiV2({
|
|
299
|
+
route: 'flows/data-outs',
|
|
300
|
+
params: {
|
|
301
|
+
query: {
|
|
302
|
+
type: {
|
|
303
|
+
not: 'session',
|
|
304
|
+
ne: null,
|
|
305
|
+
},
|
|
306
|
+
name: { ne: null },
|
|
307
|
+
botId: id,
|
|
308
|
+
flowId: flows.map((flow: {id: string;}) => flow.id),
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
return _.reduce(flows, (acc: any, flow: any) => {
|
|
314
|
+
const flowLabel = _.get(flow, 'data.label', 'No name flow');
|
|
315
|
+
acc[flow.id] = _.map(dataOuts as any, (dataOut: any) => ({
|
|
316
|
+
...dataOut,
|
|
317
|
+
flowLabel,
|
|
318
|
+
}));
|
|
319
|
+
return acc;
|
|
320
|
+
}, {});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Get empty step
|
|
325
|
+
*
|
|
326
|
+
* ```typescript
|
|
327
|
+
* const data = await flows.constructor.getEmptyStep(id);
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
static getEmptyStep(stepId?: string) {
|
|
331
|
+
return {
|
|
332
|
+
id: stepId || uuidV4(),
|
|
333
|
+
icon: 'add',
|
|
334
|
+
iconType: 'default',
|
|
335
|
+
iconUrl: '',
|
|
336
|
+
shape: 'empty',
|
|
337
|
+
type: 'empty',
|
|
338
|
+
pinLabel: true,
|
|
339
|
+
stepInputData: {},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Get empty flow
|
|
345
|
+
*
|
|
346
|
+
* ```typescript
|
|
347
|
+
* const data = await flows.constructor.getEmptyFlow(botId);
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
static getEmptyFlow(botId: string): any {
|
|
351
|
+
const defaultLambdaMemorySize = 1024;
|
|
352
|
+
const defaultLambdaTimeout = 30;
|
|
353
|
+
return {
|
|
354
|
+
botId,
|
|
173
355
|
data: {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
356
|
+
label: '',
|
|
357
|
+
description: '',
|
|
358
|
+
deploy: {
|
|
359
|
+
memory: defaultLambdaMemorySize,
|
|
360
|
+
timeout: defaultLambdaTimeout,
|
|
361
|
+
role: 'USER',
|
|
362
|
+
},
|
|
363
|
+
meta: {},
|
|
364
|
+
color: null,
|
|
365
|
+
categories: null,
|
|
366
|
+
annotations: null,
|
|
367
|
+
stepTemplates: [],
|
|
368
|
+
trees: {
|
|
369
|
+
main: {
|
|
370
|
+
position: {
|
|
371
|
+
x: 0,
|
|
372
|
+
y: 0,
|
|
373
|
+
},
|
|
374
|
+
steps: [this.getEmptyStep()],
|
|
375
|
+
},
|
|
376
|
+
},
|
|
178
377
|
},
|
|
179
378
|
};
|
|
379
|
+
}
|
|
180
380
|
|
|
181
|
-
|
|
381
|
+
/**
|
|
382
|
+
* Get new flow
|
|
383
|
+
*
|
|
384
|
+
* ```typescript
|
|
385
|
+
* const data = await flows.constructor.getNewFlow(botId, flowTemplate);
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
static async getNewFlow(botId: string, flowTemplate: any) {
|
|
389
|
+
const flow = this.getEmptyFlow(botId);
|
|
390
|
+
const template = _.omit(flowTemplate, ['id', 'botId', 'dateCreated', 'dateModified', 'version']);
|
|
182
391
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
variables,
|
|
187
|
-
};
|
|
392
|
+
// if template has any steps then remove default empty step
|
|
393
|
+
// or leave it otherwise
|
|
394
|
+
flow.data.steps = _.get(template, 'data.steps.length') > 0 ? [] : flow.data.steps;
|
|
188
395
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
396
|
+
// merge step with flow template
|
|
397
|
+
return _.merge(flow, template);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
public async listFlows(botId?: string, params: ListFlowsParams = {}): Promise<List<Flow>> {
|
|
402
|
+
return this.getFlows({
|
|
403
|
+
...params,
|
|
404
|
+
query: { botId },
|
|
193
405
|
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Get flow
|
|
410
|
+
* ```typescript
|
|
411
|
+
* const flow = await flows.getFlow('flow-id');
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
public async getFlow(id: string): Promise<Flow> {
|
|
415
|
+
return this.getFlowById(id);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private get deployUrl() {
|
|
419
|
+
return this.targetAccountId ? `${this.deployerUrl}/accounts/${this.targetAccountId}/flows/deploy` : `${this.deployerUrl}/flows/deploy`;
|
|
420
|
+
}
|
|
421
|
+
|
|
194
422
|
|
|
195
|
-
|
|
423
|
+
private get checkUrl() {
|
|
424
|
+
return this.targetAccountId ? `${this.deployerUrl}/accounts/${this.targetAccountId}/flows/check` : `${this.deployerUrl}/flows/check`;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
private async _pollResult(flowId: string, requestId: string, headers?: any, progresCallback?: any) {
|
|
428
|
+
let counter = 0;
|
|
429
|
+
|
|
430
|
+
do {
|
|
431
|
+
counter++;
|
|
432
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
433
|
+
|
|
434
|
+
const result: any = await this.callApiV2({
|
|
435
|
+
url: `${this.checkUrl}`,
|
|
436
|
+
route: `/${flowId}/${requestId}`,
|
|
437
|
+
});
|
|
438
|
+
if (_.isFunction(progresCallback)) {
|
|
439
|
+
progresCallback(result);
|
|
440
|
+
}
|
|
441
|
+
if (result.status !== 'pending') {
|
|
442
|
+
if (result.errorData) {
|
|
443
|
+
throw result;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return result;
|
|
447
|
+
}
|
|
448
|
+
} while (counter < 100);
|
|
449
|
+
|
|
450
|
+
throw new Error('Activation duration is too long');
|
|
196
451
|
}
|
|
197
452
|
|
|
198
453
|
/**
|
|
@@ -201,8 +456,23 @@ export class Flows implements Taggable<Flow> {
|
|
|
201
456
|
* const triggerList = await flows.activateFlow(flowSource, false);
|
|
202
457
|
* ```
|
|
203
458
|
*/
|
|
204
|
-
|
|
205
|
-
|
|
459
|
+
|
|
460
|
+
async activateFlow(flow: ActivateFlowParams, progresCallback: any) {
|
|
461
|
+
const flowAlias = `v-${Date.now()}`;
|
|
462
|
+
|
|
463
|
+
const { requestId } = await this.callApiV2({
|
|
464
|
+
url: this.deployUrl,
|
|
465
|
+
route: '',
|
|
466
|
+
method: 'post',
|
|
467
|
+
data: {
|
|
468
|
+
flowId: flow.id,
|
|
469
|
+
flowAlias,
|
|
470
|
+
interactiveDebug: flow.interactiveDebug,
|
|
471
|
+
role: _.get(flow, 'data.deploy.role'),
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
return this._pollResult(flow.id, requestId, null, progresCallback);
|
|
206
476
|
}
|
|
207
477
|
|
|
208
478
|
/**
|
|
@@ -211,31 +481,46 @@ export class Flows implements Taggable<Flow> {
|
|
|
211
481
|
* const deactivatedFlowList = await flows.deactivateFlow(flowSource, 'flowAlias', false);
|
|
212
482
|
* ```
|
|
213
483
|
*/
|
|
214
|
-
|
|
215
|
-
|
|
484
|
+
async deactivateFlow(flow: DeactivageFlowParams, flowAlias: string, deleteLambda = false) {
|
|
485
|
+
const { requestId } = await this.callApiV2({
|
|
486
|
+
url: this.deployUrl,
|
|
487
|
+
route: '',
|
|
488
|
+
method: 'delete',
|
|
489
|
+
data: {
|
|
490
|
+
flow: {
|
|
491
|
+
id: flow.id,
|
|
492
|
+
},
|
|
493
|
+
flowAlias,
|
|
494
|
+
role: _.get(flow, 'data.deploy.role'),
|
|
495
|
+
deleteLambda,
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
return this._pollResult(flow.id, requestId);
|
|
216
500
|
}
|
|
217
501
|
|
|
502
|
+
|
|
218
503
|
/**
|
|
219
504
|
* Add tags
|
|
220
505
|
* ```typescript
|
|
221
506
|
* const flow = await flows.addTags(flowSource, tagIdsArr);
|
|
222
507
|
* ```
|
|
223
508
|
*/
|
|
224
|
-
public async addTags(source: Flow, tagNames: string[]): Promise<Flow> {
|
|
225
|
-
|
|
226
|
-
|
|
509
|
+
// public async addTags(source: Flow, tagNames: string[]): Promise<Flow> {
|
|
510
|
+
// const tags = await this.tags.getMultipleTagsByName(tagNames, true);
|
|
511
|
+
// const tagIds = tags.map(tag => tag.id!);
|
|
227
512
|
|
|
228
|
-
|
|
513
|
+
// const { newIds } = filterTagIds(source.tags, tagIds);
|
|
229
514
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
515
|
+
// if (!newIds.length) {
|
|
516
|
+
// throw Error('No tags to add.');
|
|
517
|
+
// }
|
|
233
518
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
519
|
+
// return this.saveFlow({
|
|
520
|
+
// ...source,
|
|
521
|
+
// tags: addTagsIds(source.tags, newIds),
|
|
522
|
+
// });
|
|
523
|
+
// }
|
|
239
524
|
|
|
240
525
|
/**
|
|
241
526
|
* Remove tags
|
|
@@ -243,21 +528,21 @@ export class Flows implements Taggable<Flow> {
|
|
|
243
528
|
* const flow = await flows.removeTags(flowSource, tagIdsArr);
|
|
244
529
|
* ```
|
|
245
530
|
*/
|
|
246
|
-
public async removeTags(source: Flow, tagNames: string[]): Promise<Flow> {
|
|
247
|
-
|
|
248
|
-
|
|
531
|
+
// public async removeTags(source: Flow, tagNames: string[]): Promise<Flow> {
|
|
532
|
+
// const tags = await this.tags.getMultipleTagsByName(tagNames);
|
|
533
|
+
// const tagIds = tags.map(tag => tag.id!);
|
|
249
534
|
|
|
250
|
-
|
|
535
|
+
// const { existingIds } = filterTagIds(source.tags, tagIds);
|
|
251
536
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
537
|
+
// if (!existingIds.length) {
|
|
538
|
+
// throw Error('No tags to remove.');
|
|
539
|
+
// }
|
|
255
540
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
541
|
+
// return this.saveFlow({
|
|
542
|
+
// ...source,
|
|
543
|
+
// tags: removeTagIds(source.tags, existingIds),
|
|
544
|
+
// });
|
|
545
|
+
// }
|
|
261
546
|
|
|
262
547
|
/**
|
|
263
548
|
* List unused step templates from flow source
|
package/src/constants.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
export const
|
|
2
|
-
deleteTemporarily(entity: $entity, data: $data) {
|
|
3
|
-
... on AsyncRequest {
|
|
4
|
-
requestId
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
}`;
|
|
1
|
+
export const SERVICE_KEY = 'datahub2';
|
|
8
2
|
|
|
9
|
-
export const ENTITY_NAME = 'FLOW';
|