@crowdin/app-project-module 1.15.1 → 2.0.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/index.js +8 -15
- package/out/middlewares/auto-credentials-masker.js +5 -2
- package/out/middlewares/crowdin-client.d.ts +1 -1
- package/out/middlewares/crowdin-client.js +1 -1
- package/out/middlewares/export.d.ts +2 -2
- package/out/middlewares/export.js +4 -35
- package/out/middlewares/json-response.d.ts +1 -1
- package/out/middlewares/json-response.js +1 -1
- package/out/modules/ai-prompt-provider/index.js +6 -6
- package/out/modules/ai-provider/index.js +7 -7
- package/out/modules/ai-provider/types.d.ts +10 -0
- package/out/modules/ai-provider/types.js +12 -0
- package/out/modules/ai-provider/util/index.d.ts +0 -10
- package/out/modules/ai-provider/util/index.js +2 -13
- package/out/modules/ai-request-processors/index.js +4 -4
- package/out/modules/api/api.js +18 -18
- package/out/modules/auth-guard/index.js +4 -5
- package/out/modules/automation-action/index.js +4 -6
- package/out/modules/context-menu/index.js +4 -13
- package/out/modules/custom-mt/index.js +4 -4
- package/out/modules/custom-spell-check/index.js +11 -11
- package/out/modules/editor-right-panel/index.js +1 -1
- package/out/modules/external-qa-check/index.js +7 -7
- package/out/modules/file-processing/index.js +14 -14
- package/out/modules/integration/index.js +26 -26
- package/out/modules/integration/types.d.ts +4 -4
- package/out/modules/integration/util/files.js +1 -1
- package/out/modules/integration/util/types.d.ts +1 -1
- package/out/modules/manifest.js +70 -281
- package/out/modules/modal/index.js +4 -13
- package/out/modules/organization-menu/index.js +1 -1
- package/out/modules/organization-settings-menu/index.js +1 -1
- package/out/modules/profile-resources-menu/index.js +1 -1
- package/out/modules/profile-settings-menu/index.js +1 -1
- package/out/modules/project-menu/index.js +1 -1
- package/out/modules/project-menu-crowdsource/index.js +1 -1
- package/out/modules/project-reports/index.js +1 -1
- package/out/modules/project-tools/index.js +1 -1
- package/out/modules/webhooks/index.js +3 -6
- package/out/modules/workflow-step-type/index.js +6 -6
- package/out/static/ui/form.bundle.js +7947 -6975
- package/out/static/ui/form.bundle.js.map +1 -1
- package/out/storage/drizzle/d1/index.d.ts +7 -0
- package/out/storage/drizzle/d1/index.js +48 -0
- package/out/storage/drizzle/d1/migrations/init.d.ts +2 -0
- package/out/storage/drizzle/d1/migrations/init.js +122 -0
- package/out/storage/drizzle/d1/types.d.ts +13 -0
- package/out/storage/drizzle/d1/types.js +38 -0
- package/out/storage/{sqlite.d.ts → drizzle/index.d.ts} +37 -58
- package/out/storage/drizzle/index.js +939 -0
- package/out/storage/drizzle/postgresql/config.d.ts +5 -0
- package/out/storage/drizzle/postgresql/config.js +11 -0
- package/out/storage/drizzle/postgresql/index.d.ts +14 -0
- package/out/storage/drizzle/postgresql/index.js +144 -0
- package/out/storage/drizzle/postgresql/migrations/0000_init.sql +113 -0
- package/out/storage/drizzle/postgresql/migrations/0001_init_indexes.sql +28 -0
- package/out/storage/drizzle/postgresql/migrations/meta/0000_snapshot.json +646 -0
- package/out/storage/drizzle/postgresql/migrations/meta/0001_snapshot.json +646 -0
- package/out/storage/drizzle/postgresql/migrations/meta/_journal.json +20 -0
- package/out/storage/drizzle/postgresql/schema.d.ts +1410 -0
- package/out/storage/drizzle/postgresql/schema.js +106 -0
- package/out/storage/drizzle/sqlite/config.d.ts +5 -0
- package/out/storage/drizzle/sqlite/config.js +11 -0
- package/out/storage/drizzle/sqlite/index.d.ts +8 -0
- package/out/storage/drizzle/sqlite/index.js +63 -0
- package/out/storage/drizzle/sqlite/migrations/0000_init.sql +113 -0
- package/out/storage/drizzle/sqlite/migrations/meta/0000_snapshot.json +687 -0
- package/out/storage/drizzle/sqlite/migrations/meta/_journal.json +13 -0
- package/out/storage/drizzle/sqlite/schema.d.ts +1544 -0
- package/out/storage/drizzle/sqlite/schema.js +106 -0
- package/out/storage/index.d.ts +2 -88
- package/out/storage/index.js +12 -128
- package/out/storage/internal/backup.d.ts +3 -0
- package/out/storage/internal/backup.js +94 -0
- package/out/storage/types.d.ts +66 -0
- package/out/types.d.ts +43 -47
- package/out/util/credentials-masker.js +2 -2
- package/out/util/export.d.ts +1 -0
- package/out/util/export.js +2 -1
- package/out/util/index.d.ts +2 -1
- package/out/util/index.js +12 -9
- package/out/util/normalize-module.d.ts +0 -1
- package/out/util/normalize-module.js +0 -4
- package/package.json +23 -23
- package/out/modules/ai-tools/handlers/tool-calls.d.ts +0 -4
- package/out/modules/ai-tools/handlers/tool-calls.js +0 -52
- package/out/modules/ai-tools/index.d.ts +0 -10
- package/out/modules/ai-tools/index.js +0 -46
- package/out/modules/ai-tools/types.d.ts +0 -63
- package/out/modules/ai-tools/types.js +0 -2
- package/out/modules/ai-tools/util/index.d.ts +0 -5
- package/out/modules/ai-tools/util/index.js +0 -24
- package/out/storage/d1.d.ts +0 -107
- package/out/storage/d1.js +0 -837
- package/out/storage/export.d.ts +0 -1
- package/out/storage/export.js +0 -2
- package/out/storage/mysql.d.ts +0 -109
- package/out/storage/mysql.js +0 -984
- package/out/storage/postgre.d.ts +0 -124
- package/out/storage/postgre.js +0 -1027
- package/out/storage/sqlite.js +0 -786
package/out/storage/postgre.js
DELETED
|
@@ -1,1027 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable no-unused-expressions */
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.PostgreStorage = void 0;
|
|
17
|
-
const pg_1 = require("pg");
|
|
18
|
-
const crypto_1 = require("crypto");
|
|
19
|
-
const types_1 = require("../types");
|
|
20
|
-
const types_2 = require("../modules/integration/util/types");
|
|
21
|
-
const util_1 = require("../util");
|
|
22
|
-
const fs_1 = __importDefault(require("fs"));
|
|
23
|
-
const path_1 = require("path");
|
|
24
|
-
class PostgreStorage {
|
|
25
|
-
constructor(config, directoryPath) {
|
|
26
|
-
this.dbPromise = new Promise((res, rej) => {
|
|
27
|
-
this._res = res;
|
|
28
|
-
this._rej = rej;
|
|
29
|
-
});
|
|
30
|
-
this.tables = {
|
|
31
|
-
crowdin_credentials: `(
|
|
32
|
-
id varchar primary key,
|
|
33
|
-
app_secret varchar,
|
|
34
|
-
domain varchar,
|
|
35
|
-
user_id varchar,
|
|
36
|
-
agent_id varchar,
|
|
37
|
-
organization_id varchar,
|
|
38
|
-
base_url varchar,
|
|
39
|
-
access_token varchar not null,
|
|
40
|
-
refresh_token varchar not null,
|
|
41
|
-
expire varchar not null,
|
|
42
|
-
type varchar not null
|
|
43
|
-
)`,
|
|
44
|
-
integration_credentials: `(
|
|
45
|
-
id varchar primary key,
|
|
46
|
-
credentials varchar,
|
|
47
|
-
crowdin_id varchar not null,
|
|
48
|
-
managers varchar
|
|
49
|
-
)`,
|
|
50
|
-
sync_settings: `(
|
|
51
|
-
id serial primary key,
|
|
52
|
-
files varchar,
|
|
53
|
-
integration_id varchar not null,
|
|
54
|
-
crowdin_id varchar not null,
|
|
55
|
-
type varchar not null,
|
|
56
|
-
provider varchar not null
|
|
57
|
-
)`,
|
|
58
|
-
app_metadata: `(
|
|
59
|
-
id varchar primary key,
|
|
60
|
-
data varchar,
|
|
61
|
-
crowdin_id varchar
|
|
62
|
-
)`,
|
|
63
|
-
files_snapshot: `(
|
|
64
|
-
id serial primary key,
|
|
65
|
-
integration_id varchar not null,
|
|
66
|
-
crowdin_id varchar not null,
|
|
67
|
-
files varchar,
|
|
68
|
-
provider varchar not null
|
|
69
|
-
)`,
|
|
70
|
-
webhooks: `(
|
|
71
|
-
id serial primary key,
|
|
72
|
-
file_id varchar not null,
|
|
73
|
-
integration_id varchar not null,
|
|
74
|
-
crowdin_id varchar not null,
|
|
75
|
-
provider varchar not null
|
|
76
|
-
)`,
|
|
77
|
-
user_errors: `(
|
|
78
|
-
id serial primary key,
|
|
79
|
-
action varchar not null,
|
|
80
|
-
message varchar not null,
|
|
81
|
-
data varchar,
|
|
82
|
-
created_at varchar not null,
|
|
83
|
-
crowdin_id varchar not null,
|
|
84
|
-
integration_id varchar
|
|
85
|
-
)`,
|
|
86
|
-
integration_settings: `(
|
|
87
|
-
id serial primary key,
|
|
88
|
-
integration_id varchar not null,
|
|
89
|
-
crowdin_id varchar not null,
|
|
90
|
-
config varchar
|
|
91
|
-
)`,
|
|
92
|
-
job: `(
|
|
93
|
-
id varchar not null primary key,
|
|
94
|
-
integration_id varchar not null,
|
|
95
|
-
crowdin_id varchar not null,
|
|
96
|
-
type varchar not null,
|
|
97
|
-
title varchar null,
|
|
98
|
-
progress int default 0,
|
|
99
|
-
status varchar default '${types_2.JobStatus.CREATED}',
|
|
100
|
-
payload varchar null,
|
|
101
|
-
info varchar null,
|
|
102
|
-
data varchar null,
|
|
103
|
-
attempt int default 0,
|
|
104
|
-
errors varchar null,
|
|
105
|
-
processed_entities varchar null,
|
|
106
|
-
initiated_by varchar null,
|
|
107
|
-
created_at varchar not null,
|
|
108
|
-
updated_at varchar null,
|
|
109
|
-
finished_at varchar null
|
|
110
|
-
)`,
|
|
111
|
-
translation_file_cache: `(
|
|
112
|
-
id serial primary key,
|
|
113
|
-
integration_id varchar not null,
|
|
114
|
-
crowdin_id varchar not null,
|
|
115
|
-
file_id int not null,
|
|
116
|
-
language_id varchar not null,
|
|
117
|
-
etag varchar
|
|
118
|
-
)`,
|
|
119
|
-
unsynced_files: `(
|
|
120
|
-
id serial primary key,
|
|
121
|
-
integration_id varchar not null,
|
|
122
|
-
crowdin_id varchar not null,
|
|
123
|
-
files varchar
|
|
124
|
-
)`,
|
|
125
|
-
synced_data: `(
|
|
126
|
-
id serial primary key,
|
|
127
|
-
files varchar,
|
|
128
|
-
integration_id varchar not null,
|
|
129
|
-
crowdin_id varchar not null,
|
|
130
|
-
type varchar not null,
|
|
131
|
-
updated_at varchar null
|
|
132
|
-
)`,
|
|
133
|
-
};
|
|
134
|
-
this.tableIndexes = {
|
|
135
|
-
integration_credentials: {
|
|
136
|
-
idx_crowdin: '(crowdin_id)',
|
|
137
|
-
},
|
|
138
|
-
sync_settings: {
|
|
139
|
-
idx_integration_provider: '(integration_id, provider)',
|
|
140
|
-
idx_crowdin: '(crowdin_id)',
|
|
141
|
-
idx_type: '(type)',
|
|
142
|
-
},
|
|
143
|
-
files_snapshot: {
|
|
144
|
-
idx_integration: '(integration_id)',
|
|
145
|
-
idx_crowdin: '(crowdin_id)',
|
|
146
|
-
},
|
|
147
|
-
webhooks: {
|
|
148
|
-
idx_integration_crowdin: '(integration_id, crowdin_id)',
|
|
149
|
-
idx_file_provider: '(file_id, provider)',
|
|
150
|
-
},
|
|
151
|
-
user_errors: {
|
|
152
|
-
idx_integration_crowdin: '(integration_id, crowdin_id)',
|
|
153
|
-
idx_crowdin: '(crowdin_id)',
|
|
154
|
-
idx_created_at: '(created_at)',
|
|
155
|
-
},
|
|
156
|
-
integration_settings: {
|
|
157
|
-
idx_integration: '(integration_id)',
|
|
158
|
-
idx_crowdin: '(crowdin_id)',
|
|
159
|
-
},
|
|
160
|
-
job: {
|
|
161
|
-
idx_integration_crowdin: '(integration_id, crowdin_id) WHERE finished_at IS NULL',
|
|
162
|
-
idx_finished_at: '(finished_at) WHERE finished_at IS NOT NULL',
|
|
163
|
-
idx_status: '(status) WHERE finished_at IS NULL',
|
|
164
|
-
},
|
|
165
|
-
translation_file_cache: {
|
|
166
|
-
idx_integration_crowdin_file_language: '(integration_id, crowdin_id, file_id, language_id)',
|
|
167
|
-
idx_crowdin: '(crowdin_id)',
|
|
168
|
-
},
|
|
169
|
-
unsynced_files: {
|
|
170
|
-
idx_integration_crowdin: '(integration_id, crowdin_id)',
|
|
171
|
-
idx_crowdin: '(crowdin_id)',
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
this.config = config.postgreConfig;
|
|
175
|
-
this.directoryPath = directoryPath;
|
|
176
|
-
this.migrationLockId = this.generateLockId(config.name);
|
|
177
|
-
}
|
|
178
|
-
generateLockId(str) {
|
|
179
|
-
// Create MD5 hash of the string
|
|
180
|
-
const hash = (0, crypto_1.createHash)('md5').update(str).digest('hex');
|
|
181
|
-
// Take first 8 hex characters and convert to integer
|
|
182
|
-
return parseInt(hash.substring(0, 8), 16);
|
|
183
|
-
}
|
|
184
|
-
executeQuery(command) {
|
|
185
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
return (0, util_1.executeWithRetry)(() => __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
const client = new pg_1.Client(this.config);
|
|
188
|
-
try {
|
|
189
|
-
yield client.connect();
|
|
190
|
-
const res = yield command(client);
|
|
191
|
-
yield client.end();
|
|
192
|
-
return res;
|
|
193
|
-
}
|
|
194
|
-
catch (error) {
|
|
195
|
-
try {
|
|
196
|
-
yield client.end();
|
|
197
|
-
throw error;
|
|
198
|
-
}
|
|
199
|
-
catch (nestedError) {
|
|
200
|
-
throw nestedError;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}));
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
hasDumpFiles(directoryPath) {
|
|
207
|
-
if (!fs_1.default.existsSync(directoryPath)) {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
const [name, extension] = types_1.storageFiles.DUMP.split('%s');
|
|
211
|
-
const files = fs_1.default.readdirSync(directoryPath).filter((file) => file.startsWith(name) && file.endsWith(extension));
|
|
212
|
-
return files.length > 0;
|
|
213
|
-
}
|
|
214
|
-
migrate(skipOnboarding) {
|
|
215
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
-
try {
|
|
217
|
-
if (!skipOnboarding) {
|
|
218
|
-
if (this.directoryPath && this.hasDumpFiles(this.directoryPath)) {
|
|
219
|
-
yield this.migrateFromSqlite(this.directoryPath);
|
|
220
|
-
}
|
|
221
|
-
// Use advisory lock to prevent concurrent migrations
|
|
222
|
-
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
223
|
-
yield client.query('SELECT pg_advisory_lock($1)', [this.migrationLockId]);
|
|
224
|
-
try {
|
|
225
|
-
yield this.addTables(client);
|
|
226
|
-
yield this.alterTables(client);
|
|
227
|
-
}
|
|
228
|
-
finally {
|
|
229
|
-
yield client.query('SELECT pg_advisory_unlock($1)', [this.migrationLockId]);
|
|
230
|
-
}
|
|
231
|
-
}));
|
|
232
|
-
}
|
|
233
|
-
this._res && this._res();
|
|
234
|
-
}
|
|
235
|
-
catch (e) {
|
|
236
|
-
console.error(e);
|
|
237
|
-
this._rej && this._rej();
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
addColumns(client, newColumns, tableName) {
|
|
242
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
-
const tableInfo = yield client.query('SELECT column_name FROM information_schema.columns WHERE table_name = $1', [tableName]);
|
|
244
|
-
tableInfo.rows.map((columnInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
245
|
-
const index = newColumns.indexOf(columnInfo.column_name);
|
|
246
|
-
if (~index) {
|
|
247
|
-
newColumns.splice(index, 1);
|
|
248
|
-
}
|
|
249
|
-
}));
|
|
250
|
-
for (const column of newColumns) {
|
|
251
|
-
yield client.query(`ALTER TABLE ${tableName} ADD COLUMN ${column} varchar NULL;`);
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
addColumn(client, columnName, tableName, columnType) {
|
|
256
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
-
const tableInfo = yield client.query('SELECT column_name FROM information_schema.columns WHERE table_name = $1', [tableName]);
|
|
258
|
-
const exists = tableInfo.rows.some((columnInfo) => columnInfo.column_name === columnName);
|
|
259
|
-
if (!exists) {
|
|
260
|
-
yield client.query(`ALTER TABLE ${tableName} ADD COLUMN ${columnName} ${columnType};`);
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
addTables(client) {
|
|
265
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
-
for (const [tableName, tableSchema] of Object.entries(this.tables)) {
|
|
267
|
-
yield client.query(`create table if not exists ${tableName} ${tableSchema}`);
|
|
268
|
-
if (this.tableIndexes[tableName]) {
|
|
269
|
-
for (const [indexName, indexSchema] of Object.entries(this.tableIndexes[tableName])) {
|
|
270
|
-
yield client.query(`create index if not exists ${indexName} on ${tableName}${indexSchema}`);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
alterTables(client) {
|
|
277
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
-
yield this.addColumn(client, 'initiated_by', 'job', 'varchar NULL');
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
saveCrowdinCredentials(credentials) {
|
|
282
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
-
yield this.dbPromise;
|
|
284
|
-
yield this.executeQuery((client) => client.query('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, agent_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)', [
|
|
285
|
-
credentials.id,
|
|
286
|
-
credentials.appSecret,
|
|
287
|
-
credentials.domain,
|
|
288
|
-
credentials.userId,
|
|
289
|
-
credentials.agentId,
|
|
290
|
-
credentials.organizationId,
|
|
291
|
-
credentials.baseUrl,
|
|
292
|
-
credentials.accessToken,
|
|
293
|
-
credentials.refreshToken,
|
|
294
|
-
credentials.expire,
|
|
295
|
-
credentials.type,
|
|
296
|
-
]));
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
updateCrowdinCredentials(credentials) {
|
|
300
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
301
|
-
yield this.dbPromise;
|
|
302
|
-
yield this.executeQuery((client) => client.query('UPDATE crowdin_credentials SET app_secret = $1, domain = $2, user_id = $3, agent_id = $4, organization_id = $5, base_url = $6, access_token = $7, refresh_token = $8, expire = $9 WHERE id = $10', [
|
|
303
|
-
credentials.appSecret,
|
|
304
|
-
credentials.domain,
|
|
305
|
-
credentials.userId,
|
|
306
|
-
credentials.agentId,
|
|
307
|
-
credentials.organizationId,
|
|
308
|
-
credentials.baseUrl,
|
|
309
|
-
credentials.accessToken,
|
|
310
|
-
credentials.refreshToken,
|
|
311
|
-
credentials.expire,
|
|
312
|
-
credentials.id,
|
|
313
|
-
]));
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
getCrowdinCredentials(id) {
|
|
317
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
318
|
-
yield this.dbPromise;
|
|
319
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
320
|
-
const res = yield client.query('SELECT id, app_secret as "appSecret", domain, user_id as "userId", agent_id as "agentId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials WHERE id = $1', [id]);
|
|
321
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
322
|
-
}));
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
getAllCrowdinCredentials() {
|
|
326
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
-
yield this.dbPromise;
|
|
328
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
329
|
-
const res = yield client.query('SELECT id, app_secret as "appSecret", domain, user_id as "userId", agent_id as "agentId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials', []);
|
|
330
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
331
|
-
}));
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
deleteCrowdinCredentials(id) {
|
|
335
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
336
|
-
yield this.dbPromise;
|
|
337
|
-
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
338
|
-
yield client.query('DELETE FROM crowdin_credentials where id = $1', [id]);
|
|
339
|
-
yield client.query('DELETE FROM integration_credentials where crowdin_id = $1', [id]);
|
|
340
|
-
yield client.query('DELETE FROM sync_settings WHERE crowdin_id = $1', [id]);
|
|
341
|
-
yield client.query('DELETE FROM files_snapshot WHERE crowdin_id = $1', [id]);
|
|
342
|
-
yield client.query('DELETE FROM app_metadata WHERE crowdin_id = $1', [id]);
|
|
343
|
-
yield client.query('DELETE FROM webhooks WHERE crowdin_id = $1', [id]);
|
|
344
|
-
yield client.query('DELETE FROM user_errors WHERE crowdin_id = $1', [id]);
|
|
345
|
-
yield client.query('DELETE FROM integration_settings WHERE crowdin_id = $1', [id]);
|
|
346
|
-
yield client.query('DELETE FROM job WHERE crowdin_id = $1', [id]);
|
|
347
|
-
yield client.query('DELETE FROM translation_file_cache WHERE crowdin_id = $1', [id]);
|
|
348
|
-
yield client.query('DELETE FROM unsynced_files WHERE crowdin_id = $1', [id]);
|
|
349
|
-
yield client.query('DELETE FROM synced_data WHERE crowdin_id = $1', [id]);
|
|
350
|
-
}));
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
saveIntegrationCredentials(id, credentials, crowdinId) {
|
|
354
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
355
|
-
yield this.dbPromise;
|
|
356
|
-
yield this.executeQuery((client) => client.query('INSERT INTO integration_credentials(id, credentials, crowdin_id) VALUES ($1, $2, $3)', [
|
|
357
|
-
id,
|
|
358
|
-
credentials,
|
|
359
|
-
crowdinId,
|
|
360
|
-
]));
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
updateIntegrationCredentials(id, credentials) {
|
|
364
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
365
|
-
yield this.dbPromise;
|
|
366
|
-
yield this.executeQuery((client) => client.query('UPDATE integration_credentials SET credentials = $1 WHERE id = $2', [credentials, id]));
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
updateIntegrationManagers(id, managers) {
|
|
370
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
371
|
-
yield this.dbPromise;
|
|
372
|
-
yield this.executeQuery((client) => client.query('UPDATE integration_credentials SET managers = $1 WHERE id = $2', [managers, id]));
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
getIntegrationCredentials(id) {
|
|
376
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
377
|
-
yield this.dbPromise;
|
|
378
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
379
|
-
const res = yield client.query('SELECT id, credentials, crowdin_id as "crowdinId", managers FROM integration_credentials WHERE id = $1', [id]);
|
|
380
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
381
|
-
}));
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
getAllIntegrationCredentials(crowdinId) {
|
|
385
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
386
|
-
yield this.dbPromise;
|
|
387
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
388
|
-
const res = yield client.query('SELECT id, credentials, crowdin_id as "crowdinId", managers FROM integration_credentials WHERE crowdin_id = $1', [crowdinId]);
|
|
389
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
390
|
-
}));
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
deleteIntegrationCredentials(id) {
|
|
394
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
395
|
-
yield this.dbPromise;
|
|
396
|
-
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
397
|
-
yield client.query('DELETE FROM integration_credentials where id = $1', [id]);
|
|
398
|
-
yield client.query('DELETE FROM sync_settings where integration_id = $1', [id]);
|
|
399
|
-
yield client.query('DELETE FROM files_snapshot where integration_id = $1', [id]);
|
|
400
|
-
yield client.query('DELETE FROM webhooks where integration_id = $1', [id]);
|
|
401
|
-
yield client.query('DELETE FROM user_errors where integration_id = $1', [id]);
|
|
402
|
-
yield client.query('DELETE FROM integration_settings where integration_id = $1', [id]);
|
|
403
|
-
yield client.query('DELETE FROM job where integration_id = $1', [id]);
|
|
404
|
-
yield client.query('DELETE FROM translation_file_cache where integration_id = $1', [id]);
|
|
405
|
-
yield client.query('DELETE FROM unsynced_files where integration_id = $1', [id]);
|
|
406
|
-
yield client.query('DELETE FROM synced_data where integration_id = $1', [id]);
|
|
407
|
-
}));
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
deleteAllIntegrationCredentials(crowdinId) {
|
|
411
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
412
|
-
yield this.dbPromise;
|
|
413
|
-
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
414
|
-
yield client.query('DELETE FROM integration_credentials where crowdin_id = $1', [crowdinId]);
|
|
415
|
-
yield client.query('DELETE FROM sync_settings where crowdin_id = $1', [crowdinId]);
|
|
416
|
-
yield client.query('DELETE FROM files_snapshot where crowdin_id = $1', [crowdinId]);
|
|
417
|
-
yield client.query('DELETE FROM webhooks where crowdin_id = $1', [crowdinId]);
|
|
418
|
-
yield client.query('DELETE FROM user_errors where crowdin_id = $1', [crowdinId]);
|
|
419
|
-
yield client.query('DELETE FROM job where crowdin_id = $1', [crowdinId]);
|
|
420
|
-
yield client.query('DELETE FROM unsynced_files where crowdin_id = $1', [crowdinId]);
|
|
421
|
-
yield client.query('DELETE FROM synced_data where crowdin_id = $1', [crowdinId]);
|
|
422
|
-
}));
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
saveMetadata(id, metadata, crowdinId) {
|
|
426
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
427
|
-
yield this.dbPromise;
|
|
428
|
-
yield this.executeQuery((client) => client.query('INSERT INTO app_metadata(id, data, crowdin_id) VALUES ($1, $2, $3)', [
|
|
429
|
-
id,
|
|
430
|
-
JSON.stringify(metadata),
|
|
431
|
-
crowdinId,
|
|
432
|
-
]));
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
updateMetadata(id, metadata, crowdinId) {
|
|
436
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
437
|
-
yield this.dbPromise;
|
|
438
|
-
yield this.executeQuery((client) => client.query('UPDATE app_metadata SET data = $1, crowdin_id = $2 WHERE id = $3', [
|
|
439
|
-
JSON.stringify(metadata),
|
|
440
|
-
crowdinId,
|
|
441
|
-
id,
|
|
442
|
-
]));
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
getMetadata(id) {
|
|
446
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
447
|
-
yield this.dbPromise;
|
|
448
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
449
|
-
const res = yield client.query('SELECT data FROM app_metadata WHERE id = $1', [id]);
|
|
450
|
-
if (res === null || res === void 0 ? void 0 : res.rows[0]) {
|
|
451
|
-
return JSON.parse(res === null || res === void 0 ? void 0 : res.rows[0].data);
|
|
452
|
-
}
|
|
453
|
-
}));
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
getAllMetadata() {
|
|
457
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
458
|
-
yield this.dbPromise;
|
|
459
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
460
|
-
const res = yield client.query('SELECT * FROM app_metadata');
|
|
461
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
462
|
-
}));
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
deleteMetadata(id) {
|
|
466
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
467
|
-
yield this.dbPromise;
|
|
468
|
-
yield this.executeQuery((client) => client.query('DELETE FROM app_metadata where id = $1', [id]));
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
getSyncSettingsByProvider(integrationId, provider) {
|
|
472
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
473
|
-
yield this.dbPromise;
|
|
474
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
475
|
-
const res = yield client.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE integration_id = $1 AND provider = $2', [integrationId, provider]);
|
|
476
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
477
|
-
}));
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
getSyncSettingsBySchedule(type, schedule) {
|
|
481
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
482
|
-
yield this.dbPromise;
|
|
483
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
484
|
-
const res = yield client.query(`
|
|
485
|
-
SELECT s.id, s.files, s.integration_id as "integrationId", s.crowdin_id as "crowdinId", s.type, s.provider
|
|
486
|
-
FROM sync_settings s
|
|
487
|
-
INNER JOIN integration_settings i ON s.integration_id = i.integration_id
|
|
488
|
-
WHERE s.type = $1
|
|
489
|
-
AND CASE
|
|
490
|
-
WHEN i.config IS NULL THEN false
|
|
491
|
-
ELSE (i.config::json->>'schedule') = $2
|
|
492
|
-
END
|
|
493
|
-
`, [type, schedule]);
|
|
494
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
495
|
-
}));
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
saveSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
499
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
500
|
-
yield this.dbPromise;
|
|
501
|
-
yield this.executeQuery((client) => client.query('INSERT INTO sync_settings(files, integration_id, crowdin_id, type, provider) VALUES ($1, $2, $3, $4, $5)', [files, integrationId, crowdinId, type, provider]));
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
updateSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
505
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
506
|
-
yield this.dbPromise;
|
|
507
|
-
yield this.executeQuery((client) => client.query('UPDATE sync_settings SET files = $1 WHERE integration_id = $2 AND crowdin_id = $3 AND type = $4 AND provider = $5', [files, integrationId, crowdinId, type, provider]));
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
getSyncSettings(integrationId, crowdinId, type, provider) {
|
|
511
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
-
yield this.dbPromise;
|
|
513
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
514
|
-
const res = yield client.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE integration_id = $1 AND crowdin_id = $2 AND type = $3 AND provider = $4', [integrationId, crowdinId, type, provider]);
|
|
515
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
516
|
-
}));
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
saveFilesSnapshot(files, integrationId, crowdinId, provider) {
|
|
520
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
521
|
-
yield this.dbPromise;
|
|
522
|
-
yield this.executeQuery((client) => client.query('INSERT INTO files_snapshot(files, integration_id, crowdin_id, provider) VALUES ($1, $2, $3, $4)', [files, integrationId, crowdinId, provider]));
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
updateFilesSnapshot(files, integrationId, crowdinId, provider) {
|
|
526
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
527
|
-
yield this.dbPromise;
|
|
528
|
-
yield this.executeQuery((client) => client.query('UPDATE files_snapshot SET files = $1 WHERE integration_id = $2 AND crowdin_id = $3 AND provider = $4', [files, integrationId, crowdinId, provider]));
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
getFilesSnapshot(integrationId, crowdinId, provider) {
|
|
532
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
533
|
-
yield this.dbPromise;
|
|
534
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
535
|
-
const res = yield client.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId" FROM files_snapshot WHERE integration_id = $1 AND crowdin_id = $2 AND provider = $3', [integrationId, crowdinId, provider]);
|
|
536
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
537
|
-
}));
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
getAllWebhooks(integrationId, crowdinId, provider) {
|
|
541
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
542
|
-
yield this.dbPromise;
|
|
543
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
544
|
-
const res = yield client.query('SELECT id, file_id as "fileId", integration_id as "integrationId", crowdin_id as "crowdinId" FROM webhooks WHERE integration_id = $1 AND crowdin_id = $2 AND provider = $3', [integrationId, crowdinId, provider]);
|
|
545
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
546
|
-
}));
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
getWebhooks(fileId, integrationId, crowdinId, provider) {
|
|
550
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
551
|
-
yield this.dbPromise;
|
|
552
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
553
|
-
const res = yield client.query('SELECT id, file_id as "fileId", integration_id as "integrationId", crowdin_id as "crowdinId" FROM webhooks WHERE file_id = $1 AND integration_id = $2 AND crowdin_id = $3 AND provider = $4', [fileId, integrationId, crowdinId, provider]);
|
|
554
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
555
|
-
}));
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
saveWebhooks(fileId, integrationId, crowdinId, provider) {
|
|
559
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
560
|
-
yield this.dbPromise;
|
|
561
|
-
yield this.executeQuery((client) => client.query('INSERT INTO webhooks(file_id, integration_id, crowdin_id, provider) VALUES ($1, $2, $3, $4)', [fileId, integrationId, crowdinId, provider]));
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
deleteWebhooks(fileIds, integrationId, crowdinId, provider) {
|
|
565
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
566
|
-
if (!fileIds.length) {
|
|
567
|
-
return;
|
|
568
|
-
}
|
|
569
|
-
let index = 0;
|
|
570
|
-
const placeholders = fileIds.map(() => `$${++index}`).join(',');
|
|
571
|
-
yield this.dbPromise;
|
|
572
|
-
yield this.executeQuery((client) => client.query(`DELETE FROM webhooks WHERE file_id IN (${placeholders}) AND integration_id = $${++index} AND crowdin_id = $${++index} AND provider = $${++index}`, [...fileIds, integrationId, crowdinId, provider]));
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
getAllUserErrors(crowdinId, integrationId) {
|
|
576
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
577
|
-
yield this.dbPromise;
|
|
578
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
579
|
-
let whereIntegrationCondition = 'integration_id is NULL';
|
|
580
|
-
const params = [crowdinId];
|
|
581
|
-
if (integrationId) {
|
|
582
|
-
whereIntegrationCondition = 'integration_id = $2';
|
|
583
|
-
params.push(integrationId);
|
|
584
|
-
}
|
|
585
|
-
const res = yield client.query(`SELECT id, action, message, data, created_at as "createdAt", integration_id as "integrationId", crowdin_id as "crowdinId" FROM user_errors WHERE crowdin_id = $1 AND ${whereIntegrationCondition}`, params);
|
|
586
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
587
|
-
}));
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
saveUserError(action, message, data, createdAt, crowdinId, integrationId) {
|
|
591
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
592
|
-
yield this.dbPromise;
|
|
593
|
-
yield this.executeQuery((client) => client.query('INSERT INTO user_errors(action, message, data, created_at, integration_id, crowdin_id) VALUES ($1, $2, $3, $4, $5, $6)', [action, message, data, createdAt, integrationId, crowdinId]));
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
deleteUserErrors(createdAt, crowdinId, integrationId) {
|
|
597
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
598
|
-
yield this.dbPromise;
|
|
599
|
-
yield this.executeQuery((client) => {
|
|
600
|
-
let whereIntegrationCondition = 'integration_id is NULL';
|
|
601
|
-
const params = [createdAt, crowdinId];
|
|
602
|
-
if (integrationId) {
|
|
603
|
-
whereIntegrationCondition = 'integration_id = $3';
|
|
604
|
-
params.push(integrationId);
|
|
605
|
-
}
|
|
606
|
-
return client.query(`DELETE FROM user_errors WHERE created_at < $1 AND crowdin_id = $2 AND ${whereIntegrationCondition}`, params);
|
|
607
|
-
});
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
deleteAllUsersErrorsOlderThan(createdAt) {
|
|
611
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
612
|
-
yield this.dbPromise;
|
|
613
|
-
yield this.executeQuery((client) => {
|
|
614
|
-
return client.query('DELETE FROM user_errors WHERE created_at < $1', [createdAt]);
|
|
615
|
-
});
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
saveIntegrationConfig(integrationId, crowdinId, config) {
|
|
619
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
620
|
-
yield this.dbPromise;
|
|
621
|
-
yield this.executeQuery((client) => client.query('INSERT INTO integration_settings(integration_id, crowdin_id, config) VALUES ($1, $2, $3)', [
|
|
622
|
-
integrationId,
|
|
623
|
-
crowdinId,
|
|
624
|
-
config,
|
|
625
|
-
]));
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
getAllIntegrationConfigs(crowdinId) {
|
|
629
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
630
|
-
yield this.dbPromise;
|
|
631
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
632
|
-
const res = yield client.query('SELECT config FROM integration_settings WHERE crowdin_id = $1', [crowdinId]);
|
|
633
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
634
|
-
}));
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
getIntegrationConfig(integrationId) {
|
|
638
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
639
|
-
yield this.dbPromise;
|
|
640
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
641
|
-
const res = yield client.query('SELECT config FROM integration_settings WHERE integration_id = $1', [integrationId]);
|
|
642
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
643
|
-
}));
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
updateIntegrationConfig(integrationId, config) {
|
|
647
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
648
|
-
yield this.dbPromise;
|
|
649
|
-
yield this.executeQuery((client) => client.query('UPDATE integration_settings SET config = $1 WHERE integration_id = $2', [
|
|
650
|
-
config,
|
|
651
|
-
integrationId,
|
|
652
|
-
]));
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
createJob(_a) {
|
|
656
|
-
return __awaiter(this, arguments, void 0, function* ({ integrationId, crowdinId, type, payload, title, initiatedBy }) {
|
|
657
|
-
const id = (0, crypto_1.randomUUID)();
|
|
658
|
-
yield this.dbPromise;
|
|
659
|
-
yield this.executeQuery((client) => client.query(`
|
|
660
|
-
INSERT
|
|
661
|
-
INTO job(id, integration_id, crowdin_id, type, payload, title, initiated_by, created_at)
|
|
662
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
663
|
-
`, [id, integrationId, crowdinId, type, payload, title, initiatedBy !== null && initiatedBy !== void 0 ? initiatedBy : null, Date.now().toString()]));
|
|
664
|
-
return id;
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
updateJob(_a) {
|
|
668
|
-
return __awaiter(this, arguments, void 0, function* ({ id, progress, status, info, data, attempt, errors, processedEntities, }) {
|
|
669
|
-
let parametersPointer = 1;
|
|
670
|
-
const updateFields = [`updated_at = $${parametersPointer}`];
|
|
671
|
-
const updateParams = [Date.now().toString()];
|
|
672
|
-
if (progress) {
|
|
673
|
-
parametersPointer++;
|
|
674
|
-
updateFields.push('progress = $' + parametersPointer);
|
|
675
|
-
updateParams.push(Math.round(progress));
|
|
676
|
-
if (progress >= 100) {
|
|
677
|
-
parametersPointer++;
|
|
678
|
-
updateFields.push('finished_at = $' + parametersPointer);
|
|
679
|
-
updateParams.push(Date.now().toString());
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
if (status) {
|
|
683
|
-
parametersPointer++;
|
|
684
|
-
updateFields.push('status = $' + parametersPointer);
|
|
685
|
-
updateParams.push(status);
|
|
686
|
-
if ((!progress || progress <= 100) && [types_2.JobStatus.FAILED, types_2.JobStatus.CANCELED].includes(status)) {
|
|
687
|
-
parametersPointer++;
|
|
688
|
-
updateFields.push('finished_at = $' + parametersPointer);
|
|
689
|
-
updateParams.push(Date.now().toString());
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
if (data) {
|
|
693
|
-
parametersPointer++;
|
|
694
|
-
updateFields.push('data = $' + parametersPointer);
|
|
695
|
-
updateParams.push(data);
|
|
696
|
-
}
|
|
697
|
-
if (info) {
|
|
698
|
-
parametersPointer++;
|
|
699
|
-
updateFields.push('info = $' + parametersPointer);
|
|
700
|
-
updateParams.push(info);
|
|
701
|
-
}
|
|
702
|
-
if (attempt) {
|
|
703
|
-
parametersPointer++;
|
|
704
|
-
updateFields.push('attempt = $' + parametersPointer);
|
|
705
|
-
updateParams.push(attempt);
|
|
706
|
-
}
|
|
707
|
-
if (errors) {
|
|
708
|
-
parametersPointer++;
|
|
709
|
-
updateFields.push('errors = $' + parametersPointer);
|
|
710
|
-
updateParams.push(JSON.stringify(errors));
|
|
711
|
-
}
|
|
712
|
-
if (processedEntities) {
|
|
713
|
-
parametersPointer++;
|
|
714
|
-
updateFields.push('processed_entities = $' + parametersPointer);
|
|
715
|
-
updateParams.push(processedEntities);
|
|
716
|
-
}
|
|
717
|
-
parametersPointer++;
|
|
718
|
-
updateParams.push(id);
|
|
719
|
-
yield this.dbPromise;
|
|
720
|
-
yield this.executeQuery((client) => client.query(`
|
|
721
|
-
UPDATE job
|
|
722
|
-
SET ${updateFields.join(', ')}
|
|
723
|
-
WHERE id = $${parametersPointer}
|
|
724
|
-
`, updateParams));
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
getJob(_a) {
|
|
728
|
-
return __awaiter(this, arguments, void 0, function* ({ id }) {
|
|
729
|
-
yield this.dbPromise;
|
|
730
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
731
|
-
const res = yield client.query(`
|
|
732
|
-
SELECT id, integration_id as "integrationId", crowdin_id as "crowdinId", type, payload, progress, status,
|
|
733
|
-
title, info, data, attempt, errors, processed_entities as "processedEntities", initiated_by as "initiatedBy", created_at as "createdAt", updated_at as "updatedAt", finished_at as "finishedAt"
|
|
734
|
-
FROM job
|
|
735
|
-
WHERE id = $1
|
|
736
|
-
`, [id]);
|
|
737
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
738
|
-
}));
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
getActiveJobs(_a) {
|
|
742
|
-
return __awaiter(this, arguments, void 0, function* ({ integrationId, crowdinId }) {
|
|
743
|
-
yield this.dbPromise;
|
|
744
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
745
|
-
const res = yield client.query(`
|
|
746
|
-
SELECT id, integration_id as "integrationId", crowdin_id as "crowdinId", type, payload, progress, status,
|
|
747
|
-
title, info, data, attempt, errors, processed_entities as "processedEntities", initiated_by as "initiatedBy", created_at as "createdAt", updated_at as "updatedAt", finished_at as "finishedAt"
|
|
748
|
-
FROM job
|
|
749
|
-
WHERE integration_id = $1 AND crowdin_id = $2 AND finished_at is NULL
|
|
750
|
-
`, [integrationId, crowdinId]);
|
|
751
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
752
|
-
}));
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
deleteFinishedJobs() {
|
|
756
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
757
|
-
yield this.dbPromise;
|
|
758
|
-
yield this.executeQuery((client) => client.query(' DELETE FROM job WHERE finished_at is not NULL', []));
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
getAllInProgressJobs() {
|
|
762
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
763
|
-
yield this.dbPromise;
|
|
764
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
765
|
-
const res = yield client.query(`
|
|
766
|
-
SELECT id, integration_id as "integrationId", crowdin_id as "crowdinId", type, payload, progress, status,
|
|
767
|
-
title, info, data, attempt, errors, processed_entities as "processedEntities", initiated_by as "initiatedBy", created_at as "createdAt", updated_at as "updatedAt", finished_at as "finishedAt"
|
|
768
|
-
FROM job
|
|
769
|
-
WHERE status IN ($1, $2) AND finished_at is NULL
|
|
770
|
-
`, [types_2.JobStatus.IN_PROGRESS, types_2.JobStatus.CREATED]);
|
|
771
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
772
|
-
}));
|
|
773
|
-
});
|
|
774
|
-
}
|
|
775
|
-
getAllJobs(_a) {
|
|
776
|
-
return __awaiter(this, arguments, void 0, function* ({ integrationId, crowdinId, limit, offset }) {
|
|
777
|
-
yield this.dbPromise;
|
|
778
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
779
|
-
const res = yield client.query(`
|
|
780
|
-
SELECT
|
|
781
|
-
id,
|
|
782
|
-
integration_id as "integrationId",
|
|
783
|
-
crowdin_id as "crowdinId",
|
|
784
|
-
type,
|
|
785
|
-
payload,
|
|
786
|
-
progress,
|
|
787
|
-
status,
|
|
788
|
-
title,
|
|
789
|
-
info,
|
|
790
|
-
data,
|
|
791
|
-
attempt,
|
|
792
|
-
initiated_by as "initiatedBy",
|
|
793
|
-
created_at as "createdAt",
|
|
794
|
-
updated_at as "updatedAt",
|
|
795
|
-
finished_at as "finishedAt"
|
|
796
|
-
FROM job
|
|
797
|
-
WHERE integration_id = $1 AND crowdin_id = $2
|
|
798
|
-
ORDER BY created_at DESC
|
|
799
|
-
LIMIT $3 OFFSET $4
|
|
800
|
-
`, [integrationId, crowdinId, limit, offset]);
|
|
801
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
802
|
-
}));
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
saveTranslationCache(_a) {
|
|
806
|
-
return __awaiter(this, arguments, void 0, function* ({ integrationId, crowdinId, fileId, languageId, etag, }) {
|
|
807
|
-
yield this.dbPromise;
|
|
808
|
-
yield this.executeQuery((client) => client.query(`
|
|
809
|
-
INSERT
|
|
810
|
-
INTO translation_file_cache(integration_id, crowdin_id, file_id, language_id, etag)
|
|
811
|
-
VALUES ($1, $2, $3, $4, $5)
|
|
812
|
-
`, [integrationId, crowdinId, fileId, languageId, etag]));
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
getFileTranslationCache(_a) {
|
|
816
|
-
return __awaiter(this, arguments, void 0, function* ({ integrationId, crowdinId, fileId, }) {
|
|
817
|
-
yield this.dbPromise;
|
|
818
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
819
|
-
const res = yield client.query(`
|
|
820
|
-
SELECT integration_id as "integrationId", crowdin_id as "crowdinId", file_id as "fileId", language_id as "languageId", etag
|
|
821
|
-
FROM translation_file_cache
|
|
822
|
-
WHERE integration_id = $1 AND crowdin_id = $2 AND file_id = $3
|
|
823
|
-
`, [integrationId, crowdinId, fileId]);
|
|
824
|
-
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
825
|
-
}));
|
|
826
|
-
});
|
|
827
|
-
}
|
|
828
|
-
getFileTranslationCacheByLanguage(_a) {
|
|
829
|
-
return __awaiter(this, arguments, void 0, function* ({ integrationId, crowdinId, fileId, languageId, }) {
|
|
830
|
-
yield this.dbPromise;
|
|
831
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
832
|
-
const res = yield client.query(`
|
|
833
|
-
SELECT integration_id as "integrationId", crowdin_id as "crowdinId", file_id as "fileId", language_id as "languageId", etag
|
|
834
|
-
FROM translation_file_cache
|
|
835
|
-
WHERE integration_id = $1 AND crowdin_id = $2 AND file_id = $3 AND language_id = $4
|
|
836
|
-
`, [integrationId, crowdinId, fileId, languageId]);
|
|
837
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
838
|
-
}));
|
|
839
|
-
});
|
|
840
|
-
}
|
|
841
|
-
updateTranslationCache(_a) {
|
|
842
|
-
return __awaiter(this, arguments, void 0, function* ({ integrationId, crowdinId, fileId, languageId, etag, }) {
|
|
843
|
-
yield this.dbPromise;
|
|
844
|
-
yield this.executeQuery((client) => client.query(`
|
|
845
|
-
UPDATE translation_file_cache
|
|
846
|
-
SET etag = $1
|
|
847
|
-
WHERE integration_id = $2 AND crowdin_id = $3 AND file_id = $4 AND language_id = $5
|
|
848
|
-
`, [etag, integrationId, crowdinId, fileId, languageId]));
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
migrateFromSqlite(directoryPath) {
|
|
852
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
853
|
-
const [name, extension] = types_1.storageFiles.DUMP.split('%s');
|
|
854
|
-
const files = fs_1.default
|
|
855
|
-
.readdirSync(directoryPath)
|
|
856
|
-
.filter((file) => file.startsWith(name) && file.endsWith(extension))
|
|
857
|
-
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
|
|
858
|
-
for (const file of files) {
|
|
859
|
-
const filePath = (0, path_1.join)(directoryPath, file);
|
|
860
|
-
const sql = fs_1.default.readFileSync(filePath, 'utf8');
|
|
861
|
-
try {
|
|
862
|
-
yield this.executeQuery((client) => client.query(sql));
|
|
863
|
-
fs_1.default.unlinkSync(filePath);
|
|
864
|
-
}
|
|
865
|
-
catch (e) {
|
|
866
|
-
console.error('Error while executing', file);
|
|
867
|
-
console.error(e);
|
|
868
|
-
fs_1.default.renameSync(filePath, filePath.replace('dump_table_', 'error_dump_table_'));
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
// Reset sequences for tables with serial primary keys
|
|
872
|
-
yield this.resetSequences();
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
saveUnsyncedFiles(_a) {
|
|
876
|
-
return __awaiter(this, arguments, void 0, function* ({ integrationId, crowdinId, files }) {
|
|
877
|
-
yield this.dbPromise;
|
|
878
|
-
yield this.executeQuery((client) => client.query(`
|
|
879
|
-
INSERT
|
|
880
|
-
INTO unsynced_files(integration_id, crowdin_id, files)
|
|
881
|
-
VALUES ($1, $2, $3,)
|
|
882
|
-
`, [integrationId, crowdinId, files]));
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
updateUnsyncedFiles(_a) {
|
|
886
|
-
return __awaiter(this, arguments, void 0, function* ({ integrationId, crowdinId, files }) {
|
|
887
|
-
yield this.dbPromise;
|
|
888
|
-
yield this.executeQuery((client) => client.query(`
|
|
889
|
-
UPDATE unsynced_files
|
|
890
|
-
SET files = $1
|
|
891
|
-
WHERE integration_id = $2 AND crowdin_id = $3
|
|
892
|
-
`, [files, integrationId, crowdinId]));
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
getUnsyncedFiles(_a) {
|
|
896
|
-
return __awaiter(this, arguments, void 0, function* ({ integrationId, crowdinId }) {
|
|
897
|
-
yield this.dbPromise;
|
|
898
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
899
|
-
const res = yield client.query(`
|
|
900
|
-
SELECT files
|
|
901
|
-
FROM unsynced_files
|
|
902
|
-
WHERE integration_id = $1 AND crowdin_id = $2
|
|
903
|
-
`, [integrationId, crowdinId]);
|
|
904
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
905
|
-
}));
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
registerCustomTable(tableName, schema) {
|
|
909
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
910
|
-
const columns = Object.entries(schema)
|
|
911
|
-
.map(([col, def]) => `"${col}" ${def}`)
|
|
912
|
-
.join(', ');
|
|
913
|
-
const query = `CREATE TABLE IF NOT EXISTS "${tableName}" (${columns});`;
|
|
914
|
-
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
915
|
-
yield client.query(query);
|
|
916
|
-
return;
|
|
917
|
-
}));
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
insertRecord(tableName, data) {
|
|
921
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
922
|
-
const columns = Object.keys(data)
|
|
923
|
-
.map((col) => `"${col}"`)
|
|
924
|
-
.join(', ');
|
|
925
|
-
const placeholders = Object.keys(data)
|
|
926
|
-
.map((_, i) => `$${i + 1}`)
|
|
927
|
-
.join(', ');
|
|
928
|
-
const values = Object.values(data);
|
|
929
|
-
const query = `INSERT INTO "${tableName}" (${columns}) VALUES (${placeholders});`;
|
|
930
|
-
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
931
|
-
yield client.query(query, values);
|
|
932
|
-
return;
|
|
933
|
-
}));
|
|
934
|
-
});
|
|
935
|
-
}
|
|
936
|
-
selectRecords(tableName_1) {
|
|
937
|
-
return __awaiter(this, arguments, void 0, function* (tableName, options = {}, params = []) {
|
|
938
|
-
var _a;
|
|
939
|
-
const columns = ((_a = options.columns) === null || _a === void 0 ? void 0 : _a.length) ? options.columns.join(', ') : '*';
|
|
940
|
-
const distinctKeyword = options.distinct ? 'DISTINCT ' : '';
|
|
941
|
-
const whereClause = options.whereClause ? ` ${options.whereClause}` : '';
|
|
942
|
-
const orderByClause = options.orderBy ? ` ORDER BY ${options.orderBy}` : '';
|
|
943
|
-
const limitClause = options.limit ? ` LIMIT ${options.limit}` : '';
|
|
944
|
-
const offsetClause = options.offset ? ` OFFSET ${options.offset}` : '';
|
|
945
|
-
const query = `SELECT ${distinctKeyword}${columns} FROM ${tableName}${whereClause}${orderByClause}${limitClause}${offsetClause};`;
|
|
946
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
947
|
-
const res = yield client.query(query, params);
|
|
948
|
-
return res.rows;
|
|
949
|
-
}));
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
updateRecord(tableName_1, data_1, whereClause_1) {
|
|
953
|
-
return __awaiter(this, arguments, void 0, function* (tableName, data, whereClause, params = []) {
|
|
954
|
-
const keys = Object.keys(data);
|
|
955
|
-
const setClause = keys.map((key, index) => `"${key}" = $${index + 1}`).join(', ');
|
|
956
|
-
const values = Object.values(data);
|
|
957
|
-
const query = `UPDATE "${tableName}" SET ${setClause} ${whereClause};`;
|
|
958
|
-
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
959
|
-
yield client.query(query, [...values, ...params]);
|
|
960
|
-
return;
|
|
961
|
-
}));
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
deleteRecord(tableName_1, whereClause_1) {
|
|
965
|
-
return __awaiter(this, arguments, void 0, function* (tableName, whereClause, params = []) {
|
|
966
|
-
const query = `DELETE FROM ${tableName} ${whereClause};`;
|
|
967
|
-
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
968
|
-
yield client.query(query, params);
|
|
969
|
-
return;
|
|
970
|
-
}));
|
|
971
|
-
});
|
|
972
|
-
}
|
|
973
|
-
saveSyncedData(files, integrationId, crowdinId, type) {
|
|
974
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
975
|
-
yield this.dbPromise;
|
|
976
|
-
yield this.executeQuery((client) => client.query('INSERT INTO synced_data(files, integration_id, crowdin_id, type, updated_at) VALUES ($1, $2, $3, $4, $5)', [files, integrationId, crowdinId, type, Date.now().toString()]));
|
|
977
|
-
});
|
|
978
|
-
}
|
|
979
|
-
updateSyncedData(files, integrationId, crowdinId, type) {
|
|
980
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
981
|
-
yield this.dbPromise;
|
|
982
|
-
yield this.executeQuery((client) => client.query('UPDATE synced_data SET files = $1, updated_at = $2 WHERE integration_id = $3 AND crowdin_id = $4 AND type = $5', [files, Date.now().toString(), integrationId, crowdinId, type]));
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
getSyncedData(integrationId, crowdinId, type) {
|
|
986
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
987
|
-
yield this.dbPromise;
|
|
988
|
-
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
989
|
-
const res = yield client.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, updated_at as "updatedAt" FROM synced_data WHERE integration_id = $1 AND crowdin_id = $2 AND type = $3', [integrationId, crowdinId, type]);
|
|
990
|
-
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
991
|
-
}));
|
|
992
|
-
});
|
|
993
|
-
}
|
|
994
|
-
resetSequences() {
|
|
995
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
996
|
-
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
997
|
-
const tables = Object.keys(this.tables);
|
|
998
|
-
for (const table of tables) {
|
|
999
|
-
try {
|
|
1000
|
-
const primaryKeyResult = yield client.query(`
|
|
1001
|
-
SELECT a.attname
|
|
1002
|
-
FROM pg_index i
|
|
1003
|
-
JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey)
|
|
1004
|
-
WHERE i.indrelid = '${table}'::regclass
|
|
1005
|
-
AND i.indisprimary;
|
|
1006
|
-
`);
|
|
1007
|
-
if (primaryKeyResult.rows.length === 0) {
|
|
1008
|
-
continue;
|
|
1009
|
-
}
|
|
1010
|
-
const primaryKey = primaryKeyResult.rows[0].attname;
|
|
1011
|
-
const maxIdResult = yield client.query(`SELECT MAX(${primaryKey}) FROM ${table}`);
|
|
1012
|
-
const maxId = maxIdResult.rows[0].max;
|
|
1013
|
-
// Skip if maxId is not a valid integer
|
|
1014
|
-
if (maxId === null || isNaN(Number(maxId))) {
|
|
1015
|
-
continue;
|
|
1016
|
-
}
|
|
1017
|
-
yield client.query(`SELECT setval('${table}_${primaryKey}_seq', ${Number(maxId)}, true)`);
|
|
1018
|
-
}
|
|
1019
|
-
catch (error) {
|
|
1020
|
-
console.error(`Error resetting sequence for table ${table}:`, error);
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
}));
|
|
1024
|
-
});
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
exports.PostgreStorage = PostgreStorage;
|