@crowdin/app-project-module 0.17.8 → 0.18.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/README.md +30 -3
- package/out/handlers/custom-file-format/process.js +7 -3
- package/out/handlers/install.js +3 -3
- package/out/handlers/integration-login.js +3 -3
- package/out/handlers/integration-logout.js +1 -1
- package/out/handlers/settings-save.js +1 -1
- package/out/handlers/sync-settings-save.js +3 -3
- package/out/handlers/sync-settings.js +1 -1
- package/out/handlers/uninstall.js +1 -1
- package/out/index.js +9 -9
- package/out/middlewares/crowdin-client.js +1 -1
- package/out/middlewares/integration-credentials.js +1 -1
- package/out/middlewares/ui-module.js +1 -1
- package/out/models/index.d.ts +6 -1
- package/out/storage/index.d.ts +26 -22
- package/out/storage/index.js +29 -308
- package/out/storage/postgre.d.ts +42 -0
- package/out/storage/postgre.js +261 -0
- package/out/storage/sqlite.d.ts +37 -0
- package/out/storage/sqlite.js +297 -0
- package/out/util/connection.js +2 -2
- package/out/util/cron.js +5 -5
- package/out/util/index.js +1 -1
- package/package.json +3 -1
package/out/storage/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/camelcase */
|
|
3
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -9,311 +8,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
9
|
});
|
|
11
10
|
};
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (err) {
|
|
46
|
-
rej(err);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
res();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function get(query, params) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
yield dbPromise;
|
|
58
|
-
return new Promise((res, rej) => {
|
|
59
|
-
db.get(query, params, (err, row) => {
|
|
60
|
-
if (err) {
|
|
61
|
-
rej(err);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
res(row);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function each(query, params) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
yield dbPromise;
|
|
73
|
-
return new Promise((res, rej) => {
|
|
74
|
-
const result = [];
|
|
75
|
-
db.each(query, params, (err, row) => {
|
|
76
|
-
if (err) {
|
|
77
|
-
rej(err);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
result.push(row);
|
|
81
|
-
}
|
|
82
|
-
}, () => res(result));
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
function migrate() {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
const newColumns = ['app_secret', 'domain', 'user_id', 'organization_id', 'base_url'];
|
|
89
|
-
const crowdinCredentialsInfo = yield each('PRAGMA table_info(crowdin_credentials);', []);
|
|
90
|
-
crowdinCredentialsInfo.map((columnInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
const index = newColumns.indexOf(columnInfo.name);
|
|
92
|
-
if (~index) {
|
|
93
|
-
newColumns.splice(index, 1);
|
|
94
|
-
}
|
|
95
|
-
}));
|
|
96
|
-
for (const column of newColumns) {
|
|
97
|
-
yield run(`ALTER TABLE crowdin_credentials ADD COLUMN ${column} varchar null;`, []);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
function connect(folder) {
|
|
102
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
let _connection_res;
|
|
104
|
-
let _connection_rej;
|
|
105
|
-
const connectionPromise = new Promise((res, rej) => {
|
|
106
|
-
_connection_res = res;
|
|
107
|
-
_connection_rej = rej;
|
|
108
|
-
});
|
|
109
|
-
db = new sqlite3_1.default.Database((0, path_1.join)(folder, 'app.sqlite'), error => {
|
|
110
|
-
if (error) {
|
|
111
|
-
_connection_rej(error);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
_connection_res();
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
try {
|
|
118
|
-
yield connectionPromise;
|
|
119
|
-
yield _run(`
|
|
120
|
-
create table if not exists crowdin_credentials
|
|
121
|
-
(
|
|
122
|
-
id varchar not null primary key,
|
|
123
|
-
app_secret varchar null,
|
|
124
|
-
domain varchar null,
|
|
125
|
-
user_id varchar null,
|
|
126
|
-
organization_id varchar null,
|
|
127
|
-
base_url varchar null,
|
|
128
|
-
access_token varchar not null,
|
|
129
|
-
refresh_token varchar not null,
|
|
130
|
-
expire varchar not null,
|
|
131
|
-
type varchar not null
|
|
132
|
-
);
|
|
133
|
-
`, []);
|
|
134
|
-
yield _run(`
|
|
135
|
-
create table if not exists integration_credentials
|
|
136
|
-
(
|
|
137
|
-
id varchar not null primary key,
|
|
138
|
-
credentials varchar not null,
|
|
139
|
-
config varchar null,
|
|
140
|
-
crowdin_id varchar not null
|
|
141
|
-
);
|
|
142
|
-
`, []);
|
|
143
|
-
yield _run(`
|
|
144
|
-
create table if not exists sync_settings
|
|
145
|
-
(
|
|
146
|
-
id integer not null primary key autoincrement,
|
|
147
|
-
files varchar null,
|
|
148
|
-
integration_id varchar not null,
|
|
149
|
-
crowdin_id varchar not null,
|
|
150
|
-
type varchar not null,
|
|
151
|
-
provider varchar not null
|
|
152
|
-
);
|
|
153
|
-
`, []);
|
|
154
|
-
yield _run(`
|
|
155
|
-
create table if not exists app_metadata
|
|
156
|
-
(
|
|
157
|
-
id varchar not null primary key,
|
|
158
|
-
data varchar null
|
|
159
|
-
);
|
|
160
|
-
`, []);
|
|
161
|
-
_res();
|
|
162
|
-
// TODO: temporary code
|
|
163
|
-
yield migrate();
|
|
164
|
-
}
|
|
165
|
-
catch (e) {
|
|
166
|
-
_rej(e);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
exports.connect = connect;
|
|
171
|
-
function saveCrowdinCredentials(credentials) {
|
|
172
|
-
return run('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
|
|
173
|
-
credentials.id,
|
|
174
|
-
credentials.appSecret,
|
|
175
|
-
credentials.domain,
|
|
176
|
-
credentials.userId,
|
|
177
|
-
credentials.organizationId,
|
|
178
|
-
credentials.baseUrl,
|
|
179
|
-
credentials.accessToken,
|
|
180
|
-
credentials.refreshToken,
|
|
181
|
-
credentials.expire,
|
|
182
|
-
credentials.type,
|
|
183
|
-
]);
|
|
184
|
-
}
|
|
185
|
-
exports.saveCrowdinCredentials = saveCrowdinCredentials;
|
|
186
|
-
function updateCrowdinCredentials(credentials) {
|
|
187
|
-
return run('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
|
|
188
|
-
credentials.appSecret,
|
|
189
|
-
credentials.domain,
|
|
190
|
-
credentials.userId,
|
|
191
|
-
credentials.organizationId,
|
|
192
|
-
credentials.baseUrl,
|
|
193
|
-
credentials.accessToken,
|
|
194
|
-
credentials.refreshToken,
|
|
195
|
-
credentials.expire,
|
|
196
|
-
credentials.id,
|
|
197
|
-
]);
|
|
198
|
-
}
|
|
199
|
-
exports.updateCrowdinCredentials = updateCrowdinCredentials;
|
|
200
|
-
function getCrowdinCredentials(id) {
|
|
201
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
-
const row = yield get('SELECT id, app_secret as appSecret, domain, user_id as userId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials WHERE id = ?', [id]);
|
|
203
|
-
if (row) {
|
|
204
|
-
return row;
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
exports.getCrowdinCredentials = getCrowdinCredentials;
|
|
209
|
-
function getAllCrowdinCredentials() {
|
|
210
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
-
return each('SELECT id, app_secret as appSecret, domain, user_id as userId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials', []);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
exports.getAllCrowdinCredentials = getAllCrowdinCredentials;
|
|
215
|
-
function deleteCrowdinCredentials(id) {
|
|
216
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
yield run('DELETE FROM crowdin_credentials where id = ?', [id]);
|
|
218
|
-
yield run('DELETE FROM integration_credentials where crowdin_id = ?', [id]);
|
|
219
|
-
yield run('DELETE FROM sync_settings WHERE crowdin_id = ?', [id]);
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
exports.deleteCrowdinCredentials = deleteCrowdinCredentials;
|
|
223
|
-
function saveIntegrationCredentials(id, credentials, crowdinId) {
|
|
224
|
-
return run('INSERT INTO integration_credentials(id, credentials, crowdin_id) VALUES (?, ?, ?)', [
|
|
225
|
-
id,
|
|
226
|
-
credentials,
|
|
227
|
-
crowdinId,
|
|
228
|
-
]);
|
|
229
|
-
}
|
|
230
|
-
exports.saveIntegrationCredentials = saveIntegrationCredentials;
|
|
231
|
-
function updateIntegrationCredentials(id, credentials) {
|
|
232
|
-
return run('UPDATE integration_credentials SET credentials = ? WHERE id = ?', [credentials, id]);
|
|
233
|
-
}
|
|
234
|
-
exports.updateIntegrationCredentials = updateIntegrationCredentials;
|
|
235
|
-
function updateIntegrationConfig(id, config) {
|
|
236
|
-
return run('UPDATE integration_credentials SET config = ? WHERE id = ?', [config, id]);
|
|
237
|
-
}
|
|
238
|
-
exports.updateIntegrationConfig = updateIntegrationConfig;
|
|
239
|
-
function getIntegrationCredentials(id) {
|
|
240
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
const row = yield get('SELECT id, credentials, config, crowdin_id as crowdinId FROM integration_credentials WHERE id = ?', [id]);
|
|
242
|
-
if (row) {
|
|
243
|
-
return row;
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
exports.getIntegrationCredentials = getIntegrationCredentials;
|
|
248
|
-
function getAllIntegrationCredentials(crowdinId) {
|
|
249
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
return each('SELECT id, credentials, config, crowdin_id as crowdinId FROM integration_credentials WHERE crowdin_id = ?', [crowdinId]);
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
exports.getAllIntegrationCredentials = getAllIntegrationCredentials;
|
|
254
|
-
function deleteIntegrationCredentials(id) {
|
|
255
|
-
return run('DELETE FROM integration_credentials where id = ?', [id]);
|
|
256
|
-
return run('DELETE FROM sync_settings where integration_id = ?', [id]);
|
|
257
|
-
}
|
|
258
|
-
exports.deleteIntegrationCredentials = deleteIntegrationCredentials;
|
|
259
|
-
function saveMetadata(id, metadata) {
|
|
260
|
-
return run('INSERT INTO app_metadata(id, data) VALUES (?, ?)', [id, JSON.stringify(metadata)]);
|
|
261
|
-
}
|
|
262
|
-
exports.saveMetadata = saveMetadata;
|
|
263
|
-
function updateMetadata(id, metadata) {
|
|
264
|
-
return run('UPDATE app_metadata SET data = ? WHERE id = ?', [JSON.stringify(metadata), id]);
|
|
265
|
-
}
|
|
266
|
-
exports.updateMetadata = updateMetadata;
|
|
267
|
-
function getMetadata(id) {
|
|
268
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
-
const row = yield get('SELECT data FROM app_metadata WHERE id = ?', [id]);
|
|
270
|
-
if (row) {
|
|
271
|
-
return JSON.parse(row.data);
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
exports.getMetadata = getMetadata;
|
|
276
|
-
function deleteMetadata(id) {
|
|
277
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
-
yield run('DELETE FROM app_metadata where id = ?', [id]);
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
exports.deleteMetadata = deleteMetadata;
|
|
282
|
-
function getSyncSettingsByProvider(integrationId, provider) {
|
|
283
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
-
const row = yield get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, provider FROM sync_settings WHERE integration_id = ? AND provider = ?', [integrationId, provider]);
|
|
285
|
-
if (row) {
|
|
286
|
-
return row;
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
exports.getSyncSettingsByProvider = getSyncSettingsByProvider;
|
|
291
|
-
function getAllSyncSettingsByType(type) {
|
|
292
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
293
|
-
return each('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, provider FROM sync_settings WHERE type = ?', [type]);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
exports.getAllSyncSettingsByType = getAllSyncSettingsByType;
|
|
297
|
-
function saveSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
298
|
-
return run('INSERT INTO sync_settings(files, integration_id, crowdin_id, type, provider) VALUES (?, ?, ?, ?, ?)', [
|
|
299
|
-
files,
|
|
300
|
-
integrationId,
|
|
301
|
-
crowdinId,
|
|
302
|
-
type,
|
|
303
|
-
provider,
|
|
304
|
-
]);
|
|
305
|
-
}
|
|
306
|
-
exports.saveSyncSettings = saveSyncSettings;
|
|
307
|
-
function updateSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
308
|
-
return run('UPDATE sync_settings SET files = ? WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?', [files, integrationId, crowdinId, type, provider]);
|
|
309
|
-
}
|
|
310
|
-
exports.updateSyncSettings = updateSyncSettings;
|
|
311
|
-
function getSyncSettings(integrationId, crowdinId, type, provider) {
|
|
312
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
-
const row = yield get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type FROM sync_settings WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?', [integrationId, crowdinId, type, provider]);
|
|
314
|
-
if (row) {
|
|
315
|
-
return row;
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
exports.getSyncSettings = getSyncSettings;
|
|
12
|
+
exports.getStorage = exports.initialize = void 0;
|
|
13
|
+
const util_1 = require("../util");
|
|
14
|
+
const postgre_1 = require("./postgre");
|
|
15
|
+
const sqlite_1 = require("./sqlite");
|
|
16
|
+
let storage;
|
|
17
|
+
function initialize(config) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
if (config.dbFolder) {
|
|
20
|
+
(0, util_1.log)('Using SQLite database', config.logger);
|
|
21
|
+
const sqlite = new sqlite_1.SQLiteStorage();
|
|
22
|
+
storage = sqlite;
|
|
23
|
+
yield sqlite.connect({ dbFolder: config.dbFolder });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (config.postgreConfig) {
|
|
27
|
+
(0, util_1.log)('Using PostgreSQL database', config.logger);
|
|
28
|
+
const postgre = new postgre_1.PostgreStorage();
|
|
29
|
+
storage = postgre;
|
|
30
|
+
yield postgre.connect(config.postgreConfig);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
throw new Error('Database is not configured');
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.initialize = initialize;
|
|
37
|
+
function getStorage() {
|
|
38
|
+
return storage;
|
|
39
|
+
}
|
|
40
|
+
exports.getStorage = getStorage;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Storage } from '.';
|
|
2
|
+
import { CrowdinCredentials, IntegrationCredentials, IntegrationSyncSettings } from '../models';
|
|
3
|
+
export interface PostgreStorageConfig {
|
|
4
|
+
host?: string;
|
|
5
|
+
connectionString?: string;
|
|
6
|
+
user?: string;
|
|
7
|
+
database?: string;
|
|
8
|
+
password?: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
keepAlive?: boolean;
|
|
11
|
+
keepAliveInitialDelayMillis?: number;
|
|
12
|
+
idle_in_transaction_session_timeout?: number;
|
|
13
|
+
connectionTimeoutMillis?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class PostgreStorage implements Storage<PostgreStorageConfig> {
|
|
16
|
+
private client?;
|
|
17
|
+
private _res?;
|
|
18
|
+
private _rej?;
|
|
19
|
+
private dbPromise;
|
|
20
|
+
connect(config: PostgreStorageConfig): Promise<void>;
|
|
21
|
+
migrate(): Promise<void>;
|
|
22
|
+
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
23
|
+
updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
24
|
+
getCrowdinCredentials(id: string): Promise<CrowdinCredentials | undefined>;
|
|
25
|
+
getAllCrowdinCredentials(): Promise<CrowdinCredentials[]>;
|
|
26
|
+
deleteCrowdinCredentials(id: string): Promise<void>;
|
|
27
|
+
saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
|
|
28
|
+
updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
|
|
29
|
+
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
30
|
+
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
31
|
+
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
32
|
+
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
33
|
+
saveMetadata(id: string, metadata: any): Promise<void>;
|
|
34
|
+
updateMetadata(id: string, metadata: any): Promise<void>;
|
|
35
|
+
getMetadata(id: string): Promise<any>;
|
|
36
|
+
deleteMetadata(id: string): Promise<void>;
|
|
37
|
+
getSyncSettingsByProvider(integrationId: string, provider: string): Promise<IntegrationSyncSettings | undefined>;
|
|
38
|
+
getAllSyncSettingsByType(type: string): Promise<IntegrationSyncSettings[]>;
|
|
39
|
+
saveSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: string): Promise<void>;
|
|
40
|
+
updateSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: string): Promise<void>;
|
|
41
|
+
getSyncSettings(integrationId: string, crowdinId: string, type: string, provider: string): Promise<IntegrationSyncSettings | undefined>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.PostgreStorage = void 0;
|
|
14
|
+
const pg_1 = require("pg");
|
|
15
|
+
class PostgreStorage {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.dbPromise = new Promise((res, rej) => {
|
|
18
|
+
this._res = res;
|
|
19
|
+
this._rej = rej;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
connect(config) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
this.client = new pg_1.Client(config);
|
|
25
|
+
try {
|
|
26
|
+
yield this.client.connect();
|
|
27
|
+
yield this.migrate();
|
|
28
|
+
this._res && this._res();
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error(e);
|
|
32
|
+
this._rej && this._rej();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
migrate() {
|
|
37
|
+
var _a, _b, _c, _d;
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query(`
|
|
40
|
+
create table if not exists crowdin_credentials
|
|
41
|
+
(
|
|
42
|
+
id varchar primary key,
|
|
43
|
+
app_secret varchar,
|
|
44
|
+
domain varchar,
|
|
45
|
+
user_id varchar,
|
|
46
|
+
organization_id varchar,
|
|
47
|
+
base_url varchar,
|
|
48
|
+
access_token varchar not null,
|
|
49
|
+
refresh_token varchar not null,
|
|
50
|
+
expire varchar not null,
|
|
51
|
+
type varchar not null
|
|
52
|
+
)
|
|
53
|
+
`));
|
|
54
|
+
yield ((_b = this.client) === null || _b === void 0 ? void 0 : _b.query(`
|
|
55
|
+
create table if not exists integration_credentials
|
|
56
|
+
(
|
|
57
|
+
id varchar primary key,
|
|
58
|
+
credentials varchar,
|
|
59
|
+
config varchar,
|
|
60
|
+
crowdin_id varchar not null
|
|
61
|
+
)
|
|
62
|
+
`));
|
|
63
|
+
yield ((_c = this.client) === null || _c === void 0 ? void 0 : _c.query(`
|
|
64
|
+
create table if not exists sync_settings
|
|
65
|
+
(
|
|
66
|
+
id serial primary key,
|
|
67
|
+
files varchar,
|
|
68
|
+
integration_id varchar not null,
|
|
69
|
+
crowdin_id varchar not null,
|
|
70
|
+
type varchar not null,
|
|
71
|
+
provider varchar not null
|
|
72
|
+
)
|
|
73
|
+
`));
|
|
74
|
+
yield ((_d = this.client) === null || _d === void 0 ? void 0 : _d.query(`
|
|
75
|
+
create table if not exists app_metadata
|
|
76
|
+
(
|
|
77
|
+
id varchar primary key,
|
|
78
|
+
data varchar
|
|
79
|
+
)
|
|
80
|
+
`));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
saveCrowdinCredentials(credentials) {
|
|
84
|
+
var _a;
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
yield this.dbPromise;
|
|
87
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)', [
|
|
88
|
+
credentials.id,
|
|
89
|
+
credentials.appSecret,
|
|
90
|
+
credentials.domain,
|
|
91
|
+
credentials.userId,
|
|
92
|
+
credentials.organizationId,
|
|
93
|
+
credentials.baseUrl,
|
|
94
|
+
credentials.accessToken,
|
|
95
|
+
credentials.refreshToken,
|
|
96
|
+
credentials.expire,
|
|
97
|
+
credentials.type,
|
|
98
|
+
]));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
updateCrowdinCredentials(credentials) {
|
|
102
|
+
var _a;
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
yield this.dbPromise;
|
|
105
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE crowdin_credentials SET app_secret = $1, domain = $2, user_id = $3, organization_id = $4, base_url = $5, access_token = $6, refresh_token = $7, expire = $8 WHERE id = $9', [
|
|
106
|
+
credentials.appSecret,
|
|
107
|
+
credentials.domain,
|
|
108
|
+
credentials.userId,
|
|
109
|
+
credentials.organizationId,
|
|
110
|
+
credentials.baseUrl,
|
|
111
|
+
credentials.accessToken,
|
|
112
|
+
credentials.refreshToken,
|
|
113
|
+
credentials.expire,
|
|
114
|
+
credentials.id,
|
|
115
|
+
]));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
getCrowdinCredentials(id) {
|
|
119
|
+
var _a;
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
yield this.dbPromise;
|
|
122
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, app_secret as "appSecret", domain, user_id as "userId", 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]));
|
|
123
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
getAllCrowdinCredentials() {
|
|
127
|
+
var _a;
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
yield this.dbPromise;
|
|
130
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, app_secret as "appSecret", domain, user_id as "userId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials', []));
|
|
131
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
deleteCrowdinCredentials(id) {
|
|
135
|
+
var _a, _b, _c;
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
yield this.dbPromise;
|
|
138
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('DELETE FROM crowdin_credentials where id = $1', [id]));
|
|
139
|
+
yield ((_b = this.client) === null || _b === void 0 ? void 0 : _b.query('DELETE FROM integration_credentials where crowdin_id = $1', [id]));
|
|
140
|
+
yield ((_c = this.client) === null || _c === void 0 ? void 0 : _c.query('DELETE FROM sync_settings WHERE crowdin_id = $1', [id]));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
saveIntegrationCredentials(id, credentials, crowdinId) {
|
|
144
|
+
var _a;
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
yield this.dbPromise;
|
|
147
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('INSERT INTO integration_credentials(id, credentials, crowdin_id) VALUES ($1, $2, $3)', [id, credentials, crowdinId]));
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
updateIntegrationCredentials(id, credentials) {
|
|
151
|
+
var _a;
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
yield this.dbPromise;
|
|
154
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE integration_credentials SET credentials = $1 WHERE id = $2', [
|
|
155
|
+
credentials,
|
|
156
|
+
id,
|
|
157
|
+
]));
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
updateIntegrationConfig(id, config) {
|
|
161
|
+
var _a;
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
yield this.dbPromise;
|
|
164
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE integration_credentials SET config = $1 WHERE id = $2', [config, id]));
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
getIntegrationCredentials(id) {
|
|
168
|
+
var _a;
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
yield this.dbPromise;
|
|
171
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, credentials, config, crowdin_id as "crowdinId" FROM integration_credentials WHERE id = $1', [id]));
|
|
172
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
getAllIntegrationCredentials(crowdinId) {
|
|
176
|
+
var _a;
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
yield this.dbPromise;
|
|
179
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, credentials, config, crowdin_id as "crowdinId" FROM integration_credentials WHERE crowdin_id = $1', [crowdinId]));
|
|
180
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
deleteIntegrationCredentials(id) {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
yield this.dbPromise;
|
|
187
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('DELETE FROM integration_credentials where id = $1', [id]));
|
|
188
|
+
yield ((_b = this.client) === null || _b === void 0 ? void 0 : _b.query('DELETE FROM sync_settings where integration_id = $1', [id]));
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
saveMetadata(id, metadata) {
|
|
192
|
+
var _a;
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
yield this.dbPromise;
|
|
195
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('INSERT INTO app_metadata(id, data) VALUES ($1, $2)', [id, metadata]));
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
updateMetadata(id, metadata) {
|
|
199
|
+
var _a;
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
yield this.dbPromise;
|
|
202
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE app_metadata SET data = $1 WHERE id = $2', [id, metadata]));
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
getMetadata(id) {
|
|
206
|
+
var _a;
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
yield this.dbPromise;
|
|
209
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT data FROM app_metadata WHERE id = $1', [id]));
|
|
210
|
+
if (res === null || res === void 0 ? void 0 : res.rows[0]) {
|
|
211
|
+
return JSON.parse(res === null || res === void 0 ? void 0 : res.rows[0].data);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
deleteMetadata(id) {
|
|
216
|
+
var _a;
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
yield this.dbPromise;
|
|
219
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('DELETE FROM app_metadata where id = $1', [id]));
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
getSyncSettingsByProvider(integrationId, provider) {
|
|
223
|
+
var _a;
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
yield this.dbPromise;
|
|
226
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.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]));
|
|
227
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
getAllSyncSettingsByType(type) {
|
|
231
|
+
var _a;
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
yield this.dbPromise;
|
|
234
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE type = $1', [type]));
|
|
235
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
saveSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
239
|
+
var _a;
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
yield this.dbPromise;
|
|
242
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('INSERT INTO sync_settings(files, integration_id, crowdin_id, type, provider) VALUES ($1, $2, $3, $4, $5)', [files, integrationId, crowdinId, type, provider]));
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
updateSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
246
|
+
var _a;
|
|
247
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
yield this.dbPromise;
|
|
249
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.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]));
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
getSyncSettings(integrationId, crowdinId, type, provider) {
|
|
253
|
+
var _a;
|
|
254
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
yield this.dbPromise;
|
|
256
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type FROM sync_settings WHERE integration_id = $1 AND crowdin_id = $2 AND type = $3 AND provider = $4', [integrationId, crowdinId, type, provider]));
|
|
257
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.PostgreStorage = PostgreStorage;
|