@crowdin/app-project-module 0.13.1 → 0.13.3
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 +3 -0
- package/out/handlers/custom-mt/translate.js +15 -7
- package/out/handlers/oauth-login.js +34 -28
- package/out/util/index.d.ts +1 -0
- package/out/util/index.js +16 -12
- package/out/views/login.handlebars +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -483,6 +483,9 @@ const configuration = {
|
|
|
483
483
|
translate: async (client, context, projectId, source, target, strings) => {
|
|
484
484
|
//translate strings
|
|
485
485
|
const translations = ['hello', 'world'];
|
|
486
|
+
if (source === 'fr') {
|
|
487
|
+
throw 'Source language is not supported by the model';
|
|
488
|
+
}
|
|
486
489
|
return translations;
|
|
487
490
|
}
|
|
488
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
|
}
|
|
@@ -17,38 +17,44 @@ const util_1 = require("../util");
|
|
|
17
17
|
function handle(config, integration) {
|
|
18
18
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
20
|
-
const code = req.query[((_b = (_a = integration.oauthLogin) === null || _a === void 0 ? void 0 : _a.fieldsMapping) === null || _b === void 0 ? void 0 : _b.code) || 'code'];
|
|
21
|
-
const oauthLogin = integration.oauthLogin;
|
|
22
|
-
let credentials;
|
|
23
|
-
if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.performGetTokenRequest) {
|
|
24
|
-
credentials = yield oauthLogin.performGetTokenRequest(code);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const request = {};
|
|
28
|
-
const oauthLogin = integration.oauthLogin;
|
|
29
|
-
request[((_c = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _c === void 0 ? void 0 : _c.code) || 'code'] = code;
|
|
30
|
-
request[((_d = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _d === void 0 ? void 0 : _d.clientId) || 'client_id'] = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.clientId;
|
|
31
|
-
request[((_e = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _e === void 0 ? void 0 : _e.clientSecret) || 'client_secret'] = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.clientSecret;
|
|
32
|
-
request[((_f = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _f === void 0 ? void 0 : _f.redirectUri) || 'redirect_uri'] = `${config.baseUrl}${(0, util_1.getOauthRoute)(integration)}`;
|
|
33
|
-
if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.extraAccessTokenParameters) {
|
|
34
|
-
Object.entries(oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.extraAccessTokenParameters).forEach(([key, value]) => (request[key] = value));
|
|
35
|
-
}
|
|
36
|
-
credentials = (yield axios_1.default.post(((_g = integration.oauthLogin) === null || _g === void 0 ? void 0 : _g.accessTokenUrl) || '', request, {
|
|
37
|
-
headers: { Accept: 'application/json' },
|
|
38
|
-
})).data;
|
|
39
|
-
}
|
|
40
20
|
const message = {
|
|
41
21
|
uid: 'oauth_popup',
|
|
42
22
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
23
|
+
try {
|
|
24
|
+
const code = req.query[((_b = (_a = integration.oauthLogin) === null || _a === void 0 ? void 0 : _a.fieldsMapping) === null || _b === void 0 ? void 0 : _b.code) || 'code'];
|
|
25
|
+
const oauthLogin = integration.oauthLogin;
|
|
26
|
+
let credentials;
|
|
27
|
+
if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.performGetTokenRequest) {
|
|
28
|
+
credentials = yield oauthLogin.performGetTokenRequest(code);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const request = {};
|
|
32
|
+
const oauthLogin = integration.oauthLogin;
|
|
33
|
+
request[((_c = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _c === void 0 ? void 0 : _c.code) || 'code'] = code;
|
|
34
|
+
request[((_d = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _d === void 0 ? void 0 : _d.clientId) || 'client_id'] = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.clientId;
|
|
35
|
+
request[((_e = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _e === void 0 ? void 0 : _e.clientSecret) || 'client_secret'] = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.clientSecret;
|
|
36
|
+
request[((_f = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _f === void 0 ? void 0 : _f.redirectUri) || 'redirect_uri'] = `${config.baseUrl}${(0, util_1.getOauthRoute)(integration)}`;
|
|
37
|
+
if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.extraAccessTokenParameters) {
|
|
38
|
+
Object.entries(oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.extraAccessTokenParameters).forEach(([key, value]) => (request[key] = value));
|
|
39
|
+
}
|
|
40
|
+
credentials = (yield axios_1.default.post(((_g = integration.oauthLogin) === null || _g === void 0 ? void 0 : _g.accessTokenUrl) || '', request, {
|
|
41
|
+
headers: { Accept: 'application/json' },
|
|
42
|
+
})).data;
|
|
43
|
+
}
|
|
44
|
+
const oauthCredentials = {};
|
|
45
|
+
oauthCredentials.accessToken = credentials[((_h = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _h === void 0 ? void 0 : _h.accessToken) || 'access_token'];
|
|
46
|
+
if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.refresh) {
|
|
47
|
+
oauthCredentials.refreshToken = credentials[((_j = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _j === void 0 ? void 0 : _j.refreshToken) || 'refresh_token'];
|
|
48
|
+
oauthCredentials.expireIn =
|
|
49
|
+
Number(credentials[((_k = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _k === void 0 ? void 0 : _k.expiresIn) || 'expires_in']) + Date.now() / 1000;
|
|
50
|
+
}
|
|
51
|
+
message.data = oauthCredentials;
|
|
52
|
+
return res.render('oauth', { message: JSON.stringify(message) });
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
message.data = { error: (0, util_1.getMessage)(e) };
|
|
56
|
+
return res.render('oauth', { message: JSON.stringify(message) });
|
|
49
57
|
}
|
|
50
|
-
message.data = oauthCredentials;
|
|
51
|
-
return res.render('oauth', { message: JSON.stringify(message) });
|
|
52
58
|
}), config.onError);
|
|
53
59
|
}
|
|
54
60
|
exports.default = handle;
|
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) {
|
|
@@ -65,9 +65,13 @@
|
|
|
65
65
|
|
|
66
66
|
function oauthLogin() {
|
|
67
67
|
const url = '{{{ oauthUrl }}}';
|
|
68
|
-
const oauthWindow = window.open(url, '{{ name }}', 'location=0,status=0,width=800,height=400');
|
|
68
|
+
const oauthWindow = window.open(url, '{{ name }}', 'location=0,status=0,width=800,height=400');
|
|
69
69
|
postPromises['oauth_popup'] = {
|
|
70
70
|
resolve: (data) => {
|
|
71
|
+
if (data.error) {
|
|
72
|
+
showToast(data.error);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
71
75
|
integrationLogin({
|
|
72
76
|
refreshToken: data.refreshToken,
|
|
73
77
|
accessToken: data.accessToken,
|
package/package.json
CHANGED