@crowdin/app-project-module 0.28.0-13 → 0.28.0-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.
@@ -17,17 +17,20 @@ 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
+ }
20
24
  if (config.postgreConfig) {
21
25
  (0, util_1.log)('Using PostgreSQL database', config.logger);
22
26
  storage = new postgre_1.PostgreStorage(config.postgreConfig);
23
27
  }
24
- else if (config.mysqlConfig) {
28
+ if (config.mysqlConfig) {
25
29
  (0, util_1.log)('Using MySQL database', config.logger);
26
30
  storage = new mysql_1.MySQLStorage(config.mysqlConfig);
27
31
  }
28
- else {
29
- (0, util_1.log)('Using SQLite database', config.logger);
30
- storage = new sqlite_1.SQLiteStorage({ dbFolder: config.dbFolder });
32
+ if (!storage) {
33
+ throw new Error('Database is not configured');
31
34
  }
32
35
  yield storage.migrate();
33
36
  });
package/out/util/cron.js CHANGED
@@ -1,11 +1,7 @@
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
- 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);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -1,7 +1,6 @@
1
1
  import Crowdin, { SourceFilesModel } from '@crowdin/crowdin-api-client';
2
- import { ClientConfig, Config, IntegrationLogic } from '../models';
2
+ import { 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 applyIntegrationModuleDefaults(config: Config, integration: IntegrationLogic): void;
5
+ export declare function applyDefaults(config: Config, integration: IntegrationLogic): void;
6
6
  export declare function constructOauthUrl(config: Config, integration: IntegrationLogic): string;
7
- export declare function convertClientConfig(clientConfig: ClientConfig): Config;
@@ -1,11 +1,7 @@
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
- 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);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -32,9 +28,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
28
  });
33
29
  };
34
30
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.convertClientConfig = exports.constructOauthUrl = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
31
+ exports.constructOauthUrl = exports.applyDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
36
32
  const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
37
- const path_1 = require("path");
38
33
  function getRootFolder(config, integration, client, projectId) {
39
34
  return __awaiter(this, void 0, void 0, function* () {
40
35
  if (!integration.withRootFolder) {
@@ -57,7 +52,7 @@ function getOauthRoute(integration) {
57
52
  return ((_a = integration.oauthLogin) === null || _a === void 0 ? void 0 : _a.redirectUriRoute) || '/oauth/code';
58
53
  }
59
54
  exports.getOauthRoute = getOauthRoute;
60
- function applyIntegrationModuleDefaults(config, integration) {
55
+ function applyDefaults(config, integration) {
61
56
  var _a;
62
57
  if (!integration.getCrowdinFiles) {
63
58
  integration.getCrowdinFiles = (projectId, client, rootFolder) => __awaiter(this, void 0, void 0, function* () {
@@ -246,7 +241,7 @@ function applyIntegrationModuleDefaults(config, integration) {
246
241
  integration.webhooks.urlParam = 'crowdinData';
247
242
  }
248
243
  }
249
- exports.applyIntegrationModuleDefaults = applyIntegrationModuleDefaults;
244
+ exports.applyDefaults = applyDefaults;
250
245
  function constructOauthUrl(config, integration) {
251
246
  var _a, _b, _c;
252
247
  const oauth = integration.oauthLogin;
@@ -262,15 +257,3 @@ function constructOauthUrl(config, integration) {
262
257
  return url;
263
258
  }
264
259
  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/out/util/index.js CHANGED
@@ -1,11 +1,7 @@
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
- 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);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -1,11 +1,7 @@
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
- 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);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -43,7 +39,6 @@ const index_1 = require("./index");
43
39
  const connection_1 = require("./connection");
44
40
  const storage_1 = require("../storage");
45
41
  const defaults_1 = require("./defaults");
46
- const util_1 = require("../util");
47
42
  const HookEvents = {
48
43
  ALL: ['file.translated', 'file.approved'],
49
44
  TRANSLATED: ['file.translated'],
@@ -254,7 +249,7 @@ function updateCrowdinFromWebhookRequest(integration, webhookData, req) {
254
249
  let filesToSync = [];
255
250
  const { projectId, crowdinClient, preparedIntegrationCredentials, rootFolder, appSettings, syncSettings } = webhookData;
256
251
  if ((_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.integrationWebhookInterceptor) {
257
- filesToSync = yield ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhookInterceptor(projectId, crowdinClient.client, preparedIntegrationCredentials, rootFolder, appSettings, syncSettings, req));
252
+ filesToSync = yield ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhookInterceptor(projectId, crowdinClient.client, rootFolder, appSettings, syncSettings, req));
258
253
  }
259
254
  return yield integration.updateCrowdin(projectId, crowdinClient.client, preparedIntegrationCredentials, filesToSync, rootFolder, appSettings);
260
255
  });
@@ -289,20 +284,14 @@ function consumer(channel, config, integration) {
289
284
  return function (msg) {
290
285
  var _a;
291
286
  return __awaiter(this, void 0, void 0, function* () {
292
- if (!msg) {
293
- return;
294
- }
295
- try {
287
+ if (msg) {
296
288
  const data = JSON.parse(msg.content.toString());
297
289
  const urlParam = (_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.urlParam;
298
290
  const webhookUrlParam = data.query[urlParam];
299
291
  const webhookData = yield prepareWebhookData(config, integration, webhookUrlParam, 'integration');
300
292
  yield updateCrowdinFromWebhookRequest(integration, webhookData, data);
293
+ channel.ack(msg);
301
294
  }
302
- catch (e) {
303
- (0, util_1.logError)(e, config.onError);
304
- }
305
- channel.ack(msg);
306
295
  });
307
296
  };
308
297
  }
@@ -17,12 +17,8 @@
17
17
  </div>
18
18
  <crowdin-toasts></crowdin-toasts>
19
19
  <script>
20
- /*<!--*/
21
- var formGetDataUrl = '{{formGetDataUrl}}';
22
- var formPostDataUrl = '{{formPostDataUrl}}';
23
- var formSchema = {{{formSchema}}};
24
- var formUiSchema = {{{formUiSchema}}};
25
- /*-->*/
20
+ var formDataUrl = '{{formDataUrl}}';
21
+ var formSchema = JSON.parse('{{{formSchema}}}');
26
22
  </script>
27
23
  <script src="/assets/js/form.js"></script>
28
24
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.28.0-13",
3
+ "version": "0.28.0-2",
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",
@@ -13,16 +13,16 @@
13
13
  "test": "jest"
14
14
  },
15
15
  "dependencies": {
16
- "@crowdin/crowdin-apps-functions": "0.4.0",
17
- "@types/pg": "^8.6.6",
16
+ "@crowdin/crowdin-apps-functions": "0.3.1",
17
+ "@types/pg": "^8.6.5",
18
18
  "amqplib": "^0.10.3",
19
19
  "crypto-js": "^4.0.0",
20
- "express": "4.18.2",
20
+ "express": "4.17.1",
21
21
  "express-handlebars": "^5.3.4",
22
22
  "mysql2": "^2.3.3",
23
- "node-cron": "^3.0.2",
24
- "pg": "^8.10.0",
25
- "sqlite3": "^5.1.6",
23
+ "node-cron": "^3.0.0",
24
+ "pg": "^8.8.0",
25
+ "sqlite3": "^5.0.2",
26
26
  "uuid": "^8.3.2"
27
27
  },
28
28
  "devDependencies": {
@@ -43,24 +43,24 @@
43
43
  "@rollup/plugin-replace": "^5.0.2",
44
44
  "@rollup/plugin-terser": "^0.4.0",
45
45
  "@types/crypto-js": "^4.0.0",
46
- "@types/express": "4.17.17",
46
+ "@types/express": "4.17.13",
47
47
  "@types/express-handlebars": "^5.3.1",
48
- "@types/jest": "^29.5.0",
49
- "@types/node": "^12.20.55",
50
- "@types/node-cron": "^3.0.7",
48
+ "@types/jest": "^29.2.5",
49
+ "@types/node": "^12.0.10",
50
+ "@types/node-cron": "^3.0.0",
51
51
  "@typescript-eslint/eslint-plugin": "^2.3.1",
52
52
  "@typescript-eslint/parser": "^2.3.1",
53
53
  "eslint": "^6.4.0",
54
54
  "eslint-config-prettier": "^6.3.0",
55
55
  "eslint-plugin-prettier": "^3.1.1",
56
- "jest": "^29.5.0",
56
+ "jest": "^29.3.1",
57
57
  "jest-junit": "^15.0.0",
58
58
  "prettier": "^2.8.1",
59
59
  "react": "^18.2.0",
60
60
  "react-dom": "^18.2.0",
61
- "rollup": "^3.20.2",
62
- "ts-jest": "^29.0.5",
63
- "typescript": "^4.9.5"
61
+ "rollup": "^3.18.0",
62
+ "ts-jest": "^29.0.3",
63
+ "typescript": "^4.4.4"
64
64
  },
65
65
  "repository": {
66
66
  "type": "git",
@@ -0,0 +1,31 @@
1
+ import babel from '@rollup/plugin-babel';
2
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
3
+ import commonjs from '@rollup/plugin-commonjs';
4
+ import json from '@rollup/plugin-json';
5
+ import replace from '@rollup/plugin-replace';
6
+ import terser from '@rollup/plugin-terser';
7
+ export default {
8
+ input: 'out/static/js/form.js',
9
+ output: {
10
+ file: 'out/static/js/form.js',
11
+ format: 'iife',
12
+ sourcemap: false,
13
+ },
14
+ plugins: [
15
+ nodeResolve({
16
+ browser: true,
17
+ extensions: ['.js'],
18
+ }),
19
+ replace({
20
+ preventAssignment: true,
21
+ 'process.env.NODE_ENV': JSON.stringify( 'production' )
22
+ }),
23
+ json(),
24
+ babel({
25
+ babelHelpers: 'bundled',
26
+ presets: ['@babel/preset-react'],
27
+ }),
28
+ commonjs(),
29
+ terser(),
30
+ ],
31
+ };
@@ -1,4 +0,0 @@
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;
@@ -1,4 +0,0 @@
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;
@@ -1,99 +0,0 @@
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, fileName, fileType, error: contentFileError, } = fileProcessResult;
48
- if (contentFile) {
49
- const contentFileEncoded = 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,3 +0,0 @@
1
- export declare const MAX_BODY_SIZE: number;
2
- export declare function storeFile(fileContent: string, folder: string): Promise<string>;
3
- export declare function getFileContent(url: string, isString?: boolean): Promise<any>;
package/out/util/files.js DELETED
@@ -1,43 +0,0 @@
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
- exports.getFileContent = exports.storeFile = exports.MAX_BODY_SIZE = void 0;
16
- const fs_1 = __importDefault(require("fs"));
17
- const path_1 = __importDefault(require("path"));
18
- const axios_1 = __importDefault(require("axios"));
19
- exports.MAX_BODY_SIZE = 4.9 * 1024 * 1024; //4.9mb
20
- function storeFile(fileContent, folder) {
21
- const fileName = `file${Date.now()}`;
22
- return new Promise((res, rej) => fs_1.default.writeFile(path_1.default.join(folder, fileName), fileContent, (err) => {
23
- if (err) {
24
- rej(err);
25
- }
26
- else {
27
- res(fileName);
28
- }
29
- }));
30
- }
31
- exports.storeFile = storeFile;
32
- function getFileContent(url, isString = false) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const response = (yield axios_1.default.get(url)).data;
35
- if (isString) {
36
- // the response is presented in the ndjson format
37
- const jsonRows = response.split(/\n|\n\r/).filter(Boolean);
38
- return jsonRows.map((jsonStringRow) => JSON.parse(jsonStringRow));
39
- }
40
- return response;
41
- });
42
- }
43
- exports.getFileContent = getFileContent;