@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.
Files changed (79) hide show
  1. package/README.md +5 -9
  2. package/out/handlers/crowdin-file-progress.d.ts +4 -0
  3. package/out/handlers/crowdin-file-progress.js +22 -0
  4. package/out/handlers/crowdin-files.d.ts +4 -0
  5. package/out/handlers/crowdin-files.js +31 -0
  6. package/out/handlers/crowdin-project.d.ts +4 -0
  7. package/out/handlers/crowdin-project.js +22 -0
  8. package/out/handlers/crowdin-update.d.ts +4 -0
  9. package/out/handlers/crowdin-update.js +26 -0
  10. package/out/handlers/custom-file-format/download.d.ts +4 -0
  11. package/out/handlers/custom-file-format/download.js +32 -0
  12. package/out/handlers/custom-file-format/process.d.ts +4 -0
  13. package/out/handlers/custom-file-format/process.js +139 -0
  14. package/out/handlers/custom-mt/translate.d.ts +4 -0
  15. package/out/handlers/custom-mt/translate.js +42 -0
  16. package/out/handlers/install.d.ts +4 -0
  17. package/out/handlers/install.js +46 -0
  18. package/out/handlers/integration-data.d.ts +4 -0
  19. package/out/handlers/integration-data.js +21 -0
  20. package/out/handlers/integration-login.d.ts +4 -0
  21. package/out/handlers/integration-login.js +30 -0
  22. package/out/handlers/integration-logout.d.ts +4 -0
  23. package/out/handlers/integration-logout.js +23 -0
  24. package/out/handlers/integration-update.d.ts +4 -0
  25. package/out/handlers/integration-update.js +25 -0
  26. package/out/handlers/main.d.ts +4 -0
  27. package/out/handlers/main.js +64 -0
  28. package/out/handlers/manifest.d.ts +3 -0
  29. package/out/handlers/manifest.js +126 -0
  30. package/out/handlers/oauth-login.d.ts +4 -0
  31. package/out/handlers/oauth-login.js +69 -0
  32. package/out/handlers/settings-save.d.ts +4 -0
  33. package/out/handlers/settings-save.js +21 -0
  34. package/out/handlers/subscription-info.d.ts +3 -0
  35. package/out/handlers/subscription-info.js +15 -0
  36. package/out/handlers/subscription-paid.d.ts +4 -0
  37. package/out/handlers/subscription-paid.js +22 -0
  38. package/out/handlers/sync-settings-save.d.ts +4 -0
  39. package/out/handlers/sync-settings-save.js +29 -0
  40. package/out/handlers/sync-settings.d.ts +4 -0
  41. package/out/handlers/sync-settings.js +27 -0
  42. package/out/handlers/uninstall.d.ts +4 -0
  43. package/out/handlers/uninstall.js +27 -0
  44. package/out/index.d.ts +5 -0
  45. package/out/index.js +191 -0
  46. package/out/logo.png +0 -0
  47. package/out/middlewares/crowdin-client.d.ts +10 -0
  48. package/out/middlewares/crowdin-client.js +88 -0
  49. package/out/middlewares/integration-credentials.d.ts +4 -0
  50. package/out/middlewares/integration-credentials.js +39 -0
  51. package/out/middlewares/json-response.d.ts +2 -0
  52. package/out/middlewares/json-response.js +7 -0
  53. package/out/middlewares/ui-module.d.ts +4 -0
  54. package/out/middlewares/ui-module.js +39 -0
  55. package/out/models/index.d.ts +549 -0
  56. package/out/models/index.js +41 -0
  57. package/out/static/css/styles.css +57 -0
  58. package/out/static/js/main.js +130 -0
  59. package/out/static/js/polyfills/fetch.js +494 -0
  60. package/out/static/js/polyfills/promise.js +375 -0
  61. package/out/storage/index.d.ts +22 -0
  62. package/out/storage/index.js +319 -0
  63. package/out/util/connection.d.ts +10 -0
  64. package/out/util/connection.js +217 -0
  65. package/out/util/cron.d.ts +3 -0
  66. package/out/util/cron.js +103 -0
  67. package/out/util/defaults.d.ts +5 -0
  68. package/out/util/defaults.js +153 -0
  69. package/out/util/index.d.ts +11 -0
  70. package/out/util/index.js +105 -0
  71. package/out/views/install.handlebars +16 -0
  72. package/out/views/login.handlebars +115 -0
  73. package/out/views/main.handlebars +471 -0
  74. package/out/views/oauth.handlebars +4 -0
  75. package/out/views/partials/head.handlebars +20 -0
  76. package/out/views/subscription.handlebars +26 -0
  77. package/package.json +2 -2
  78. package/.github/workflows/basic.yml +0 -39
  79. package/.github/workflows/publish.yml +0 -34
package/out/index.js ADDED
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.createApp = exports.addCrowdinEndpoints = exports.Scope = void 0;
35
+ const express_1 = __importDefault(require("express"));
36
+ const express_handlebars_1 = __importDefault(require("express-handlebars"));
37
+ const cron = __importStar(require("node-cron"));
38
+ const path_1 = require("path");
39
+ const crowdin_file_progress_1 = __importDefault(require("./handlers/crowdin-file-progress"));
40
+ const crowdin_files_1 = __importDefault(require("./handlers/crowdin-files"));
41
+ const crowdin_project_1 = __importDefault(require("./handlers/crowdin-project"));
42
+ const crowdin_update_1 = __importDefault(require("./handlers/crowdin-update"));
43
+ const download_1 = __importDefault(require("./handlers/custom-file-format/download"));
44
+ const process_1 = __importDefault(require("./handlers/custom-file-format/process"));
45
+ const translate_1 = __importDefault(require("./handlers/custom-mt/translate"));
46
+ const install_1 = __importDefault(require("./handlers/install"));
47
+ const integration_data_1 = __importDefault(require("./handlers/integration-data"));
48
+ const integration_login_1 = __importDefault(require("./handlers/integration-login"));
49
+ const integration_logout_1 = __importDefault(require("./handlers/integration-logout"));
50
+ const integration_update_1 = __importDefault(require("./handlers/integration-update"));
51
+ const main_1 = __importDefault(require("./handlers/main"));
52
+ const manifest_1 = __importDefault(require("./handlers/manifest"));
53
+ const oauth_login_1 = __importDefault(require("./handlers/oauth-login"));
54
+ const settings_save_1 = __importDefault(require("./handlers/settings-save"));
55
+ const subscription_info_1 = __importDefault(require("./handlers/subscription-info"));
56
+ const subscription_paid_1 = __importDefault(require("./handlers/subscription-paid"));
57
+ const sync_settings_1 = __importDefault(require("./handlers/sync-settings"));
58
+ const sync_settings_save_1 = __importDefault(require("./handlers/sync-settings-save"));
59
+ const uninstall_1 = __importDefault(require("./handlers/uninstall"));
60
+ const crowdin_client_1 = __importStar(require("./middlewares/crowdin-client"));
61
+ const integration_credentials_1 = __importDefault(require("./middlewares/integration-credentials"));
62
+ const json_response_1 = __importDefault(require("./middlewares/json-response"));
63
+ const ui_module_1 = __importDefault(require("./middlewares/ui-module"));
64
+ const storage = __importStar(require("./storage"));
65
+ const connection_1 = require("./util/connection");
66
+ const cron_1 = require("./util/cron");
67
+ const defaults_1 = require("./util/defaults");
68
+ var models_1 = require("./models");
69
+ Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return models_1.Scope; } });
70
+ function addCrowdinEndpoints(app, config) {
71
+ storage.connect(config.dbFolder);
72
+ app.use(express_1.default.json({ limit: '50mb' }));
73
+ app.use('/assets', express_1.default.static((0, path_1.join)(__dirname, 'static')));
74
+ app.set('views', (0, path_1.join)(__dirname, 'views'));
75
+ app.engine('handlebars', (0, express_handlebars_1.default)({
76
+ layoutsDir: '',
77
+ defaultLayout: '',
78
+ helpers: {
79
+ ifeq: function (a, b, options) {
80
+ if (a === b) {
81
+ return options.fn(this);
82
+ }
83
+ return options.inverse(this);
84
+ },
85
+ checkLength: function (a, b, options) {
86
+ if (a.length > b) {
87
+ return options.fn(this);
88
+ }
89
+ return options.inverse(this);
90
+ },
91
+ },
92
+ }));
93
+ app.set('view engine', 'handlebars');
94
+ app.get('/logo.png', (req, res) => res.sendFile(config.imagePath || (0, path_1.join)(__dirname, 'logo.png')));
95
+ app.post('/installed', (0, install_1.default)(config));
96
+ app.post('/uninstall', (0, uninstall_1.default)(config));
97
+ app.get('/manifest.json', json_response_1.default, (0, manifest_1.default)(config));
98
+ if (!(0, connection_1.isAppFree)(config)) {
99
+ app.post('/subscription-paid', (0, subscription_paid_1.default)(config));
100
+ }
101
+ const integrationLogic = config.projectIntegration;
102
+ if (integrationLogic) {
103
+ (0, defaults_1.applyDefaults)(config, integrationLogic);
104
+ app.get('/logo/integration/logo.png', (req, res) => res.sendFile(integrationLogic.imagePath || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')));
105
+ app.get('/', (0, crowdin_client_1.default)(config, true, false), (0, integration_credentials_1.default)(config, integrationLogic, true), (0, main_1.default)(config, integrationLogic));
106
+ app.get('/api/subscription-info', json_response_1.default, (0, crowdin_client_1.default)(config), (0, subscription_info_1.default)(config));
107
+ app.post('/api/settings', (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, settings_save_1.default)(config));
108
+ app.post('/api/login', (0, crowdin_client_1.default)(config, false, false), (0, integration_login_1.default)(config, integrationLogic));
109
+ app.post('/api/logout', (0, crowdin_client_1.default)(config, false, false), (0, integration_logout_1.default)(config));
110
+ app.get('/api/crowdin/files', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, crowdin_files_1.default)(config, integrationLogic));
111
+ app.get('/api/crowdin/project', json_response_1.default, (0, crowdin_client_1.default)(config), (0, crowdin_project_1.default)(config));
112
+ app.get('/api/crowdin/file-progress/:fileId', (0, crowdin_client_1.default)(config), (0, crowdin_file_progress_1.default)(config));
113
+ app.get('/api/integration/data', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, integration_data_1.default)(config, integrationLogic));
114
+ app.post('/api/crowdin/update', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, crowdin_update_1.default)(config, integrationLogic));
115
+ app.post('/api/integration/update', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, integration_update_1.default)(config, integrationLogic));
116
+ app.get('/api/sync-settings/:provider', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, sync_settings_1.default)(config));
117
+ app.post('/api/sync-settings', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, sync_settings_save_1.default)(config));
118
+ if (integrationLogic.oauthLogin) {
119
+ app.get((0, defaults_1.getOauthRoute)(integrationLogic), (0, oauth_login_1.default)(config, integrationLogic));
120
+ }
121
+ if (integrationLogic.cronJobs) {
122
+ integrationLogic.cronJobs.forEach(job => {
123
+ cron.schedule(job.expression, () => (0, cron_1.runJob)(config, integrationLogic, job).catch(console.error));
124
+ });
125
+ }
126
+ if (integrationLogic.withCronSync) {
127
+ cron.schedule('0 * * * *', () => (0, cron_1.filesCron)(config, integrationLogic, '1').catch(console.error));
128
+ cron.schedule('0 */3 * * *', () => (0, cron_1.filesCron)(config, integrationLogic, '3').catch(console.error));
129
+ cron.schedule('0 */6 * * *', () => (0, cron_1.filesCron)(config, integrationLogic, '6').catch(console.error));
130
+ cron.schedule('0 */12 * * *', () => (0, cron_1.filesCron)(config, integrationLogic, '12').catch(console.error));
131
+ cron.schedule('0 0 * * *', () => (0, cron_1.filesCron)(config, integrationLogic, '24').catch(console.error));
132
+ }
133
+ }
134
+ if (config.customFileFormat) {
135
+ app.post('/process', (0, crowdin_client_1.default)(config), (0, process_1.default)(config, config.baseUrl, config.customFileFormat.filesFolder || config.dbFolder, config.customFileFormat));
136
+ app.get('/file/download', (0, download_1.default)(config, config.customFileFormat.filesFolder || config.dbFolder));
137
+ }
138
+ if (config.customMT) {
139
+ app.post('/translate', (0, crowdin_client_1.default)(config), (0, translate_1.default)(config, config.customMT));
140
+ }
141
+ if (config.profileResourcesMenu) {
142
+ app.get('/logo/resources/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.profileResourcesMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
143
+ app.use('/resources', (0, ui_module_1.default)(config), express_1.default.static(config.profileResourcesMenu.uiPath));
144
+ }
145
+ if (config.organizationMenu) {
146
+ app.get('/logo/resources/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.organizationMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
147
+ app.use('/resources', (0, ui_module_1.default)(config), express_1.default.static(config.organizationMenu.uiPath));
148
+ }
149
+ if (config.editorRightPanel) {
150
+ app.use('/editor-panels', (0, ui_module_1.default)(config), express_1.default.static(config.editorRightPanel.uiPath));
151
+ }
152
+ if (config.projectMenu) {
153
+ app.use('/project-menu', (0, ui_module_1.default)(config), express_1.default.static(config.projectMenu.uiPath));
154
+ }
155
+ if (config.projectTools) {
156
+ app.get('/logo/tools/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.projectTools) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
157
+ app.use('/tools', (0, ui_module_1.default)(config), express_1.default.static(config.projectTools.uiPath));
158
+ }
159
+ if (config.projectReports) {
160
+ app.get('/logo/reports/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.projectReports) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
161
+ app.use('/reports', (0, ui_module_1.default)(config), express_1.default.static(config.projectReports.uiPath));
162
+ }
163
+ return {
164
+ getMetadata: storage.getMetadata,
165
+ saveMetadata: (id, metadata) => __awaiter(this, void 0, void 0, function* () {
166
+ const existing = yield storage.getMetadata(id);
167
+ if (existing) {
168
+ yield storage.updateMetadata(id, metadata);
169
+ }
170
+ else {
171
+ yield storage.saveMetadata(id, metadata);
172
+ }
173
+ }),
174
+ deleteMetadata: storage.deleteMetadata,
175
+ getUserSettings: (clientId) => __awaiter(this, void 0, void 0, function* () {
176
+ const integrationCredentials = yield storage.getIntegrationCredentials(clientId);
177
+ if (integrationCredentials === null || integrationCredentials === void 0 ? void 0 : integrationCredentials.config) {
178
+ return JSON.parse(integrationCredentials.config);
179
+ }
180
+ }),
181
+ establishCrowdinConnection: jwtToken => (0, crowdin_client_1.prepareCrowdinRequest)(jwtToken, config),
182
+ };
183
+ }
184
+ exports.addCrowdinEndpoints = addCrowdinEndpoints;
185
+ function createApp(config) {
186
+ const app = (0, express_1.default)();
187
+ addCrowdinEndpoints(app, config);
188
+ /* eslint no-console: "off" */
189
+ app.listen(config.port || 3000, () => console.log(`App started on port ${config.port || 3000}`));
190
+ }
191
+ exports.createApp = createApp;
package/out/logo.png ADDED
Binary file
@@ -0,0 +1,10 @@
1
+ /// <reference types="qs" />
2
+ import Crowdin from '@crowdin/crowdin-api-client';
3
+ import { Response } from 'express';
4
+ import { Config, CrowdinContextInfo, SubscriptionInfo } from '../models';
5
+ export declare function prepareCrowdinRequest(jwtToken: string, config: Config, optional?: boolean, checkSubscriptionExpiration?: boolean): Promise<{
6
+ context: CrowdinContextInfo;
7
+ client?: Crowdin;
8
+ subscriptionInfo?: SubscriptionInfo;
9
+ }>;
10
+ export default function handle(config: Config, optional?: boolean, checkSubscriptionExpiration?: 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,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,2 @@
1
+ import { Request, Response } from 'express';
2
+ export default function handle(_req: Request, res: Response, next: Function): void;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function handle(_req, res, next) {
4
+ res.header('Content-Type', 'application/json');
5
+ next();
6
+ }
7
+ 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;