@crowdin/app-project-module 0.20.0 → 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
@@ -143,7 +143,7 @@ const configuration = {
143
143
  );
144
144
  },
145
145
  updateIntegration: async (projectId, client, credentials, request, rootFolder, appSettings) => {
146
- ////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
147
147
  console.log(`Request for updating data in Integration ${JSON.stringify(request)}`);
148
148
  const directories = await client.sourceFilesApi
149
149
  .withFetchAll()
@@ -170,6 +170,9 @@ const configuration = {
170
170
  console.log(response.data);
171
171
  }
172
172
  },
173
+ onLogout: async (projectId, client, credentials, appSettings) => {
174
+ //cleanup logic
175
+ }
173
176
  }
174
177
  };
175
178
 
@@ -293,7 +296,9 @@ configuration.projectIntegration.oauthLogin = {
293
296
  response_type: 'code'
294
297
  },
295
298
  refresh: true,
296
- 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
297
302
  const url = `${tokenUrl}?code=${code}&grant_type=authorization_code`;
298
303
  const headers = {
299
304
  'Authorization': `Bearer ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
@@ -681,7 +686,8 @@ const configuration = {
681
686
 
682
687
  const crowdinApp = crowdinModule.addCrowdinEndpoints(app, configuration);
683
688
 
684
- async function cleanup(organization) {
689
+ async function cleanup(organization, allCredentials) {
690
+ //Cleanup logic
685
691
  await crowdinApp.deleteMetadata(organization);
686
692
  }
687
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));
@@ -95,7 +95,7 @@ export interface Config extends ImagePath {
95
95
  /**
96
96
  * Uninstall hook for cleanup logic
97
97
  */
98
- onUninstall?: (organization: string) => Promise<void>;
98
+ onUninstall?: (organization: string, allCredentials: IntegrationCredentials[]) => Promise<void>;
99
99
  /**
100
100
  * Error interceptor (can be used to log error in centralized place)
101
101
  */
@@ -170,6 +170,10 @@ export interface IntegrationLogic {
170
170
  * function to define configuration(settings) modal for you app (by default app will not have any custom settings)
171
171
  */
172
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>;
173
177
  /**
174
178
  * flag to turn on auto reload of the tree whenever user updates the configuration
175
179
  */
@@ -317,7 +321,9 @@ export interface OAuthLogin {
317
321
  /**
318
322
  * Override to implement request for retrieving access token (and refresh token if 'refresh' is enabled)
319
323
  */
320
- performGetTokenRequest?: (code: string) => Promise<any>;
324
+ performGetTokenRequest?: (code: string, query: {
325
+ [key: string]: any;
326
+ }, url: string) => Promise<any>;
321
327
  /**
322
328
  * Override to implement request for refreshing token (only if 'refresh' is enabled)
323
329
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.20.0",
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",