@crowdin/app-project-module 0.40.0 → 0.41.1
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/out/handlers/integration/crowdin-update.js +10 -0
- package/out/handlers/integration/settings-save.js +8 -1
- package/out/handlers/integration/sync-settings-save.js +39 -8
- package/out/handlers/uninstall.js +4 -2
- package/out/index.js +1 -1
- package/out/middlewares/integration-credentials.js +3 -2
- package/out/models/index.d.ts +7 -1
- package/out/models/job.d.ts +3 -1
- package/out/models/job.js +2 -0
- package/out/static/js/form.js +13 -13
- package/out/storage/index.d.ts +5 -2
- package/out/storage/mysql.d.ts +5 -2
- package/out/storage/mysql.js +49 -10
- package/out/storage/postgre.d.ts +5 -2
- package/out/storage/postgre.js +46 -9
- package/out/storage/sqlite.d.ts +8 -3
- package/out/storage/sqlite.js +64 -14
- package/out/util/cron.js +6 -3
- package/out/util/files.d.ts +3 -1
- package/out/util/files.js +24 -1
- package/out/util/job.js +3 -1
- package/out/util/logger.js +8 -8
- package/out/util/webhooks.js +3 -2
- package/out/views/main.handlebars +87 -18
- package/package.json +12 -10
package/out/storage/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config, CrowdinCredentials, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks, Provider, UserErrors } from '../models';
|
|
1
|
+
import { Config, CrowdinCredentials, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationConfig, IntegrationSyncSettings, IntegrationWebhooks, Provider, UserErrors } from '../models';
|
|
2
2
|
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../models/job';
|
|
3
3
|
export interface Storage {
|
|
4
4
|
migrate(): Promise<void>;
|
|
@@ -9,7 +9,6 @@ export interface Storage {
|
|
|
9
9
|
deleteCrowdinCredentials(id: string): Promise<void>;
|
|
10
10
|
saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
|
|
11
11
|
updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
|
|
12
|
-
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
13
12
|
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
14
13
|
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
15
14
|
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
@@ -33,6 +32,10 @@ export interface Storage {
|
|
|
33
32
|
getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[] | undefined>;
|
|
34
33
|
saveUserError(action: string, message: string, data: any, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
35
34
|
deleteUserErrors(date: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
35
|
+
saveIntegrationConfig(integrationId: string, crowdinId: string, config: any): Promise<void>;
|
|
36
|
+
getAllIntegrationConfigs(crowdinId: string): Promise<IntegrationConfig[]>;
|
|
37
|
+
getIntegrationConfig(integrationId: string): Promise<IntegrationConfig | undefined>;
|
|
38
|
+
updateIntegrationConfig(integrationId: string, config: any): Promise<void>;
|
|
36
39
|
createJob(params: CreateJobParams): Promise<string>;
|
|
37
40
|
updateJob(params: UpdateJobParams): Promise<void>;
|
|
38
41
|
getJob(params: GetJobParams): Promise<Job | undefined>;
|
package/out/storage/mysql.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Storage } from '.';
|
|
2
|
-
import { CrowdinCredentials, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks, UserErrors } from '../models';
|
|
2
|
+
import { CrowdinCredentials, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationConfig, IntegrationSyncSettings, IntegrationWebhooks, UserErrors } from '../models';
|
|
3
3
|
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../models/job';
|
|
4
4
|
export interface MySQLStorageConfig {
|
|
5
5
|
uri?: string;
|
|
@@ -26,7 +26,6 @@ export declare class MySQLStorage implements Storage {
|
|
|
26
26
|
deleteCrowdinCredentials(id: string): Promise<void>;
|
|
27
27
|
saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
|
|
28
28
|
updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
|
|
29
|
-
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
30
29
|
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
31
30
|
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
32
31
|
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
@@ -50,6 +49,10 @@ export declare class MySQLStorage implements Storage {
|
|
|
50
49
|
getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[] | undefined>;
|
|
51
50
|
saveUserError(action: string, message: string, data: any, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
52
51
|
deleteUserErrors(createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
52
|
+
saveIntegrationConfig(integrationId: string, crowdinId: string, config: any): Promise<void>;
|
|
53
|
+
getAllIntegrationConfigs(crowdinId: string): Promise<IntegrationConfig[]>;
|
|
54
|
+
getIntegrationConfig(integrationId: string): Promise<IntegrationConfig | undefined>;
|
|
55
|
+
updateIntegrationConfig(integrationId: string, config: any): Promise<void>;
|
|
53
56
|
createJob({ integrationId, crowdinId, type, title, payload }: CreateJobParams): Promise<string>;
|
|
54
57
|
updateJob({ id, progress, status, info, data }: UpdateJobParams): Promise<void>;
|
|
55
58
|
getJob({ id }: GetJobParams): Promise<Job | undefined>;
|
package/out/storage/mysql.js
CHANGED
|
@@ -83,7 +83,6 @@ class MySQLStorage {
|
|
|
83
83
|
(
|
|
84
84
|
id varchar(255) primary key,
|
|
85
85
|
credentials text,
|
|
86
|
-
config text,
|
|
87
86
|
crowdin_id varchar(255) not null
|
|
88
87
|
)
|
|
89
88
|
`);
|
|
@@ -136,7 +135,16 @@ class MySQLStorage {
|
|
|
136
135
|
created_at varchar(255) not null,
|
|
137
136
|
crowdin_id varchar(255) not null,
|
|
138
137
|
integration_id varchar(255)
|
|
139
|
-
|
|
138
|
+
)
|
|
139
|
+
`);
|
|
140
|
+
yield connection.execute(`
|
|
141
|
+
create table if not exists integration_settings
|
|
142
|
+
(
|
|
143
|
+
id int auto_increment primary key,
|
|
144
|
+
integration_id varchar(255) not null,
|
|
145
|
+
crowdin_id varchar(255) not null,
|
|
146
|
+
config text
|
|
147
|
+
)
|
|
140
148
|
`);
|
|
141
149
|
yield connection.execute(`
|
|
142
150
|
create table if not exists job
|
|
@@ -221,6 +229,7 @@ class MySQLStorage {
|
|
|
221
229
|
yield connection.execute('DELETE FROM files_snapshot WHERE crowdin_id = ?', [id]);
|
|
222
230
|
yield connection.execute('DELETE FROM webhooks WHERE crowdin_id = ?', [id]);
|
|
223
231
|
yield connection.execute('DELETE FROM user_errors WHERE crowdin_id = ?', [id]);
|
|
232
|
+
yield connection.execute('DELETE FROM integration_settings WHERE crowdin_id = ?', [id]);
|
|
224
233
|
yield connection.execute('DELETE FROM job WHERE crowdin_id = ?', [id]);
|
|
225
234
|
}));
|
|
226
235
|
});
|
|
@@ -241,17 +250,11 @@ class MySQLStorage {
|
|
|
241
250
|
yield this.executeQuery((connection) => connection.execute('UPDATE integration_credentials SET credentials = ? WHERE id = ?', [credentials, id]));
|
|
242
251
|
});
|
|
243
252
|
}
|
|
244
|
-
updateIntegrationConfig(id, config) {
|
|
245
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
-
yield this.dbPromise;
|
|
247
|
-
yield this.executeQuery((connection) => connection.execute('UPDATE integration_credentials SET config = ? WHERE id = ?', [config, id]));
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
253
|
getIntegrationCredentials(id) {
|
|
251
254
|
return __awaiter(this, void 0, void 0, function* () {
|
|
252
255
|
yield this.dbPromise;
|
|
253
256
|
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
254
|
-
const [rows] = yield connection.execute('SELECT id, credentials,
|
|
257
|
+
const [rows] = yield connection.execute('SELECT id, credentials, crowdin_id as "crowdinId" FROM integration_credentials WHERE id = ?', [id]);
|
|
255
258
|
return (rows || [])[0];
|
|
256
259
|
}));
|
|
257
260
|
});
|
|
@@ -260,7 +263,7 @@ class MySQLStorage {
|
|
|
260
263
|
return __awaiter(this, void 0, void 0, function* () {
|
|
261
264
|
yield this.dbPromise;
|
|
262
265
|
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
263
|
-
const [rows] = yield connection.execute('SELECT id, credentials,
|
|
266
|
+
const [rows] = yield connection.execute('SELECT id, credentials, crowdin_id as "crowdinId" FROM integration_credentials WHERE crowdin_id = ?', [crowdinId]);
|
|
264
267
|
return rows || [];
|
|
265
268
|
}));
|
|
266
269
|
});
|
|
@@ -453,6 +456,42 @@ class MySQLStorage {
|
|
|
453
456
|
});
|
|
454
457
|
});
|
|
455
458
|
}
|
|
459
|
+
saveIntegrationConfig(integrationId, crowdinId, config) {
|
|
460
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
461
|
+
yield this.dbPromise;
|
|
462
|
+
yield this.executeQuery((connection) => connection.execute('INSERT INTO integration_settings(integrationId, crowdin_id, config) VALUES (?, ?, ?)', [
|
|
463
|
+
integrationId,
|
|
464
|
+
crowdinId,
|
|
465
|
+
config,
|
|
466
|
+
]));
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
getAllIntegrationConfigs(crowdinId) {
|
|
470
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
471
|
+
yield this.dbPromise;
|
|
472
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
473
|
+
const [rows] = yield connection.execute('SELECT config FROM integration_settings WHERE crowdin_id = ?', [
|
|
474
|
+
crowdinId,
|
|
475
|
+
]);
|
|
476
|
+
return rows || [];
|
|
477
|
+
}));
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
getIntegrationConfig(integrationId) {
|
|
481
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
482
|
+
yield this.dbPromise;
|
|
483
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
const [rows] = yield connection.execute('SELECT config FROM integration_settings WHERE integration_id = ?', [integrationId]);
|
|
485
|
+
return (rows || [])[0];
|
|
486
|
+
}));
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
updateIntegrationConfig(integrationId, config) {
|
|
490
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
491
|
+
yield this.dbPromise;
|
|
492
|
+
yield this.executeQuery((connection) => connection.execute('UPDATE integration_settings SET config = ? WHERE id = ?', [config, integrationId]));
|
|
493
|
+
});
|
|
494
|
+
}
|
|
456
495
|
createJob({ integrationId, crowdinId, type, title, payload }) {
|
|
457
496
|
return __awaiter(this, void 0, void 0, function* () {
|
|
458
497
|
const id = (0, uuid_1.v4)();
|
package/out/storage/postgre.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from 'pg';
|
|
2
2
|
import { Storage } from '.';
|
|
3
|
-
import { CrowdinCredentials, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks, UserErrors } from '../models';
|
|
3
|
+
import { CrowdinCredentials, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationConfig, IntegrationSyncSettings, IntegrationWebhooks, UserErrors } from '../models';
|
|
4
4
|
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../models/job';
|
|
5
5
|
export interface PostgreStorageConfig {
|
|
6
6
|
host?: string;
|
|
@@ -31,7 +31,6 @@ export declare class PostgreStorage implements Storage {
|
|
|
31
31
|
deleteCrowdinCredentials(id: string): Promise<void>;
|
|
32
32
|
saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
|
|
33
33
|
updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
|
|
34
|
-
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
35
34
|
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
36
35
|
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
37
36
|
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
@@ -55,6 +54,10 @@ export declare class PostgreStorage implements Storage {
|
|
|
55
54
|
getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[] | undefined>;
|
|
56
55
|
saveUserError(action: string, message: string, data: any, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
57
56
|
deleteUserErrors(createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
57
|
+
saveIntegrationConfig(integrationId: string, crowdinId: string, config: any): Promise<void>;
|
|
58
|
+
getAllIntegrationConfigs(crowdinId: string): Promise<IntegrationConfig[]>;
|
|
59
|
+
getIntegrationConfig(integrationId: string): Promise<IntegrationConfig | undefined>;
|
|
60
|
+
updateIntegrationConfig(integrationId: string, config: any): Promise<void>;
|
|
58
61
|
createJob({ integrationId, crowdinId, type, payload, title }: CreateJobParams): Promise<string>;
|
|
59
62
|
updateJob({ id, progress, status, info, data }: UpdateJobParams): Promise<void>;
|
|
60
63
|
getJob({ id }: GetJobParams): Promise<Job | undefined>;
|
package/out/storage/postgre.js
CHANGED
|
@@ -97,7 +97,6 @@ class PostgreStorage {
|
|
|
97
97
|
(
|
|
98
98
|
id varchar primary key,
|
|
99
99
|
credentials varchar,
|
|
100
|
-
config varchar,
|
|
101
100
|
crowdin_id varchar not null
|
|
102
101
|
)
|
|
103
102
|
`);
|
|
@@ -153,6 +152,15 @@ class PostgreStorage {
|
|
|
153
152
|
)
|
|
154
153
|
`);
|
|
155
154
|
yield client.query(`
|
|
155
|
+
create table if not exists integration_settings
|
|
156
|
+
(
|
|
157
|
+
id serial primary key,
|
|
158
|
+
integration_id varchar not null,
|
|
159
|
+
crowdin_id varchar not null,
|
|
160
|
+
config varchar
|
|
161
|
+
)
|
|
162
|
+
`);
|
|
163
|
+
yield client.query(`
|
|
156
164
|
create table if not exists job
|
|
157
165
|
(
|
|
158
166
|
id varchar not null primary key,
|
|
@@ -235,6 +243,7 @@ class PostgreStorage {
|
|
|
235
243
|
yield client.query('DELETE FROM app_metadata WHERE crowdin_id = $1', [id]);
|
|
236
244
|
yield client.query('DELETE FROM webhooks WHERE crowdin_id = $1', [id]);
|
|
237
245
|
yield client.query('DELETE FROM user_errors WHERE crowdin_id = $1', [id]);
|
|
246
|
+
yield client.query('DELETE FROM integration_settings WHERE crowdin_id = $1', [id]);
|
|
238
247
|
yield client.query('DELETE FROM job WHERE crowdin_id = $1', [id]);
|
|
239
248
|
}));
|
|
240
249
|
});
|
|
@@ -255,17 +264,11 @@ class PostgreStorage {
|
|
|
255
264
|
yield this.executeQuery((client) => client.query('UPDATE integration_credentials SET credentials = $1 WHERE id = $2', [credentials, id]));
|
|
256
265
|
});
|
|
257
266
|
}
|
|
258
|
-
updateIntegrationConfig(id, config) {
|
|
259
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
260
|
-
yield this.dbPromise;
|
|
261
|
-
yield this.executeQuery((client) => client.query('UPDATE integration_credentials SET config = $1 WHERE id = $2', [config, id]));
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
267
|
getIntegrationCredentials(id) {
|
|
265
268
|
return __awaiter(this, void 0, void 0, function* () {
|
|
266
269
|
yield this.dbPromise;
|
|
267
270
|
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
268
|
-
const res = yield client.query('SELECT id, credentials,
|
|
271
|
+
const res = yield client.query('SELECT id, credentials, crowdin_id as "crowdinId" FROM integration_credentials WHERE id = $1', [id]);
|
|
269
272
|
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
270
273
|
}));
|
|
271
274
|
});
|
|
@@ -274,7 +277,7 @@ class PostgreStorage {
|
|
|
274
277
|
return __awaiter(this, void 0, void 0, function* () {
|
|
275
278
|
yield this.dbPromise;
|
|
276
279
|
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
277
|
-
const res = yield client.query('SELECT id, credentials,
|
|
280
|
+
const res = yield client.query('SELECT id, credentials, crowdin_id as "crowdinId" FROM integration_credentials WHERE crowdin_id = $1', [crowdinId]);
|
|
278
281
|
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
279
282
|
}));
|
|
280
283
|
});
|
|
@@ -468,6 +471,40 @@ class PostgreStorage {
|
|
|
468
471
|
});
|
|
469
472
|
});
|
|
470
473
|
}
|
|
474
|
+
saveIntegrationConfig(integrationId, crowdinId, config) {
|
|
475
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
476
|
+
yield this.dbPromise;
|
|
477
|
+
yield this.executeQuery((client) => client.query('INSERT INTO integration_settings(integration_id, crowdin_id, config) VALUES ($1, $2, $3)', [
|
|
478
|
+
integrationId,
|
|
479
|
+
crowdinId,
|
|
480
|
+
config,
|
|
481
|
+
]));
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
getAllIntegrationConfigs(crowdinId) {
|
|
485
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
486
|
+
yield this.dbPromise;
|
|
487
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
488
|
+
const res = yield client.query('SELECT config FROM integration_settings WHERE crowdin_id = $1', [crowdinId]);
|
|
489
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
490
|
+
}));
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
getIntegrationConfig(integrationId) {
|
|
494
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
495
|
+
yield this.dbPromise;
|
|
496
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
497
|
+
const res = yield client.query('SELECT config FROM integration_settings WHERE integration_id = $1', [integrationId]);
|
|
498
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
499
|
+
}));
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
updateIntegrationConfig(integrationId, config) {
|
|
503
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
504
|
+
yield this.dbPromise;
|
|
505
|
+
yield this.executeQuery((client) => client.query('UPDATE integration_settings SET config = $1 WHERE id = $2', [config, integrationId]));
|
|
506
|
+
});
|
|
507
|
+
}
|
|
471
508
|
createJob({ integrationId, crowdinId, type, payload, title }) {
|
|
472
509
|
return __awaiter(this, void 0, void 0, function* () {
|
|
473
510
|
const id = (0, uuid_1.v4)();
|
package/out/storage/sqlite.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Storage } from '.';
|
|
2
|
-
import { CrowdinCredentials, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks, UserErrors } from '../models';
|
|
2
|
+
import { CrowdinCredentials, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationConfig, IntegrationSyncSettings, IntegrationWebhooks, UserErrors } from '../models';
|
|
3
3
|
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../models/job';
|
|
4
4
|
export interface SQLiteStorageConfig {
|
|
5
5
|
dbFolder: string;
|
|
@@ -15,8 +15,10 @@ export declare class SQLiteStorage implements Storage {
|
|
|
15
15
|
private run;
|
|
16
16
|
private get;
|
|
17
17
|
private each;
|
|
18
|
-
private
|
|
18
|
+
private removeColumns;
|
|
19
19
|
private addColumns;
|
|
20
|
+
private updateTables;
|
|
21
|
+
private moveIntegrationSettings;
|
|
20
22
|
migrate(): Promise<void>;
|
|
21
23
|
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
22
24
|
updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
@@ -25,7 +27,6 @@ export declare class SQLiteStorage implements Storage {
|
|
|
25
27
|
deleteCrowdinCredentials(id: string): Promise<void>;
|
|
26
28
|
saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
|
|
27
29
|
updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
|
|
28
|
-
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
29
30
|
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
30
31
|
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
31
32
|
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
@@ -49,6 +50,10 @@ export declare class SQLiteStorage implements Storage {
|
|
|
49
50
|
getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[]>;
|
|
50
51
|
saveUserError(action: string, message: string, data: any, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
51
52
|
deleteUserErrors(createAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
53
|
+
saveIntegrationConfig(integrationId: string, crowdinId: string, config: any): Promise<void>;
|
|
54
|
+
getAllIntegrationConfigs(crowdinId: string): Promise<IntegrationConfig[]>;
|
|
55
|
+
getIntegrationConfig(integrationId: string): Promise<IntegrationConfig | undefined>;
|
|
56
|
+
updateIntegrationConfig(integrationId: string, config: any): Promise<void>;
|
|
52
57
|
createJob({ integrationId, crowdinId, type, title, payload }: CreateJobParams): Promise<string>;
|
|
53
58
|
updateJob({ id, progress, status, info, data }: UpdateJobParams): Promise<void>;
|
|
54
59
|
getJob({ id }: GetJobParams): Promise<Job | undefined>;
|
package/out/storage/sqlite.js
CHANGED
|
@@ -94,25 +94,45 @@ class SQLiteStorage {
|
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
removeColumns(column, tableName) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const tableInfo = yield this.each(`PRAGMA table_info(${tableName});`, []);
|
|
100
|
+
const exists = tableInfo.some((columnInfo) => columnInfo.name === column);
|
|
101
|
+
if (exists) {
|
|
102
|
+
yield this.run(`ALTER TABLE ${tableName} DROP COLUMN ${column};`, []);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
addColumns(columns, tableName) {
|
|
98
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
108
|
const tableInfo = yield this.each(`PRAGMA table_info(${tableName});`, []);
|
|
100
109
|
//@ts-ignore
|
|
101
110
|
tableInfo.map((columnInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
const index =
|
|
111
|
+
const index = columns.indexOf(columnInfo.name);
|
|
103
112
|
if (~index) {
|
|
104
|
-
|
|
113
|
+
columns.splice(index, 1);
|
|
105
114
|
}
|
|
106
115
|
}));
|
|
107
|
-
for (const column of
|
|
116
|
+
for (const column of columns) {
|
|
108
117
|
yield this.run(`ALTER TABLE ${tableName} ADD COLUMN ${column} varchar null;`, []);
|
|
109
118
|
}
|
|
110
119
|
});
|
|
111
120
|
}
|
|
112
|
-
|
|
121
|
+
updateTables() {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
yield this.addColumns(['app_secret', 'domain', 'user_id', 'organization_id', 'base_url'], 'crowdin_credentials');
|
|
124
|
+
yield this.addColumns(['crowdin_id'], 'app_metadata');
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
moveIntegrationSettings() {
|
|
113
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
yield this.
|
|
115
|
-
|
|
129
|
+
const integrationCredentials = yield this.each('SELECT * FROM integration_credentials', []);
|
|
130
|
+
for (const credentials of integrationCredentials) {
|
|
131
|
+
if (credentials.config) {
|
|
132
|
+
yield this.saveIntegrationConfig(credentials.id, credentials.crowdin_id, credentials.config);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
yield this.removeColumns('config', 'integration_credentials');
|
|
116
136
|
});
|
|
117
137
|
}
|
|
118
138
|
migrate() {
|
|
@@ -155,7 +175,6 @@ class SQLiteStorage {
|
|
|
155
175
|
(
|
|
156
176
|
id varchar not null primary key,
|
|
157
177
|
credentials varchar not null,
|
|
158
|
-
config varchar null,
|
|
159
178
|
crowdin_id varchar not null
|
|
160
179
|
);
|
|
161
180
|
`, []);
|
|
@@ -209,6 +228,15 @@ class SQLiteStorage {
|
|
|
209
228
|
crowdin_id varchar not null,
|
|
210
229
|
integration_id varchar null
|
|
211
230
|
);
|
|
231
|
+
`, []);
|
|
232
|
+
yield this._run(`
|
|
233
|
+
create table if not exists integration_settings
|
|
234
|
+
(
|
|
235
|
+
id integer not null primary key autoincrement,
|
|
236
|
+
integration_id varchar not null,
|
|
237
|
+
crowdin_id varchar not null,
|
|
238
|
+
config varchar null
|
|
239
|
+
);
|
|
212
240
|
`, []);
|
|
213
241
|
yield this._run(`
|
|
214
242
|
create table if not exists job
|
|
@@ -230,7 +258,8 @@ class SQLiteStorage {
|
|
|
230
258
|
`, []);
|
|
231
259
|
this._res && this._res();
|
|
232
260
|
// TODO: temporary code
|
|
233
|
-
yield this.
|
|
261
|
+
yield this.updateTables();
|
|
262
|
+
yield this.moveIntegrationSettings();
|
|
234
263
|
}
|
|
235
264
|
catch (e) {
|
|
236
265
|
this._rej && this._rej(e);
|
|
@@ -284,6 +313,7 @@ class SQLiteStorage {
|
|
|
284
313
|
yield this.run('DELETE FROM files_snapshot WHERE crowdin_id = ?', [id]);
|
|
285
314
|
yield this.run('DELETE FROM webhooks WHERE crowdin_id = ?', [id]);
|
|
286
315
|
yield this.run('DELETE FROM user_errors WHERE crowdin_id = ?', [id]);
|
|
316
|
+
yield this.run('DELETE FROM integration_settings WHERE crowdin_id = ?', [id]);
|
|
287
317
|
yield this.run('DELETE FROM job WHERE crowdin_id = ?', [id]);
|
|
288
318
|
});
|
|
289
319
|
}
|
|
@@ -297,19 +327,16 @@ class SQLiteStorage {
|
|
|
297
327
|
updateIntegrationCredentials(id, credentials) {
|
|
298
328
|
return this.run('UPDATE integration_credentials SET credentials = ? WHERE id = ?', [credentials, id]);
|
|
299
329
|
}
|
|
300
|
-
updateIntegrationConfig(id, config) {
|
|
301
|
-
return this.run('UPDATE integration_credentials SET config = ? WHERE id = ?', [config, id]);
|
|
302
|
-
}
|
|
303
330
|
getIntegrationCredentials(id) {
|
|
304
331
|
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
-
const row = yield this.get('SELECT id, credentials,
|
|
332
|
+
const row = yield this.get('SELECT id, credentials, crowdin_id as crowdinId FROM integration_credentials WHERE id = ?', [id]);
|
|
306
333
|
if (row) {
|
|
307
334
|
return row;
|
|
308
335
|
}
|
|
309
336
|
});
|
|
310
337
|
}
|
|
311
338
|
getAllIntegrationCredentials(crowdinId) {
|
|
312
|
-
return this.each('SELECT id, credentials,
|
|
339
|
+
return this.each('SELECT id, credentials, crowdin_id as crowdinId FROM integration_credentials WHERE crowdin_id = ?', [crowdinId]);
|
|
313
340
|
}
|
|
314
341
|
deleteIntegrationCredentials(id) {
|
|
315
342
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -449,6 +476,29 @@ class SQLiteStorage {
|
|
|
449
476
|
return this.run(`DELETE FROM user_errors WHERE created_at < ? AND crowdin_id = ? AND ${whereIntegrationCondition}`, params);
|
|
450
477
|
});
|
|
451
478
|
}
|
|
479
|
+
saveIntegrationConfig(integrationId, crowdinId, config) {
|
|
480
|
+
return this.run('INSERT INTO integration_settings(integration_id, crowdin_id, config) VALUES (?, ?, ?)', [
|
|
481
|
+
integrationId,
|
|
482
|
+
crowdinId,
|
|
483
|
+
config,
|
|
484
|
+
]);
|
|
485
|
+
}
|
|
486
|
+
getAllIntegrationConfigs(crowdinId) {
|
|
487
|
+
return this.each('SELECT config, integration_id as integrationId FROM integration_settings WHERE crowdin_id = ?', [crowdinId]);
|
|
488
|
+
}
|
|
489
|
+
getIntegrationConfig(integrationId) {
|
|
490
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
491
|
+
const row = yield this.get('SELECT config FROM integration_settings WHERE integration_id = ?', [
|
|
492
|
+
integrationId,
|
|
493
|
+
]);
|
|
494
|
+
if (row) {
|
|
495
|
+
return row;
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
updateIntegrationConfig(integrationId, config) {
|
|
500
|
+
return this.run('UPDATE integration_settings SET config = ? WHERE integration_id = ?', [config, integrationId]);
|
|
501
|
+
}
|
|
452
502
|
createJob({ integrationId, crowdinId, type, title, payload }) {
|
|
453
503
|
return __awaiter(this, void 0, void 0, function* () {
|
|
454
504
|
const id = (0, uuid_1.v4)();
|
package/out/util/cron.js
CHANGED
|
@@ -63,11 +63,13 @@ function runJob(config, integration, job) {
|
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
const integrationCredentialsList = yield (0, storage_1.getStorage)().getAllIntegrationCredentials(crowdinCredentials.id);
|
|
66
|
+
const allIntegrationConfigs = yield (0, storage_1.getStorage)().getAllIntegrationConfigs(crowdinCredentials.id);
|
|
66
67
|
for (const integrationCredentials of integrationCredentialsList) {
|
|
68
|
+
const integrationConfig = allIntegrationConfigs.find(({ integrationId }) => integrationId === integrationCredentials.id);
|
|
67
69
|
const projectId = crowdinAppFunctions.getProjectId(integrationCredentials.id);
|
|
68
70
|
const apiCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
|
69
71
|
const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, crowdinClient, projectId);
|
|
70
|
-
const intConfig =
|
|
72
|
+
const intConfig = (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.config) ? JSON.parse(integrationConfig.config) : undefined;
|
|
71
73
|
(0, logger_1.log)(`Executing task for cron job with expression [${job.expression}] for project ${projectId}`);
|
|
72
74
|
yield job.task(projectId, crowdinClient, apiCredentials, rootFolder, intConfig);
|
|
73
75
|
(0, logger_1.log)(`Task for cron job with expression [${job.expression}] for project ${projectId} completed`);
|
|
@@ -87,11 +89,12 @@ function filesCron(config, integration, period) {
|
|
|
87
89
|
let newFiles = [];
|
|
88
90
|
const crowdinCredentials = yield (0, storage_1.getStorage)().getCrowdinCredentials(syncSettings.crowdinId);
|
|
89
91
|
const integrationCredentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(syncSettings.integrationId);
|
|
92
|
+
const integrationConfig = yield (0, storage_1.getStorage)().getIntegrationConfig(syncSettings.integrationId);
|
|
90
93
|
if (!crowdinCredentials || !integrationCredentials) {
|
|
91
94
|
return;
|
|
92
95
|
}
|
|
93
|
-
const intConfig =
|
|
94
|
-
? JSON.parse(
|
|
96
|
+
const intConfig = (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.config)
|
|
97
|
+
? JSON.parse(integrationConfig.config)
|
|
95
98
|
: { schedule: '0', condition: '0' };
|
|
96
99
|
if (period !== intConfig.schedule) {
|
|
97
100
|
return;
|
package/out/util/files.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ProcessFileString, SkipIntegrationNodes, TreeItem } from '../models';
|
|
2
|
+
import { IntegrationFile, IntegrationLogic, IntegrationRequest, ProcessFileString, SkipIntegrationNodes, TreeItem } from '../models';
|
|
3
|
+
import { JobClient } from '../models/job';
|
|
3
4
|
export declare const MAX_BODY_SIZE: number;
|
|
4
5
|
export declare function storeFile(fileContent: Buffer, folder: string): Promise<string>;
|
|
5
6
|
export declare function getFileContent(url: string): Promise<Buffer>;
|
|
6
7
|
export declare function getFileStrings(url: string): Promise<ProcessFileString[]>;
|
|
7
8
|
export declare function skipFilesByRegex(files: TreeItem[] | undefined, skipIntegrationNodes?: SkipIntegrationNodes): TreeItem[];
|
|
9
|
+
export declare function expandFilesTree(nodes: IntegrationFile[], req: IntegrationRequest, integration: IntegrationLogic, job?: JobClient): Promise<IntegrationFile[]>;
|
package/out/util/files.js
CHANGED
|
@@ -12,10 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.skipFilesByRegex = exports.getFileStrings = exports.getFileContent = exports.storeFile = exports.MAX_BODY_SIZE = void 0;
|
|
15
|
+
exports.expandFilesTree = exports.skipFilesByRegex = exports.getFileStrings = exports.getFileContent = exports.storeFile = exports.MAX_BODY_SIZE = void 0;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
17
|
const fs_1 = __importDefault(require("fs"));
|
|
18
18
|
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const index_1 = require("./index");
|
|
20
|
+
const job_1 = require("../models/job");
|
|
19
21
|
exports.MAX_BODY_SIZE = 4.9 * 1024 * 1024; //4.9mb
|
|
20
22
|
function storeFile(fileContent, folder) {
|
|
21
23
|
const fileName = `file${Date.now()}`;
|
|
@@ -63,3 +65,24 @@ function skipFilesByRegex(files, skipIntegrationNodes) {
|
|
|
63
65
|
return files;
|
|
64
66
|
}
|
|
65
67
|
exports.skipFilesByRegex = skipFilesByRegex;
|
|
68
|
+
function expandFilesTree(nodes, req, integration, job) {
|
|
69
|
+
var _a;
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
if (job && job_1.JobStatus.CANCELED === ((_a = (yield job.get())) === null || _a === void 0 ? void 0 : _a.status)) {
|
|
72
|
+
throw new Error('Job canceled');
|
|
73
|
+
}
|
|
74
|
+
const files = nodes.filter((file) => file.nodeType === undefined || file.nodeType === '1');
|
|
75
|
+
const folders = nodes.filter((folder) => folder.nodeType === '0' && !nodes.find((node) => node.parentId === folder.id));
|
|
76
|
+
for (const { id } of folders) {
|
|
77
|
+
const integrationData = yield integration.getIntegrationFiles(req.integrationCredentials, req.integrationSettings, id);
|
|
78
|
+
const integrationTreeItems = (0, index_1.isExtendedResultType)(integrationData)
|
|
79
|
+
? integrationData.data
|
|
80
|
+
: integrationData;
|
|
81
|
+
const checkNodes = integrationTreeItems.map((item) => (Object.assign(Object.assign({}, item), { nodeType: item.nodeType || ('type' in item ? '1' : '0') })));
|
|
82
|
+
const expandedResult = yield expandFilesTree(checkNodes, req, integration, job);
|
|
83
|
+
files.push(...expandedResult);
|
|
84
|
+
}
|
|
85
|
+
return files;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
exports.expandFilesTree = expandFilesTree;
|
package/out/util/job.js
CHANGED
|
@@ -16,6 +16,8 @@ const logger_1 = require("./logger");
|
|
|
16
16
|
const blockingJobs = {
|
|
17
17
|
[job_1.JobType.UPDATE_TO_CROWDIN]: [job_1.JobType.UPDATE_TO_CROWDIN, job_1.JobType.UPDATE_TO_INTEGRATION],
|
|
18
18
|
[job_1.JobType.UPDATE_TO_INTEGRATION]: [job_1.JobType.UPDATE_TO_CROWDIN, job_1.JobType.UPDATE_TO_INTEGRATION],
|
|
19
|
+
[job_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE]: [job_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE],
|
|
20
|
+
[job_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE]: [job_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE],
|
|
19
21
|
};
|
|
20
22
|
function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCallback, onError, }) {
|
|
21
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -25,7 +27,7 @@ function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCall
|
|
|
25
27
|
const existingJob = activeJobs.find((job) => blockingJobs[type].includes(job.type));
|
|
26
28
|
if (existingJob === null || existingJob === void 0 ? void 0 : existingJob.id) {
|
|
27
29
|
if (res) {
|
|
28
|
-
res.status(202).send({ jobId: existingJob.id, message: '
|
|
30
|
+
res.status(202).send({ jobId: existingJob.id, message: 'Another sync is running' });
|
|
29
31
|
}
|
|
30
32
|
return;
|
|
31
33
|
}
|
package/out/util/logger.js
CHANGED
|
@@ -137,20 +137,20 @@ function logError(e, context) {
|
|
|
137
137
|
}
|
|
138
138
|
exports.logError = logError;
|
|
139
139
|
function errorOutputByType(error) {
|
|
140
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
140
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
141
141
|
const message = error.message || error;
|
|
142
142
|
if (isAxiosError(error)) {
|
|
143
|
-
const request = error.config || error.data.config
|
|
143
|
+
const request = (error === null || error === void 0 ? void 0 : error.config) || ((_a = error.data) === null || _a === void 0 ? void 0 : _a.config)
|
|
144
144
|
? {
|
|
145
|
-
url: ((
|
|
146
|
-
method: ((
|
|
147
|
-
data: ((
|
|
145
|
+
url: ((_b = error.config) === null || _b === void 0 ? void 0 : _b.url) || ((_c = error.data) === null || _c === void 0 ? void 0 : _c.config.url),
|
|
146
|
+
method: ((_d = error.config) === null || _d === void 0 ? void 0 : _d.method) || ((_e = error.data) === null || _e === void 0 ? void 0 : _e.config.method),
|
|
147
|
+
data: ((_f = error.config) === null || _f === void 0 ? void 0 : _f.data) || ((_g = error.data) === null || _g === void 0 ? void 0 : _g.config.data),
|
|
148
148
|
}
|
|
149
149
|
: {};
|
|
150
|
-
const response = error.response || error.data.response
|
|
150
|
+
const response = (error === null || error === void 0 ? void 0 : error.response) || ((_h = error.data) === null || _h === void 0 ? void 0 : _h.response)
|
|
151
151
|
? {
|
|
152
|
-
data: ((
|
|
153
|
-
status: ((
|
|
152
|
+
data: ((_j = error.response) === null || _j === void 0 ? void 0 : _j.data) || ((_k = error.data) === null || _k === void 0 ? void 0 : _k.response.data),
|
|
153
|
+
status: ((_l = error.response) === null || _l === void 0 ? void 0 : _l.status) || ((_m = error.data) === null || _m === void 0 ? void 0 : _m.response.status),
|
|
154
154
|
}
|
|
155
155
|
: {};
|
|
156
156
|
console.error(message, { attributes: JSON.stringify({ request, response }) }, { backtrace: error.stack });
|
package/out/util/webhooks.js
CHANGED
|
@@ -229,6 +229,7 @@ function prepareWebhookData(config, integration, webhookUrlParam, provider) {
|
|
|
229
229
|
const { projectId, crowdinId, clientId } = decodedUrlParam(config, webhookUrlParam);
|
|
230
230
|
const crowdinCredentials = yield (0, storage_1.getStorage)().getCrowdinCredentials(crowdinId);
|
|
231
231
|
const integrationCredentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(clientId);
|
|
232
|
+
const integrationConfig = yield (0, storage_1.getStorage)().getIntegrationConfig(clientId);
|
|
232
233
|
const context = {
|
|
233
234
|
jwtPayload: {
|
|
234
235
|
context: {
|
|
@@ -247,8 +248,8 @@ function prepareWebhookData(config, integration, webhookUrlParam, provider) {
|
|
|
247
248
|
context,
|
|
248
249
|
});
|
|
249
250
|
const preparedIntegrationCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
|
250
|
-
if (
|
|
251
|
-
appSettings = JSON.parse(
|
|
251
|
+
if (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.config) {
|
|
252
|
+
appSettings = JSON.parse(integrationConfig.config);
|
|
252
253
|
const isWebhookSync = Number(appSettings.schedule) !== models_1.SyncSchedule.DISABLED;
|
|
253
254
|
if (isWebhookSync) {
|
|
254
255
|
syncSettings = (yield (0, storage_1.getStorage)().getSyncSettings(clientId, crowdinId, 'schedule', provider));
|