@crowdin/app-project-module 0.28.0 → 0.28.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.
- package/CONTRIBUTING.md +19 -1
- package/README.md +1 -984
- package/out/handlers/crowdin-webhook.js +1 -1
- package/out/handlers/{custom-file-format/process.js → file-processing/custom-file-format.js} +8 -23
- package/out/handlers/file-processing/file-download.d.ts +4 -0
- package/out/handlers/{custom-file-format/download.js → file-processing/file-download.js} +3 -2
- package/out/handlers/file-processing/pre-post-process.d.ts +4 -0
- package/out/handlers/file-processing/pre-post-process.js +99 -0
- package/out/handlers/form-data-display.js +6 -2
- package/out/handlers/form-data-save.js +5 -1
- package/out/handlers/manifest.js +63 -0
- package/out/index.d.ts +3 -3
- package/out/index.js +56 -28
- package/out/middlewares/render-ui-module.js +5 -3
- package/out/models/index.d.ts +104 -28
- package/out/models/index.js +20 -1
- package/out/static/js/form.js +9 -9
- package/out/storage/index.js +4 -7
- package/out/util/cron.js +5 -1
- package/out/util/defaults.d.ts +3 -2
- package/out/util/defaults.js +21 -4
- package/out/util/files.d.ts +3 -0
- package/out/util/files.js +43 -0
- package/out/util/index.js +5 -1
- package/out/util/webhooks.js +15 -4
- package/out/views/form.handlebars +6 -2
- package/package.json +15 -15
- package/out/handlers/custom-file-format/download.d.ts +0 -4
- package/rollup.config.mjs +0 -31
- /package/out/handlers/{custom-file-format/process.d.ts → file-processing/custom-file-format.d.ts} +0 -0
package/out/storage/index.js
CHANGED
|
@@ -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
|
-
|
|
33
|
-
|
|
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
|
});
|
package/out/util/cron.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.
|
|
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];
|
package/out/util/defaults.d.ts
CHANGED
|
@@ -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
|
|
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;
|
package/out/util/defaults.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.
|
|
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];
|
|
@@ -28,8 +32,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
28
32
|
});
|
|
29
33
|
};
|
|
30
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.constructOauthUrl = exports.
|
|
35
|
+
exports.convertClientConfig = exports.constructOauthUrl = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
|
|
32
36
|
const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
|
|
37
|
+
const path_1 = require("path");
|
|
33
38
|
function getRootFolder(config, integration, client, projectId) {
|
|
34
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
40
|
if (!integration.withRootFolder) {
|
|
@@ -52,7 +57,7 @@ function getOauthRoute(integration) {
|
|
|
52
57
|
return ((_a = integration.oauthLogin) === null || _a === void 0 ? void 0 : _a.redirectUriRoute) || '/oauth/code';
|
|
53
58
|
}
|
|
54
59
|
exports.getOauthRoute = getOauthRoute;
|
|
55
|
-
function
|
|
60
|
+
function applyIntegrationModuleDefaults(config, integration) {
|
|
56
61
|
var _a;
|
|
57
62
|
if (!integration.getCrowdinFiles) {
|
|
58
63
|
integration.getCrowdinFiles = (projectId, client, rootFolder) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -241,7 +246,7 @@ function applyDefaults(config, integration) {
|
|
|
241
246
|
integration.webhooks.urlParam = 'crowdinData';
|
|
242
247
|
}
|
|
243
248
|
}
|
|
244
|
-
exports.
|
|
249
|
+
exports.applyIntegrationModuleDefaults = applyIntegrationModuleDefaults;
|
|
245
250
|
function constructOauthUrl(config, integration) {
|
|
246
251
|
var _a, _b, _c;
|
|
247
252
|
const oauth = integration.oauthLogin;
|
|
@@ -257,3 +262,15 @@ function constructOauthUrl(config, integration) {
|
|
|
257
262
|
return url;
|
|
258
263
|
}
|
|
259
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;
|
|
@@ -0,0 +1,43 @@
|
|
|
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;
|
package/out/util/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.
|
|
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];
|
package/out/util/webhooks.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.
|
|
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];
|
|
@@ -39,6 +43,7 @@ const index_1 = require("./index");
|
|
|
39
43
|
const connection_1 = require("./connection");
|
|
40
44
|
const storage_1 = require("../storage");
|
|
41
45
|
const defaults_1 = require("./defaults");
|
|
46
|
+
const util_1 = require("../util");
|
|
42
47
|
const HookEvents = {
|
|
43
48
|
ALL: ['file.translated', 'file.approved'],
|
|
44
49
|
TRANSLATED: ['file.translated'],
|
|
@@ -249,7 +254,7 @@ function updateCrowdinFromWebhookRequest(integration, webhookData, req) {
|
|
|
249
254
|
let filesToSync = [];
|
|
250
255
|
const { projectId, crowdinClient, preparedIntegrationCredentials, rootFolder, appSettings, syncSettings } = webhookData;
|
|
251
256
|
if ((_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.integrationWebhookInterceptor) {
|
|
252
|
-
filesToSync = yield ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhookInterceptor(projectId, crowdinClient.client, rootFolder, appSettings, syncSettings, req));
|
|
257
|
+
filesToSync = yield ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhookInterceptor(projectId, crowdinClient.client, preparedIntegrationCredentials, rootFolder, appSettings, syncSettings, req));
|
|
253
258
|
}
|
|
254
259
|
return yield integration.updateCrowdin(projectId, crowdinClient.client, preparedIntegrationCredentials, filesToSync, rootFolder, appSettings);
|
|
255
260
|
});
|
|
@@ -284,14 +289,20 @@ function consumer(channel, config, integration) {
|
|
|
284
289
|
return function (msg) {
|
|
285
290
|
var _a;
|
|
286
291
|
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
-
if (msg) {
|
|
292
|
+
if (!msg) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
288
296
|
const data = JSON.parse(msg.content.toString());
|
|
289
297
|
const urlParam = (_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.urlParam;
|
|
290
298
|
const webhookUrlParam = data.query[urlParam];
|
|
291
299
|
const webhookData = yield prepareWebhookData(config, integration, webhookUrlParam, 'integration');
|
|
292
300
|
yield updateCrowdinFromWebhookRequest(integration, webhookData, data);
|
|
293
|
-
channel.ack(msg);
|
|
294
301
|
}
|
|
302
|
+
catch (e) {
|
|
303
|
+
(0, util_1.logError)(e, config.onError);
|
|
304
|
+
}
|
|
305
|
+
channel.ack(msg);
|
|
295
306
|
});
|
|
296
307
|
};
|
|
297
308
|
}
|
|
@@ -17,8 +17,12 @@
|
|
|
17
17
|
</div>
|
|
18
18
|
<crowdin-toasts></crowdin-toasts>
|
|
19
19
|
<script>
|
|
20
|
-
|
|
21
|
-
var
|
|
20
|
+
/*<!--*/
|
|
21
|
+
var formGetDataUrl = '{{formGetDataUrl}}';
|
|
22
|
+
var formPostDataUrl = '{{formPostDataUrl}}';
|
|
23
|
+
var formSchema = {{{formSchema}}};
|
|
24
|
+
var formUiSchema = {{{formUiSchema}}};
|
|
25
|
+
/*-->*/
|
|
22
26
|
</script>
|
|
23
27
|
<script src="/assets/js/form.js"></script>
|
|
24
28
|
</body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crowdin/app-project-module",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.1",
|
|
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.
|
|
17
|
-
"@types/pg": "^8.6.
|
|
16
|
+
"@crowdin/crowdin-apps-functions": "0.4.0",
|
|
17
|
+
"@types/pg": "^8.6.6",
|
|
18
18
|
"amqplib": "^0.10.3",
|
|
19
19
|
"crypto-js": "^4.0.0",
|
|
20
|
-
"express": "4.
|
|
20
|
+
"express": "4.18.2",
|
|
21
21
|
"express-handlebars": "^5.3.4",
|
|
22
22
|
"mysql2": "^2.3.3",
|
|
23
|
-
"node-cron": "^3.0.
|
|
24
|
-
"pg": "^8.
|
|
25
|
-
"sqlite3": "^5.
|
|
23
|
+
"node-cron": "^3.0.2",
|
|
24
|
+
"pg": "^8.10.0",
|
|
25
|
+
"sqlite3": "^5.1.6",
|
|
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.
|
|
46
|
+
"@types/express": "4.17.17",
|
|
47
47
|
"@types/express-handlebars": "^5.3.1",
|
|
48
|
-
"@types/jest": "^29.
|
|
49
|
-
"@types/node": "^12.
|
|
50
|
-
"@types/node-cron": "^3.0.
|
|
48
|
+
"@types/jest": "^29.5.0",
|
|
49
|
+
"@types/node": "^12.20.55",
|
|
50
|
+
"@types/node-cron": "^3.0.7",
|
|
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.
|
|
56
|
+
"jest": "^29.5.0",
|
|
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.
|
|
62
|
-
"ts-jest": "^29.0.
|
|
63
|
-
"typescript": "^4.
|
|
61
|
+
"rollup": "^3.20.2",
|
|
62
|
+
"ts-jest": "^29.0.5",
|
|
63
|
+
"typescript": "^4.9.5"
|
|
64
64
|
},
|
|
65
65
|
"repository": {
|
|
66
66
|
"type": "git",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/// <reference types="qs" />
|
|
2
|
-
import { Request, Response } from 'express';
|
|
3
|
-
import { Config } from '../../models';
|
|
4
|
-
export default function handle(config: Config, folder: 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;
|
package/rollup.config.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
};
|
/package/out/handlers/{custom-file-format/process.d.ts → file-processing/custom-file-format.d.ts}
RENAMED
|
File without changes
|