@crowdin/app-project-module 0.39.1 → 0.41.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.
- package/out/handlers/integration/crowdin-update.js +36 -17
- package/out/handlers/integration/integration-data.js +2 -0
- package/out/handlers/integration/integration-update.js +35 -17
- package/out/handlers/integration/integration-webhook.js +1 -1
- package/out/handlers/integration/job-cancel.d.ts +3 -0
- package/out/handlers/integration/job-cancel.js +28 -0
- package/out/handlers/integration/job-info.d.ts +3 -0
- package/out/handlers/integration/job-info.js +54 -0
- package/out/handlers/integration/main.js +6 -3
- package/out/handlers/integration/settings-save.js +8 -1
- package/out/handlers/integration/user-errors.d.ts +3 -0
- package/out/handlers/{user-errors.js → integration/user-errors.js} +2 -2
- package/out/handlers/uninstall.js +4 -2
- package/out/index.d.ts +2 -1
- package/out/index.js +35 -27
- package/out/middlewares/crowdin-client.js +1 -0
- package/out/middlewares/integration-credentials.js +3 -2
- package/out/middlewares/ui-module.js +1 -0
- package/out/models/index.d.ts +54 -18
- package/out/models/index.js +1 -0
- package/out/models/job.d.ts +44 -0
- package/out/models/job.js +16 -0
- package/out/static/js/form.js +13 -13
- package/out/static/js/main.js +1 -1
- package/out/storage/index.d.ts +11 -2
- package/out/storage/index.js +3 -0
- package/out/storage/mysql.d.ts +11 -2
- package/out/storage/mysql.js +155 -10
- package/out/storage/postgre.d.ts +11 -2
- package/out/storage/postgre.js +153 -9
- package/out/storage/sqlite.d.ts +14 -3
- package/out/storage/sqlite.js +160 -14
- package/out/util/cron.d.ts +1 -0
- package/out/util/cron.js +53 -6
- package/out/util/defaults.js +4 -11
- package/out/util/file-snapshot.js +2 -0
- package/out/util/files.d.ts +2 -1
- package/out/util/files.js +19 -1
- package/out/util/index.js +3 -1
- package/out/util/job.d.ts +12 -0
- package/out/util/job.js +88 -0
- package/out/util/logger.js +4 -0
- package/out/util/webhooks.js +53 -6
- package/out/views/main.handlebars +153 -5
- package/package.json +16 -15
- package/out/handlers/user-errors.d.ts +0 -3
package/out/static/js/main.js
CHANGED
package/out/storage/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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
|
+
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../models/job';
|
|
2
3
|
export interface Storage {
|
|
3
4
|
migrate(): Promise<void>;
|
|
4
5
|
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
@@ -8,7 +9,6 @@ export interface Storage {
|
|
|
8
9
|
deleteCrowdinCredentials(id: string): Promise<void>;
|
|
9
10
|
saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
|
|
10
11
|
updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
|
|
11
|
-
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
12
12
|
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
13
13
|
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
14
14
|
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
@@ -32,6 +32,15 @@ export interface Storage {
|
|
|
32
32
|
getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[] | undefined>;
|
|
33
33
|
saveUserError(action: string, message: string, data: any, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
34
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>;
|
|
39
|
+
createJob(params: CreateJobParams): Promise<string>;
|
|
40
|
+
updateJob(params: UpdateJobParams): Promise<void>;
|
|
41
|
+
getJob(params: GetJobParams): Promise<Job | undefined>;
|
|
42
|
+
getActiveJobs(params: GetActiveJobsParams): Promise<Job[] | undefined>;
|
|
43
|
+
deleteFinishedJobs(): Promise<void>;
|
|
35
44
|
}
|
|
36
45
|
export declare function initialize(config: Config): Promise<void>;
|
|
37
46
|
export declare function getStorage(): Storage;
|
package/out/storage/index.js
CHANGED
package/out/storage/mysql.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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
|
+
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../models/job';
|
|
3
4
|
export interface MySQLStorageConfig {
|
|
4
5
|
uri?: string;
|
|
5
6
|
host?: string;
|
|
@@ -25,7 +26,6 @@ export declare class MySQLStorage implements Storage {
|
|
|
25
26
|
deleteCrowdinCredentials(id: string): Promise<void>;
|
|
26
27
|
saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
|
|
27
28
|
updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
|
|
28
|
-
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
29
29
|
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
30
30
|
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
31
31
|
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
@@ -49,4 +49,13 @@ export declare class MySQLStorage implements Storage {
|
|
|
49
49
|
getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[] | undefined>;
|
|
50
50
|
saveUserError(action: string, message: string, data: any, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
51
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>;
|
|
56
|
+
createJob({ integrationId, crowdinId, type, title, payload }: CreateJobParams): Promise<string>;
|
|
57
|
+
updateJob({ id, progress, status, info, data }: UpdateJobParams): Promise<void>;
|
|
58
|
+
getJob({ id }: GetJobParams): Promise<Job | undefined>;
|
|
59
|
+
getActiveJobs({ integrationId, crowdinId }: GetActiveJobsParams): Promise<Job[] | undefined>;
|
|
60
|
+
deleteFinishedJobs(): Promise<void>;
|
|
52
61
|
}
|
package/out/storage/mysql.js
CHANGED
|
@@ -13,6 +13,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.MySQLStorage = void 0;
|
|
16
|
+
const uuid_1 = require("uuid");
|
|
17
|
+
const job_1 = require("../models/job");
|
|
16
18
|
const util_1 = require("../util");
|
|
17
19
|
class MySQLStorage {
|
|
18
20
|
constructor(config) {
|
|
@@ -81,7 +83,6 @@ class MySQLStorage {
|
|
|
81
83
|
(
|
|
82
84
|
id varchar(255) primary key,
|
|
83
85
|
credentials text,
|
|
84
|
-
config text,
|
|
85
86
|
crowdin_id varchar(255) not null
|
|
86
87
|
)
|
|
87
88
|
`);
|
|
@@ -134,7 +135,35 @@ class MySQLStorage {
|
|
|
134
135
|
created_at varchar(255) not null,
|
|
135
136
|
crowdin_id varchar(255) not null,
|
|
136
137
|
integration_id varchar(255)
|
|
137
|
-
|
|
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
|
+
)
|
|
148
|
+
`);
|
|
149
|
+
yield connection.execute(`
|
|
150
|
+
create table if not exists job
|
|
151
|
+
(
|
|
152
|
+
id varchar(255) not null primary key,
|
|
153
|
+
integration_id varchar(255) not null,
|
|
154
|
+
crowdin_id varchar(255) not null,
|
|
155
|
+
type varchar(255) not null,
|
|
156
|
+
payload text,
|
|
157
|
+
title text,
|
|
158
|
+
progress int 0,
|
|
159
|
+
status varchar(255) '${job_1.JobStatus.CREATED}',
|
|
160
|
+
payload text,
|
|
161
|
+
info text,
|
|
162
|
+
data text,
|
|
163
|
+
created_at varchar(255) not null,
|
|
164
|
+
updated_at varchar(255),
|
|
165
|
+
finished_at varchar(255)
|
|
166
|
+
)
|
|
138
167
|
`);
|
|
139
168
|
});
|
|
140
169
|
}
|
|
@@ -200,6 +229,8 @@ class MySQLStorage {
|
|
|
200
229
|
yield connection.execute('DELETE FROM files_snapshot WHERE crowdin_id = ?', [id]);
|
|
201
230
|
yield connection.execute('DELETE FROM webhooks WHERE crowdin_id = ?', [id]);
|
|
202
231
|
yield connection.execute('DELETE FROM user_errors WHERE crowdin_id = ?', [id]);
|
|
232
|
+
yield connection.execute('DELETE FROM integration_settings WHERE crowdin_id = ?', [id]);
|
|
233
|
+
yield connection.execute('DELETE FROM job WHERE crowdin_id = ?', [id]);
|
|
203
234
|
}));
|
|
204
235
|
});
|
|
205
236
|
}
|
|
@@ -219,17 +250,11 @@ class MySQLStorage {
|
|
|
219
250
|
yield this.executeQuery((connection) => connection.execute('UPDATE integration_credentials SET credentials = ? WHERE id = ?', [credentials, id]));
|
|
220
251
|
});
|
|
221
252
|
}
|
|
222
|
-
updateIntegrationConfig(id, config) {
|
|
223
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
-
yield this.dbPromise;
|
|
225
|
-
yield this.executeQuery((connection) => connection.execute('UPDATE integration_credentials SET config = ? WHERE id = ?', [config, id]));
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
253
|
getIntegrationCredentials(id) {
|
|
229
254
|
return __awaiter(this, void 0, void 0, function* () {
|
|
230
255
|
yield this.dbPromise;
|
|
231
256
|
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
232
|
-
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]);
|
|
233
258
|
return (rows || [])[0];
|
|
234
259
|
}));
|
|
235
260
|
});
|
|
@@ -238,7 +263,7 @@ class MySQLStorage {
|
|
|
238
263
|
return __awaiter(this, void 0, void 0, function* () {
|
|
239
264
|
yield this.dbPromise;
|
|
240
265
|
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
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]);
|
|
242
267
|
return rows || [];
|
|
243
268
|
}));
|
|
244
269
|
});
|
|
@@ -251,6 +276,7 @@ class MySQLStorage {
|
|
|
251
276
|
yield connection.execute('DELETE FROM sync_settings where integration_id = ?', [id]);
|
|
252
277
|
yield connection.execute('DELETE FROM files_snapshot where integration_id = ?', [id]);
|
|
253
278
|
yield connection.execute('DELETE FROM webhooks where integration_id = ?', [id]);
|
|
279
|
+
yield connection.execute('DELETE FROM job where integration_id = ?', [id]);
|
|
254
280
|
}));
|
|
255
281
|
});
|
|
256
282
|
}
|
|
@@ -263,6 +289,7 @@ class MySQLStorage {
|
|
|
263
289
|
yield connection.execute('DELETE FROM files_snapshot where crowdin_id = ?', [crowdinId]);
|
|
264
290
|
yield connection.execute('DELETE FROM webhooks where crowdin_id = ?', [crowdinId]);
|
|
265
291
|
yield connection.execute('DELETE FROM user_errors where crowdin_id = ?', [crowdinId]);
|
|
292
|
+
yield connection.execute('DELETE FROM job where crowdin_id = ?', [crowdinId]);
|
|
266
293
|
}));
|
|
267
294
|
});
|
|
268
295
|
}
|
|
@@ -429,5 +456,123 @@ class MySQLStorage {
|
|
|
429
456
|
});
|
|
430
457
|
});
|
|
431
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
|
+
}
|
|
495
|
+
createJob({ integrationId, crowdinId, type, title, payload }) {
|
|
496
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
497
|
+
const id = (0, uuid_1.v4)();
|
|
498
|
+
yield this.dbPromise;
|
|
499
|
+
yield this.executeQuery((connection) => connection.execute(`
|
|
500
|
+
INSERT INTO jobs(id, integration_id, crowdin_id, type, payload, title, created_at)
|
|
501
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
502
|
+
`, [id, integrationId, crowdinId, type, payload, title, Date.now().toString()]));
|
|
503
|
+
return id;
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
updateJob({ id, progress, status, info, data }) {
|
|
507
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
508
|
+
const updateFields = ['updated_at'];
|
|
509
|
+
const updateParams = [Date.now().toString()];
|
|
510
|
+
if (progress) {
|
|
511
|
+
updateFields.push('progress = ?');
|
|
512
|
+
updateParams.push(progress);
|
|
513
|
+
if (progress >= 100) {
|
|
514
|
+
updateFields.push('finished_at = ?');
|
|
515
|
+
updateParams.push(Date.now().toString());
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (status) {
|
|
519
|
+
updateFields.push('status = ?');
|
|
520
|
+
updateParams.push(status);
|
|
521
|
+
if (!updateFields.includes('finished_at = ?') && [job_1.JobStatus.FAILED, job_1.JobStatus.CANCELED].includes(status)) {
|
|
522
|
+
updateFields.push('finished_at = ?');
|
|
523
|
+
updateParams.push(Date.now().toString());
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
if (data) {
|
|
527
|
+
updateFields.push('data = ?');
|
|
528
|
+
updateParams.push(data);
|
|
529
|
+
}
|
|
530
|
+
if (info) {
|
|
531
|
+
updateFields.push('info = ?');
|
|
532
|
+
updateParams.push(info);
|
|
533
|
+
}
|
|
534
|
+
updateParams.push(id);
|
|
535
|
+
yield this.dbPromise;
|
|
536
|
+
yield this.executeQuery((connection) => connection.execute(`
|
|
537
|
+
UPDATE job
|
|
538
|
+
SET ${updateFields.join(', ')}
|
|
539
|
+
WHERE id = ?
|
|
540
|
+
`, updateParams));
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
getJob({ id }) {
|
|
544
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
545
|
+
yield this.dbPromise;
|
|
546
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
547
|
+
const [rows] = yield connection.execute(`
|
|
548
|
+
SELECT id, integration_id as integrationId, crowdin_id as crowdinId, type, payload, progress, status,
|
|
549
|
+
title, info, payload, data, created_at as createdAt, updated_at as updatedAt, finished_at as finishedAt
|
|
550
|
+
FROM job
|
|
551
|
+
WHERE id = ?
|
|
552
|
+
`, [id]);
|
|
553
|
+
return (rows || [])[0];
|
|
554
|
+
}));
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
getActiveJobs({ integrationId, crowdinId }) {
|
|
558
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
559
|
+
yield this.dbPromise;
|
|
560
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
561
|
+
const [rows] = yield connection.execute(`
|
|
562
|
+
SELECT id, integration_id as integrationId, crowdin_id as crowdinId, type, payload, progress, status,
|
|
563
|
+
title, info, payload, data, created_at as createdAt, updated_at as updatedAt, finished_at as finishedAt
|
|
564
|
+
FROM job
|
|
565
|
+
WHERE integration_id = ? AND crowdin_id = ? AND finished_at is NULL
|
|
566
|
+
`, [integrationId, crowdinId]);
|
|
567
|
+
return rows || [];
|
|
568
|
+
}));
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
deleteFinishedJobs() {
|
|
572
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
573
|
+
yield this.dbPromise;
|
|
574
|
+
yield this.executeQuery((connection) => connection.execute('DELETE FROM job WHERE finished_at is not NULL', []));
|
|
575
|
+
});
|
|
576
|
+
}
|
|
432
577
|
}
|
|
433
578
|
exports.MySQLStorage = MySQLStorage;
|
package/out/storage/postgre.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../models/job';
|
|
4
5
|
export interface PostgreStorageConfig {
|
|
5
6
|
host?: string;
|
|
6
7
|
connectionString?: string;
|
|
@@ -30,7 +31,6 @@ export declare class PostgreStorage implements Storage {
|
|
|
30
31
|
deleteCrowdinCredentials(id: string): Promise<void>;
|
|
31
32
|
saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
|
|
32
33
|
updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
|
|
33
|
-
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
34
34
|
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
35
35
|
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
36
36
|
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
@@ -54,4 +54,13 @@ export declare class PostgreStorage implements Storage {
|
|
|
54
54
|
getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[] | undefined>;
|
|
55
55
|
saveUserError(action: string, message: string, data: any, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
56
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>;
|
|
61
|
+
createJob({ integrationId, crowdinId, type, payload, title }: CreateJobParams): Promise<string>;
|
|
62
|
+
updateJob({ id, progress, status, info, data }: UpdateJobParams): Promise<void>;
|
|
63
|
+
getJob({ id }: GetJobParams): Promise<Job | undefined>;
|
|
64
|
+
getActiveJobs({ integrationId, crowdinId }: GetActiveJobsParams): Promise<Job[] | undefined>;
|
|
65
|
+
deleteFinishedJobs(): Promise<void>;
|
|
57
66
|
}
|
package/out/storage/postgre.js
CHANGED
|
@@ -12,6 +12,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.PostgreStorage = void 0;
|
|
14
14
|
const pg_1 = require("pg");
|
|
15
|
+
const uuid_1 = require("uuid");
|
|
16
|
+
const job_1 = require("../models/job");
|
|
15
17
|
const util_1 = require("../util");
|
|
16
18
|
class PostgreStorage {
|
|
17
19
|
constructor(config) {
|
|
@@ -95,7 +97,6 @@ class PostgreStorage {
|
|
|
95
97
|
(
|
|
96
98
|
id varchar primary key,
|
|
97
99
|
credentials varchar,
|
|
98
|
-
config varchar,
|
|
99
100
|
crowdin_id varchar not null
|
|
100
101
|
)
|
|
101
102
|
`);
|
|
@@ -150,6 +151,34 @@ class PostgreStorage {
|
|
|
150
151
|
integration_id varchar
|
|
151
152
|
)
|
|
152
153
|
`);
|
|
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(`
|
|
164
|
+
create table if not exists job
|
|
165
|
+
(
|
|
166
|
+
id varchar not null primary key,
|
|
167
|
+
integration_id varchar not null,
|
|
168
|
+
crowdin_id varchar not null,
|
|
169
|
+
type varchar not null,
|
|
170
|
+
payload varchar null,
|
|
171
|
+
title varchar null,
|
|
172
|
+
progress int 0,
|
|
173
|
+
status varchar '${job_1.JobStatus.CREATED}',
|
|
174
|
+
payload varchar null,
|
|
175
|
+
info varchar null,
|
|
176
|
+
data varchar null,
|
|
177
|
+
created_at varchar not null,
|
|
178
|
+
updated_at varchar null,
|
|
179
|
+
finished_at varchar null
|
|
180
|
+
)
|
|
181
|
+
`);
|
|
153
182
|
});
|
|
154
183
|
}
|
|
155
184
|
saveCrowdinCredentials(credentials) {
|
|
@@ -214,6 +243,8 @@ class PostgreStorage {
|
|
|
214
243
|
yield client.query('DELETE FROM app_metadata WHERE crowdin_id = $1', [id]);
|
|
215
244
|
yield client.query('DELETE FROM webhooks WHERE crowdin_id = $1', [id]);
|
|
216
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]);
|
|
247
|
+
yield client.query('DELETE FROM job WHERE crowdin_id = $1', [id]);
|
|
217
248
|
}));
|
|
218
249
|
});
|
|
219
250
|
}
|
|
@@ -233,17 +264,11 @@ class PostgreStorage {
|
|
|
233
264
|
yield this.executeQuery((client) => client.query('UPDATE integration_credentials SET credentials = $1 WHERE id = $2', [credentials, id]));
|
|
234
265
|
});
|
|
235
266
|
}
|
|
236
|
-
updateIntegrationConfig(id, config) {
|
|
237
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
-
yield this.dbPromise;
|
|
239
|
-
yield this.executeQuery((client) => client.query('UPDATE integration_credentials SET config = $1 WHERE id = $2', [config, id]));
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
267
|
getIntegrationCredentials(id) {
|
|
243
268
|
return __awaiter(this, void 0, void 0, function* () {
|
|
244
269
|
yield this.dbPromise;
|
|
245
270
|
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
246
|
-
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]);
|
|
247
272
|
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
248
273
|
}));
|
|
249
274
|
});
|
|
@@ -252,7 +277,7 @@ class PostgreStorage {
|
|
|
252
277
|
return __awaiter(this, void 0, void 0, function* () {
|
|
253
278
|
yield this.dbPromise;
|
|
254
279
|
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
255
|
-
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]);
|
|
256
281
|
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
257
282
|
}));
|
|
258
283
|
});
|
|
@@ -265,6 +290,7 @@ class PostgreStorage {
|
|
|
265
290
|
yield client.query('DELETE FROM sync_settings where integration_id = $1', [id]);
|
|
266
291
|
yield client.query('DELETE FROM files_snapshot where integration_id = $1', [id]);
|
|
267
292
|
yield client.query('DELETE FROM webhooks where integration_id = $1', [id]);
|
|
293
|
+
yield client.query('DELETE FROM job where integration_id = $1', [id]);
|
|
268
294
|
}));
|
|
269
295
|
});
|
|
270
296
|
}
|
|
@@ -277,6 +303,7 @@ class PostgreStorage {
|
|
|
277
303
|
yield client.query('DELETE FROM files_snapshot where crowdin_id = $1', [crowdinId]);
|
|
278
304
|
yield client.query('DELETE FROM webhooks where crowdin_id = $1', [crowdinId]);
|
|
279
305
|
yield client.query('DELETE FROM user_errors where crowdin_id = $1', [crowdinId]);
|
|
306
|
+
yield client.query('DELETE FROM job where crowdin_id = $1', [crowdinId]);
|
|
280
307
|
}));
|
|
281
308
|
});
|
|
282
309
|
}
|
|
@@ -444,5 +471,122 @@ class PostgreStorage {
|
|
|
444
471
|
});
|
|
445
472
|
});
|
|
446
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
|
+
}
|
|
508
|
+
createJob({ integrationId, crowdinId, type, payload, title }) {
|
|
509
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
510
|
+
const id = (0, uuid_1.v4)();
|
|
511
|
+
yield this.dbPromise;
|
|
512
|
+
yield this.executeQuery((client) => client.query(`
|
|
513
|
+
INSERT
|
|
514
|
+
INTO job(id, integration_id, crowdin_id, type, payload, title, created_at)
|
|
515
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
516
|
+
`, [id, integrationId, crowdinId, type, payload, title, Date.now().toString()]));
|
|
517
|
+
return id;
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
updateJob({ id, progress, status, info, data }) {
|
|
521
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
522
|
+
const updateFields = ['updated_at'];
|
|
523
|
+
const updateParams = [Date.now().toString()];
|
|
524
|
+
if (progress) {
|
|
525
|
+
updateFields.push('progress = $' + updateParams.length.toString());
|
|
526
|
+
updateParams.push(progress);
|
|
527
|
+
if (progress >= 100) {
|
|
528
|
+
updateFields.push('finished_at = $' + updateParams.length.toString());
|
|
529
|
+
updateParams.push(Date.now().toString());
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (status) {
|
|
533
|
+
updateFields.push('status = $' + updateParams.length.toString());
|
|
534
|
+
updateParams.push(status);
|
|
535
|
+
if ((!progress || progress <= 100) && [job_1.JobStatus.FAILED, job_1.JobStatus.CANCELED].includes(status)) {
|
|
536
|
+
updateFields.push('finished_at = $' + updateParams.length.toString());
|
|
537
|
+
updateParams.push(Date.now().toString());
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (data) {
|
|
541
|
+
updateFields.push('data = $' + updateParams.length.toString());
|
|
542
|
+
updateParams.push(data);
|
|
543
|
+
}
|
|
544
|
+
if (info) {
|
|
545
|
+
updateFields.push('info = $' + updateParams.length.toString());
|
|
546
|
+
updateParams.push(data);
|
|
547
|
+
}
|
|
548
|
+
updateParams.push(id);
|
|
549
|
+
yield this.dbPromise;
|
|
550
|
+
yield this.executeQuery((client) => client.query(`
|
|
551
|
+
UPDATE job
|
|
552
|
+
SET ${updateFields.join(', ')}
|
|
553
|
+
WHERE id = $${updateParams.length.toString()}
|
|
554
|
+
`, updateParams));
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
getJob({ id }) {
|
|
558
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
559
|
+
yield this.dbPromise;
|
|
560
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
561
|
+
const res = yield client.query(`
|
|
562
|
+
SELECT id, integration_id as integrationId, crowdin_id as crowdinId, type, payload, progress, status,
|
|
563
|
+
title, info, payload, data, created_at as createdAt, updated_at as updatedAt, finished_at as finishedAt
|
|
564
|
+
FROM jobs
|
|
565
|
+
WHERE id = $1
|
|
566
|
+
`, [id]);
|
|
567
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
568
|
+
}));
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
getActiveJobs({ integrationId, crowdinId }) {
|
|
572
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
573
|
+
yield this.dbPromise;
|
|
574
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
575
|
+
const res = yield client.query(`
|
|
576
|
+
SELECT id, integration_id as integrationId, crowdin_id as crowdinId, type, payload, progress, status,
|
|
577
|
+
title, info, payload, data, created_at as createdAt, updated_at as updatedAt, finished_at as finishedAt
|
|
578
|
+
FROM jobs
|
|
579
|
+
WHERE integration_id = $1 AND crowdin_id = $2 AND finished_at is NULL
|
|
580
|
+
`, [integrationId, crowdinId]);
|
|
581
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
582
|
+
}));
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
deleteFinishedJobs() {
|
|
586
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
587
|
+
yield this.dbPromise;
|
|
588
|
+
yield this.executeQuery((client) => client.query(' DELETE FROM job WHERE finished_at is not NULL', []));
|
|
589
|
+
});
|
|
590
|
+
}
|
|
447
591
|
}
|
|
448
592
|
exports.PostgreStorage = PostgreStorage;
|
package/out/storage/sqlite.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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
|
+
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../models/job';
|
|
3
4
|
export interface SQLiteStorageConfig {
|
|
4
5
|
dbFolder: string;
|
|
5
6
|
}
|
|
@@ -14,8 +15,10 @@ export declare class SQLiteStorage implements Storage {
|
|
|
14
15
|
private run;
|
|
15
16
|
private get;
|
|
16
17
|
private each;
|
|
17
|
-
private
|
|
18
|
+
private removeColumns;
|
|
18
19
|
private addColumns;
|
|
20
|
+
private updateTables;
|
|
21
|
+
private moveIntegrationSettings;
|
|
19
22
|
migrate(): Promise<void>;
|
|
20
23
|
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
21
24
|
updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
@@ -24,7 +27,6 @@ export declare class SQLiteStorage implements Storage {
|
|
|
24
27
|
deleteCrowdinCredentials(id: string): Promise<void>;
|
|
25
28
|
saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
|
|
26
29
|
updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
|
|
27
|
-
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
28
30
|
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
29
31
|
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
30
32
|
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
@@ -48,4 +50,13 @@ export declare class SQLiteStorage implements Storage {
|
|
|
48
50
|
getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[]>;
|
|
49
51
|
saveUserError(action: string, message: string, data: any, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
50
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>;
|
|
57
|
+
createJob({ integrationId, crowdinId, type, title, payload }: CreateJobParams): Promise<string>;
|
|
58
|
+
updateJob({ id, progress, status, info, data }: UpdateJobParams): Promise<void>;
|
|
59
|
+
getJob({ id }: GetJobParams): Promise<Job | undefined>;
|
|
60
|
+
getActiveJobs({ integrationId, crowdinId }: GetActiveJobsParams): Promise<Job[] | undefined>;
|
|
61
|
+
deleteFinishedJobs(): Promise<void>;
|
|
51
62
|
}
|