@crowdin/app-project-module 0.17.6 → 0.17.7
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/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 +45 -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 +544 -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 +211 -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 +1 -1
- package/.github/workflows/basic.yml +0 -39
- package/.github/workflows/publish.yml +0 -34
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
exports.prepareCrowdinRequest = void 0;
|
|
13
|
+
const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
|
|
14
|
+
const storage_1 = require("../storage");
|
|
15
|
+
const util_1 = require("../util");
|
|
16
|
+
const connection_1 = require("../util/connection");
|
|
17
|
+
function getToken(req) {
|
|
18
|
+
const tokenJwt = (req.query.tokenJwt || req.query.jwtToken);
|
|
19
|
+
if (tokenJwt) {
|
|
20
|
+
return tokenJwt;
|
|
21
|
+
}
|
|
22
|
+
if (req.headers.authorization) {
|
|
23
|
+
if (req.headers.authorization.startsWith('Bearer ') || req.headers.authorization.startsWith('bearer ')) {
|
|
24
|
+
return req.headers.authorization.substring(7);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function prepareCrowdinRequest(jwtToken, config, optional = false, checkSubscriptionExpiration = true) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
(0, util_1.log)('Validating jwt token from incoming request', config.logger);
|
|
31
|
+
const jwtPayload = yield (0, crowdin_apps_functions_1.validateJwtToken)(jwtToken, config.clientSecret);
|
|
32
|
+
const context = {
|
|
33
|
+
jwtPayload,
|
|
34
|
+
clientId: (0, crowdin_apps_functions_1.constructCrowdinIdFromJwtPayload)(jwtPayload),
|
|
35
|
+
crowdinId: `${jwtPayload.domain || jwtPayload.context.organization_id}`,
|
|
36
|
+
};
|
|
37
|
+
(0, util_1.log)('Loading crowdin credentials', config.logger);
|
|
38
|
+
const credentials = yield (0, storage_1.getCrowdinCredentials)(context.crowdinId);
|
|
39
|
+
if (!credentials) {
|
|
40
|
+
if (optional) {
|
|
41
|
+
return { context };
|
|
42
|
+
}
|
|
43
|
+
throw new Error("Can't find organization by id");
|
|
44
|
+
}
|
|
45
|
+
(0, util_1.log)('Building crowdin client instance', config.logger);
|
|
46
|
+
const { client, token } = yield (0, connection_1.prepareCrowdinClient)(config, credentials);
|
|
47
|
+
let subscriptionInfo;
|
|
48
|
+
if (checkSubscriptionExpiration) {
|
|
49
|
+
subscriptionInfo = yield (0, connection_1.checkSubscription)(config, token, credentials.id, credentials.type);
|
|
50
|
+
if (subscriptionInfo.expired) {
|
|
51
|
+
throw new util_1.CodeError(subscriptionInfo.subscribeLink || '', 402);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { context, client, subscriptionInfo };
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.prepareCrowdinRequest = prepareCrowdinRequest;
|
|
58
|
+
function handle(config, optional = false, checkSubscriptionExpiration = true) {
|
|
59
|
+
return (0, util_1.runAsyncWrapper)((req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const tokenJwt = getToken(req);
|
|
61
|
+
if (!tokenJwt) {
|
|
62
|
+
return res.status(403).send({ error: 'Access denied' });
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const data = yield prepareCrowdinRequest(tokenJwt, config, optional, checkSubscriptionExpiration);
|
|
66
|
+
req.crowdinContext = data.context;
|
|
67
|
+
if (data.client) {
|
|
68
|
+
req.crowdinApiClient = data.client;
|
|
69
|
+
}
|
|
70
|
+
req.subscriptionInfo = data.subscriptionInfo;
|
|
71
|
+
next();
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
if (e instanceof util_1.CodeError) {
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
if (config.onError) {
|
|
78
|
+
config.onError(e);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.error(e);
|
|
82
|
+
}
|
|
83
|
+
const message = typeof e === 'string' ? e : e.message;
|
|
84
|
+
return res.status(403).send({ error: message || 'Error' });
|
|
85
|
+
}
|
|
86
|
+
}), config.onError);
|
|
87
|
+
}
|
|
88
|
+
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, optional?: boolean): (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,39 @@
|
|
|
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, integration, optional = false) {
|
|
16
|
+
return (0, util_1.runAsyncWrapper)((req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const clientId = req.crowdinContext.clientId;
|
|
18
|
+
(0, util_1.log)(`Loading integration credentials for client ${clientId}`, config.logger);
|
|
19
|
+
const integrationCredentials = yield (0, storage_1.getIntegrationCredentials)(clientId);
|
|
20
|
+
if (!integrationCredentials) {
|
|
21
|
+
if (optional) {
|
|
22
|
+
return next();
|
|
23
|
+
}
|
|
24
|
+
return res.status(403).send({ error: 'Access denied' });
|
|
25
|
+
}
|
|
26
|
+
if (integrationCredentials.config) {
|
|
27
|
+
req.integrationSettings = JSON.parse(integrationCredentials.config);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
req.integrationCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
console.error(e);
|
|
34
|
+
throw new util_1.CodeError('Credentials to integration either exprired or invalid', 401);
|
|
35
|
+
}
|
|
36
|
+
next();
|
|
37
|
+
}), config.onError);
|
|
38
|
+
}
|
|
39
|
+
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,39 @@
|
|
|
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 storage_1 = require("../storage");
|
|
14
|
+
const util_1 = require("../util");
|
|
15
|
+
const connection_1 = require("../util/connection");
|
|
16
|
+
function handle(config) {
|
|
17
|
+
return (0, util_1.runAsyncWrapper)((req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const tokenJwt = req.query.tokenJwt;
|
|
19
|
+
if (!tokenJwt) {
|
|
20
|
+
return res.status(403).send({ error: 'Access denied' });
|
|
21
|
+
}
|
|
22
|
+
(0, util_1.log)('Validating jwt token from incoming request', config.logger);
|
|
23
|
+
const jwtPayload = yield (0, crowdin_apps_functions_1.validateJwtToken)(tokenJwt, config.clientSecret);
|
|
24
|
+
const id = `${jwtPayload.domain || jwtPayload.context.organization_id}`;
|
|
25
|
+
(0, util_1.log)('Loading crowdin credentials', config.logger);
|
|
26
|
+
const credentials = yield (0, storage_1.getCrowdinCredentials)(id);
|
|
27
|
+
if (!credentials) {
|
|
28
|
+
throw new Error("Can't find organization by id");
|
|
29
|
+
}
|
|
30
|
+
(0, util_1.log)('Building crowdin client instance', config.logger);
|
|
31
|
+
const { token } = yield (0, connection_1.prepareCrowdinClient)(config, credentials);
|
|
32
|
+
const { expired, subscribeLink } = yield (0, connection_1.checkSubscription)(config, token, credentials.id, credentials.type);
|
|
33
|
+
if (expired) {
|
|
34
|
+
return res.render('subscription', { subscribeLink });
|
|
35
|
+
}
|
|
36
|
+
next();
|
|
37
|
+
}), config.onError);
|
|
38
|
+
}
|
|
39
|
+
exports.default = handle;
|