@or-sdk/bots 0.24.1 → 0.25.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/Bots.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,185 +61,137 @@ 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 __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
- };
60
64
  Object.defineProperty(exports, "__esModule", { value: true });
61
65
  exports.Bots = void 0;
62
- var data_hub_1 = require("@or-sdk/data-hub");
66
+ var base_1 = require("@or-sdk/base");
63
67
  var constants_1 = require("./constants");
64
- var tags_1 = require("@or-sdk/tags");
65
- var utils_1 = require("./utils");
66
- var Bots = (function () {
68
+ var Bots = (function (_super) {
69
+ __extends(Bots, _super);
67
70
  function Bots(params) {
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({
71
+ var token = params.token, discoveryUrl = params.discoveryUrl, accountId = params.accountId, dataHub2Url = params.dataHub2Url;
72
+ return _super.call(this, {
76
73
  token: token,
77
74
  discoveryUrl: discoveryUrl,
75
+ serviceKey: constants_1.SERVICE_KEY,
78
76
  accountId: accountId,
79
- dataHubUrl: dataHubUrl,
80
- });
77
+ serviceUrl: dataHub2Url,
78
+ }) || this;
81
79
  }
82
80
  Bots.prototype.init = function () {
83
81
  return __awaiter(this, void 0, void 0, function () {
84
82
  return __generator(this, function (_a) {
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
- }
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
+ })];
94
104
  });
95
105
  });
96
106
  };
97
107
  Bots.prototype.listBots = function (params) {
98
108
  if (params === void 0) { params = {}; }
99
109
  return __awaiter(this, void 0, void 0, function () {
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)];
110
+ return __generator(this, function (_a) {
111
+ return [2, this.getBots(params)];
113
112
  });
114
113
  });
115
114
  };
116
- Bots.prototype.getBot = function (id) {
115
+ Bots.prototype.getBotById = function (botId, projection) {
117
116
  return __awaiter(this, void 0, void 0, function () {
118
- var route, params;
119
117
  return __generator(this, function (_a) {
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
- }
118
+ return [2, this.callApiV2({
119
+ route: "/bots/".concat(botId),
120
+ params: {
121
+ projection: projection,
122
+ },
123
+ })];
134
124
  });
135
125
  });
136
126
  };
137
- Bots.prototype.saveBot = function (source) {
127
+ Bots.prototype.getBot = function (id) {
138
128
  return __awaiter(this, void 0, void 0, function () {
139
- var route, data;
140
129
  return __generator(this, function (_a) {
141
- switch (_a.label) {
142
- case 0:
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,
151
- })];
152
- case 1: return [2, _a.sent()];
153
- }
130
+ return [2, this.getBotById(id)];
154
131
  });
155
132
  });
156
133
  };
157
- Bots.prototype.deleteBot = function (botId) {
134
+ Bots.prototype.saveBot = function (bot) {
158
135
  return __awaiter(this, void 0, void 0, function () {
159
- var variables, operationName, data, result;
136
+ var id;
160
137
  return __generator(this, function (_a) {
161
138
  switch (_a.label) {
162
139
  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,
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',
183
147
  })];
184
148
  case 1:
185
- result = _a.sent();
186
- return [2, this.dataHub.subscribe(result.data[operationName].requestId)];
149
+ id = (_a.sent()).id;
150
+ return [2, __assign(__assign({}, bot), { id: id })];
187
151
  }
188
152
  });
189
153
  });
190
154
  };
191
- Bots.prototype.addTags = function (source, tagNames) {
155
+ Bots.prototype.deleteBot = function (bot, temporarily) {
156
+ if (temporarily === void 0) { temporarily = true; }
192
157
  return __awaiter(this, void 0, void 0, function () {
193
- var tags, tagIds, newIds;
194
158
  return __generator(this, function (_a) {
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
- }
159
+ return [2, this.callApiV2({
160
+ route: "/bots/".concat(bot.id),
161
+ data: {
162
+ temporarily: temporarily,
163
+ },
164
+ method: 'delete',
165
+ })];
206
166
  });
207
167
  });
208
168
  };
209
- Bots.prototype.removeTags = function (source, tagNames) {
169
+ Bots.getNewBot = function () {
210
170
  return __awaiter(this, void 0, void 0, function () {
211
- var tags, tagIds, existingIds;
212
171
  return __generator(this, function (_a) {
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
- }
172
+ return [2, {
173
+ data: {
174
+ label: '',
175
+ description: '',
176
+ longDescription: '',
177
+ iconUrl: '',
178
+ deploy: {},
179
+ },
180
+ }];
181
+ });
182
+ });
183
+ };
184
+ Bots.prototype.recoverBot = function (bot) {
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ return __generator(this, function (_a) {
187
+ return [2, this.callApiV2({
188
+ route: "/bots/".concat(bot.id),
189
+ method: 'patch',
190
+ })];
224
191
  });
225
192
  });
226
193
  };
227
194
  return Bots;
228
- }());
195
+ }(base_1.Base));
229
196
  exports.Bots = Bots;
230
197
  //# sourceMappingURL=Bots.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Bots.js","sourceR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,GAApB,UAAqB,GAAQ;;;;;;wBAC3B,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,IAAI,KAAK,CAAC;wBACV,WAAM,IAAI,CAAC,SAAS,CAAC;gCAClC,KAAK,EAAE,gBAAS,GAAG,CAAC,EAAE,CAAE;gCACxB,IAAI,EAAE;oCACJ,GAAG,KAAA;iCACJ;gCACD,MAAM,EAAE,MAAM;6BACf,CAAC,EAAA;;wBANM,EAAE,GAAK,CAAA,SAMb,CAAA,GANQ;wBAQV,iCACK,GAAG,KACN,EAAE,IAAA,KACF;;;;KACH;IAQY,wBAAS,GAAtB,UAAuB,GAAkB,EAAE,WAAkB;QAAlB,4BAAA,EAAA,kBAAkB;;;gBAC3D,WAAO,IAAI,CAAC,SAAS,CAAC;wBACpB,KAAK,EAAE,gBAAS,GAAG,CAAC,EAAE,CAAE;wBACxB,IAAI,EAAE;4BACJ,WAAW,aAAA;yBACZ;wBACD,MAAM,EAAE,QAAQ;qBACjB,CAAC,EAAC;;;KACJ;IAoDY,cAAS,GAAtB;;;gBACE,WAAO;wBACL,IAAI,EAAE;4BACJ,KAAK,EAAE,EAAE;4BACT,WAAW,EAAE,EAAE;4BACf,eAAe,EAAE,EAAE;4BACnB,OAAO,EAAE,EAAE;4BACX,MAAM,EAAE,EAAE;yBACX;qBACF,EAAC;;;KACH;IAQY,yBAAU,GAAvB,UAAwB,GAAkB;;;gBACxC,WAAO,IAAI,CAAC,SAAS,CAAC;wBACpB,KAAK,EAAE,gBAAS,GAAG,CAAC,EAAE,CAAE;wBACxB,MAAM,EAAE,OAAO;qBAChB,CAAC,EAAC;;;KACJ;IACH,WAAC;AAAD,CAAC,AAxMD,CAA0B,WAAI,GAwM7B;AAxMY,oBAAI"}
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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';
3
+ exports.SERVICE_KEY = void 0;
4
+ exports.SERVICE_KEY = 'datahub2';
6
5
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,UAAU,CAAC"}
package/dist/esm/Bots.js CHANGED
@@ -7,133 +7,103 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
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 {
10
+ import { Base } from '@or-sdk/base';
11
+ import { SERVICE_KEY } from './constants';
12
+ export class Bots extends Base {
26
13
  constructor(params) {
27
- const { token, discoveryUrl, accountId, dataHubUrl } = params;
28
- this.dataHub = new DataHub({
14
+ const { token, discoveryUrl, accountId, dataHub2Url } = params;
15
+ super({
29
16
  token,
30
17
  discoveryUrl,
18
+ serviceKey: SERVICE_KEY,
31
19
  accountId,
32
- dataHubUrl,
33
- });
34
- this.tags = new Tags({
35
- token,
36
- discoveryUrl,
37
- accountId,
38
- dataHubUrl,
20
+ serviceUrl: dataHub2Url,
39
21
  });
40
22
  }
41
23
  init() {
42
24
  return __awaiter(this, void 0, void 0, function* () {
43
- yield Promise.all([
44
- this.dataHub.init(),
45
- this.tags.init(),
46
- ]);
25
+ });
26
+ }
27
+ getBots({ query = {}, projection, includeDeleted = false, includeExisting = true, limit, offset } = {}) {
28
+ 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
+ });
47
42
  });
48
43
  }
49
44
  listBots(params = {}) {
50
45
  return __awaiter(this, void 0, void 0, function* () {
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,
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: {
57
54
  projection,
58
- }),
59
- variables,
60
- };
61
- return this.dataHub.getFullList('POST', '/graphql', data);
55
+ },
56
+ });
62
57
  });
63
58
  }
64
59
  getBot(id) {
65
60
  return __awaiter(this, void 0, void 0, function* () {
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
- });
61
+ return this.getBotById(id);
76
62
  });
77
63
  }
78
- saveBot(source) {
64
+ saveBot(bot) {
79
65
  return __awaiter(this, void 0, void 0, function* () {
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,
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',
88
73
  });
74
+ return Object.assign(Object.assign({}, bot), { id });
89
75
  });
90
76
  }
91
- deleteBot(botId) {
77
+ deleteBot(bot, temporarily = true) {
92
78
  return __awaiter(this, void 0, void 0, function* () {
93
- if (this.dataHub.isCrossAccount) {
94
- throw Error('Cross-account deleting is not implemented.');
95
- }
96
- const variables = {
97
- entity: ENTITY_NAME,
79
+ return this.callApiV2({
80
+ route: `/bots/${bot.id}`,
98
81
  data: {
99
- id: botId,
100
- subscribe: true,
82
+ temporarily,
101
83
  },
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,
84
+ method: 'delete',
113
85
  });
114
- return this.dataHub.subscribe(result.data[operationName].requestId);
115
86
  });
116
87
  }
117
- addTags(source, tagNames) {
88
+ static getNewBot() {
118
89
  return __awaiter(this, void 0, void 0, function* () {
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) }));
90
+ return {
91
+ data: {
92
+ label: '',
93
+ description: '',
94
+ longDescription: '',
95
+ iconUrl: '',
96
+ deploy: {},
97
+ },
98
+ };
126
99
  });
127
100
  }
128
- removeTags(source, tagNames) {
101
+ recoverBot(bot) {
129
102
  return __awaiter(this, void 0, void 0, function* () {
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) }));
103
+ return this.callApiV2({
104
+ route: `/bots/${bot.id}`,
105
+ method: 'patch',
106
+ });
137
107
  });
138
108
  }
139
109
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Bots.js","sourceRoot":"","sources":["../../src/Bots.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,OAAO,EAAyE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElI,OAAO,EACL,YAAY,EACZ,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,IAAI,EAAY,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASvC,MAAM,OAAO,IAAI;IAUf,YAAY,MAAkB;QAC5B,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;QAE9D,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC;YACzB,KAAK;YACL,YAAY;YACZ,SAAS;YACT,UAAU;SACX,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,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teInput!) {
2
- deleteTemporarily(entity: $entity, data: $data) {
3
- ... on AsyncRequest {
4
- requestId
5
- }
6
- }
7
- }`;
8
- export const ENTITY_NAME = 'BOT';
1
+ export const SERVICE_KEY = 'datahub2';
9
2
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
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
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC"}
@@ -1,16 +1,26 @@
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;
1
+ import { Base, List } from '@or-sdk/base';
2
+ import { Bot, BotsConfig, GetBotsParams, ListBotsParams } from './types';
3
+ export declare class Bots extends Base {
8
4
  constructor(params: BotsConfig);
9
5
  init(): Promise<void>;
6
+ getBots({ query, projection, includeDeleted, includeExisting, limit, offset }?: GetBotsParams): Promise<List<Bot>>;
10
7
  listBots(params?: ListBotsParams): Promise<List<Bot>>;
8
+ getBotById(botId: string, projection?: string[]): Promise<Bot>;
11
9
  getBot(id: string): Promise<Bot>;
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>;
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>;
16
26
  }
@@ -1,2 +1 @@
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";
1
+ export declare const SERVICE_KEY = "datahub2";
@@ -3,7 +3,7 @@ export declare type BotsConfig = {
3
3
  token: Token;
4
4
  discoveryUrl?: string;
5
5
  accountId?: string;
6
- dataHubUrl?: string;
6
+ dataHub2Url?: string;
7
7
  };
8
8
  export declare type Bot = {
9
9
  id?: string;
@@ -27,3 +27,13 @@ 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.1",
2
+ "version": "0.25.0-beta.427.0",
3
3
  "name": "@or-sdk/bots",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
@@ -24,9 +24,8 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@or-sdk/base": "^0.24.2",
28
- "@or-sdk/data-hub": "^0.23.8",
29
- "@or-sdk/tags": "^0.24.1"
30
- },
31
- "gitHead": "7467e3ef0fcf3df42472266f512506432b5f8395"
27
+ "@or-sdk/base": "^0.24.3-beta.427.0",
28
+ "@or-sdk/data-hub": "^0.23.9-beta.427.0",
29
+ "@or-sdk/tags": "^0.25.0-beta.427.0"
30
+ }
32
31
  }
package/src/Bots.ts CHANGED
@@ -1,12 +1,8 @@
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';
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
+
10
6
 
11
7
  /**
12
8
  * OneReach Bots service client
@@ -15,9 +11,8 @@ import { getListQuery } from './utils';
15
11
  * $ npm i @or-sdk/bots
16
12
  * ```
17
13
  */
18
- export class Bots implements Taggable<Bot> {
19
- private readonly dataHub: DataHub;
20
- private readonly tags: Tags;
14
+ export class Bots extends Base {
15
+ // private readonly tags: Tags;
21
16
 
22
17
  /**
23
18
  * ```typescript
@@ -26,27 +21,46 @@ export class Bots implements Taggable<Bot> {
26
21
  * ```
27
22
  */
28
23
  constructor(params: BotsConfig) {
29
- const { token, discoveryUrl, accountId, dataHubUrl } = params;
30
-
31
- this.dataHub = new DataHub({
24
+ const { token, discoveryUrl, accountId, dataHub2Url } = params;
25
+ super({
32
26
  token,
33
27
  discoveryUrl,
28
+ serviceKey: SERVICE_KEY,
34
29
  accountId,
35
- dataHubUrl,
36
- });
37
- this.tags = new Tags({
38
- token,
39
- discoveryUrl,
40
- accountId,
41
- dataHubUrl,
30
+ serviceUrl: dataHub2Url,
42
31
  });
32
+
33
+ // this.tags = new Tags({
34
+ // token,
35
+ // discoveryUrl,
36
+ // accountId,
37
+ // serviceKey: SERVICE_KEY,
38
+ // dataHub2Url,
39
+ // });
43
40
  }
44
41
 
45
42
  async init() {
46
- await Promise.all([
47
- this.dataHub.init(),
48
- this.tags.init(),
49
- ]);
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
+ });
50
64
  }
51
65
 
52
66
  /**
@@ -56,33 +70,23 @@ export class Bots implements Taggable<Bot> {
56
70
  * ```
57
71
  */
58
72
  public async listBots(params: ListBotsParams = {}): Promise<List<Bot>> {
59
- const { projection = [], ...varPrams } = params;
60
- const variables = {
61
- entity: ENTITY_NAME,
62
- params: {
63
- queryParams: {},
64
- includeDeleted: false,
65
- includeExisting: true,
66
- limit: 30,
67
-
68
- // overrides
69
- ...varPrams,
70
- },
71
- ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : { sandbox: false },
72
- };
73
+ return this.getBots(params);
74
+ }
73
75
 
74
- const data = {
75
- operationName: this.dataHub.getOperationName(OperationNames.LIST),
76
- query: getListQuery({
77
- crossAccount: this.dataHub.isCrossAccount,
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}`,
85
+ params: {
78
86
  projection,
79
- }),
80
- variables,
81
- };
82
-
83
- return this.dataHub.getFullList<Bot>('POST', '/graphql', data);
87
+ },
88
+ });
84
89
  }
85
-
86
90
  /**
87
91
  * Get bot
88
92
  * ```typescript
@@ -90,18 +94,7 @@ export class Bots implements Taggable<Bot> {
90
94
  * ```
91
95
  */
92
96
  public async getBot(id: string): Promise<Bot> {
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
- });
97
+ return this.getBotById(id);
105
98
  }
106
99
 
107
100
  /**
@@ -112,18 +105,20 @@ export class Bots implements Taggable<Bot> {
112
105
  * const savedBot = await bots.saveBot(botSource);
113
106
  * ```
114
107
  */
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'}`;
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
+ });
117
117
 
118
- const data = {
119
- bot: source,
118
+ return {
119
+ ...bot,
120
+ id,
120
121
  };
121
-
122
- return await this.dataHub.makeRequest<Bot>({
123
- method: 'POST',
124
- route,
125
- data,
126
- });
127
122
  }
128
123
 
129
124
  /**
@@ -132,34 +127,14 @@ export class Bots implements Taggable<Bot> {
132
127
  * await bots.deleteBot('bot-id');
133
128
  * ```
134
129
  */
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,
130
+ public async deleteBot(bot: {id: string;}, temporarily = true): Promise<null> {
131
+ return this.callApiV2({
132
+ route: `/bots/${bot.id}`,
142
133
  data: {
143
- id: botId,
144
- subscribe: true,
134
+ temporarily,
145
135
  },
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,
136
+ method: 'delete',
160
137
  });
161
-
162
- return this.dataHub.subscribe((result.data[operationName] as GraphqlResponseDelete).requestId);
163
138
  }
164
139
 
165
140
  /**
@@ -168,21 +143,21 @@ export class Bots implements Taggable<Bot> {
168
143
  * const bot = await bots.addTags(botSource, tagIdsArr);
169
144
  * ```
170
145
  */
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!);
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!);
174
149
 
175
- const { newIds } = filterTagIds(source.tags, tagIds);
150
+ // const { newIds } = filterTagIds(source.tags, tagIds);
176
151
 
177
- if (!newIds.length) {
178
- throw Error('No tags to add.');
179
- }
152
+ // if (!newIds.length) {
153
+ // throw Error('No tags to add.');
154
+ // }
180
155
 
181
- return this.saveBot({
182
- ...source,
183
- tags: addTagsIds(source.tags, newIds),
184
- });
185
- }
156
+ // return this.saveBot({
157
+ // ...source,
158
+ // tags: addTagsIds(source.tags, newIds),
159
+ // });
160
+ // }
186
161
 
187
162
  /**
188
163
  * Remove tags
@@ -190,20 +165,50 @@ export class Bots implements Taggable<Bot> {
190
165
  * const bot = await bots.removeTags(botSource, tagIdsArr);
191
166
  * ```
192
167
  */
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!);
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!);
196
171
 
197
- const { existingIds } = filterTagIds(source.tags, tagIds);
172
+ // const { existingIds } = filterTagIds(source.tags, tagIds);
198
173
 
199
- if (!existingIds.length) {
200
- throw Error('No tags to remove.');
201
- }
174
+ // if (!existingIds.length) {
175
+ // throw Error('No tags to remove.');
176
+ // }
202
177
 
203
- return this.saveBot({
204
- ...source,
205
- tags: removeTagIds(source.tags, existingIds),
206
- });
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
+ };
207
200
  }
208
201
 
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',
212
+ });
213
+ }
209
214
  }
package/src/constants.ts CHANGED
@@ -1,10 +1,2 @@
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';
1
+ export const SERVICE_KEY = 'datahub2';
10
2
 
package/src/types.ts CHANGED
@@ -19,7 +19,7 @@ export type BotsConfig = {
19
19
  /**
20
20
  * Url of OneReach DataHub api
21
21
  */
22
- dataHubUrl?: string;
22
+ dataHub2Url?: string;
23
23
  };
24
24
 
25
25
  export type Bot = {
@@ -45,3 +45,12 @@ 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
+ };