@crowdin/app-project-module 0.20.2 → 0.20.3
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/storage/index.d.ts +3 -3
- package/out/storage/index.js +7 -13
- package/out/storage/mysql.d.ts +6 -3
- package/out/storage/mysql.js +92 -74
- package/out/storage/postgre.d.ts +6 -3
- package/out/storage/postgre.js +89 -74
- package/out/storage/sqlite.d.ts +5 -3
- package/out/storage/sqlite.js +6 -5
- package/package.json +1 -1
package/out/storage/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Config, CrowdinCredentials, IntegrationCredentials, IntegrationSyncSettings } from '../models';
|
|
2
|
-
export interface Storage
|
|
3
|
-
|
|
2
|
+
export interface Storage {
|
|
3
|
+
migrate(): Promise<void>;
|
|
4
4
|
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
5
5
|
updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
6
6
|
getCrowdinCredentials(id: string): Promise<CrowdinCredentials | undefined>;
|
|
@@ -24,4 +24,4 @@ export interface Storage<T> {
|
|
|
24
24
|
getSyncSettings(integrationId: string, crowdinId: string, type: string, provider: string): Promise<IntegrationSyncSettings | undefined>;
|
|
25
25
|
}
|
|
26
26
|
export declare function initialize(config: Config): Promise<void>;
|
|
27
|
-
export declare function getStorage(): Storage
|
|
27
|
+
export declare function getStorage(): Storage;
|
package/out/storage/index.js
CHANGED
|
@@ -19,26 +19,20 @@ function initialize(config) {
|
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
if (config.dbFolder) {
|
|
21
21
|
(0, util_1.log)('Using SQLite database', config.logger);
|
|
22
|
-
|
|
23
|
-
storage = sqlite;
|
|
24
|
-
yield sqlite.connect({ dbFolder: config.dbFolder });
|
|
25
|
-
return;
|
|
22
|
+
storage = new sqlite_1.SQLiteStorage({ dbFolder: config.dbFolder });
|
|
26
23
|
}
|
|
27
24
|
if (config.postgreConfig) {
|
|
28
25
|
(0, util_1.log)('Using PostgreSQL database', config.logger);
|
|
29
|
-
|
|
30
|
-
storage = postgre;
|
|
31
|
-
yield postgre.connect(config.postgreConfig);
|
|
32
|
-
return;
|
|
26
|
+
storage = new postgre_1.PostgreStorage(config.postgreConfig);
|
|
33
27
|
}
|
|
34
28
|
if (config.mysqlConfig) {
|
|
35
29
|
(0, util_1.log)('Using MySQL database', config.logger);
|
|
36
|
-
|
|
37
|
-
storage = mysql;
|
|
38
|
-
yield mysql.connect(config.mysqlConfig);
|
|
39
|
-
return;
|
|
30
|
+
storage = new mysql_1.MySQLStorage(config.mysqlConfig);
|
|
40
31
|
}
|
|
41
|
-
|
|
32
|
+
if (!storage) {
|
|
33
|
+
throw new Error('Database is not configured');
|
|
34
|
+
}
|
|
35
|
+
yield storage.migrate();
|
|
42
36
|
});
|
|
43
37
|
}
|
|
44
38
|
exports.initialize = initialize;
|
package/out/storage/mysql.d.ts
CHANGED
|
@@ -8,13 +8,16 @@ export interface MySQLStorageConfig {
|
|
|
8
8
|
database?: string;
|
|
9
9
|
port?: number;
|
|
10
10
|
}
|
|
11
|
-
export declare class MySQLStorage implements Storage
|
|
12
|
-
private
|
|
11
|
+
export declare class MySQLStorage implements Storage {
|
|
12
|
+
private mysql;
|
|
13
13
|
private _res?;
|
|
14
14
|
private _rej?;
|
|
15
15
|
private dbPromise;
|
|
16
|
-
|
|
16
|
+
private config;
|
|
17
|
+
constructor(config: MySQLStorageConfig);
|
|
18
|
+
executeQuery<T>(command: (connection: any) => Promise<T>): Promise<T>;
|
|
17
19
|
migrate(): Promise<void>;
|
|
20
|
+
addTables(connection: any): Promise<void>;
|
|
18
21
|
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
19
22
|
updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
20
23
|
getCrowdinCredentials(id: string): Promise<CrowdinCredentials | undefined>;
|
package/out/storage/mysql.js
CHANGED
|
@@ -14,18 +14,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.MySQLStorage = void 0;
|
|
16
16
|
class MySQLStorage {
|
|
17
|
-
constructor() {
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.mysql = require('mysql2/promise');
|
|
18
19
|
this.dbPromise = new Promise((res, rej) => {
|
|
19
20
|
this._res = res;
|
|
20
21
|
this._rej = rej;
|
|
21
22
|
});
|
|
23
|
+
this.config = config;
|
|
22
24
|
}
|
|
23
|
-
|
|
25
|
+
executeQuery(command) {
|
|
24
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
let connection;
|
|
25
28
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
yield
|
|
29
|
+
connection = yield this.mysql.createConnection(this.config);
|
|
30
|
+
const res = yield command(connection);
|
|
31
|
+
yield connection.end();
|
|
32
|
+
return res;
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
if (connection) {
|
|
36
|
+
yield connection.end();
|
|
37
|
+
}
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
migrate() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
try {
|
|
45
|
+
yield this.executeQuery(this.addTables);
|
|
29
46
|
this._res && this._res();
|
|
30
47
|
}
|
|
31
48
|
catch (e) {
|
|
@@ -34,10 +51,9 @@ class MySQLStorage {
|
|
|
34
51
|
}
|
|
35
52
|
});
|
|
36
53
|
}
|
|
37
|
-
|
|
38
|
-
var _a, _b, _c, _d;
|
|
54
|
+
addTables(connection) {
|
|
39
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
yield
|
|
56
|
+
yield connection.execute(`
|
|
41
57
|
create table if not exists crowdin_credentials
|
|
42
58
|
(
|
|
43
59
|
id varchar(255) primary key,
|
|
@@ -51,8 +67,8 @@ class MySQLStorage {
|
|
|
51
67
|
expire varchar(255) not null,
|
|
52
68
|
type varchar(255) not null
|
|
53
69
|
)
|
|
54
|
-
`)
|
|
55
|
-
yield
|
|
70
|
+
`);
|
|
71
|
+
yield connection.execute(`
|
|
56
72
|
create table if not exists integration_credentials
|
|
57
73
|
(
|
|
58
74
|
id varchar(255) primary key,
|
|
@@ -60,8 +76,8 @@ class MySQLStorage {
|
|
|
60
76
|
config text,
|
|
61
77
|
crowdin_id varchar(255) not null
|
|
62
78
|
)
|
|
63
|
-
`)
|
|
64
|
-
yield
|
|
79
|
+
`);
|
|
80
|
+
yield connection.execute(`
|
|
65
81
|
create table if not exists sync_settings
|
|
66
82
|
(
|
|
67
83
|
id int auto_increment primary key,
|
|
@@ -71,21 +87,20 @@ class MySQLStorage {
|
|
|
71
87
|
type varchar(255) not null,
|
|
72
88
|
provider varchar(255) not null
|
|
73
89
|
)
|
|
74
|
-
`)
|
|
75
|
-
yield
|
|
90
|
+
`);
|
|
91
|
+
yield connection.execute(`
|
|
76
92
|
create table if not exists app_metadata
|
|
77
93
|
(
|
|
78
94
|
id varchar(255) primary key,
|
|
79
95
|
data text
|
|
80
96
|
)
|
|
81
|
-
`)
|
|
97
|
+
`);
|
|
82
98
|
});
|
|
83
99
|
}
|
|
84
100
|
saveCrowdinCredentials(credentials) {
|
|
85
|
-
var _a;
|
|
86
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
102
|
yield this.dbPromise;
|
|
88
|
-
yield
|
|
103
|
+
yield this.executeQuery(connection => connection.execute('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
|
|
89
104
|
credentials.id,
|
|
90
105
|
credentials.appSecret,
|
|
91
106
|
credentials.domain,
|
|
@@ -100,10 +115,9 @@ class MySQLStorage {
|
|
|
100
115
|
});
|
|
101
116
|
}
|
|
102
117
|
updateCrowdinCredentials(credentials) {
|
|
103
|
-
var _a;
|
|
104
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
119
|
yield this.dbPromise;
|
|
106
|
-
yield
|
|
120
|
+
yield this.executeQuery(connection => connection.execute('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
|
|
107
121
|
credentials.appSecret,
|
|
108
122
|
credentials.domain,
|
|
109
123
|
credentials.userId,
|
|
@@ -117,153 +131,157 @@ class MySQLStorage {
|
|
|
117
131
|
});
|
|
118
132
|
}
|
|
119
133
|
getCrowdinCredentials(id) {
|
|
120
|
-
var _a;
|
|
121
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
135
|
yield this.dbPromise;
|
|
123
|
-
|
|
124
|
-
|
|
136
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const [rows,] = yield connection.execute('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]);
|
|
138
|
+
return (rows || [])[0];
|
|
139
|
+
}));
|
|
125
140
|
});
|
|
126
141
|
}
|
|
127
142
|
getAllCrowdinCredentials() {
|
|
128
|
-
var _a;
|
|
129
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
144
|
yield this.dbPromise;
|
|
131
|
-
|
|
132
|
-
|
|
145
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const [rows] = yield connection.execute('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', []);
|
|
147
|
+
return rows || [];
|
|
148
|
+
}));
|
|
133
149
|
});
|
|
134
150
|
}
|
|
135
151
|
deleteCrowdinCredentials(id) {
|
|
136
|
-
var _a, _b, _c;
|
|
137
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
153
|
yield this.dbPromise;
|
|
139
|
-
yield ((
|
|
140
|
-
|
|
141
|
-
|
|
154
|
+
yield this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
yield connection.execute('DELETE FROM crowdin_credentials where id = ?', [id]);
|
|
156
|
+
yield connection.execute('DELETE FROM integration_credentials where crowdin_id = ?', [id]);
|
|
157
|
+
yield connection.execute('DELETE FROM sync_settings WHERE crowdin_id = ?', [id]);
|
|
158
|
+
}));
|
|
142
159
|
});
|
|
143
160
|
}
|
|
144
161
|
saveIntegrationCredentials(id, credentials, crowdinId) {
|
|
145
|
-
var _a;
|
|
146
162
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
163
|
yield this.dbPromise;
|
|
148
|
-
yield
|
|
164
|
+
yield this.executeQuery(connection => connection.execute('INSERT INTO integration_credentials(id, credentials, crowdin_id) VALUES (?, ?, ?)', [
|
|
165
|
+
id,
|
|
166
|
+
credentials,
|
|
167
|
+
crowdinId,
|
|
168
|
+
]));
|
|
149
169
|
});
|
|
150
170
|
}
|
|
151
171
|
updateIntegrationCredentials(id, credentials) {
|
|
152
|
-
var _a;
|
|
153
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
154
173
|
yield this.dbPromise;
|
|
155
|
-
yield
|
|
156
|
-
credentials,
|
|
157
|
-
id,
|
|
158
|
-
]));
|
|
174
|
+
yield this.executeQuery(connection => connection.execute('UPDATE integration_credentials SET credentials = ? WHERE id = ?', [credentials, id]));
|
|
159
175
|
});
|
|
160
176
|
}
|
|
161
177
|
updateIntegrationConfig(id, config) {
|
|
162
|
-
var _a;
|
|
163
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
179
|
yield this.dbPromise;
|
|
165
|
-
yield
|
|
180
|
+
yield this.executeQuery(connection => connection.execute('UPDATE integration_credentials SET config = ? WHERE id = ?', [config, id]));
|
|
166
181
|
});
|
|
167
182
|
}
|
|
168
183
|
getIntegrationCredentials(id) {
|
|
169
|
-
var _a;
|
|
170
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
185
|
yield this.dbPromise;
|
|
172
|
-
|
|
173
|
-
|
|
186
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
const [rows,] = yield connection.execute('SELECT id, credentials, config, crowdin_id as "crowdinId" FROM integration_credentials WHERE id = ?', [id]);
|
|
188
|
+
return (rows || [])[0];
|
|
189
|
+
}));
|
|
174
190
|
});
|
|
175
191
|
}
|
|
176
192
|
getAllIntegrationCredentials(crowdinId) {
|
|
177
|
-
var _a;
|
|
178
193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
194
|
yield this.dbPromise;
|
|
180
|
-
|
|
181
|
-
|
|
195
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
const [rows,] = yield connection.execute('SELECT id, credentials, config, crowdin_id as "crowdinId" FROM integration_credentials WHERE crowdin_id = ?', [crowdinId]);
|
|
197
|
+
return rows || [];
|
|
198
|
+
}));
|
|
182
199
|
});
|
|
183
200
|
}
|
|
184
201
|
deleteIntegrationCredentials(id) {
|
|
185
|
-
var _a, _b;
|
|
186
202
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
203
|
yield this.dbPromise;
|
|
188
|
-
yield ((
|
|
189
|
-
|
|
204
|
+
yield this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
yield connection.execute('DELETE FROM integration_credentials where id = ?', [id]);
|
|
206
|
+
yield connection.execute('DELETE FROM sync_settings where integration_id = ?', [id]);
|
|
207
|
+
}));
|
|
190
208
|
});
|
|
191
209
|
}
|
|
192
210
|
deleteAllIntegrationCredentials(crowdinId) {
|
|
193
|
-
var _a, _b;
|
|
194
211
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
212
|
yield this.dbPromise;
|
|
196
|
-
yield ((
|
|
197
|
-
|
|
213
|
+
yield this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
yield connection.execute('DELETE FROM integration_credentials where crowdin_id = ?', [crowdinId]);
|
|
215
|
+
yield connection.execute('DELETE FROM sync_settings where crowdin_id = ?', [crowdinId]);
|
|
216
|
+
}));
|
|
198
217
|
});
|
|
199
218
|
}
|
|
200
219
|
saveMetadata(id, metadata) {
|
|
201
|
-
var _a;
|
|
202
220
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203
221
|
yield this.dbPromise;
|
|
204
|
-
yield
|
|
222
|
+
yield this.executeQuery(connection => connection.execute('INSERT INTO app_metadata(id, data) VALUES (?, ?)', [id, metadata]));
|
|
205
223
|
});
|
|
206
224
|
}
|
|
207
225
|
updateMetadata(id, metadata) {
|
|
208
|
-
var _a;
|
|
209
226
|
return __awaiter(this, void 0, void 0, function* () {
|
|
210
227
|
yield this.dbPromise;
|
|
211
|
-
yield
|
|
228
|
+
yield this.executeQuery(connection => connection.execute('UPDATE app_metadata SET data = ? WHERE id = ?', [id, metadata]));
|
|
212
229
|
});
|
|
213
230
|
}
|
|
214
231
|
getMetadata(id) {
|
|
215
|
-
var _a;
|
|
216
232
|
return __awaiter(this, void 0, void 0, function* () {
|
|
217
233
|
yield this.dbPromise;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
234
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
const [rows] = yield connection.execute('SELECT data FROM app_metadata WHERE id = ?', [id]);
|
|
236
|
+
if (rows && rows[0]) {
|
|
237
|
+
return JSON.parse(rows[0].data);
|
|
238
|
+
}
|
|
239
|
+
}));
|
|
222
240
|
});
|
|
223
241
|
}
|
|
224
242
|
deleteMetadata(id) {
|
|
225
|
-
var _a;
|
|
226
243
|
return __awaiter(this, void 0, void 0, function* () {
|
|
227
244
|
yield this.dbPromise;
|
|
228
|
-
yield
|
|
245
|
+
yield this.executeQuery(connection => connection.execute('DELETE FROM app_metadata where id = ?', [id]));
|
|
229
246
|
});
|
|
230
247
|
}
|
|
231
248
|
getSyncSettingsByProvider(integrationId, provider) {
|
|
232
|
-
var _a;
|
|
233
249
|
return __awaiter(this, void 0, void 0, function* () {
|
|
234
250
|
yield this.dbPromise;
|
|
235
|
-
|
|
236
|
-
|
|
251
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
const [rows,] = yield connection.execute('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE integration_id = ? AND provider = ?', [integrationId, provider]);
|
|
253
|
+
return (rows || [])[0];
|
|
254
|
+
}));
|
|
237
255
|
});
|
|
238
256
|
}
|
|
239
257
|
getAllSyncSettingsByType(type) {
|
|
240
|
-
var _a;
|
|
241
258
|
return __awaiter(this, void 0, void 0, function* () {
|
|
242
259
|
yield this.dbPromise;
|
|
243
|
-
|
|
244
|
-
|
|
260
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
261
|
+
const [rows,] = yield connection.execute('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE type = ?', [type]);
|
|
262
|
+
return rows || [];
|
|
263
|
+
}));
|
|
245
264
|
});
|
|
246
265
|
}
|
|
247
266
|
saveSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
248
|
-
var _a;
|
|
249
267
|
return __awaiter(this, void 0, void 0, function* () {
|
|
250
268
|
yield this.dbPromise;
|
|
251
|
-
yield
|
|
269
|
+
yield this.executeQuery(connection => connection.execute('INSERT INTO sync_settings(files, integration_id, crowdin_id, type, provider) VALUES (?, , ?, ?, ?)', [files, integrationId, crowdinId, type, provider]));
|
|
252
270
|
});
|
|
253
271
|
}
|
|
254
272
|
updateSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
255
|
-
var _a;
|
|
256
273
|
return __awaiter(this, void 0, void 0, function* () {
|
|
257
274
|
yield this.dbPromise;
|
|
258
|
-
yield
|
|
275
|
+
yield this.executeQuery(connection => connection.execute('UPDATE sync_settings SET files = ? WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?', [files, integrationId, crowdinId, type, provider]));
|
|
259
276
|
});
|
|
260
277
|
}
|
|
261
278
|
getSyncSettings(integrationId, crowdinId, type, provider) {
|
|
262
|
-
var _a;
|
|
263
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
264
280
|
yield this.dbPromise;
|
|
265
|
-
|
|
266
|
-
|
|
281
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
const [rows,] = yield connection.execute('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]);
|
|
283
|
+
return (rows || [])[0];
|
|
284
|
+
}));
|
|
267
285
|
});
|
|
268
286
|
}
|
|
269
287
|
}
|
package/out/storage/postgre.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Client } from 'pg';
|
|
1
2
|
import { Storage } from '.';
|
|
2
3
|
import { CrowdinCredentials, IntegrationCredentials, IntegrationSyncSettings } from '../models';
|
|
3
4
|
export interface PostgreStorageConfig {
|
|
@@ -12,13 +13,15 @@ export interface PostgreStorageConfig {
|
|
|
12
13
|
idle_in_transaction_session_timeout?: number;
|
|
13
14
|
connectionTimeoutMillis?: number;
|
|
14
15
|
}
|
|
15
|
-
export declare class PostgreStorage implements Storage
|
|
16
|
-
private
|
|
16
|
+
export declare class PostgreStorage implements Storage {
|
|
17
|
+
private config;
|
|
17
18
|
private _res?;
|
|
18
19
|
private _rej?;
|
|
19
20
|
private dbPromise;
|
|
20
|
-
|
|
21
|
+
constructor(config: PostgreStorageConfig);
|
|
22
|
+
executeQuery<T>(command: (client: Client) => Promise<T>): Promise<T>;
|
|
21
23
|
migrate(): Promise<void>;
|
|
24
|
+
addTables(client: Client): Promise<void>;
|
|
22
25
|
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
23
26
|
updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
24
27
|
getCrowdinCredentials(id: string): Promise<CrowdinCredentials | undefined>;
|
package/out/storage/postgre.js
CHANGED
|
@@ -13,18 +13,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
exports.PostgreStorage = void 0;
|
|
14
14
|
const pg_1 = require("pg");
|
|
15
15
|
class PostgreStorage {
|
|
16
|
-
constructor() {
|
|
16
|
+
constructor(config) {
|
|
17
17
|
this.dbPromise = new Promise((res, rej) => {
|
|
18
18
|
this._res = res;
|
|
19
19
|
this._rej = rej;
|
|
20
20
|
});
|
|
21
|
+
this.config = config;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
executeQuery(command) {
|
|
23
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
|
|
25
|
+
const client = new pg_1.Client(this.config);
|
|
25
26
|
try {
|
|
26
|
-
yield
|
|
27
|
-
yield
|
|
27
|
+
yield client.connect();
|
|
28
|
+
const res = yield command(client);
|
|
29
|
+
yield client.end();
|
|
30
|
+
return res;
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
yield client.end();
|
|
34
|
+
throw e;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
migrate() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
try {
|
|
41
|
+
yield this.executeQuery(this.addTables);
|
|
28
42
|
this._res && this._res();
|
|
29
43
|
}
|
|
30
44
|
catch (e) {
|
|
@@ -33,10 +47,9 @@ class PostgreStorage {
|
|
|
33
47
|
}
|
|
34
48
|
});
|
|
35
49
|
}
|
|
36
|
-
|
|
37
|
-
var _a, _b, _c, _d;
|
|
50
|
+
addTables(client) {
|
|
38
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
yield
|
|
52
|
+
yield client.query(`
|
|
40
53
|
create table if not exists crowdin_credentials
|
|
41
54
|
(
|
|
42
55
|
id varchar primary key,
|
|
@@ -50,8 +63,8 @@ class PostgreStorage {
|
|
|
50
63
|
expire varchar not null,
|
|
51
64
|
type varchar not null
|
|
52
65
|
)
|
|
53
|
-
`)
|
|
54
|
-
yield
|
|
66
|
+
`);
|
|
67
|
+
yield client.query(`
|
|
55
68
|
create table if not exists integration_credentials
|
|
56
69
|
(
|
|
57
70
|
id varchar primary key,
|
|
@@ -59,8 +72,8 @@ class PostgreStorage {
|
|
|
59
72
|
config varchar,
|
|
60
73
|
crowdin_id varchar not null
|
|
61
74
|
)
|
|
62
|
-
`)
|
|
63
|
-
yield
|
|
75
|
+
`);
|
|
76
|
+
yield client.query(`
|
|
64
77
|
create table if not exists sync_settings
|
|
65
78
|
(
|
|
66
79
|
id serial primary key,
|
|
@@ -70,21 +83,20 @@ class PostgreStorage {
|
|
|
70
83
|
type varchar not null,
|
|
71
84
|
provider varchar not null
|
|
72
85
|
)
|
|
73
|
-
`)
|
|
74
|
-
yield
|
|
86
|
+
`);
|
|
87
|
+
yield client.query(`
|
|
75
88
|
create table if not exists app_metadata
|
|
76
89
|
(
|
|
77
90
|
id varchar primary key,
|
|
78
91
|
data varchar
|
|
79
92
|
)
|
|
80
|
-
`)
|
|
93
|
+
`);
|
|
81
94
|
});
|
|
82
95
|
}
|
|
83
96
|
saveCrowdinCredentials(credentials) {
|
|
84
|
-
var _a;
|
|
85
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
98
|
yield this.dbPromise;
|
|
87
|
-
yield
|
|
99
|
+
yield this.executeQuery(client => client.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
100
|
credentials.id,
|
|
89
101
|
credentials.appSecret,
|
|
90
102
|
credentials.domain,
|
|
@@ -99,10 +111,9 @@ class PostgreStorage {
|
|
|
99
111
|
});
|
|
100
112
|
}
|
|
101
113
|
updateCrowdinCredentials(credentials) {
|
|
102
|
-
var _a;
|
|
103
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
115
|
yield this.dbPromise;
|
|
105
|
-
yield
|
|
116
|
+
yield this.executeQuery(client => client.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
117
|
credentials.appSecret,
|
|
107
118
|
credentials.domain,
|
|
108
119
|
credentials.userId,
|
|
@@ -116,153 +127,157 @@ class PostgreStorage {
|
|
|
116
127
|
});
|
|
117
128
|
}
|
|
118
129
|
getCrowdinCredentials(id) {
|
|
119
|
-
var _a;
|
|
120
130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
131
|
yield this.dbPromise;
|
|
122
|
-
|
|
123
|
-
|
|
132
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
const res = yield client.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]);
|
|
134
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
135
|
+
}));
|
|
124
136
|
});
|
|
125
137
|
}
|
|
126
138
|
getAllCrowdinCredentials() {
|
|
127
|
-
var _a;
|
|
128
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
140
|
yield this.dbPromise;
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
const res = yield client.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', []);
|
|
143
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
144
|
+
}));
|
|
132
145
|
});
|
|
133
146
|
}
|
|
134
147
|
deleteCrowdinCredentials(id) {
|
|
135
|
-
var _a, _b, _c;
|
|
136
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
149
|
yield this.dbPromise;
|
|
138
|
-
yield ((
|
|
139
|
-
|
|
140
|
-
|
|
150
|
+
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
yield client.query('DELETE FROM crowdin_credentials where id = $1', [id]);
|
|
152
|
+
yield client.query('DELETE FROM integration_credentials where crowdin_id = $1', [id]);
|
|
153
|
+
yield client.query('DELETE FROM sync_settings WHERE crowdin_id = $1', [id]);
|
|
154
|
+
}));
|
|
141
155
|
});
|
|
142
156
|
}
|
|
143
157
|
saveIntegrationCredentials(id, credentials, crowdinId) {
|
|
144
|
-
var _a;
|
|
145
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
159
|
yield this.dbPromise;
|
|
147
|
-
yield
|
|
160
|
+
yield this.executeQuery(client => client.query('INSERT INTO integration_credentials(id, credentials, crowdin_id) VALUES ($1, $2, $3)', [
|
|
161
|
+
id,
|
|
162
|
+
credentials,
|
|
163
|
+
crowdinId,
|
|
164
|
+
]));
|
|
148
165
|
});
|
|
149
166
|
}
|
|
150
167
|
updateIntegrationCredentials(id, credentials) {
|
|
151
|
-
var _a;
|
|
152
168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
169
|
yield this.dbPromise;
|
|
154
|
-
yield
|
|
155
|
-
credentials,
|
|
156
|
-
id,
|
|
157
|
-
]));
|
|
170
|
+
yield this.executeQuery(client => client.query('UPDATE integration_credentials SET credentials = $1 WHERE id = $2', [credentials, id]));
|
|
158
171
|
});
|
|
159
172
|
}
|
|
160
173
|
updateIntegrationConfig(id, config) {
|
|
161
|
-
var _a;
|
|
162
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
163
175
|
yield this.dbPromise;
|
|
164
|
-
yield
|
|
176
|
+
yield this.executeQuery(client => client.query('UPDATE integration_credentials SET config = $1 WHERE id = $2', [config, id]));
|
|
165
177
|
});
|
|
166
178
|
}
|
|
167
179
|
getIntegrationCredentials(id) {
|
|
168
|
-
var _a;
|
|
169
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
170
181
|
yield this.dbPromise;
|
|
171
|
-
|
|
172
|
-
|
|
182
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
183
|
+
const res = yield client.query('SELECT id, credentials, config, crowdin_id as "crowdinId" FROM integration_credentials WHERE id = $1', [id]);
|
|
184
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
185
|
+
}));
|
|
173
186
|
});
|
|
174
187
|
}
|
|
175
188
|
getAllIntegrationCredentials(crowdinId) {
|
|
176
|
-
var _a;
|
|
177
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
190
|
yield this.dbPromise;
|
|
179
|
-
|
|
180
|
-
|
|
191
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
const res = yield client.query('SELECT id, credentials, config, crowdin_id as "crowdinId" FROM integration_credentials WHERE crowdin_id = $1', [crowdinId]);
|
|
193
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
194
|
+
}));
|
|
181
195
|
});
|
|
182
196
|
}
|
|
183
197
|
deleteIntegrationCredentials(id) {
|
|
184
|
-
var _a, _b;
|
|
185
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
186
199
|
yield this.dbPromise;
|
|
187
|
-
yield ((
|
|
188
|
-
|
|
200
|
+
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
yield client.query('DELETE FROM integration_credentials where id = $1', [id]);
|
|
202
|
+
yield client.query('DELETE FROM sync_settings where integration_id = $1', [id]);
|
|
203
|
+
}));
|
|
189
204
|
});
|
|
190
205
|
}
|
|
191
206
|
deleteAllIntegrationCredentials(crowdinId) {
|
|
192
|
-
var _a, _b;
|
|
193
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
208
|
yield this.dbPromise;
|
|
195
|
-
yield ((
|
|
196
|
-
|
|
209
|
+
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
yield client.query('DELETE FROM integration_credentials where crowdin_id = $1', [crowdinId]);
|
|
211
|
+
yield client.query('DELETE FROM sync_settings where crowdin_id = $1', [crowdinId]);
|
|
212
|
+
}));
|
|
197
213
|
});
|
|
198
214
|
}
|
|
199
215
|
saveMetadata(id, metadata) {
|
|
200
|
-
var _a;
|
|
201
216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
202
217
|
yield this.dbPromise;
|
|
203
|
-
yield
|
|
218
|
+
yield this.executeQuery(client => client.query('INSERT INTO app_metadata(id, data) VALUES ($1, $2)', [id, metadata]));
|
|
204
219
|
});
|
|
205
220
|
}
|
|
206
221
|
updateMetadata(id, metadata) {
|
|
207
|
-
var _a;
|
|
208
222
|
return __awaiter(this, void 0, void 0, function* () {
|
|
209
223
|
yield this.dbPromise;
|
|
210
|
-
yield
|
|
224
|
+
yield this.executeQuery(client => client.query('UPDATE app_metadata SET data = $1 WHERE id = $2', [id, metadata]));
|
|
211
225
|
});
|
|
212
226
|
}
|
|
213
227
|
getMetadata(id) {
|
|
214
|
-
var _a;
|
|
215
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
216
229
|
yield this.dbPromise;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
230
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
const res = yield client.query('SELECT data FROM app_metadata WHERE id = $1', [id]);
|
|
232
|
+
if (res === null || res === void 0 ? void 0 : res.rows[0]) {
|
|
233
|
+
return JSON.parse(res === null || res === void 0 ? void 0 : res.rows[0].data);
|
|
234
|
+
}
|
|
235
|
+
}));
|
|
221
236
|
});
|
|
222
237
|
}
|
|
223
238
|
deleteMetadata(id) {
|
|
224
|
-
var _a;
|
|
225
239
|
return __awaiter(this, void 0, void 0, function* () {
|
|
226
240
|
yield this.dbPromise;
|
|
227
|
-
yield
|
|
241
|
+
yield this.executeQuery(client => client.query('DELETE FROM app_metadata where id = $1', [id]));
|
|
228
242
|
});
|
|
229
243
|
}
|
|
230
244
|
getSyncSettingsByProvider(integrationId, provider) {
|
|
231
|
-
var _a;
|
|
232
245
|
return __awaiter(this, void 0, void 0, function* () {
|
|
233
246
|
yield this.dbPromise;
|
|
234
|
-
|
|
235
|
-
|
|
247
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
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]);
|
|
249
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
250
|
+
}));
|
|
236
251
|
});
|
|
237
252
|
}
|
|
238
253
|
getAllSyncSettingsByType(type) {
|
|
239
|
-
var _a;
|
|
240
254
|
return __awaiter(this, void 0, void 0, function* () {
|
|
241
255
|
yield this.dbPromise;
|
|
242
|
-
|
|
243
|
-
|
|
256
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const res = yield client.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE type = $1', [type]);
|
|
258
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
259
|
+
}));
|
|
244
260
|
});
|
|
245
261
|
}
|
|
246
262
|
saveSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
247
|
-
var _a;
|
|
248
263
|
return __awaiter(this, void 0, void 0, function* () {
|
|
249
264
|
yield this.dbPromise;
|
|
250
|
-
yield
|
|
265
|
+
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]));
|
|
251
266
|
});
|
|
252
267
|
}
|
|
253
268
|
updateSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
254
|
-
var _a;
|
|
255
269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
256
270
|
yield this.dbPromise;
|
|
257
|
-
yield
|
|
271
|
+
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]));
|
|
258
272
|
});
|
|
259
273
|
}
|
|
260
274
|
getSyncSettings(integrationId, crowdinId, type, provider) {
|
|
261
|
-
var _a;
|
|
262
275
|
return __awaiter(this, void 0, void 0, function* () {
|
|
263
276
|
yield this.dbPromise;
|
|
264
|
-
|
|
265
|
-
|
|
277
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
const res = yield client.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]);
|
|
279
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
280
|
+
}));
|
|
266
281
|
});
|
|
267
282
|
}
|
|
268
283
|
}
|
package/out/storage/sqlite.d.ts
CHANGED
|
@@ -3,17 +3,19 @@ import { CrowdinCredentials, IntegrationCredentials, IntegrationSyncSettings } f
|
|
|
3
3
|
export interface SQLiteStorageConfig {
|
|
4
4
|
dbFolder: string;
|
|
5
5
|
}
|
|
6
|
-
export declare class SQLiteStorage implements Storage
|
|
6
|
+
export declare class SQLiteStorage implements Storage {
|
|
7
7
|
private db;
|
|
8
8
|
private _res?;
|
|
9
9
|
private _rej?;
|
|
10
10
|
private dbPromise;
|
|
11
|
+
private config;
|
|
12
|
+
constructor(config: SQLiteStorageConfig);
|
|
11
13
|
private _run;
|
|
12
14
|
private run;
|
|
13
15
|
private get;
|
|
14
16
|
private each;
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
+
private addColumns;
|
|
18
|
+
migrate(): Promise<void>;
|
|
17
19
|
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
18
20
|
updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
19
21
|
getCrowdinCredentials(id: string): Promise<CrowdinCredentials | undefined>;
|
package/out/storage/sqlite.js
CHANGED
|
@@ -16,11 +16,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.SQLiteStorage = void 0;
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
class SQLiteStorage {
|
|
19
|
-
constructor() {
|
|
19
|
+
constructor(config) {
|
|
20
20
|
this.dbPromise = new Promise((res, rej) => {
|
|
21
21
|
this._res = res;
|
|
22
22
|
this._rej = rej;
|
|
23
23
|
});
|
|
24
|
+
this.config = config;
|
|
24
25
|
}
|
|
25
26
|
_run(query, params) {
|
|
26
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -91,7 +92,7 @@ class SQLiteStorage {
|
|
|
91
92
|
});
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
addColumns() {
|
|
95
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
97
|
const newColumns = ['app_secret', 'domain', 'user_id', 'organization_id', 'base_url'];
|
|
97
98
|
const crowdinCredentialsInfo = yield this.each('PRAGMA table_info(crowdin_credentials);', []);
|
|
@@ -107,7 +108,7 @@ class SQLiteStorage {
|
|
|
107
108
|
}
|
|
108
109
|
});
|
|
109
110
|
}
|
|
110
|
-
|
|
111
|
+
migrate() {
|
|
111
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
113
|
let _connection_res;
|
|
113
114
|
let _connection_rej;
|
|
@@ -117,7 +118,7 @@ class SQLiteStorage {
|
|
|
117
118
|
});
|
|
118
119
|
const sqlite = require('sqlite3');
|
|
119
120
|
//@ts-ignore
|
|
120
|
-
this.db = new sqlite.Database((0, path_1.join)(config.dbFolder, 'app.sqlite'), error => {
|
|
121
|
+
this.db = new sqlite.Database((0, path_1.join)(this.config.dbFolder, 'app.sqlite'), error => {
|
|
121
122
|
if (error) {
|
|
122
123
|
_connection_rej(error);
|
|
123
124
|
}
|
|
@@ -171,7 +172,7 @@ class SQLiteStorage {
|
|
|
171
172
|
`, []);
|
|
172
173
|
this._res && this._res();
|
|
173
174
|
// TODO: temporary code
|
|
174
|
-
yield this.
|
|
175
|
+
yield this.addColumns();
|
|
175
176
|
}
|
|
176
177
|
catch (e) {
|
|
177
178
|
this._rej && this._rej(e);
|
package/package.json
CHANGED