@crowdin/app-project-module 0.17.3 → 0.17.5

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 (77) hide show
  1. package/.github/workflows/basic.yml +39 -0
  2. package/.github/workflows/publish.yml +34 -0
  3. package/README.md +2 -1
  4. package/package.json +1 -1
  5. package/out/handlers/crowdin-file-progress.d.ts +0 -4
  6. package/out/handlers/crowdin-file-progress.js +0 -22
  7. package/out/handlers/crowdin-files.d.ts +0 -4
  8. package/out/handlers/crowdin-files.js +0 -31
  9. package/out/handlers/crowdin-project.d.ts +0 -4
  10. package/out/handlers/crowdin-project.js +0 -22
  11. package/out/handlers/crowdin-update.d.ts +0 -4
  12. package/out/handlers/crowdin-update.js +0 -26
  13. package/out/handlers/custom-file-format/download.d.ts +0 -4
  14. package/out/handlers/custom-file-format/download.js +0 -32
  15. package/out/handlers/custom-file-format/process.d.ts +0 -4
  16. package/out/handlers/custom-file-format/process.js +0 -134
  17. package/out/handlers/custom-mt/translate.d.ts +0 -4
  18. package/out/handlers/custom-mt/translate.js +0 -42
  19. package/out/handlers/install.d.ts +0 -4
  20. package/out/handlers/install.js +0 -45
  21. package/out/handlers/integration-data.d.ts +0 -4
  22. package/out/handlers/integration-data.js +0 -21
  23. package/out/handlers/integration-login.d.ts +0 -4
  24. package/out/handlers/integration-login.js +0 -30
  25. package/out/handlers/integration-logout.d.ts +0 -4
  26. package/out/handlers/integration-logout.js +0 -23
  27. package/out/handlers/integration-update.d.ts +0 -4
  28. package/out/handlers/integration-update.js +0 -25
  29. package/out/handlers/main.d.ts +0 -4
  30. package/out/handlers/main.js +0 -64
  31. package/out/handlers/manifest.d.ts +0 -3
  32. package/out/handlers/manifest.js +0 -120
  33. package/out/handlers/oauth-login.d.ts +0 -4
  34. package/out/handlers/oauth-login.js +0 -69
  35. package/out/handlers/settings-save.d.ts +0 -4
  36. package/out/handlers/settings-save.js +0 -21
  37. package/out/handlers/subscription-info.d.ts +0 -3
  38. package/out/handlers/subscription-info.js +0 -15
  39. package/out/handlers/sync-settings-save.d.ts +0 -4
  40. package/out/handlers/sync-settings-save.js +0 -29
  41. package/out/handlers/sync-settings.d.ts +0 -4
  42. package/out/handlers/sync-settings.js +0 -27
  43. package/out/handlers/uninstall.d.ts +0 -4
  44. package/out/handlers/uninstall.js +0 -27
  45. package/out/index.d.ts +0 -5
  46. package/out/index.js +0 -186
  47. package/out/logo.png +0 -0
  48. package/out/middlewares/crowdin-client.d.ts +0 -10
  49. package/out/middlewares/crowdin-client.js +0 -88
  50. package/out/middlewares/integration-credentials.d.ts +0 -4
  51. package/out/middlewares/integration-credentials.js +0 -39
  52. package/out/middlewares/json-response.d.ts +0 -2
  53. package/out/middlewares/json-response.js +0 -7
  54. package/out/middlewares/ui-module.d.ts +0 -4
  55. package/out/middlewares/ui-module.js +0 -39
  56. package/out/models/index.d.ts +0 -534
  57. package/out/models/index.js +0 -41
  58. package/out/static/css/styles.css +0 -57
  59. package/out/static/js/main.js +0 -130
  60. package/out/static/js/polyfills/fetch.js +0 -494
  61. package/out/static/js/polyfills/promise.js +0 -375
  62. package/out/storage/index.d.ts +0 -22
  63. package/out/storage/index.js +0 -319
  64. package/out/util/connection.d.ts +0 -10
  65. package/out/util/connection.js +0 -213
  66. package/out/util/cron.d.ts +0 -3
  67. package/out/util/cron.js +0 -103
  68. package/out/util/defaults.d.ts +0 -5
  69. package/out/util/defaults.js +0 -153
  70. package/out/util/index.d.ts +0 -11
  71. package/out/util/index.js +0 -105
  72. package/out/views/install.handlebars +0 -16
  73. package/out/views/login.handlebars +0 -115
  74. package/out/views/main.handlebars +0 -471
  75. package/out/views/oauth.handlebars +0 -4
  76. package/out/views/partials/head.handlebars +0 -20
  77. package/out/views/subscription.handlebars +0 -26
@@ -1,88 +0,0 @@
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;
@@ -1,4 +0,0 @@
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;
@@ -1,39 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- import { Request, Response } from 'express';
2
- export default function handle(_req: Request, res: Response, next: Function): void;
@@ -1,7 +0,0 @@
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;
@@ -1,4 +0,0 @@
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;
@@ -1,39 +0,0 @@
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;