@or-sdk/idw 1.3.7-beta.1499.0 → 1.4.0-beta.1525.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 (70) hide show
  1. package/dist/cjs/constants.js +2 -1
  2. package/dist/cjs/constants.js.map +1 -1
  3. package/dist/cjs/idw.js +23 -58
  4. package/dist/cjs/idw.js.map +1 -1
  5. package/dist/cjs/index.js +14 -3
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/migration-base.js +15 -0
  8. package/dist/cjs/migration-base.js.map +1 -0
  9. package/dist/cjs/migration-handler.js +188 -0
  10. package/dist/cjs/migration-handler.js.map +1 -0
  11. package/dist/cjs/migrations/Migration__1.js +147 -0
  12. package/dist/cjs/migrations/Migration__1.js.map +1 -0
  13. package/dist/cjs/migrations/Migration__2.js +155 -0
  14. package/dist/cjs/migrations/Migration__2.js.map +1 -0
  15. package/dist/cjs/migrations/index.js +11 -0
  16. package/dist/cjs/migrations/index.js.map +1 -0
  17. package/dist/esm/constants.js +1 -0
  18. package/dist/esm/constants.js.map +1 -1
  19. package/dist/esm/idw.js +13 -33
  20. package/dist/esm/idw.js.map +1 -1
  21. package/dist/esm/index.js +2 -1
  22. package/dist/esm/index.js.map +1 -1
  23. package/dist/esm/migration-base.js +10 -0
  24. package/dist/esm/migration-base.js.map +1 -0
  25. package/dist/esm/migration-handler.js +89 -0
  26. package/dist/esm/migration-handler.js.map +1 -0
  27. package/dist/esm/migrations/Migration__1.js +56 -0
  28. package/dist/esm/migrations/Migration__1.js.map +1 -0
  29. package/dist/esm/migrations/Migration__2.js +80 -0
  30. package/dist/esm/migrations/Migration__2.js.map +1 -0
  31. package/dist/esm/migrations/index.js +3 -0
  32. package/dist/esm/migrations/index.js.map +1 -0
  33. package/dist/types/constants.d.ts +1 -0
  34. package/dist/types/constants.d.ts.map +1 -1
  35. package/dist/types/idw.d.ts +4 -3
  36. package/dist/types/idw.d.ts.map +1 -1
  37. package/dist/types/index.d.ts +1 -1
  38. package/dist/types/index.d.ts.map +1 -1
  39. package/dist/types/migration-base.d.ts +21 -0
  40. package/dist/types/migration-base.d.ts.map +1 -0
  41. package/dist/types/migration-handler.d.ts +18 -0
  42. package/dist/types/migration-handler.d.ts.map +1 -0
  43. package/dist/types/migrations/Migration__1.d.ts +8 -0
  44. package/dist/types/migrations/Migration__1.d.ts.map +1 -0
  45. package/dist/types/migrations/Migration__2.d.ts +7 -0
  46. package/dist/types/migrations/Migration__2.d.ts.map +1 -0
  47. package/dist/types/migrations/index.d.ts +3 -0
  48. package/dist/types/migrations/index.d.ts.map +1 -0
  49. package/package.json +4 -3
  50. package/src/constants.ts +1 -0
  51. package/src/idw.ts +26 -36
  52. package/src/index.ts +1 -1
  53. package/src/migration-base.ts +30 -0
  54. package/src/migration-handler.ts +84 -0
  55. package/src/migrations/Migration__1.ts +44 -0
  56. package/src/{data/channels.ts → migrations/Migration__2.ts} +33 -1
  57. package/src/migrations/index.ts +2 -0
  58. package/dist/cjs/data/channels.js +0 -41
  59. package/dist/cjs/data/channels.js.map +0 -1
  60. package/dist/cjs/data/idwSetupData.js +0 -9
  61. package/dist/cjs/data/idwSetupData.js.map +0 -1
  62. package/dist/esm/data/channels.js +0 -38
  63. package/dist/esm/data/channels.js.map +0 -1
  64. package/dist/esm/data/idwSetupData.js +0 -6
  65. package/dist/esm/data/idwSetupData.js.map +0 -1
  66. package/dist/types/data/channels.d.ts +0 -6
  67. package/dist/types/data/channels.d.ts.map +0 -1
  68. package/dist/types/data/idwSetupData.d.ts +0 -6
  69. package/dist/types/data/idwSetupData.d.ts.map +0 -1
  70. package/src/data/idwSetupData.ts +0 -5
@@ -0,0 +1,21 @@
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
+ export interface MigrationsParams {
6
+ graphApi: Graphs;
7
+ users: Users;
8
+ accounts: Accounts;
9
+ settings: Settings;
10
+ accountId: string | undefined;
11
+ }
12
+ export declare abstract class MigrationBase {
13
+ protected graphApi: Graphs;
14
+ protected users: Users;
15
+ protected accounts: Accounts;
16
+ protected settings: Settings;
17
+ protected accountId: string | undefined;
18
+ constructor(params: MigrationsParams);
19
+ abstract up(): Promise<void>;
20
+ }
21
+ //# 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;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;IACjC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IACvB,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC7B,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC7B,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE5B,MAAM,EAAE,gBAAgB;IAQpC,QAAQ,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;CAC7B"}
@@ -0,0 +1,18 @@
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
+ export default class MigrationHandler {
6
+ private graphApi;
7
+ private users;
8
+ private accounts;
9
+ private settings;
10
+ private accountId;
11
+ private migrations;
12
+ constructor(graphApi: Graphs, users: Users, accounts: Accounts, settings: Settings, accountId: string | undefined);
13
+ applyMigrations(): Promise<void>;
14
+ saveVersion(currentLatestVersion: string): Promise<void>;
15
+ deleteMigrationVersion(): Promise<void>;
16
+ findAccountsMigrationVersion(): Promise<any>;
17
+ }
18
+ //# 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,EAA6E,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAOvH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IAGvB,OAAO,CAAC,QAAQ;IAAU,OAAO,CAAC,KAAK;IAAS,OAAO,CAAC,QAAQ;IAC1E,OAAO,CAAC,QAAQ;IAAY,OAAO,CAAC,SAAS;IAH/C,OAAO,CAAC,UAAU,CAA6B;gBAE3B,QAAQ,EAAE,MAAM,EAAU,KAAK,EAAE,KAAK,EAAU,QAAQ,EAAE,QAAQ,EAC5E,QAAQ,EAAE,QAAQ,EAAU,SAAS,EAAE,MAAM,GAAG,SAAS;IAY7D,eAAe;IA0Bf,WAAW,CAAC,oBAAoB,EAAE,MAAM;IAaxC,sBAAsB;IAOtB,4BAA4B;CAWnC"}
@@ -0,0 +1,8 @@
1
+ import { MigrationBase } from '../migration-base';
2
+ export default class Migration__1 extends MigrationBase {
3
+ up(): Promise<void>;
4
+ private resolveAccountId;
5
+ checkOrSetupIDWInfo(): Promise<void>;
6
+ checkIfIDWInfoExists(): Promise<boolean>;
7
+ }
8
+ //# 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;YAOM,gBAAgB;IAQxB,mBAAmB;IAanB,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC;CAK/C"}
@@ -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,3 @@
1
+ export { default as Migration__1 } from './Migration__1';
2
+ export { default as Migration__2 } from './Migration__2';
3
+ //# 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"}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.7-beta.1499.0",
2
+ "version": "1.4.0-beta.1525.0",
3
3
  "name": "@or-sdk/idw",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
@@ -24,10 +24,11 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@or-sdk/accounts": "^1.2.12",
27
+ "@or-sdk/accounts": "^1.3.0-beta.1525.0",
28
28
  "@or-sdk/base": "^0.28.3",
29
- "@or-sdk/deployer": "^1.1.6-beta.1499.0",
29
+ "@or-sdk/deployer": "^1.1.5",
30
30
  "@or-sdk/graph": "^1.4.1",
31
+ "@or-sdk/settings": "^0.24.11",
31
32
  "@or-sdk/users": "^0.30.2",
32
33
  "axios": "^0.24.0"
33
34
  }
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,12 @@
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';
11
10
  /**
12
11
  * OneReach IDW service client
13
12
  * ## Installation:
@@ -19,7 +18,9 @@ export class IDW extends Base {
19
18
  private readonly graphApi: Graphs;
20
19
  private readonly users: Users;
21
20
  private readonly accounts: Accounts;
21
+ private readonly settings: Settings;
22
22
  private accountId: string | undefined;
23
+ private migrationHandler: MigrationHandler;
23
24
 
24
25
  /**
25
26
  * ```typescript
@@ -65,51 +66,40 @@ export class IDW extends Base {
65
66
  discoveryUrl,
66
67
  sdkUrl: sdkApiUrl,
67
68
  });
69
+ this.settings = new Settings({
70
+ token,
71
+ sdkUrl: sdkApiUrl,
72
+ });
68
73
 
69
74
  this.accountId = accountId;
75
+
76
+ this.migrationHandler = new MigrationHandler(
77
+ this.graphApi,
78
+ this.users,
79
+ this.accounts,
80
+ this.settings,
81
+ this.accountId
82
+ );
70
83
  }
71
84
 
85
+ async runMigrations() {
86
+ await this.migrationHandler.applyMigrations();
87
+ }
72
88
 
73
89
  async checkOrCreateDb() {
74
90
  try {
75
91
  await this.graphApi.getGraphInfo(GRAPH_NAME);
76
92
  } catch (e) {
77
93
  this.createDb();
78
- // TODO: this should be removed after chat starts handling this part
79
- this.checkOrSetupIDWInfo();
94
+ // TODO: This function removes account setting storing the migration version
95
+ // to apply all migrations after creating db.
96
+ // Will be moved to the backend.
97
+ this.migrationHandler.deleteMigrationVersion();
80
98
  }
81
99
  }
82
100
 
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
101
  private async createDb() {
92
102
  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
103
  }
114
104
 
115
105
  async createOrUpdateFlow(flow: Flow) {
@@ -163,7 +153,7 @@ export class IDW extends Base {
163
153
  `, { id });
164
154
 
165
155
  const channel = flow.data.meta.idw?.channel;
166
- const skills = flow.data.meta.idw?.skills;
156
+ const skills: string[] | undefined = flow.data.meta.idw?.skills;
167
157
 
168
158
  if (channel !== undefined && channel.length !== 0) {
169
159
  await this.graphQuery(`
@@ -218,7 +208,7 @@ export class IDW extends Base {
218
208
  });
219
209
 
220
210
  const channel = flow.data.meta.idw?.channel;
221
- const skills = flow.data.meta.idw?.skills;
211
+ const skills: string[] | undefined = flow.data.meta.idw?.skills;
222
212
 
223
213
  if (channel !== undefined && channel.length !== 0) {
224
214
  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';
@@ -0,0 +1,30 @@
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
+
6
+ export interface MigrationsParams {
7
+ graphApi: Graphs;
8
+ users: Users;
9
+ accounts: Accounts;
10
+ settings: Settings;
11
+ accountId: string | undefined;
12
+ }
13
+
14
+ export abstract class MigrationBase {
15
+ protected graphApi: Graphs;
16
+ protected users: Users;
17
+ protected accounts: Accounts;
18
+ protected settings: Settings;
19
+ protected accountId: string | undefined;
20
+
21
+ constructor(params: MigrationsParams) {
22
+ this.graphApi = params.graphApi;
23
+ this.users = params.users;
24
+ this.accounts = params.accounts;
25
+ this.settings = params.settings;
26
+ this.accountId = params.accountId;
27
+ }
28
+
29
+ abstract up(): Promise<void>;
30
+ }
@@ -0,0 +1,84 @@
1
+ import { Accounts } from '@or-sdk/accounts';
2
+ import { Graphs } from '@or-sdk/graph';
3
+ import { Users } from '@or-sdk/users';
4
+ import { AccountRouteDeletePayload, AccountRouteGetPayload, AccountRouteSetPayload, Settings } from '@or-sdk/settings';
5
+ import { MigrationBase } from './migration-base';
6
+ import { VERSION_PROP } from './constants';
7
+ import * as migrations from './migrations';
8
+
9
+ const PREFIX = 'Migration__';
10
+
11
+ export default class MigrationHandler {
12
+ private migrations: Map<string, MigrationBase>;
13
+
14
+ constructor(private graphApi: Graphs, private users: Users, private accounts: Accounts,
15
+ private settings: Settings, private accountId: string | undefined) {
16
+ const params = {
17
+ graphApi,
18
+ users,
19
+ accounts,
20
+ settings,
21
+ accountId,
22
+ };
23
+
24
+ this.migrations = new Map(Object.values(migrations).map(ctor => [ctor.name, new ctor(params)]));
25
+ }
26
+
27
+ async applyMigrations() {
28
+ const accountsLatestVersion = await this.findAccountsMigrationVersion();
29
+
30
+ const migrationVersions = Array.from(this.migrations.keys()).map(migrationName => {
31
+ const [, version] = migrationName.split(PREFIX);
32
+ return version;
33
+ }).sort();
34
+
35
+ for (let i = 0;i < migrationVersions.length;i++) {
36
+ if (migrationVersions[i] <= accountsLatestVersion) {
37
+ continue;
38
+ }
39
+
40
+ const migration = this.migrations.get(PREFIX + migrationVersions[i]);
41
+ if (migration) {
42
+ try {
43
+ await migration.up();
44
+ await this.saveVersion(migrationVersions[i]);
45
+
46
+ } catch (e) {
47
+ throw new Error(`Migration ${migration.constructor.name} is not applied`);
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ async saveVersion(currentLatestVersion: string) {
54
+ try {
55
+ const params = {
56
+ key: VERSION_PROP,
57
+ value: currentLatestVersion,
58
+ } as AccountRouteSetPayload;
59
+ await this.settings.setAccountSettings(params);
60
+ } catch (e) {
61
+ // eslint-disable-next-line no-console
62
+ console.log(e);
63
+ }
64
+ }
65
+
66
+ async deleteMigrationVersion() {
67
+ const params = {
68
+ key: VERSION_PROP,
69
+ } as AccountRouteDeletePayload;
70
+ await this.settings.deleteAccountSettings(params);
71
+ }
72
+
73
+ async findAccountsMigrationVersion() {
74
+ try {
75
+ const params: Record<string, AccountRouteGetPayload> = {
76
+ key: VERSION_PROP as AccountRouteGetPayload,
77
+ };
78
+ return await this.settings.getAccountSettings(params);
79
+ } catch (e) {
80
+ // eslint-disable-next-line no-console
81
+ console.log(e);
82
+ }
83
+ }
84
+ }
@@ -0,0 +1,44 @@
1
+ import { MigrationBase } from '../migration-base';
2
+
3
+ const idwSetupData = {
4
+ description: 'Add a fancy description to your IDW',
5
+ role: 'You can set your IDW\'s role/s just by chatting with the embedded RWC',
6
+ avatar: 'https://files.qa.api.onereach.ai/public/03db4abe-0477-47c0-ae4e-4c68f1047d59/IDW/IDWs-media-data/Img.png',
7
+ };
8
+
9
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
+ export default class Migration__1 extends MigrationBase {
11
+ async up() {
12
+ const idwDataExists = await this.checkIfIDWInfoExists();
13
+ if (!idwDataExists) {
14
+ await this.checkOrSetupIDWInfo();
15
+ }
16
+ }
17
+
18
+ private async resolveAccountId(): Promise<string> {
19
+ return this.accountId ?? (async () => {
20
+ const { accountId } = await this.users.getCurrentUser();
21
+ this.accountId = accountId;
22
+ return accountId;
23
+ })();
24
+ }
25
+
26
+ async checkOrSetupIDWInfo() {
27
+ const accountId = await this.resolveAccountId();
28
+ const { name, role, description, avatar } = await this.accounts.getIdwData(accountId);
29
+ const idwData = {
30
+ name,
31
+ // using || instead of ?? to replace empty strings
32
+ role: role?.trim() || idwSetupData.role,
33
+ description: description?.trim() || idwSetupData.description,
34
+ avatar: avatar?.trim() || idwSetupData.avatar,
35
+ };
36
+ await this.accounts.updateIdwData(accountId, idwData);
37
+ }
38
+
39
+ async checkIfIDWInfoExists(): Promise<boolean> {
40
+ const accountId = await this.resolveAccountId();
41
+ const idwData = await this.accounts.getIdwData(accountId);
42
+ return Boolean(idwData && idwData.name && idwData.role);
43
+ }
44
+ }
@@ -1,4 +1,7 @@
1
- export const startUpChannels = [
1
+ import { GRAPH_NAME } from '../constants';
2
+ import { MigrationBase } from '../migration-base';
3
+
4
+ const startUpChannels = [
2
5
  {
3
6
  id: 'facebook-messenger',
4
7
  name: 'Facebook Messenger',
@@ -35,3 +38,32 @@ export const startUpChannels = [
35
38
  icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/whatsapp.png',
36
39
  },
37
40
  ];
41
+
42
+ // eslint-disable-next-line @typescript-eslint/naming-convention
43
+ export default class Migration__2 extends MigrationBase {
44
+ async up() {
45
+ const channelsExist = await this.checkIfChannelsExist();
46
+ if (!channelsExist) {
47
+ await this.createChannels();
48
+ }
49
+ }
50
+
51
+ private async createChannels() {
52
+ await this.graphApi.query({
53
+ graph: GRAPH_NAME,
54
+ query: `CREATE ${startUpChannels.map(({ id, name, icon }) => {
55
+ return `(:CHANNEL {id: '${id}', name: '${name}', icon: '${icon}'})`;
56
+ }).join(', ')}`,
57
+ params: {},
58
+ });
59
+ }
60
+
61
+ private async checkIfChannelsExist() {
62
+ const [data] = await this.graphApi.query<{ channels: any[]; }>({
63
+ graph: GRAPH_NAME,
64
+ query: 'MATCH (channels: CHANNEL) RETURN collect(DISTINCT channels) as channels',
65
+ params: {},
66
+ });
67
+ return data.channels.length > 0;
68
+ }
69
+ }
@@ -0,0 +1,2 @@
1
+ export { default as Migration__1 } from './Migration__1';
2
+ export { default as Migration__2 } from './Migration__2';
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startUpChannels = void 0;
4
- exports.startUpChannels = [
5
- {
6
- id: 'facebook-messenger',
7
- name: 'Facebook Messenger',
8
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/messenger.png',
9
- },
10
- {
11
- id: 'sms',
12
- name: 'SMS',
13
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/sms.png',
14
- },
15
- {
16
- id: 'telegram',
17
- name: 'Telegram',
18
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/telegram.png',
19
- },
20
- {
21
- id: 'twitter',
22
- name: 'Twitter',
23
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/twitter.png',
24
- },
25
- {
26
- id: 'viber',
27
- name: 'Viber',
28
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/viber.png',
29
- },
30
- {
31
- id: 'viber-business',
32
- name: 'Viber Business',
33
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/viber.png',
34
- },
35
- {
36
- id: 'whatsapp',
37
- name: 'WhatsApp',
38
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/whatsapp.png',
39
- },
40
- ];
41
- //# sourceMappingURL=channels.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"channels.js","sourceRoot":"","sources":["../../../src/data/channels.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG;IAC7B;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"}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.idwSetupData = void 0;
4
- exports.idwSetupData = {
5
- description: 'Add a fancy description to your IDW',
6
- role: 'You can set your IDW\'s role/s just by chatting with the embedded RWC',
7
- avatar: 'https://files.qa.api.onereach.ai/public/03db4abe-0477-47c0-ae4e-4c68f1047d59/IDW/IDWs-media-data/Img.png',
8
- };
9
- //# sourceMappingURL=idwSetupData.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"idwSetupData.js","sourceRoot":"","sources":["../../../src/data/idwSetupData.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG;IAC1B,WAAW,EAAE,qCAAqC;IAClD,IAAI,EAAE,uEAAuE;IAC7E,MAAM,EAAE,0GAA0G;CACnH,CAAC"}
@@ -1,38 +0,0 @@
1
- export const startUpChannels = [
2
- {
3
- id: 'facebook-messenger',
4
- name: 'Facebook Messenger',
5
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/messenger.png',
6
- },
7
- {
8
- id: 'sms',
9
- name: 'SMS',
10
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/sms.png',
11
- },
12
- {
13
- id: 'telegram',
14
- name: 'Telegram',
15
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/telegram.png',
16
- },
17
- {
18
- id: 'twitter',
19
- name: 'Twitter',
20
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/twitter.png',
21
- },
22
- {
23
- id: 'viber',
24
- name: 'Viber',
25
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/viber.png',
26
- },
27
- {
28
- id: 'viber-business',
29
- name: 'Viber Business',
30
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/viber.png',
31
- },
32
- {
33
- id: 'whatsapp',
34
- name: 'WhatsApp',
35
- icon: 'https://files.qa.api.onereach.ai/public/9c1b43df-0f7c-43fe-819f-be9df1f39759/channel-icons/whatsapp.png',
36
- },
37
- ];
38
- //# sourceMappingURL=channels.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"channels.js","sourceRoot":"","sources":["../../../src/data/channels.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B;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"}
@@ -1,6 +0,0 @@
1
- export const idwSetupData = {
2
- description: 'Add a fancy description to your IDW',
3
- role: 'You can set your IDW\'s role/s just by chatting with the embedded RWC',
4
- avatar: 'https://files.qa.api.onereach.ai/public/03db4abe-0477-47c0-ae4e-4c68f1047d59/IDW/IDWs-media-data/Img.png',
5
- };
6
- //# sourceMappingURL=idwSetupData.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"idwSetupData.js","sourceRoot":"","sources":["../../../src/data/idwSetupData.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,WAAW,EAAE,qCAAqC;IAClD,IAAI,EAAE,uEAAuE;IAC7E,MAAM,EAAE,0GAA0G;CACnH,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare const startUpChannels: {
2
- id: string;
3
- name: string;
4
- icon: string;
5
- }[];
6
- //# sourceMappingURL=channels.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"channels.d.ts","sourceRoot":"","sources":["../../../src/data/channels.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;;GAoC3B,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare const idwSetupData: {
2
- description: string;
3
- role: string;
4
- avatar: string;
5
- };
6
- //# sourceMappingURL=idwSetupData.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"idwSetupData.d.ts","sourceRoot":"","sources":["../../../src/data/idwSetupData.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;CAIxB,CAAC"}
@@ -1,5 +0,0 @@
1
- export const idwSetupData = {
2
- description: 'Add a fancy description to your IDW',
3
- role: 'You can set your IDW\'s role/s just by chatting with the embedded RWC',
4
- avatar: 'https://files.qa.api.onereach.ai/public/03db4abe-0477-47c0-ae4e-4c68f1047d59/IDW/IDWs-media-data/Img.png',
5
- };