@or-sdk/idw 1.3.7-beta.1499.0 → 1.3.7
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 +9 -0
- package/dist/cjs/constants.js +2 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/idw.js +23 -58
- package/dist/cjs/idw.js.map +1 -1
- package/dist/cjs/index.js +14 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/migration-base.js +71 -0
- package/dist/cjs/migration-base.js.map +1 -0
- package/dist/cjs/migration-handler.js +184 -0
- package/dist/cjs/migration-handler.js.map +1 -0
- package/dist/cjs/migrations/Migration__1.js +108 -0
- package/dist/cjs/migrations/Migration__1.js.map +1 -0
- package/dist/cjs/migrations/Migration__2.js +155 -0
- package/dist/cjs/migrations/Migration__2.js.map +1 -0
- package/dist/cjs/migrations/index.js +11 -0
- package/dist/cjs/migrations/index.js.map +1 -0
- package/dist/esm/constants.js +1 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/idw.js +13 -33
- package/dist/esm/idw.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/migration-base.js +29 -0
- package/dist/esm/migration-base.js.map +1 -0
- package/dist/esm/migration-handler.js +88 -0
- package/dist/esm/migration-handler.js.map +1 -0
- package/dist/esm/migrations/Migration__1.js +40 -0
- package/dist/esm/migrations/Migration__1.js.map +1 -0
- package/dist/esm/migrations/Migration__2.js +80 -0
- package/dist/esm/migrations/Migration__2.js.map +1 -0
- package/dist/esm/migrations/index.js +3 -0
- package/dist/esm/migrations/index.js.map +1 -0
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/idw.d.ts +4 -3
- package/dist/types/idw.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/migration-base.d.ts +22 -0
- package/dist/types/migration-base.d.ts.map +1 -0
- package/dist/types/migration-handler.d.ts +18 -0
- package/dist/types/migration-handler.d.ts.map +1 -0
- package/dist/types/migrations/Migration__1.d.ts +6 -0
- package/dist/types/migrations/Migration__1.d.ts.map +1 -0
- package/dist/types/migrations/Migration__2.d.ts +7 -0
- package/dist/types/migrations/Migration__2.d.ts.map +1 -0
- package/dist/types/migrations/index.d.ts +3 -0
- package/dist/types/migrations/index.d.ts.map +1 -0
- package/package.json +6 -4
- package/src/constants.ts +1 -0
- package/src/idw.ts +26 -36
- package/src/index.ts +1 -1
- package/src/migration-base.ts +38 -0
- package/src/migration-handler.ts +82 -0
- package/src/migrations/Migration__1.ts +33 -0
- package/src/{data/channels.ts → migrations/Migration__2.ts} +33 -1
- package/src/migrations/index.ts +2 -0
- package/dist/cjs/data/channels.js +0 -41
- package/dist/cjs/data/channels.js.map +0 -1
- package/dist/cjs/data/idwSetupData.js +0 -9
- package/dist/cjs/data/idwSetupData.js.map +0 -1
- package/dist/esm/data/channels.js +0 -38
- package/dist/esm/data/channels.js.map +0 -1
- package/dist/esm/data/idwSetupData.js +0 -6
- package/dist/esm/data/idwSetupData.js.map +0 -1
- package/dist/types/data/channels.d.ts +0 -6
- package/dist/types/data/channels.d.ts.map +0 -1
- package/dist/types/data/idwSetupData.d.ts +0 -6
- package/dist/types/data/idwSetupData.d.ts.map +0 -1
- package/src/data/idwSetupData.ts +0 -5
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
protected resolveAccountId(): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
//# 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;cAEZ,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;CAOpD"}
|
|
@@ -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: number): 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,EAA6B,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAOvE,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;IAwBf,WAAW,CAAC,oBAAoB,EAAE,MAAM;IAaxC,sBAAsB;IAOtB,4BAA4B;CAWnC"}
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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
|
|
2
|
+
"version": "1.3.7",
|
|
3
3
|
"name": "@or-sdk/idw",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
@@ -24,11 +24,13 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@or-sdk/accounts": "^1.2.
|
|
27
|
+
"@or-sdk/accounts": "^1.2.13",
|
|
28
28
|
"@or-sdk/base": "^0.28.3",
|
|
29
|
-
"@or-sdk/deployer": "^1.1.
|
|
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
|
+
},
|
|
35
|
+
"gitHead": "79a0a0801d0bcf1f52962ea5e522c96028461a9a"
|
|
34
36
|
}
|
package/src/constants.ts
CHANGED
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
|
|
9
|
-
import {
|
|
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:
|
|
79
|
-
|
|
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
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
|
|
31
|
+
protected async resolveAccountId(): Promise<string> {
|
|
32
|
+
return this.accountId ?? (async () => {
|
|
33
|
+
const { accountId } = await this.users.getCurrentUser();
|
|
34
|
+
this.accountId = accountId;
|
|
35
|
+
return accountId;
|
|
36
|
+
})();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Accounts } from '@or-sdk/accounts';
|
|
2
|
+
import { Graphs } from '@or-sdk/graph';
|
|
3
|
+
import { Users } from '@or-sdk/users';
|
|
4
|
+
import { AccountRouteDeletePayload, Settings } from '@or-sdk/settings';
|
|
5
|
+
import { MigrationBase } from './migration-base';
|
|
6
|
+
import { SERVICE_KEY, 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 Number(version);
|
|
33
|
+
}).sort();
|
|
34
|
+
|
|
35
|
+
for (let i = 0;i < migrationVersions.length;i++) {
|
|
36
|
+
if (migrationVersions[i] > accountsLatestVersion) {
|
|
37
|
+
const migration = this.migrations.get(PREFIX + migrationVersions[i]);
|
|
38
|
+
if (migration) {
|
|
39
|
+
try {
|
|
40
|
+
await migration.up();
|
|
41
|
+
await this.saveVersion(migrationVersions[i]);
|
|
42
|
+
|
|
43
|
+
} catch (e) {
|
|
44
|
+
throw new Error(`Migration ${migration.constructor.name} is not applied`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async saveVersion(currentLatestVersion: number) {
|
|
52
|
+
try {
|
|
53
|
+
const params = {
|
|
54
|
+
key: `${SERVICE_KEY}.${VERSION_PROP}`,
|
|
55
|
+
value: currentLatestVersion,
|
|
56
|
+
};
|
|
57
|
+
await this.settings.setAccountSettings(params);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
throw new Error(`Error while saving migration "${PREFIX + currentLatestVersion}"`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async deleteMigrationVersion() {
|
|
65
|
+
const params = {
|
|
66
|
+
key: `${SERVICE_KEY}.${VERSION_PROP}`,
|
|
67
|
+
} as AccountRouteDeletePayload;
|
|
68
|
+
await this.settings.deleteAccountSettings(params);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async findAccountsMigrationVersion() {
|
|
72
|
+
try {
|
|
73
|
+
const params = {
|
|
74
|
+
key: `${SERVICE_KEY}.${VERSION_PROP}`,
|
|
75
|
+
};
|
|
76
|
+
return await this.settings.getAccountSettings(params);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
// eslint-disable-next-line no-console
|
|
79
|
+
throw new Error('Error while getting account settings');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
await this.checkOrSetupIDWInfo();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async checkOrSetupIDWInfo(): Promise<void> {
|
|
16
|
+
const accountId = await this.resolveAccountId();
|
|
17
|
+
const idwData = await this.accounts.getIdwData(accountId);
|
|
18
|
+
const hasIdwInfo = Boolean(idwData && idwData.name && idwData.role);
|
|
19
|
+
|
|
20
|
+
if (!hasIdwInfo) {
|
|
21
|
+
const { name, role, description, avatar } = idwData;
|
|
22
|
+
await this.accounts.updateIdwData(accountId, {
|
|
23
|
+
name,
|
|
24
|
+
// using || instead of ?? to replace empty strings
|
|
25
|
+
role: role?.trim() || idwSetupData.role,
|
|
26
|
+
description: description?.trim() || idwSetupData.description,
|
|
27
|
+
avatar: avatar?.trim() || idwSetupData.avatar,
|
|
28
|
+
});
|
|
29
|
+
//TODO it's necessary bc redis cache.
|
|
30
|
+
return new Promise(res => setTimeout(res, 60000));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
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
|
+
}
|
|
@@ -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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"channels.d.ts","sourceRoot":"","sources":["../../../src/data/channels.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;;GAoC3B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"idwSetupData.d.ts","sourceRoot":"","sources":["../../../src/data/idwSetupData.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;CAIxB,CAAC"}
|
package/src/data/idwSetupData.ts
DELETED
|
@@ -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
|
-
};
|