@or-sdk/bots 0.25.0-beta.427.0 → 0.25.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 CHANGED
@@ -3,6 +3,84 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.25.0](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.24.9...@or-sdk/bots@0.25.0) (2022-07-27)
7
+
8
+
9
+ ### Features
10
+
11
+ * export related service-keys ([6959668](https://gitlab.com/onereach/platform/or-sdk-next/commit/69596684c513b6d078dd3fde7ca6885b852dfdfd))
12
+
13
+
14
+
15
+ ### [0.24.9](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.24.8...@or-sdk/bots@0.24.9) (2022-07-25)
16
+
17
+ **Note:** Version bump only for package @or-sdk/bots
18
+
19
+
20
+
21
+
22
+
23
+ ### [0.24.8](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.24.7...@or-sdk/bots@0.24.8) (2022-07-21)
24
+
25
+ **Note:** Version bump only for package @or-sdk/bots
26
+
27
+
28
+
29
+
30
+
31
+ ### [0.24.7](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.24.6...@or-sdk/bots@0.24.7) (2022-07-20)
32
+
33
+
34
+ ### Bug Fixes
35
+
36
+ * Fix Lockfiles ([bcb74df](https://gitlab.com/onereach/platform/or-sdk-next/commit/bcb74dfa54bed0e46ca3834a235b1068927a68d1))
37
+
38
+
39
+
40
+ # Change Log
41
+
42
+ ### [0.24.6](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.24.5...@or-sdk/bots@0.24.6) (2022-07-20)
43
+
44
+
45
+ ### Bug Fixes
46
+
47
+ * Fix lockfiles ([91e3384](https://gitlab.com/onereach/platform/or-sdk-next/commit/91e3384a2774698efe36e9fa955633670cfdb03a))
48
+
49
+
50
+
51
+ ### [0.24.5](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.24.4...@or-sdk/bots@0.24.5) (2022-07-20)
52
+
53
+ **Note:** Version bump only for package @or-sdk/bots
54
+
55
+
56
+
57
+
58
+
59
+ ### [0.24.4](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.24.3...@or-sdk/bots@0.24.4) (2022-06-27)
60
+
61
+ **Note:** Version bump only for package @or-sdk/bots
62
+
63
+
64
+
65
+
66
+
67
+ ### [0.24.3](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.24.2...@or-sdk/bots@0.24.3) (2022-06-20)
68
+
69
+
70
+ ### Bug Fixes
71
+
72
+ * Fix watch, better build ([b3e8528](https://gitlab.com/onereach/platform/or-sdk-next/commit/b3e85287dae5b53b892fcefc48348094dac8a0cc))
73
+
74
+
75
+
76
+ ### [0.24.2](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.24.1...@or-sdk/bots@0.24.2) (2022-06-20)
77
+
78
+ **Note:** Version bump only for package @or-sdk/bots
79
+
80
+
81
+
82
+
83
+
6
84
  ### [0.24.1](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.24.0...@or-sdk/bots@0.24.1) (2022-06-17)
7
85
 
8
86
 
package/dist/cjs/Bots.js CHANGED
@@ -1,19 +1,4 @@
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
- })();
17
2
  var __assign = (this && this.__assign) || function () {
18
3
  __assign = Object.assign || function(t) {
19
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -61,137 +46,185 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
61
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
47
  }
63
48
  };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
64
60
  Object.defineProperty(exports, "__esModule", { value: true });
65
61
  exports.Bots = void 0;
66
- var base_1 = require("@or-sdk/base");
62
+ var data_hub_1 = require("@or-sdk/data-hub");
67
63
  var constants_1 = require("./constants");
68
- var Bots = (function (_super) {
69
- __extends(Bots, _super);
64
+ var tags_1 = require("@or-sdk/tags");
65
+ var utils_1 = require("./utils");
66
+ var Bots = (function () {
70
67
  function Bots(params) {
71
- var token = params.token, discoveryUrl = params.discoveryUrl, accountId = params.accountId, dataHub2Url = params.dataHub2Url;
72
- return _super.call(this, {
68
+ var token = params.token, discoveryUrl = params.discoveryUrl, accountId = params.accountId, dataHubUrl = params.dataHubUrl;
69
+ this.dataHub = new data_hub_1.DataHub({
70
+ token: token,
71
+ discoveryUrl: discoveryUrl,
72
+ accountId: accountId,
73
+ dataHubUrl: dataHubUrl,
74
+ });
75
+ this.tags = new tags_1.Tags({
73
76
  token: token,
74
77
  discoveryUrl: discoveryUrl,
75
- serviceKey: constants_1.SERVICE_KEY,
76
78
  accountId: accountId,
77
- serviceUrl: dataHub2Url,
78
- }) || this;
79
+ dataHubUrl: dataHubUrl,
80
+ });
79
81
  }
80
82
  Bots.prototype.init = function () {
81
83
  return __awaiter(this, void 0, void 0, function () {
82
84
  return __generator(this, function (_a) {
83
- return [2];
84
- });
85
- });
86
- };
87
- Bots.prototype.getBots = function (_a) {
88
- 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, limit = _b.limit, offset = _b.offset;
89
- return __awaiter(this, void 0, void 0, function () {
90
- return __generator(this, function (_f) {
91
- if (includeDeleted && !includeExisting)
92
- query.isDeleted = true;
93
- if (!includeDeleted && includeExisting)
94
- query.isDeleted = false;
95
- return [2, this.callApiV2({
96
- route: '/bots',
97
- params: {
98
- query: query,
99
- projection: projection,
100
- limit: limit,
101
- offset: offset,
102
- },
103
- })];
85
+ switch (_a.label) {
86
+ case 0: return [4, Promise.all([
87
+ this.dataHub.init(),
88
+ this.tags.init(),
89
+ ])];
90
+ case 1:
91
+ _a.sent();
92
+ return [2];
93
+ }
104
94
  });
105
95
  });
106
96
  };
107
97
  Bots.prototype.listBots = function (params) {
108
98
  if (params === void 0) { params = {}; }
109
99
  return __awaiter(this, void 0, void 0, function () {
110
- return __generator(this, function (_a) {
111
- return [2, this.getBots(params)];
112
- });
113
- });
114
- };
115
- Bots.prototype.getBotById = function (botId, projection) {
116
- return __awaiter(this, void 0, void 0, function () {
117
- return __generator(this, function (_a) {
118
- return [2, this.callApiV2({
119
- route: "/bots/".concat(botId),
120
- params: {
121
- projection: projection,
122
- },
123
- })];
100
+ var _a, projection, varPrams, variables, data;
101
+ return __generator(this, function (_b) {
102
+ _a = params.projection, projection = _a === void 0 ? [] : _a, varPrams = __rest(params, ["projection"]);
103
+ variables = __assign({ entity: constants_1.ENTITY_NAME, params: __assign({ queryParams: {}, includeDeleted: false, includeExisting: true, limit: 30 }, varPrams) }, this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : { sandbox: false });
104
+ data = {
105
+ operationName: this.dataHub.getOperationName(data_hub_1.OperationNames.LIST),
106
+ query: (0, utils_1.getListQuery)({
107
+ crossAccount: this.dataHub.isCrossAccount,
108
+ projection: projection,
109
+ }),
110
+ variables: variables,
111
+ };
112
+ return [2, this.dataHub.getFullList('POST', '/graphql', data)];
124
113
  });
125
114
  });
126
115
  };
127
116
  Bots.prototype.getBot = function (id) {
128
117
  return __awaiter(this, void 0, void 0, function () {
118
+ var route, params;
129
119
  return __generator(this, function (_a) {
130
- return [2, this.getBotById(id)];
120
+ switch (_a.label) {
121
+ case 0:
122
+ route = "/v2/".concat(this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current', "/bot/").concat(id);
123
+ params = {
124
+ includeDeleted: false,
125
+ includeExisting: true,
126
+ };
127
+ return [4, this.dataHub.makeRequest({
128
+ method: 'GET',
129
+ route: route,
130
+ params: params,
131
+ })];
132
+ case 1: return [2, _a.sent()];
133
+ }
131
134
  });
132
135
  });
133
136
  };
134
- Bots.prototype.saveBot = function (bot) {
137
+ Bots.prototype.saveBot = function (source) {
135
138
  return __awaiter(this, void 0, void 0, function () {
136
- var id;
139
+ var route, data;
137
140
  return __generator(this, function (_a) {
138
141
  switch (_a.label) {
139
142
  case 0:
140
- bot.id = bot.id || 'new';
141
- return [4, this.callApiV2({
142
- route: "/bots/".concat(bot.id),
143
- data: {
144
- bot: bot,
145
- },
146
- method: 'post',
143
+ route = "/v2/".concat(this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current', "/bot/").concat(source.id ? source.id : 'new');
144
+ data = {
145
+ bot: source,
146
+ };
147
+ return [4, this.dataHub.makeRequest({
148
+ method: 'POST',
149
+ route: route,
150
+ data: data,
147
151
  })];
148
- case 1:
149
- id = (_a.sent()).id;
150
- return [2, __assign(__assign({}, bot), { id: id })];
152
+ case 1: return [2, _a.sent()];
151
153
  }
152
154
  });
153
155
  });
154
156
  };
155
- Bots.prototype.deleteBot = function (bot, temporarily) {
156
- if (temporarily === void 0) { temporarily = true; }
157
+ Bots.prototype.deleteBot = function (botId) {
157
158
  return __awaiter(this, void 0, void 0, function () {
159
+ var variables, operationName, data, result;
158
160
  return __generator(this, function (_a) {
159
- return [2, this.callApiV2({
160
- route: "/bots/".concat(bot.id),
161
- data: {
162
- temporarily: temporarily,
163
- },
164
- method: 'delete',
165
- })];
161
+ switch (_a.label) {
162
+ case 0:
163
+ if (this.dataHub.isCrossAccount) {
164
+ throw Error('Cross-account deleting is not implemented.');
165
+ }
166
+ variables = {
167
+ entity: constants_1.ENTITY_NAME,
168
+ data: {
169
+ id: botId,
170
+ subscribe: true,
171
+ },
172
+ };
173
+ operationName = this.dataHub.getOperationName(data_hub_1.OperationNames.DELETE_TEMPORARILY);
174
+ data = {
175
+ operationName: operationName,
176
+ query: constants_1.QUERY_DELETE,
177
+ variables: variables,
178
+ };
179
+ return [4, this.dataHub.makeRequest({
180
+ method: 'POST',
181
+ route: '/graphql',
182
+ data: data,
183
+ })];
184
+ case 1:
185
+ result = _a.sent();
186
+ return [2, this.dataHub.subscribe(result.data[operationName].requestId)];
187
+ }
166
188
  });
167
189
  });
168
190
  };
169
- Bots.getNewBot = function () {
191
+ Bots.prototype.addTags = function (source, tagNames) {
170
192
  return __awaiter(this, void 0, void 0, function () {
193
+ var tags, tagIds, newIds;
171
194
  return __generator(this, function (_a) {
172
- return [2, {
173
- data: {
174
- label: '',
175
- description: '',
176
- longDescription: '',
177
- iconUrl: '',
178
- deploy: {},
179
- },
180
- }];
195
+ switch (_a.label) {
196
+ case 0: return [4, this.tags.getMultipleTagsByName(tagNames, true)];
197
+ case 1:
198
+ tags = _a.sent();
199
+ tagIds = tags.map(function (tag) { return tag.id; });
200
+ newIds = (0, tags_1.filterTagIds)(source.tags, tagIds).newIds;
201
+ if (!newIds.length) {
202
+ throw Error('No tags to add.');
203
+ }
204
+ return [2, this.saveBot(__assign(__assign({}, source), { tags: (0, tags_1.addTagsIds)(source.tags, newIds) }))];
205
+ }
181
206
  });
182
207
  });
183
208
  };
184
- Bots.prototype.recoverBot = function (bot) {
209
+ Bots.prototype.removeTags = function (source, tagNames) {
185
210
  return __awaiter(this, void 0, void 0, function () {
211
+ var tags, tagIds, existingIds;
186
212
  return __generator(this, function (_a) {
187
- return [2, this.callApiV2({
188
- route: "/bots/".concat(bot.id),
189
- method: 'patch',
190
- })];
213
+ switch (_a.label) {
214
+ case 0: return [4, this.tags.getMultipleTagsByName(tagNames)];
215
+ case 1:
216
+ tags = _a.sent();
217
+ tagIds = tags.map(function (tag) { return tag.id; });
218
+ existingIds = (0, tags_1.filterTagIds)(source.tags, tagIds).existingIds;
219
+ if (!existingIds.length) {
220
+ throw Error('No tags to remove.');
221
+ }
222
+ return [2, this.saveBot(__assign(__assign({}, source), { tags: (0, tags_1.removeTagIds)(source.tags, existingIds) }))];
223
+ }
191
224
  });
192
225
  });
193
226
  };
194
227
  return Bots;
195
- }(base_1.Base));
228
+ }());
196
229
  exports.Bots = Bots;
197
230
  //# sourceMappingURL=Bots.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Bots.js","sourceRoot":"","sources":["../../src/Bots.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA0C;AAE1C,yCAA0C;AAW1C;IAA0B,wBAAI;IAS5B,cAAY,MAAkB;QACpB,IAAA,KAAK,GAA2C,MAAM,MAAjD,EAAE,YAAY,GAA6B,MAAM,aAAnC,EAAE,SAAS,GAAkB,MAAM,UAAxB,EAAE,WAAW,GAAK,MAAM,YAAX,CAAY;eAC/D,kBAAM;YACJ,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,UAAU,EAAE,uBAAW;YACvB,SAAS,WAAA;YACT,UAAU,EAAE,WAAW;SACxB,CAAC;IASJ,CAAC;IAEK,mBAAI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AkB;;;;;4BACxC,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,OAAO,uBACd,MAAM,KACT,IAAI,EAAE,IAAA,mBAAY,EAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,IAC5C,EAAC;;;;KACJ;IAEH,WAAC;AAAD,CAAC,AAhMD,IAgMC;AAhMY,oBAAI"}
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SERVICE_KEY = void 0;
4
- exports.SERVICE_KEY = 'datahub2';
3
+ exports.ENTITY_NAME = exports.QUERY_DELETE = exports.DATA_HUB_SERVICE_KEY = void 0;
4
+ var data_hub_1 = require("@or-sdk/data-hub");
5
+ Object.defineProperty(exports, "DATA_HUB_SERVICE_KEY", { enumerable: true, get: function () { return data_hub_1.DATA_HUB_SERVICE_KEY; } });
6
+ exports.QUERY_DELETE = "mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {\n deleteTemporarily(entity: $entity, data: $data) {\n ... on AsyncRequest {\n requestId\n }\n }\n}";
7
+ exports.ENTITY_NAME = 'BOT';
5
8
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,UAAU,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA,6CAAwD;AAA/C,gHAAA,oBAAoB,OAAA;AAEhB,QAAA,YAAY,GAAG,yLAM1B,CAAC;AAEU,QAAA,WAAW,GAAG,KAAK,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -18,4 +18,5 @@ exports.Bots = void 0;
18
18
  var Bots_1 = require("./Bots");
19
19
  Object.defineProperty(exports, "Bots", { enumerable: true, get: function () { return Bots_1.Bots; } });
20
20
  __exportStar(require("./types"), exports);
21
+ __exportStar(require("./constants"), exports);
21
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,0CAAwB;AACxB,8CAA4B"}
package/dist/esm/Bots.js CHANGED
@@ -7,103 +7,133 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Base } from '@or-sdk/base';
11
- import { SERVICE_KEY } from './constants';
12
- export class Bots extends Base {
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { DataHub, OperationNames } from '@or-sdk/data-hub';
22
+ import { QUERY_DELETE, ENTITY_NAME, } from './constants';
23
+ import { Tags, filterTagIds, addTagsIds, removeTagIds } from '@or-sdk/tags';
24
+ import { getListQuery } from './utils';
25
+ export class Bots {
13
26
  constructor(params) {
14
- const { token, discoveryUrl, accountId, dataHub2Url } = params;
15
- super({
27
+ const { token, discoveryUrl, accountId, dataHubUrl } = params;
28
+ this.dataHub = new DataHub({
16
29
  token,
17
30
  discoveryUrl,
18
- serviceKey: SERVICE_KEY,
19
31
  accountId,
20
- serviceUrl: dataHub2Url,
32
+ dataHubUrl,
21
33
  });
22
- }
23
- init() {
24
- return __awaiter(this, void 0, void 0, function* () {
34
+ this.tags = new Tags({
35
+ token,
36
+ discoveryUrl,
37
+ accountId,
38
+ dataHubUrl,
25
39
  });
26
40
  }
27
- getBots({ query = {}, projection, includeDeleted = false, includeExisting = true, limit, offset } = {}) {
41
+ init() {
28
42
  return __awaiter(this, void 0, void 0, function* () {
29
- if (includeDeleted && !includeExisting)
30
- query.isDeleted = true;
31
- if (!includeDeleted && includeExisting)
32
- query.isDeleted = false;
33
- return this.callApiV2({
34
- route: '/bots',
35
- params: {
36
- query,
37
- projection,
38
- limit,
39
- offset,
40
- },
41
- });
43
+ yield Promise.all([
44
+ this.dataHub.init(),
45
+ this.tags.init(),
46
+ ]);
42
47
  });
43
48
  }
44
49
  listBots(params = {}) {
45
50
  return __awaiter(this, void 0, void 0, function* () {
46
- return this.getBots(params);
47
- });
48
- }
49
- getBotById(botId, projection) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- return this.callApiV2({
52
- route: `/bots/${botId}`,
53
- params: {
51
+ const { projection = [] } = params, varPrams = __rest(params, ["projection"]);
52
+ const variables = Object.assign({ entity: ENTITY_NAME, params: Object.assign({ queryParams: {}, includeDeleted: false, includeExisting: true, limit: 30 }, varPrams) }, this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : { sandbox: false });
53
+ const data = {
54
+ operationName: this.dataHub.getOperationName(OperationNames.LIST),
55
+ query: getListQuery({
56
+ crossAccount: this.dataHub.isCrossAccount,
54
57
  projection,
55
- },
56
- });
58
+ }),
59
+ variables,
60
+ };
61
+ return this.dataHub.getFullList('POST', '/graphql', data);
57
62
  });
58
63
  }
59
64
  getBot(id) {
60
65
  return __awaiter(this, void 0, void 0, function* () {
61
- return this.getBotById(id);
66
+ const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/bot/${id}`;
67
+ const params = {
68
+ includeDeleted: false,
69
+ includeExisting: true,
70
+ };
71
+ return yield this.dataHub.makeRequest({
72
+ method: 'GET',
73
+ route,
74
+ params,
75
+ });
62
76
  });
63
77
  }
64
- saveBot(bot) {
78
+ saveBot(source) {
65
79
  return __awaiter(this, void 0, void 0, function* () {
66
- bot.id = bot.id || 'new';
67
- const { id } = yield this.callApiV2({
68
- route: `/bots/${bot.id}`,
69
- data: {
70
- bot,
71
- },
72
- method: 'post',
80
+ const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/bot/${source.id ? source.id : 'new'}`;
81
+ const data = {
82
+ bot: source,
83
+ };
84
+ return yield this.dataHub.makeRequest({
85
+ method: 'POST',
86
+ route,
87
+ data,
73
88
  });
74
- return Object.assign(Object.assign({}, bot), { id });
75
89
  });
76
90
  }
77
- deleteBot(bot, temporarily = true) {
91
+ deleteBot(botId) {
78
92
  return __awaiter(this, void 0, void 0, function* () {
79
- return this.callApiV2({
80
- route: `/bots/${bot.id}`,
93
+ if (this.dataHub.isCrossAccount) {
94
+ throw Error('Cross-account deleting is not implemented.');
95
+ }
96
+ const variables = {
97
+ entity: ENTITY_NAME,
81
98
  data: {
82
- temporarily,
99
+ id: botId,
100
+ subscribe: true,
83
101
  },
84
- method: 'delete',
102
+ };
103
+ const operationName = this.dataHub.getOperationName(OperationNames.DELETE_TEMPORARILY);
104
+ const data = {
105
+ operationName,
106
+ query: QUERY_DELETE,
107
+ variables,
108
+ };
109
+ const result = yield this.dataHub.makeRequest({
110
+ method: 'POST',
111
+ route: '/graphql',
112
+ data,
85
113
  });
114
+ return this.dataHub.subscribe(result.data[operationName].requestId);
86
115
  });
87
116
  }
88
- static getNewBot() {
117
+ addTags(source, tagNames) {
89
118
  return __awaiter(this, void 0, void 0, function* () {
90
- return {
91
- data: {
92
- label: '',
93
- description: '',
94
- longDescription: '',
95
- iconUrl: '',
96
- deploy: {},
97
- },
98
- };
119
+ const tags = yield this.tags.getMultipleTagsByName(tagNames, true);
120
+ const tagIds = tags.map(tag => tag.id);
121
+ const { newIds } = filterTagIds(source.tags, tagIds);
122
+ if (!newIds.length) {
123
+ throw Error('No tags to add.');
124
+ }
125
+ return this.saveBot(Object.assign(Object.assign({}, source), { tags: addTagsIds(source.tags, newIds) }));
99
126
  });
100
127
  }
101
- recoverBot(bot) {
128
+ removeTags(source, tagNames) {
102
129
  return __awaiter(this, void 0, void 0, function* () {
103
- return this.callApiV2({
104
- route: `/bots/${bot.id}`,
105
- method: 'patch',
106
- });
130
+ const tags = yield this.tags.getMultipleTagsByName(tagNames);
131
+ const tagIds = tags.map(tag => tag.id);
132
+ const { existingIds } = filterTagIds(source.tags, tagIds);
133
+ if (!existingIds.length) {
134
+ throw Error('No tags to remove.');
135
+ }
136
+ return this.saveBot(Object.assign(Object.assign({}, source), { tags: removeTagIds(source.tags, existingIds) }));
107
137
  });
108
138
  }
109
139
  }