@crowdin/app-project-module 0.30.3 → 0.32.0

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 (82) 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 +11 -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 +9 -18
  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 +37 -32
  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 +27 -2
  65. package/out/models/index.js +13 -1
  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/defaults.js +2 -1
  72. package/out/util/file-snapshot.d.ts +1 -1
  73. package/out/util/file-snapshot.js +4 -4
  74. package/out/util/index.d.ts +3 -6
  75. package/out/util/index.js +12 -42
  76. package/out/util/logger.d.ts +14 -0
  77. package/out/util/logger.js +71 -0
  78. package/out/util/synced-files.js +4 -4
  79. package/out/util/webhooks.d.ts +1 -1
  80. package/out/util/webhooks.js +6 -6
  81. package/out/views/partials/head.handlebars +28 -1
  82. 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
  ];
@@ -194,19 +194,10 @@ function handle(config) {
194
194
  events['subscription_paid'] = '/subscription-paid';
195
195
  }
196
196
  return (_req, res) => {
197
- const manifest = {
198
- identifier: config.identifier,
199
- name: config.name,
200
- logo: (0, util_1.getLogoUrl)(config),
201
- baseUrl: config.baseUrl,
202
- authentication: {
197
+ const manifest = Object.assign(Object.assign({ identifier: config.identifier, name: config.name, logo: (0, util_1.getLogoUrl)(config), baseUrl: config.baseUrl, authentication: {
203
198
  type: config.authenticationType || models_1.AuthenticationType.APP,
204
199
  clientId: config.clientId,
205
- },
206
- events,
207
- scopes: config.scopes ? config.scopes : [models_1.Scope.PROJECTS],
208
- modules,
209
- };
200
+ }, events, scopes: config.scopes ? config.scopes : [models_1.Scope.PROJECTS] }, (config.defaultPermissions && { default_permissions: config.defaultPermissions })), { modules });
210
201
  res.send(manifest);
211
202
  };
212
203
  }
@@ -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 } 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.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,18 +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; } });
90
+ Object.defineProperty(exports, "UserPermissions", { enumerable: true, get: function () { return models_2.UserPermissions; } });
87
91
  function addCrowdinEndpoints(app, clientConfig) {
88
92
  var _a, _b, _c, _d, _e, _f, _g;
89
93
  const config = (0, defaults_1.convertClientConfig)(clientConfig);
90
94
  if (!config.disableGlobalErrorHandling) {
91
- handleUncaughtErrors(config);
95
+ handleUncaughtErrors();
92
96
  }
93
97
  storage.initialize(config);
98
+ logger.initialize(config);
94
99
  app.use(terminus_express_1.default.json({ limit: '50mb' }));
95
100
  app.use('/assets', terminus_express_1.default.static((0, path_1.join)(__dirname, 'static')));
96
101
  app.set('views', (0, path_1.join)(__dirname, 'views'));
@@ -122,31 +127,31 @@ function addCrowdinEndpoints(app, clientConfig) {
122
127
  },
123
128
  }));
124
129
  app.set('view engine', 'handlebars');
125
- 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));
126
131
  app.post('/installed', (0, install_1.default)(config));
127
132
  app.post('/uninstall', (0, uninstall_1.default)(config));
128
133
  app.get('/manifest.json', json_response_1.default, (0, manifest_1.default)(config));
129
134
  if (!(0, connection_1.isAppFree)(config)) {
130
- app.post('/subscription-paid', (0, subscription_paid_1.default)(config));
135
+ app.post('/subscription-paid', (0, subscription_paid_1.default)());
131
136
  }
132
137
  const integrationLogic = config.projectIntegration;
133
138
  if (integrationLogic) {
134
139
  (0, defaults_1.applyIntegrationModuleDefaults)(config, integrationLogic);
135
- 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));
136
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));
137
142
  app.get('/api/subscription-info', json_response_1.default, (0, crowdin_client_1.default)(config), (0, subscription_info_1.default)(config));
138
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));
139
144
  app.post('/api/login', (0, crowdin_client_1.default)(config, false, false), (0, integration_login_1.default)(config, integrationLogic));
140
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));
141
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));
142
- app.get('/api/crowdin/project', json_response_1.default, (0, crowdin_client_1.default)(config), (0, crowdin_project_1.default)(config));
143
- app.get('/api/crowdin/file-progress/:fileId', (0, crowdin_client_1.default)(config), (0, crowdin_file_progress_1.default)(config, integrationLogic));
144
- 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));
145
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));
146
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));
147
- 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)());
148
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));
149
- 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)());
150
155
  if (integrationLogic.oauthLogin) {
151
156
  app.get((0, defaults_1.getOauthRoute)(integrationLogic), (0, oauth_login_1.default)(config, integrationLogic));
152
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));
@@ -178,7 +183,7 @@ function addCrowdinEndpoints(app, clientConfig) {
178
183
  }
179
184
  }
180
185
  if (config.customFileFormat) {
181
- 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));
182
187
  app.get('/file/download', (0, file_download_1.default)(config, config.customFileFormat, 'custom-file-format'));
183
188
  }
184
189
  if (config.filePreImport) {
@@ -198,39 +203,39 @@ function addCrowdinEndpoints(app, clientConfig) {
198
203
  app.get(`/file/download/${models_1.ProcessFileJobType.POST_EXPORT}`, (0, file_download_1.default)(config, config.filePostExport, models_1.ProcessFileJobType.POST_EXPORT));
199
204
  }
200
205
  if (config.customMT) {
201
- 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); });
202
- 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));
203
208
  }
204
209
  if (config.profileResourcesMenu) {
205
- 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); });
206
- 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));
207
212
  }
208
213
  if (config.organizationMenu) {
209
- 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); });
210
- 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));
211
216
  }
212
217
  if (config.editorRightPanel) {
213
- 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));
214
219
  }
215
220
  if (config.projectMenu) {
216
- 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));
217
222
  }
218
223
  if (config.projectMenuCrowdsource) {
219
- 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));
220
225
  }
221
226
  if (config.projectTools) {
222
- 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); });
223
- 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));
224
229
  }
225
230
  if (config.projectReports) {
226
- 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); });
227
- 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));
228
233
  }
229
234
  if (((_d = config.modal) === null || _d === void 0 ? void 0 : _d.uiPath) || ((_e = config.modal) === null || _e === void 0 ? void 0 : _e.formSchema)) {
230
- 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));
231
236
  }
232
237
  if (((_f = config.contextMenu) === null || _f === void 0 ? void 0 : _f.uiPath) || ((_g = config.contextMenu) === null || _g === void 0 ? void 0 : _g.formSchema)) {
233
- 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));
234
239
  }
235
240
  if (config.api) {
236
241
  if (config.api.default) {
@@ -276,11 +281,11 @@ function addCrowdinEndpoints(app, clientConfig) {
276
281
  encryptCrowdinConnection: (data) => (0, util_1.encryptData)(config, JSON.stringify(data)),
277
282
  dencryptCrowdinConnection: (hash) => __awaiter(this, void 0, void 0, function* () {
278
283
  const { crowdinId, extra } = JSON.parse((0, util_1.decryptData)(config, hash));
279
- const creds = yield storage.getStorage().getCrowdinCredentials(crowdinId);
280
- if (!creds) {
284
+ const credentials = yield storage.getStorage().getCrowdinCredentials(crowdinId);
285
+ if (!credentials) {
281
286
  throw new Error('Failed to find Crowdin credentials');
282
287
  }
283
- const { client } = yield (0, connection_1.prepareCrowdinClient)(config, creds);
288
+ const { client } = yield (0, connection_1.prepareCrowdinClient)({ config, credentials });
284
289
  return { client, extra };
285
290
  }),
286
291
  };
@@ -294,14 +299,14 @@ function createApp(clientConfig) {
294
299
  app.listen(config.port, () => console.log(`App started on port ${config.port}`));
295
300
  }
296
301
  exports.createApp = createApp;
297
- function handleUncaughtErrors(config) {
302
+ function handleUncaughtErrors() {
298
303
  process
299
304
  .on('unhandledRejection', (reason) => {
300
305
  const error = `Unhandled Rejection. Reason: ${reason.stack || reason}`;
301
- (0, util_1.logError)(error, config.onError);
306
+ (0, logger_1.logError)(error);
302
307
  })
303
308
  .on('uncaughtException', (reason) => {
304
309
  const error = `Uncaught Exception. Reason: ${reason.stack || reason}`;
305
- (0, util_1.logError)(error, config.onError);
310
+ (0, logger_1.logError)(error);
306
311
  });
307
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;