@crowdin/app-project-module 0.17.6 → 0.17.8
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/README.md +5 -9
- package/out/handlers/crowdin-file-progress.d.ts +4 -0
- package/out/handlers/crowdin-file-progress.js +22 -0
- package/out/handlers/crowdin-files.d.ts +4 -0
- package/out/handlers/crowdin-files.js +31 -0
- package/out/handlers/crowdin-project.d.ts +4 -0
- package/out/handlers/crowdin-project.js +22 -0
- package/out/handlers/crowdin-update.d.ts +4 -0
- package/out/handlers/crowdin-update.js +26 -0
- package/out/handlers/custom-file-format/download.d.ts +4 -0
- package/out/handlers/custom-file-format/download.js +32 -0
- package/out/handlers/custom-file-format/process.d.ts +4 -0
- package/out/handlers/custom-file-format/process.js +139 -0
- package/out/handlers/custom-mt/translate.d.ts +4 -0
- package/out/handlers/custom-mt/translate.js +42 -0
- package/out/handlers/install.d.ts +4 -0
- package/out/handlers/install.js +46 -0
- package/out/handlers/integration-data.d.ts +4 -0
- package/out/handlers/integration-data.js +21 -0
- package/out/handlers/integration-login.d.ts +4 -0
- package/out/handlers/integration-login.js +30 -0
- package/out/handlers/integration-logout.d.ts +4 -0
- package/out/handlers/integration-logout.js +23 -0
- package/out/handlers/integration-update.d.ts +4 -0
- package/out/handlers/integration-update.js +25 -0
- package/out/handlers/main.d.ts +4 -0
- package/out/handlers/main.js +64 -0
- package/out/handlers/manifest.d.ts +3 -0
- package/out/handlers/manifest.js +126 -0
- package/out/handlers/oauth-login.d.ts +4 -0
- package/out/handlers/oauth-login.js +69 -0
- package/out/handlers/settings-save.d.ts +4 -0
- package/out/handlers/settings-save.js +21 -0
- package/out/handlers/subscription-info.d.ts +3 -0
- package/out/handlers/subscription-info.js +15 -0
- package/out/handlers/subscription-paid.d.ts +4 -0
- package/out/handlers/subscription-paid.js +22 -0
- package/out/handlers/sync-settings-save.d.ts +4 -0
- package/out/handlers/sync-settings-save.js +29 -0
- package/out/handlers/sync-settings.d.ts +4 -0
- package/out/handlers/sync-settings.js +27 -0
- package/out/handlers/uninstall.d.ts +4 -0
- package/out/handlers/uninstall.js +27 -0
- package/out/index.d.ts +5 -0
- package/out/index.js +191 -0
- package/out/logo.png +0 -0
- package/out/middlewares/crowdin-client.d.ts +10 -0
- package/out/middlewares/crowdin-client.js +88 -0
- package/out/middlewares/integration-credentials.d.ts +4 -0
- package/out/middlewares/integration-credentials.js +39 -0
- package/out/middlewares/json-response.d.ts +2 -0
- package/out/middlewares/json-response.js +7 -0
- package/out/middlewares/ui-module.d.ts +4 -0
- package/out/middlewares/ui-module.js +39 -0
- package/out/models/index.d.ts +549 -0
- package/out/models/index.js +41 -0
- package/out/static/css/styles.css +57 -0
- package/out/static/js/main.js +130 -0
- package/out/static/js/polyfills/fetch.js +494 -0
- package/out/static/js/polyfills/promise.js +375 -0
- package/out/storage/index.d.ts +22 -0
- package/out/storage/index.js +319 -0
- package/out/util/connection.d.ts +10 -0
- package/out/util/connection.js +217 -0
- package/out/util/cron.d.ts +3 -0
- package/out/util/cron.js +103 -0
- package/out/util/defaults.d.ts +5 -0
- package/out/util/defaults.js +153 -0
- package/out/util/index.d.ts +11 -0
- package/out/util/index.js +105 -0
- package/out/views/install.handlebars +16 -0
- package/out/views/login.handlebars +115 -0
- package/out/views/main.handlebars +471 -0
- package/out/views/oauth.handlebars +4 -0
- package/out/views/partials/head.handlebars +20 -0
- package/out/views/subscription.handlebars +26 -0
- package/package.json +2 -2
- package/.github/workflows/basic.yml +0 -39
- package/.github/workflows/publish.yml +0 -34
package/README.md
CHANGED
|
@@ -19,14 +19,6 @@ In both options you will need to provide Crowdin App configuration file. Please
|
|
|
19
19
|
- `getUserSettings` to get settings that users manage in the integration module
|
|
20
20
|
- `establishCrowdinConnection` method that accept jwt token that you may forward from module UI and it will return back Crowdin client instance and the context.
|
|
21
21
|
|
|
22
|
-
## Status
|
|
23
|
-
|
|
24
|
-
[](https://www.npmjs.com/package/@crowdin/app-project-module)
|
|
25
|
-
[](https://dev.azure.com/crowdin/app-project-module/_build/latest?definitionId=39&branchName=master)
|
|
26
|
-
[](https://www.npmjs.com/package/@crowdin/app-project-module)
|
|
27
|
-
<!-- [](https://github.com/crowdin/app-project-module/issues)
|
|
28
|
-
[](https://github.com/crowdin/app-project-module/blob/master/LICENSE) -->
|
|
29
|
-
|
|
30
22
|
## Table of Contents
|
|
31
23
|
|
|
32
24
|
- [Installation](#installation)
|
|
@@ -81,7 +73,11 @@ const configuration = {
|
|
|
81
73
|
description: 'Sample App description',
|
|
82
74
|
dbFolder: __dirname,
|
|
83
75
|
imagePath: __dirname + '/' + 'logo.png',
|
|
84
|
-
//
|
|
76
|
+
crowdinUrls: { // custom urls to override
|
|
77
|
+
// apiUrl: 'https://local.crowdin.dev/api/v2'
|
|
78
|
+
// accountUrl: 'https://local.crowdin.dev/oauth/token' // (default https://accounts.crowdin.com/oauth/token)
|
|
79
|
+
// subscriptionUrl: 'https://local.crowdin.dev' // (default https://crowdin.com or https://org.api.crowdin.com)
|
|
80
|
+
},
|
|
85
81
|
projectIntegration: {
|
|
86
82
|
withRootFolder: true,
|
|
87
83
|
withCronSync: {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config } from '../models';
|
|
4
|
+
export default function handle(config: Config): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const util_1 = require("../util");
|
|
13
|
+
function handle(config) {
|
|
14
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const fileId = Number(req.params.fileId);
|
|
16
|
+
(0, util_1.log)(`Loading translation progress for file ${fileId}`, config.logger);
|
|
17
|
+
const progress = yield req.crowdinApiClient.translationStatusApi.getFileProgress(req.crowdinContext.jwtPayload.context.project_id, fileId);
|
|
18
|
+
(0, util_1.log)(`Translation progress for file ${fileId} ${JSON.stringify(progress.data, null, 2)}`, config.logger);
|
|
19
|
+
res.send({ [fileId]: progress.data.map(e => e.data) });
|
|
20
|
+
}), config.onError);
|
|
21
|
+
}
|
|
22
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config, IntegrationLogic } from '../models';
|
|
4
|
+
export default function handle(config: Config, integration: IntegrationLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const util_1 = require("../util");
|
|
13
|
+
const defaults_1 = require("../util/defaults");
|
|
14
|
+
function handle(config, integration) {
|
|
15
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
(0, util_1.log)('Loading crowdin files', config.logger);
|
|
17
|
+
if (integration.getCrowdinFiles) {
|
|
18
|
+
const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, req.crowdinApiClient, req.crowdinContext.jwtPayload.context.project_id);
|
|
19
|
+
(0, util_1.log)(`Loading files ${rootFolder ? `from folder ${rootFolder.id}` : 'from root'}`, config.logger);
|
|
20
|
+
const files = integration.getCrowdinFiles
|
|
21
|
+
? yield integration.getCrowdinFiles(req.crowdinContext.jwtPayload.context.project_id, req.crowdinApiClient, rootFolder, req.integrationSettings)
|
|
22
|
+
: [];
|
|
23
|
+
(0, util_1.log)(`Returning files ${JSON.stringify(files, null, 2)}`, config.logger);
|
|
24
|
+
res.send(files);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
res.send([]);
|
|
28
|
+
}
|
|
29
|
+
}), config.onError);
|
|
30
|
+
}
|
|
31
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config } from '../models';
|
|
4
|
+
export default function handle(config: Config): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const util_1 = require("../util");
|
|
13
|
+
function handle(config) {
|
|
14
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const projectId = req.crowdinContext.jwtPayload.context.project_id;
|
|
16
|
+
(0, util_1.log)(`Loading crowdin project ${projectId}`, config.logger);
|
|
17
|
+
const project = yield req.crowdinApiClient.projectsGroupsApi.getProject(projectId);
|
|
18
|
+
(0, util_1.log)(`Loaded crowdin project ${JSON.stringify(project, null, 2)}`, config.logger);
|
|
19
|
+
res.send(project.data);
|
|
20
|
+
}), config.onError);
|
|
21
|
+
}
|
|
22
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config, IntegrationLogic } from '../models';
|
|
4
|
+
export default function handle(config: Config, integration: IntegrationLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const util_1 = require("../util");
|
|
13
|
+
const defaults_1 = require("../util/defaults");
|
|
14
|
+
function handle(config, integration) {
|
|
15
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const projectId = req.crowdinContext.jwtPayload.context.project_id;
|
|
17
|
+
(0, util_1.log)(`Upading crowdin project ${projectId}`, config.logger);
|
|
18
|
+
const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, req.crowdinApiClient, projectId);
|
|
19
|
+
if (rootFolder) {
|
|
20
|
+
(0, util_1.log)(`Upading crowdin files under folder ${rootFolder.id}`, config.logger);
|
|
21
|
+
}
|
|
22
|
+
yield integration.updateCrowdin(projectId, req.crowdinApiClient, req.integrationCredentials, req.body, rootFolder, req.integrationSettings);
|
|
23
|
+
res.status(204).end();
|
|
24
|
+
}), config.onError);
|
|
25
|
+
}
|
|
26
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
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;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 util_1 = require("../../util");
|
|
18
|
+
function handle(config, folder) {
|
|
19
|
+
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
|
+
(0, util_1.log)(`Downloading file ${filePath}`, config.logger);
|
|
22
|
+
res.download(filePath, function (err) {
|
|
23
|
+
if (err) {
|
|
24
|
+
console.error(err);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
fs_1.default.unlinkSync(filePath);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}), config.onError);
|
|
31
|
+
}
|
|
32
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config, CustomFileFormatLogic } from '../../models';
|
|
4
|
+
export default function handle(baseConfig: Config, baseUrl: string, folder: string, config: CustomFileFormatLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,139 @@
|
|
|
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 axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const models_1 = require("../../models");
|
|
19
|
+
const util_1 = require("../../util");
|
|
20
|
+
const MAX_BODY_SIZE = 5 * 1024 * 1024; //5mb
|
|
21
|
+
function storeFile(fileContent, folder) {
|
|
22
|
+
const fileName = `file${Date.now()}`;
|
|
23
|
+
return new Promise((res, rej) => fs_1.default.writeFile(path_1.default.join(folder, 'custom-file-format', fileName), fileContent, err => {
|
|
24
|
+
if (err) {
|
|
25
|
+
rej(err);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
res(fileName);
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
function handleBuildFile(baseUrl, dataFolder, config, req, client, context, projectId, file) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const response = {};
|
|
35
|
+
if (!req.strings && !req.stringsUrl) {
|
|
36
|
+
throw new Error('Bad payload received: No strings found');
|
|
37
|
+
}
|
|
38
|
+
let strings;
|
|
39
|
+
if (req.strings) {
|
|
40
|
+
strings = req.strings;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
strings = (yield axios_1.default.get(req.stringsUrl)).data;
|
|
44
|
+
}
|
|
45
|
+
let res;
|
|
46
|
+
if ((req.file.id || !file) && config.exportStrings) {
|
|
47
|
+
res = yield config.exportStrings(req, strings, client, context, projectId);
|
|
48
|
+
}
|
|
49
|
+
else if (file && config.buildFile) {
|
|
50
|
+
res = yield config.buildFile(file, req, strings, client, context, projectId);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return { response };
|
|
54
|
+
}
|
|
55
|
+
const contentFileEncoded = Buffer.from(res.contentFile).toString('base64');
|
|
56
|
+
if (Buffer.byteLength(contentFileEncoded, 'utf8') < MAX_BODY_SIZE) {
|
|
57
|
+
response.content = contentFileEncoded;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const storedFile = yield storeFile(res.contentFile, dataFolder);
|
|
61
|
+
response.contentUrl = `${baseUrl}?file=${storedFile}`;
|
|
62
|
+
}
|
|
63
|
+
return { response, error: res.error };
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function handleParseFile(baseUrl, dataFolder, config, req, client, context, projectId, file) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const response = {};
|
|
69
|
+
if (!config.parseFile || !file) {
|
|
70
|
+
return { response };
|
|
71
|
+
}
|
|
72
|
+
const res = yield config.parseFile(file, req, client, context, projectId);
|
|
73
|
+
if (res.previewFile) {
|
|
74
|
+
const previewFileEncoded = Buffer.from(res.previewFile).toString('base64');
|
|
75
|
+
if (Buffer.byteLength(previewFileEncoded, 'utf8') < MAX_BODY_SIZE) {
|
|
76
|
+
response.preview = previewFileEncoded;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const storedFile = yield storeFile(res.previewFile, dataFolder);
|
|
80
|
+
response.previewUrl = `${baseUrl}?file=${storedFile}`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (res.strings) {
|
|
84
|
+
let strings = res.strings;
|
|
85
|
+
if (config.autoUploadTranslations) {
|
|
86
|
+
strings = strings.map(string => {
|
|
87
|
+
const translations = {};
|
|
88
|
+
req.targetLanguages
|
|
89
|
+
.map(targetLanguage => targetLanguage.id)
|
|
90
|
+
.forEach(targetLanguage => (translations[targetLanguage] = { text: string.text }));
|
|
91
|
+
return Object.assign(Object.assign({}, string), { translations });
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const stringsJson = JSON.stringify(strings);
|
|
95
|
+
if (Buffer.byteLength(stringsJson, 'utf8') < MAX_BODY_SIZE) {
|
|
96
|
+
response.strings = strings;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const storedFile = yield storeFile(stringsJson, dataFolder);
|
|
100
|
+
response.stringsUrl = `${baseUrl}?file=${storedFile}`;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { response, error: res.error };
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function handle(baseConfig, baseUrl, folder, config) {
|
|
107
|
+
if (!fs_1.default.existsSync(path_1.default.join(folder, 'custom-file-format'))) {
|
|
108
|
+
fs_1.default.mkdirSync(path_1.default.join(folder, 'custom-file-format'), { recursive: true });
|
|
109
|
+
}
|
|
110
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const baseFilesUrl = `${baseUrl}/file/download`;
|
|
112
|
+
const body = req.body;
|
|
113
|
+
(0, util_1.log)(`Recieved request to process file ${JSON.stringify(body, null, 2)}`, baseConfig.logger);
|
|
114
|
+
let file;
|
|
115
|
+
if (body.file.content) {
|
|
116
|
+
file = Buffer.from(body.file.content, 'base64').toString();
|
|
117
|
+
}
|
|
118
|
+
else if (body.file.contentUrl) {
|
|
119
|
+
file = (yield axios_1.default.get(body.file.contentUrl)).data;
|
|
120
|
+
}
|
|
121
|
+
let response = {};
|
|
122
|
+
let error;
|
|
123
|
+
switch (body.jobType) {
|
|
124
|
+
case models_1.ProcessFileJobType.BUILD_FILE:
|
|
125
|
+
const buildFileResult = yield handleBuildFile(baseFilesUrl, folder, config, body, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id, file);
|
|
126
|
+
response = buildFileResult.response;
|
|
127
|
+
error = buildFileResult.error;
|
|
128
|
+
break;
|
|
129
|
+
case models_1.ProcessFileJobType.PARSE_FILE:
|
|
130
|
+
const parseFileResult = yield handleParseFile(baseFilesUrl, folder, config, body, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id, file);
|
|
131
|
+
response = parseFileResult.response;
|
|
132
|
+
error = parseFileResult.error;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
(0, util_1.log)(`Returning response from process file action ${JSON.stringify(response, null, 2)}`, baseConfig.logger);
|
|
136
|
+
res.send({ data: response, error: error ? { message: error } : undefined });
|
|
137
|
+
}), baseConfig.onError);
|
|
138
|
+
}
|
|
139
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config, CustomMTLogic } from '../../models';
|
|
4
|
+
export default function handle(baseConfig: Config, config: CustomMTLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const util_1 = require("../../util");
|
|
13
|
+
function handle(baseConfig, config) {
|
|
14
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const source = req.query.source;
|
|
16
|
+
const target = req.query.target;
|
|
17
|
+
const body = req.body;
|
|
18
|
+
(0, util_1.log)('Recieved request for custom mt', baseConfig.logger);
|
|
19
|
+
(0, util_1.log)(`Source language ${source}, target language ${target}`, baseConfig.logger);
|
|
20
|
+
(0, util_1.log)(`Payload ${JSON.stringify(body, null, 2)}`, baseConfig.logger);
|
|
21
|
+
const projectId = Number(req.query.project_id);
|
|
22
|
+
try {
|
|
23
|
+
if (source === 'en' && target === 'de' && body.strings && body.strings[0] === 'validation') {
|
|
24
|
+
if (config.validate) {
|
|
25
|
+
yield config.validate(req.crowdinApiClient);
|
|
26
|
+
}
|
|
27
|
+
res.send({ data: { translations: [] } });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const translations = yield config.translate(req.crowdinApiClient, req.crowdinContext, projectId, source, target, body.strings);
|
|
31
|
+
res.send({ data: { translations } });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
const message = (0, util_1.getMessage)(e);
|
|
36
|
+
res.send({
|
|
37
|
+
error: { message },
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}), baseConfig.onError);
|
|
41
|
+
}
|
|
42
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Request, Response } from 'express';
|
|
3
|
+
import { Config } from '../models';
|
|
4
|
+
export default function handle(config: Config): (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
|
|
13
|
+
const models_1 = require("../models");
|
|
14
|
+
const storage_1 = require("../storage");
|
|
15
|
+
const util_1 = require("../util");
|
|
16
|
+
function handle(config) {
|
|
17
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
19
|
+
const event = req.body;
|
|
20
|
+
(0, util_1.log)(`Recieved install request ${JSON.stringify(event, null, 2)}`, config.logger);
|
|
21
|
+
const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)(config.clientId, config.clientSecret, event.code, (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.accountUrl);
|
|
22
|
+
const credentials = {
|
|
23
|
+
id: (event.domain || event.organizationId).toString(),
|
|
24
|
+
appSecret: event.appSecret,
|
|
25
|
+
domain: event.domain,
|
|
26
|
+
userId: event.userId,
|
|
27
|
+
organizationId: event.organizationId,
|
|
28
|
+
baseUrl: event.baseUrl,
|
|
29
|
+
accessToken: (0, util_1.encryptData)(config, token.accessToken),
|
|
30
|
+
refreshToken: (0, util_1.encryptData)(config, token.refreshToken),
|
|
31
|
+
expire: (new Date().getTime() / 1000 + token.expiresIn).toString(),
|
|
32
|
+
type: event.domain ? models_1.AccountType.ENTERPRISE : models_1.AccountType.NORMAL,
|
|
33
|
+
};
|
|
34
|
+
const existingCredentials = yield (0, storage_1.getCrowdinCredentials)(credentials.id);
|
|
35
|
+
if (!!existingCredentials) {
|
|
36
|
+
yield (0, storage_1.updateCrowdinCredentials)(credentials);
|
|
37
|
+
(0, util_1.log)('An existing App has been reinstalled', config.logger);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
yield (0, storage_1.saveCrowdinCredentials)(credentials);
|
|
41
|
+
(0, util_1.log)('A new App has been installed', config.logger);
|
|
42
|
+
}
|
|
43
|
+
res.status(204).end();
|
|
44
|
+
}), config.onError);
|
|
45
|
+
}
|
|
46
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config, IntegrationLogic } from '../models';
|
|
4
|
+
export default function handle(config: Config, integration: IntegrationLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const util_1 = require("../util");
|
|
13
|
+
function handle(config, integration) {
|
|
14
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
(0, util_1.log)('Recieved request to get integration data', config.logger);
|
|
16
|
+
const files = yield integration.getIntegrationFiles(req.integrationCredentials, req.integrationSettings);
|
|
17
|
+
(0, util_1.log)(`Integration data response ${JSON.stringify(files, null, 2)}`, config.logger);
|
|
18
|
+
res.send(files);
|
|
19
|
+
}), config.onError);
|
|
20
|
+
}
|
|
21
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config, IntegrationLogic } from '../models';
|
|
4
|
+
export default function handle(config: Config, integration: IntegrationLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const storage_1 = require("../storage");
|
|
13
|
+
const util_1 = require("../util");
|
|
14
|
+
function handle(config, integration) {
|
|
15
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
(0, util_1.log)('Recieved integration login request', config.logger);
|
|
17
|
+
if (integration.checkConnection) {
|
|
18
|
+
(0, util_1.log)('Checking the integration credentials', config.logger);
|
|
19
|
+
yield integration.checkConnection(req.body.credentials);
|
|
20
|
+
}
|
|
21
|
+
const existing = yield (0, storage_1.getIntegrationCredentials)(req.crowdinContext.clientId);
|
|
22
|
+
if (!!existing) {
|
|
23
|
+
(0, util_1.log)('Deleting old credentials', config.logger);
|
|
24
|
+
yield (0, storage_1.deleteIntegrationCredentials)(req.crowdinContext.clientId);
|
|
25
|
+
}
|
|
26
|
+
yield (0, storage_1.saveIntegrationCredentials)(req.crowdinContext.clientId, (0, util_1.encryptData)(config, JSON.stringify(req.body.credentials)), req.crowdinContext.crowdinId);
|
|
27
|
+
res.status(204).end();
|
|
28
|
+
}), config.onError);
|
|
29
|
+
}
|
|
30
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config } from '../models';
|
|
4
|
+
export default function handle(config: Config): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const storage_1 = require("../storage");
|
|
13
|
+
const util_1 = require("../util");
|
|
14
|
+
const connection_1 = require("../util/connection");
|
|
15
|
+
function handle(config) {
|
|
16
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
(0, util_1.log)('Recieved integration logout request', config.logger);
|
|
18
|
+
yield (0, storage_1.deleteIntegrationCredentials)(req.crowdinContext.clientId);
|
|
19
|
+
(0, connection_1.clearCache)(req.crowdinContext.crowdinId);
|
|
20
|
+
res.status(204).end();
|
|
21
|
+
}), config.onError);
|
|
22
|
+
}
|
|
23
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config, IntegrationLogic } from '../models';
|
|
4
|
+
export default function handle(config: Config, integration: IntegrationLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const util_1 = require("../util");
|
|
13
|
+
const defaults_1 = require("../util/defaults");
|
|
14
|
+
function handle(config, integration) {
|
|
15
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
(0, util_1.log)('Upading integratino data', config.logger);
|
|
17
|
+
const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, req.crowdinApiClient, req.crowdinContext.jwtPayload.context.project_id);
|
|
18
|
+
if (rootFolder) {
|
|
19
|
+
(0, util_1.log)(`Upading integration data for crowding root folder ${rootFolder.id}`, config.logger);
|
|
20
|
+
}
|
|
21
|
+
yield integration.updateIntegration(req.crowdinContext.jwtPayload.context.project_id, req.crowdinApiClient, req.integrationCredentials, req.body, rootFolder, req.integrationSettings);
|
|
22
|
+
res.status(204).end();
|
|
23
|
+
}), config.onError);
|
|
24
|
+
}
|
|
25
|
+
exports.default = handle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config, IntegrationLogic } from '../models';
|
|
4
|
+
export default function handle(config: Config, integration: IntegrationLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|