@crowdin/app-project-module 0.19.1 → 0.20.1

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
@@ -30,6 +30,7 @@ In both options you will need to provide Crowdin App configuration file. Please
30
30
  - [Storage](#storage)
31
31
  - [SQLite](#sqlite)
32
32
  - [PostgreSQL](#postgresql)
33
+ - [MySQL](#mysql)
33
34
  - [Settings window](#settings-window)
34
35
  - [Info window](#info-window)
35
36
  - [Background tasks](#background-tasks)
@@ -142,7 +143,7 @@ const configuration = {
142
143
  );
143
144
  },
144
145
  updateIntegration: async (projectId, client, credentials, request, rootFolder, appSettings) => {
145
- ////here should be logic to get translations from Crowdin and upload them to integration
146
+ //here should be logic to get translations from Crowdin and upload them to integration
146
147
  console.log(`Request for updating data in Integration ${JSON.stringify(request)}`);
147
148
  const directories = await client.sourceFilesApi
148
149
  .withFetchAll()
@@ -169,6 +170,9 @@ const configuration = {
169
170
  console.log(response.data);
170
171
  }
171
172
  },
173
+ onLogout: async (projectId, client, credentials, appSettings) => {
174
+ //cleanup logic
175
+ }
172
176
  }
173
177
  };
174
178
 
@@ -292,7 +296,9 @@ configuration.projectIntegration.oauthLogin = {
292
296
  response_type: 'code'
293
297
  },
294
298
  refresh: true,
295
- performGetTokenRequest: async (code) => {
299
+ performGetTokenRequest: async (code, query, url) => {
300
+ //query is an object with all query params
301
+ //url is an url string that OAuth server used to call us back
296
302
  const url = `${tokenUrl}?code=${code}&grant_type=authorization_code`;
297
303
  const headers = {
298
304
  'Authorization': `Bearer ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
@@ -341,6 +347,17 @@ configuration.postgreConfig = {
341
347
  };
342
348
  ```
343
349
 
350
+ ### MySQL
351
+
352
+ ```javascript
353
+ configuration.mysqlConfig = {
354
+ host: 'localhost',
355
+ user: 'root',
356
+ password: 'password',
357
+ database: 'test'
358
+ };
359
+ ```
360
+
344
361
  ## Settings window
345
362
 
346
363
  It is also possible to define settings window for your app where users can customize integration flow.
@@ -669,7 +686,8 @@ const configuration = {
669
686
 
670
687
  const crowdinApp = crowdinModule.addCrowdinEndpoints(app, configuration);
671
688
 
672
- async function cleanup(organization) {
689
+ async function cleanup(organization, allCredentials) {
690
+ //Cleanup logic
673
691
  await crowdinApp.deleteMetadata(organization);
674
692
  }
675
693
 
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config } from '../models';
4
- export default function handle(config: Config): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
3
+ import { Config, IntegrationLogic } from '../models';
4
+ export default function handle(config: Config, integration: IntegrationLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -12,9 +12,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const storage_1 = require("../storage");
13
13
  const util_1 = require("../util");
14
14
  const connection_1 = require("../util/connection");
15
- function handle(config) {
15
+ function handle(config, integration) {
16
16
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
17
17
  (0, util_1.log)('Recieved integration logout request', config.logger);
18
+ if (integration.onLogout) {
19
+ const credentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(req.crowdinContext.clientId);
20
+ yield integration.onLogout(req.crowdinContext.jwtPayload.context.project_id, req.crowdinApiClient, credentials === null || credentials === void 0 ? void 0 : credentials.credentials, credentials === null || credentials === void 0 ? void 0 : credentials.config);
21
+ }
18
22
  yield (0, storage_1.getStorage)().deleteIntegrationCredentials(req.crowdinContext.clientId);
19
23
  (0, connection_1.clearCache)(req.crowdinContext.crowdinId);
20
24
  res.status(204).end();
@@ -28,7 +28,7 @@ function handle(config, integration) {
28
28
  let credentials;
29
29
  if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.performGetTokenRequest) {
30
30
  (0, util_1.log)('Performing custom get bearer token request', config.logger);
31
- credentials = yield oauthLogin.performGetTokenRequest(code);
31
+ credentials = yield oauthLogin.performGetTokenRequest(code, req.query, req.originalUrl);
32
32
  }
33
33
  else {
34
34
  const request = {};
@@ -16,9 +16,10 @@ function handle(config) {
16
16
  const event = req.body;
17
17
  (0, util_1.log)(`Recieved uninstall request ${JSON.stringify(event, null, 2)}`, config.logger);
18
18
  const organization = (event.domain || event.organizationId).toString();
19
+ const allCredentials = yield (0, storage_1.getStorage)().getAllIntegrationCredentials(organization);
19
20
  yield (0, storage_1.getStorage)().deleteCrowdinCredentials(organization);
20
21
  if (config.onUninstall) {
21
- yield config.onUninstall(organization);
22
+ yield config.onUninstall(organization, allCredentials);
22
23
  }
23
24
  (0, util_1.log)('App has been uninstalled', config.logger);
24
25
  res.status(204).end();
package/out/index.js CHANGED
@@ -106,7 +106,7 @@ function addCrowdinEndpoints(app, config) {
106
106
  app.get('/api/subscription-info', json_response_1.default, (0, crowdin_client_1.default)(config), (0, subscription_info_1.default)(config));
107
107
  app.post('/api/settings', (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, settings_save_1.default)(config));
108
108
  app.post('/api/login', (0, crowdin_client_1.default)(config, false, false), (0, integration_login_1.default)(config, integrationLogic));
109
- app.post('/api/logout', (0, crowdin_client_1.default)(config, false, false), (0, integration_logout_1.default)(config));
109
+ app.post('/api/logout', (0, crowdin_client_1.default)(config, false, false), (0, integration_logout_1.default)(config, integrationLogic));
110
110
  app.get('/api/crowdin/files', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, crowdin_files_1.default)(config, integrationLogic));
111
111
  app.get('/api/crowdin/project', json_response_1.default, (0, crowdin_client_1.default)(config), (0, crowdin_project_1.default)(config));
112
112
  app.get('/api/crowdin/file-progress/:fileId', (0, crowdin_client_1.default)(config), (0, crowdin_file_progress_1.default)(config));
@@ -1,6 +1,7 @@
1
1
  import Crowdin, { LanguagesModel, SourceFilesModel, SourceStringsModel } from '@crowdin/crowdin-api-client';
2
2
  import { JwtPayload } from '@crowdin/crowdin-apps-functions';
3
3
  import { Request } from 'express';
4
+ import { MySQLStorageConfig } from '../storage/mysql';
4
5
  import { PostgreStorageConfig } from '../storage/postgre';
5
6
  export interface Config extends ImagePath {
6
7
  /**
@@ -48,9 +49,13 @@ export interface Config extends ImagePath {
48
49
  */
49
50
  dbFolder?: string;
50
51
  /**
51
- * config to configure PostgreSQL as a storage
52
+ * config to configure PostgreSQL as a storage
52
53
  */
53
54
  postgreConfig?: PostgreStorageConfig;
55
+ /**
56
+ * config to configure MySQL as a storage
57
+ */
58
+ mysqlConfig?: MySQLStorageConfig;
54
59
  /**
55
60
  * integration module logic
56
61
  */
@@ -90,7 +95,7 @@ export interface Config extends ImagePath {
90
95
  /**
91
96
  * Uninstall hook for cleanup logic
92
97
  */
93
- onUninstall?: (organization: string) => Promise<void>;
98
+ onUninstall?: (organization: string, allCredentials: IntegrationCredentials[]) => Promise<void>;
94
99
  /**
95
100
  * Error interceptor (can be used to log error in centralized place)
96
101
  */
@@ -165,6 +170,10 @@ export interface IntegrationLogic {
165
170
  * function to define configuration(settings) modal for you app (by default app will not have any custom settings)
166
171
  */
167
172
  getConfiguration?: (projectId: number, client: Crowdin, apiCredentials: any) => Promise<ConfigurationModalEntity[]>;
173
+ /**
174
+ * Logout hook for cleanup logic
175
+ */
176
+ onLogout?: (projectId: number, client: Crowdin, apiCredentials: any, config?: any) => Promise<void>;
168
177
  /**
169
178
  * flag to turn on auto reload of the tree whenever user updates the configuration
170
179
  */
@@ -312,7 +321,9 @@ export interface OAuthLogin {
312
321
  /**
313
322
  * Override to implement request for retrieving access token (and refresh token if 'refresh' is enabled)
314
323
  */
315
- performGetTokenRequest?: (code: string) => Promise<any>;
324
+ performGetTokenRequest?: (code: string, query: {
325
+ [key: string]: any;
326
+ }, url: string) => Promise<any>;
316
327
  /**
317
328
  * Override to implement request for refreshing token (only if 'refresh' is enabled)
318
329
  */
@@ -539,7 +550,7 @@ export interface CrowdinAppUtilities {
539
550
  }>;
540
551
  }
541
552
  export interface IntegrationSyncSettings {
542
- id: string;
553
+ id: number;
543
554
  files?: any;
544
555
  integrationId: string;
545
556
  crowdinId: string;
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getStorage = exports.initialize = void 0;
13
13
  const util_1 = require("../util");
14
+ const mysql_1 = require("./mysql");
14
15
  const postgre_1 = require("./postgre");
15
16
  const sqlite_1 = require("./sqlite");
16
17
  let storage;
@@ -30,6 +31,13 @@ function initialize(config) {
30
31
  yield postgre.connect(config.postgreConfig);
31
32
  return;
32
33
  }
34
+ if (config.mysqlConfig) {
35
+ (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;
40
+ }
33
41
  throw new Error('Database is not configured');
34
42
  });
35
43
  }
@@ -0,0 +1,38 @@
1
+ import { Storage } from '.';
2
+ import { CrowdinCredentials, IntegrationCredentials, IntegrationSyncSettings } from '../models';
3
+ export interface MySQLStorageConfig {
4
+ uri?: string;
5
+ host?: string;
6
+ user?: string;
7
+ password?: string;
8
+ database?: string;
9
+ port?: number;
10
+ }
11
+ export declare class MySQLStorage implements Storage<MySQLStorageConfig> {
12
+ private connection;
13
+ private _res?;
14
+ private _rej?;
15
+ private dbPromise;
16
+ connect(config: MySQLStorageConfig): Promise<void>;
17
+ migrate(): Promise<void>;
18
+ saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
19
+ updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
20
+ getCrowdinCredentials(id: string): Promise<CrowdinCredentials | undefined>;
21
+ getAllCrowdinCredentials(): Promise<CrowdinCredentials[]>;
22
+ deleteCrowdinCredentials(id: string): Promise<void>;
23
+ saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
24
+ updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
25
+ updateIntegrationConfig(id: string, config: any): Promise<void>;
26
+ getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
27
+ getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
28
+ deleteIntegrationCredentials(id: string): Promise<void>;
29
+ saveMetadata(id: string, metadata: any): Promise<void>;
30
+ updateMetadata(id: string, metadata: any): Promise<void>;
31
+ getMetadata(id: string): Promise<any>;
32
+ deleteMetadata(id: string): Promise<void>;
33
+ getSyncSettingsByProvider(integrationId: string, provider: string): Promise<IntegrationSyncSettings | undefined>;
34
+ getAllSyncSettingsByType(type: string): Promise<IntegrationSyncSettings[]>;
35
+ saveSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: string): Promise<void>;
36
+ updateSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: string): Promise<void>;
37
+ getSyncSettings(integrationId: string, crowdinId: string, type: string, provider: string): Promise<IntegrationSyncSettings | undefined>;
38
+ }
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ /* eslint-disable no-unused-expressions */
3
+ /* eslint-disable @typescript-eslint/no-var-requires */
4
+ /* eslint-disable @typescript-eslint/ban-ts-ignore */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.MySQLStorage = void 0;
16
+ class MySQLStorage {
17
+ constructor() {
18
+ this.dbPromise = new Promise((res, rej) => {
19
+ this._res = res;
20
+ this._rej = rej;
21
+ });
22
+ }
23
+ connect(config) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ try {
26
+ const mysql = require('mysql2/promise');
27
+ this.connection = yield mysql.createConnection(config);
28
+ yield this.migrate();
29
+ this._res && this._res();
30
+ }
31
+ catch (e) {
32
+ console.error(e);
33
+ this._rej && this._rej();
34
+ }
35
+ });
36
+ }
37
+ migrate() {
38
+ var _a, _b, _c, _d;
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute(`
41
+ create table if not exists crowdin_credentials
42
+ (
43
+ id varchar(255) primary key,
44
+ app_secret text,
45
+ domain varchar(255),
46
+ user_id varchar(255),
47
+ organization_id varchar(255),
48
+ base_url varchar(255),
49
+ access_token text not null,
50
+ refresh_token text not null,
51
+ expire varchar(255) not null,
52
+ type varchar(255) not null
53
+ )
54
+ `));
55
+ yield ((_b = this.connection) === null || _b === void 0 ? void 0 : _b.execute(`
56
+ create table if not exists integration_credentials
57
+ (
58
+ id varchar(255) primary key,
59
+ credentials text,
60
+ config text,
61
+ crowdin_id varchar(255) not null
62
+ )
63
+ `));
64
+ yield ((_c = this.connection) === null || _c === void 0 ? void 0 : _c.execute(`
65
+ create table if not exists sync_settings
66
+ (
67
+ id int auto_increment primary key,
68
+ files text,
69
+ integration_id varchar(255) not null,
70
+ crowdin_id varchar(255) not null,
71
+ type varchar(255) not null,
72
+ provider varchar(255) not null
73
+ )
74
+ `));
75
+ yield ((_d = this.connection) === null || _d === void 0 ? void 0 : _d.execute(`
76
+ create table if not exists app_metadata
77
+ (
78
+ id varchar(255) primary key,
79
+ data text
80
+ )
81
+ `));
82
+ });
83
+ }
84
+ saveCrowdinCredentials(credentials) {
85
+ var _a;
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
89
+ credentials.id,
90
+ credentials.appSecret,
91
+ credentials.domain,
92
+ credentials.userId,
93
+ credentials.organizationId,
94
+ credentials.baseUrl,
95
+ credentials.accessToken,
96
+ credentials.refreshToken,
97
+ credentials.expire,
98
+ credentials.type,
99
+ ]));
100
+ });
101
+ }
102
+ updateCrowdinCredentials(credentials) {
103
+ var _a;
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ 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 = ?', [
107
+ credentials.appSecret,
108
+ credentials.domain,
109
+ credentials.userId,
110
+ credentials.organizationId,
111
+ credentials.baseUrl,
112
+ credentials.accessToken,
113
+ credentials.refreshToken,
114
+ credentials.expire,
115
+ credentials.id,
116
+ ]));
117
+ });
118
+ }
119
+ getCrowdinCredentials(id) {
120
+ var _a;
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ 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];
125
+ });
126
+ }
127
+ getAllCrowdinCredentials() {
128
+ var _a;
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ 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 || [];
133
+ });
134
+ }
135
+ deleteCrowdinCredentials(id) {
136
+ var _a, _b, _c;
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ 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]));
142
+ });
143
+ }
144
+ saveIntegrationCredentials(id, credentials, crowdinId) {
145
+ var _a;
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ 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]));
149
+ });
150
+ }
151
+ updateIntegrationCredentials(id, credentials) {
152
+ var _a;
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ 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
+ ]));
159
+ });
160
+ }
161
+ updateIntegrationConfig(id, config) {
162
+ var _a;
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ 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]));
166
+ });
167
+ }
168
+ getIntegrationCredentials(id) {
169
+ var _a;
170
+ return __awaiter(this, void 0, void 0, function* () {
171
+ 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];
174
+ });
175
+ }
176
+ getAllIntegrationCredentials(crowdinId) {
177
+ var _a;
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ 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 || [];
182
+ });
183
+ }
184
+ deleteIntegrationCredentials(id) {
185
+ var _a, _b;
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ 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]));
190
+ });
191
+ }
192
+ saveMetadata(id, metadata) {
193
+ var _a;
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ yield this.dbPromise;
196
+ yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('INSERT INTO app_metadata(id, data) VALUES (?, ?)', [id, metadata]));
197
+ });
198
+ }
199
+ updateMetadata(id, metadata) {
200
+ var _a;
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ yield this.dbPromise;
203
+ yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('UPDATE app_metadata SET data = ? WHERE id = ?', [id, metadata]));
204
+ });
205
+ }
206
+ getMetadata(id) {
207
+ var _a;
208
+ return __awaiter(this, void 0, void 0, function* () {
209
+ yield this.dbPromise;
210
+ const [rows] = yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('SELECT data FROM app_metadata WHERE id = ?', [id]));
211
+ if (rows && rows[0]) {
212
+ return JSON.parse(rows[0].data);
213
+ }
214
+ });
215
+ }
216
+ deleteMetadata(id) {
217
+ var _a;
218
+ return __awaiter(this, void 0, void 0, function* () {
219
+ yield this.dbPromise;
220
+ yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.execute('DELETE FROM app_metadata where id = ?', [id]));
221
+ });
222
+ }
223
+ getSyncSettingsByProvider(integrationId, provider) {
224
+ var _a;
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ yield this.dbPromise;
227
+ 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]));
228
+ return (rows || [])[0];
229
+ });
230
+ }
231
+ getAllSyncSettingsByType(type) {
232
+ var _a;
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ 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 type = ?', [type]));
236
+ return rows || [];
237
+ });
238
+ }
239
+ saveSyncSettings(files, integrationId, crowdinId, type, provider) {
240
+ var _a;
241
+ return __awaiter(this, void 0, void 0, function* () {
242
+ yield this.dbPromise;
243
+ 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]));
244
+ });
245
+ }
246
+ updateSyncSettings(files, integrationId, crowdinId, type, provider) {
247
+ var _a;
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ yield this.dbPromise;
250
+ 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]));
251
+ });
252
+ }
253
+ getSyncSettings(integrationId, crowdinId, type, provider) {
254
+ var _a;
255
+ return __awaiter(this, void 0, void 0, function* () {
256
+ yield this.dbPromise;
257
+ 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]));
258
+ return (rows || [])[0];
259
+ });
260
+ }
261
+ }
262
+ exports.MySQLStorage = MySQLStorage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.19.1",
3
+ "version": "0.20.1",
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",
@@ -17,6 +17,7 @@
17
17
  "crypto-js": "^4.0.0",
18
18
  "express": "4.17.1",
19
19
  "express-handlebars": "^5.3.4",
20
+ "mysql2": "^2.3.3",
20
21
  "node-cron": "^3.0.0",
21
22
  "pg": "^8.8.0",
22
23
  "sqlite3": "^5.0.2",