@crowdin/app-project-module 0.28.0-11 → 0.28.0-13

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.
@@ -16,7 +16,7 @@ const fs_1 = __importDefault(require("fs"));
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const util_1 = require("../../util");
18
18
  function handle(config, processingConfig, folderName) {
19
- const folder = processingConfig.filesFolder || config.dbFolder || '/';
19
+ const folder = processingConfig.filesFolder || config.dbFolder;
20
20
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
21
21
  const filePath = path_1.default.join(folder, folderName, req.query.file);
22
22
  (0, util_1.log)(`Downloading file ${filePath}`, config.logger);
@@ -18,7 +18,7 @@ const models_1 = require("../../models");
18
18
  const util_1 = require("../../util");
19
19
  const files_1 = require("../../util/files");
20
20
  function handle(baseConfig, config, folderName) {
21
- const folderPath = config.filesFolder || baseConfig.dbFolder || '/';
21
+ const folderPath = config.filesFolder || baseConfig.dbFolder;
22
22
  if (!fs_1.default.existsSync(path_1.default.join(folderPath, folderName))) {
23
23
  fs_1.default.mkdirSync(path_1.default.join(folderPath, folderName), { recursive: true });
24
24
  }
@@ -44,7 +44,7 @@ function handle(baseConfig, config, folderName) {
44
44
  switch (body.jobType) {
45
45
  case models_1.ProcessFileJobType.PRE_IMPORT:
46
46
  case models_1.ProcessFileJobType.POST_EXPORT:
47
- const { contentFile, fileName, error: contentFileError } = fileProcessResult;
47
+ const { contentFile, fileName, fileType, error: contentFileError, } = fileProcessResult;
48
48
  if (contentFile) {
49
49
  const contentFileEncoded = Buffer.from(contentFile).toString('base64');
50
50
  if (Buffer.byteLength(contentFileEncoded, 'utf8') < files_1.MAX_BODY_SIZE) {
@@ -65,6 +65,9 @@ function handle(baseConfig, config, folderName) {
65
65
  if (fileName) {
66
66
  response.fileName = fileName;
67
67
  }
68
+ if (fileType) {
69
+ response.fileType = fileType;
70
+ }
68
71
  processingError = contentFileError;
69
72
  break;
70
73
  case models_1.ProcessFileJobType.POST_IMPORT:
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
@@ -45,23 +45,23 @@ const crowdin_files_1 = __importDefault(require("./handlers/crowdin-files"));
45
45
  const crowdin_project_1 = __importDefault(require("./handlers/crowdin-project"));
46
46
  const crowdin_update_1 = __importDefault(require("./handlers/crowdin-update"));
47
47
  const crowdin_webhook_1 = __importDefault(require("./handlers/crowdin-webhook"));
48
- const integration_webhook_1 = __importDefault(require("./handlers/integration-webhook"));
49
- const file_download_1 = __importDefault(require("./handlers/file-processing/file-download"));
48
+ const translate_1 = __importDefault(require("./handlers/custom-mt/translate"));
50
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
51
  const pre_post_process_1 = __importDefault(require("./handlers/file-processing/pre-post-process"));
52
- const translate_1 = __importDefault(require("./handlers/custom-mt/translate"));
52
+ const form_data_display_1 = __importDefault(require("./handlers/form-data-display"));
53
+ const form_data_save_1 = __importDefault(require("./handlers/form-data-save"));
53
54
  const install_1 = __importDefault(require("./handlers/install"));
54
55
  const integration_data_1 = __importDefault(require("./handlers/integration-data"));
55
56
  const integration_login_1 = __importDefault(require("./handlers/integration-login"));
56
57
  const integration_logout_1 = __importDefault(require("./handlers/integration-logout"));
57
58
  const integration_update_1 = __importDefault(require("./handlers/integration-update"));
59
+ const integration_webhook_1 = __importDefault(require("./handlers/integration-webhook"));
58
60
  const main_1 = __importDefault(require("./handlers/main"));
59
61
  const manifest_1 = __importDefault(require("./handlers/manifest"));
60
62
  const oauth_login_1 = __importDefault(require("./handlers/oauth-login"));
61
63
  const oauth_url_1 = __importDefault(require("./handlers/oauth-url"));
62
64
  const settings_save_1 = __importDefault(require("./handlers/settings-save"));
63
- const form_data_display_1 = __importDefault(require("./handlers/form-data-display"));
64
- const form_data_save_1 = __importDefault(require("./handlers/form-data-save"));
65
65
  const subscription_info_1 = __importDefault(require("./handlers/subscription-info"));
66
66
  const subscription_paid_1 = __importDefault(require("./handlers/subscription-paid"));
67
67
  const sync_settings_1 = __importDefault(require("./handlers/sync-settings"));
@@ -70,8 +70,8 @@ const uninstall_1 = __importDefault(require("./handlers/uninstall"));
70
70
  const crowdin_client_1 = __importStar(require("./middlewares/crowdin-client"));
71
71
  const integration_credentials_1 = __importDefault(require("./middlewares/integration-credentials"));
72
72
  const json_response_1 = __importDefault(require("./middlewares/json-response"));
73
- const ui_module_1 = __importDefault(require("./middlewares/ui-module"));
74
73
  const render_ui_module_1 = __importDefault(require("./middlewares/render-ui-module"));
74
+ const ui_module_1 = __importDefault(require("./middlewares/ui-module"));
75
75
  const models_1 = require("./models");
76
76
  const storage = __importStar(require("./storage"));
77
77
  const util_1 = require("./util");
@@ -81,12 +81,12 @@ const defaults_1 = require("./util/defaults");
81
81
  const webhooks_1 = require("./util/webhooks");
82
82
  var models_2 = require("./models");
83
83
  Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return models_2.Scope; } });
84
- function addCrowdinEndpoints(app, plainConfig) {
84
+ function addCrowdinEndpoints(app, clientConfig) {
85
85
  var _a, _b, _c;
86
- if (!plainConfig.disableGlobalErrorHandling) {
87
- handleUncaughtErrors(plainConfig);
86
+ const config = (0, defaults_1.convertClientConfig)(clientConfig);
87
+ if (!config.disableGlobalErrorHandling) {
88
+ handleUncaughtErrors(config);
88
89
  }
89
- const config = Object.assign(Object.assign({}, plainConfig), { baseUrl: plainConfig.baseUrl.endsWith('/') ? plainConfig.baseUrl.slice(0, -1) : plainConfig.baseUrl });
90
90
  storage.initialize(config);
91
91
  app.use(express_1.default.json({ limit: '50mb' }));
92
92
  app.use('/assets', express_1.default.static((0, path_1.join)(__dirname, 'static')));
@@ -119,7 +119,7 @@ function addCrowdinEndpoints(app, plainConfig) {
119
119
  },
120
120
  }));
121
121
  app.set('view engine', 'handlebars');
122
- 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));
123
123
  app.post('/installed', (0, install_1.default)(config));
124
124
  app.post('/uninstall', (0, uninstall_1.default)(config));
125
125
  app.get('/manifest.json', json_response_1.default, (0, manifest_1.default)(config));
@@ -128,8 +128,8 @@ function addCrowdinEndpoints(app, plainConfig) {
128
128
  }
129
129
  const integrationLogic = config.projectIntegration;
130
130
  if (integrationLogic) {
131
- (0, defaults_1.applyDefaults)(config, integrationLogic);
132
- 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));
133
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));
134
134
  app.get('/api/subscription-info', json_response_1.default, (0, crowdin_client_1.default)(config), (0, subscription_info_1.default)(config));
135
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));
@@ -174,7 +174,7 @@ function addCrowdinEndpoints(app, plainConfig) {
174
174
  }
175
175
  }
176
176
  if (config.customFileFormat) {
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));
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
178
  app.get('/file/download', (0, file_download_1.default)(config, config.customFileFormat, 'custom-file-format'));
179
179
  }
180
180
  if (config.filePreImport) {
@@ -194,15 +194,15 @@ function addCrowdinEndpoints(app, plainConfig) {
194
194
  app.get(`/file/download/${models_1.ProcessFileJobType.POST_EXPORT}`, (0, file_download_1.default)(config, config.filePostExport, models_1.ProcessFileJobType.POST_EXPORT));
195
195
  }
196
196
  if (config.customMT) {
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 || (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); });
198
198
  app.post('/translate', (0, crowdin_client_1.default)(config), (0, translate_1.default)(config, config.customMT));
199
199
  }
200
200
  if (config.profileResourcesMenu) {
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 || (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); });
202
202
  app.use('/resources', (0, ui_module_1.default)(config, config.profileResourcesMenu.allowUnauthorized), (0, render_ui_module_1.default)(config, config.profileResourcesMenu));
203
203
  }
204
204
  if (config.organizationMenu) {
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 || (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); });
206
206
  app.use('/resources', (0, ui_module_1.default)(config, config.organizationMenu.allowUnauthorized), (0, render_ui_module_1.default)(config, config.organizationMenu));
207
207
  }
208
208
  if (config.editorRightPanel) {
@@ -215,11 +215,11 @@ function addCrowdinEndpoints(app, plainConfig) {
215
215
  app.use('/project-menu-crowdsource', (0, ui_module_1.default)(config, config.projectMenuCrowdsource.allowUnauthorized), (0, render_ui_module_1.default)(config, config.projectMenuCrowdsource));
216
216
  }
217
217
  if (config.projectTools) {
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 || (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); });
219
219
  app.use('/tools', (0, ui_module_1.default)(config, config.projectTools.allowUnauthorized), (0, render_ui_module_1.default)(config, config.projectTools));
220
220
  }
221
221
  if (config.projectReports) {
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 || (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); });
223
223
  app.use('/reports', (0, ui_module_1.default)(config, config.projectReports.allowUnauthorized), (0, render_ui_module_1.default)(config, config.projectReports));
224
224
  }
225
225
  if (Object.keys(config).some((moduleKey) => {
@@ -251,11 +251,12 @@ function addCrowdinEndpoints(app, plainConfig) {
251
251
  };
252
252
  }
253
253
  exports.addCrowdinEndpoints = addCrowdinEndpoints;
254
- function createApp(config) {
254
+ function createApp(clientConfig) {
255
255
  const app = (0, express_1.default)();
256
+ const config = (0, defaults_1.convertClientConfig)(clientConfig);
256
257
  addCrowdinEndpoints(app, config);
257
258
  /* eslint no-console: "off" */
258
- app.listen(config.port || 3000, () => console.log(`App started on port ${config.port || 3000}`));
259
+ app.listen(config.port, () => console.log(`App started on port ${config.port}`));
259
260
  }
260
261
  exports.createApp = createApp;
261
262
  function handleUncaughtErrors(config) {
@@ -3,7 +3,7 @@ import { JwtPayload, VerifyOptions } from '@crowdin/crowdin-apps-functions';
3
3
  import { Request } from 'express';
4
4
  import { MySQLStorageConfig } from '../storage/mysql';
5
5
  import { PostgreStorageConfig } from '../storage/postgre';
6
- export interface Config extends ImagePath {
6
+ export interface ClientConfig extends ImagePath {
7
7
  /**
8
8
  * Authentication Crowdin App type: "authorization_code", "crowdin_app". Default: "crowdin_app"
9
9
  */
@@ -11,11 +11,11 @@ export interface Config extends ImagePath {
11
11
  /**
12
12
  * client id that we received when registering the app
13
13
  */
14
- clientId: string;
14
+ clientId?: string;
15
15
  /**
16
16
  * client secret that we received when registering the app
17
17
  */
18
- clientSecret: string;
18
+ clientSecret?: string;
19
19
  /**
20
20
  * Secret to encrypt/decrypt credentials (by default @clientSecret will be used)
21
21
  */
@@ -27,7 +27,7 @@ export interface Config extends ImagePath {
27
27
  /**
28
28
  * https url where an app is reachable from the internet (e.g. the one that ngrok generates for us)
29
29
  */
30
- baseUrl: string;
30
+ baseUrl?: string;
31
31
  /**
32
32
  * define custom Crowdin urls (e.g. to work against local Crowdin server)
33
33
  */
@@ -132,6 +132,14 @@ export interface Config extends ImagePath {
132
132
  filePreExport?: FilePreExportLogic;
133
133
  filePostExport?: FilePostExportLogic;
134
134
  }
135
+ export type Config = ClientConfig & {
136
+ baseUrl: string;
137
+ clientId: string;
138
+ clientSecret: string;
139
+ port: number;
140
+ dbFolder: string;
141
+ imagePath: string;
142
+ };
135
143
  export declare enum AuthenticationType {
136
144
  CODE = "authorization_code",
137
145
  APP = "crowdin_app"
@@ -593,6 +601,7 @@ export interface BuildFileResponse {
593
601
  contentFile: string;
594
602
  error?: string;
595
603
  fileName?: string;
604
+ fileType?: string;
596
605
  }
597
606
  export interface ProcessFileString {
598
607
  previewId?: number;
@@ -17,20 +17,17 @@ const sqlite_1 = require("./sqlite");
17
17
  let storage;
18
18
  function initialize(config) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- if (config.dbFolder) {
21
- (0, util_1.log)('Using SQLite database', config.logger);
22
- storage = new sqlite_1.SQLiteStorage({ dbFolder: config.dbFolder });
23
- }
24
20
  if (config.postgreConfig) {
25
21
  (0, util_1.log)('Using PostgreSQL database', config.logger);
26
22
  storage = new postgre_1.PostgreStorage(config.postgreConfig);
27
23
  }
28
- if (config.mysqlConfig) {
24
+ else if (config.mysqlConfig) {
29
25
  (0, util_1.log)('Using MySQL database', config.logger);
30
26
  storage = new mysql_1.MySQLStorage(config.mysqlConfig);
31
27
  }
32
- if (!storage) {
33
- throw new Error('Database is not configured');
28
+ else {
29
+ (0, util_1.log)('Using SQLite database', config.logger);
30
+ storage = new sqlite_1.SQLiteStorage({ dbFolder: config.dbFolder });
34
31
  }
35
32
  yield storage.migrate();
36
33
  });
@@ -1,6 +1,7 @@
1
1
  import Crowdin, { SourceFilesModel } from '@crowdin/crowdin-api-client';
2
- import { Config, IntegrationLogic } from '../models';
2
+ import { ClientConfig, Config, IntegrationLogic } from '../models';
3
3
  export declare function getRootFolder(config: Config, integration: IntegrationLogic, client: Crowdin, projectId: number): Promise<SourceFilesModel.Directory | undefined>;
4
4
  export declare function getOauthRoute(integration: IntegrationLogic): string;
5
- export declare function applyDefaults(config: Config, integration: IntegrationLogic): void;
5
+ export declare function applyIntegrationModuleDefaults(config: Config, integration: IntegrationLogic): void;
6
6
  export declare function constructOauthUrl(config: Config, integration: IntegrationLogic): string;
7
+ export declare function convertClientConfig(clientConfig: ClientConfig): Config;
@@ -32,8 +32,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.constructOauthUrl = exports.applyDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
35
+ exports.convertClientConfig = exports.constructOauthUrl = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
36
36
  const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
37
+ const path_1 = require("path");
37
38
  function getRootFolder(config, integration, client, projectId) {
38
39
  return __awaiter(this, void 0, void 0, function* () {
39
40
  if (!integration.withRootFolder) {
@@ -56,7 +57,7 @@ function getOauthRoute(integration) {
56
57
  return ((_a = integration.oauthLogin) === null || _a === void 0 ? void 0 : _a.redirectUriRoute) || '/oauth/code';
57
58
  }
58
59
  exports.getOauthRoute = getOauthRoute;
59
- function applyDefaults(config, integration) {
60
+ function applyIntegrationModuleDefaults(config, integration) {
60
61
  var _a;
61
62
  if (!integration.getCrowdinFiles) {
62
63
  integration.getCrowdinFiles = (projectId, client, rootFolder) => __awaiter(this, void 0, void 0, function* () {
@@ -245,7 +246,7 @@ function applyDefaults(config, integration) {
245
246
  integration.webhooks.urlParam = 'crowdinData';
246
247
  }
247
248
  }
248
- exports.applyDefaults = applyDefaults;
249
+ exports.applyIntegrationModuleDefaults = applyIntegrationModuleDefaults;
249
250
  function constructOauthUrl(config, integration) {
250
251
  var _a, _b, _c;
251
252
  const oauth = integration.oauthLogin;
@@ -261,3 +262,15 @@ function constructOauthUrl(config, integration) {
261
262
  return url;
262
263
  }
263
264
  exports.constructOauthUrl = constructOauthUrl;
265
+ function convertClientConfig(clientConfig) {
266
+ const baseUrl = clientConfig.baseUrl || process.env.URL;
267
+ const clientId = clientConfig.clientId || process.env.CROWDIN_CLIENT_ID;
268
+ const clientSecret = clientConfig.clientSecret || process.env.CROWDIN_CLIENT_SECRET;
269
+ const port = clientConfig.port || process.env.PORT || 3000;
270
+ if (!baseUrl || !clientId || !clientSecret) {
271
+ throw new Error('One of following parameters are not defined [baseUrl, clientId, clientSecret]');
272
+ }
273
+ return Object.assign(Object.assign({}, clientConfig), { baseUrl: baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl, clientId,
274
+ clientSecret, port: Number(port), dbFolder: clientConfig.dbFolder || (0, path_1.join)(process.cwd(), 'db'), imagePath: clientConfig.imagePath || (0, path_1.join)(process.cwd(), 'logo.png') });
275
+ }
276
+ exports.convertClientConfig = convertClientConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.28.0-11",
3
+ "version": "0.28.0-13",
4
4
  "description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",