@or-sdk/bots 0.24.0-410.0 → 0.24.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,15 @@
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.24.0](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.23.7...@or-sdk/bots@0.24.0) (2022-06-14)
7
+
8
+
9
+ ### Features
10
+
11
+ * **deployments:** Deployments sdk ([41219bd](https://gitlab.com/onereach/platform/or-sdk-next/commit/41219bdf58956fc07aea1d0d5093e8cfddabc00d))
12
+
13
+
14
+
6
15
  ### [0.23.7](https://gitlab.com/onereach/platform/or-sdk-next/compare/@or-sdk/bots@0.23.6...@or-sdk/bots@0.23.7) (2022-06-10)
7
16
 
8
17
 
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,139 +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 _this = this;
72
- var token = params.token, discoveryUrl = params.discoveryUrl, accountId = params.accountId, dataHub2Url = params.dataHub2Url;
73
- _this = _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({
74
76
  token: token,
75
77
  discoveryUrl: discoveryUrl,
76
- serviceKey: constants_1.SERVICE_KEY,
77
78
  accountId: accountId,
78
- serviceUrl: dataHub2Url,
79
- }) || this;
80
- return _this;
79
+ dataHubUrl: dataHubUrl,
80
+ });
81
81
  }
82
82
  Bots.prototype.init = function () {
83
83
  return __awaiter(this, void 0, void 0, function () {
84
84
  return __generator(this, function (_a) {
85
- return [2];
86
- });
87
- });
88
- };
89
- Bots.prototype.getBots = function (_a) {
90
- 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;
91
- return __awaiter(this, void 0, void 0, function () {
92
- return __generator(this, function (_f) {
93
- if (includeDeleted && !includeExisting)
94
- query.isDeleted = true;
95
- if (!includeDeleted && includeExisting)
96
- query.isDeleted = false;
97
- return [2, this.callApiV2({
98
- route: '/bots',
99
- params: {
100
- query: query,
101
- projection: projection,
102
- limit: limit,
103
- offset: offset,
104
- },
105
- })];
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
+ }
106
94
  });
107
95
  });
108
96
  };
109
97
  Bots.prototype.listBots = function (params) {
110
98
  if (params === void 0) { params = {}; }
111
99
  return __awaiter(this, void 0, void 0, function () {
112
- return __generator(this, function (_a) {
113
- return [2, this.getBots(params)];
114
- });
115
- });
116
- };
117
- Bots.prototype.getBotById = function (botId, projection) {
118
- return __awaiter(this, void 0, void 0, function () {
119
- return __generator(this, function (_a) {
120
- return [2, this.callApiV2({
121
- route: "/bots/".concat(botId),
122
- params: {
123
- projection: projection,
124
- },
125
- })];
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)];
126
113
  });
127
114
  });
128
115
  };
129
116
  Bots.prototype.getBot = function (id) {
130
117
  return __awaiter(this, void 0, void 0, function () {
118
+ var route, params;
131
119
  return __generator(this, function (_a) {
132
- 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
+ }
133
134
  });
134
135
  });
135
136
  };
136
- Bots.prototype.saveBot = function (bot) {
137
+ Bots.prototype.saveBot = function (source) {
137
138
  return __awaiter(this, void 0, void 0, function () {
138
- var id;
139
+ var route, data;
139
140
  return __generator(this, function (_a) {
140
141
  switch (_a.label) {
141
142
  case 0:
142
- bot.id = bot.id || 'new';
143
- return [4, this.callApiV2({
144
- route: "/bots/".concat(bot.id),
145
- data: {
146
- bot: bot,
147
- },
148
- 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,
149
151
  })];
150
- case 1:
151
- id = (_a.sent()).id;
152
- return [2, __assign(__assign({}, bot), { id: id })];
152
+ case 1: return [2, _a.sent()];
153
153
  }
154
154
  });
155
155
  });
156
156
  };
157
- Bots.prototype.deleteBot = function (bot, temporarily) {
158
- if (temporarily === void 0) { temporarily = true; }
157
+ Bots.prototype.deleteBot = function (botId) {
159
158
  return __awaiter(this, void 0, void 0, function () {
159
+ var variables, operationName, data, result;
160
160
  return __generator(this, function (_a) {
161
- return [2, this.callApiV2({
162
- route: "/bots/".concat(bot.id),
163
- data: {
164
- temporarily: temporarily,
165
- },
166
- method: 'delete',
167
- })];
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
+ }
168
188
  });
169
189
  });
170
190
  };
171
- Bots.getNewBot = function () {
191
+ Bots.prototype.addTags = function (source, tagNames) {
172
192
  return __awaiter(this, void 0, void 0, function () {
193
+ var tags, tagIds, newIds;
173
194
  return __generator(this, function (_a) {
174
- return [2, {
175
- data: {
176
- label: '',
177
- description: '',
178
- longDescription: '',
179
- iconUrl: '',
180
- deploy: {},
181
- },
182
- }];
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
+ }
183
206
  });
184
207
  });
185
208
  };
186
- Bots.prototype.recoverBot = function (bot) {
209
+ Bots.prototype.removeTags = function (source, tagNames) {
187
210
  return __awaiter(this, void 0, void 0, function () {
211
+ var tags, tagIds, existingIds;
188
212
  return __generator(this, function (_a) {
189
- return [2, this.callApiV2({
190
- route: "/bots/".concat(bot.id),
191
- method: 'patch',
192
- })];
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
+ }
193
224
  });
194
225
  });
195
226
  };
196
227
  return Bots;
197
- }(base_1.Base));
228
+ }());
198
229
  exports.Bots = Bots;
199
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;QAA9B,iBAiBC;QAhBS,IAAA,KAAK,GAA2C,MAAM,MAAjD,EAAE,YAAY,GAA6B,MAAM,aAAnC,EAAE,SAAS,GAAkB,MAAM,UAAxB,EAAE,WAAW,GAAK,MAAM,YAAX,CAAY;QAC/D,QAAA,kBAAM;YACJ,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,UAAU,EAAE,uBAAW;YACvB,SAAS,WAAA;YACT,UAAU,EAAE,WAAW;SACxB,CAAC,SAAC;;IASL,CAAC;IAEK,mBAAI,GAAV;;;;;;KAEC;IAQY,sBAAO,GAApB,UAAqB,EAA6G;YAA7G,qBAA2G,EAAE,KAAA,EAA3G,aAAU,EAAV,KAAK,mBAAG,EAAE,KAAA,EAAE,UAAU,gBAAA,EAAE,sBAAsB,EAAtB,cAAc,mBAAG,KAAK,KAAA,EAAE,uBAAsB,EAAtB,eA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AC;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,AA/LD,IA+LC;AA/LY,oBAAI"}
@@ -1,5 +1,6 @@
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 = void 0;
4
+ exports.QUERY_DELETE = "mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {\n deleteTemporarily(entity: $entity, data: $data) {\n ... on AsyncRequest {\n requestId\n }\n }\n}";
5
+ exports.ENTITY_NAME = 'BOT';
5
6
  //# 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,QAAA,YAAY,GAAG,yLAM1B,CAAC;AAEU,QAAA,WAAW,GAAG,KAAK,CAAC"}
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
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Bots.js","sourceRoot":"","sources":["../../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AI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;YAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAG,CAAC,CAAC;YAExC,MAAM,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAE1D,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;gBACvB,MAAM,KAAK,CAAC,oBAAoB,CAAC,CAAC;aACnC;YAED,OAAO,IAAI,CAAC,OAAO,iCACd,MAAM,KACT,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,IAC5C,CAAC;QACL,CAAC;KAAA;CAEF"}
@@ -1,2 +1,9 @@
1
- export const SERVICE_KEY = 'datahub2';
1
+ export const QUERY_DELETE = `mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {
2
+ deleteTemporarily(entity: $entity, data: $data) {
3
+ ... on AsyncRequest {
4
+ requestId
5
+ }
6
+ }
7
+ }`;
8
+ export const ENTITY_NAME = 'BOT';
2
9
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;EAM1B,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC"}
@@ -1,26 +1,16 @@
1
- import { Base, List } from '@or-sdk/base';
2
- import { Bot, BotsConfig, GetBotsParams, ListBotsParams } from './types';
3
- export declare class Bots extends Base {
1
+ import { List } from '@or-sdk/base';
2
+ import { GraphqlResponseCheckExecution } from '@or-sdk/data-hub';
3
+ import { BotsConfig, Bot, ListBotsParams } from './types';
4
+ import { Taggable } from '@or-sdk/tags';
5
+ export declare class Bots implements Taggable<Bot> {
6
+ private readonly dataHub;
7
+ private readonly tags;
4
8
  constructor(params: BotsConfig);
5
9
  init(): Promise<void>;
6
- getBots({ query, projection, includeDeleted, includeExisting, limit, offset }?: GetBotsParams): Promise<List<Bot>>;
7
10
  listBots(params?: ListBotsParams): Promise<List<Bot>>;
8
- getBotById(botId: string, projection?: string[]): Promise<Bot>;
9
11
  getBot(id: string): Promise<Bot>;
10
- saveBot(bot: Bot): Promise<Bot>;
11
- deleteBot(bot: {
12
- id: string;
13
- }, temporarily?: boolean): Promise<null>;
14
- static getNewBot(): Promise<{
15
- data: {
16
- label: string;
17
- description: string;
18
- longDescription: string;
19
- iconUrl: string;
20
- deploy: {};
21
- };
22
- }>;
23
- recoverBot(bot: {
24
- id: string;
25
- }): Promise<null>;
12
+ saveBot(source: Bot): Promise<Bot>;
13
+ deleteBot(botId: string): Promise<GraphqlResponseCheckExecution>;
14
+ addTags(source: Bot, tagNames: string[]): Promise<Bot>;
15
+ removeTags(source: Bot, tagNames: string[]): Promise<Bot>;
26
16
  }
@@ -1 +1,2 @@
1
- export declare const SERVICE_KEY = "datahub2";
1
+ export declare const QUERY_DELETE = "mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {\n deleteTemporarily(entity: $entity, data: $data) {\n ... on AsyncRequest {\n requestId\n }\n }\n}";
2
+ export declare const ENTITY_NAME = "BOT";
@@ -3,7 +3,7 @@ export declare type BotsConfig = {
3
3
  token: Token;
4
4
  discoveryUrl?: string;
5
5
  accountId?: string;
6
- dataHub2Url?: string;
6
+ dataHubUrl?: string;
7
7
  };
8
8
  export declare type Bot = {
9
9
  id?: string;
@@ -27,13 +27,3 @@ export declare type ListBotsParams = {
27
27
  includeExisting?: boolean;
28
28
  projection?: string[];
29
29
  };
30
- export declare type GetBotsParams = {
31
- includeDeleted?: boolean;
32
- includeExisting?: boolean;
33
- projection?: string[];
34
- query?: {
35
- [key: string]: any;
36
- };
37
- limit?: number;
38
- offset?: number;
39
- };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.24.0-410.0",
2
+ "version": "0.24.0",
3
3
  "name": "@or-sdk/bots",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
@@ -23,8 +23,9 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@or-sdk/base": "^0.24.2-410.0",
27
- "@or-sdk/data-hub": "^0.23.8-410.0",
28
- "@or-sdk/tags": "^0.24.0-410.0"
29
- }
26
+ "@or-sdk/base": "^0.24.1",
27
+ "@or-sdk/data-hub": "^0.23.7",
28
+ "@or-sdk/tags": "^0.24.0"
29
+ },
30
+ "gitHead": "cb96ea9aaf7a72dd4bde29b1d58ef47b40d3052c"
30
31
  }
package/src/Bots.ts CHANGED
@@ -1,8 +1,12 @@
1
- import { Base, List } from '@or-sdk/base';
2
- // import { addTagsIds, filterTagIds, removeTagIds, Tags } from '@or-sdk/tags';
3
- import { SERVICE_KEY } from './constants';
4
- import { Bot, BotsConfig, GetBotsParams, ListBotsParams } from './types';
5
-
1
+ import { List } from '@or-sdk/base';
2
+ import { DataHub, GraphqlResponse, GraphqlResponseCheckExecution, GraphqlResponseDelete, OperationNames } from '@or-sdk/data-hub';
3
+ import { BotsConfig, Bot, ListBotsParams } from './types';
4
+ import {
5
+ QUERY_DELETE,
6
+ ENTITY_NAME,
7
+ } from './constants';
8
+ import { Tags, Taggable, filterTagIds, addTagsIds, removeTagIds } from '@or-sdk/tags';
9
+ import { getListQuery } from './utils';
6
10
 
7
11
  /**
8
12
  * OneReach Bots service client
@@ -11,8 +15,9 @@ import { Bot, BotsConfig, GetBotsParams, ListBotsParams } from './types';
11
15
  * $ npm i @or-sdk/bots
12
16
  * ```
13
17
  */
14
- export class Bots extends Base {
15
- // private readonly tags: Tags;
18
+ export class Bots implements Taggable<Bot> {
19
+ private readonly dataHub: DataHub;
20
+ private readonly tags: Tags;
16
21
 
17
22
  /**
18
23
  * ```typescript
@@ -21,46 +26,27 @@ export class Bots extends Base {
21
26
  * ```
22
27
  */
23
28
  constructor(params: BotsConfig) {
24
- const { token, discoveryUrl, accountId, dataHub2Url } = params;
25
- super({
29
+ const { token, discoveryUrl, accountId, dataHubUrl } = params;
30
+
31
+ this.dataHub = new DataHub({
26
32
  token,
27
33
  discoveryUrl,
28
- serviceKey: SERVICE_KEY,
29
34
  accountId,
30
- serviceUrl: dataHub2Url,
35
+ dataHubUrl,
36
+ });
37
+ this.tags = new Tags({
38
+ token,
39
+ discoveryUrl,
40
+ accountId,
41
+ dataHubUrl,
31
42
  });
32
-
33
- // this.tags = new Tags({
34
- // token,
35
- // discoveryUrl,
36
- // accountId,
37
- // serviceKey: SERVICE_KEY,
38
- // dataHub2Url,
39
- // });
40
43
  }
41
44
 
42
45
  async init() {
43
- // await this.tags.init();
44
- }
45
- /**
46
- * Get bots
47
- * ```typescript
48
- * const botList = await bots.getBots();
49
- * ```
50
- */
51
-
52
- public async getBots({ query = {}, projection, includeDeleted = false, includeExisting = true, limit, offset }: GetBotsParams = {}): Promise<List<Bot>> {
53
- if (includeDeleted && !includeExisting) query.isDeleted = true;
54
- if (!includeDeleted && includeExisting) query.isDeleted = false;
55
- return this.callApiV2({
56
- route: '/bots',
57
- params: {
58
- query,
59
- projection,
60
- limit,
61
- offset,
62
- },
63
- });
46
+ await Promise.all([
47
+ this.dataHub.init(),
48
+ this.tags.init(),
49
+ ]);
64
50
  }
65
51
 
66
52
  /**
@@ -70,23 +56,33 @@ export class Bots extends Base {
70
56
  * ```
71
57
  */
72
58
  public async listBots(params: ListBotsParams = {}): Promise<List<Bot>> {
73
- return this.getBots(params);
74
- }
75
-
76
- /**
77
- * Get bot by id
78
- * ```typescript
79
- * const bot = await bots.getBotById('bot-id');
80
- * ```
81
- */
82
- public async getBotById(botId: string, projection?: string[]): Promise<Bot> {
83
- return this.callApiV2({
84
- route: `/bots/${botId}`,
59
+ const { projection = [], ...varPrams } = params;
60
+ const variables = {
61
+ entity: ENTITY_NAME,
85
62
  params: {
86
- projection,
63
+ queryParams: {},
64
+ includeDeleted: false,
65
+ includeExisting: true,
66
+ limit: 30,
67
+
68
+ // overrides
69
+ ...varPrams,
87
70
  },
88
- });
71
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : { sandbox: false },
72
+ };
73
+
74
+ const data = {
75
+ operationName: this.dataHub.getOperationName(OperationNames.LIST),
76
+ query: getListQuery({
77
+ crossAccount: this.dataHub.isCrossAccount,
78
+ projection,
79
+ }),
80
+ variables,
81
+ };
82
+
83
+ return this.dataHub.getFullList<Bot>('POST', '/graphql', data);
89
84
  }
85
+
90
86
  /**
91
87
  * Get bot
92
88
  * ```typescript
@@ -94,31 +90,40 @@ export class Bots extends Base {
94
90
  * ```
95
91
  */
96
92
  public async getBot(id: string): Promise<Bot> {
97
- return this.getBotById(id);
93
+ const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/bot/${id}`;
94
+
95
+ const params = {
96
+ includeDeleted: false,
97
+ includeExisting: true,
98
+ };
99
+
100
+ return await this.dataHub.makeRequest<Bot>({
101
+ method: 'GET',
102
+ route,
103
+ params,
104
+ });
98
105
  }
99
106
 
100
107
  /**
101
108
  * Save bot
102
109
  *
103
- * If source contains existing id - existing bot be updated
110
+ * If source contains existing id - existing bot will be updated
104
111
  * ```typescript
105
112
  * const savedBot = await bots.saveBot(botSource);
106
113
  * ```
107
114
  */
108
- public async saveBot(bot: Bot): Promise<Bot> {
109
- bot.id = bot.id || 'new';
110
- const { id } = await this.callApiV2({
111
- route: `/bots/${bot.id}`,
112
- data: {
113
- bot,
114
- },
115
- method: 'post',
116
- });
115
+ public async saveBot(source: Bot): Promise<Bot> {
116
+ const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/bot/${source.id ? source.id : 'new'}`;
117
117
 
118
- return {
119
- ...bot,
120
- id,
118
+ const data = {
119
+ bot: source,
121
120
  };
121
+
122
+ return await this.dataHub.makeRequest<Bot>({
123
+ method: 'POST',
124
+ route,
125
+ data,
126
+ });
122
127
  }
123
128
 
124
129
  /**
@@ -127,14 +132,34 @@ export class Bots extends Base {
127
132
  * await bots.deleteBot('bot-id');
128
133
  * ```
129
134
  */
130
- public async deleteBot(bot: {id: string;}, temporarily = true): Promise<null> {
131
- return this.callApiV2({
132
- route: `/bots/${bot.id}`,
135
+ public async deleteBot(botId: string): Promise<GraphqlResponseCheckExecution> {
136
+ if (this.dataHub.isCrossAccount) {
137
+ throw Error('Cross-account deleting is not implemented.');
138
+ }
139
+
140
+ const variables = {
141
+ entity: ENTITY_NAME,
133
142
  data: {
134
- temporarily,
143
+ id: botId,
144
+ subscribe: true,
135
145
  },
136
- method: 'delete',
146
+ };
147
+
148
+ const operationName = this.dataHub.getOperationName(OperationNames.DELETE_TEMPORARILY);
149
+
150
+ const data = {
151
+ operationName,
152
+ query: QUERY_DELETE,
153
+ variables,
154
+ };
155
+
156
+ const result = await this.dataHub.makeRequest<GraphqlResponse<void>>({
157
+ method: 'POST',
158
+ route: '/graphql',
159
+ data,
137
160
  });
161
+
162
+ return this.dataHub.subscribe((result.data[operationName] as GraphqlResponseDelete).requestId);
138
163
  }
139
164
 
140
165
  /**
@@ -143,21 +168,21 @@ export class Bots extends Base {
143
168
  * const bot = await bots.addTags(botSource, tagIdsArr);
144
169
  * ```
145
170
  */
146
- // public async addTags(source: Bot, tagNames: string[]): Promise<Bot> {
147
- // const tags = await this.tags.getMultipleTagsByName(tagNames, true);
148
- // const tagIds = tags.map(tag => tag.id!);
171
+ public async addTags(source: Bot, tagNames: string[]): Promise<Bot> {
172
+ const tags = await this.tags.getMultipleTagsByName(tagNames, true);
173
+ const tagIds = tags.map(tag => tag.id!);
149
174
 
150
- // const { newIds } = filterTagIds(source.tags, tagIds);
175
+ const { newIds } = filterTagIds(source.tags, tagIds);
151
176
 
152
- // if (!newIds.length) {
153
- // throw Error('No tags to add.');
154
- // }
177
+ if (!newIds.length) {
178
+ throw Error('No tags to add.');
179
+ }
155
180
 
156
- // return this.saveBot({
157
- // ...source,
158
- // tags: addTagsIds(source.tags, newIds),
159
- // });
160
- // }
181
+ return this.saveBot({
182
+ ...source,
183
+ tags: addTagsIds(source.tags, newIds),
184
+ });
185
+ }
161
186
 
162
187
  /**
163
188
  * Remove tags
@@ -165,50 +190,20 @@ export class Bots extends Base {
165
190
  * const bot = await bots.removeTags(botSource, tagIdsArr);
166
191
  * ```
167
192
  */
168
- // public async removeTags(source: Bot, tagNames: string[]): Promise<Bot> {
169
- // const tags = await this.tags.getMultipleTagsByName(tagNames);
170
- // const tagIds = tags.map(tag => tag.id!);
171
-
172
- // const { existingIds } = filterTagIds(source.tags, tagIds);
193
+ public async removeTags(source: Bot, tagNames: string[]): Promise<Bot> {
194
+ const tags = await this.tags.getMultipleTagsByName(tagNames);
195
+ const tagIds = tags.map(tag => tag.id!);
173
196
 
174
- // if (!existingIds.length) {
175
- // throw Error('No tags to remove.');
176
- // }
197
+ const { existingIds } = filterTagIds(source.tags, tagIds);
177
198
 
178
- // return this.saveBot({
179
- // ...source,
180
- // tags: removeTagIds(source.tags, existingIds),
181
- // });
182
- // }
183
-
184
- /**
185
- * Get new bot
186
- * ```typescript
187
- * const bot = await bots.getNewBot();
188
- * ```
189
- */
190
- static async getNewBot() {
191
- return {
192
- data: {
193
- label: '',
194
- description: '',
195
- longDescription: '',
196
- iconUrl: '',
197
- deploy: {},
198
- },
199
- };
200
- }
199
+ if (!existingIds.length) {
200
+ throw Error('No tags to remove.');
201
+ }
201
202
 
202
- /**
203
- * Recover deleted bot
204
- * ```typescript
205
- * const bot = await bots.recoverBot({id});
206
- * ```
207
- */
208
- public async recoverBot(bot: {id: string;}): Promise<null> {
209
- return this.callApiV2({
210
- route: `/bots/${bot.id}`,
211
- method: 'patch',
203
+ return this.saveBot({
204
+ ...source,
205
+ tags: removeTagIds(source.tags, existingIds),
212
206
  });
213
207
  }
208
+
214
209
  }
package/src/constants.ts CHANGED
@@ -1,2 +1,10 @@
1
- export const SERVICE_KEY = 'datahub2';
1
+ export const QUERY_DELETE = `mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {
2
+ deleteTemporarily(entity: $entity, data: $data) {
3
+ ... on AsyncRequest {
4
+ requestId
5
+ }
6
+ }
7
+ }`;
8
+
9
+ export const ENTITY_NAME = 'BOT';
2
10
 
package/src/types.ts CHANGED
@@ -19,7 +19,7 @@ export type BotsConfig = {
19
19
  /**
20
20
  * Url of OneReach DataHub api
21
21
  */
22
- dataHub2Url?: string;
22
+ dataHubUrl?: string;
23
23
  };
24
24
 
25
25
  export type Bot = {
@@ -45,12 +45,3 @@ export type ListBotsParams = {
45
45
  includeExisting?: boolean;
46
46
  projection?: string[];
47
47
  };
48
-
49
- export type GetBotsParams = {
50
- includeDeleted?: boolean;
51
- includeExisting?: boolean;
52
- projection?: string[];
53
- query?: {[key: string]: any;};
54
- limit?: number;
55
- offset?: number;
56
- };