@crowdin/app-project-module 0.15.2 → 0.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,8 +20,8 @@ function handle(config) {
20
20
  const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)(config.clientId, config.clientSecret, event.code);
21
21
  const credentials = {
22
22
  id: (event.domain || event.organizationId).toString(),
23
- accessToken: (0, util_1.encryptData)(config.clientSecret, token.accessToken),
24
- refreshToken: (0, util_1.encryptData)(config.clientSecret, token.refreshToken),
23
+ accessToken: (0, util_1.encryptData)(config, token.accessToken),
24
+ refreshToken: (0, util_1.encryptData)(config, token.refreshToken),
25
25
  expire: (new Date().getTime() / 1000 + token.expiresIn).toString(),
26
26
  type: event.domain ? models_1.AccountType.ENTERPRISE : models_1.AccountType.NORMAL,
27
27
  };
@@ -23,7 +23,7 @@ function handle(config, integration) {
23
23
  (0, util_1.log)('Deleting old credentials', config.logger);
24
24
  yield (0, storage_1.deleteIntegrationCredentials)(req.crowdinContext.clientId);
25
25
  }
26
- yield (0, storage_1.saveIntegrationCredentials)(req.crowdinContext.clientId, (0, util_1.encryptData)(config.clientSecret, JSON.stringify(req.body.credentials)), req.crowdinContext.crowdinId);
26
+ yield (0, storage_1.saveIntegrationCredentials)(req.crowdinContext.clientId, (0, util_1.encryptData)(config, JSON.stringify(req.body.credentials)), req.crowdinContext.crowdinId);
27
27
  res.status(204).end();
28
28
  }), config.onError);
29
29
  }
@@ -10,6 +10,10 @@ export interface Config extends ImagePath {
10
10
  * client secret that we received when registering the app
11
11
  */
12
12
  clientSecret: string;
13
+ /**
14
+ * Secret to encrypt/decrypt credentials (by default @clientSecret will be used)
15
+ */
16
+ cryptoSecret?: string;
13
17
  /**
14
18
  * https url where an app is reachable from the internet (e.g. the one that ngrok generates for us)
15
19
  */
@@ -45,19 +45,19 @@ function prepareCrowdinClient(config, credentials) {
45
45
  let token;
46
46
  const organization = credentials.type === models_1.AccountType.ENTERPRISE ? credentials.id : undefined;
47
47
  if (!isExpired) {
48
- const token = (0, _1.decryptData)(config.clientSecret, credentials.accessToken);
48
+ const token = (0, _1.decryptData)(config, credentials.accessToken);
49
49
  return {
50
50
  client: new crowdin_api_client_1.default({ token, organization }),
51
51
  token,
52
52
  };
53
53
  }
54
54
  (0, _1.log)('Crowdin credentials have expired. Requesting a new credentials', config.logger);
55
- const newCredentials = yield crowdinAppFunctions.refreshOAuthToken(config.clientId, config.clientSecret, (0, _1.decryptData)(config.clientSecret, credentials.refreshToken));
55
+ const newCredentials = yield crowdinAppFunctions.refreshOAuthToken(config.clientId, config.clientSecret, (0, _1.decryptData)(config, credentials.refreshToken));
56
56
  (0, _1.log)('Saving updated crowdin credentials in the database', config.logger);
57
57
  yield (0, storage_1.updateCrowdinCredentials)({
58
58
  id: credentials.id,
59
- refreshToken: (0, _1.encryptData)(config.clientSecret, newCredentials.refreshToken),
60
- accessToken: (0, _1.encryptData)(config.clientSecret, newCredentials.accessToken),
59
+ refreshToken: (0, _1.encryptData)(config, newCredentials.refreshToken),
60
+ accessToken: (0, _1.encryptData)(config, newCredentials.accessToken),
61
61
  expire: (new Date().getTime() / 1000 + newCredentials.expiresIn).toString(),
62
62
  type: credentials.type,
63
63
  });
@@ -71,7 +71,7 @@ exports.prepareCrowdinClient = prepareCrowdinClient;
71
71
  function prepareIntegrationCredentials(config, integration, integrationCredentials) {
72
72
  var _a, _b, _c, _d, _e, _f, _g, _h;
73
73
  return __awaiter(this, void 0, void 0, function* () {
74
- const credentials = JSON.parse((0, _1.decryptData)(config.clientSecret, integrationCredentials.credentials));
74
+ const credentials = JSON.parse((0, _1.decryptData)(config, integrationCredentials.credentials));
75
75
  if ((_a = integration.oauthLogin) === null || _a === void 0 ? void 0 : _a.refresh) {
76
76
  (0, _1.log)('Checking if integration credentials need to be refreshed', config.logger);
77
77
  const oauthLogin = integration.oauthLogin;
@@ -104,7 +104,7 @@ function prepareIntegrationCredentials(config, integration, integrationCredentia
104
104
  credentials.refreshToken = newCredentials[((_h = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _h === void 0 ? void 0 : _h.refreshToken) || 'refresh_token'];
105
105
  }
106
106
  (0, _1.log)('Saving updated integration credentials in the database', config.logger);
107
- yield (0, storage_1.updateIntegrationCredentials)(integrationCredentials.id, (0, _1.encryptData)(config.clientSecret, JSON.stringify(credentials)));
107
+ yield (0, storage_1.updateIntegrationCredentials)(integrationCredentials.id, (0, _1.encryptData)(config, JSON.stringify(credentials)));
108
108
  }
109
109
  }
110
110
  return credentials;
@@ -1,5 +1,5 @@
1
1
  import { Request, Response } from 'express';
2
- import { Logger } from '../models';
2
+ import { Config, Logger } from '../models';
3
3
  export declare class CodeError extends Error {
4
4
  code: number | undefined;
5
5
  constructor(message: string, code?: number);
@@ -7,5 +7,5 @@ export declare class CodeError extends Error {
7
7
  export declare function log(message: string, logger?: Logger): void;
8
8
  export declare function getMessage(err: any): any;
9
9
  export declare function runAsyncWrapper(callback: Function, onError?: (e: any) => void): (req: Request, res: Response, next: Function) => void;
10
- export declare function encryptData(secret: string, data: string): string;
11
- export declare function decryptData(secret: string, data: string): string;
10
+ export declare function encryptData(config: Config, data: string): string;
11
+ export declare function decryptData(config: Config, data: string): string;
package/out/util/index.js CHANGED
@@ -95,11 +95,11 @@ function runAsyncWrapper(callback, onError) {
95
95
  };
96
96
  }
97
97
  exports.runAsyncWrapper = runAsyncWrapper;
98
- function encryptData(secret, data) {
99
- return crypto.AES.encrypt(data, secret).toString();
98
+ function encryptData(config, data) {
99
+ return crypto.AES.encrypt(data, config.cryptoSecret || config.clientSecret).toString();
100
100
  }
101
101
  exports.encryptData = encryptData;
102
- function decryptData(secret, data) {
103
- return crypto.AES.decrypt(data, secret).toString(crypto.enc.Utf8);
102
+ function decryptData(config, data) {
103
+ return crypto.AES.decrypt(data, config.cryptoSecret || config.clientSecret).toString(crypto.enc.Utf8);
104
104
  }
105
105
  exports.decryptData = decryptData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.15.2",
3
+ "version": "0.15.3",
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",