@crowdin/app-project-module 0.31.0 → 0.32.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.
Files changed (80) hide show
  1. package/out/handlers/custom-mt/translate.d.ts +2 -2
  2. package/out/handlers/custom-mt/translate.js +8 -6
  3. package/out/handlers/file-processing/custom-file-format.d.ts +2 -2
  4. package/out/handlers/file-processing/custom-file-format.js +4 -4
  5. package/out/handlers/file-processing/file-download.d.ts +1 -1
  6. package/out/handlers/file-processing/file-download.js +3 -2
  7. package/out/handlers/file-processing/pre-post-process.d.ts +2 -2
  8. package/out/handlers/file-processing/pre-post-process.js +11 -3
  9. package/out/handlers/form-data-display.d.ts +1 -1
  10. package/out/handlers/form-data-save.d.ts +1 -1
  11. package/out/handlers/install.d.ts +1 -1
  12. package/out/handlers/install.js +5 -3
  13. package/out/handlers/integration/crowdin-file-progress.d.ts +2 -2
  14. package/out/handlers/integration/crowdin-file-progress.js +4 -4
  15. package/out/handlers/integration/crowdin-files.d.ts +1 -1
  16. package/out/handlers/integration/crowdin-files.js +4 -4
  17. package/out/handlers/integration/crowdin-project.d.ts +2 -2
  18. package/out/handlers/integration/crowdin-project.js +4 -4
  19. package/out/handlers/integration/crowdin-update.d.ts +1 -1
  20. package/out/handlers/integration/crowdin-update.js +4 -4
  21. package/out/handlers/integration/crowdin-webhook.d.ts +1 -1
  22. package/out/handlers/integration/crowdin-webhook.js +1 -1
  23. package/out/handlers/integration/integration-data.d.ts +2 -2
  24. package/out/handlers/integration/integration-data.js +4 -4
  25. package/out/handlers/integration/integration-login.d.ts +2 -2
  26. package/out/handlers/integration/integration-login.js +4 -4
  27. package/out/handlers/integration/integration-logout.d.ts +1 -1
  28. package/out/handlers/integration/integration-logout.js +4 -4
  29. package/out/handlers/integration/integration-update.d.ts +1 -1
  30. package/out/handlers/integration/integration-update.js +3 -3
  31. package/out/handlers/integration/integration-webhook.d.ts +1 -1
  32. package/out/handlers/integration/integration-webhook.js +1 -1
  33. package/out/handlers/integration/main.d.ts +1 -1
  34. package/out/handlers/integration/main.js +5 -3
  35. package/out/handlers/integration/oauth-login.d.ts +1 -1
  36. package/out/handlers/integration/oauth-login.js +6 -10
  37. package/out/handlers/integration/oauth-url.d.ts +2 -2
  38. package/out/handlers/integration/oauth-url.js +3 -3
  39. package/out/handlers/integration/settings-save.d.ts +1 -1
  40. package/out/handlers/integration/settings-save.js +2 -2
  41. package/out/handlers/integration/settings.d.ts +1 -2
  42. package/out/handlers/integration/settings.js +2 -2
  43. package/out/handlers/integration/sync-settings-save.d.ts +1 -1
  44. package/out/handlers/integration/sync-settings-save.js +1 -1
  45. package/out/handlers/integration/sync-settings.d.ts +1 -2
  46. package/out/handlers/integration/sync-settings.js +4 -4
  47. package/out/handlers/integration/synced-files.d.ts +1 -2
  48. package/out/handlers/integration/synced-files.js +4 -4
  49. package/out/handlers/manifest.js +7 -7
  50. package/out/handlers/subscription-paid.d.ts +1 -2
  51. package/out/handlers/subscription-paid.js +4 -3
  52. package/out/handlers/uninstall.d.ts +1 -1
  53. package/out/handlers/uninstall.js +7 -6
  54. package/out/index.d.ts +1 -1
  55. package/out/index.js +36 -33
  56. package/out/middlewares/crowdin-client.d.ts +4 -1
  57. package/out/middlewares/crowdin-client.js +26 -16
  58. package/out/middlewares/integration-credentials.d.ts +1 -1
  59. package/out/middlewares/integration-credentials.js +2 -2
  60. package/out/middlewares/render-ui-module.d.ts +2 -2
  61. package/out/middlewares/render-ui-module.js +2 -2
  62. package/out/middlewares/ui-module.d.ts +1 -1
  63. package/out/middlewares/ui-module.js +17 -6
  64. package/out/models/index.d.ts +8 -4
  65. package/out/models/index.js +1 -0
  66. package/out/storage/index.js +4 -4
  67. package/out/util/api/api.js +4 -4
  68. package/out/util/connection.d.ts +11 -2
  69. package/out/util/connection.js +17 -16
  70. package/out/util/cron.js +43 -25
  71. package/out/util/file-snapshot.d.ts +1 -1
  72. package/out/util/file-snapshot.js +4 -4
  73. package/out/util/index.d.ts +3 -6
  74. package/out/util/index.js +12 -42
  75. package/out/util/logger.d.ts +14 -0
  76. package/out/util/logger.js +71 -0
  77. package/out/util/synced-files.js +4 -4
  78. package/out/util/webhooks.d.ts +1 -1
  79. package/out/util/webhooks.js +6 -6
  80. package/package.json +1 -1
@@ -13,10 +13,10 @@ const util_1 = require("../../util");
13
13
  const defaults_1 = require("../../util/defaults");
14
14
  function handle(config, integration) {
15
15
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
- (0, util_1.log)('Received OAuth login url request', config.logger);
16
+ req.logInfo('Received OAuth login url request');
17
17
  const { oauthLogin } = integration;
18
18
  if (!oauthLogin) {
19
- (0, util_1.log)('OAuth login url request is not supported', config.logger);
19
+ req.logInfo('OAuth login url request is not supported');
20
20
  res.status(400).end();
21
21
  return;
22
22
  }
@@ -25,6 +25,6 @@ function handle(config, integration) {
25
25
  ? oauthLogin.getAuthorizationUrl(`${config.baseUrl}${(0, defaults_1.getOauthRoute)(integration)}`, loginForm)
26
26
  : (0, defaults_1.constructOauthUrl)(config, integration);
27
27
  res.send({ url });
28
- }), config.onError);
28
+ }));
29
29
  }
30
30
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
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;
4
+ export default function handle(config: Config, integration: IntegrationLogic): (req: import("../../models").CrowdinClientRequest | 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;
@@ -18,7 +18,7 @@ const webhooks_1 = require("../../util/webhooks");
18
18
  function handle(config, integration) {
19
19
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
20
20
  const appSettings = req.body.config;
21
- (0, util_1.log)(`Saving settings ${JSON.stringify(appSettings, null, 2)}`, config.logger);
21
+ req.logInfo(`Saving settings ${JSON.stringify(appSettings, null, 2)}`);
22
22
  yield (0, storage_1.getStorage)().updateIntegrationConfig(req.crowdinContext.clientId, JSON.stringify(appSettings));
23
23
  if (integration.webhooks) {
24
24
  yield (0, webhooks_1.registerWebhooks)(config, integration, req.crowdinApiClient, req.crowdinContext, req.integrationCredentials, appSettings);
@@ -34,6 +34,6 @@ function handle(config, integration) {
34
34
  yield (0, cron_1.createOrUpdateSyncSettings)(config, req, [], models_1.Provider.INTEGRATION, true);
35
35
  }
36
36
  res.status(204).end();
37
- }), config.onError);
37
+ }));
38
38
  }
39
39
  exports.default = handle;
@@ -1,4 +1,3 @@
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
+ export default function handle(): (req: import("../../models").CrowdinClientRequest | 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;
@@ -10,13 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const util_1 = require("../../util");
13
- function handle(config) {
13
+ function handle() {
14
14
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
15
15
  let settings = {};
16
16
  if (req.integrationSettings) {
17
17
  settings = req.integrationSettings;
18
18
  }
19
19
  res.send(settings);
20
- }), config.onError);
20
+ }));
21
21
  }
22
22
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
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;
4
+ export default function handle(config: Config, integration: IntegrationLogic): (req: import("../../models").CrowdinClientRequest | 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;
@@ -21,6 +21,6 @@ function handle(config, integration) {
21
21
  yield (0, file_snapshot_1.createOrUpdateFileSnapshot)(config, integration, req, provider);
22
22
  }
23
23
  res.status(204).end();
24
- }), config.onError);
24
+ }));
25
25
  }
26
26
  exports.default = handle;
@@ -1,4 +1,3 @@
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
+ export default function handle(): (req: import("../../models").CrowdinClientRequest | 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;
@@ -11,17 +11,17 @@ 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
- function handle(config) {
14
+ function handle() {
15
15
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
16
  let files = {};
17
17
  const provider = req.params.provider || req.body.provider;
18
- (0, util_1.log)(`Loading sync settings for provider ${provider}`, config.logger);
18
+ req.logInfo(`Loading sync settings for provider ${provider}`);
19
19
  const syncSettings = yield (0, storage_1.getStorage)().getSyncSettingsByProvider(req.crowdinContext.clientId, provider);
20
20
  if (syncSettings) {
21
21
  files = JSON.parse(syncSettings.files) || [];
22
22
  }
23
- (0, util_1.log)(`Returning sync settings ${JSON.stringify(files, null, 2)}`, config.logger);
23
+ req.logInfo(`Returning sync settings ${JSON.stringify(files, null, 2)}`);
24
24
  res.send(files);
25
- }), config.onError);
25
+ }));
26
26
  }
27
27
  exports.default = handle;
@@ -1,4 +1,3 @@
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
+ export default function handle(): (req: import("../../models").CrowdinClientRequest | 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;
@@ -11,16 +11,16 @@ 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
- function handle(config) {
14
+ function handle() {
15
15
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
16
  let fileIds = [];
17
- (0, util_1.log)('Loading synced files', config.logger);
17
+ req.logInfo('Loading synced files');
18
18
  const syncedFiles = yield (0, storage_1.getStorage)().getSyncedFiles(req.crowdinContext.clientId, req.crowdinContext.crowdinId);
19
19
  if (syncedFiles) {
20
20
  fileIds = JSON.parse(syncedFiles.fileIds) || [];
21
21
  }
22
- (0, util_1.log)(`Returning synced files ${JSON.stringify(fileIds, null, 2)}`, config.logger);
22
+ req.logInfo(`Returning synced files ${JSON.stringify(fileIds, null, 2)}`);
23
23
  res.send(fileIds);
24
- }), config.onError);
24
+ }));
25
25
  }
26
26
  exports.default = handle;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const models_1 = require("../models");
4
- const connection_1 = require("../util/connection");
5
4
  const util_1 = require("../util");
6
5
  const api_1 = require("../util/api/api");
6
+ const connection_1 = require("../util/connection");
7
7
  function handle(config) {
8
8
  const modules = {};
9
9
  if (config.projectIntegration) {
@@ -12,7 +12,7 @@ function handle(config) {
12
12
  key: config.identifier + '-int',
13
13
  name: config.name,
14
14
  description: config.description,
15
- logo: (0, util_1.getLogoUrl)(config, config.projectIntegration, '/integration'),
15
+ logo: (0, util_1.getLogoUrl)(config.projectIntegration, '/integration'),
16
16
  url: '/',
17
17
  environments: config.projectIntegration.environments,
18
18
  },
@@ -74,7 +74,7 @@ function handle(config) {
74
74
  {
75
75
  key: config.identifier + '-mt',
76
76
  name: config.name,
77
- logo: (0, util_1.getLogoUrl)(config, config.customMT, '/mt'),
77
+ logo: (0, util_1.getLogoUrl)(config.customMT, '/mt'),
78
78
  url: '/translate',
79
79
  environments: config.customMT.environments,
80
80
  withContext: !!config.customMT.withContext,
@@ -87,7 +87,7 @@ function handle(config) {
87
87
  key: config.identifier + '-resources',
88
88
  name: config.organizationMenu.name || config.name,
89
89
  url: '/resources/' + (config.organizationMenu.fileName || 'index.html'),
90
- icon: (0, util_1.getLogoUrl)(config, config.organizationMenu, '/resources'),
90
+ icon: (0, util_1.getLogoUrl)(config.organizationMenu, '/resources'),
91
91
  },
92
92
  ];
93
93
  }
@@ -97,7 +97,7 @@ function handle(config) {
97
97
  key: config.identifier + '-profile-resources-menu',
98
98
  name: config.profileResourcesMenu.name || config.name,
99
99
  url: '/resources/' + (config.profileResourcesMenu.fileName || 'index.html'),
100
- icon: (0, util_1.getLogoUrl)(config, config.profileResourcesMenu, '/resources'),
100
+ icon: (0, util_1.getLogoUrl)(config.profileResourcesMenu, '/resources'),
101
101
  environments: config.profileResourcesMenu.environments,
102
102
  },
103
103
  ];
@@ -138,7 +138,7 @@ function handle(config) {
138
138
  key: config.identifier + '-tools',
139
139
  name: config.projectTools.name || config.name,
140
140
  description: config.description,
141
- logo: (0, util_1.getLogoUrl)(config, config.projectTools, '/tools'),
141
+ logo: (0, util_1.getLogoUrl)(config.projectTools, '/tools'),
142
142
  url: '/tools/' + (config.projectTools.fileName || 'index.html'),
143
143
  environments: config.projectTools.environments,
144
144
  },
@@ -150,7 +150,7 @@ function handle(config) {
150
150
  key: config.identifier + '-project-reports',
151
151
  name: config.projectReports.name || config.name,
152
152
  description: config.description,
153
- logo: (0, util_1.getLogoUrl)(config, config.projectReports, '/reports'),
153
+ logo: (0, util_1.getLogoUrl)(config.projectReports, '/reports'),
154
154
  url: '/reports/' + (config.projectReports.fileName || 'index.html'),
155
155
  },
156
156
  ];
@@ -1,4 +1,3 @@
1
1
  /// <reference types="qs" />
2
2
  import { Request, Response } from 'express';
3
- import { Config } from '../models';
4
- export default function handle(config: Config): (req: 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
+ export default function handle(): (req: import("../models").CrowdinClientRequest | Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -11,12 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const util_1 = require("../util");
13
13
  const connection_1 = require("../util/connection");
14
- function handle(config) {
14
+ const logger_1 = require("../util/logger");
15
+ function handle() {
15
16
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
17
  const organizationId = (req.query || {})['organization_id'] || (req.body || {})['organization_id'];
17
- (0, util_1.log)(`Received subscription paid request for organization ${organizationId}`, config.logger);
18
+ (0, logger_1.log)(`Received subscription paid request for organization ${organizationId}`);
18
19
  (0, connection_1.clearCache)(organizationId);
19
20
  res.status(204).end();
20
- }), config.onError);
21
+ }));
21
22
  }
22
23
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Request, Response } from 'express';
3
3
  import { Config } from '../models';
4
- export default function handle(config: Config): (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
4
+ export default function handle(config: Config): (req: import("../models").CrowdinClientRequest | 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,11 +12,12 @@ 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
+ const logger_1 = require("../util/logger");
15
16
  const webhooks_1 = require("../util/webhooks");
16
17
  function handle(config) {
17
18
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
18
19
  const event = req.body;
19
- (0, util_1.log)(`Received uninstall request ${JSON.stringify(event, null, 2)}`, config.logger);
20
+ (0, logger_1.log)(`Received uninstall request ${JSON.stringify(event, null, 2)}`);
20
21
  const projectIntegration = config.projectIntegration;
21
22
  const organization = (event.domain || event.organizationId).toString();
22
23
  if (config.onUninstall) {
@@ -32,20 +33,20 @@ function handle(config) {
32
33
  return { settings, credentials };
33
34
  })));
34
35
  }
35
- (0, util_1.log)('Invoking onUninstall hook', config.logger);
36
+ (0, logger_1.log)('Invoking onUninstall hook');
36
37
  yield config.onUninstall(organization, allCredentials);
37
38
  }
38
39
  if (projectIntegration) {
39
40
  if (projectIntegration.webhooks) {
40
41
  yield (0, webhooks_1.unregisterAllCrowdinWebhooks)(config, projectIntegration, organization);
41
42
  }
42
- (0, util_1.log)(`Deleting all integration credentials for ${organization} organization`, config.logger);
43
+ (0, logger_1.log)(`Deleting all integration credentials for ${organization} organization`);
43
44
  yield (0, storage_1.getStorage)().deleteAllIntegrationCredentials(organization);
44
45
  }
45
- (0, util_1.log)(`Deleting crowdin credentials for ${organization} organization`, config.logger);
46
+ (0, logger_1.log)(`Deleting crowdin credentials for ${organization} organization`);
46
47
  yield (0, storage_1.getStorage)().deleteCrowdinCredentials(organization);
47
- (0, util_1.log)('App has been uninstalled', config.logger);
48
+ (0, logger_1.log)('App has been uninstalled');
48
49
  res.status(204).end();
49
- }), config.onError);
50
+ }));
50
51
  }
51
52
  exports.default = handle;
package/out/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Express } from 'express';
2
2
  import { ClientConfig, Config, CrowdinAppUtilities } from './models';
3
3
  import express from './util/terminus-express';
4
- export { Scope, UserPermissions, ProjectPermissions } from './models';
4
+ export { ProjectPermissions, Scope, UserPermissions } from './models';
5
5
  export { express };
6
6
  export declare function addCrowdinEndpoints(app: Express, clientConfig: Config | ClientConfig): CrowdinAppUtilities;
7
7
  export declare function createApp(clientConfig: ClientConfig): void;
package/out/index.js CHANGED
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.createApp = exports.addCrowdinEndpoints = exports.express = exports.ProjectPermissions = exports.UserPermissions = exports.Scope = void 0;
38
+ exports.createApp = exports.addCrowdinEndpoints = exports.express = exports.UserPermissions = exports.Scope = exports.ProjectPermissions = void 0;
39
39
  const express_handlebars_1 = __importDefault(require("express-handlebars"));
40
40
  const cron = __importStar(require("node-cron"));
41
41
  const path_1 = require("path");
@@ -79,20 +79,23 @@ const api_1 = require("./util/api/api");
79
79
  const connection_1 = require("./util/connection");
80
80
  const cron_1 = require("./util/cron");
81
81
  const defaults_1 = require("./util/defaults");
82
+ const logger = __importStar(require("./util/logger"));
83
+ const logger_1 = require("./util/logger");
82
84
  const terminus_express_1 = __importDefault(require("./util/terminus-express"));
83
85
  exports.express = terminus_express_1.default;
84
86
  const webhooks_1 = require("./util/webhooks");
85
87
  var models_2 = require("./models");
88
+ Object.defineProperty(exports, "ProjectPermissions", { enumerable: true, get: function () { return models_2.ProjectPermissions; } });
86
89
  Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return models_2.Scope; } });
87
90
  Object.defineProperty(exports, "UserPermissions", { enumerable: true, get: function () { return models_2.UserPermissions; } });
88
- Object.defineProperty(exports, "ProjectPermissions", { enumerable: true, get: function () { return models_2.ProjectPermissions; } });
89
91
  function addCrowdinEndpoints(app, clientConfig) {
90
92
  var _a, _b, _c, _d, _e, _f, _g;
91
93
  const config = (0, defaults_1.convertClientConfig)(clientConfig);
92
94
  if (!config.disableGlobalErrorHandling) {
93
- handleUncaughtErrors(config);
95
+ handleUncaughtErrors();
94
96
  }
95
97
  storage.initialize(config);
98
+ logger.initialize(config);
96
99
  app.use(terminus_express_1.default.json({ limit: '50mb' }));
97
100
  app.use('/assets', terminus_express_1.default.static((0, path_1.join)(__dirname, 'static')));
98
101
  app.set('views', (0, path_1.join)(__dirname, 'views'));
@@ -124,31 +127,31 @@ function addCrowdinEndpoints(app, clientConfig) {
124
127
  },
125
128
  }));
126
129
  app.set('view engine', 'handlebars');
127
- app.get((0, util_1.getLogoUrl)(config), (req, res) => res.sendFile(config.imagePath));
130
+ app.get((0, util_1.getLogoUrl)(), (req, res) => res.sendFile(config.imagePath));
128
131
  app.post('/installed', (0, install_1.default)(config));
129
132
  app.post('/uninstall', (0, uninstall_1.default)(config));
130
133
  app.get('/manifest.json', json_response_1.default, (0, manifest_1.default)(config));
131
134
  if (!(0, connection_1.isAppFree)(config)) {
132
- app.post('/subscription-paid', (0, subscription_paid_1.default)(config));
135
+ app.post('/subscription-paid', (0, subscription_paid_1.default)());
133
136
  }
134
137
  const integrationLogic = config.projectIntegration;
135
138
  if (integrationLogic) {
136
139
  (0, defaults_1.applyIntegrationModuleDefaults)(config, integrationLogic);
137
- app.get((0, util_1.getLogoUrl)(config, integrationLogic, '/integration'), (req, res) => res.sendFile(integrationLogic.imagePath || config.imagePath));
140
+ app.get((0, util_1.getLogoUrl)(integrationLogic, '/integration'), (req, res) => res.sendFile(integrationLogic.imagePath || config.imagePath));
138
141
  app.get('/', (0, crowdin_client_1.default)(config, true, false), (0, integration_credentials_1.default)(config, integrationLogic, true), (0, main_1.default)(config, integrationLogic));
139
142
  app.get('/api/subscription-info', json_response_1.default, (0, crowdin_client_1.default)(config), (0, subscription_info_1.default)(config));
140
143
  app.post('/api/settings', (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, settings_save_1.default)(config, integrationLogic));
141
144
  app.post('/api/login', (0, crowdin_client_1.default)(config, false, false), (0, integration_login_1.default)(config, integrationLogic));
142
145
  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));
143
146
  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));
144
- app.get('/api/crowdin/project', json_response_1.default, (0, crowdin_client_1.default)(config), (0, crowdin_project_1.default)(config));
145
- app.get('/api/crowdin/file-progress/:fileId', (0, crowdin_client_1.default)(config), (0, crowdin_file_progress_1.default)(config, integrationLogic));
146
- app.get('/api/integration/data', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, integration_data_1.default)(config, integrationLogic));
147
+ app.get('/api/crowdin/project', json_response_1.default, (0, crowdin_client_1.default)(config), (0, crowdin_project_1.default)());
148
+ app.get('/api/crowdin/file-progress/:fileId', (0, crowdin_client_1.default)(config), (0, crowdin_file_progress_1.default)(integrationLogic));
149
+ app.get('/api/integration/data', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, integration_data_1.default)(integrationLogic));
147
150
  app.post('/api/crowdin/update', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, crowdin_update_1.default)(config, integrationLogic));
148
151
  app.post('/api/integration/update', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, integration_update_1.default)(config, integrationLogic));
149
- app.get('/api/sync-settings/:provider', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, sync_settings_1.default)(config));
152
+ app.get('/api/sync-settings/:provider', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, sync_settings_1.default)());
150
153
  app.post('/api/sync-settings', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, sync_settings_save_1.default)(config, integrationLogic));
151
- app.get('/api/synced-files', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, synced_files_1.default)(config));
154
+ app.get('/api/synced-files', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, synced_files_1.default)());
152
155
  if (integrationLogic.oauthLogin) {
153
156
  app.get((0, defaults_1.getOauthRoute)(integrationLogic), (0, oauth_login_1.default)(config, integrationLogic));
154
157
  app.post('/api/oauth-url', json_response_1.default, (0, crowdin_client_1.default)(config, false, false), (0, oauth_url_1.default)(config, integrationLogic));
@@ -180,7 +183,7 @@ function addCrowdinEndpoints(app, clientConfig) {
180
183
  }
181
184
  }
182
185
  if (config.customFileFormat) {
183
- app.post('/process', (0, crowdin_client_1.default)(config), (0, custom_file_format_1.default)(config, config.baseUrl, config.customFileFormat.filesFolder || config.dbFolder, config.customFileFormat));
186
+ app.post('/process', (0, crowdin_client_1.default)(config), (0, custom_file_format_1.default)(config.baseUrl, config.customFileFormat.filesFolder || config.dbFolder, config.customFileFormat));
184
187
  app.get('/file/download', (0, file_download_1.default)(config, config.customFileFormat, 'custom-file-format'));
185
188
  }
186
189
  if (config.filePreImport) {
@@ -200,39 +203,39 @@ function addCrowdinEndpoints(app, clientConfig) {
200
203
  app.get(`/file/download/${models_1.ProcessFileJobType.POST_EXPORT}`, (0, file_download_1.default)(config, config.filePostExport, models_1.ProcessFileJobType.POST_EXPORT));
201
204
  }
202
205
  if (config.customMT) {
203
- app.get((0, util_1.getLogoUrl)(config, config.customMT, '/mt'), (req, res) => { var _a; return res.sendFile(((_a = config.customMT) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
204
- app.post('/translate', (0, crowdin_client_1.default)(config), (0, translate_1.default)(config, config.customMT));
206
+ app.get((0, util_1.getLogoUrl)(config.customMT, '/mt'), (req, res) => { var _a; return res.sendFile(((_a = config.customMT) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
207
+ app.post('/translate', (0, crowdin_client_1.default)(config), (0, translate_1.default)(config.customMT));
205
208
  }
206
209
  if (config.profileResourcesMenu) {
207
- app.get((0, util_1.getLogoUrl)(config, config.profileResourcesMenu, '/resources'), (req, res) => { var _a; return res.sendFile(((_a = config.profileResourcesMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
208
- app.use('/resources', (0, ui_module_1.default)(config, config.profileResourcesMenu.allowUnauthorized), (0, render_ui_module_1.default)(config, config.profileResourcesMenu));
210
+ app.get((0, util_1.getLogoUrl)(config.profileResourcesMenu, '/resources'), (req, res) => { var _a; return res.sendFile(((_a = config.profileResourcesMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
211
+ app.use('/resources', (0, ui_module_1.default)(config, config.profileResourcesMenu.allowUnauthorized), (0, render_ui_module_1.default)(config.profileResourcesMenu));
209
212
  }
210
213
  if (config.organizationMenu) {
211
- app.get((0, util_1.getLogoUrl)(config, config.organizationMenu, '/resources'), (req, res) => { var _a; return res.sendFile(((_a = config.organizationMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
212
- app.use('/resources', (0, ui_module_1.default)(config, config.organizationMenu.allowUnauthorized), (0, render_ui_module_1.default)(config, config.organizationMenu));
214
+ app.get((0, util_1.getLogoUrl)(config.organizationMenu, '/resources'), (req, res) => { var _a; return res.sendFile(((_a = config.organizationMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
215
+ app.use('/resources', (0, ui_module_1.default)(config, config.organizationMenu.allowUnauthorized), (0, render_ui_module_1.default)(config.organizationMenu));
213
216
  }
214
217
  if (config.editorRightPanel) {
215
- app.use('/editor-panels', (0, ui_module_1.default)(config, config.editorRightPanel.allowUnauthorized), (0, render_ui_module_1.default)(config, config.editorRightPanel));
218
+ app.use('/editor-panels', (0, ui_module_1.default)(config, config.editorRightPanel.allowUnauthorized), (0, render_ui_module_1.default)(config.editorRightPanel));
216
219
  }
217
220
  if (config.projectMenu) {
218
- app.use('/project-menu', (0, ui_module_1.default)(config, config.projectMenu.allowUnauthorized), (0, render_ui_module_1.default)(config, config.projectMenu));
221
+ app.use('/project-menu', (0, ui_module_1.default)(config, config.projectMenu.allowUnauthorized), (0, render_ui_module_1.default)(config.projectMenu));
219
222
  }
220
223
  if (config.projectMenuCrowdsource) {
221
- app.use('/project-menu-crowdsource', (0, ui_module_1.default)(config, config.projectMenuCrowdsource.allowUnauthorized), (0, render_ui_module_1.default)(config, config.projectMenuCrowdsource));
224
+ app.use('/project-menu-crowdsource', (0, ui_module_1.default)(config, config.projectMenuCrowdsource.allowUnauthorized), (0, render_ui_module_1.default)(config.projectMenuCrowdsource));
222
225
  }
223
226
  if (config.projectTools) {
224
- app.get((0, util_1.getLogoUrl)(config, config.projectTools, '/tools'), (req, res) => { var _a; return res.sendFile(((_a = config.projectTools) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
225
- app.use('/tools', (0, ui_module_1.default)(config, config.projectTools.allowUnauthorized), (0, render_ui_module_1.default)(config, config.projectTools));
227
+ app.get((0, util_1.getLogoUrl)(config.projectTools, '/tools'), (req, res) => { var _a; return res.sendFile(((_a = config.projectTools) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
228
+ app.use('/tools', (0, ui_module_1.default)(config, config.projectTools.allowUnauthorized), (0, render_ui_module_1.default)(config.projectTools));
226
229
  }
227
230
  if (config.projectReports) {
228
- app.get((0, util_1.getLogoUrl)(config, config.projectReports, '/reports'), (req, res) => { var _a; return res.sendFile(((_a = config.projectReports) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
229
- app.use('/reports', (0, ui_module_1.default)(config, config.projectReports.allowUnauthorized), (0, render_ui_module_1.default)(config, config.projectReports));
231
+ app.get((0, util_1.getLogoUrl)(config.projectReports, '/reports'), (req, res) => { var _a; return res.sendFile(((_a = config.projectReports) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
232
+ app.use('/reports', (0, ui_module_1.default)(config, config.projectReports.allowUnauthorized), (0, render_ui_module_1.default)(config.projectReports));
230
233
  }
231
234
  if (((_d = config.modal) === null || _d === void 0 ? void 0 : _d.uiPath) || ((_e = config.modal) === null || _e === void 0 ? void 0 : _e.formSchema)) {
232
- app.use('/modal', (0, ui_module_1.default)(config, config.modal.allowUnauthorized), (0, render_ui_module_1.default)(config, config.modal));
235
+ app.use('/modal', (0, ui_module_1.default)(config, config.modal.allowUnauthorized), (0, render_ui_module_1.default)(config.modal));
233
236
  }
234
237
  if (((_f = config.contextMenu) === null || _f === void 0 ? void 0 : _f.uiPath) || ((_g = config.contextMenu) === null || _g === void 0 ? void 0 : _g.formSchema)) {
235
- app.use('/context', (0, ui_module_1.default)(config, config.contextMenu.allowUnauthorized), (0, render_ui_module_1.default)(config, config.contextMenu));
238
+ app.use('/context', (0, ui_module_1.default)(config, config.contextMenu.allowUnauthorized), (0, render_ui_module_1.default)(config.contextMenu));
236
239
  }
237
240
  if (config.api) {
238
241
  if (config.api.default) {
@@ -278,11 +281,11 @@ function addCrowdinEndpoints(app, clientConfig) {
278
281
  encryptCrowdinConnection: (data) => (0, util_1.encryptData)(config, JSON.stringify(data)),
279
282
  dencryptCrowdinConnection: (hash) => __awaiter(this, void 0, void 0, function* () {
280
283
  const { crowdinId, extra } = JSON.parse((0, util_1.decryptData)(config, hash));
281
- const creds = yield storage.getStorage().getCrowdinCredentials(crowdinId);
282
- if (!creds) {
284
+ const credentials = yield storage.getStorage().getCrowdinCredentials(crowdinId);
285
+ if (!credentials) {
283
286
  throw new Error('Failed to find Crowdin credentials');
284
287
  }
285
- const { client } = yield (0, connection_1.prepareCrowdinClient)(config, creds);
288
+ const { client } = yield (0, connection_1.prepareCrowdinClient)({ config, credentials });
286
289
  return { client, extra };
287
290
  }),
288
291
  };
@@ -296,14 +299,14 @@ function createApp(clientConfig) {
296
299
  app.listen(config.port, () => console.log(`App started on port ${config.port}`));
297
300
  }
298
301
  exports.createApp = createApp;
299
- function handleUncaughtErrors(config) {
302
+ function handleUncaughtErrors() {
300
303
  process
301
304
  .on('unhandledRejection', (reason) => {
302
305
  const error = `Unhandled Rejection. Reason: ${reason.stack || reason}`;
303
- (0, util_1.logError)(error, config.onError);
306
+ (0, logger_1.logError)(error);
304
307
  })
305
308
  .on('uncaughtException', (reason) => {
306
309
  const error = `Uncaught Exception. Reason: ${reason.stack || reason}`;
307
- (0, util_1.logError)(error, config.onError);
310
+ (0, logger_1.logError)(error);
308
311
  });
309
312
  }
@@ -2,10 +2,13 @@
2
2
  import Crowdin from '@crowdin/crowdin-api-client';
3
3
  import { Response } from 'express';
4
4
  import { Config, CrowdinClientRequest, CrowdinContextInfo, SubscriptionInfo } from '../models';
5
+ import { LogErrorFunction, LogFunction } from '../util/logger';
5
6
  export declare function prepareCrowdinRequest(jwtToken: string, config: Config, optional?: boolean, checkSubscriptionExpiration?: boolean): Promise<{
6
7
  context: CrowdinContextInfo;
8
+ logInfo: LogFunction;
9
+ logError: LogErrorFunction;
7
10
  client?: Crowdin;
8
11
  subscriptionInfo?: SubscriptionInfo;
9
12
  }>;
10
- export default function handle(config: Config, optional?: boolean, checkSubscriptionExpiration?: boolean): (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;
13
+ export default function handle(config: Config, optional?: boolean, checkSubscriptionExpiration?: boolean): (req: CrowdinClientRequest | 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;
11
14
  export declare function getToken(req: CrowdinClientRequest): string | undefined;
@@ -13,35 +13,48 @@ exports.getToken = exports.prepareCrowdinRequest = void 0;
13
13
  const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
14
14
  const storage_1 = require("../storage");
15
15
  const util_1 = require("../util");
16
- const connection_1 = require("../util/connection");
17
16
  const api_1 = require("../util/api/api");
17
+ const connection_1 = require("../util/connection");
18
+ const logger_1 = require("../util/logger");
18
19
  function prepareCrowdinRequest(jwtToken, config, optional = false, checkSubscriptionExpiration = true) {
19
20
  return __awaiter(this, void 0, void 0, function* () {
20
- (0, util_1.log)('Validating jwt token from incoming request', config.logger);
21
+ (0, logger_1.log)('Validating jwt token from incoming request');
21
22
  const jwtPayload = yield (0, crowdin_apps_functions_1.validateJwtToken)(jwtToken, config.clientSecret, config.jwtValidationOptions);
22
23
  const context = {
23
24
  jwtPayload,
24
25
  clientId: (0, crowdin_apps_functions_1.constructCrowdinIdFromJwtPayload)(jwtPayload),
25
26
  crowdinId: `${jwtPayload.domain || jwtPayload.context.organization_id}`,
26
27
  };
27
- (0, util_1.log)('Loading crowdin credentials', config.logger);
28
+ const logContext = {
29
+ orgId: context.crowdinId,
30
+ userId: context.clientId,
31
+ projectId: jwtPayload.context.project_id,
32
+ };
33
+ const logInfo = (0, logger_1.withContext)(logContext);
34
+ const logError = (0, logger_1.withContextError)(logContext);
35
+ logInfo('Loading crowdin credentials');
28
36
  const credentials = yield (0, storage_1.getStorage)().getCrowdinCredentials(context.crowdinId);
29
37
  if (!credentials) {
30
38
  if (optional) {
31
- return { context };
39
+ return { context, logInfo, logError };
32
40
  }
33
41
  throw new Error("Can't find organization by id");
34
42
  }
35
- (0, util_1.log)('Building crowdin client instance', config.logger);
36
- const { client, token } = yield (0, connection_1.prepareCrowdinClient)(config, credentials);
43
+ logInfo('Building crowdin client instance');
44
+ const { client, token } = yield (0, connection_1.prepareCrowdinClient)({ config, credentials });
37
45
  let subscriptionInfo;
38
46
  if (checkSubscriptionExpiration) {
39
- subscriptionInfo = yield (0, connection_1.checkSubscription)(config, token, credentials.id, credentials.type);
47
+ subscriptionInfo = yield (0, connection_1.checkSubscription)({
48
+ config,
49
+ token,
50
+ organization: credentials.id,
51
+ accountType: credentials.type,
52
+ });
40
53
  if (subscriptionInfo.expired) {
41
54
  throw new util_1.CodeError(subscriptionInfo.subscribeLink || '', 402);
42
55
  }
43
56
  }
44
- return { context, client, subscriptionInfo };
57
+ return { context, client, subscriptionInfo, logInfo, logError };
45
58
  });
46
59
  }
47
60
  exports.prepareCrowdinRequest = prepareCrowdinRequest;
@@ -62,22 +75,19 @@ function handle(config, optional = false, checkSubscriptionExpiration = true) {
62
75
  req.crowdinApiClient = data.client;
63
76
  }
64
77
  req.subscriptionInfo = data.subscriptionInfo;
78
+ req.logInfo = data.logInfo;
79
+ req.logError = data.logError;
65
80
  next();
66
81
  }
67
82
  catch (e) {
83
+ (0, logger_1.logError)(e);
68
84
  if (e instanceof util_1.CodeError) {
69
85
  throw e;
70
86
  }
71
- if (config.onError) {
72
- config.onError(e);
73
- }
74
- else {
75
- console.error(e);
76
- }
77
- const message = typeof e === 'string' ? e : e.message;
87
+ const message = (0, logger_1.getErrorMessage)(e);
78
88
  return res.status(403).send({ error: message || 'Error' });
79
89
  }
80
- }), config.onError);
90
+ }));
81
91
  }
82
92
  exports.default = handle;
83
93
  function getToken(req) {
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
3
  import { Config, IntegrationLogic } from '../models';
4
- export default function handle(config: Config, integration: IntegrationLogic, optional?: boolean): (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;
4
+ export default function handle(config: Config, integration: IntegrationLogic, optional?: boolean): (req: import("../models").CrowdinClientRequest | 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;
@@ -15,7 +15,7 @@ const connection_1 = require("../util/connection");
15
15
  function handle(config, integration, optional = false) {
16
16
  return (0, util_1.runAsyncWrapper)((req, res, next) => __awaiter(this, void 0, void 0, function* () {
17
17
  const clientId = req.crowdinContext.clientId;
18
- (0, util_1.log)(`Loading integration credentials for client ${clientId}`, config.logger);
18
+ req.logInfo(`Loading integration credentials for client ${clientId}`);
19
19
  const integrationCredentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(clientId);
20
20
  if (!integrationCredentials) {
21
21
  if (optional) {
@@ -34,6 +34,6 @@ function handle(config, integration, optional = false) {
34
34
  throw new util_1.CodeError('Credentials to integration either exprired or invalid', 401);
35
35
  }
36
36
  next();
37
- }), config.onError);
37
+ }));
38
38
  }
39
39
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import express from 'express';
3
- import { Config, UiModule } from '../models';
4
- export default function handle(config: Config, moduleConfig: UiModule): (req: express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: Function) => void;
3
+ import { UiModule } from '../models';
4
+ export default function handle(moduleConfig: UiModule): (req: import("../models").CrowdinClientRequest | express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: Function) => void;