@or-sdk/bots 0.5.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.
@@ -0,0 +1,169 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.Bots = void 0;
55
+ var base_1 = require("@or-sdk/base");
56
+ var data_hub_1 = require("@or-sdk/data-hub");
57
+ var constants_1 = require("./constants");
58
+ var Bots = (function (_super) {
59
+ __extends(Bots, _super);
60
+ function Bots(params) {
61
+ var _this = this;
62
+ var token = params.token, discoveryUrl = params.discoveryUrl;
63
+ _this = _super.call(this, {
64
+ token: token,
65
+ discoveryUrl: discoveryUrl,
66
+ serviceKey: constants_1.SERVICE_KEY,
67
+ requestAccountId: true,
68
+ }) || this;
69
+ _this.dataHub = new data_hub_1.DataHub({ token: token, discoveryUrl: discoveryUrl });
70
+ return _this;
71
+ }
72
+ Bots.prototype.listBots = function () {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var variables, data;
75
+ return __generator(this, function (_a) {
76
+ variables = {
77
+ entity: constants_1.ENTITY_NAME,
78
+ params: {
79
+ queryParams: {},
80
+ includeDeleted: false,
81
+ includeExisting: true,
82
+ limit: 30,
83
+ },
84
+ sandbox: false,
85
+ };
86
+ data = {
87
+ operationName: 'list',
88
+ query: constants_1.QUERY_LIST,
89
+ variables: variables,
90
+ };
91
+ return [2, this.dataHub.getFullList('POST', '/graphql', data)];
92
+ });
93
+ });
94
+ };
95
+ Bots.prototype.getBot = function (id) {
96
+ return __awaiter(this, void 0, void 0, function () {
97
+ var route, params;
98
+ return __generator(this, function (_a) {
99
+ switch (_a.label) {
100
+ case 0:
101
+ route = "/v2/".concat(this.currentAccountId, "/bot/").concat(id);
102
+ params = {
103
+ includeDeleted: false,
104
+ includeExisting: true,
105
+ };
106
+ return [4, this.dataHub.makeRequest({
107
+ method: 'GET',
108
+ route: route,
109
+ params: params,
110
+ })];
111
+ case 1: return [2, _a.sent()];
112
+ }
113
+ });
114
+ });
115
+ };
116
+ Bots.prototype.saveBot = function (source) {
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ var route, data;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0:
122
+ route = "/v2/".concat(this.currentAccountId, "/bot/").concat(source.id ? source.id : 'new');
123
+ data = {
124
+ bot: source,
125
+ };
126
+ return [4, this.dataHub.makeRequest({
127
+ method: 'POST',
128
+ route: route,
129
+ data: data,
130
+ })];
131
+ case 1: return [2, _a.sent()];
132
+ }
133
+ });
134
+ });
135
+ };
136
+ Bots.prototype.deleteBot = function (botId) {
137
+ return __awaiter(this, void 0, void 0, function () {
138
+ var variables, data, requestId;
139
+ return __generator(this, function (_a) {
140
+ switch (_a.label) {
141
+ case 0:
142
+ variables = {
143
+ entity: constants_1.ENTITY_NAME,
144
+ data: {
145
+ id: botId,
146
+ subscribe: true,
147
+ },
148
+ };
149
+ data = {
150
+ operationName: 'deleteTemporarily',
151
+ query: constants_1.QUERY_DELETE,
152
+ variables: variables,
153
+ };
154
+ return [4, this.dataHub.makeRequest({
155
+ method: 'POST',
156
+ route: '/graphql',
157
+ data: data,
158
+ })];
159
+ case 1:
160
+ requestId = (_a.sent()).data.deleteTemporarily.requestId;
161
+ return [2, this.dataHub.subscribe(requestId)];
162
+ }
163
+ });
164
+ });
165
+ };
166
+ return Bots;
167
+ }(base_1.Base));
168
+ exports.Bots = Bots;
169
+ //# sourceMappingURL=Bots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Bots.js","sourceRoot":"","sources":["../../src/Bots.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAoC;AACpC,6CAAgE;AAEhE,yCAAiF;AASjF;IAA0B,wBAAI;IAW5B,cAAY,MAAkB;QAA9B,iBAYC;QAXS,IAAA,KAAK,GAAmB,MAAM,MAAzB,EAAE,YAAY,GAAK,MAAM,aAAX,CAAY;QAEvC,QAAA,kBAAM;YACJ,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,UAAU,EAAE,uBAAW;YACvB,gBAAgB,EAAE,IAAI;SACvB,CAAC,SAAC;QAEH,KAAI,CAAC,OAAO,GAAG,IAAI,kBAAO,CAAC,EAAE,KAAK,OAAA,EAChC,YAAY,cAAA,EAAE,CAAC,CAAC;;IACpB,CAAC;IAEY,uBAAQ,GAArB;;;;gBACQ,SAAS,GAAG;oBAChB,MAAM,EAAE,uBAAW;oBACnB,MAAM,EAAE;wBACN,WAAW,EAAE,EAAE;wBACf,cAAc,EAAE,KAAK;wBACrB,eAAe,EAAE,IAAI;wBACrB,KAAK,EAAE,EAAE;qBACV;oBACD,OAAO,EAAE,KAAK;iBACf,CAAC;gBAEI,IAAI,GAAG;oBACX,aAAa,EAAE,MAAM;oBACrB,KAAK,EAAE,sBAAU;oBACjB,SAAS,WAAA;iBACV,CAAC;gBAEF,WAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAM,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,EAAC;;;KAChE;IAEY,qBAA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IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,EAAC;;;;KAC1C;IAEH,WAAC;AAAD,CAAC,AAzGD,CAA0B,WAAI,GAyG7B;AAzGY,oBAAI"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENTITY_NAME = exports.QUERY_DELETE = exports.QUERY_LIST = exports.SERVICE_KEY = void 0;
4
+ exports.SERVICE_KEY = 'data-hub';
5
+ 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 __typename\n }\n __typename\n }\n tags\n dateModified\n __typename\n }\n __typename\n }\n last\n __typename\n }\n}";
6
+ exports.QUERY_DELETE = "mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {\n deleteTemporarily(entity: $entity, data: $data) {\n ... on AsyncRequest {\n requestId\n __typename\n }\n __typename\n }\n}";
7
+ exports.ENTITY_NAME = 'BOT';
8
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,UAAU,CAAC;AAEzB,QAAA,UAAU,GAAG,qhBA0BxB,CAAC;AAEU,QAAA,YAAY,GAAG,2NAQ1B,CAAC;AAEU,QAAA,WAAW,GAAG,KAAK,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.Bots = void 0;
14
+ var Bots_1 = require("./Bots");
15
+ Object.defineProperty(exports, "Bots", { enumerable: true, get: function () { return Bots_1.Bots; } });
16
+ __exportStar(require("./types"), exports);
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,0CAAwB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,95 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Base } from '@or-sdk/base';
11
+ import { DataHub } from '@or-sdk/data-hub';
12
+ import { SERVICE_KEY, QUERY_LIST, QUERY_DELETE, ENTITY_NAME } from './constants';
13
+ export class Bots extends Base {
14
+ constructor(params) {
15
+ const { token, discoveryUrl } = params;
16
+ super({
17
+ token,
18
+ discoveryUrl,
19
+ serviceKey: SERVICE_KEY,
20
+ requestAccountId: true,
21
+ });
22
+ this.dataHub = new DataHub({ token,
23
+ discoveryUrl });
24
+ }
25
+ listBots() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const variables = {
28
+ entity: ENTITY_NAME,
29
+ params: {
30
+ queryParams: {},
31
+ includeDeleted: false,
32
+ includeExisting: true,
33
+ limit: 30,
34
+ },
35
+ sandbox: false,
36
+ };
37
+ const data = {
38
+ operationName: 'list',
39
+ query: QUERY_LIST,
40
+ variables,
41
+ };
42
+ return this.dataHub.getFullList('POST', '/graphql', data);
43
+ });
44
+ }
45
+ getBot(id) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const route = `/v2/${this.currentAccountId}/bot/${id}`;
48
+ const params = {
49
+ includeDeleted: false,
50
+ includeExisting: true,
51
+ };
52
+ return yield this.dataHub.makeRequest({
53
+ method: 'GET',
54
+ route,
55
+ params,
56
+ });
57
+ });
58
+ }
59
+ saveBot(source) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const route = `/v2/${this.currentAccountId}/bot/${source.id ? source.id : 'new'}`;
62
+ const data = {
63
+ bot: source,
64
+ };
65
+ return yield this.dataHub.makeRequest({
66
+ method: 'POST',
67
+ route,
68
+ data,
69
+ });
70
+ });
71
+ }
72
+ deleteBot(botId) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ const variables = {
75
+ entity: ENTITY_NAME,
76
+ data: {
77
+ id: botId,
78
+ subscribe: true,
79
+ },
80
+ };
81
+ const data = {
82
+ operationName: 'deleteTemporarily',
83
+ query: QUERY_DELETE,
84
+ variables,
85
+ };
86
+ const { data: { deleteTemporarily: { requestId } } } = yield this.dataHub.makeRequest({
87
+ method: 'POST',
88
+ route: '/graphql',
89
+ data,
90
+ });
91
+ return this.dataHub.subscribe(requestId);
92
+ });
93
+ }
94
+ }
95
+ //# sourceMappingURL=Bots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Bots.js","sourceRoot":"","sources":["../../src/Bots.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MA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;KAAA;IAQY,OAAO,CAAC,MAAW;;YAC9B,MAAM,KAAK,GAAG,OAAO,IAAI,CAAC,gBAAgB,QAAQ,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;YAElF,MAAM,IAAI,GAAG;gBACX,GAAG,EAAE,MAAM;aACZ,CAAC;YAEF,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;gBACpC,MAAM,EAAE,MAAM;gBACd,KAAK;gBACL,IAAI;aACL,CAAC,CAAC;QACL,CAAC;KAAA;IAEY,SAAS,CAAC,KAAa;;YAClC,MAAM,SAAS,GAAG;gBAChB,MAAM,EAAE,WAAW;gBACnB,IAAI,EAAE;oBACJ,EAAE,EAAE,KAAK;oBACT,SAAS,EAAE,IAAI;iBAChB;aACF,CAAC;YAEF,MAAM,IAAI,GAAG;gBACX,aAAa,EAAE,mBAAmB;gBAClC,KAAK,EAAE,YAAY;gBACnB,SAAS;aACV,CAAC;YAEF,MAAM,EAAE,IAAI,EAAE,EAAE,iBAAiB,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;gBACpF,MAAM,EAAE,MAAM;gBACd,KAAK,EAAE,UAAU;gBACjB,IAAI;aACL,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC3C,CAAC;KAAA;CAEF"}
@@ -0,0 +1,39 @@
1
+ export const SERVICE_KEY = 'data-hub';
2
+ export const QUERY_LIST = `query list($entity: EntityType!, $params: ListInput!, $sandbox: Boolean) {
3
+ list(entity: $entity, params: $params, sandbox: $sandbox) {
4
+ records {
5
+ ... on Bot {
6
+ id
7
+ data {
8
+ label
9
+ color
10
+ description
11
+ iconUrl
12
+ password
13
+ deploy {
14
+ logsTTL
15
+ __typename
16
+ }
17
+ __typename
18
+ }
19
+ tags
20
+ dateModified
21
+ __typename
22
+ }
23
+ __typename
24
+ }
25
+ last
26
+ __typename
27
+ }
28
+ }`;
29
+ export const QUERY_DELETE = `mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {
30
+ deleteTemporarily(entity: $entity, data: $data) {
31
+ ... on AsyncRequest {
32
+ requestId
33
+ __typename
34
+ }
35
+ __typename
36
+ }
37
+ }`;
38
+ export const ENTITY_NAME = 'BOT';
39
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC;AAEtC,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BxB,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;EAQ1B,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { Bots } from './Bots';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { Base } from '@or-sdk/base';
2
+ import { SubscribeResultData } from '@or-sdk/data-hub';
3
+ import { BotsConfig, Bot } from './types';
4
+ export declare class Bots extends Base {
5
+ private readonly dataHub;
6
+ constructor(params: BotsConfig);
7
+ listBots(): Promise<Bot[]>;
8
+ getBot(id: string): Promise<Bot>;
9
+ saveBot(source: Bot): Promise<Bot>;
10
+ deleteBot(botId: string): Promise<SubscribeResultData>;
11
+ }
@@ -0,0 +1,4 @@
1
+ export declare const SERVICE_KEY = "data-hub";
2
+ 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 __typename\n }\n __typename\n }\n tags\n dateModified\n __typename\n }\n __typename\n }\n last\n __typename\n }\n}";
3
+ export declare const QUERY_DELETE = "mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {\n deleteTemporarily(entity: $entity, data: $data) {\n ... on AsyncRequest {\n requestId\n __typename\n }\n __typename\n }\n}";
4
+ export declare const ENTITY_NAME = "BOT";
@@ -0,0 +1,2 @@
1
+ export { Bots } from './Bots';
2
+ export * from './types';
@@ -0,0 +1,21 @@
1
+ import { Token } from '@or-sdk/base';
2
+ export declare type BotsConfig = {
3
+ token: Token;
4
+ discoveryUrl: string;
5
+ };
6
+ export declare type Bot = {
7
+ id?: string;
8
+ data: {
9
+ label: string;
10
+ color: string | null;
11
+ description: string;
12
+ iconUrl: string;
13
+ password: string;
14
+ deploy: {
15
+ logsTTL: number;
16
+ };
17
+ };
18
+ dateCreated?: number;
19
+ dateModified?: number;
20
+ schemaVersion?: number;
21
+ };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "version": "0.5.0",
3
+ "name": "@or-sdk/bots",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "scripts": {
8
+ "build": "npm run clean && concurrently \"npm run build:cjs\" \"npm run build:esm\" \"npm run build:types\"",
9
+ "build:watch": "concurrently -r --hide 1,2 \"npm run build:watch:cjs\" \"npm run build:watch:esm\" \"npm run build:watch:types\"",
10
+ "build:cjs": "tsc --project tsconfig.json",
11
+ "build:watch:cjs": "tsc --project tsconfig.json -w",
12
+ "build:esm": "tsc --project tsconfig.esm.json",
13
+ "build:watch:esm": "tsc --project tsconfig.esm.json -w",
14
+ "build:types": "tsc --project tsconfig.types.json",
15
+ "build:watch:types": "tsc --project tsconfig.types.json -w",
16
+ "clean": "rm -rf ./dist"
17
+ },
18
+ "devDependencies": {
19
+ "concurrently": "^6.4.0",
20
+ "typescript": "^4.4.4"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "dependencies": {
26
+ "@or-sdk/base": "^0.5.0",
27
+ "@or-sdk/data-hub": "^0.5.0"
28
+ },
29
+ "gitHead": "26a6532bede3f10b83865957ae21e4d19240019f"
30
+ }
package/src/Bots.ts ADDED
@@ -0,0 +1,118 @@
1
+ import { Base } from '@or-sdk/base';
2
+ import { DataHub, SubscribeResultData } from '@or-sdk/data-hub';
3
+ import { BotsConfig, Bot } from './types';
4
+ import { SERVICE_KEY, QUERY_LIST, QUERY_DELETE, ENTITY_NAME } from './constants';
5
+
6
+ /**
7
+ * OneReach Bots service client
8
+ * ## Installation:
9
+ * ```
10
+ * $ npm i @or-sdk/bots
11
+ * ```
12
+ */
13
+ export class Bots extends Base {
14
+ private readonly dataHub: DataHub;
15
+
16
+ /**
17
+ * ```typescript
18
+ *
19
+ * import { Bots } from '@or-sdk/bots'
20
+ * const bots = new Bots({token: 'my-account-token-string', discoveryUrl: 'http://example.bots/endpoint'});
21
+ *
22
+ * ```
23
+ */
24
+ constructor(params: BotsConfig) {
25
+ const { token, discoveryUrl } = params;
26
+
27
+ super({
28
+ token,
29
+ discoveryUrl,
30
+ serviceKey: SERVICE_KEY,
31
+ requestAccountId: true,
32
+ });
33
+
34
+ this.dataHub = new DataHub({ token,
35
+ discoveryUrl });
36
+ }
37
+
38
+ public async listBots(): Promise<Bot[]> {
39
+ const variables = {
40
+ entity: ENTITY_NAME,
41
+ params: {
42
+ queryParams: {},
43
+ includeDeleted: false,
44
+ includeExisting: true,
45
+ limit: 30,
46
+ },
47
+ sandbox: false,
48
+ };
49
+
50
+ const data = {
51
+ operationName: 'list',
52
+ query: QUERY_LIST,
53
+ variables,
54
+ };
55
+
56
+ return this.dataHub.getFullList<Bot>('POST', '/graphql', data);
57
+ }
58
+
59
+ public async getBot(id: string): Promise<Bot> {
60
+ const route = `/v2/${this.currentAccountId}/bot/${id}`;
61
+
62
+ const params = {
63
+ includeDeleted: false,
64
+ includeExisting: true,
65
+ };
66
+
67
+ return await this.dataHub.makeRequest({
68
+ method: 'GET',
69
+ route,
70
+ params,
71
+ });
72
+ }
73
+
74
+ /**
75
+ *
76
+ * if source contains id - existing bot be updated
77
+ *
78
+ * @returns created/updated bot source
79
+ */
80
+ public async saveBot(source: Bot): Promise<Bot> {
81
+ const route = `/v2/${this.currentAccountId}/bot/${source.id ? source.id : 'new'}`;
82
+
83
+ const data = {
84
+ bot: source,
85
+ };
86
+
87
+ return await this.dataHub.makeRequest({
88
+ method: 'POST',
89
+ route,
90
+ data,
91
+ });
92
+ }
93
+
94
+ public async deleteBot(botId: string): Promise<SubscribeResultData> {
95
+ const variables = {
96
+ entity: ENTITY_NAME,
97
+ data: {
98
+ id: botId,
99
+ subscribe: true,
100
+ },
101
+ };
102
+
103
+ const data = {
104
+ operationName: 'deleteTemporarily',
105
+ query: QUERY_DELETE,
106
+ variables,
107
+ };
108
+
109
+ const { data: { deleteTemporarily: { requestId } } } = await this.dataHub.makeRequest({
110
+ method: 'POST',
111
+ route: '/graphql',
112
+ data,
113
+ });
114
+
115
+ return this.dataHub.subscribe(requestId);
116
+ }
117
+
118
+ }
@@ -0,0 +1,42 @@
1
+ export const SERVICE_KEY = 'data-hub';
2
+
3
+ export const QUERY_LIST = `query list($entity: EntityType!, $params: ListInput!, $sandbox: Boolean) {
4
+ list(entity: $entity, params: $params, sandbox: $sandbox) {
5
+ records {
6
+ ... on Bot {
7
+ id
8
+ data {
9
+ label
10
+ color
11
+ description
12
+ iconUrl
13
+ password
14
+ deploy {
15
+ logsTTL
16
+ __typename
17
+ }
18
+ __typename
19
+ }
20
+ tags
21
+ dateModified
22
+ __typename
23
+ }
24
+ __typename
25
+ }
26
+ last
27
+ __typename
28
+ }
29
+ }`;
30
+
31
+ export const QUERY_DELETE = `mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {
32
+ deleteTemporarily(entity: $entity, data: $data) {
33
+ ... on AsyncRequest {
34
+ requestId
35
+ __typename
36
+ }
37
+ __typename
38
+ }
39
+ }`;
40
+
41
+ export const ENTITY_NAME = 'BOT';
42
+
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { Bots } from './Bots';
2
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { Token } from '@or-sdk/base';
2
+
3
+ export type BotsConfig = {
4
+ /**
5
+ * token
6
+ */
7
+ token: Token;
8
+ /**
9
+ * function which return token
10
+ */
11
+ discoveryUrl: string;
12
+ };
13
+
14
+ export type Bot = {
15
+ id?: string;
16
+ data: {
17
+ label: string;
18
+ color: string | null;
19
+ description: string;
20
+ iconUrl: string;
21
+ password: string;
22
+ deploy: {
23
+ logsTTL: number;
24
+ };
25
+ };
26
+ dateCreated?: number;
27
+ dateModified?: number;
28
+ schemaVersion?: number;
29
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "ES6",
5
+ "target": "es6",
6
+ "outDir": "./dist/esm/",
7
+ "rootDir": "./src"
8
+ }
9
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/cjs/",
5
+ "rootDir": "./src"
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/types/",
5
+ "rootDir": "./src",
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true
8
+ }
9
+ }