@or-sdk/idw 1.0.2

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 ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.0.2 (2023-05-18)
7
+
8
+ **Note:** Version bump only for package @or-sdk/idw
package/README.md ADDED
@@ -0,0 +1 @@
1
+ ## Installation:
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SERVICE_KEY = exports.GRAPH_NAME = void 0;
4
+ exports.GRAPH_NAME = 'idw';
5
+ exports.SERVICE_KEY = 'idw';
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,KAAK,CAAC;AACnB,QAAA,WAAW,GAAG,KAAK,CAAC"}
@@ -0,0 +1,212 @@
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 (g && (g = 0, op[0] && (_ = 0)), _) 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.IDW = void 0;
55
+ var base_1 = require("@or-sdk/base");
56
+ var graph_1 = require("@or-sdk/graph");
57
+ var users_1 = require("@or-sdk/users");
58
+ var constants_1 = require("./constants");
59
+ var IDW = (function (_super) {
60
+ __extends(IDW, _super);
61
+ function IDW(params) {
62
+ var _this = this;
63
+ var accountId = params.accountId, discoveryUrl = params.discoveryUrl, graphUrl = params.graphUrl, sdkApiUrl = params.sdkApiUrl, token = params.token;
64
+ _this = _super.call(this, {
65
+ accountId: accountId,
66
+ discoveryUrl: discoveryUrl,
67
+ serviceKey: constants_1.SERVICE_KEY,
68
+ token: token,
69
+ }) || this;
70
+ _this.graphApi = new graph_1.Graphs({
71
+ accountId: accountId,
72
+ discoveryUrl: discoveryUrl,
73
+ graphUrl: graphUrl,
74
+ token: token,
75
+ });
76
+ _this.users = new users_1.Users({
77
+ accountId: accountId,
78
+ token: token,
79
+ discoveryUrl: discoveryUrl,
80
+ sdkUrl: sdkApiUrl,
81
+ });
82
+ return _this;
83
+ }
84
+ IDW.prototype.checkOrCreateDb = function () {
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ var e_1;
87
+ return __generator(this, function (_a) {
88
+ switch (_a.label) {
89
+ case 0:
90
+ _a.trys.push([0, 2, , 4]);
91
+ return [4, this.graphApi.getGraphInfo(constants_1.GRAPH_NAME)];
92
+ case 1:
93
+ _a.sent();
94
+ return [3, 4];
95
+ case 2:
96
+ e_1 = _a.sent();
97
+ return [4, this.graphApi.createGraph({
98
+ name: constants_1.GRAPH_NAME,
99
+ })];
100
+ case 3:
101
+ _a.sent();
102
+ return [3, 4];
103
+ case 4: return [2];
104
+ }
105
+ });
106
+ });
107
+ };
108
+ IDW.prototype.createOrUpdateFlow = function (flow) {
109
+ return __awaiter(this, void 0, void 0, function () {
110
+ var userId;
111
+ return __generator(this, function (_a) {
112
+ switch (_a.label) {
113
+ case 0:
114
+ if (flow.id === undefined) {
115
+ throw new Error('Only flows with id can be added to the IDW graph');
116
+ }
117
+ if (!flow.isDeleted) return [3, 2];
118
+ return [4, this.deleteFlow(flow.id)];
119
+ case 1: return [2, _a.sent()];
120
+ case 2: return [4, this.users.getCurrentUser()];
121
+ case 3:
122
+ userId = (_a.sent()).userId;
123
+ return [4, this.graphQuery("\n MERGE (flow:FLOW { id: $id })\n ON MATCH\n SET flow.createdAt = $createdAt,\n flow.createdBy = $userId,\n flow.description = $description,\n flow.groupId = $groupId,\n flow.name = $name,\n flow.updatedAt = $updatedAt,\n flow.updatedBy = $userId\n ON CREATE\n SET flow.createdAt = $createdAt,\n flow.createdBy = $userId,\n flow.description = $description,\n flow.groupId = $groupId,\n flow.isActive = false,\n flow.name = $name,\n flow.updatedAt = $updatedAt,\n flow.updatedBy = $userId\n RETURN flow\n ", {
124
+ createdAt: flow.dateCreated,
125
+ description: flow.data.description,
126
+ groupId: flow.botId,
127
+ id: flow.id,
128
+ name: flow.data.label,
129
+ updatedAt: flow.dateModified,
130
+ userId: userId,
131
+ })];
132
+ case 4:
133
+ _a.sent();
134
+ return [2];
135
+ }
136
+ });
137
+ });
138
+ };
139
+ IDW.prototype.deleteFlow = function (id) {
140
+ return __awaiter(this, void 0, void 0, function () {
141
+ return __generator(this, function (_a) {
142
+ switch (_a.label) {
143
+ case 0: return [4, this.graphQuery("\n MATCH (flow:FLOW { id: $id })\n DETACH DELETE flow\n ", { id: id })];
144
+ case 1:
145
+ _a.sent();
146
+ return [2];
147
+ }
148
+ });
149
+ });
150
+ };
151
+ IDW.prototype.activateFlow = function (flow) {
152
+ return __awaiter(this, void 0, void 0, function () {
153
+ var id;
154
+ return __generator(this, function (_a) {
155
+ switch (_a.label) {
156
+ case 0:
157
+ id = flow.id;
158
+ if (id === undefined) {
159
+ throw new Error('Only flows with id can be added to the IDW graph');
160
+ }
161
+ return [4, this.graphQuery("\n MATCH (flow:FLOW { id: $id })\n SET flow.isActive = true,\n flow.activatedAt = $activatedAt\n RETURN flow\n ", {
162
+ activatedAt: Date.now(),
163
+ id: id,
164
+ })];
165
+ case 1:
166
+ _a.sent();
167
+ return [2];
168
+ }
169
+ });
170
+ });
171
+ };
172
+ IDW.prototype.deactivateFlow = function (id) {
173
+ return __awaiter(this, void 0, void 0, function () {
174
+ return __generator(this, function (_a) {
175
+ switch (_a.label) {
176
+ case 0: return [4, this.graphQuery("\n MATCH (flow:FLOW { id: $id } )\n SET flow.isActive = false\n REMOVE flow.activatedAt\n RETURN flow\n ", { id: id })];
177
+ case 1:
178
+ _a.sent();
179
+ return [2];
180
+ }
181
+ });
182
+ });
183
+ };
184
+ IDW.prototype.graphQuery = function (query, params) {
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ var e_2;
187
+ return __generator(this, function (_a) {
188
+ switch (_a.label) {
189
+ case 0: return [4, this.checkOrCreateDb()];
190
+ case 1:
191
+ _a.sent();
192
+ _a.label = 2;
193
+ case 2:
194
+ _a.trys.push([2, 4, , 5]);
195
+ return [4, this.graphApi.query({
196
+ graph: constants_1.GRAPH_NAME,
197
+ params: params,
198
+ query: query,
199
+ })];
200
+ case 3: return [2, _a.sent()];
201
+ case 4:
202
+ e_2 = _a.sent();
203
+ return [3, 5];
204
+ case 5: return [2];
205
+ }
206
+ });
207
+ });
208
+ };
209
+ return IDW;
210
+ }(base_1.Base));
211
+ exports.IDW = IDW;
212
+ //# sourceMappingURL=idw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idw.js","sourceRoot":"","sources":["../../src/idw.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAoC;AAEpC,uCAAuC;AACvC,uCAAsC;AACtC,yCAAsD;AAUtD;IAAyB,uBAAI;IAe3B,aAAY,MAAiB;QAA7B,iBA4BC;QA1BG,IAAA,SAAS,GAKP,MAAM,UALC,EACT,YAAY,GAIV,MAAM,aAJ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AAC,AApND,CAAyB,WAAI,GAoN5B;AApNY,kBAAG"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.IDW = void 0;
18
+ var idw_1 = require("./idw");
19
+ Object.defineProperty(exports, "IDW", { enumerable: true, get: function () { return idw_1.IDW; } });
20
+ __exportStar(require("./types"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AACZ,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,3 @@
1
+ export const GRAPH_NAME = 'idw';
2
+ export const SERVICE_KEY = 'idw';
3
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC;AAChC,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC"}
@@ -0,0 +1,138 @@
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 { Graphs } from '@or-sdk/graph';
12
+ import { Users } from '@or-sdk/users';
13
+ import { GRAPH_NAME, SERVICE_KEY } from './constants';
14
+ export class IDW extends Base {
15
+ constructor(params) {
16
+ const { accountId, discoveryUrl, graphUrl, sdkApiUrl, token, } = params;
17
+ super({
18
+ accountId,
19
+ discoveryUrl,
20
+ serviceKey: SERVICE_KEY,
21
+ token,
22
+ });
23
+ this.graphApi = new Graphs({
24
+ accountId,
25
+ discoveryUrl,
26
+ graphUrl,
27
+ token,
28
+ });
29
+ this.users = new Users({
30
+ accountId,
31
+ token,
32
+ discoveryUrl,
33
+ sdkUrl: sdkApiUrl,
34
+ });
35
+ }
36
+ checkOrCreateDb() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ try {
39
+ yield this.graphApi.getGraphInfo(GRAPH_NAME);
40
+ }
41
+ catch (e) {
42
+ yield this.graphApi.createGraph({
43
+ name: GRAPH_NAME,
44
+ });
45
+ }
46
+ });
47
+ }
48
+ createOrUpdateFlow(flow) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ if (flow.id === undefined) {
51
+ throw new Error('Only flows with id can be added to the IDW graph');
52
+ }
53
+ if (flow.isDeleted) {
54
+ return yield this.deleteFlow(flow.id);
55
+ }
56
+ const { userId } = yield this.users.getCurrentUser();
57
+ yield this.graphQuery(`
58
+ MERGE (flow:FLOW { id: $id })
59
+ ON MATCH
60
+ SET flow.createdAt = $createdAt,
61
+ flow.createdBy = $userId,
62
+ flow.description = $description,
63
+ flow.groupId = $groupId,
64
+ flow.name = $name,
65
+ flow.updatedAt = $updatedAt,
66
+ flow.updatedBy = $userId
67
+ ON CREATE
68
+ SET flow.createdAt = $createdAt,
69
+ flow.createdBy = $userId,
70
+ flow.description = $description,
71
+ flow.groupId = $groupId,
72
+ flow.isActive = false,
73
+ flow.name = $name,
74
+ flow.updatedAt = $updatedAt,
75
+ flow.updatedBy = $userId
76
+ RETURN flow
77
+ `, {
78
+ createdAt: flow.dateCreated,
79
+ description: flow.data.description,
80
+ groupId: flow.botId,
81
+ id: flow.id,
82
+ name: flow.data.label,
83
+ updatedAt: flow.dateModified,
84
+ userId,
85
+ });
86
+ });
87
+ }
88
+ deleteFlow(id) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ yield this.graphQuery(`
91
+ MATCH (flow:FLOW { id: $id })
92
+ DETACH DELETE flow
93
+ `, { id });
94
+ });
95
+ }
96
+ activateFlow(flow) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ const id = flow.id;
99
+ if (id === undefined) {
100
+ throw new Error('Only flows with id can be added to the IDW graph');
101
+ }
102
+ yield this.graphQuery(`
103
+ MATCH (flow:FLOW { id: $id })
104
+ SET flow.isActive = true,
105
+ flow.activatedAt = $activatedAt
106
+ RETURN flow
107
+ `, {
108
+ activatedAt: Date.now(),
109
+ id,
110
+ });
111
+ });
112
+ }
113
+ deactivateFlow(id) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ yield this.graphQuery(`
116
+ MATCH (flow:FLOW { id: $id } )
117
+ SET flow.isActive = false
118
+ REMOVE flow.activatedAt
119
+ RETURN flow
120
+ `, { id });
121
+ });
122
+ }
123
+ graphQuery(query, params) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ yield this.checkOrCreateDb();
126
+ try {
127
+ return yield this.graphApi.query({
128
+ graph: GRAPH_NAME,
129
+ params,
130
+ query,
131
+ });
132
+ }
133
+ catch (e) {
134
+ }
135
+ });
136
+ }
137
+ }
138
+ //# sourceMappingURL=idw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idw.js","sourceRoot":"","sources":["../../src/idw.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAUtD,MAAM,OAAO,GAAI,SAAQ,IAAI;IAe3B,YAAY,MAAiB;QAC3B,MAAM,EACJ,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,KAAK,GACN,GAAG,MAAM,CAAC;QAEX,KAAK,CAAC;YACJ,SAAS;YACT,YAAY;YACZ,UAAU,EAAE,WAAW;YACvB,KAAK;SACN,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,IAAI,MAAM,CAAC;YACzB,SAAS;YACT,YAAY;YACZ,QAAQ;YACR,KAAK;SACN,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC;YACrB,SAAS;YACT,KAAK;YACL,YAAY;YACZ,MAAM,EAAE,SAAS;SAClB,CAAC,CAAC;IACL,CAAC;IAEK,eAAe;;YACnB,IAAI;gBACF,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;aAC9C;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;oBAC9B,IAAI,EAAE,UAAU;iBACjB,CAAC,CAAC;aACJ;QACH,CAAC;KAAA;IAEK,kBAAkB,CAAC,IAAU;;YACjC,IA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,UAAU,CAAC,KAAa,EAAE,MAAyD;;YAE/F,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;YAC7B,IAAI;gBACF,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;oBAC/B,KAAK,EAAE,UAAU;oBACjB,MAAM;oBACN,KAAK;iBACN,CAAC,CAAC;aACJ;YAAC,OAAO,CAAC,EAAE;aAEX;QACH,CAAC;KAAA;CACF"}
@@ -0,0 +1,3 @@
1
+ export { IDW } from './idw';
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,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,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,3 @@
1
+ export declare const GRAPH_NAME = "idw";
2
+ export declare const SERVICE_KEY = "idw";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,QAAQ,CAAC;AAChC,eAAO,MAAM,WAAW,QAAQ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { Base } from '@or-sdk/base';
2
+ import { Flow } from '@or-sdk/deployer';
3
+ import { IDWConfig } from './types';
4
+ export declare class IDW extends Base {
5
+ private readonly graphApi;
6
+ private readonly users;
7
+ constructor(params: IDWConfig);
8
+ checkOrCreateDb(): Promise<void>;
9
+ createOrUpdateFlow(flow: Flow): Promise<void>;
10
+ deleteFlow(id: string): Promise<void>;
11
+ activateFlow(flow: Flow): Promise<void>;
12
+ deactivateFlow(id: string): Promise<void>;
13
+ private graphQuery;
14
+ }
15
+ //# sourceMappingURL=idw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idw.d.ts","sourceRoot":"","sources":["../../src/idw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAIxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AASpC,qBAAa,GAAI,SAAQ,IAAI;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;gBAalB,MAAM,EAAE,SAAS;IA8BvB,eAAe;IAUf,kBAAkB,CAAC,IAAI,EAAE,IAAI;IAqG7B,UAAU,CAAC,EAAE,EAAE,MAAM;IAOrB,YAAY,CAAC,IAAI,EAAE,IAAI;IA2BvB,cAAc,CAAC,EAAE,EAAE,MAAM;YASjB,UAAU;CAazB"}
@@ -0,0 +1,3 @@
1
+ export { IDW } from './idw';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Token } from '@or-sdk/base';
2
+ export type IDWConfig = {
3
+ accountId?: string;
4
+ discoveryUrl?: string;
5
+ graphUrl?: string;
6
+ sdkApiUrl?: string;
7
+ token: Token;
8
+ };
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,MAAM,MAAM,SAAS,GAAG;IAItB,SAAS,CAAC,EAAE,MAAM,CAAC;IAKnB,YAAY,CAAC,EAAE,MAAM,CAAC;IAKtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAKlB,SAAS,CAAC,EAAE,MAAM,CAAC;IAKnB,KAAK,EAAE,KAAK,CAAC;CACd,CAAC"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "version": "1.0.2",
3
+ "name": "@or-sdk/idw",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "scripts": {
8
+ "build": "pnpm clean && pnpm build:esm && pnpm build:cjs",
9
+ "build:cjs": "tsc --project tsconfig.json",
10
+ "build:esm": "tsc --project tsconfig.esm.json",
11
+ "build:types": "tsc --project tsconfig.types.json",
12
+ "build:watch": "concurrently -r --hide 1,2 \"pnpm build:watch:cjs\" \"pnpm build:watch:esm\" \"pnpm build:watch:types\"",
13
+ "build:watch:cjs": "tsc --project tsconfig.json -w",
14
+ "build:watch:esm": "tsc --project tsconfig.esm.json -w",
15
+ "build:watch:types": "tsc --project tsconfig.types.json -w",
16
+ "clean": "rm -rf ./dist",
17
+ "dev": "pnpm build:watch:esm"
18
+ },
19
+ "devDependencies": {
20
+ "concurrently": "^6.4.0",
21
+ "typescript": "^4.4.4"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "dependencies": {
27
+ "@or-sdk/base": "^0.28.1",
28
+ "@or-sdk/deployer": "^1.1.1",
29
+ "@or-sdk/graph": "^1.3.1",
30
+ "@or-sdk/users": "^0.30.0"
31
+ },
32
+ "gitHead": "c1a9c3094ebe80016dc4e86ebaecab4023480164"
33
+ }
@@ -0,0 +1,2 @@
1
+ export const GRAPH_NAME = 'idw';
2
+ export const SERVICE_KEY = 'idw';
package/src/idw.ts ADDED
@@ -0,0 +1,227 @@
1
+ import { Base } from '@or-sdk/base';
2
+ import { Flow } from '@or-sdk/deployer';
3
+ import { Graphs } from '@or-sdk/graph';
4
+ import { Users } from '@or-sdk/users';
5
+ import { GRAPH_NAME, SERVICE_KEY } from './constants';
6
+ import { IDWConfig } from './types';
7
+
8
+ /**
9
+ * OneReach IDW service client
10
+ * ## Installation:
11
+ * ```
12
+ * $ npm i @or-sdk/idw
13
+ * ```
14
+ */
15
+ export class IDW extends Base {
16
+ private readonly graphApi: Graphs;
17
+ private readonly users: Users;
18
+
19
+ /**
20
+ * ```typescript
21
+ * import { IDW } from '@or-sdk/idw'
22
+ * import config from '../config';
23
+ *
24
+ * const idw = new IDW({
25
+ * graphUrl: config.GRAPHS_API_URL,
26
+ * token: 'account-token-string'
27
+ * })
28
+ * ```
29
+ */
30
+ constructor(params: IDWConfig) {
31
+ const {
32
+ accountId,
33
+ discoveryUrl,
34
+ graphUrl,
35
+ sdkApiUrl,
36
+ token,
37
+ } = params;
38
+
39
+ super({
40
+ accountId,
41
+ discoveryUrl,
42
+ serviceKey: SERVICE_KEY,
43
+ token,
44
+ });
45
+
46
+ this.graphApi = new Graphs({
47
+ accountId,
48
+ discoveryUrl,
49
+ graphUrl,
50
+ token,
51
+ });
52
+ this.users = new Users({
53
+ accountId,
54
+ token,
55
+ discoveryUrl,
56
+ sdkUrl: sdkApiUrl,
57
+ });
58
+ }
59
+
60
+ async checkOrCreateDb() {
61
+ try {
62
+ await this.graphApi.getGraphInfo(GRAPH_NAME);
63
+ } catch (e) {
64
+ await this.graphApi.createGraph({
65
+ name: GRAPH_NAME,
66
+ });
67
+ }
68
+ }
69
+
70
+ async createOrUpdateFlow(flow: Flow) {
71
+ if (flow.id === undefined) {
72
+ throw new Error('Only flows with id can be added to the IDW graph');
73
+ }
74
+
75
+ if (flow.isDeleted) {
76
+ return await this.deleteFlow(flow.id);
77
+ }
78
+
79
+ const { userId } = await this.users.getCurrentUser();
80
+
81
+ await this.graphQuery(`
82
+ MERGE (flow:FLOW { id: $id })
83
+ ON MATCH
84
+ SET flow.createdAt = $createdAt,
85
+ flow.createdBy = $userId,
86
+ flow.description = $description,
87
+ flow.groupId = $groupId,
88
+ flow.name = $name,
89
+ flow.updatedAt = $updatedAt,
90
+ flow.updatedBy = $userId
91
+ ON CREATE
92
+ SET flow.createdAt = $createdAt,
93
+ flow.createdBy = $userId,
94
+ flow.description = $description,
95
+ flow.groupId = $groupId,
96
+ flow.isActive = false,
97
+ flow.name = $name,
98
+ flow.updatedAt = $updatedAt,
99
+ flow.updatedBy = $userId
100
+ RETURN flow
101
+ `,
102
+ {
103
+ createdAt: flow.dateCreated,
104
+ description: flow.data.description,
105
+ groupId: flow.botId,
106
+ id: flow.id,
107
+ name: flow.data.label,
108
+ updatedAt: flow.dateModified,
109
+ userId,
110
+ }
111
+ );
112
+
113
+ // const channel = flow.data.meta.idw?.channel;
114
+ // if (channel !== undefined) {
115
+ // const _channel = await this.getChannel(channel);
116
+ // if (channel !== undefined && _.isEmpty(_channel)) return;
117
+ // // TODO: ON MATCH DELETE [:IMPLEMENTS] relationship with channel node's { id != $channel }
118
+ // await this.deleteRelationship(flow.id, channel);
119
+ // // TODO: create :IMPLEMENTS relationship with channel node { id: $channel }
120
+ // await this.createRelationship(flow.id, channel);
121
+ // } else {
122
+ // // TODO: ON MATCH DELETE [:IMPLEMENTS] relationship with channel nodes
123
+ // await this.deleteAllRelationship(flow.id);
124
+ // }
125
+ }
126
+
127
+ // async getChannel(channel: string) {
128
+ // return await this.graphQuery(`
129
+ // MATCH (channel: CHANNEL {id: $channel})
130
+ // RETURN channel`,
131
+ // { channel });
132
+ // }
133
+
134
+ // async getActivatedFlow(channel: string) {
135
+ // return await this.graphQuery(`
136
+ // MATCH (flow:FLOW { isActive: true })-[:IMPLEMENTS]-(:CHANNEL { channel: $channel })
137
+ // RETURN flow`,
138
+ // { channel });
139
+ // }
140
+
141
+ // async deleteRelationship(id: string, channel = '') {
142
+ // await this.graphQuery(`
143
+ // MATCH (:FLOW {id: $id})-[r:IMPLEMENTS]->(:CHANNEL {id: $channel})
144
+ // DELETE r
145
+ // `, {
146
+ // id,
147
+ // channel,
148
+ // });
149
+ // }
150
+
151
+ // async deleteAllRelationship(id: string, channel = '') {
152
+ // await this.graphQuery(`
153
+ // MATCH (:FLOW {id: $id})-[r:IMPLEMENTS]->(:CHANNEL)
154
+ // DELETE r
155
+ // `, {
156
+ // id,
157
+ // channel,
158
+ // });
159
+ // }
160
+
161
+ // async createRelationship(id: string, channel: string) {
162
+ // await this.graphQuery(`
163
+ // MATCH (f:FLOW {id: $id}), (c:CHANNEL {id: $channel})
164
+ // MERGE (f)-[:IMPLEMENTS]->(c)
165
+ // `, {
166
+ // id,
167
+ // channel,
168
+ // });
169
+ // }
170
+
171
+ async deleteFlow(id: string) {
172
+ await this.graphQuery(`
173
+ MATCH (flow:FLOW { id: $id })
174
+ DETACH DELETE flow
175
+ `, { id });
176
+ }
177
+
178
+ async activateFlow(flow: Flow) {
179
+ const id = flow.id;
180
+ if (id === undefined) {
181
+ throw new Error('Only flows with id can be added to the IDW graph');
182
+ }
183
+
184
+ // const channel = flow.data.meta?.idw?.channel;
185
+ // if (channel != undefined) {
186
+ // // TODO: only throw if a (:FLOW { isActive: true })-[:IMPLEMENTS]-(:CHANNEL { channel: $channel })
187
+ // const activatedFlow = await this.getActivatedFlow(channel);
188
+ // if (activatedFlow && activatedFlow.length > 0) {
189
+ // throw new Error(`Cannot activate second flow for channel ${channel}`);
190
+ // }
191
+ // }
192
+
193
+ await this.graphQuery(`
194
+ MATCH (flow:FLOW { id: $id })
195
+ SET flow.isActive = true,
196
+ flow.activatedAt = $activatedAt
197
+ RETURN flow
198
+ `, {
199
+ activatedAt: Date.now(),
200
+ id,
201
+ });
202
+ }
203
+
204
+
205
+ async deactivateFlow(id: string) {
206
+ await this.graphQuery(`
207
+ MATCH (flow:FLOW { id: $id } )
208
+ SET flow.isActive = false
209
+ REMOVE flow.activatedAt
210
+ RETURN flow
211
+ `, { id });
212
+ }
213
+
214
+ private async graphQuery(query: string, params?: Record<string, null | number | string | boolean>) {
215
+ // if 'idw' graph doesn't exist - create it
216
+ await this.checkOrCreateDb();
217
+ try {
218
+ return await this.graphApi.query({
219
+ graph: GRAPH_NAME,
220
+ params,
221
+ query,
222
+ });
223
+ } catch (e) {
224
+ // TODO: if 'idw' graph doesn't exist - create it, seed with channels data, and retry query
225
+ }
226
+ }
227
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { IDW } from './idw';
2
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { Token } from '@or-sdk/base';
2
+
3
+ export type IDWConfig = {
4
+ /**
5
+ * Account ID for cross-account requests (super admin only)
6
+ */
7
+ accountId?: string;
8
+
9
+ /**
10
+ * Url of OneReach service discovery api
11
+ */
12
+ discoveryUrl?: string;
13
+
14
+ /**
15
+ * Url of OneReach.ai Graph api
16
+ */
17
+ graphUrl?: string;
18
+
19
+ /**
20
+ * Url of OneReach.ai SDK api
21
+ */
22
+ sdkApiUrl?: string;
23
+
24
+ /**
25
+ * token
26
+ */
27
+ token: Token;
28
+ };
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.esm.json",
3
+ "compilerOptions": {
4
+ "declarationDir": "./dist/types",
5
+ "rootDir": "./src",
6
+ "declaration": true
7
+ }
8
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/esm",
5
+ "declarationDir": "./dist/types",
6
+ "module": "ES6",
7
+ "target": "es6",
8
+ "rootDir": "./src",
9
+ "declaration": true,
10
+ "declarationMap": true
11
+ }
12
+ }
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,10 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/types/",
5
+ "rootDir": "./src",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "emitDeclarationOnly": true
9
+ }
10
+ }