@crowdin/app-project-module 0.20.2 → 0.20.4

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 CHANGED
@@ -217,6 +217,22 @@ configuration.projectIntegration.loginForm = {
217
217
  helpText: 'Api Key for http requests',
218
218
  key: 'apiKey',
219
219
  label: 'Api Key'
220
+ },
221
+ {
222
+ key: 'server',
223
+ label: 'Data center',
224
+ type: 'select',
225
+ defaultValue: '1',
226
+ options: [
227
+ {
228
+ value: '1',
229
+ label: 'USA'
230
+ },
231
+ {
232
+ value: '2',
233
+ label: 'EU'
234
+ }
235
+ ]
220
236
  }
221
237
  ]
222
238
  };
@@ -337,7 +337,19 @@ export interface FormField {
337
337
  helpText?: string;
338
338
  helpTextHtml?: string;
339
339
  label: string;
340
- type?: 'text' | 'password' | 'checkbox';
340
+ type?: 'text' | 'password' | 'checkbox' | 'select';
341
+ defaultValue?: any;
342
+ /**
343
+ * only for select
344
+ */
345
+ isMulti?: boolean;
346
+ /**
347
+ * only for select
348
+ */
349
+ options?: {
350
+ label: string;
351
+ value: string;
352
+ }[];
341
353
  }
342
354
  export declare type TreeItem = File | Folder;
343
355
  export interface File {
@@ -1,6 +1,6 @@
1
1
  import { Config, CrowdinCredentials, IntegrationCredentials, IntegrationSyncSettings } from '../models';
2
- export interface Storage<T> {
3
- connect(config: T): Promise<void>;
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<any>;
27
+ export declare function getStorage(): Storage;
@@ -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
- const sqlite = new sqlite_1.SQLiteStorage();
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
- const postgre = new postgre_1.PostgreStorage();
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
- const mysql = new mysql_1.MySQLStorage();
37
- storage = mysql;
38
- yield mysql.connect(config.mysqlConfig);
39
- return;
30
+ storage = new mysql_1.MySQLStorage(config.mysqlConfig);
40
31
  }
41
- throw new Error('Database is not configured');
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;
@@ -8,13 +8,16 @@ export interface MySQLStorageConfig {
8
8
  database?: string;
9
9
  port?: number;
10
10
  }
11
- export declare class MySQLStorage implements Storage<MySQLStorageConfig> {
12
- private connection;
11
+ export declare class MySQLStorage implements Storage {
12
+ private mysql;
13
13
  private _res?;
14
14
  private _rej?;
15
15
  private dbPromise;
16
- connect(config: MySQLStorageConfig): Promise<void>;
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>;
@@ -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
- connect(config) {
25
+ executeQuery(command) {
24
26
  return __awaiter(this, void 0, void 0, function* () {
27
+ let connection;
25
28
  try {
26
- const mysql = require('mysql2/promise');
27
- this.connection = yield mysql.createConnection(config);
28
- yield this.migrate();
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
- migrate() {
38
- var _a, _b, _c, _d;
54
+ addTables(connection) {
39
55
  return __awaiter(this, void 0, void 0, function* () {
40
- yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute(`
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 ((_b = this.connection) === null || _b === void 0 ? void 0 : _b.execute(`
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 ((_c = this.connection) === null || _c === void 0 ? void 0 : _c.execute(`
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 ((_d = this.connection) === null || _d === void 0 ? void 0 : _d.execute(`
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
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
- const [rows,] = yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.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]));
124
- return (rows || [])[0];
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
- const [rows] = yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.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', []));
132
- return rows || [];
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('DELETE FROM crowdin_credentials where id = ?', [id]));
140
- yield ((_b = this.connection) === null || _b === void 0 ? void 0 : _b.execute('DELETE FROM integration_credentials where crowdin_id = ?', [id]));
141
- yield ((_c = this.connection) === null || _c === void 0 ? void 0 : _c.execute('DELETE FROM sync_settings WHERE crowdin_id = ?', [id]));
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('INSERT INTO integration_credentials(id, credentials, crowdin_id) VALUES (?, ?, ?)', [id, credentials, crowdinId]));
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('UPDATE integration_credentials SET credentials = ? WHERE id = ?', [
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('UPDATE integration_credentials SET config = ? WHERE id = ?', [config, id]));
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
- const [rows,] = yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('SELECT id, credentials, config, crowdin_id as "crowdinId" FROM integration_credentials WHERE id = ?', [id]));
173
- return (rows || [])[0];
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
- const [rows,] = yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('SELECT id, credentials, config, crowdin_id as "crowdinId" FROM integration_credentials WHERE crowdin_id = ?', [crowdinId]));
181
- return rows || [];
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('DELETE FROM integration_credentials where id = ?', [id]));
189
- yield ((_b = this.connection) === null || _b === void 0 ? void 0 : _b.execute('DELETE FROM sync_settings where integration_id = ?', [id]));
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('DELETE FROM integration_credentials where crowdin_id = ?', [crowdinId]));
197
- yield ((_b = this.connection) === null || _b === void 0 ? void 0 : _b.execute('DELETE FROM sync_settings where crowdin_id = ?', [crowdinId]));
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('INSERT INTO app_metadata(id, data) VALUES (?, ?)', [id, metadata]));
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('UPDATE app_metadata SET data = ? WHERE id = ?', [id, metadata]));
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
- const [rows] = yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('SELECT data FROM app_metadata WHERE id = ?', [id]));
219
- if (rows && rows[0]) {
220
- return JSON.parse(rows[0].data);
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('DELETE FROM app_metadata where id = ?', [id]));
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
- const [rows,] = yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE integration_id = ? AND provider = ?', [integrationId, provider]));
236
- return (rows || [])[0];
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
- const [rows,] = yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE type = ?', [type]));
244
- return rows || [];
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('INSERT INTO sync_settings(files, integration_id, crowdin_id, type, provider) VALUES (?, , ?, ?, ?)', [files, integrationId, crowdinId, type, provider]));
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 ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('UPDATE sync_settings SET files = ? WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?', [files, integrationId, crowdinId, type, provider]));
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
- const [rows,] = yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.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]));
266
- return (rows || [])[0];
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
  }
@@ -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<PostgreStorageConfig> {
16
- private client?;
16
+ export declare class PostgreStorage implements Storage {
17
+ private config;
17
18
  private _res?;
18
19
  private _rej?;
19
20
  private dbPromise;
20
- connect(config: PostgreStorageConfig): Promise<void>;
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>;
@@ -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
- connect(config) {
23
+ executeQuery(command) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
- this.client = new pg_1.Client(config);
25
+ const client = new pg_1.Client(this.config);
25
26
  try {
26
- yield this.client.connect();
27
- yield this.migrate();
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
- migrate() {
37
- var _a, _b, _c, _d;
50
+ addTables(client) {
38
51
  return __awaiter(this, void 0, void 0, function* () {
39
- yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query(`
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 ((_b = this.client) === null || _b === void 0 ? void 0 : _b.query(`
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 ((_c = this.client) === null || _c === void 0 ? void 0 : _c.query(`
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 ((_d = this.client) === null || _d === void 0 ? void 0 : _d.query(`
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 ((_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)', [
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 ((_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', [
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
- 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];
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
- 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) || [];
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 ((_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]));
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 ((_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]));
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 ((_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
- ]));
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 ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE integration_credentials SET config = $1 WHERE id = $2', [config, id]));
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
- 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];
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
- 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) || [];
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 ((_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]));
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 ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('DELETE FROM integration_credentials where crowdin_id = $1', [crowdinId]));
196
- yield ((_b = this.client) === null || _b === void 0 ? void 0 : _b.query('DELETE FROM sync_settings where crowdin_id = $1', [crowdinId]));
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 ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('INSERT INTO app_metadata(id, data) VALUES ($1, $2)', [id, metadata]));
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 ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE app_metadata SET data = $1 WHERE id = $2', [id, metadata]));
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
- const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT data FROM app_metadata WHERE id = $1', [id]));
218
- if (res === null || res === void 0 ? void 0 : res.rows[0]) {
219
- return JSON.parse(res === null || res === void 0 ? void 0 : res.rows[0].data);
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 ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('DELETE FROM app_metadata where id = $1', [id]));
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
- 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]));
235
- return res === null || res === void 0 ? void 0 : res.rows[0];
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
- 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]));
243
- return (res === null || res === void 0 ? void 0 : res.rows) || [];
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 ((_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]));
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 ((_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]));
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
- 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]));
265
- return res === null || res === void 0 ? void 0 : res.rows[0];
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
  }
@@ -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<SQLiteStorageConfig> {
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 migrate;
16
- connect(config: SQLiteStorageConfig): Promise<void>;
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>;
@@ -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
- migrate() {
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
- connect(config) {
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.migrate();
175
+ yield this.addColumns();
175
176
  }
176
177
  catch (e) {
177
178
  this._rej && this._rej(e);
@@ -24,24 +24,48 @@
24
24
  {{#if helpTextHtml}}
25
25
  help-text-html="{{helpTextHtml}}"
26
26
  {{/if}}
27
+ {{#ifeq defaultValue true}}
28
+ checked="{{defaultValue}}"
29
+ {{/ifeq}}
27
30
  >
28
31
  </crowdin-checkbox>
29
32
  {{else}}
30
- <crowdin-input
31
- id="{{key}}"
32
- label="{{label}}"
33
- {{#if helpText}}
34
- help-text="{{helpText}}"
35
- {{/if}}
36
- {{#if helpTextHtml}}
37
- help-text-html="{{helpTextHtml}}"
38
- {{/if}}
39
- {{#if type}}
40
- type="{{type}}"
41
- {{/if}}
42
- value="">
43
- </crowdin-input>
44
- {{/ifeq}}
33
+ {{#ifeq type "select"}}
34
+ <crowdin-select
35
+ {{#if isMulti}}
36
+ is-multi
37
+ close-on-select="false"
38
+ {{/if}}
39
+ id="{{key}}"
40
+ label="{{label}}"
41
+ {{#if helpText}}
42
+ help-text="{{helpText}}"
43
+ {{/if}}
44
+ {{#if helpTextHtml}}
45
+ help-text-html="{{helpTextHtml}}"
46
+ {{/if}}
47
+ >
48
+ {{#each options}}
49
+ <option {{#ifeq ../defaultValue value}} selected {{/ifeq}} value="{{value}}">{{label}}</option>
50
+ {{/each}}
51
+ </crowdin-select>
52
+ {{else}}
53
+ <crowdin-input
54
+ id="{{key}}"
55
+ label="{{label}}"
56
+ {{#if helpText}}
57
+ help-text="{{helpText}}"
58
+ {{/if}}
59
+ {{#if helpTextHtml}}
60
+ help-text-html="{{helpTextHtml}}"
61
+ {{/if}}
62
+ {{#if type}}
63
+ type="{{type}}"
64
+ {{/if}}
65
+ value="{{#if defaultValue}}{{defaultValue}}{{/if}}">
66
+ </crowdin-input>
67
+ {{/ifeq}}
68
+ {{/ifeq}}
45
69
  {{/each}}
46
70
  </div>
47
71
  {{/if}}
@@ -133,7 +133,7 @@
133
133
  <script type="text/javascript">
134
134
  document.body.addEventListener('refreshFilesList', (e) => {
135
135
  if (e.detail.refreshIntegration) {
136
- getIntegrationData();
136
+ getIntegrationData(true);
137
137
  } else if (e.detail.refreshCrowdin) {
138
138
  getCrowdinData();
139
139
  }
@@ -144,7 +144,7 @@
144
144
  }
145
145
  {{#if integrationOneLevelFetching}}
146
146
  if (event.detail.componentId === 'integration-files' && event.detail.isOpen) {
147
- getIntegrationData(event.detail.id);
147
+ getIntegrationData(false, event.detail.id);
148
148
  }
149
149
  {{/if}}
150
150
  });
@@ -152,7 +152,7 @@
152
152
  document.body.addEventListener('uploadFilesToIntegration', uploadFilesToIntegration);
153
153
  {{#if integrationSearchListener}}
154
154
  document.body.addEventListener("integrationFilterChange", (event) => {
155
- getIntegrationData(0, event.detail);
155
+ getIntegrationData(false, 0, event.detail);
156
156
  })
157
157
  {{/if}}
158
158
  const appComponent = document.querySelector('crowdin-simple-integration');
@@ -212,7 +212,7 @@
212
212
  .finally(() => (appComponent.setAttribute('is-crowdin-loading', false)));
213
213
  }
214
214
 
215
- function getIntegrationData(parentId = null, search = '') {
215
+ function getIntegrationData(hardReload = false, parentId = '', search = '',) {
216
216
  appComponent.setAttribute('is-integration-loading', true);
217
217
  checkOrigin()
218
218
  .then(restParams => fetch(`api/integration/data${restParams}&parent_id=${parentId}&search=${search}`))
@@ -232,7 +232,11 @@
232
232
  }
233
233
  return item;
234
234
  });
235
- appComponent.pushIntegrationFilesData(tree);
235
+ if (hardReload) {
236
+ appComponent.setIntegrationFilesData(tree);
237
+ } else {
238
+ appComponent.pushIntegrationFilesData(tree);
239
+ }
236
240
  if (search) {
237
241
  const openIds = res.filter(e => !e.type).map(e => e.id);
238
242
  appComponent.setIntegrationOpenedFolders(openIds);
@@ -382,7 +386,7 @@
382
386
  settingsSaveBtn.removeAttribute('disabled');
383
387
  settingsModal.close();
384
388
  {{#if reloadOnConfigSave}}
385
- getIntegrationData();
389
+ getIntegrationData(true);
386
390
  getCrowdinData();
387
391
  {{/if}}
388
392
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.20.2",
3
+ "version": "0.20.4",
4
4
  "description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",