@crowdin/app-project-module 0.28.0 → 0.28.2

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.
@@ -26,7 +26,7 @@ function handle(config, integration) {
26
26
  return res.status(200).send({ message: 'Sync is not configured' });
27
27
  }
28
28
  if ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.crowdinWebhookInterceptor) {
29
- filesToSync = yield integration.webhooks.crowdinWebhookInterceptor(projectId, crowdinClient.client, rootFolder, appSettings, syncSettings);
29
+ filesToSync = yield integration.webhooks.crowdinWebhookInterceptor(projectId, crowdinClient.client, rootFolder, appSettings, syncSettings, req.body);
30
30
  }
31
31
  else {
32
32
  filesToSync = (0, webhooks_1.filterSyncFiles)(req.body.events, JSON.parse(syncSettings.files));
@@ -12,12 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
15
  const fs_1 = __importDefault(require("fs"));
17
16
  const path_1 = __importDefault(require("path"));
18
17
  const models_1 = require("../../models");
19
18
  const util_1 = require("../../util");
20
- const MAX_BODY_SIZE = 4.9 * 1024 * 1024; //4.9mb
19
+ const files_1 = require("../../util/files");
21
20
  function handle(baseConfig, baseUrl, folder, config) {
22
21
  if (!fs_1.default.existsSync(path_1.default.join(folder, 'custom-file-format'))) {
23
22
  fs_1.default.mkdirSync(path_1.default.join(folder, 'custom-file-format'), { recursive: true });
@@ -38,7 +37,7 @@ function handle(baseConfig, baseUrl, folder, config) {
38
37
  file = Buffer.from(body.file.content, 'base64').toString();
39
38
  }
40
39
  else if (body.file.contentUrl) {
41
- file = (yield axios_1.default.get(body.file.contentUrl)).data;
40
+ file = yield (0, files_1.getFileContent)(body.file.contentUrl);
42
41
  }
43
42
  let response = {};
44
43
  let error;
@@ -71,10 +70,7 @@ function handleBuildFile(baseUrl, dataFolder, config, req, client, context, proj
71
70
  strings = req.strings;
72
71
  }
73
72
  else {
74
- // the response is presented in the ndjson format
75
- const response = (yield axios_1.default.get(req.stringsUrl)).data;
76
- const jsonRows = response.split(/\n|\n\r/).filter(Boolean);
77
- strings = jsonRows.map((jsonStringRow) => JSON.parse(jsonStringRow));
73
+ strings = yield (0, files_1.getFileContent)(req.stringsUrl, true);
78
74
  }
79
75
  let res;
80
76
  if ((req.file.id || !file) && config.exportStrings) {
@@ -87,7 +83,7 @@ function handleBuildFile(baseUrl, dataFolder, config, req, client, context, proj
87
83
  return { response };
88
84
  }
89
85
  const contentFileEncoded = Buffer.from(res.contentFile).toString('base64');
90
- if (Buffer.byteLength(contentFileEncoded, 'utf8') < MAX_BODY_SIZE) {
86
+ if (Buffer.byteLength(contentFileEncoded, 'utf8') < files_1.MAX_BODY_SIZE) {
91
87
  response.content = contentFileEncoded;
92
88
  }
93
89
  else {
@@ -96,7 +92,7 @@ function handleBuildFile(baseUrl, dataFolder, config, req, client, context, proj
96
92
  url = yield config.storeFile(res.contentFile);
97
93
  }
98
94
  else {
99
- const storedFile = yield storeFile(res.contentFile, dataFolder);
95
+ const storedFile = yield (0, files_1.storeFile)(res.contentFile, path_1.default.join(dataFolder, 'custom-file-format'));
100
96
  url = `${baseUrl}?file=${storedFile}`;
101
97
  }
102
98
  response.contentUrl = url;
@@ -111,7 +107,7 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
111
107
  return { response };
112
108
  }
113
109
  const res = yield config.parseFile(file, req, client, context, projectId);
114
- let maxSize = MAX_BODY_SIZE;
110
+ let maxSize = files_1.MAX_BODY_SIZE;
115
111
  if (res.strings && res.previewFile) {
116
112
  maxSize = maxSize / 2;
117
113
  }
@@ -126,7 +122,7 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
126
122
  url = yield config.storeFile(res.previewFile);
127
123
  }
128
124
  else {
129
- const storedFile = yield storeFile(res.previewFile, dataFolder);
125
+ const storedFile = yield (0, files_1.storeFile)(res.previewFile, path_1.default.join(dataFolder, 'custom-file-format'));
130
126
  url = `${baseUrl}?file=${storedFile}`;
131
127
  }
132
128
  response.previewUrl = url;
@@ -153,7 +149,7 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
153
149
  url = yield config.storeFile(stringsNDJson);
154
150
  }
155
151
  else {
156
- const storedFile = yield storeFile(stringsNDJson, dataFolder);
152
+ const storedFile = yield (0, files_1.storeFile)(stringsNDJson, path_1.default.join(dataFolder, 'custom-file-format'));
157
153
  url = `${baseUrl}?file=${storedFile}`;
158
154
  }
159
155
  response.stringsUrl = url;
@@ -162,14 +158,3 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
162
158
  return { response, error: res.error };
163
159
  });
164
160
  }
165
- function storeFile(fileContent, folder) {
166
- const fileName = `file${Date.now()}`;
167
- return new Promise((res, rej) => fs_1.default.writeFile(path_1.default.join(folder, 'custom-file-format', fileName), fileContent, (err) => {
168
- if (err) {
169
- rej(err);
170
- }
171
- else {
172
- res(fileName);
173
- }
174
- }));
175
- }
@@ -0,0 +1,4 @@
1
+ /// <reference types="qs" />
2
+ import { Request, Response } from 'express';
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;
@@ -15,9 +15,10 @@ 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
- function handle(config, folder) {
18
+ function handle(config, processingConfig, folderName) {
19
+ const folder = processingConfig.filesFolder || config.dbFolder;
19
20
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
20
- const filePath = path_1.default.join(folder, 'custom-file-format', req.query.file);
21
+ const filePath = path_1.default.join(folder, folderName, req.query.file);
21
22
  (0, util_1.log)(`Downloading file ${filePath}`, config.logger);
22
23
  res.download(filePath, function (err) {
23
24
  if (err) {
@@ -0,0 +1,4 @@
1
+ /// <reference types="qs" />
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;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const fs_1 = __importDefault(require("fs"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const models_1 = require("../../models");
18
+ const util_1 = require("../../util");
19
+ const files_1 = require("../../util/files");
20
+ function handle(baseConfig, config, folderName) {
21
+ const folderPath = config.filesFolder || baseConfig.dbFolder;
22
+ if (!fs_1.default.existsSync(path_1.default.join(folderPath, folderName))) {
23
+ fs_1.default.mkdirSync(path_1.default.join(folderPath, folderName), { recursive: true });
24
+ }
25
+ return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
26
+ const response = {};
27
+ const baseFilesUrl = `${baseConfig.baseUrl}/file/download/${folderName}`;
28
+ const body = req.body;
29
+ let processingError;
30
+ let fileContent;
31
+ if (body.stringsUrl) {
32
+ fileContent = yield (0, files_1.getFileContent)(body.stringsUrl, true);
33
+ }
34
+ else if (body.strings) {
35
+ fileContent = body.strings;
36
+ }
37
+ else if (body.file.contentUrl) {
38
+ fileContent = yield (0, files_1.getFileContent)(body.file.contentUrl);
39
+ }
40
+ else if (body.file.content) {
41
+ fileContent = Buffer.from(body.file.content, 'base64').toString();
42
+ }
43
+ const fileProcessResult = yield config.fileProcess(body, fileContent, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id);
44
+ switch (body.jobType) {
45
+ case models_1.ProcessFileJobType.PRE_IMPORT:
46
+ case models_1.ProcessFileJobType.POST_EXPORT:
47
+ const { contentFile, base64EncodedContent, fileName, fileType, error: contentFileError, } = fileProcessResult;
48
+ if (contentFile) {
49
+ const contentFileEncoded = base64EncodedContent || Buffer.from(contentFile).toString('base64');
50
+ if (Buffer.byteLength(contentFileEncoded, 'utf8') < files_1.MAX_BODY_SIZE) {
51
+ response.content = contentFileEncoded;
52
+ }
53
+ else {
54
+ let url;
55
+ if (config.storeFile) {
56
+ url = yield config.storeFile(contentFile);
57
+ }
58
+ else {
59
+ const storedFile = yield (0, files_1.storeFile)(contentFile, path_1.default.join(folderPath, folderName));
60
+ url = `${baseFilesUrl}?file=${storedFile}`;
61
+ }
62
+ response.contentUrl = url;
63
+ }
64
+ }
65
+ if (fileName) {
66
+ response.fileName = fileName;
67
+ }
68
+ if (fileType) {
69
+ response.fileType = fileType;
70
+ }
71
+ processingError = contentFileError;
72
+ break;
73
+ case models_1.ProcessFileJobType.POST_IMPORT:
74
+ case models_1.ProcessFileJobType.PRE_EXPORT:
75
+ const { strings, error: stringsFileError } = fileProcessResult;
76
+ if (strings) {
77
+ const stringsNDJson = strings.map((s) => JSON.stringify(s)).join('\n\r');
78
+ if (Buffer.byteLength(stringsNDJson, 'utf8') < files_1.MAX_BODY_SIZE) {
79
+ response.strings = strings;
80
+ }
81
+ else {
82
+ let url;
83
+ if (config.storeFile) {
84
+ url = yield config.storeFile(stringsNDJson);
85
+ }
86
+ else {
87
+ const storedFile = yield (0, files_1.storeFile)(stringsNDJson, path_1.default.join(folderPath, folderName));
88
+ url = `${baseFilesUrl}?file=${storedFile}`;
89
+ }
90
+ response.stringsUrl = url;
91
+ }
92
+ }
93
+ processingError = stringsFileError;
94
+ break;
95
+ }
96
+ res.send({ data: response, error: processingError ? { message: processingError } : undefined });
97
+ }), baseConfig.onError);
98
+ }
99
+ exports.default = handle;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -35,7 +39,7 @@ function handle() {
35
39
  const id = req.query.id;
36
40
  const data = (yield storage.getStorage().getMetadata(id)) || {};
37
41
  return res.send({
38
- data,
42
+ formData: data,
39
43
  });
40
44
  }));
41
45
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -31,6 +31,42 @@ function handle(config) {
31
31
  },
32
32
  ];
33
33
  }
34
+ if (config.filePreImport) {
35
+ modules['file-pre-import'] = [
36
+ {
37
+ key: config.identifier + '-pri',
38
+ signaturePatterns: config.filePreImport.signaturePatterns,
39
+ url: '/pre-import',
40
+ },
41
+ ];
42
+ }
43
+ if (config.filePostImport) {
44
+ modules['file-post-import'] = [
45
+ {
46
+ key: config.identifier + '-poi',
47
+ signaturePatterns: config.filePostImport.signaturePatterns,
48
+ url: '/post-import',
49
+ },
50
+ ];
51
+ }
52
+ if (config.filePreExport) {
53
+ modules['file-pre-export'] = [
54
+ {
55
+ key: config.identifier + '-pre',
56
+ signaturePatterns: config.filePreExport.signaturePatterns,
57
+ url: '/pre-export',
58
+ },
59
+ ];
60
+ }
61
+ if (config.filePostExport) {
62
+ modules['file-post-export'] = [
63
+ {
64
+ key: config.identifier + '-poe',
65
+ signaturePatterns: config.filePostExport.signaturePatterns,
66
+ url: '/post-export',
67
+ },
68
+ ];
69
+ }
34
70
  if (config.customMT) {
35
71
  modules['custom-mt'] = [
36
72
  {
@@ -116,6 +152,33 @@ function handle(config) {
116
152
  },
117
153
  ];
118
154
  }
155
+ if (config.modal) {
156
+ modules['modal'] = [
157
+ {
158
+ key: config.identifier + '-modal',
159
+ name: config.name,
160
+ url: config.modal.url || '/modal/' + (config.modal.fileName || 'index.html'),
161
+ environments: config.modal.environments,
162
+ },
163
+ ];
164
+ }
165
+ if (config.contextMenu) {
166
+ modules['context-menu'] = [
167
+ {
168
+ key: config.identifier + '-context-menu',
169
+ name: config.name,
170
+ description: config.description,
171
+ options: Object.assign(Object.assign({ location: config.contextMenu.location, type: config.contextMenu.type }, (config.contextMenu.module
172
+ ? {
173
+ module: {
174
+ [config.contextMenu.module]: modules[config.contextMenu.module][0].key,
175
+ },
176
+ }
177
+ : {})), { url: '/context/' + (config.contextMenu.fileName || 'index.html') }),
178
+ environments: config.contextMenu.environments,
179
+ },
180
+ ];
181
+ }
119
182
  const events = {
120
183
  installed: '/installed',
121
184
  uninstall: '/uninstall',
package/out/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Express } from 'express';
2
- import { Config, CrowdinAppUtilities } from './models';
2
+ import { ClientConfig, Config, CrowdinAppUtilities } from './models';
3
3
  export { Scope } from './models';
4
- export declare function addCrowdinEndpoints(app: Express, plainConfig: Config): CrowdinAppUtilities;
5
- export declare function createApp(config: Config): void;
4
+ export declare function addCrowdinEndpoints(app: Express, clientConfig: Config | ClientConfig): CrowdinAppUtilities;
5
+ export declare function createApp(clientConfig: ClientConfig): void;
package/out/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -41,22 +45,23 @@ const crowdin_files_1 = __importDefault(require("./handlers/crowdin-files"));
41
45
  const crowdin_project_1 = __importDefault(require("./handlers/crowdin-project"));
42
46
  const crowdin_update_1 = __importDefault(require("./handlers/crowdin-update"));
43
47
  const crowdin_webhook_1 = __importDefault(require("./handlers/crowdin-webhook"));
44
- const integration_webhook_1 = __importDefault(require("./handlers/integration-webhook"));
45
- const download_1 = __importDefault(require("./handlers/custom-file-format/download"));
46
- const process_1 = __importDefault(require("./handlers/custom-file-format/process"));
47
48
  const translate_1 = __importDefault(require("./handlers/custom-mt/translate"));
49
+ const custom_file_format_1 = __importDefault(require("./handlers/file-processing/custom-file-format"));
50
+ const file_download_1 = __importDefault(require("./handlers/file-processing/file-download"));
51
+ const pre_post_process_1 = __importDefault(require("./handlers/file-processing/pre-post-process"));
52
+ const form_data_display_1 = __importDefault(require("./handlers/form-data-display"));
53
+ const form_data_save_1 = __importDefault(require("./handlers/form-data-save"));
48
54
  const install_1 = __importDefault(require("./handlers/install"));
49
55
  const integration_data_1 = __importDefault(require("./handlers/integration-data"));
50
56
  const integration_login_1 = __importDefault(require("./handlers/integration-login"));
51
57
  const integration_logout_1 = __importDefault(require("./handlers/integration-logout"));
52
58
  const integration_update_1 = __importDefault(require("./handlers/integration-update"));
59
+ const integration_webhook_1 = __importDefault(require("./handlers/integration-webhook"));
53
60
  const main_1 = __importDefault(require("./handlers/main"));
54
61
  const manifest_1 = __importDefault(require("./handlers/manifest"));
55
62
  const oauth_login_1 = __importDefault(require("./handlers/oauth-login"));
56
63
  const oauth_url_1 = __importDefault(require("./handlers/oauth-url"));
57
64
  const settings_save_1 = __importDefault(require("./handlers/settings-save"));
58
- const form_data_display_1 = __importDefault(require("./handlers/form-data-display"));
59
- const form_data_save_1 = __importDefault(require("./handlers/form-data-save"));
60
65
  const subscription_info_1 = __importDefault(require("./handlers/subscription-info"));
61
66
  const subscription_paid_1 = __importDefault(require("./handlers/subscription-paid"));
62
67
  const sync_settings_1 = __importDefault(require("./handlers/sync-settings"));
@@ -65,22 +70,23 @@ const uninstall_1 = __importDefault(require("./handlers/uninstall"));
65
70
  const crowdin_client_1 = __importStar(require("./middlewares/crowdin-client"));
66
71
  const integration_credentials_1 = __importDefault(require("./middlewares/integration-credentials"));
67
72
  const json_response_1 = __importDefault(require("./middlewares/json-response"));
68
- const ui_module_1 = __importDefault(require("./middlewares/ui-module"));
69
73
  const render_ui_module_1 = __importDefault(require("./middlewares/render-ui-module"));
74
+ const ui_module_1 = __importDefault(require("./middlewares/ui-module"));
75
+ const models_1 = require("./models");
70
76
  const storage = __importStar(require("./storage"));
71
77
  const util_1 = require("./util");
72
78
  const connection_1 = require("./util/connection");
73
79
  const cron_1 = require("./util/cron");
74
80
  const defaults_1 = require("./util/defaults");
75
81
  const webhooks_1 = require("./util/webhooks");
76
- var models_1 = require("./models");
77
- Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return models_1.Scope; } });
78
- function addCrowdinEndpoints(app, plainConfig) {
79
- var _a, _b, _c;
80
- if (!plainConfig.disableGlobalErrorHandling) {
81
- handleUncaughtErrors(plainConfig);
82
- }
83
- const config = Object.assign(Object.assign({}, plainConfig), { baseUrl: plainConfig.baseUrl.endsWith('/') ? plainConfig.baseUrl.slice(0, -1) : plainConfig.baseUrl });
82
+ var models_2 = require("./models");
83
+ Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return models_2.Scope; } });
84
+ function addCrowdinEndpoints(app, clientConfig) {
85
+ var _a, _b, _c, _d, _e, _f, _g;
86
+ const config = (0, defaults_1.convertClientConfig)(clientConfig);
87
+ if (!config.disableGlobalErrorHandling) {
88
+ handleUncaughtErrors(config);
89
+ }
84
90
  storage.initialize(config);
85
91
  app.use(express_1.default.json({ limit: '50mb' }));
86
92
  app.use('/assets', express_1.default.static((0, path_1.join)(__dirname, 'static')));
@@ -113,7 +119,7 @@ function addCrowdinEndpoints(app, plainConfig) {
113
119
  },
114
120
  }));
115
121
  app.set('view engine', 'handlebars');
116
- app.get('/logo.png', (req, res) => res.sendFile(config.imagePath || (0, path_1.join)(__dirname, 'logo.png')));
122
+ app.get('/logo.png', (req, res) => res.sendFile(config.imagePath));
117
123
  app.post('/installed', (0, install_1.default)(config));
118
124
  app.post('/uninstall', (0, uninstall_1.default)(config));
119
125
  app.get('/manifest.json', json_response_1.default, (0, manifest_1.default)(config));
@@ -122,13 +128,11 @@ function addCrowdinEndpoints(app, plainConfig) {
122
128
  }
123
129
  const integrationLogic = config.projectIntegration;
124
130
  if (integrationLogic) {
125
- (0, defaults_1.applyDefaults)(config, integrationLogic);
126
- app.get('/logo/integration/logo.png', (req, res) => res.sendFile(integrationLogic.imagePath || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')));
131
+ (0, defaults_1.applyIntegrationModuleDefaults)(config, integrationLogic);
132
+ app.get('/logo/integration/logo.png', (req, res) => res.sendFile(integrationLogic.imagePath || config.imagePath));
127
133
  app.get('/', (0, crowdin_client_1.default)(config, true, false), (0, integration_credentials_1.default)(config, integrationLogic, true), (0, main_1.default)(config, integrationLogic));
128
134
  app.get('/api/subscription-info', json_response_1.default, (0, crowdin_client_1.default)(config), (0, subscription_info_1.default)(config));
129
135
  app.post('/api/settings', (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, settings_save_1.default)(config, integrationLogic));
130
- app.get('/api/form-data', json_response_1.default, (0, crowdin_client_1.default)(config), (0, form_data_display_1.default)());
131
- app.post('/api/form-data', (0, crowdin_client_1.default)(config), (0, form_data_save_1.default)());
132
136
  app.post('/api/login', (0, crowdin_client_1.default)(config, false, false), (0, integration_login_1.default)(config, integrationLogic));
133
137
  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));
134
138
  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));
@@ -165,24 +169,40 @@ function addCrowdinEndpoints(app, plainConfig) {
165
169
  : '/api/integration/webhook'}`, (0, integration_webhook_1.default)(config, integrationLogic));
166
170
  }
167
171
  if ((_c = integrationLogic.webhooks) === null || _c === void 0 ? void 0 : _c.queueUrl) {
168
- (0, webhooks_1.listenQueueMessage)(config, integrationLogic, integrationLogic.webhooks.queueUrl, config.name);
172
+ (0, webhooks_1.listenQueueMessage)(config, integrationLogic, integrationLogic.webhooks.queueUrl, config.identifier);
169
173
  }
170
174
  }
171
175
  }
172
176
  if (config.customFileFormat) {
173
- app.post('/process', (0, crowdin_client_1.default)(config), (0, process_1.default)(config, config.baseUrl, config.customFileFormat.filesFolder || config.dbFolder || '/', config.customFileFormat));
174
- app.get('/file/download', (0, download_1.default)(config, config.customFileFormat.filesFolder || config.dbFolder || '/'));
177
+ 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));
178
+ app.get('/file/download', (0, file_download_1.default)(config, config.customFileFormat, 'custom-file-format'));
179
+ }
180
+ if (config.filePreImport) {
181
+ app.post('/pre-import', (0, crowdin_client_1.default)(config), (0, pre_post_process_1.default)(config, config.filePreImport, models_1.ProcessFileJobType.PRE_IMPORT));
182
+ app.get(`/file/download/${models_1.ProcessFileJobType.PRE_IMPORT}`, (0, file_download_1.default)(config, config.filePreImport, models_1.ProcessFileJobType.PRE_IMPORT));
183
+ }
184
+ if (config.filePostImport) {
185
+ app.post('/post-import', (0, crowdin_client_1.default)(config), (0, pre_post_process_1.default)(config, config.filePostImport, models_1.ProcessFileJobType.POST_IMPORT));
186
+ app.get(`/file/download/${models_1.ProcessFileJobType.POST_IMPORT}`, (0, file_download_1.default)(config, config.filePostImport, models_1.ProcessFileJobType.POST_IMPORT));
187
+ }
188
+ if (config.filePreExport) {
189
+ app.post('/pre-export', (0, crowdin_client_1.default)(config), (0, pre_post_process_1.default)(config, config.filePreExport, models_1.ProcessFileJobType.PRE_EXPORT));
190
+ app.get(`/file/download/${models_1.ProcessFileJobType.PRE_EXPORT}`, (0, file_download_1.default)(config, config.filePreExport, models_1.ProcessFileJobType.PRE_EXPORT));
191
+ }
192
+ if (config.filePostExport) {
193
+ app.post('/post-export', (0, crowdin_client_1.default)(config), (0, pre_post_process_1.default)(config, config.filePostExport, models_1.ProcessFileJobType.POST_EXPORT));
194
+ app.get(`/file/download/${models_1.ProcessFileJobType.POST_EXPORT}`, (0, file_download_1.default)(config, config.filePostExport, models_1.ProcessFileJobType.POST_EXPORT));
175
195
  }
176
196
  if (config.customMT) {
177
- app.get('/logo/mt/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.customMT) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
197
+ app.get('/logo/mt/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.customMT) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
178
198
  app.post('/translate', (0, crowdin_client_1.default)(config), (0, translate_1.default)(config, config.customMT));
179
199
  }
180
200
  if (config.profileResourcesMenu) {
181
- app.get('/logo/resources/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.profileResourcesMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
201
+ app.get('/logo/resources/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.profileResourcesMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
182
202
  app.use('/resources', (0, ui_module_1.default)(config, config.profileResourcesMenu.allowUnauthorized), (0, render_ui_module_1.default)(config, config.profileResourcesMenu));
183
203
  }
184
204
  if (config.organizationMenu) {
185
- app.get('/logo/resources/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.organizationMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
205
+ app.get('/logo/resources/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.organizationMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
186
206
  app.use('/resources', (0, ui_module_1.default)(config, config.organizationMenu.allowUnauthorized), (0, render_ui_module_1.default)(config, config.organizationMenu));
187
207
  }
188
208
  if (config.editorRightPanel) {
@@ -195,13 +215,26 @@ function addCrowdinEndpoints(app, plainConfig) {
195
215
  app.use('/project-menu-crowdsource', (0, ui_module_1.default)(config, config.projectMenuCrowdsource.allowUnauthorized), (0, render_ui_module_1.default)(config, config.projectMenuCrowdsource));
196
216
  }
197
217
  if (config.projectTools) {
198
- app.get('/logo/tools/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.projectTools) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
218
+ app.get('/logo/tools/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.projectTools) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
199
219
  app.use('/tools', (0, ui_module_1.default)(config, config.projectTools.allowUnauthorized), (0, render_ui_module_1.default)(config, config.projectTools));
200
220
  }
201
221
  if (config.projectReports) {
202
- app.get('/logo/reports/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.projectReports) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
222
+ app.get('/logo/reports/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.projectReports) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
203
223
  app.use('/reports', (0, ui_module_1.default)(config, config.projectReports.allowUnauthorized), (0, render_ui_module_1.default)(config, config.projectReports));
204
224
  }
225
+ if (((_d = config.modal) === null || _d === void 0 ? void 0 : _d.uiPath) || ((_e = config.modal) === null || _e === void 0 ? void 0 : _e.formSchema)) {
226
+ app.use('/modal', (0, ui_module_1.default)(config, config.modal.allowUnauthorized), (0, render_ui_module_1.default)(config, config.modal));
227
+ }
228
+ if (((_f = config.contextMenu) === null || _f === void 0 ? void 0 : _f.uiPath) || ((_g = config.contextMenu) === null || _g === void 0 ? void 0 : _g.formSchema)) {
229
+ app.use('/context', (0, ui_module_1.default)(config, config.contextMenu.allowUnauthorized), (0, render_ui_module_1.default)(config, config.contextMenu));
230
+ }
231
+ if (Object.keys(config).some((moduleKey) => {
232
+ const moduleConfig = config[moduleKey];
233
+ return typeof moduleConfig === 'object' && moduleConfig.hasOwnProperty('formSchema');
234
+ })) {
235
+ app.get('/api/form-data', json_response_1.default, (0, crowdin_client_1.default)(config), (0, form_data_display_1.default)());
236
+ app.post('/api/form-data', (0, crowdin_client_1.default)(config), (0, form_data_save_1.default)());
237
+ }
205
238
  return {
206
239
  getMetadata: storage.getStorage().getMetadata.bind(storage.getStorage()),
207
240
  saveMetadata: (id, metadata) => __awaiter(this, void 0, void 0, function* () {
@@ -224,11 +257,12 @@ function addCrowdinEndpoints(app, plainConfig) {
224
257
  };
225
258
  }
226
259
  exports.addCrowdinEndpoints = addCrowdinEndpoints;
227
- function createApp(config) {
260
+ function createApp(clientConfig) {
228
261
  const app = (0, express_1.default)();
262
+ const config = (0, defaults_1.convertClientConfig)(clientConfig);
229
263
  addCrowdinEndpoints(app, config);
230
264
  /* eslint no-console: "off" */
231
- app.listen(config.port || 3000, () => console.log(`App started on port ${config.port || 3000}`));
265
+ app.listen(config.port, () => console.log(`App started on port ${config.port}`));
232
266
  }
233
267
  exports.createApp = createApp;
234
268
  function handleUncaughtErrors(config) {
@@ -15,15 +15,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const express_1 = __importDefault(require("express"));
16
16
  const util_1 = require("../util");
17
17
  function handle(config, moduleConfig) {
18
- return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
18
+ return (0, util_1.runAsyncWrapper)((req, res, next) => __awaiter(this, void 0, void 0, function* () {
19
19
  if (moduleConfig.formSchema) {
20
20
  return res.render('form', {
21
- formDataUrl: moduleConfig.formDataUrl ? moduleConfig.formDataUrl : '/api/form-data',
21
+ formGetDataUrl: moduleConfig.formGetDataUrl ? moduleConfig.formGetDataUrl : '/api/form-data',
22
+ formPostDataUrl: moduleConfig.formPostDataUrl ? moduleConfig.formPostDataUrl : '/api/form-data',
22
23
  formSchema: JSON.stringify(moduleConfig.formSchema),
24
+ formUiSchema: moduleConfig.formUiSchema ? JSON.stringify(moduleConfig.formUiSchema) : '{}',
23
25
  });
24
26
  }
25
27
  if (moduleConfig.uiPath) {
26
- return express_1.default.static(moduleConfig.uiPath);
28
+ return express_1.default.static(moduleConfig.uiPath)(req, res, next);
27
29
  }
28
30
  throw new Error('uiPath or formSchema should be provided for module');
29
31
  }), config.onError);