@or-sdk/idw 1.3.7-beta.1500.0 → 1.3.8-beta.1536.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/constants.js +2 -1
  3. package/dist/cjs/constants.js.map +1 -1
  4. package/dist/cjs/idw.js +44 -73
  5. package/dist/cjs/idw.js.map +1 -1
  6. package/dist/cjs/index.js +14 -3
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/migration-base.js +72 -0
  9. package/dist/cjs/migration-base.js.map +1 -0
  10. package/dist/cjs/migration-handler.js +183 -0
  11. package/dist/cjs/migration-handler.js.map +1 -0
  12. package/dist/cjs/migrations/Migration__1.js +108 -0
  13. package/dist/cjs/migrations/Migration__1.js.map +1 -0
  14. package/dist/cjs/migrations/Migration__2.js +155 -0
  15. package/dist/cjs/migrations/Migration__2.js.map +1 -0
  16. package/dist/cjs/migrations/Migration__3.js +108 -0
  17. package/dist/cjs/migrations/Migration__3.js.map +1 -0
  18. package/dist/cjs/migrations/index.js +13 -0
  19. package/dist/cjs/migrations/index.js.map +1 -0
  20. package/dist/esm/constants.js +1 -0
  21. package/dist/esm/constants.js.map +1 -1
  22. package/dist/esm/idw.js +24 -36
  23. package/dist/esm/idw.js.map +1 -1
  24. package/dist/esm/index.js +2 -1
  25. package/dist/esm/index.js.map +1 -1
  26. package/dist/esm/migration-base.js +30 -0
  27. package/dist/esm/migration-base.js.map +1 -0
  28. package/dist/esm/migration-handler.js +86 -0
  29. package/dist/esm/migration-handler.js.map +1 -0
  30. package/dist/esm/migrations/Migration__1.js +40 -0
  31. package/dist/esm/migrations/Migration__1.js.map +1 -0
  32. package/dist/esm/migrations/Migration__2.js +80 -0
  33. package/dist/esm/migrations/Migration__2.js.map +1 -0
  34. package/dist/esm/migrations/Migration__3.js +53 -0
  35. package/dist/esm/migrations/Migration__3.js.map +1 -0
  36. package/dist/esm/migrations/index.js +4 -0
  37. package/dist/esm/migrations/index.js.map +1 -0
  38. package/dist/types/constants.d.ts +1 -0
  39. package/dist/types/constants.d.ts.map +1 -1
  40. package/dist/types/idw.d.ts +5 -3
  41. package/dist/types/idw.d.ts.map +1 -1
  42. package/dist/types/index.d.ts +1 -1
  43. package/dist/types/index.d.ts.map +1 -1
  44. package/dist/types/migration-base.d.ts +24 -0
  45. package/dist/types/migration-base.d.ts.map +1 -0
  46. package/dist/types/migration-handler.d.ts +20 -0
  47. package/dist/types/migration-handler.d.ts.map +1 -0
  48. package/dist/types/migrations/Migration__1.d.ts +6 -0
  49. package/dist/types/migrations/Migration__1.d.ts.map +1 -0
  50. package/dist/types/migrations/Migration__2.d.ts +7 -0
  51. package/dist/types/migrations/Migration__2.d.ts.map +1 -0
  52. package/dist/types/migrations/Migration__3.d.ts +5 -0
  53. package/dist/types/migrations/Migration__3.d.ts.map +1 -0
  54. package/dist/types/migrations/index.d.ts +4 -0
  55. package/dist/types/migrations/index.d.ts.map +1 -0
  56. package/package.json +5 -3
  57. package/src/constants.ts +1 -0
  58. package/src/idw.ts +36 -36
  59. package/src/index.ts +1 -1
  60. package/src/migration-base.ts +35 -0
  61. package/src/migration-handler.ts +94 -0
  62. package/src/migrations/Migration__1.ts +33 -0
  63. package/src/{data/channels.ts → migrations/Migration__2.ts} +33 -1
  64. package/src/migrations/Migration__3.ts +45 -0
  65. package/src/migrations/index.ts +3 -0
  66. package/dist/cjs/data/channels.js +0 -41
  67. package/dist/cjs/data/channels.js.map +0 -1
  68. package/dist/cjs/data/idwSetupData.js +0 -9
  69. package/dist/cjs/data/idwSetupData.js.map +0 -1
  70. package/dist/esm/data/channels.js +0 -38
  71. package/dist/esm/data/channels.js.map +0 -1
  72. package/dist/esm/data/idwSetupData.js +0 -6
  73. package/dist/esm/data/idwSetupData.js.map +0 -1
  74. package/dist/types/data/channels.d.ts +0 -6
  75. package/dist/types/data/channels.d.ts.map +0 -1
  76. package/dist/types/data/idwSetupData.d.ts +0 -6
  77. package/dist/types/data/idwSetupData.d.ts.map +0 -1
  78. package/src/data/idwSetupData.ts +0 -5
@@ -0,0 +1,86 @@
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 { SERVICE_KEY, VERSION_PROP } from './constants';
11
+ import * as migrations from './migrations';
12
+ const PREFIX = 'Migration__';
13
+ export default class MigrationHandler {
14
+ constructor(graphApi, users, accounts, settings, accountId, flows) {
15
+ this.graphApi = graphApi;
16
+ this.users = users;
17
+ this.accounts = accounts;
18
+ this.settings = settings;
19
+ this.accountId = accountId;
20
+ this.flows = flows;
21
+ this.migrations = new Map(Object.values(migrations)
22
+ .map(ctor => [
23
+ ctor.name, new ctor(this.graphApi, this.users, this.accounts, this.settings, this.accountId, this.flows),
24
+ ]));
25
+ }
26
+ applyMigrations() {
27
+ var _a;
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const accountsLatestVersion = (_a = (yield this.findAccountsMigrationVersion())) !== null && _a !== void 0 ? _a : 0;
30
+ const migrationVersions = Array.from(this.migrations.keys()).map(migrationName => {
31
+ const [, version] = migrationName.split(PREFIX);
32
+ return Number(version);
33
+ }).sort();
34
+ for (let i = 0; i < migrationVersions.length; i++) {
35
+ if (migrationVersions[i] > accountsLatestVersion) {
36
+ const migration = this.migrations.get(PREFIX + migrationVersions[i]);
37
+ if (migration) {
38
+ try {
39
+ yield migration.up();
40
+ yield this.saveVersion(migrationVersions[i]);
41
+ }
42
+ catch (e) {
43
+ throw new Error(`Migration ${migration.constructor.name} is not applied`);
44
+ }
45
+ }
46
+ }
47
+ }
48
+ });
49
+ }
50
+ saveVersion(currentLatestVersion) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ try {
53
+ const params = {
54
+ key: `${SERVICE_KEY}.${VERSION_PROP}`,
55
+ value: currentLatestVersion,
56
+ };
57
+ yield this.settings.setAccountSettings(params);
58
+ }
59
+ catch (e) {
60
+ throw new Error(`Error while saving migration "${PREFIX + currentLatestVersion}"`);
61
+ }
62
+ });
63
+ }
64
+ deleteMigrationVersion() {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const params = {
67
+ key: `${SERVICE_KEY}.${VERSION_PROP}`,
68
+ };
69
+ yield this.settings.deleteAccountSettings(params);
70
+ });
71
+ }
72
+ findAccountsMigrationVersion() {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ try {
75
+ const params = {
76
+ key: `${SERVICE_KEY}.${VERSION_PROP}`,
77
+ };
78
+ return yield this.settings.getAccountSettings(params);
79
+ }
80
+ catch (e) {
81
+ throw new Error('Error while getting account settings');
82
+ }
83
+ });
84
+ }
85
+ }
86
+ //# sourceMappingURL=migration-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-handler.js","sourceRoot":"","sources":["../../src/migration-handler.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,40 @@
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 { MigrationBase } from '../migration-base';
11
+ const idwSetupData = {
12
+ description: 'Add a fancy description to your IDW',
13
+ role: 'You can set your IDW\'s role/s just by chatting with the embedded RWC',
14
+ avatar: 'https://files.qa.api.onereach.ai/public/03db4abe-0477-47c0-ae4e-4c68f1047d59/IDW/IDWs-media-data/Img.png',
15
+ };
16
+ export default class Migration__1 extends MigrationBase {
17
+ up() {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ yield this.checkOrSetupIDWInfo();
20
+ });
21
+ }
22
+ checkOrSetupIDWInfo() {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const accountId = yield this.resolveAccountId();
25
+ const idwData = yield this.accounts.getIdwData(accountId);
26
+ const hasIdwInfo = Boolean(idwData && idwData.name && idwData.role);
27
+ if (!hasIdwInfo) {
28
+ const { name, role, description, avatar } = idwData;
29
+ yield this.accounts.updateIdwData(accountId, {
30
+ name,
31
+ role: (role === null || role === void 0 ? void 0 : role.trim()) || idwSetupData.role,
32
+ description: (description === null || description === void 0 ? void 0 : description.trim()) || idwSetupData.description,
33
+ avatar: (avatar === null || avatar === void 0 ? void 0 : avatar.trim()) || idwSetupData.avatar,
34
+ });
35
+ return new Promise(res => setTimeout(res, 60000));
36
+ }
37
+ });
38
+ }
39
+ }
40
+ //# sourceMappingURL=Migration__1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration__1.js","sourceRoot":"","sources":["../../../src/migrations/Migration__1.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,YAAY,GAAG;IACnB,WAAW,EAAE,qCAAqC;IAClD,IAAI,EAAE,uEAAuE;IAC7E,MAAM,EAAE,0GAA0G;CACnH,CAAC;AAGF,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,aAAa;IAC/C,EAAE;;YACN,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACnC,CAAC;KAAA;IAEK,mBAAmB;;YACvB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAChD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YAC1D,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;YAEpE,IAAI,CAAC,UAAU,EAAE;gBACf,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;gBACpD,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE;oBAC3C,IAAI;oBAEJ,IAAI,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,KAAI,YAAY,CAAC,IAAI;oBACvC,WAAW,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,IAAI,EAAE,KAAI,YAAY,CAAC,WAAW;oBAC5D,MAAM,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAE,KAAI,YAAY,CAAC,MAAM;iBAC9C,CAAC,CAAC;gBAEH,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;aACnD;QACH,CAAC;KAAA;CACF"}
@@ -0,0 +1,80 @@
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 { GRAPH_NAME } from '../constants';
11
+ import { MigrationBase } from '../migration-base';
12
+ const startUpChannels = [
13
+ {
14
+ id: 'facebook-messenger',
15
+ name: 'Facebook Messenger',
16
+ icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/messenger.png',
17
+ },
18
+ {
19
+ id: 'sms',
20
+ name: 'SMS',
21
+ icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/sms.png',
22
+ },
23
+ {
24
+ id: 'telegram',
25
+ name: 'Telegram',
26
+ icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/telegram.png',
27
+ },
28
+ {
29
+ id: 'twitter',
30
+ name: 'Twitter',
31
+ icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/twitter.png',
32
+ },
33
+ {
34
+ id: 'viber',
35
+ name: 'Viber',
36
+ icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/viber.png',
37
+ },
38
+ {
39
+ id: 'viber-business',
40
+ name: 'Viber Business',
41
+ icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/viber.png',
42
+ },
43
+ {
44
+ id: 'whatsapp',
45
+ name: 'WhatsApp',
46
+ icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/whatsapp.png',
47
+ },
48
+ ];
49
+ export default class Migration__2 extends MigrationBase {
50
+ up() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const channelsExist = yield this.checkIfChannelsExist();
53
+ if (!channelsExist) {
54
+ yield this.createChannels();
55
+ }
56
+ });
57
+ }
58
+ createChannels() {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ yield this.graphApi.query({
61
+ graph: GRAPH_NAME,
62
+ query: `CREATE ${startUpChannels.map(({ id, name, icon }) => {
63
+ return `(:CHANNEL {id: '${id}', name: '${name}', icon: '${icon}'})`;
64
+ }).join(', ')}`,
65
+ params: {},
66
+ });
67
+ });
68
+ }
69
+ checkIfChannelsExist() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const [data] = yield this.graphApi.query({
72
+ graph: GRAPH_NAME,
73
+ query: 'MATCH (channels: CHANNEL) RETURN collect(DISTINCT channels) as channels',
74
+ params: {},
75
+ });
76
+ return data.channels.length > 0;
77
+ });
78
+ }
79
+ }
80
+ //# sourceMappingURL=Migration__2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration__2.js","sourceRoot":"","sources":["../../../src/migrations/Migration__2.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,eAAe,GAAG;IACtB;QACE,EAAE,EAAE,oBAAoB;QACxB,IAAI,EAAE,oBAAoB;QAC1B,IAAI,EAAE,0GAA0G;KACjH;IACD;QACE,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,oGAAoG;KAC3G;IACD;QACE,EAAE,EAAE,UAAU;QACd,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,yGAAyG;KAChH;IACD;QACE,EAAE,EAAE,SAAS;QACb,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,wGAAwG;KAC/G;IACD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,sGAAsG;KAC7G;IACD;QACE,EAAE,EAAE,gBAAgB;QACpB,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,sGAAsG;KAC7G;IACD;QACE,EAAE,EAAE,UAAU;QACd,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,yGAAyG;KAChH;CACF,CAAC;AAGF,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,aAAa;IAC/C,EAAE;;YACN,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACxD,IAAI,CAAC,aAAa,EAAE;gBAClB,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;aAC7B;QACH,CAAC;KAAA;IAEa,cAAc;;YAC1B,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;gBACxB,KAAK,EAAE,UAAU;gBACjB,KAAK,EAAE,UAAU,eAAe,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE;oBAC1D,OAAO,mBAAmB,EAAE,aAAa,IAAI,aAAa,IAAI,KAAK,CAAC;gBACtE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBACf,MAAM,EAAE,EAAE;aACX,CAAC,CAAC;QACL,CAAC;KAAA;IAEa,oBAAoB;;YAChC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAuB;gBAC7D,KAAK,EAAE,UAAU;gBACjB,KAAK,EAAE,yEAAyE;gBAChF,MAAM,EAAE,EAAE;aACX,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QAClC,CAAC;KAAA;CACF"}
@@ -0,0 +1,53 @@
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 { MigrationBase } from '../migration-base';
11
+ import { GRAPH_NAME } from '../constants';
12
+ export default class Migration__3 extends MigrationBase {
13
+ up() {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const flowsIds = yield this.graphApi.query({
16
+ graph: GRAPH_NAME,
17
+ query: `match (flow: FLOW)
18
+ where flow.steps is NULL
19
+ return flow.id as id
20
+ `,
21
+ params: {},
22
+ });
23
+ if (flowsIds.length) {
24
+ const preparedIds = flowsIds.map(f => f.id);
25
+ const flows = yield this.flows.listFlows({
26
+ query: {
27
+ id: preparedIds,
28
+ },
29
+ projection: ['data.trees.main.steps'],
30
+ });
31
+ const pairs = flows.items.map(flow => {
32
+ var _a, _b, _c;
33
+ return ({
34
+ steps: (_c = (_b = (_a = flow.data.trees) === null || _a === void 0 ? void 0 : _a.main.steps) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0,
35
+ id: flow.id,
36
+ });
37
+ });
38
+ yield this.graphApi.query({
39
+ graph: GRAPH_NAME,
40
+ query: `
41
+ unwind $list as pairs
42
+ MERGE (flow:FLOW { id: pairs.id })
43
+ SET flow.steps = pairs.steps
44
+ `,
45
+ params: {
46
+ list: pairs,
47
+ },
48
+ });
49
+ }
50
+ });
51
+ }
52
+ }
53
+ //# sourceMappingURL=Migration__3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration__3.js","sourceRoot":"","sources":["../../../src/migrations/Migration__3.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,aAAa;IAC/C,EAAE;;YACN,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAgB;gBACxD,KAAK,EAAE,UAAU;gBACjB,KAAK,EAAE;;;eAGE;gBACT,MAAM,EAAE,EAAE;aACX,CAAC,CAAC;YAEH,IAAI,QAAQ,CAAC,MAAM,EAAE;gBACnB,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBAC5C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;oBACvC,KAAK,EAAE;wBACL,EAAE,EAAE,WAAW;qBAChB;oBACD,UAAU,EAAE,CAAC,uBAAuB,CAAC;iBACtC,CAAC,CAAC;gBAEH,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;;oBAAC,OAAA,CACpC;wBACE,KAAK,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,IAAI,CAAC,KAAK,0CAAE,MAAM,mCAAI,CAAC;wBAC/C,EAAE,EAAE,IAAI,CAAC,EAAE;qBACZ,CAAC,CAAA;iBAAA,CACH,CAAC;gBAEF,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;oBACxB,KAAK,EAAE,UAAU;oBACjB,KAAK,EAAE;;;;eAIA;oBACP,MAAM,EAAE;wBACN,IAAI,EAAE,KAAY;qBACnB;iBACF,CAAC,CAAC;aACJ;QACH,CAAC;KAAA;CACF"}
@@ -0,0 +1,4 @@
1
+ export { default as Migration__1 } from './Migration__1';
2
+ export { default as Migration__2 } from './Migration__2';
3
+ export { default as Migration__3 } from './Migration__3';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/migrations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export declare const GRAPH_NAME = "idw";
2
2
  export declare const SERVICE_KEY = "idw";
3
+ export declare const VERSION_PROP = "idwMigrationVersion";
3
4
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +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"}
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;AACjC,eAAO,MAAM,YAAY,wBAAwB,CAAC"}
@@ -1,16 +1,18 @@
1
1
  import { Base } from '@or-sdk/base';
2
- import { Flow } from '@or-sdk/deployer';
3
2
  import { IDWConfig } from './types';
3
+ import { Flow } from '@or-sdk/deployer';
4
4
  export declare class IDW extends Base {
5
5
  private readonly graphApi;
6
6
  private readonly users;
7
7
  private readonly accounts;
8
+ private readonly settings;
9
+ private readonly flows;
8
10
  private accountId;
11
+ private migrationHandler;
9
12
  constructor(params: IDWConfig);
13
+ runMigrations(): Promise<void>;
10
14
  checkOrCreateDb(): Promise<void>;
11
- private resolveAccountId;
12
15
  private createDb;
13
- checkOrSetupIDWInfo(): Promise<void>;
14
16
  createOrUpdateFlow(flow: Flow): Promise<void>;
15
17
  deleteFlow(id: string): Promise<void>;
16
18
  activateFlow(flow: Flow): Promise<void>;
@@ -1 +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;AAKxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAWpC,qBAAa,GAAI,SAAQ,IAAI;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,SAAS,CAAqB;gBAa1B,MAAM,EAAE,SAAS;IAsCvB,eAAe;YAUP,gBAAgB;YAQhB,QAAQ;IAWhB,mBAAmB;IAanB,kBAAkB,CAAC,IAAI,EAAE,IAAI;IAgF7B,UAAU,CAAC,EAAE,EAAE,MAAM;IAOrB,YAAY,CAAC,IAAI,EAAE,IAAI;IA8CvB,cAAc,CAAC,EAAE,EAAE,MAAM;YAajB,UAAU;CAoBzB"}
1
+ {"version":3,"file":"idw.d.ts","sourceRoot":"","sources":["../../src/idw.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAKpC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AASxC,qBAAa,GAAI,SAAQ,IAAI;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,gBAAgB,CAAmB;gBAa/B,MAAM,EAAE,SAAS;IAsDvB,aAAa;IAIb,eAAe;YAYP,QAAQ;IAIhB,kBAAkB,CAAC,IAAI,EAAE,IAAI;IAmF7B,UAAU,CAAC,EAAE,EAAE,MAAM;IAOrB,YAAY,CAAC,IAAI,EAAE,IAAI;IA8CvB,cAAc,CAAC,EAAE,EAAE,MAAM;YAajB,UAAU;CAoBzB"}
@@ -1,4 +1,4 @@
1
1
  export { IDW } from './idw';
2
2
  export * from './types';
3
- export { startUpChannels } from './data/channels';
3
+ export * as migrations from './migrations';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
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;AACxB,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { Accounts } from '@or-sdk/accounts';
2
+ import { Graphs } from '@or-sdk/graph';
3
+ import { Settings } from '@or-sdk/settings';
4
+ import { Users } from '@or-sdk/users';
5
+ import { Flows } from '@or-sdk/flows';
6
+ export interface MigrationsParams {
7
+ graphApi: Graphs;
8
+ users: Users;
9
+ accounts: Accounts;
10
+ settings: Settings;
11
+ accountId: string | undefined;
12
+ }
13
+ export declare abstract class MigrationBase {
14
+ protected graphApi: Graphs;
15
+ protected users: Users;
16
+ protected accounts: Accounts;
17
+ protected settings: Settings;
18
+ protected accountId: string | undefined;
19
+ protected flows: Flows;
20
+ constructor(graphApi: Graphs, users: Users, accounts: Accounts, settings: Settings, accountId: string | undefined, flows: Flows);
21
+ abstract up(): Promise<void>;
22
+ protected resolveAccountId(): Promise<string>;
23
+ }
24
+ //# sourceMappingURL=migration-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-base.d.ts","sourceRoot":"","sources":["../../src/migration-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B;AAED,8BAAsB,aAAa;IAE/B,SAAS,CAAC,QAAQ,EAAE,MAAM;IAC1B,SAAS,CAAC,KAAK,EAAE,KAAK;IACtB,SAAS,CAAC,QAAQ,EAAE,QAAQ;IAC5B,SAAS,CAAC,QAAQ,EAAE,QAAQ;IAC5B,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;IACvC,SAAS,CAAC,KAAK,EAAE,KAAK;gBALZ,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,KAAK,EAAE,KAAK;IAIxB,QAAQ,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;cAEZ,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;CAOpD"}
@@ -0,0 +1,20 @@
1
+ import { Accounts } from '@or-sdk/accounts';
2
+ import { Graphs } from '@or-sdk/graph';
3
+ import { Users } from '@or-sdk/users';
4
+ import { Settings } from '@or-sdk/settings';
5
+ import { Flows } from '@or-sdk/flows';
6
+ export default class MigrationHandler {
7
+ private graphApi;
8
+ private users;
9
+ private accounts;
10
+ private settings;
11
+ private accountId;
12
+ private flows;
13
+ private migrations;
14
+ constructor(graphApi: Graphs, users: Users, accounts: Accounts, settings: Settings, accountId: string | undefined, flows: Flows);
15
+ applyMigrations(): Promise<void>;
16
+ saveVersion(currentLatestVersion: number): Promise<void>;
17
+ deleteMigrationVersion(): Promise<void>;
18
+ findAccountsMigrationVersion(): Promise<any>;
19
+ }
20
+ //# sourceMappingURL=migration-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-handler.d.ts","sourceRoot":"","sources":["../../src/migration-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAA6B,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIvE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAItC,MAAM,CAAC,OAAO,OAAO,gBAAgB;IAIjC,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK;IARf,OAAO,CAAC,UAAU,CAA6B;gBAGrC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,KAAK,EAAE,KAAK;IAkBhB,eAAe;IAwBf,WAAW,CAAC,oBAAoB,EAAE,MAAM;IAaxC,sBAAsB;IAOtB,4BAA4B;CAWnC"}
@@ -0,0 +1,6 @@
1
+ import { MigrationBase } from '../migration-base';
2
+ export default class Migration__1 extends MigrationBase {
3
+ up(): Promise<void>;
4
+ checkOrSetupIDWInfo(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=Migration__1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration__1.d.ts","sourceRoot":"","sources":["../../../src/migrations/Migration__1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AASlD,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,aAAa;IAC/C,EAAE;IAIF,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;CAkB3C"}
@@ -0,0 +1,7 @@
1
+ import { MigrationBase } from '../migration-base';
2
+ export default class Migration__2 extends MigrationBase {
3
+ up(): Promise<void>;
4
+ private createChannels;
5
+ private checkIfChannelsExist;
6
+ }
7
+ //# sourceMappingURL=Migration__2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration__2.d.ts","sourceRoot":"","sources":["../../../src/migrations/Migration__2.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAyClD,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,aAAa;IAC/C,EAAE;YAOM,cAAc;YAUd,oBAAoB;CAQnC"}
@@ -0,0 +1,5 @@
1
+ import { MigrationBase } from '../migration-base';
2
+ export default class Migration__3 extends MigrationBase {
3
+ up(): Promise<void>;
4
+ }
5
+ //# sourceMappingURL=Migration__3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration__3.d.ts","sourceRoot":"","sources":["../../../src/migrations/Migration__3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,aAAa;IAC/C,EAAE;CAuCT"}
@@ -0,0 +1,4 @@
1
+ export { default as Migration__1 } from './Migration__1';
2
+ export { default as Migration__2 } from './Migration__2';
3
+ export { default as Migration__3 } from './Migration__3';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.7-beta.1500.0",
2
+ "version": "1.3.8-beta.1536.0",
3
3
  "name": "@or-sdk/idw",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
@@ -24,10 +24,12 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@or-sdk/accounts": "^1.2.12",
27
+ "@or-sdk/accounts": "^1.2.13",
28
28
  "@or-sdk/base": "^0.28.3",
29
- "@or-sdk/deployer": "^1.1.6-beta.1500.0",
29
+ "@or-sdk/deployer": "^1.1.5",
30
+ "@or-sdk/flows": "^2.0.2",
30
31
  "@or-sdk/graph": "^1.4.1",
32
+ "@or-sdk/settings": "^0.24.11",
31
33
  "@or-sdk/users": "^0.30.2",
32
34
  "axios": "^0.24.0"
33
35
  }
package/src/constants.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export const GRAPH_NAME = 'idw';
2
2
  export const SERVICE_KEY = 'idw';
3
+ export const VERSION_PROP = 'idwMigrationVersion';
package/src/idw.ts CHANGED
@@ -1,13 +1,13 @@
1
+ import { Settings } from '@or-sdk/settings';
1
2
  import { Base } from '@or-sdk/base';
2
- import { Flow } from '@or-sdk/deployer';
3
3
  import { Graphs } from '@or-sdk/graph';
4
4
  import { Users } from '@or-sdk/users';
5
5
  import { Accounts } from '@or-sdk/accounts';
6
6
  import { GRAPH_NAME, SERVICE_KEY } from './constants';
7
7
  import { IDWConfig } from './types';
8
- import { startUpChannels } from './data/channels';
9
- import { idwSetupData } from './data/idwSetupData';
10
-
8
+ import MigrationHandler from './migration-handler';
9
+ import { Flow } from '@or-sdk/deployer';
10
+ import { Flows } from '@or-sdk/flows';
11
11
  /**
12
12
  * OneReach IDW service client
13
13
  * ## Installation:
@@ -19,7 +19,10 @@ export class IDW extends Base {
19
19
  private readonly graphApi: Graphs;
20
20
  private readonly users: Users;
21
21
  private readonly accounts: Accounts;
22
+ private readonly settings: Settings;
23
+ private readonly flows: Flows;
22
24
  private accountId: string | undefined;
25
+ private migrationHandler: MigrationHandler;
23
26
 
24
27
  /**
25
28
  * ```typescript
@@ -65,51 +68,45 @@ export class IDW extends Base {
65
68
  discoveryUrl,
66
69
  sdkUrl: sdkApiUrl,
67
70
  });
71
+ this.settings = new Settings({
72
+ token,
73
+ sdkUrl: sdkApiUrl,
74
+ });
75
+ this.flows = new Flows({
76
+ token,
77
+ discoveryUrl,
78
+ });
68
79
 
69
80
  this.accountId = accountId;
81
+
82
+ this.migrationHandler = new MigrationHandler(
83
+ this.graphApi,
84
+ this.users,
85
+ this.accounts,
86
+ this.settings,
87
+ this.accountId,
88
+ this.flows
89
+ );
70
90
  }
71
91
 
92
+ async runMigrations() {
93
+ await this.migrationHandler.applyMigrations();
94
+ }
72
95
 
73
96
  async checkOrCreateDb() {
74
97
  try {
75
98
  await this.graphApi.getGraphInfo(GRAPH_NAME);
76
99
  } catch (e) {
77
100
  this.createDb();
78
- // TODO: this should be removed after chat starts handling this part
79
- this.checkOrSetupIDWInfo();
101
+ // TODO: This function removes account setting storing the migration version
102
+ // to apply all migrations after creating db.
103
+ // Will be moved to the backend.
104
+ this.migrationHandler.deleteMigrationVersion();
80
105
  }
81
106
  }
82
107
 
83
- private async resolveAccountId(): Promise<string> {
84
- return this.accountId ?? (async () => {
85
- const { accountId } = await this.users.getCurrentUser();
86
- this.accountId = accountId;
87
- return accountId;
88
- })();
89
- }
90
-
91
108
  private async createDb() {
92
109
  await this.graphApi.createGraph({ name: GRAPH_NAME });
93
- await this.graphApi.query({
94
- graph: GRAPH_NAME,
95
- query: `CREATE ${startUpChannels.map(({ id, name, icon }) => {
96
- return `(:CHANNEL {id: '${id}', name: '${name}', icon: '${icon}'})`;
97
- }).join(', ')}`,
98
- params: {},
99
- });
100
- }
101
-
102
- async checkOrSetupIDWInfo() {
103
- const accountId = await this.resolveAccountId();
104
- const { name, role, description, avatar } = await this.accounts.getIdwData(accountId);
105
- const idwData = {
106
- name,
107
- // using || instead of ?? to replace empty strings
108
- role: role?.trim() || idwSetupData.role,
109
- description: description?.trim() || idwSetupData.description,
110
- avatar: avatar?.trim() || idwSetupData.avatar,
111
- };
112
- await this.accounts.updateIdwData(accountId, idwData);
113
110
  }
114
111
 
115
112
  async createOrUpdateFlow(flow: Flow) {
@@ -134,6 +131,7 @@ export class IDW extends Base {
134
131
  flow.name = $name,
135
132
  flow.updatedAt = $updatedAt,
136
133
  flow.updatedBy = $username
134
+ flow.steps = $steps
137
135
  ON CREATE
138
136
  SET flow.createdAt = $createdAt,
139
137
  flow.createdBy = $userId,
@@ -143,6 +141,7 @@ export class IDW extends Base {
143
141
  flow.name = $name,
144
142
  flow.updatedAt = $updatedAt,
145
143
  flow.updatedBy = $username
144
+ flow.steps = $steps
146
145
  RETURN flow
147
146
  `, {
148
147
  createdAt: flow.dateCreated,
@@ -153,6 +152,7 @@ export class IDW extends Base {
153
152
  updatedAt: flow.dateModified,
154
153
  username,
155
154
  userId,
155
+ steps: flow.data.trees?.main?.steps?.length ?? 0,
156
156
  });
157
157
 
158
158
  await this.graphQuery(`
@@ -163,7 +163,7 @@ export class IDW extends Base {
163
163
  `, { id });
164
164
 
165
165
  const channel = flow.data.meta.idw?.channel;
166
- const skills = flow.data.meta.idw?.skills;
166
+ const skills: string[] | undefined = flow.data.meta.idw?.skills;
167
167
 
168
168
  if (channel !== undefined && channel.length !== 0) {
169
169
  await this.graphQuery(`
@@ -218,7 +218,7 @@ export class IDW extends Base {
218
218
  });
219
219
 
220
220
  const channel = flow.data.meta.idw?.channel;
221
- const skills = flow.data.meta.idw?.skills;
221
+ const skills: string[] | undefined = flow.data.meta.idw?.skills;
222
222
 
223
223
  if (channel !== undefined && channel.length !== 0) {
224
224
  await this.graphQuery(`
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { IDW } from './idw';
2
2
  export * from './types';
3
- export { startUpChannels } from './data/channels';
3
+ export * as migrations from './migrations';