@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
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config, CustomMTLogic } from '../../models';
4
- export default function handle(baseConfig: Config, config: CustomMTLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
3
+ import { CrowdinClientRequest, CustomMTLogic } from '../../models';
4
+ export default function handle(config: CustomMTLogic): (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;
@@ -10,14 +10,15 @@ 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(baseConfig, config) {
13
+ const logger_1 = require("../../util/logger");
14
+ function handle(config) {
14
15
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
15
16
  const source = req.query.source;
16
17
  const target = req.query.target;
17
18
  const body = req.body;
18
- (0, util_1.log)('Received request for custom mt', baseConfig.logger);
19
- (0, util_1.log)(`Source language ${source}, target language ${target}`, baseConfig.logger);
20
- (0, util_1.log)(`Payload ${JSON.stringify(body, null, 2)}`, baseConfig.logger);
19
+ (0, logger_1.log)('Received request for custom mt');
20
+ (0, logger_1.log)(`Source language ${source}, target language ${target}`);
21
+ (0, logger_1.log)(`Payload ${JSON.stringify(body, null, 2)}`);
21
22
  const projectId = Number(req.query.project_id);
22
23
  try {
23
24
  if (source === 'en' && target === 'de' && body.strings && body.strings[0] === 'validation') {
@@ -32,11 +33,12 @@ function handle(baseConfig, config) {
32
33
  }
33
34
  }
34
35
  catch (e) {
35
- const message = (0, util_1.getMessage)(e);
36
+ req.logError(e);
37
+ const message = (0, logger_1.getErrorMessage)(e);
36
38
  res.send({
37
39
  error: { message },
38
40
  });
39
41
  }
40
- }), baseConfig.onError);
42
+ }));
41
43
  }
42
44
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config, CustomFileFormatLogic } from '../../models';
4
- export default function handle(baseConfig: Config, baseUrl: string, folder: string, config: CustomFileFormatLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
3
+ import { CrowdinClientRequest, CustomFileFormatLogic } from '../../models';
4
+ export default function handle(baseUrl: string, folder: string, config: CustomFileFormatLogic): (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;
@@ -17,7 +17,7 @@ const path_1 = __importDefault(require("path"));
17
17
  const models_1 = require("../../models");
18
18
  const util_1 = require("../../util");
19
19
  const files_1 = require("../../util/files");
20
- function handle(baseConfig, baseUrl, folder, config) {
20
+ function handle(baseUrl, folder, config) {
21
21
  if (!fs_1.default.existsSync(path_1.default.join(folder, 'custom-file-format'))) {
22
22
  fs_1.default.mkdirSync(path_1.default.join(folder, 'custom-file-format'), { recursive: true });
23
23
  }
@@ -31,7 +31,7 @@ function handle(baseConfig, baseUrl, folder, config) {
31
31
  else {
32
32
  logData = body;
33
33
  }
34
- (0, util_1.log)(`Received request to process file ${JSON.stringify(logData, null, 2)}`, baseConfig.logger);
34
+ req.logInfo(`Received request to process file ${JSON.stringify(logData, null, 2)}`);
35
35
  let file;
36
36
  if (body.file.content) {
37
37
  file = Buffer.from(body.file.content, 'base64').toString();
@@ -54,9 +54,9 @@ function handle(baseConfig, baseUrl, folder, config) {
54
54
  break;
55
55
  }
56
56
  const responseLength = Buffer.byteLength(JSON.stringify(response), 'utf8');
57
- (0, util_1.log)(`Returning response (${responseLength} bytes) from process file action`, baseConfig.logger);
57
+ req.logInfo(`Returning response (${responseLength} bytes) from process file action`);
58
58
  res.send({ data: response, error: error ? { message: error } : undefined });
59
- }), baseConfig.onError);
59
+ }));
60
60
  }
61
61
  exports.default = handle;
62
62
  function handleBuildFile(baseUrl, dataFolder, config, req, client, context, projectId, file) {
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Request, Response } from 'express';
3
3
  import { Config, FileProcessLogic } from '../../models';
4
- export default function handle(config: Config, processingConfig: FileProcessLogic, folderName: string): (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, processingConfig: FileProcessLogic, folderName: string): (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;
@@ -15,11 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const fs_1 = __importDefault(require("fs"));
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const util_1 = require("../../util");
18
+ const logger_1 = require("../../util/logger");
18
19
  function handle(config, processingConfig, folderName) {
19
20
  const folder = processingConfig.filesFolder || config.dbFolder;
20
21
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
21
22
  const filePath = path_1.default.join(folder, folderName, req.query.file);
22
- (0, util_1.log)(`Downloading file ${filePath}`, config.logger);
23
+ (0, logger_1.log)(`Downloading file ${filePath}`);
23
24
  res.download(filePath, function (err) {
24
25
  if (err) {
25
26
  console.error(err);
@@ -28,6 +29,6 @@ function handle(config, processingConfig, folderName) {
28
29
  fs_1.default.unlinkSync(filePath);
29
30
  }
30
31
  });
31
- }), config.onError);
32
+ }));
32
33
  }
33
34
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config, FileImportExportLogic } from '../../models';
4
- export default function handle(baseConfig: Config, config: FileImportExportLogic, folderName: string): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
3
+ import { Config, CrowdinClientRequest, FileImportExportLogic } from '../../models';
4
+ export default function handle(baseConfig: Config, config: FileImportExportLogic, folderName: string): (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;
@@ -28,6 +28,7 @@ function handle(baseConfig, config, folderName) {
28
28
  const body = req.body;
29
29
  let processingError;
30
30
  let fileContent;
31
+ let rawContent;
31
32
  if (body.stringsUrl) {
32
33
  fileContent = yield (0, files_1.getFileContent)(body.stringsUrl, true);
33
34
  }
@@ -35,10 +36,17 @@ function handle(baseConfig, config, folderName) {
35
36
  fileContent = body.strings;
36
37
  }
37
38
  else if (body.file.contentUrl) {
38
- fileContent = yield (0, files_1.getFileContent)(body.file.contentUrl);
39
+ rawContent = yield (0, files_1.getFileContent)(body.file.contentUrl);
40
+ fileContent = Buffer.from(rawContent).toString('base64');
39
41
  }
40
42
  else if (body.file.content) {
41
- fileContent = Buffer.from(body.file.content, 'base64').toString();
43
+ rawContent = body.file.content;
44
+ fileContent = Buffer.from(rawContent, 'base64');
45
+ }
46
+ if (body.jobType === models_1.ProcessFileJobType.PRE_IMPORT || body.jobType === models_1.ProcessFileJobType.POST_EXPORT) {
47
+ body.getRawContent = (encoding) => __awaiter(this, void 0, void 0, function* () {
48
+ return Buffer.from(rawContent, 'base64').toString(encoding);
49
+ });
42
50
  }
43
51
  const fileProcessResult = yield config.fileProcess(body, fileContent, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id);
44
52
  switch (body.jobType) {
@@ -94,6 +102,6 @@ function handle(baseConfig, config, folderName) {
94
102
  break;
95
103
  }
96
104
  res.send({ data: response, error: processingError ? { message: processingError } : undefined });
97
- }), baseConfig.onError);
105
+ }));
98
106
  }
99
107
  exports.default = handle;
@@ -1,3 +1,3 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- export default function handle(): (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;
@@ -1,3 +1,3 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- export default function handle(): (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;
@@ -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;
@@ -13,9 +13,11 @@ const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
13
13
  const models_1 = require("../models");
14
14
  const storage_1 = require("../storage");
15
15
  const util_1 = require("../util");
16
+ const logger_1 = require("../util/logger");
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;
20
+ (0, logger_1.log)(`Received install request ${JSON.stringify(event, null, 2)}`);
19
21
  const token = yield fetchToken(config, event);
20
22
  const credentials = {
21
23
  id: (event.domain || event.organizationId).toString(),
@@ -32,14 +34,14 @@ function handle(config) {
32
34
  const existingCredentials = yield (0, storage_1.getStorage)().getCrowdinCredentials(credentials.id);
33
35
  if (!!existingCredentials) {
34
36
  yield (0, storage_1.getStorage)().updateCrowdinCredentials(credentials);
35
- (0, util_1.log)('An existing App has been reinstalled', config.logger);
37
+ (0, logger_1.log)('An existing App has been reinstalled');
36
38
  }
37
39
  else {
38
40
  yield (0, storage_1.getStorage)().saveCrowdinCredentials(credentials);
39
- (0, util_1.log)('A new App has been installed', config.logger);
41
+ (0, logger_1.log)('A new App has been installed');
40
42
  }
41
43
  res.status(204).end();
42
- }), config.onError);
44
+ }));
43
45
  }
44
46
  exports.default = handle;
45
47
  function fetchToken(config, event) {
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
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;
3
+ import { CrowdinClientRequest, IntegrationLogic } from '../../models';
4
+ export default function handle(integration: IntegrationLogic): (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;
@@ -10,18 +10,18 @@ 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, integration) {
13
+ function handle(integration) {
14
14
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
15
15
  const fileId = Number(req.params.fileId || req.body.fileId);
16
- (0, util_1.log)(`Loading translation progress for file ${fileId}`, config.logger);
16
+ req.logInfo(`Loading translation progress for file ${fileId}`);
17
17
  if (integration.getFileProgress) {
18
18
  const progress = yield integration.getFileProgress(req.crowdinContext.jwtPayload.context.project_id, req.crowdinApiClient, fileId);
19
- (0, util_1.log)(`Translation progress for file ${fileId} ${JSON.stringify(progress, null, 2)}`, config.logger);
19
+ req.logInfo(`Translation progress for file ${fileId} ${JSON.stringify(progress, null, 2)}`);
20
20
  res.send(progress);
21
21
  }
22
22
  else {
23
23
  res.send({});
24
24
  }
25
- }), config.onError);
25
+ }));
26
26
  }
27
27
  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;
@@ -13,19 +13,19 @@ 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)('Loading crowdin files', config.logger);
16
+ req.logInfo('Loading crowdin files');
17
17
  if (integration.getCrowdinFiles) {
18
18
  const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, req.crowdinApiClient, req.crowdinContext.jwtPayload.context.project_id);
19
- (0, util_1.log)(`Loading files ${rootFolder ? `from folder ${rootFolder.id}` : 'from root'}`, config.logger);
19
+ req.logInfo(`Loading files ${rootFolder ? `from folder ${rootFolder.id}` : 'from root'}`);
20
20
  const files = integration.getCrowdinFiles
21
21
  ? yield integration.getCrowdinFiles(req.crowdinContext.jwtPayload.context.project_id, req.crowdinApiClient, rootFolder, req.integrationSettings)
22
22
  : [];
23
- (0, util_1.log)(`Returning files ${JSON.stringify(files, null, 2)}`, config.logger);
23
+ req.logInfo(`Returning ${files.length} files`);
24
24
  res.send(files);
25
25
  }
26
26
  else {
27
27
  res.send([]);
28
28
  }
29
- }), config.onError);
29
+ }));
30
30
  }
31
31
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config } from '../../models';
4
- export default function handle(config: Config): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
3
+ import { CrowdinClientRequest } from '../../models';
4
+ export default function handle(): (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;
@@ -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
  const projectId = req.crowdinContext.jwtPayload.context.project_id;
16
- (0, util_1.log)(`Loading crowdin project ${projectId}`, config.logger);
16
+ req.logInfo(`Loading crowdin project ${projectId}`);
17
17
  const project = yield req.crowdinApiClient.projectsGroupsApi.getProject(projectId);
18
- (0, util_1.log)(`Loaded crowdin project ${JSON.stringify(project, null, 2)}`, config.logger);
18
+ req.logInfo(`Loaded crowdin project ${projectId}`);
19
19
  res.send(project.data);
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;
@@ -17,10 +17,10 @@ function handle(config, integration) {
17
17
  var _a, _b, _c;
18
18
  const projectId = req.crowdinContext.jwtPayload.context.project_id || (req === null || req === void 0 ? void 0 : req.body.projectId);
19
19
  const uploadTranslations = req.query.uploadTranslations === 'true' || ((_a = req.body) === null || _a === void 0 ? void 0 : _a.uploadTranslations);
20
- (0, util_1.log)(`Updating crowdin project ${projectId}`, config.logger);
20
+ req.logInfo(`Updating crowdin project ${projectId}`);
21
21
  const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, req.crowdinApiClient, projectId);
22
22
  if (rootFolder) {
23
- (0, util_1.log)(`Updating crowdin files under folder ${rootFolder.id}`, config.logger);
23
+ req.logInfo(`Updating crowdin files under folder ${rootFolder.id}`);
24
24
  }
25
25
  // A request via API has a different structure
26
26
  if (((_b = config.api) === null || _b === void 0 ? void 0 : _b.default) && req.body.files) {
@@ -38,8 +38,8 @@ function handle(config, integration) {
38
38
  if (!fileIds) {
39
39
  fileIds = req.body.map((file) => file.id);
40
40
  }
41
- (0, synced_files_1.createOrUpdateSyncedFiles)({ config, req, fileIds });
41
+ (0, synced_files_1.createOrUpdateSyncedFiles)({ req, fileIds });
42
42
  }
43
- }), config.onError);
43
+ }));
44
44
  }
45
45
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Request, Response } from 'express';
3
3
  import { Config, IntegrationLogic } from '../../models';
4
- export default function handle(config: Config, integration: IntegrationLogic): (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, integration: IntegrationLogic): (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;
@@ -48,6 +48,6 @@ function handle(config, integration) {
48
48
  }
49
49
  res.send({ message });
50
50
  }
51
- }), config.onError);
51
+ }));
52
52
  }
53
53
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
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;
3
+ import { IntegrationLogic } from '../../models';
4
+ export default function handle(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;
@@ -10,10 +10,10 @@ 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, integration) {
13
+ function handle(integration) {
14
14
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
15
15
  const { parent_id: parentId, search, page } = req.query;
16
- (0, util_1.log)('Recieved request to get integration data', config.logger);
16
+ req.logInfo('Recieved request to get integration data');
17
17
  const result = yield integration.getIntegrationFiles(req.integrationCredentials, req.integrationSettings, parentId, search, page);
18
18
  let message;
19
19
  let stopPagination;
@@ -26,8 +26,8 @@ function handle(config, integration) {
26
26
  else {
27
27
  files = result;
28
28
  }
29
- (0, util_1.log)(`Integration data response ${JSON.stringify(files, null, 2)}`, config.logger);
29
+ req.logInfo(`Integration data response ${JSON.stringify(files, null, 2)}`);
30
30
  res.send({ data: files, message, stopPagination });
31
- }), config.onError);
31
+ }));
32
32
  }
33
33
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
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;
3
+ import { Config, CrowdinClientRequest, IntegrationLogic } from '../../models';
4
+ export default function handle(config: Config, integration: IntegrationLogic): (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;
@@ -13,18 +13,18 @@ const storage_1 = require("../../storage");
13
13
  const util_1 = require("../../util");
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 integration login request', config.logger);
16
+ req.logInfo('Received integration login request');
17
17
  if (integration.checkConnection) {
18
- (0, util_1.log)('Checking the integration credentials', config.logger);
18
+ req.logInfo('Checking the integration credentials');
19
19
  yield integration.checkConnection(req.body.credentials);
20
20
  }
21
21
  const existing = yield (0, storage_1.getStorage)().getIntegrationCredentials(req.crowdinContext.clientId);
22
22
  if (!!existing) {
23
- (0, util_1.log)('Deleting old credentials', config.logger);
23
+ req.logInfo('Deleting old credentials');
24
24
  yield (0, storage_1.getStorage)().deleteIntegrationCredentials(req.crowdinContext.clientId);
25
25
  }
26
26
  yield (0, storage_1.getStorage)().saveIntegrationCredentials(req.crowdinContext.clientId, (0, util_1.encryptData)(config, JSON.stringify(req.body.credentials)), req.crowdinContext.crowdinId);
27
27
  res.status(204).end();
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;
@@ -15,18 +15,18 @@ const connection_1 = require("../../util/connection");
15
15
  const webhooks_1 = require("../../util/webhooks");
16
16
  function handle(config, integration) {
17
17
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
18
- (0, util_1.log)('Received integration logout request', config.logger);
18
+ req.logInfo('Received integration logout request');
19
19
  if (integration.onLogout) {
20
- (0, util_1.log)('Invoking onLogout hook', config.logger);
20
+ req.logInfo('Invoking onLogout hook');
21
21
  yield integration.onLogout(req.crowdinContext.jwtPayload.context.project_id, req.crowdinApiClient, req.integrationCredentials, req.integrationSettings);
22
22
  }
23
- (0, util_1.log)(`Deleting integration credentials for ${req.crowdinContext.clientId} client`, config.logger);
23
+ req.logInfo(`Deleting integration credentials for ${req.crowdinContext.clientId} client`);
24
24
  yield (0, storage_1.getStorage)().deleteIntegrationCredentials(req.crowdinContext.clientId);
25
25
  (0, connection_1.clearCache)(req.crowdinContext.crowdinId);
26
26
  if (integration.webhooks) {
27
27
  yield (0, webhooks_1.unregisterWebhooks)(config, integration, req.crowdinApiClient, req.crowdinContext, req.integrationCredentials, req.integrationSettings);
28
28
  }
29
29
  res.status(204).end();
30
- }), config.onError);
30
+ }));
31
31
  }
32
32
  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;
@@ -14,10 +14,10 @@ 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
16
  var _a;
17
- (0, util_1.log)('Updating integration data', config.logger);
17
+ req.logInfo('Updating integration data');
18
18
  const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, req.crowdinApiClient, req.crowdinContext.jwtPayload.context.project_id);
19
19
  if (rootFolder) {
20
- (0, util_1.log)(`Updating integration data for crowding root folder ${rootFolder.id}`, config.logger);
20
+ req.logInfo(`Updating integration data for crowding root folder ${rootFolder.id}`);
21
21
  }
22
22
  // A request via API has a different structure
23
23
  if (((_a = config.api) === null || _a === void 0 ? void 0 : _a.default) && req.body.files) {
@@ -29,6 +29,6 @@ function handle(config, integration) {
29
29
  message = result.message;
30
30
  }
31
31
  res.send({ message });
32
- }), config.onError);
32
+ }));
33
33
  }
34
34
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Request, Response } from 'express';
3
3
  import { Config, IntegrationLogic } from '../../models';
4
- export default function handle(config: Config, integration: IntegrationLogic): (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, integration: IntegrationLogic): (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;
@@ -35,6 +35,6 @@ function handle(config, integration) {
35
35
  else {
36
36
  return res.status(403).send({ error: 'Access denied' });
37
37
  }
38
- }), config.onError);
38
+ }));
39
39
  }
40
40
  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;
@@ -12,9 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const util_1 = require("../../util");
13
13
  const connection_1 = require("../../util/connection");
14
14
  const defaults_1 = require("../../util/defaults");
15
+ const logger_1 = require("../../util/logger");
15
16
  function handle(config, integration) {
16
17
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
17
18
  var _a;
19
+ const logger = req.logInfo || logger_1.log;
18
20
  const installed = !!req.crowdinApiClient;
19
21
  const loggedIn = !!req.integrationCredentials;
20
22
  const options = {
@@ -41,7 +43,7 @@ function handle(config, integration) {
41
43
  options.config = JSON.stringify(req.integrationSettings || {});
42
44
  options.reloadOnConfigSave = !!integration.reloadOnConfigSave;
43
45
  options.integrationPagination = integration.integrationPagination;
44
- (0, util_1.log)(`Adding configuration fields ${JSON.stringify(configurationFields, null, 2)}`, config.logger);
46
+ logger(`Adding configuration fields ${JSON.stringify(configurationFields, null, 2)}`);
45
47
  }
46
48
  options.infoModal = integration.infoModal;
47
49
  options.syncNewElements = integration.syncNewElements;
@@ -63,8 +65,8 @@ function handle(config, integration) {
63
65
  appIdentifier: config.identifier,
64
66
  }
65
67
  : null;
66
- (0, util_1.log)(`Routing user to ${view} view`, config.logger);
68
+ logger(`Routing user to ${view} view`);
67
69
  return res.render(view, options);
68
- }), config.onError);
70
+ }));
69
71
  }
70
72
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Request, Response } from 'express';
3
3
  import { Config, IntegrationLogic } from '../../models';
4
- export default function handle(config: Config, integration: IntegrationLogic): (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, integration: IntegrationLogic): (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;
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const axios_1 = __importDefault(require("axios"));
16
16
  const util_1 = require("../../util");
17
17
  const defaults_1 = require("../../util/defaults");
18
+ const logger_1 = require("../../util/logger");
18
19
  function handle(config, integration) {
19
20
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
20
21
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
@@ -22,12 +23,12 @@ function handle(config, integration) {
22
23
  uid: 'oauth_popup',
23
24
  };
24
25
  const code = req.query[((_b = (_a = integration.oauthLogin) === null || _a === void 0 ? void 0 : _a.fieldsMapping) === null || _b === void 0 ? void 0 : _b.code) || 'code'];
25
- (0, util_1.log)(`Received request from OAuth login callback. Code ${code}`, config.logger);
26
+ (0, logger_1.log)(`Received request from OAuth login callback. Code ${code}`);
26
27
  try {
27
28
  const oauthLogin = integration.oauthLogin;
28
29
  let credentials;
29
30
  if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.performGetTokenRequest) {
30
- (0, util_1.log)('Performing custom get bearer token request', config.logger);
31
+ (0, logger_1.log)('Performing custom get bearer token request');
31
32
  credentials = yield oauthLogin.performGetTokenRequest(code, req.query, req.originalUrl);
32
33
  }
33
34
  else {
@@ -55,15 +56,10 @@ function handle(config, integration) {
55
56
  return res.render('oauth', { message: JSON.stringify(message) });
56
57
  }
57
58
  catch (e) {
58
- if (config.onError) {
59
- config.onError(e);
60
- }
61
- else {
62
- console.error(e);
63
- }
64
- message.data = { error: (0, util_1.getMessage)(e) };
59
+ (0, logger_1.logError)(e);
60
+ message.data = { error: (0, logger_1.getErrorMessage)(e) };
65
61
  return res.render('oauth', { message: JSON.stringify(message) });
66
62
  }
67
- }), config.onError);
63
+ }));
68
64
  }
69
65
  exports.default = handle;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
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;
3
+ import { Config, CrowdinClientRequest, IntegrationLogic } from '../../models';
4
+ export default function handle(config: Config, integration: IntegrationLogic): (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;