@crowdin/app-project-module 0.13.0 → 0.13.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.
- package/README.md +7 -0
- package/out/handlers/custom-mt/translate.js +15 -7
- package/out/handlers/manifest.js +2 -1
- package/out/index.d.ts +1 -0
- package/out/index.js +3 -1
- package/out/models/index.d.ts +19 -0
- package/out/models/index.js +17 -1
- package/out/util/index.d.ts +1 -0
- package/out/util/index.js +16 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,10 @@ const configuration = {
|
|
|
67
67
|
baseUrl: 'https://123.ngrok.io',
|
|
68
68
|
clientId: 'clientId',
|
|
69
69
|
clientSecret: 'clientSecret',
|
|
70
|
+
scopes: [
|
|
71
|
+
crowdinModule.Scope.PROJECTS,
|
|
72
|
+
crowdinModule.Scope.TRANSLATION_MEMORIES
|
|
73
|
+
],
|
|
70
74
|
name: 'Sample App',
|
|
71
75
|
identifier: 'sample-app',
|
|
72
76
|
description: 'Sample App description',
|
|
@@ -479,6 +483,9 @@ const configuration = {
|
|
|
479
483
|
translate: async (client, context, projectId, source, target, strings) => {
|
|
480
484
|
//translate strings
|
|
481
485
|
const translations = ['hello', 'world'];
|
|
486
|
+
if (source === 'fr') {
|
|
487
|
+
throw 'Source language is not supported by the model';
|
|
488
|
+
}
|
|
482
489
|
return translations;
|
|
483
490
|
}
|
|
484
491
|
}
|
|
@@ -16,15 +16,23 @@ function handle(baseConfig, config) {
|
|
|
16
16
|
const target = req.query.target;
|
|
17
17
|
const body = req.body;
|
|
18
18
|
const projectId = Number(req.query.project_id);
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
19
|
+
try {
|
|
20
|
+
if (source === 'en' && target === 'de' && body.strings && body.strings[0] === 'validation') {
|
|
21
|
+
if (config.validate) {
|
|
22
|
+
yield config.validate(req.crowdinApiClient);
|
|
23
|
+
}
|
|
24
|
+
res.send({ data: { translations: [] } });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const translations = yield config.translate(req.crowdinApiClient, req.crowdinContext, projectId, source, target, body.strings);
|
|
28
|
+
res.send({ data: { translations } });
|
|
22
29
|
}
|
|
23
|
-
res.send({ data: { translations: [] } });
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
res.send({
|
|
31
|
+
catch (e) {
|
|
32
|
+
const message = (0, util_1.getMessage)(e);
|
|
33
|
+
res.send({
|
|
34
|
+
error: { message },
|
|
35
|
+
});
|
|
28
36
|
}
|
|
29
37
|
}), baseConfig.onError);
|
|
30
38
|
}
|
package/out/handlers/manifest.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const models_1 = require("../models");
|
|
3
4
|
function handle(config) {
|
|
4
5
|
const modules = {};
|
|
5
6
|
// TEMPORARY CODE drop on step 3 of CN-30453
|
|
@@ -179,7 +180,7 @@ function handle(config) {
|
|
|
179
180
|
installed: '/installed',
|
|
180
181
|
uninstall: '/uninstall',
|
|
181
182
|
},
|
|
182
|
-
scopes: [
|
|
183
|
+
scopes: config.scopes ? config.scopes : [models_1.Scope.PROJECTS],
|
|
183
184
|
modules,
|
|
184
185
|
};
|
|
185
186
|
res.send(manifest);
|
package/out/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Express } from 'express';
|
|
2
2
|
import { Config, CrowdinAppUtilities } from './models';
|
|
3
|
+
export { Scope } from './models';
|
|
3
4
|
export declare function addCrowdinEndpoints(app: Express, config: Config): CrowdinAppUtilities;
|
|
4
5
|
export declare function createApp(config: Config): void;
|
package/out/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.createApp = exports.addCrowdinEndpoints = void 0;
|
|
34
|
+
exports.createApp = exports.addCrowdinEndpoints = exports.Scope = void 0;
|
|
35
35
|
const express_1 = __importDefault(require("express"));
|
|
36
36
|
const express_handlebars_1 = __importDefault(require("express-handlebars"));
|
|
37
37
|
const cron = __importStar(require("node-cron"));
|
|
@@ -60,6 +60,8 @@ const integration_credentials_1 = __importDefault(require("./middlewares/integra
|
|
|
60
60
|
const json_response_1 = __importDefault(require("./middlewares/json-response"));
|
|
61
61
|
const storage = __importStar(require("./storage"));
|
|
62
62
|
const util_1 = require("./util");
|
|
63
|
+
var models_1 = require("./models");
|
|
64
|
+
Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return models_1.Scope; } });
|
|
63
65
|
function addCrowdinEndpoints(app, config) {
|
|
64
66
|
storage.connect(config.dbFolder);
|
|
65
67
|
app.use(express_1.default.json({ limit: '50mb' }));
|
package/out/models/index.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ export interface Config extends ImagePath {
|
|
|
14
14
|
* https url where an app is reachable from the internet (e.g. the one that ngrok generates for us)
|
|
15
15
|
*/
|
|
16
16
|
baseUrl: string;
|
|
17
|
+
/**
|
|
18
|
+
* Set of scopes requested by this app (default 'project')
|
|
19
|
+
*/
|
|
20
|
+
scopes?: Scope[];
|
|
17
21
|
/**
|
|
18
22
|
* app name
|
|
19
23
|
*/
|
|
@@ -99,6 +103,21 @@ export interface Config extends ImagePath {
|
|
|
99
103
|
*/
|
|
100
104
|
onError?: (error: any) => void;
|
|
101
105
|
}
|
|
106
|
+
export declare enum Scope {
|
|
107
|
+
ALL_SCOPES = "all",
|
|
108
|
+
NOTIFICATIONS = "notification",
|
|
109
|
+
TRANSLATION_MEMORIES = "tm",
|
|
110
|
+
MACHINE_TRANSLATION_ENGINES = "mt",
|
|
111
|
+
GLOSSARIES = "glossary",
|
|
112
|
+
PROJECTS = "project",
|
|
113
|
+
TASKS = "project.task",
|
|
114
|
+
REPORTS = "project.report",
|
|
115
|
+
TRANSLATION_STATUS = "project.status",
|
|
116
|
+
SOURCE_FILES_AND_STRINGS = "project.source",
|
|
117
|
+
WEBHOOKS = "project.webhook",
|
|
118
|
+
TRANSLATIONS = "project.translation",
|
|
119
|
+
SCREENSHOTS = "project.screenshot"
|
|
120
|
+
}
|
|
102
121
|
export interface IntegrationLogic {
|
|
103
122
|
/**
|
|
104
123
|
* Customize your app login form
|
package/out/models/index.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EditorPanelsMode = exports.ProcessFileJobType = exports.AccountType = void 0;
|
|
3
|
+
exports.EditorPanelsMode = exports.ProcessFileJobType = exports.AccountType = exports.Scope = void 0;
|
|
4
|
+
var Scope;
|
|
5
|
+
(function (Scope) {
|
|
6
|
+
Scope["ALL_SCOPES"] = "all";
|
|
7
|
+
Scope["NOTIFICATIONS"] = "notification";
|
|
8
|
+
Scope["TRANSLATION_MEMORIES"] = "tm";
|
|
9
|
+
Scope["MACHINE_TRANSLATION_ENGINES"] = "mt";
|
|
10
|
+
Scope["GLOSSARIES"] = "glossary";
|
|
11
|
+
Scope["PROJECTS"] = "project";
|
|
12
|
+
Scope["TASKS"] = "project.task";
|
|
13
|
+
Scope["REPORTS"] = "project.report";
|
|
14
|
+
Scope["TRANSLATION_STATUS"] = "project.status";
|
|
15
|
+
Scope["SOURCE_FILES_AND_STRINGS"] = "project.source";
|
|
16
|
+
Scope["WEBHOOKS"] = "project.webhook";
|
|
17
|
+
Scope["TRANSLATIONS"] = "project.translation";
|
|
18
|
+
Scope["SCREENSHOTS"] = "project.screenshot";
|
|
19
|
+
})(Scope = exports.Scope || (exports.Scope = {}));
|
|
4
20
|
var AccountType;
|
|
5
21
|
(function (AccountType) {
|
|
6
22
|
AccountType["NORMAL"] = "normal";
|
package/out/util/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class CodeError extends Error {
|
|
|
5
5
|
code: number | undefined;
|
|
6
6
|
constructor(message: string, code?: number);
|
|
7
7
|
}
|
|
8
|
+
export declare function getMessage(err: any): any;
|
|
8
9
|
export declare function runAsyncWrapper(callback: Function, onError?: (e: any) => void): (req: Request, res: Response, next: Function) => void;
|
|
9
10
|
export declare function encryptData(secret: string, data: string): string;
|
|
10
11
|
export declare function decryptData(secret: string, data: string): string;
|
package/out/util/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.filesCron = exports.runJob = exports.prepareIntegrationCredentials = exports.prepareCrowdinClient = exports.applyDefaults = exports.getRootFolder = exports.getOauthRoute = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.CodeError = void 0;
|
|
34
|
+
exports.filesCron = exports.runJob = exports.prepareIntegrationCredentials = exports.prepareCrowdinClient = exports.applyDefaults = exports.getRootFolder = exports.getOauthRoute = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.getMessage = exports.CodeError = void 0;
|
|
35
35
|
const crowdin_api_client_1 = __importDefault(require("@crowdin/crowdin-api-client"));
|
|
36
36
|
const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
|
|
37
37
|
const axios_1 = __importDefault(require("axios"));
|
|
@@ -48,6 +48,20 @@ exports.CodeError = CodeError;
|
|
|
48
48
|
function isCrowdinClientRequest(req) {
|
|
49
49
|
return req.crowdinContext;
|
|
50
50
|
}
|
|
51
|
+
function getMessage(err) {
|
|
52
|
+
let message;
|
|
53
|
+
if (typeof err === 'string') {
|
|
54
|
+
message = err;
|
|
55
|
+
}
|
|
56
|
+
else if (err.message) {
|
|
57
|
+
message = err.message;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
message = JSON.stringify(err);
|
|
61
|
+
}
|
|
62
|
+
return message;
|
|
63
|
+
}
|
|
64
|
+
exports.getMessage = getMessage;
|
|
51
65
|
function handleError(err, req, res) {
|
|
52
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
67
|
const code = err.code ? err.code : 500;
|
|
@@ -58,17 +72,7 @@ function handleError(err, req, res) {
|
|
|
58
72
|
res.redirect('/');
|
|
59
73
|
return;
|
|
60
74
|
}
|
|
61
|
-
|
|
62
|
-
if (typeof err === 'string') {
|
|
63
|
-
message = err;
|
|
64
|
-
}
|
|
65
|
-
else if (err.message) {
|
|
66
|
-
message = err.message;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
message = JSON.stringify(err);
|
|
70
|
-
}
|
|
71
|
-
res.status(code).send({ message, code });
|
|
75
|
+
res.status(code).send({ message: getMessage(err), code });
|
|
72
76
|
});
|
|
73
77
|
}
|
|
74
78
|
function runAsyncWrapper(callback, onError) {
|
package/package.json
CHANGED