@or-sdk/flows 0.13.1 → 0.17.1
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 +68 -8
- package/dist/cjs/Flows.js.map +1 -1
- package/dist/esm/Flows.js +42 -7
- package/dist/esm/Flows.js.map +1 -1
- package/dist/types/Flows.d.ts +5 -1
- package/dist/types/types.d.ts +1 -0
- package/package.json +6 -5
- package/src/Flows.ts +69 -9
- package/src/types.ts +4 -0
package/dist/cjs/Flows.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -50,16 +61,24 @@ var base_1 = require("@or-sdk/base");
|
|
|
50
61
|
var data_hub_1 = require("@or-sdk/data-hub");
|
|
51
62
|
var deployer_1 = require("@or-sdk/deployer");
|
|
52
63
|
var constants_1 = require("./constants");
|
|
64
|
+
var tags_1 = require("@or-sdk/tags");
|
|
53
65
|
var Flows = (function () {
|
|
54
66
|
function Flows(params) {
|
|
55
|
-
var discoveryUrl = params.discoveryUrl, token = params.token;
|
|
67
|
+
var discoveryUrl = params.discoveryUrl, token = params.token, accountId = params.accountId;
|
|
56
68
|
this.dataHub = new data_hub_1.DataHub({
|
|
57
69
|
token: token,
|
|
58
70
|
discoveryUrl: discoveryUrl,
|
|
71
|
+
accountId: accountId,
|
|
59
72
|
});
|
|
60
73
|
this.deployer = new deployer_1.Deployer({
|
|
61
74
|
token: token,
|
|
62
75
|
discoveryUrl: discoveryUrl,
|
|
76
|
+
accountId: accountId,
|
|
77
|
+
});
|
|
78
|
+
this.tags = new tags_1.Tags({
|
|
79
|
+
token: token,
|
|
80
|
+
discoveryUrl: discoveryUrl,
|
|
81
|
+
accountId: accountId,
|
|
63
82
|
});
|
|
64
83
|
}
|
|
65
84
|
Flows.prototype.init = function () {
|
|
@@ -69,6 +88,7 @@ var Flows = (function () {
|
|
|
69
88
|
case 0: return [4, Promise.all([
|
|
70
89
|
this.dataHub.init(),
|
|
71
90
|
this.deployer.init(),
|
|
91
|
+
this.tags.init(),
|
|
72
92
|
])];
|
|
73
93
|
case 1:
|
|
74
94
|
_a.sent();
|
|
@@ -89,7 +109,7 @@ var Flows = (function () {
|
|
|
89
109
|
projection: JSON.stringify(['id', 'version', 'botId', 'data.label', 'data.color', 'data.description', 'data.isHidden', 'tags', 'dateModified']),
|
|
90
110
|
query: undefined,
|
|
91
111
|
};
|
|
92
|
-
route = "/v2/" + this.dataHub.currentAccountId + "/flows";
|
|
112
|
+
route = "/v2/" + (this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current') + "/flows";
|
|
93
113
|
flowList = [];
|
|
94
114
|
query = { botId: botId ? botId : undefined };
|
|
95
115
|
_a.label = 1;
|
|
@@ -119,7 +139,7 @@ var Flows = (function () {
|
|
|
119
139
|
return __generator(this, function (_a) {
|
|
120
140
|
switch (_a.label) {
|
|
121
141
|
case 0:
|
|
122
|
-
route = "/v2/" + this.dataHub.currentAccountId + "/flow/" + id;
|
|
142
|
+
route = "/v2/" + (this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current') + "/flow/" + id;
|
|
123
143
|
params = {
|
|
124
144
|
includeDeleted: false,
|
|
125
145
|
includeExisting: true,
|
|
@@ -141,7 +161,7 @@ var Flows = (function () {
|
|
|
141
161
|
return __generator(this, function (_a) {
|
|
142
162
|
switch (_a.label) {
|
|
143
163
|
case 0:
|
|
144
|
-
route = "/v2/" + this.dataHub.currentAccountId + "/flow/" + (source.id ? source.id : 'new');
|
|
164
|
+
route = "/v2/" + (this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current') + "/flow/" + (source.id ? source.id : 'new');
|
|
145
165
|
data = {
|
|
146
166
|
flow: source,
|
|
147
167
|
previousVersion: source.id ? source.version : undefined,
|
|
@@ -159,10 +179,13 @@ var Flows = (function () {
|
|
|
159
179
|
Flows.prototype.deleteFlow = function (source, flowAlias) {
|
|
160
180
|
if (flowAlias === void 0) { flowAlias = 'dev'; }
|
|
161
181
|
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
-
var variables, data,
|
|
182
|
+
var variables, operationName, data, result;
|
|
163
183
|
return __generator(this, function (_a) {
|
|
164
184
|
switch (_a.label) {
|
|
165
185
|
case 0:
|
|
186
|
+
if (this.dataHub.isCrossAccount) {
|
|
187
|
+
throw Error('Cross-account deleting is not implemented.');
|
|
188
|
+
}
|
|
166
189
|
variables = {
|
|
167
190
|
entity: constants_1.ENTITY_NAME,
|
|
168
191
|
data: {
|
|
@@ -172,8 +195,9 @@ var Flows = (function () {
|
|
|
172
195
|
role: source.data.deploy.role,
|
|
173
196
|
},
|
|
174
197
|
};
|
|
198
|
+
operationName = this.dataHub.getOperationName('deleteTemporarily');
|
|
175
199
|
data = {
|
|
176
|
-
operationName:
|
|
200
|
+
operationName: operationName,
|
|
177
201
|
query: constants_1.QUERY_DELETE,
|
|
178
202
|
variables: variables,
|
|
179
203
|
};
|
|
@@ -183,8 +207,8 @@ var Flows = (function () {
|
|
|
183
207
|
data: data,
|
|
184
208
|
})];
|
|
185
209
|
case 1:
|
|
186
|
-
|
|
187
|
-
return [2, this.dataHub.subscribe(requestId)];
|
|
210
|
+
result = _a.sent();
|
|
211
|
+
return [2, this.dataHub.subscribe(result.data[operationName].requestId)];
|
|
188
212
|
}
|
|
189
213
|
});
|
|
190
214
|
});
|
|
@@ -205,6 +229,42 @@ var Flows = (function () {
|
|
|
205
229
|
});
|
|
206
230
|
});
|
|
207
231
|
};
|
|
232
|
+
Flows.prototype.addTags = function (source, tagNames) {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
234
|
+
var tags, tagIds, newIds;
|
|
235
|
+
return __generator(this, function (_a) {
|
|
236
|
+
switch (_a.label) {
|
|
237
|
+
case 0: return [4, this.tags.getMultipleTagsByName(tagNames, true)];
|
|
238
|
+
case 1:
|
|
239
|
+
tags = _a.sent();
|
|
240
|
+
tagIds = tags.map(function (tag) { return tag.id; });
|
|
241
|
+
newIds = (0, tags_1.filterTagIds)(source.tags, tagIds).newIds;
|
|
242
|
+
if (!newIds.length) {
|
|
243
|
+
throw Error('No tags to add.');
|
|
244
|
+
}
|
|
245
|
+
return [2, this.saveFlow(__assign(__assign({}, source), { tags: (0, tags_1.addTagsIds)(source.tags, newIds) }))];
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
Flows.prototype.removeTags = function (source, tagNames) {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
252
|
+
var tags, tagIds, existingIds;
|
|
253
|
+
return __generator(this, function (_a) {
|
|
254
|
+
switch (_a.label) {
|
|
255
|
+
case 0: return [4, this.tags.getMultipleTagsByName(tagNames)];
|
|
256
|
+
case 1:
|
|
257
|
+
tags = _a.sent();
|
|
258
|
+
tagIds = tags.map(function (tag) { return tag.id; });
|
|
259
|
+
existingIds = (0, tags_1.filterTagIds)(source.tags, tagIds).existingIds;
|
|
260
|
+
if (!existingIds.length) {
|
|
261
|
+
throw Error('No tags to remove.');
|
|
262
|
+
}
|
|
263
|
+
return [2, this.saveFlow(__assign(__assign({}, source), { tags: (0, tags_1.removeTagIds)(source.tags, existingIds) }))];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
};
|
|
208
268
|
return Flows;
|
|
209
269
|
}());
|
|
210
270
|
exports.Flows = Flows;
|
package/dist/cjs/Flows.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Flows.js","sourceRoot":"","sources":["../../src/Flows.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Flows.js","sourceRoot":"","sources":["../../src/Flows.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA8C;AAC9C,6CAAkH;AAClH,6CAAgH;AAEhH,yCAAwD;AACxD,qCAAsF;AAStF;IAYE,eAAY,MAAmB;QACrB,IAAA,YAAY,GAAuB,MAAM,aAA7B,EAAE,KAAK,GAAgB,MAAM,MAAtB,EAAE,SAAS,GAAK,MAAM,UAAX,CAAY;QAElD,IAAI,CAAC,OAAO,GAAG,IAAI,kBAAO,CAAC;YACzB,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,SAAS,WAAA;SACV,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,CAAC;YAC3B,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,SAAS,WAAA;SACV,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,WAAI,CAAC;YACnB,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,SAAS,WAAA;SACV,CAAC,CAAC;IACL,CAAC;IAEK,oBAAI,GAAV;;;;4BACE,WAAM,OAAO,CAAC,GAAG,CAAC;4BAChB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;4BACnB,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;4BACpB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;yBACjB,CAAC,EAAA;;wBAJF,SAIE,CAAC;;;;;KACJ;IAUY,yBAAS,GAAtB,UAAuB,KAAc;;;;;;wBAC7B,MAAM,GAAG;4BACb,cAAc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AAC,iBAAiB,CAAC,CAAC;yBAChC;wBAED,WAAO,IAAI,CAAC,QAAQ,uBACf,MAAM,KACT,IAAI,EAAE,IAAA,iBAAU,EAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IACrC,EAAC;;;;KACJ;IAQY,0BAAU,GAAvB,UAAwB,MAAY,EAAE,QAAkB;;;;;4BACzC,WAAM,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAA;;wBAAtD,IAAI,GAAG,SAA+C;wBACtD,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,GAAG,CAAC,EAAG,EAAP,CAAO,CAAC,CAAC;wBAEhC,WAAW,GAAK,IAAA,mBAAY,EAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,YAAtC,CAAuC;wBAE1D,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;4BACvB,MAAM,KAAK,CAAC,oBAAoB,CAAC,CAAC;yBACnC;wBAED,WAAO,IAAI,CAAC,QAAQ,uBACf,MAAM,KACT,IAAI,EAAE,IAAA,mBAAY,EAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,IAC5C,EAAC;;;;KACJ;IAEH,YAAC;AAAD,CAAC,AAlOD,IAkOC;AAlOY,sBAAK"}
|
package/dist/esm/Flows.js
CHANGED
|
@@ -11,16 +11,24 @@ import { makeList } from '@or-sdk/base';
|
|
|
11
11
|
import { DataHub } from '@or-sdk/data-hub';
|
|
12
12
|
import { Deployer } from '@or-sdk/deployer';
|
|
13
13
|
import { QUERY_DELETE, ENTITY_NAME } from './constants';
|
|
14
|
+
import { Tags, filterTagIds, addTagsIds, removeTagIds } from '@or-sdk/tags';
|
|
14
15
|
export class Flows {
|
|
15
16
|
constructor(params) {
|
|
16
|
-
const { discoveryUrl, token } = params;
|
|
17
|
+
const { discoveryUrl, token, accountId } = params;
|
|
17
18
|
this.dataHub = new DataHub({
|
|
18
19
|
token,
|
|
19
20
|
discoveryUrl,
|
|
21
|
+
accountId,
|
|
20
22
|
});
|
|
21
23
|
this.deployer = new Deployer({
|
|
22
24
|
token,
|
|
23
25
|
discoveryUrl,
|
|
26
|
+
accountId,
|
|
27
|
+
});
|
|
28
|
+
this.tags = new Tags({
|
|
29
|
+
token,
|
|
30
|
+
discoveryUrl,
|
|
31
|
+
accountId,
|
|
24
32
|
});
|
|
25
33
|
}
|
|
26
34
|
init() {
|
|
@@ -28,6 +36,7 @@ export class Flows {
|
|
|
28
36
|
yield Promise.all([
|
|
29
37
|
this.dataHub.init(),
|
|
30
38
|
this.deployer.init(),
|
|
39
|
+
this.tags.init(),
|
|
31
40
|
]);
|
|
32
41
|
});
|
|
33
42
|
}
|
|
@@ -39,7 +48,7 @@ export class Flows {
|
|
|
39
48
|
projection: JSON.stringify(['id', 'version', 'botId', 'data.label', 'data.color', 'data.description', 'data.isHidden', 'tags', 'dateModified']),
|
|
40
49
|
query: undefined,
|
|
41
50
|
};
|
|
42
|
-
const route = `/v2/${this.dataHub.currentAccountId}/flows`;
|
|
51
|
+
const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/flows`;
|
|
43
52
|
let result;
|
|
44
53
|
let flowList = [];
|
|
45
54
|
const query = { botId: botId ? botId : undefined };
|
|
@@ -58,7 +67,7 @@ export class Flows {
|
|
|
58
67
|
}
|
|
59
68
|
getFlow(id) {
|
|
60
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
const route = `/v2/${this.dataHub.currentAccountId}/flow/${id}`;
|
|
70
|
+
const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/flow/${id}`;
|
|
62
71
|
const params = {
|
|
63
72
|
includeDeleted: false,
|
|
64
73
|
includeExisting: true,
|
|
@@ -73,7 +82,7 @@ export class Flows {
|
|
|
73
82
|
}
|
|
74
83
|
saveFlow(source) {
|
|
75
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
const route = `/v2/${this.dataHub.currentAccountId}/flow/${source.id ? source.id : 'new'}`;
|
|
85
|
+
const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/flow/${source.id ? source.id : 'new'}`;
|
|
77
86
|
const data = {
|
|
78
87
|
flow: source,
|
|
79
88
|
previousVersion: source.id ? source.version : undefined,
|
|
@@ -87,6 +96,9 @@ export class Flows {
|
|
|
87
96
|
}
|
|
88
97
|
deleteFlow(source, flowAlias = 'dev') {
|
|
89
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
if (this.dataHub.isCrossAccount) {
|
|
100
|
+
throw Error('Cross-account deleting is not implemented.');
|
|
101
|
+
}
|
|
90
102
|
const variables = {
|
|
91
103
|
entity: ENTITY_NAME,
|
|
92
104
|
data: {
|
|
@@ -96,17 +108,18 @@ export class Flows {
|
|
|
96
108
|
role: source.data.deploy.role,
|
|
97
109
|
},
|
|
98
110
|
};
|
|
111
|
+
const operationName = this.dataHub.getOperationName('deleteTemporarily');
|
|
99
112
|
const data = {
|
|
100
|
-
operationName
|
|
113
|
+
operationName,
|
|
101
114
|
query: QUERY_DELETE,
|
|
102
115
|
variables,
|
|
103
116
|
};
|
|
104
|
-
const
|
|
117
|
+
const result = yield this.dataHub.makeRequest({
|
|
105
118
|
method: 'POST',
|
|
106
119
|
route: '/graphql',
|
|
107
120
|
data,
|
|
108
121
|
});
|
|
109
|
-
return this.dataHub.subscribe(requestId);
|
|
122
|
+
return this.dataHub.subscribe(result.data[operationName].requestId);
|
|
110
123
|
});
|
|
111
124
|
}
|
|
112
125
|
activateFlow(source, interactiveDebug = false) {
|
|
@@ -119,5 +132,27 @@ export class Flows {
|
|
|
119
132
|
return this.deployer.deactivateFlow(source, flowAlias, deleteLambda);
|
|
120
133
|
});
|
|
121
134
|
}
|
|
135
|
+
addTags(source, tagNames) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const tags = yield this.tags.getMultipleTagsByName(tagNames, true);
|
|
138
|
+
const tagIds = tags.map(tag => tag.id);
|
|
139
|
+
const { newIds } = filterTagIds(source.tags, tagIds);
|
|
140
|
+
if (!newIds.length) {
|
|
141
|
+
throw Error('No tags to add.');
|
|
142
|
+
}
|
|
143
|
+
return this.saveFlow(Object.assign(Object.assign({}, source), { tags: addTagsIds(source.tags, newIds) }));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
removeTags(source, tagNames) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
const tags = yield this.tags.getMultipleTagsByName(tagNames);
|
|
149
|
+
const tagIds = tags.map(tag => tag.id);
|
|
150
|
+
const { existingIds } = filterTagIds(source.tags, tagIds);
|
|
151
|
+
if (!existingIds.length) {
|
|
152
|
+
throw Error('No tags to remove.');
|
|
153
|
+
}
|
|
154
|
+
return this.saveFlow(Object.assign(Object.assign({}, source), { tags: removeTagIds(source.tags, existingIds) }));
|
|
155
|
+
});
|
|
156
|
+
}
|
|
122
157
|
}
|
|
123
158
|
//# sourceMappingURL=Flows.js.map
|
package/dist/esm/Flows.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Flows.js","sourceRoot":"","sources":["../../src/Flows.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAQ,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"Flows.js","sourceRoot":"","sources":["../../src/Flows.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAQ,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAyE,MAAM,kBAAkB,CAAC;AAClH,OAAO,EAAE,QAAQ,EAAsE,MAAM,kBAAkB,CAAC;AAEhH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,IAAI,EAAY,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAA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AAM,CAAC,IAAI,EAAE,WAAW,CAAC,IAC5C,CAAC;QACL,CAAC;KAAA;CAEF"}
|
package/dist/types/Flows.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { List } from '@or-sdk/base';
|
|
|
2
2
|
import { GraphqlResponseCheckExecution } from '@or-sdk/data-hub';
|
|
3
3
|
import { Flow, PollingResultActivateSuccess, PollingResultDeactivateSuccess } from '@or-sdk/deployer';
|
|
4
4
|
import { FlowsConfig } from './types';
|
|
5
|
-
|
|
5
|
+
import { Taggable } from '@or-sdk/tags';
|
|
6
|
+
export declare class Flows implements Taggable<Flow> {
|
|
6
7
|
private readonly dataHub;
|
|
7
8
|
private readonly deployer;
|
|
9
|
+
private readonly tags;
|
|
8
10
|
constructor(params: FlowsConfig);
|
|
9
11
|
init(): Promise<void>;
|
|
10
12
|
listFlows(botId?: string): Promise<List<Flow>>;
|
|
@@ -13,4 +15,6 @@ export declare class Flows {
|
|
|
13
15
|
deleteFlow(source: Flow, flowAlias?: string): Promise<GraphqlResponseCheckExecution>;
|
|
14
16
|
activateFlow(source: Flow, interactiveDebug?: boolean): Promise<PollingResultActivateSuccess>;
|
|
15
17
|
deactivateFlow(source: Flow, flowAlias: string, deleteLambda?: boolean): Promise<PollingResultDeactivateSuccess>;
|
|
18
|
+
addTags(source: Flow, tagNames: string[]): Promise<Flow>;
|
|
19
|
+
removeTags(source: Flow, tagNames: string[]): Promise<Flow>;
|
|
16
20
|
}
|
package/dist/types/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.17.1",
|
|
3
3
|
"name": "@or-sdk/flows",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@or-sdk/base": "^0.
|
|
27
|
-
"@or-sdk/data-hub": "^0.
|
|
28
|
-
"@or-sdk/deployer": "^0.
|
|
26
|
+
"@or-sdk/base": "^0.17.1",
|
|
27
|
+
"@or-sdk/data-hub": "^0.17.1",
|
|
28
|
+
"@or-sdk/deployer": "^0.17.1",
|
|
29
|
+
"@or-sdk/tags": "^0.17.1"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "61ede4c3b5e828ea61a8bb78a4bfc4f06852885d"
|
|
31
32
|
}
|
package/src/Flows.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { List, makeList } from '@or-sdk/base';
|
|
2
|
-
import { DataHub, GraphqlResponseCheckExecution, GraphqlResponse } from '@or-sdk/data-hub';
|
|
2
|
+
import { DataHub, GraphqlResponseCheckExecution, GraphqlResponse, GraphqlResponseDelete } from '@or-sdk/data-hub';
|
|
3
3
|
import { Deployer, Flow, PollingResultActivateSuccess, PollingResultDeactivateSuccess } from '@or-sdk/deployer';
|
|
4
4
|
import { FlowsConfig, FlowListResponse } from './types';
|
|
5
5
|
import { QUERY_DELETE, ENTITY_NAME } from './constants';
|
|
6
|
+
import { Tags, Taggable, filterTagIds, addTagsIds, removeTagIds } from '@or-sdk/tags';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* OneReach Flows service client
|
|
@@ -11,9 +12,10 @@ import { QUERY_DELETE, ENTITY_NAME } from './constants';
|
|
|
11
12
|
* $ npm i @or-sdk/flows
|
|
12
13
|
* ```
|
|
13
14
|
*/
|
|
14
|
-
export class Flows {
|
|
15
|
+
export class Flows implements Taggable<Flow> {
|
|
15
16
|
private readonly dataHub: DataHub;
|
|
16
17
|
private readonly deployer: Deployer;
|
|
18
|
+
private readonly tags: Tags;
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* ```typescript
|
|
@@ -23,15 +25,22 @@ export class Flows {
|
|
|
23
25
|
* ```
|
|
24
26
|
*/
|
|
25
27
|
constructor(params: FlowsConfig) {
|
|
26
|
-
const { discoveryUrl, token } = params;
|
|
28
|
+
const { discoveryUrl, token, accountId } = params;
|
|
27
29
|
|
|
28
30
|
this.dataHub = new DataHub({
|
|
29
31
|
token,
|
|
30
32
|
discoveryUrl,
|
|
33
|
+
accountId,
|
|
31
34
|
});
|
|
32
35
|
this.deployer = new Deployer({
|
|
33
36
|
token,
|
|
34
37
|
discoveryUrl,
|
|
38
|
+
accountId,
|
|
39
|
+
});
|
|
40
|
+
this.tags = new Tags({
|
|
41
|
+
token,
|
|
42
|
+
discoveryUrl,
|
|
43
|
+
accountId,
|
|
35
44
|
});
|
|
36
45
|
}
|
|
37
46
|
|
|
@@ -39,6 +48,7 @@ export class Flows {
|
|
|
39
48
|
await Promise.all([
|
|
40
49
|
this.dataHub.init(),
|
|
41
50
|
this.deployer.init(),
|
|
51
|
+
this.tags.init(),
|
|
42
52
|
]);
|
|
43
53
|
}
|
|
44
54
|
|
|
@@ -58,7 +68,7 @@ export class Flows {
|
|
|
58
68
|
query: undefined as unknown,
|
|
59
69
|
};
|
|
60
70
|
|
|
61
|
-
const route = `/v2/${this.dataHub.currentAccountId}/flows`;
|
|
71
|
+
const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/flows`;
|
|
62
72
|
|
|
63
73
|
let result: FlowListResponse;
|
|
64
74
|
let flowList: Flow[] = [];
|
|
@@ -88,7 +98,7 @@ export class Flows {
|
|
|
88
98
|
* ```
|
|
89
99
|
*/
|
|
90
100
|
public async getFlow(id: string): Promise<Flow> {
|
|
91
|
-
const route = `/v2/${this.dataHub.currentAccountId}/flow/${id}`;
|
|
101
|
+
const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/flow/${id}`;
|
|
92
102
|
|
|
93
103
|
const params = {
|
|
94
104
|
includeDeleted: false,
|
|
@@ -112,7 +122,7 @@ export class Flows {
|
|
|
112
122
|
* ```
|
|
113
123
|
*/
|
|
114
124
|
public async saveFlow(source: Flow): Promise<Flow> {
|
|
115
|
-
const route = `/v2/${this.dataHub.currentAccountId}/flow/${source.id ? source.id : 'new'}`;
|
|
125
|
+
const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/flow/${source.id ? source.id : 'new'}`;
|
|
116
126
|
|
|
117
127
|
const data = {
|
|
118
128
|
flow: source,
|
|
@@ -133,6 +143,10 @@ export class Flows {
|
|
|
133
143
|
* ```
|
|
134
144
|
*/
|
|
135
145
|
public async deleteFlow(source: Flow, flowAlias = 'dev'): Promise<GraphqlResponseCheckExecution> {
|
|
146
|
+
if (this.dataHub.isCrossAccount) {
|
|
147
|
+
throw Error('Cross-account deleting is not implemented.');
|
|
148
|
+
}
|
|
149
|
+
|
|
136
150
|
const variables = {
|
|
137
151
|
entity: ENTITY_NAME,
|
|
138
152
|
data: {
|
|
@@ -143,19 +157,21 @@ export class Flows {
|
|
|
143
157
|
},
|
|
144
158
|
};
|
|
145
159
|
|
|
160
|
+
const operationName = this.dataHub.getOperationName('deleteTemporarily');
|
|
161
|
+
|
|
146
162
|
const data = {
|
|
147
|
-
operationName
|
|
163
|
+
operationName,
|
|
148
164
|
query: QUERY_DELETE,
|
|
149
165
|
variables,
|
|
150
166
|
};
|
|
151
167
|
|
|
152
|
-
const
|
|
168
|
+
const result = await this.dataHub.makeRequest<GraphqlResponse<void>>({
|
|
153
169
|
method: 'POST',
|
|
154
170
|
route: '/graphql',
|
|
155
171
|
data,
|
|
156
172
|
});
|
|
157
173
|
|
|
158
|
-
return this.dataHub.subscribe(requestId);
|
|
174
|
+
return this.dataHub.subscribe((result.data[operationName] as GraphqlResponseDelete).requestId);
|
|
159
175
|
}
|
|
160
176
|
|
|
161
177
|
/**
|
|
@@ -178,4 +194,48 @@ export class Flows {
|
|
|
178
194
|
return this.deployer.deactivateFlow(source, flowAlias, deleteLambda);
|
|
179
195
|
}
|
|
180
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Add tags
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const flow = await flows.addTags(flowSource, tagIdsArr);
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
public async addTags(source: Flow, tagNames: string[]): Promise<Flow> {
|
|
204
|
+
const tags = await this.tags.getMultipleTagsByName(tagNames, true);
|
|
205
|
+
const tagIds = tags.map(tag => tag.id!);
|
|
206
|
+
|
|
207
|
+
const { newIds } = filterTagIds(source.tags, tagIds);
|
|
208
|
+
|
|
209
|
+
if (!newIds.length) {
|
|
210
|
+
throw Error('No tags to add.');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return this.saveFlow({
|
|
214
|
+
...source,
|
|
215
|
+
tags: addTagsIds(source.tags, newIds),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Remove tags
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const flow = await flows.removeTags(flowSource, tagIdsArr);
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
public async removeTags(source: Flow, tagNames: string[]): Promise<Flow> {
|
|
226
|
+
const tags = await this.tags.getMultipleTagsByName(tagNames);
|
|
227
|
+
const tagIds = tags.map(tag => tag.id!);
|
|
228
|
+
|
|
229
|
+
const { existingIds } = filterTagIds(source.tags, tagIds);
|
|
230
|
+
|
|
231
|
+
if (!existingIds.length) {
|
|
232
|
+
throw Error('No tags to remove.');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return this.saveFlow({
|
|
236
|
+
...source,
|
|
237
|
+
tags: removeTagIds(source.tags, existingIds),
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
181
241
|
}
|
package/src/types.ts
CHANGED