@or-sdk/bots 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/Bots.js +73 -16
- package/dist/cjs/Bots.js.map +1 -1
- package/dist/cjs/constants.js +2 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/esm/Bots.js +48 -16
- package/dist/esm/Bots.js.map +1 -1
- package/dist/esm/constants.js +22 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/types/Bots.d.ts +5 -1
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/types.d.ts +2 -0
- package/package.json +5 -4
- package/src/Bots.ts +79 -14
- package/src/constants.ts +23 -0
- package/src/types.ts +5 -0
package/dist/cjs/Bots.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) {
|
|
@@ -39,19 +50,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
50
|
exports.Bots = void 0;
|
|
40
51
|
var data_hub_1 = require("@or-sdk/data-hub");
|
|
41
52
|
var constants_1 = require("./constants");
|
|
53
|
+
var tags_1 = require("@or-sdk/tags");
|
|
42
54
|
var Bots = (function () {
|
|
43
55
|
function Bots(params) {
|
|
44
|
-
var token = params.token, discoveryUrl = params.discoveryUrl;
|
|
56
|
+
var token = params.token, discoveryUrl = params.discoveryUrl, accountId = params.accountId;
|
|
45
57
|
this.dataHub = new data_hub_1.DataHub({
|
|
46
58
|
token: token,
|
|
47
59
|
discoveryUrl: discoveryUrl,
|
|
60
|
+
accountId: accountId,
|
|
61
|
+
});
|
|
62
|
+
this.tags = new tags_1.Tags({
|
|
63
|
+
token: token,
|
|
64
|
+
discoveryUrl: discoveryUrl,
|
|
65
|
+
accountId: accountId,
|
|
48
66
|
});
|
|
49
67
|
}
|
|
50
68
|
Bots.prototype.init = function () {
|
|
51
69
|
return __awaiter(this, void 0, void 0, function () {
|
|
52
70
|
return __generator(this, function (_a) {
|
|
53
71
|
switch (_a.label) {
|
|
54
|
-
case 0: return [4,
|
|
72
|
+
case 0: return [4, Promise.all([
|
|
73
|
+
this.dataHub.init(),
|
|
74
|
+
this.tags.init(),
|
|
75
|
+
])];
|
|
55
76
|
case 1:
|
|
56
77
|
_a.sent();
|
|
57
78
|
return [2];
|
|
@@ -63,19 +84,15 @@ var Bots = (function () {
|
|
|
63
84
|
return __awaiter(this, void 0, void 0, function () {
|
|
64
85
|
var variables, data;
|
|
65
86
|
return __generator(this, function (_a) {
|
|
66
|
-
variables = {
|
|
67
|
-
entity: constants_1.ENTITY_NAME,
|
|
68
|
-
params: {
|
|
87
|
+
variables = __assign({ entity: constants_1.ENTITY_NAME, params: {
|
|
69
88
|
queryParams: {},
|
|
70
89
|
includeDeleted: false,
|
|
71
90
|
includeExisting: true,
|
|
72
91
|
limit: 30,
|
|
73
|
-
},
|
|
74
|
-
sandbox: false,
|
|
75
|
-
};
|
|
92
|
+
} }, this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : { sandbox: false });
|
|
76
93
|
data = {
|
|
77
|
-
operationName: 'list',
|
|
78
|
-
query: constants_1.QUERY_LIST,
|
|
94
|
+
operationName: this.dataHub.getOperationName('list'),
|
|
95
|
+
query: this.dataHub.isCrossAccount ? constants_1.QUERY_LIST_CROSSACCOUNT : constants_1.QUERY_LIST,
|
|
79
96
|
variables: variables,
|
|
80
97
|
};
|
|
81
98
|
return [2, this.dataHub.getFullList('POST', '/graphql', data)];
|
|
@@ -88,7 +105,7 @@ var Bots = (function () {
|
|
|
88
105
|
return __generator(this, function (_a) {
|
|
89
106
|
switch (_a.label) {
|
|
90
107
|
case 0:
|
|
91
|
-
route = "/v2/".concat(this.dataHub.currentAccountId, "/bot/").concat(id);
|
|
108
|
+
route = "/v2/".concat(this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current', "/bot/").concat(id);
|
|
92
109
|
params = {
|
|
93
110
|
includeDeleted: false,
|
|
94
111
|
includeExisting: true,
|
|
@@ -109,7 +126,7 @@ var Bots = (function () {
|
|
|
109
126
|
return __generator(this, function (_a) {
|
|
110
127
|
switch (_a.label) {
|
|
111
128
|
case 0:
|
|
112
|
-
route = "/v2/".concat(this.dataHub.currentAccountId, "/bot/").concat(source.id ? source.id : 'new');
|
|
129
|
+
route = "/v2/".concat(this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current', "/bot/").concat(source.id ? source.id : 'new');
|
|
113
130
|
data = {
|
|
114
131
|
bot: source,
|
|
115
132
|
};
|
|
@@ -125,10 +142,13 @@ var Bots = (function () {
|
|
|
125
142
|
};
|
|
126
143
|
Bots.prototype.deleteBot = function (botId) {
|
|
127
144
|
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
var variables, data,
|
|
145
|
+
var variables, operationName, data, result;
|
|
129
146
|
return __generator(this, function (_a) {
|
|
130
147
|
switch (_a.label) {
|
|
131
148
|
case 0:
|
|
149
|
+
if (this.dataHub.isCrossAccount) {
|
|
150
|
+
throw Error('Cross-account deleting is not implemented.');
|
|
151
|
+
}
|
|
132
152
|
variables = {
|
|
133
153
|
entity: constants_1.ENTITY_NAME,
|
|
134
154
|
data: {
|
|
@@ -136,8 +156,9 @@ var Bots = (function () {
|
|
|
136
156
|
subscribe: true,
|
|
137
157
|
},
|
|
138
158
|
};
|
|
159
|
+
operationName = this.dataHub.getOperationName('deleteTemporarily');
|
|
139
160
|
data = {
|
|
140
|
-
operationName:
|
|
161
|
+
operationName: operationName,
|
|
141
162
|
query: constants_1.QUERY_DELETE,
|
|
142
163
|
variables: variables,
|
|
143
164
|
};
|
|
@@ -147,8 +168,44 @@ var Bots = (function () {
|
|
|
147
168
|
data: data,
|
|
148
169
|
})];
|
|
149
170
|
case 1:
|
|
150
|
-
|
|
151
|
-
return [2, this.dataHub.subscribe(requestId)];
|
|
171
|
+
result = _a.sent();
|
|
172
|
+
return [2, this.dataHub.subscribe(result.data[operationName].requestId)];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
Bots.prototype.addTags = function (source, tagNames) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
+
var tags, tagIds, newIds;
|
|
180
|
+
return __generator(this, function (_a) {
|
|
181
|
+
switch (_a.label) {
|
|
182
|
+
case 0: return [4, this.tags.getMultipleTagsByName(tagNames, true)];
|
|
183
|
+
case 1:
|
|
184
|
+
tags = _a.sent();
|
|
185
|
+
tagIds = tags.map(function (tag) { return tag.id; });
|
|
186
|
+
newIds = (0, tags_1.filterTagIds)(source.tags, tagIds).newIds;
|
|
187
|
+
if (!newIds.length) {
|
|
188
|
+
throw Error('No tags to add.');
|
|
189
|
+
}
|
|
190
|
+
return [2, this.saveBot(__assign(__assign({}, source), { tags: (0, tags_1.addTagsIds)(source.tags, newIds) }))];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
Bots.prototype.removeTags = function (source, tagNames) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
+
var tags, tagIds, existingIds;
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
switch (_a.label) {
|
|
200
|
+
case 0: return [4, this.tags.getMultipleTagsByName(tagNames)];
|
|
201
|
+
case 1:
|
|
202
|
+
tags = _a.sent();
|
|
203
|
+
tagIds = tags.map(function (tag) { return tag.id; });
|
|
204
|
+
existingIds = (0, tags_1.filterTagIds)(source.tags, tagIds).existingIds;
|
|
205
|
+
if (!existingIds.length) {
|
|
206
|
+
throw Error('No tags to remove.');
|
|
207
|
+
}
|
|
208
|
+
return [2, this.saveBot(__assign(__assign({}, source), { tags: (0, tags_1.removeTagIds)(source.tags, existingIds) }))];
|
|
152
209
|
}
|
|
153
210
|
});
|
|
154
211
|
});
|
package/dist/cjs/Bots.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bots.js","sourceRoot":"","sources":["../../src/Bots.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Bots.js","sourceRoot":"","sources":["../../src/Bots.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6CAAkH;AAElH,yCAKqB;AACrB,qCAAsF;AAStF;IAUE,cAAY,MAAkB;QACpB,IAAA,KAAK,GAA8B,MAAM,MAApC,EAAE,YAAY,GAAgB,MAAM,aAAtB,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,IAAI,GAAG,IAAI,WAAI,CAAC;YACnB,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,SAAS,WAAA;SACV,CAAC,CAAC;IACL,CAAC;IAEK,mBAAI,GAAV;;;;4BACE,WAAM,OAAO,CAAC,GAAG,CAAC;4BAChB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;4BACnB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;yBACjB,CAAC,EAAA;;wBAHF,SAGE,CAAC;;;;;KACJ;IAQY,uBAAQ,GAArB;;;;gBACQ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ERY_DELETE = exports.QUERY_LIST = void 0;
|
|
3
|
+
exports.ENTITY_NAME = exports.QUERY_DELETE = exports.QUERY_LIST_CROSSACCOUNT = exports.QUERY_LIST = void 0;
|
|
4
4
|
exports.QUERY_LIST = "query list($entity: EntityType!, $params: ListInput!, $sandbox: Boolean) {\n list(entity: $entity, params: $params, sandbox: $sandbox) {\n records {\n ... on Bot {\n id\n data {\n label\n color\n description\n iconUrl\n password\n deploy {\n logsTTL\n }\n }\n tags\n dateModified\n }\n }\n last\n }\n}";
|
|
5
|
+
exports.QUERY_LIST_CROSSACCOUNT = "query listCrossAccount($entity: EntityType!, $params: ListInput!, $accountId: String!) {\n listCrossAccount(entity: $entity, params: $params, accountId: $accountId) {\n records {\n ... on Bot {\n id\n data {\n label\n color\n description\n iconUrl\n password\n deploy {\n logsTTL\n }\n }\n tags\n dateModified\n }\n }\n last\n }\n}";
|
|
5
6
|
exports.QUERY_DELETE = "mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {\n deleteTemporarily(entity: $entity, data: $data) {\n ... on AsyncRequest {\n requestId\n }\n }\n}";
|
|
6
7
|
exports.ENTITY_NAME = 'BOT';
|
|
7
8
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,ibAqBxB,CAAC;AAEU,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,UAAU,GAAG,ibAqBxB,CAAC;AAEU,QAAA,uBAAuB,GAAG,+cAqBrC,CAAC;AAEU,QAAA,YAAY,GAAG,yLAM1B,CAAC;AAEU,QAAA,WAAW,GAAG,KAAK,CAAC"}
|
package/dist/esm/Bots.js
CHANGED
|
@@ -8,35 +8,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { DataHub } from '@or-sdk/data-hub';
|
|
11
|
-
import { QUERY_LIST, QUERY_DELETE, ENTITY_NAME } from './constants';
|
|
11
|
+
import { QUERY_LIST, QUERY_DELETE, ENTITY_NAME, QUERY_LIST_CROSSACCOUNT, } from './constants';
|
|
12
|
+
import { Tags, filterTagIds, addTagsIds, removeTagIds } from '@or-sdk/tags';
|
|
12
13
|
export class Bots {
|
|
13
14
|
constructor(params) {
|
|
14
|
-
const { token, discoveryUrl } = params;
|
|
15
|
+
const { token, discoveryUrl, accountId } = params;
|
|
15
16
|
this.dataHub = new DataHub({
|
|
16
17
|
token,
|
|
17
18
|
discoveryUrl,
|
|
19
|
+
accountId,
|
|
20
|
+
});
|
|
21
|
+
this.tags = new Tags({
|
|
22
|
+
token,
|
|
23
|
+
discoveryUrl,
|
|
24
|
+
accountId,
|
|
18
25
|
});
|
|
19
26
|
}
|
|
20
27
|
init() {
|
|
21
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
yield
|
|
29
|
+
yield Promise.all([
|
|
30
|
+
this.dataHub.init(),
|
|
31
|
+
this.tags.init(),
|
|
32
|
+
]);
|
|
23
33
|
});
|
|
24
34
|
}
|
|
25
35
|
listBots() {
|
|
26
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const variables = {
|
|
28
|
-
entity: ENTITY_NAME,
|
|
29
|
-
params: {
|
|
37
|
+
const variables = Object.assign({ entity: ENTITY_NAME, params: {
|
|
30
38
|
queryParams: {},
|
|
31
39
|
includeDeleted: false,
|
|
32
40
|
includeExisting: true,
|
|
33
41
|
limit: 30,
|
|
34
|
-
},
|
|
35
|
-
sandbox: false,
|
|
36
|
-
};
|
|
42
|
+
} }, this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : { sandbox: false });
|
|
37
43
|
const data = {
|
|
38
|
-
operationName: 'list',
|
|
39
|
-
query: QUERY_LIST,
|
|
44
|
+
operationName: this.dataHub.getOperationName('list'),
|
|
45
|
+
query: this.dataHub.isCrossAccount ? QUERY_LIST_CROSSACCOUNT : QUERY_LIST,
|
|
40
46
|
variables,
|
|
41
47
|
};
|
|
42
48
|
return this.dataHub.getFullList('POST', '/graphql', data);
|
|
@@ -44,7 +50,7 @@ export class Bots {
|
|
|
44
50
|
}
|
|
45
51
|
getBot(id) {
|
|
46
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const route = `/v2/${this.dataHub.currentAccountId}/bot/${id}`;
|
|
53
|
+
const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/bot/${id}`;
|
|
48
54
|
const params = {
|
|
49
55
|
includeDeleted: false,
|
|
50
56
|
includeExisting: true,
|
|
@@ -58,7 +64,7 @@ export class Bots {
|
|
|
58
64
|
}
|
|
59
65
|
saveBot(source) {
|
|
60
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
const route = `/v2/${this.dataHub.currentAccountId}/bot/${source.id ? source.id : 'new'}`;
|
|
67
|
+
const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/bot/${source.id ? source.id : 'new'}`;
|
|
62
68
|
const data = {
|
|
63
69
|
bot: source,
|
|
64
70
|
};
|
|
@@ -71,6 +77,9 @@ export class Bots {
|
|
|
71
77
|
}
|
|
72
78
|
deleteBot(botId) {
|
|
73
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
if (this.dataHub.isCrossAccount) {
|
|
81
|
+
throw Error('Cross-account deleting is not implemented.');
|
|
82
|
+
}
|
|
74
83
|
const variables = {
|
|
75
84
|
entity: ENTITY_NAME,
|
|
76
85
|
data: {
|
|
@@ -78,17 +87,40 @@ export class Bots {
|
|
|
78
87
|
subscribe: true,
|
|
79
88
|
},
|
|
80
89
|
};
|
|
90
|
+
const operationName = this.dataHub.getOperationName('deleteTemporarily');
|
|
81
91
|
const data = {
|
|
82
|
-
operationName
|
|
92
|
+
operationName,
|
|
83
93
|
query: QUERY_DELETE,
|
|
84
94
|
variables,
|
|
85
95
|
};
|
|
86
|
-
const
|
|
96
|
+
const result = yield this.dataHub.makeRequest({
|
|
87
97
|
method: 'POST',
|
|
88
98
|
route: '/graphql',
|
|
89
99
|
data,
|
|
90
100
|
});
|
|
91
|
-
return this.dataHub.subscribe(requestId);
|
|
101
|
+
return this.dataHub.subscribe(result.data[operationName].requestId);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
addTags(source, tagNames) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const tags = yield this.tags.getMultipleTagsByName(tagNames, true);
|
|
107
|
+
const tagIds = tags.map(tag => tag.id);
|
|
108
|
+
const { newIds } = filterTagIds(source.tags, tagIds);
|
|
109
|
+
if (!newIds.length) {
|
|
110
|
+
throw Error('No tags to add.');
|
|
111
|
+
}
|
|
112
|
+
return this.saveBot(Object.assign(Object.assign({}, source), { tags: addTagsIds(source.tags, newIds) }));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
removeTags(source, tagNames) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const tags = yield this.tags.getMultipleTagsByName(tagNames);
|
|
118
|
+
const tagIds = tags.map(tag => tag.id);
|
|
119
|
+
const { existingIds } = filterTagIds(source.tags, tagIds);
|
|
120
|
+
if (!existingIds.length) {
|
|
121
|
+
throw Error('No tags to remove.');
|
|
122
|
+
}
|
|
123
|
+
return this.saveBot(Object.assign(Object.assign({}, source), { tags: removeTagIds(source.tags, existingIds) }));
|
|
92
124
|
});
|
|
93
125
|
}
|
|
94
126
|
}
|
package/dist/esm/Bots.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bots.js","sourceRoot":"","sources":["../../src/Bots.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAA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C,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"}
|
package/dist/esm/constants.js
CHANGED
|
@@ -20,6 +20,28 @@ export const QUERY_LIST = `query list($entity: EntityType!, $params: ListInput!,
|
|
|
20
20
|
last
|
|
21
21
|
}
|
|
22
22
|
}`;
|
|
23
|
+
export const QUERY_LIST_CROSSACCOUNT = `query listCrossAccount($entity: EntityType!, $params: ListInput!, $accountId: String!) {
|
|
24
|
+
listCrossAccount(entity: $entity, params: $params, accountId: $accountId) {
|
|
25
|
+
records {
|
|
26
|
+
... on Bot {
|
|
27
|
+
id
|
|
28
|
+
data {
|
|
29
|
+
label
|
|
30
|
+
color
|
|
31
|
+
description
|
|
32
|
+
iconUrl
|
|
33
|
+
password
|
|
34
|
+
deploy {
|
|
35
|
+
logsTTL
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
tags
|
|
39
|
+
dateModified
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
last
|
|
43
|
+
}
|
|
44
|
+
}`;
|
|
23
45
|
export const QUERY_DELETE = `mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {
|
|
24
46
|
deleteTemporarily(entity: $entity, data: $data) {
|
|
25
47
|
... on AsyncRequest {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;EAqBxB,CAAC;AAEH,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,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;EAqBxB,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;EAqBrC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;EAM1B,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC"}
|
package/dist/types/Bots.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { List } from '@or-sdk/base';
|
|
2
2
|
import { GraphqlResponseCheckExecution } from '@or-sdk/data-hub';
|
|
3
3
|
import { BotsConfig, Bot } from './types';
|
|
4
|
-
|
|
4
|
+
import { Taggable } from '@or-sdk/tags';
|
|
5
|
+
export declare class Bots implements Taggable<Bot> {
|
|
5
6
|
private readonly dataHub;
|
|
7
|
+
private readonly tags;
|
|
6
8
|
constructor(params: BotsConfig);
|
|
7
9
|
init(): Promise<void>;
|
|
8
10
|
listBots(): Promise<List<Bot>>;
|
|
9
11
|
getBot(id: string): Promise<Bot>;
|
|
10
12
|
saveBot(source: Bot): Promise<Bot>;
|
|
11
13
|
deleteBot(botId: string): Promise<GraphqlResponseCheckExecution>;
|
|
14
|
+
addTags(source: Bot, tagNames: string[]): Promise<Bot>;
|
|
15
|
+
removeTags(source: Bot, tagNames: string[]): Promise<Bot>;
|
|
12
16
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare const QUERY_LIST = "query list($entity: EntityType!, $params: ListInput!, $sandbox: Boolean) {\n list(entity: $entity, params: $params, sandbox: $sandbox) {\n records {\n ... on Bot {\n id\n data {\n label\n color\n description\n iconUrl\n password\n deploy {\n logsTTL\n }\n }\n tags\n dateModified\n }\n }\n last\n }\n}";
|
|
2
|
+
export declare const QUERY_LIST_CROSSACCOUNT = "query listCrossAccount($entity: EntityType!, $params: ListInput!, $accountId: String!) {\n listCrossAccount(entity: $entity, params: $params, accountId: $accountId) {\n records {\n ... on Bot {\n id\n data {\n label\n color\n description\n iconUrl\n password\n deploy {\n logsTTL\n }\n }\n tags\n dateModified\n }\n }\n last\n }\n}";
|
|
2
3
|
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}";
|
|
3
4
|
export declare const ENTITY_NAME = "BOT";
|
package/dist/types/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Token } from '@or-sdk/base';
|
|
|
2
2
|
export declare type BotsConfig = {
|
|
3
3
|
token: Token;
|
|
4
4
|
discoveryUrl: string;
|
|
5
|
+
accountId?: string;
|
|
5
6
|
};
|
|
6
7
|
export declare type Bot = {
|
|
7
8
|
id?: string;
|
|
@@ -18,4 +19,5 @@ export declare type Bot = {
|
|
|
18
19
|
dateCreated?: number;
|
|
19
20
|
dateModified?: number;
|
|
20
21
|
schemaVersion?: number;
|
|
22
|
+
tags?: string[];
|
|
21
23
|
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.17.1",
|
|
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.
|
|
27
|
-
"@or-sdk/data-hub": "^0.
|
|
26
|
+
"@or-sdk/base": "^0.17.1",
|
|
27
|
+
"@or-sdk/data-hub": "^0.17.1",
|
|
28
|
+
"@or-sdk/tags": "^0.17.1"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "61ede4c3b5e828ea61a8bb78a4bfc4f06852885d"
|
|
30
31
|
}
|
package/src/Bots.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { List } from '@or-sdk/base';
|
|
2
|
-
import { DataHub, GraphqlResponse, GraphqlResponseCheckExecution } from '@or-sdk/data-hub';
|
|
2
|
+
import { DataHub, GraphqlResponse, GraphqlResponseCheckExecution, GraphqlResponseDelete } from '@or-sdk/data-hub';
|
|
3
3
|
import { BotsConfig, Bot } from './types';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
QUERY_LIST,
|
|
6
|
+
QUERY_DELETE,
|
|
7
|
+
ENTITY_NAME,
|
|
8
|
+
QUERY_LIST_CROSSACCOUNT,
|
|
9
|
+
} from './constants';
|
|
10
|
+
import { Tags, Taggable, filterTagIds, addTagsIds, removeTagIds } from '@or-sdk/tags';
|
|
5
11
|
|
|
6
12
|
/**
|
|
7
13
|
* OneReach Bots service client
|
|
@@ -10,27 +16,36 @@ import { QUERY_LIST, QUERY_DELETE, ENTITY_NAME } from './constants';
|
|
|
10
16
|
* $ npm i @or-sdk/bots
|
|
11
17
|
* ```
|
|
12
18
|
*/
|
|
13
|
-
export class Bots {
|
|
19
|
+
export class Bots implements Taggable<Bot> {
|
|
14
20
|
private readonly dataHub: DataHub;
|
|
21
|
+
private readonly tags: Tags;
|
|
15
22
|
|
|
16
23
|
/**
|
|
17
24
|
* ```typescript
|
|
18
25
|
* import { Bots } from '@or-sdk/bots'
|
|
19
26
|
* const bots = new Bots({token: 'my-account-token-string', discoveryUrl: 'http://example.bots/endpoint'});
|
|
20
|
-
* await bots.init();
|
|
21
27
|
* ```
|
|
22
28
|
*/
|
|
23
29
|
constructor(params: BotsConfig) {
|
|
24
|
-
const { token, discoveryUrl } = params;
|
|
30
|
+
const { token, discoveryUrl, accountId } = params;
|
|
25
31
|
|
|
26
32
|
this.dataHub = new DataHub({
|
|
27
33
|
token,
|
|
28
34
|
discoveryUrl,
|
|
35
|
+
accountId,
|
|
36
|
+
});
|
|
37
|
+
this.tags = new Tags({
|
|
38
|
+
token,
|
|
39
|
+
discoveryUrl,
|
|
40
|
+
accountId,
|
|
29
41
|
});
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
async init() {
|
|
33
|
-
await
|
|
45
|
+
await Promise.all([
|
|
46
|
+
this.dataHub.init(),
|
|
47
|
+
this.tags.init(),
|
|
48
|
+
]);
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
/**
|
|
@@ -48,12 +63,12 @@ export class Bots {
|
|
|
48
63
|
includeExisting: true,
|
|
49
64
|
limit: 30,
|
|
50
65
|
},
|
|
51
|
-
sandbox: false,
|
|
66
|
+
... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : { sandbox: false },
|
|
52
67
|
};
|
|
53
68
|
|
|
54
69
|
const data = {
|
|
55
|
-
operationName: 'list',
|
|
56
|
-
query: QUERY_LIST,
|
|
70
|
+
operationName: this.dataHub.getOperationName('list'),
|
|
71
|
+
query: this.dataHub.isCrossAccount ? QUERY_LIST_CROSSACCOUNT : QUERY_LIST,
|
|
57
72
|
variables,
|
|
58
73
|
};
|
|
59
74
|
|
|
@@ -67,7 +82,7 @@ export class Bots {
|
|
|
67
82
|
* ```
|
|
68
83
|
*/
|
|
69
84
|
public async getBot(id: string): Promise<Bot> {
|
|
70
|
-
const route = `/v2/${this.dataHub.currentAccountId}/bot/${id}`;
|
|
85
|
+
const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/bot/${id}`;
|
|
71
86
|
|
|
72
87
|
const params = {
|
|
73
88
|
includeDeleted: false,
|
|
@@ -90,7 +105,7 @@ export class Bots {
|
|
|
90
105
|
* ```
|
|
91
106
|
*/
|
|
92
107
|
public async saveBot(source: Bot): Promise<Bot> {
|
|
93
|
-
const route = `/v2/${this.dataHub.currentAccountId}/bot/${source.id ? source.id : 'new'}`;
|
|
108
|
+
const route = `/v2/${this.dataHub.currentAccountId ? this.dataHub.currentAccountId : 'current'}/bot/${source.id ? source.id : 'new'}`;
|
|
94
109
|
|
|
95
110
|
const data = {
|
|
96
111
|
bot: source,
|
|
@@ -110,6 +125,10 @@ export class Bots {
|
|
|
110
125
|
* ```
|
|
111
126
|
*/
|
|
112
127
|
public async deleteBot(botId: string): Promise<GraphqlResponseCheckExecution> {
|
|
128
|
+
if (this.dataHub.isCrossAccount) {
|
|
129
|
+
throw Error('Cross-account deleting is not implemented.');
|
|
130
|
+
}
|
|
131
|
+
|
|
113
132
|
const variables = {
|
|
114
133
|
entity: ENTITY_NAME,
|
|
115
134
|
data: {
|
|
@@ -118,19 +137,65 @@ export class Bots {
|
|
|
118
137
|
},
|
|
119
138
|
};
|
|
120
139
|
|
|
140
|
+
const operationName = this.dataHub.getOperationName('deleteTemporarily');
|
|
141
|
+
|
|
121
142
|
const data = {
|
|
122
|
-
operationName
|
|
143
|
+
operationName,
|
|
123
144
|
query: QUERY_DELETE,
|
|
124
145
|
variables,
|
|
125
146
|
};
|
|
126
147
|
|
|
127
|
-
const
|
|
148
|
+
const result = await this.dataHub.makeRequest<GraphqlResponse<void>>({
|
|
128
149
|
method: 'POST',
|
|
129
150
|
route: '/graphql',
|
|
130
151
|
data,
|
|
131
152
|
});
|
|
132
153
|
|
|
133
|
-
return this.dataHub.subscribe(requestId);
|
|
154
|
+
return this.dataHub.subscribe((result.data[operationName] as GraphqlResponseDelete).requestId);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Add tags
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const bot = await bots.addTags(botSource, tagIdsArr);
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
public async addTags(source: Bot, tagNames: string[]): Promise<Bot> {
|
|
164
|
+
const tags = await this.tags.getMultipleTagsByName(tagNames, true);
|
|
165
|
+
const tagIds = tags.map(tag => tag.id!);
|
|
166
|
+
|
|
167
|
+
const { newIds } = filterTagIds(source.tags, tagIds);
|
|
168
|
+
|
|
169
|
+
if (!newIds.length) {
|
|
170
|
+
throw Error('No tags to add.');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return this.saveBot({
|
|
174
|
+
...source,
|
|
175
|
+
tags: addTagsIds(source.tags, newIds),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Remove tags
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const bot = await bots.removeTags(botSource, tagIdsArr);
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
public async removeTags(source: Bot, tagNames: string[]): Promise<Bot> {
|
|
186
|
+
const tags = await this.tags.getMultipleTagsByName(tagNames);
|
|
187
|
+
const tagIds = tags.map(tag => tag.id!);
|
|
188
|
+
|
|
189
|
+
const { existingIds } = filterTagIds(source.tags, tagIds);
|
|
190
|
+
|
|
191
|
+
if (!existingIds.length) {
|
|
192
|
+
throw Error('No tags to remove.');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return this.saveBot({
|
|
196
|
+
...source,
|
|
197
|
+
tags: removeTagIds(source.tags, existingIds),
|
|
198
|
+
});
|
|
134
199
|
}
|
|
135
200
|
|
|
136
201
|
}
|
package/src/constants.ts
CHANGED
|
@@ -21,6 +21,29 @@ export const QUERY_LIST = `query list($entity: EntityType!, $params: ListInput!,
|
|
|
21
21
|
}
|
|
22
22
|
}`;
|
|
23
23
|
|
|
24
|
+
export const QUERY_LIST_CROSSACCOUNT = `query listCrossAccount($entity: EntityType!, $params: ListInput!, $accountId: String!) {
|
|
25
|
+
listCrossAccount(entity: $entity, params: $params, accountId: $accountId) {
|
|
26
|
+
records {
|
|
27
|
+
... on Bot {
|
|
28
|
+
id
|
|
29
|
+
data {
|
|
30
|
+
label
|
|
31
|
+
color
|
|
32
|
+
description
|
|
33
|
+
iconUrl
|
|
34
|
+
password
|
|
35
|
+
deploy {
|
|
36
|
+
logsTTL
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
tags
|
|
40
|
+
dateModified
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
last
|
|
44
|
+
}
|
|
45
|
+
}`;
|
|
46
|
+
|
|
24
47
|
export const QUERY_DELETE = `mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {
|
|
25
48
|
deleteTemporarily(entity: $entity, data: $data) {
|
|
26
49
|
... on AsyncRequest {
|
package/src/types.ts
CHANGED
|
@@ -9,6 +9,10 @@ export type BotsConfig = {
|
|
|
9
9
|
* function which return token
|
|
10
10
|
*/
|
|
11
11
|
discoveryUrl: string;
|
|
12
|
+
/**
|
|
13
|
+
* Account ID for cross-account requests (super admin only)
|
|
14
|
+
*/
|
|
15
|
+
accountId?: string;
|
|
12
16
|
};
|
|
13
17
|
|
|
14
18
|
export type Bot = {
|
|
@@ -26,4 +30,5 @@ export type Bot = {
|
|
|
26
30
|
dateCreated?: number;
|
|
27
31
|
dateModified?: number;
|
|
28
32
|
schemaVersion?: number;
|
|
33
|
+
tags?: string[];
|
|
29
34
|
};
|