@or-sdk/flows 0.26.1 → 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/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 +8 -7
- package/src/Flows.ts +432 -147
- package/src/constants.ts +1 -8
- package/src/types.ts +26 -6
package/dist/cjs/Flows.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
var __assign = (this && this.__assign) || function () {
|
|
3
18
|
__assign = Object.assign || function(t) {
|
|
4
19
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -46,234 +61,422 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
61
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
62
|
}
|
|
48
63
|
};
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
if (ar || !(i in from)) {
|
|
52
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
-
ar[i] = from[i];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
64
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
65
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
57
66
|
};
|
|
58
67
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
68
|
exports.Flows = void 0;
|
|
60
69
|
var base_1 = require("@or-sdk/base");
|
|
61
|
-
var
|
|
62
|
-
var
|
|
70
|
+
var lodash_1 = __importDefault(require("lodash"));
|
|
71
|
+
var uuid_1 = require("uuid");
|
|
63
72
|
var constants_1 = require("./constants");
|
|
64
|
-
var tags_1 = require("@or-sdk/tags");
|
|
65
73
|
var utils_1 = require("./utils");
|
|
66
|
-
var Flows = (function () {
|
|
74
|
+
var Flows = (function (_super) {
|
|
75
|
+
__extends(Flows, _super);
|
|
67
76
|
function Flows(params) {
|
|
68
|
-
var
|
|
69
|
-
|
|
77
|
+
var _this = this;
|
|
78
|
+
var discoveryUrl = params.discoveryUrl, token = params.token, accountId = params.accountId, dataHub2Url = params.dataHub2Url, deployerUrl = params.deployerUrl, sdkApiUrl = params.sdkApiUrl;
|
|
79
|
+
_this = _super.call(this, {
|
|
70
80
|
token: token,
|
|
71
81
|
discoveryUrl: discoveryUrl,
|
|
82
|
+
serviceKey: constants_1.SERVICE_KEY,
|
|
72
83
|
accountId: accountId,
|
|
73
|
-
|
|
84
|
+
serviceUrl: dataHub2Url,
|
|
85
|
+
}) || this;
|
|
86
|
+
_this.deployerUrl = deployerUrl;
|
|
87
|
+
_this.sdkApiUrl = sdkApiUrl;
|
|
88
|
+
return _this;
|
|
89
|
+
}
|
|
90
|
+
Flows.prototype.init = function () {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
+
return __generator(this, function (_a) {
|
|
93
|
+
return [2];
|
|
94
|
+
});
|
|
74
95
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
96
|
+
};
|
|
97
|
+
Flows.prototype.deleteFlow = function (flow, flowAlias, temporarily) {
|
|
98
|
+
if (flowAlias === void 0) { flowAlias = 'dev'; }
|
|
99
|
+
if (temporarily === void 0) { temporarily = true; }
|
|
100
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
return [2, this.callApiV2({
|
|
103
|
+
route: "/flows/".concat(flow.id),
|
|
104
|
+
data: {
|
|
105
|
+
flowAlias: flowAlias,
|
|
106
|
+
temporarily: temporarily,
|
|
107
|
+
},
|
|
108
|
+
method: 'delete',
|
|
109
|
+
})];
|
|
110
|
+
});
|
|
80
111
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
112
|
+
};
|
|
113
|
+
Flows.prototype.recoverFlow = function (flow) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
return __generator(this, function (_a) {
|
|
116
|
+
return [2, this.callApiV2({
|
|
117
|
+
route: "/flows/".concat(flow.id),
|
|
118
|
+
method: 'patch',
|
|
119
|
+
})];
|
|
120
|
+
});
|
|
86
121
|
});
|
|
87
|
-
}
|
|
88
|
-
Flows.prototype.
|
|
122
|
+
};
|
|
123
|
+
Flows.prototype.getFlowById = function (id, projection, sandbox) {
|
|
124
|
+
if (sandbox === void 0) { sandbox = false; }
|
|
125
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
return [2, this.callApiV2({
|
|
128
|
+
route: "/flows/".concat(id),
|
|
129
|
+
params: {
|
|
130
|
+
projection: projection,
|
|
131
|
+
sandbox: sandbox,
|
|
132
|
+
},
|
|
133
|
+
})];
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
Flows.prototype.getFlows = function (_a) {
|
|
138
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.query, query = _c === void 0 ? {} : _c, projection = _b.projection, _d = _b.includeDeleted, includeDeleted = _d === void 0 ? false : _d, _e = _b.includeExisting, includeExisting = _e === void 0 ? true : _e, _f = _b.sandbox, sandbox = _f === void 0 ? false : _f, limit = _b.limit, offset = _b.offset;
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
return __generator(this, function (_g) {
|
|
141
|
+
if (typeof query.id === 'string')
|
|
142
|
+
query.id = query.id.split('.');
|
|
143
|
+
if (includeDeleted && !includeExisting)
|
|
144
|
+
query.isDeleted = true;
|
|
145
|
+
if (!includeDeleted && includeExisting)
|
|
146
|
+
query.isDeleted = false;
|
|
147
|
+
return [2, this.callApiV2({
|
|
148
|
+
route: '/flows',
|
|
149
|
+
params: {
|
|
150
|
+
projection: projection,
|
|
151
|
+
query: query,
|
|
152
|
+
sandbox: sandbox,
|
|
153
|
+
limit: limit,
|
|
154
|
+
offset: offset,
|
|
155
|
+
},
|
|
156
|
+
})];
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
Flows.prototype.getFlowEvents = function (_a) {
|
|
161
|
+
var flowId = _a.flowId, _b = _a.alias, alias = _b === void 0 ? 'prod' : _b;
|
|
162
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
163
|
+
return __generator(this, function (_c) {
|
|
164
|
+
return [2, this.callApiV2({
|
|
165
|
+
url: this.sdkApiUrl,
|
|
166
|
+
route: "".concat(this.sdkApiUrl, "/event-manager/get-flow-events/").concat(flowId, "/").concat(alias),
|
|
167
|
+
})];
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
Flows.prototype.getTriggerFlows = function (triggers) {
|
|
172
|
+
if (triggers === void 0) { triggers = []; }
|
|
173
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
+
return __generator(this, function (_a) {
|
|
175
|
+
return [2, this.callApiV2({
|
|
176
|
+
url: this.sdkApiUrl,
|
|
177
|
+
route: "".concat(this.sdkApiUrl, "event-manager/get-trigger-flows"),
|
|
178
|
+
data: { triggers: triggers },
|
|
179
|
+
method: 'post',
|
|
180
|
+
})];
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
Flows.prototype.listVersions = function (query) {
|
|
89
185
|
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
+
return __generator(this, function (_a) {
|
|
187
|
+
return [2, this.callApiV2({
|
|
188
|
+
route: '/flows/versions',
|
|
189
|
+
params: { query: query },
|
|
190
|
+
})];
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
Flows.prototype.getVersion = function (params) {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
196
|
+
var data;
|
|
90
197
|
return __generator(this, function (_a) {
|
|
91
198
|
switch (_a.label) {
|
|
92
|
-
case 0: return [4,
|
|
93
|
-
this.dataHub.init(),
|
|
94
|
-
this.deployer.init(),
|
|
95
|
-
this.tags.init(),
|
|
96
|
-
])];
|
|
199
|
+
case 0: return [4, this.listVersions(params)];
|
|
97
200
|
case 1:
|
|
98
|
-
_a.sent();
|
|
99
|
-
return [2];
|
|
201
|
+
data = _a.sent();
|
|
202
|
+
return [2, data[0]];
|
|
100
203
|
}
|
|
101
204
|
});
|
|
102
205
|
});
|
|
103
206
|
};
|
|
104
|
-
Flows.prototype.
|
|
207
|
+
Flows.prototype.listFlowVersionsByBotId = function (params) {
|
|
105
208
|
return __awaiter(this, void 0, void 0, function () {
|
|
106
|
-
var requestParams, route, result, flowList, query, projection;
|
|
107
209
|
return __generator(this, function (_a) {
|
|
108
|
-
|
|
109
|
-
case 0:
|
|
110
|
-
requestParams = __assign({ includeDeleted: false, includeExisting: true, projection: [
|
|
111
|
-
'id',
|
|
112
|
-
'version',
|
|
113
|
-
'botId',
|
|
114
|
-
'data.label',
|
|
115
|
-
'data.color',
|
|
116
|
-
'data.description',
|
|
117
|
-
'data.isHidden',
|
|
118
|
-
'tags',
|
|
119
|
-
'dateModified',
|
|
120
|
-
] }, params);
|
|
121
|
-
route = "/v2/".concat(this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current', "/flows");
|
|
122
|
-
flowList = [];
|
|
123
|
-
query = { botId: botId ? botId : undefined };
|
|
124
|
-
projection = JSON.stringify(requestParams.projection);
|
|
125
|
-
_a.label = 1;
|
|
126
|
-
case 1: return [4, this.dataHub.makeRequest({
|
|
127
|
-
method: 'GET',
|
|
128
|
-
route: route,
|
|
129
|
-
params: {
|
|
130
|
-
includeDeleted: requestParams.includeDeleted,
|
|
131
|
-
includeExisting: requestParams.includeExisting,
|
|
132
|
-
projection: projection,
|
|
133
|
-
query: JSON.stringify(query),
|
|
134
|
-
},
|
|
135
|
-
})];
|
|
136
|
-
case 2:
|
|
137
|
-
result = _a.sent();
|
|
138
|
-
flowList = __spreadArray(__spreadArray([], flowList, true), result.items, true);
|
|
139
|
-
query.last = result.last;
|
|
140
|
-
_a.label = 3;
|
|
141
|
-
case 3:
|
|
142
|
-
if (result.last) return [3, 1];
|
|
143
|
-
_a.label = 4;
|
|
144
|
-
case 4: return [2, (0, base_1.makeList)(flowList)];
|
|
145
|
-
}
|
|
210
|
+
return [2, this.listVersions(params)];
|
|
146
211
|
});
|
|
147
212
|
});
|
|
148
213
|
};
|
|
149
|
-
Flows.prototype.
|
|
214
|
+
Flows.prototype.loadLogs = function (params) {
|
|
150
215
|
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
-
var
|
|
216
|
+
var flowId, next, startTime, endTime, limit, filter, relativeTime, queryParams;
|
|
152
217
|
return __generator(this, function (_a) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
218
|
+
flowId = params.flowId, next = params.next, startTime = params.startTime, endTime = params.endTime, limit = params.limit, filter = params.filter, relativeTime = params.relativeTime;
|
|
219
|
+
queryParams = { skipOriginal: true };
|
|
220
|
+
if (next) {
|
|
221
|
+
queryParams.next = next;
|
|
222
|
+
}
|
|
223
|
+
if (startTime) {
|
|
224
|
+
queryParams.start = startTime;
|
|
225
|
+
}
|
|
226
|
+
if (endTime) {
|
|
227
|
+
queryParams.end = endTime;
|
|
228
|
+
}
|
|
229
|
+
if (limit) {
|
|
230
|
+
queryParams.limit = limit;
|
|
231
|
+
}
|
|
232
|
+
if (filter) {
|
|
233
|
+
queryParams.filter = filter;
|
|
167
234
|
}
|
|
235
|
+
if (relativeTime) {
|
|
236
|
+
queryParams.relativeTime = relativeTime;
|
|
237
|
+
}
|
|
238
|
+
return [2, this.callApiV2({
|
|
239
|
+
url: this.deployerUrl,
|
|
240
|
+
route: "/flows/".concat(flowId, "/logs"),
|
|
241
|
+
params: queryParams,
|
|
242
|
+
})];
|
|
168
243
|
});
|
|
169
244
|
});
|
|
170
245
|
};
|
|
171
|
-
Flows.prototype.saveFlow = function (
|
|
246
|
+
Flows.prototype.saveFlow = function (flow, _a) {
|
|
247
|
+
var _b = _a === void 0 ? {} : _a, previousVersion = _b.previousVersion;
|
|
172
248
|
return __awaiter(this, void 0, void 0, function () {
|
|
173
|
-
var
|
|
174
|
-
return __generator(this, function (
|
|
175
|
-
switch (
|
|
249
|
+
var _c, id, version;
|
|
250
|
+
return __generator(this, function (_d) {
|
|
251
|
+
switch (_d.label) {
|
|
176
252
|
case 0:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
data: data,
|
|
253
|
+
flow.id = flow.id || 'new';
|
|
254
|
+
return [4, this.callApiV2({
|
|
255
|
+
route: "/flows/".concat(flow.id),
|
|
256
|
+
data: {
|
|
257
|
+
flow: flow,
|
|
258
|
+
previousVersion: previousVersion,
|
|
259
|
+
},
|
|
260
|
+
method: 'post',
|
|
186
261
|
})];
|
|
187
|
-
case 1:
|
|
262
|
+
case 1:
|
|
263
|
+
_c = _d.sent(), id = _c.id, version = _c.version;
|
|
264
|
+
return [2, __assign(__assign({}, flow), { id: id, version: version })];
|
|
188
265
|
}
|
|
189
266
|
});
|
|
190
267
|
});
|
|
191
268
|
};
|
|
192
|
-
Flows.prototype.
|
|
193
|
-
|
|
269
|
+
Flows.prototype.getFlowsByBotId = function (botId, projection) {
|
|
270
|
+
return this.getFlows({
|
|
271
|
+
query: { botId: botId },
|
|
272
|
+
projection: projection,
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
Flows.prototype.getRemoteDataOutsByBotId = function (id) {
|
|
194
276
|
return __awaiter(this, void 0, void 0, function () {
|
|
195
|
-
var
|
|
277
|
+
var flows, dataOuts;
|
|
196
278
|
return __generator(this, function (_a) {
|
|
197
279
|
switch (_a.label) {
|
|
198
|
-
case 0:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
variables = {
|
|
203
|
-
entity: constants_1.ENTITY_NAME,
|
|
204
|
-
data: {
|
|
205
|
-
id: source.id,
|
|
206
|
-
flowAlias: flowAlias,
|
|
207
|
-
subscribe: true,
|
|
208
|
-
role: source.data.deploy.role,
|
|
280
|
+
case 0: return [4, this.getFlows({
|
|
281
|
+
query: {
|
|
282
|
+
botId: id,
|
|
283
|
+
isDeleted: false,
|
|
209
284
|
},
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
data = {
|
|
213
|
-
operationName: operationName,
|
|
214
|
-
query: constants_1.QUERY_DELETE,
|
|
215
|
-
variables: variables,
|
|
216
|
-
};
|
|
217
|
-
return [4, this.dataHub.makeRequest({
|
|
218
|
-
method: 'POST',
|
|
219
|
-
route: '/graphql',
|
|
220
|
-
data: data,
|
|
221
|
-
})];
|
|
285
|
+
projection: ['id', 'data.label'],
|
|
286
|
+
})];
|
|
222
287
|
case 1:
|
|
223
|
-
|
|
224
|
-
return [
|
|
288
|
+
flows = _a.sent();
|
|
289
|
+
return [4, this.callApiV2({
|
|
290
|
+
route: 'flows/data-outs',
|
|
291
|
+
params: {
|
|
292
|
+
query: {
|
|
293
|
+
type: {
|
|
294
|
+
not: 'session',
|
|
295
|
+
ne: null,
|
|
296
|
+
},
|
|
297
|
+
name: { ne: null },
|
|
298
|
+
botId: id,
|
|
299
|
+
flowId: flows.map(function (flow) { return flow.id; }),
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
})];
|
|
303
|
+
case 2:
|
|
304
|
+
dataOuts = _a.sent();
|
|
305
|
+
return [2, lodash_1.default.reduce(flows, function (acc, flow) {
|
|
306
|
+
var flowLabel = lodash_1.default.get(flow, 'data.label', 'No name flow');
|
|
307
|
+
acc[flow.id] = lodash_1.default.map(dataOuts, function (dataOut) { return (__assign(__assign({}, dataOut), { flowLabel: flowLabel })); });
|
|
308
|
+
return acc;
|
|
309
|
+
}, {})];
|
|
225
310
|
}
|
|
226
311
|
});
|
|
227
312
|
});
|
|
228
313
|
};
|
|
229
|
-
Flows.
|
|
230
|
-
|
|
314
|
+
Flows.getEmptyStep = function (stepId) {
|
|
315
|
+
return {
|
|
316
|
+
id: stepId || (0, uuid_1.v4)(),
|
|
317
|
+
icon: 'add',
|
|
318
|
+
iconType: 'default',
|
|
319
|
+
iconUrl: '',
|
|
320
|
+
shape: 'empty',
|
|
321
|
+
type: 'empty',
|
|
322
|
+
pinLabel: true,
|
|
323
|
+
stepInputData: {},
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
Flows.getEmptyFlow = function (botId) {
|
|
327
|
+
var defaultLambdaMemorySize = 1024;
|
|
328
|
+
var defaultLambdaTimeout = 30;
|
|
329
|
+
return {
|
|
330
|
+
botId: botId,
|
|
331
|
+
data: {
|
|
332
|
+
label: '',
|
|
333
|
+
description: '',
|
|
334
|
+
deploy: {
|
|
335
|
+
memory: defaultLambdaMemorySize,
|
|
336
|
+
timeout: defaultLambdaTimeout,
|
|
337
|
+
role: 'USER',
|
|
338
|
+
},
|
|
339
|
+
meta: {},
|
|
340
|
+
color: null,
|
|
341
|
+
categories: null,
|
|
342
|
+
annotations: null,
|
|
343
|
+
stepTemplates: [],
|
|
344
|
+
trees: {
|
|
345
|
+
main: {
|
|
346
|
+
position: {
|
|
347
|
+
x: 0,
|
|
348
|
+
y: 0,
|
|
349
|
+
},
|
|
350
|
+
steps: [this.getEmptyStep()],
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
Flows.getNewFlow = function (botId, flowTemplate) {
|
|
231
357
|
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
+
var flow, template;
|
|
232
359
|
return __generator(this, function (_a) {
|
|
233
|
-
|
|
360
|
+
flow = this.getEmptyFlow(botId);
|
|
361
|
+
template = lodash_1.default.omit(flowTemplate, ['id', 'botId', 'dateCreated', 'dateModified', 'version']);
|
|
362
|
+
flow.data.steps = lodash_1.default.get(template, 'data.steps.length') > 0 ? [] : flow.data.steps;
|
|
363
|
+
return [2, lodash_1.default.merge(flow, template)];
|
|
234
364
|
});
|
|
235
365
|
});
|
|
236
366
|
};
|
|
237
|
-
Flows.prototype.
|
|
238
|
-
if (
|
|
367
|
+
Flows.prototype.listFlows = function (botId, params) {
|
|
368
|
+
if (params === void 0) { params = {}; }
|
|
239
369
|
return __awaiter(this, void 0, void 0, function () {
|
|
240
370
|
return __generator(this, function (_a) {
|
|
241
|
-
return [2, this.
|
|
371
|
+
return [2, this.getFlows(__assign(__assign({}, params), { query: { botId: botId } }))];
|
|
242
372
|
});
|
|
243
373
|
});
|
|
244
374
|
};
|
|
245
|
-
Flows.prototype.
|
|
375
|
+
Flows.prototype.getFlow = function (id) {
|
|
246
376
|
return __awaiter(this, void 0, void 0, function () {
|
|
247
|
-
|
|
377
|
+
return __generator(this, function (_a) {
|
|
378
|
+
return [2, this.getFlowById(id)];
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
};
|
|
382
|
+
Object.defineProperty(Flows.prototype, "deployUrl", {
|
|
383
|
+
get: function () {
|
|
384
|
+
return this.targetAccountId ? "".concat(this.deployerUrl, "/accounts/").concat(this.targetAccountId, "/flows/deploy") : "".concat(this.deployerUrl, "/flows/deploy");
|
|
385
|
+
},
|
|
386
|
+
enumerable: false,
|
|
387
|
+
configurable: true
|
|
388
|
+
});
|
|
389
|
+
Object.defineProperty(Flows.prototype, "checkUrl", {
|
|
390
|
+
get: function () {
|
|
391
|
+
return this.targetAccountId ? "".concat(this.deployerUrl, "/accounts/").concat(this.targetAccountId, "/flows/check") : "".concat(this.deployerUrl, "/flows/check");
|
|
392
|
+
},
|
|
393
|
+
enumerable: false,
|
|
394
|
+
configurable: true
|
|
395
|
+
});
|
|
396
|
+
Flows.prototype._pollResult = function (flowId, requestId, headers, progresCallback) {
|
|
397
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
398
|
+
var counter, result;
|
|
248
399
|
return __generator(this, function (_a) {
|
|
249
400
|
switch (_a.label) {
|
|
250
|
-
case 0:
|
|
401
|
+
case 0:
|
|
402
|
+
counter = 0;
|
|
403
|
+
_a.label = 1;
|
|
251
404
|
case 1:
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
405
|
+
counter++;
|
|
406
|
+
return [4, new Promise(function (r) { return setTimeout(r, 1000); })];
|
|
407
|
+
case 2:
|
|
408
|
+
_a.sent();
|
|
409
|
+
return [4, this.callApiV2({
|
|
410
|
+
url: "".concat(this.checkUrl),
|
|
411
|
+
route: "/".concat(flowId, "/").concat(requestId),
|
|
412
|
+
})];
|
|
413
|
+
case 3:
|
|
414
|
+
result = _a.sent();
|
|
415
|
+
if (lodash_1.default.isFunction(progresCallback)) {
|
|
416
|
+
progresCallback(result);
|
|
257
417
|
}
|
|
258
|
-
|
|
418
|
+
if (result.status !== 'pending') {
|
|
419
|
+
if (result.errorData) {
|
|
420
|
+
throw result;
|
|
421
|
+
}
|
|
422
|
+
return [2, result];
|
|
423
|
+
}
|
|
424
|
+
_a.label = 4;
|
|
425
|
+
case 4:
|
|
426
|
+
if (counter < 100) return [3, 1];
|
|
427
|
+
_a.label = 5;
|
|
428
|
+
case 5: throw new Error('Activation duration is too long');
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
Flows.prototype.activateFlow = function (flow, progresCallback) {
|
|
434
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
435
|
+
var flowAlias, requestId;
|
|
436
|
+
return __generator(this, function (_a) {
|
|
437
|
+
switch (_a.label) {
|
|
438
|
+
case 0:
|
|
439
|
+
flowAlias = "v-".concat(Date.now());
|
|
440
|
+
return [4, this.callApiV2({
|
|
441
|
+
url: this.deployUrl,
|
|
442
|
+
route: '',
|
|
443
|
+
method: 'post',
|
|
444
|
+
data: {
|
|
445
|
+
flowId: flow.id,
|
|
446
|
+
flowAlias: flowAlias,
|
|
447
|
+
interactiveDebug: flow.interactiveDebug,
|
|
448
|
+
role: lodash_1.default.get(flow, 'data.deploy.role'),
|
|
449
|
+
},
|
|
450
|
+
})];
|
|
451
|
+
case 1:
|
|
452
|
+
requestId = (_a.sent()).requestId;
|
|
453
|
+
return [2, this._pollResult(flow.id, requestId, null, progresCallback)];
|
|
259
454
|
}
|
|
260
455
|
});
|
|
261
456
|
});
|
|
262
457
|
};
|
|
263
|
-
Flows.prototype.
|
|
458
|
+
Flows.prototype.deactivateFlow = function (flow, flowAlias, deleteLambda) {
|
|
459
|
+
if (deleteLambda === void 0) { deleteLambda = false; }
|
|
264
460
|
return __awaiter(this, void 0, void 0, function () {
|
|
265
|
-
var
|
|
461
|
+
var requestId;
|
|
266
462
|
return __generator(this, function (_a) {
|
|
267
463
|
switch (_a.label) {
|
|
268
|
-
case 0: return [4, this.
|
|
464
|
+
case 0: return [4, this.callApiV2({
|
|
465
|
+
url: this.deployUrl,
|
|
466
|
+
route: '',
|
|
467
|
+
method: 'delete',
|
|
468
|
+
data: {
|
|
469
|
+
flow: {
|
|
470
|
+
id: flow.id,
|
|
471
|
+
},
|
|
472
|
+
flowAlias: flowAlias,
|
|
473
|
+
role: lodash_1.default.get(flow, 'data.deploy.role'),
|
|
474
|
+
deleteLambda: deleteLambda,
|
|
475
|
+
},
|
|
476
|
+
})];
|
|
269
477
|
case 1:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
existingIds = (0, tags_1.filterTagIds)(source.tags, tagIds).existingIds;
|
|
273
|
-
if (!existingIds.length) {
|
|
274
|
-
throw Error('No tags to remove.');
|
|
275
|
-
}
|
|
276
|
-
return [2, this.saveFlow(__assign(__assign({}, source), { tags: (0, tags_1.removeTagIds)(source.tags, existingIds) }))];
|
|
478
|
+
requestId = (_a.sent()).requestId;
|
|
479
|
+
return [2, this._pollResult(flow.id, requestId)];
|
|
277
480
|
}
|
|
278
481
|
});
|
|
279
482
|
});
|
|
@@ -286,6 +489,6 @@ var Flows = (function () {
|
|
|
286
489
|
return (0, utils_1.deleteUnusedStepTemplates)(source, stepTemplates);
|
|
287
490
|
};
|
|
288
491
|
return Flows;
|
|
289
|
-
}());
|
|
492
|
+
}(base_1.Base));
|
|
290
493
|
exports.Flows = Flows;
|
|
291
494
|
//# sourceMappingURL=Flows.js.map
|