@crowdin/app-project-module 0.20.1 → 0.20.2

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.
@@ -16,9 +16,10 @@ 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
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);
19
+ (0, util_1.log)('Invoking onLogout hook', config.logger);
20
+ yield integration.onLogout(req.crowdinContext.jwtPayload.context.project_id, req.crowdinApiClient, req.integrationCredentials, req.integrationSettings);
21
21
  }
22
+ (0, util_1.log)(`Deleting integration credentials for ${req.crowdinContext.clientId} client`, config.logger);
22
23
  yield (0, storage_1.getStorage)().deleteIntegrationCredentials(req.crowdinContext.clientId);
23
24
  (0, connection_1.clearCache)(req.crowdinContext.crowdinId);
24
25
  res.status(204).end();
@@ -11,16 +11,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const storage_1 = require("../storage");
13
13
  const util_1 = require("../util");
14
+ const connection_1 = require("../util/connection");
14
15
  function handle(config) {
15
16
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
17
  const event = req.body;
17
18
  (0, util_1.log)(`Recieved uninstall request ${JSON.stringify(event, null, 2)}`, config.logger);
19
+ const projectIntegration = config.projectIntegration;
18
20
  const organization = (event.domain || event.organizationId).toString();
19
- const allCredentials = yield (0, storage_1.getStorage)().getAllIntegrationCredentials(organization);
20
- yield (0, storage_1.getStorage)().deleteCrowdinCredentials(organization);
21
21
  if (config.onUninstall) {
22
+ let allCredentials = [];
23
+ if (projectIntegration) {
24
+ const loadedCredentials = yield (0, storage_1.getStorage)().getAllIntegrationCredentials(organization);
25
+ allCredentials = yield Promise.all(loadedCredentials.map((creds) => __awaiter(this, void 0, void 0, function* () {
26
+ let settings;
27
+ if (creds.config) {
28
+ settings = JSON.parse(creds.config);
29
+ }
30
+ const credentials = yield (0, connection_1.prepareIntegrationCredentials)(config, projectIntegration, creds);
31
+ return { settings, credentials };
32
+ })));
33
+ }
34
+ (0, util_1.log)('Invoking onUninstall hook', config.logger);
22
35
  yield config.onUninstall(organization, allCredentials);
23
36
  }
37
+ if (projectIntegration) {
38
+ (0, util_1.log)(`Deleting all integration credentials for ${organization} organization`, config.logger);
39
+ yield (0, storage_1.getStorage)().deleteAllIntegrationCredentials(organization);
40
+ }
41
+ (0, util_1.log)(`Deleting crowdin credentials for ${organization} organization`, config.logger);
42
+ yield (0, storage_1.getStorage)().deleteCrowdinCredentials(organization);
24
43
  (0, util_1.log)('App has been uninstalled', config.logger);
25
44
  res.status(204).end();
26
45
  }), config.onError);
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, integrationLogic));
109
+ app.post('/api/logout', (0, crowdin_client_1.default)(config, false, false), (0, integration_credentials_1.default)(config, integrationLogic), (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));
@@ -95,7 +95,10 @@ export interface Config extends ImagePath {
95
95
  /**
96
96
  * Uninstall hook for cleanup logic
97
97
  */
98
- onUninstall?: (organization: string, allCredentials: IntegrationCredentials[]) => Promise<void>;
98
+ onUninstall?: (organization: string, allCredentials: {
99
+ settings?: any;
100
+ credentials: any;
101
+ }[]) => Promise<void>;
99
102
  /**
100
103
  * Error interceptor (can be used to log error in centralized place)
101
104
  */
@@ -12,6 +12,7 @@ export interface Storage<T> {
12
12
  getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
13
13
  getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
14
14
  deleteIntegrationCredentials(id: string): Promise<void>;
15
+ deleteAllIntegrationCredentials(crowdinId: string): Promise<void>;
15
16
  saveMetadata(id: string, metadata: any): Promise<void>;
16
17
  updateMetadata(id: string, metadata: any): Promise<void>;
17
18
  getMetadata(id: string): Promise<any | undefined>;
@@ -26,6 +26,7 @@ export declare class MySQLStorage implements Storage<MySQLStorageConfig> {
26
26
  getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
27
27
  getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
28
28
  deleteIntegrationCredentials(id: string): Promise<void>;
29
+ deleteAllIntegrationCredentials(crowdinId: string): Promise<void>;
29
30
  saveMetadata(id: string, metadata: any): Promise<void>;
30
31
  updateMetadata(id: string, metadata: any): Promise<void>;
31
32
  getMetadata(id: string): Promise<any>;
@@ -189,6 +189,14 @@ class MySQLStorage {
189
189
  yield ((_b = this.connection) === null || _b === void 0 ? void 0 : _b.execute('DELETE FROM sync_settings where integration_id = ?', [id]));
190
190
  });
191
191
  }
192
+ deleteAllIntegrationCredentials(crowdinId) {
193
+ var _a, _b;
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('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]));
198
+ });
199
+ }
192
200
  saveMetadata(id, metadata) {
193
201
  var _a;
194
202
  return __awaiter(this, void 0, void 0, function* () {
@@ -30,6 +30,7 @@ export declare class PostgreStorage implements Storage<PostgreStorageConfig> {
30
30
  getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
31
31
  getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
32
32
  deleteIntegrationCredentials(id: string): Promise<void>;
33
+ deleteAllIntegrationCredentials(crowdinId: string): Promise<void>;
33
34
  saveMetadata(id: string, metadata: any): Promise<void>;
34
35
  updateMetadata(id: string, metadata: any): Promise<void>;
35
36
  getMetadata(id: string): Promise<any>;
@@ -188,6 +188,14 @@ class PostgreStorage {
188
188
  yield ((_b = this.client) === null || _b === void 0 ? void 0 : _b.query('DELETE FROM sync_settings where integration_id = $1', [id]));
189
189
  });
190
190
  }
191
+ deleteAllIntegrationCredentials(crowdinId) {
192
+ var _a, _b;
193
+ return __awaiter(this, void 0, void 0, function* () {
194
+ yield this.dbPromise;
195
+ yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('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]));
197
+ });
198
+ }
191
199
  saveMetadata(id, metadata) {
192
200
  var _a;
193
201
  return __awaiter(this, void 0, void 0, function* () {
@@ -25,6 +25,7 @@ export declare class SQLiteStorage implements Storage<SQLiteStorageConfig> {
25
25
  getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
26
26
  getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
27
27
  deleteIntegrationCredentials(id: string): Promise<void>;
28
+ deleteAllIntegrationCredentials(crowdinId: string): Promise<void>;
28
29
  saveMetadata(id: string, metadata: any): Promise<void>;
29
30
  updateMetadata(id: string, metadata: any): Promise<void>;
30
31
  getMetadata(id: string): Promise<any>;
@@ -253,6 +253,12 @@ class SQLiteStorage {
253
253
  yield this.run('DELETE FROM sync_settings where integration_id = ?', [id]);
254
254
  });
255
255
  }
256
+ deleteAllIntegrationCredentials(crowdinId) {
257
+ return __awaiter(this, void 0, void 0, function* () {
258
+ yield this.run('DELETE FROM integration_credentials where crowdin_id = ?', [crowdinId]);
259
+ yield this.run('DELETE FROM sync_settings where crowdin_id = ?', [crowdinId]);
260
+ });
261
+ }
256
262
  saveMetadata(id, metadata) {
257
263
  return this.run('INSERT INTO app_metadata(id, data) VALUES (?, ?)', [id, JSON.stringify(metadata)]);
258
264
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
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",