@crowdin/app-project-module 0.44.0 → 0.45.1
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/index.d.ts +3 -3
- package/out/index.js +52 -59
- package/out/middlewares/crowdin-client.d.ts +1 -1
- package/out/middlewares/crowdin-client.js +3 -2
- package/out/middlewares/integration-credentials.d.ts +2 -2
- package/out/middlewares/render-ui-module.d.ts +2 -2
- package/out/middlewares/ui-module.d.ts +2 -2
- package/out/middlewares/ui-module.js +3 -3
- package/out/{util → modules}/api/api.d.ts +2 -1
- package/out/{util → modules}/api/api.js +22 -22
- package/out/modules/api/index.d.ts +6 -0
- package/out/modules/api/index.js +14 -0
- package/out/modules/api/types.d.ts +20 -0
- package/out/modules/api/types.js +11 -0
- package/out/modules/context-menu/index.d.ts +1 -1
- package/out/modules/context-menu/index.js +2 -2
- package/out/modules/context-menu/types.d.ts +27 -0
- package/out/modules/context-menu/types.js +18 -0
- package/out/modules/custom-mt/handlers/translate.d.ts +1 -1
- package/out/modules/custom-mt/index.d.ts +1 -1
- package/out/modules/custom-mt/types.d.ts +1 -1
- package/out/modules/custom-spell-check/handlers/get-languages-list.d.ts +1 -1
- package/out/modules/custom-spell-check/handlers/spell-check.d.ts +1 -1
- package/out/modules/custom-spell-check/index.d.ts +1 -1
- package/out/modules/custom-spell-check/index.js +2 -2
- package/out/modules/custom-spell-check/types.d.ts +1 -1
- package/out/modules/editor-right-panel/index.d.ts +1 -1
- package/out/modules/editor-right-panel/index.js +2 -2
- package/out/modules/editor-right-panel/types.d.ts +1 -1
- package/out/modules/editor-themes/index.d.ts +1 -1
- package/out/modules/editor-themes/types.d.ts +17 -0
- package/out/modules/editor-themes/types.js +2 -0
- package/out/modules/file-processing/handlers/custom-file-format.d.ts +1 -1
- package/out/modules/file-processing/handlers/custom-file-format.js +1 -1
- package/out/modules/file-processing/handlers/file-download.d.ts +2 -2
- package/out/modules/file-processing/handlers/pre-post-process.d.ts +1 -1
- package/out/modules/file-processing/handlers/pre-post-process.js +1 -1
- package/out/modules/file-processing/index.d.ts +1 -1
- package/out/modules/file-processing/index.js +1 -1
- package/out/modules/file-processing/types.d.ts +1 -1
- package/out/modules/file-processing/util/defaults.d.ts +3 -0
- package/out/modules/file-processing/util/defaults.js +30 -0
- package/out/modules/file-processing/util/files.d.ts +6 -0
- package/out/modules/file-processing/util/files.js +47 -0
- package/out/modules/form-data-display.d.ts +1 -1
- package/out/modules/form-data-save.d.ts +1 -1
- package/out/modules/install.d.ts +2 -2
- package/out/modules/install.js +3 -3
- package/out/modules/integration/handlers/crowdin-file-progress.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-files.d.ts +2 -2
- package/out/modules/integration/handlers/crowdin-files.js +1 -1
- package/out/modules/integration/handlers/crowdin-project.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-update.d.ts +2 -2
- package/out/modules/integration/handlers/crowdin-update.js +7 -7
- package/out/modules/integration/handlers/crowdin-webhook.d.ts +2 -2
- package/out/modules/integration/handlers/crowdin-webhook.js +16 -5
- package/out/modules/integration/handlers/integration-data.d.ts +1 -1
- package/out/modules/integration/handlers/integration-data.js +2 -2
- package/out/modules/integration/handlers/integration-login.d.ts +1 -1
- package/out/modules/integration/handlers/integration-logout.d.ts +2 -2
- package/out/modules/integration/handlers/integration-logout.js +11 -4
- package/out/modules/integration/handlers/integration-update.d.ts +2 -2
- package/out/modules/integration/handlers/integration-update.js +7 -6
- package/out/modules/integration/handlers/integration-webhook.d.ts +2 -2
- package/out/modules/integration/handlers/integration-webhook.js +7 -2
- package/out/modules/integration/handlers/job-cancel.d.ts +1 -1
- package/out/modules/integration/handlers/job-cancel.js +2 -2
- package/out/modules/integration/handlers/job-info.d.ts +1 -1
- package/out/modules/integration/handlers/job-info.js +2 -2
- package/out/modules/integration/handlers/main.d.ts +2 -2
- package/out/modules/integration/handlers/main.js +3 -3
- package/out/modules/integration/handlers/oauth-login.d.ts +2 -2
- package/out/modules/integration/handlers/oauth-login.js +1 -1
- package/out/modules/integration/handlers/oauth-url.d.ts +1 -1
- package/out/modules/integration/handlers/oauth-url.js +1 -1
- package/out/modules/integration/handlers/settings-save.d.ts +2 -2
- package/out/modules/integration/handlers/settings-save.js +25 -8
- package/out/modules/integration/handlers/settings.d.ts +1 -1
- package/out/modules/integration/handlers/subscription-info.d.ts +1 -1
- package/out/modules/integration/handlers/subscription-info.js +2 -2
- package/out/modules/integration/handlers/sync-settings-save.d.ts +2 -2
- package/out/modules/integration/handlers/sync-settings-save.js +15 -7
- package/out/modules/integration/handlers/sync-settings.d.ts +1 -1
- package/out/modules/integration/handlers/user-errors.d.ts +1 -1
- package/out/modules/integration/index.d.ts +1 -1
- package/out/modules/integration/index.js +15 -10
- package/out/modules/integration/types.d.ts +2 -13
- package/out/modules/integration/util/cron.d.ts +27 -0
- package/out/{util → modules/integration/util}/cron.js +92 -23
- package/out/{util → modules/integration/util}/defaults.d.ts +2 -6
- package/out/{util → modules/integration/util}/defaults.js +1 -46
- package/out/modules/integration/util/files.d.ts +5 -0
- package/out/{util → modules/integration/util}/files.js +9 -40
- package/out/{util → modules/integration/util}/job.d.ts +1 -1
- package/out/{util → modules/integration/util}/job.js +11 -11
- package/out/{util/file-snapshot.d.ts → modules/integration/util/snapshot.d.ts} +2 -4
- package/out/{util/file-snapshot.js → modules/integration/util/snapshot.js} +4 -63
- package/out/{models/job.d.ts → modules/integration/util/types.d.ts} +14 -0
- package/out/modules/integration/util/webhooks.d.ts +48 -0
- package/out/{util → modules/integration/util}/webhooks.js +92 -46
- package/out/modules/manifest.d.ts +1 -1
- package/out/modules/manifest.js +27 -66
- package/out/modules/modal/index.d.ts +1 -1
- package/out/modules/modal/index.js +2 -2
- package/out/modules/organization-menu/index.d.ts +1 -1
- package/out/modules/organization-menu/index.js +1 -2
- package/out/modules/profile-resources-menu/index.d.ts +1 -1
- package/out/modules/profile-resources-menu/index.js +1 -2
- package/out/modules/project-menu/index.d.ts +1 -1
- package/out/modules/project-menu/index.js +2 -2
- package/out/modules/project-menu-crowdsource/index.d.ts +1 -1
- package/out/modules/project-menu-crowdsource/index.js +2 -2
- package/out/modules/project-reports/index.d.ts +1 -1
- package/out/modules/project-reports/index.js +1 -2
- package/out/modules/project-tools/index.d.ts +1 -1
- package/out/modules/project-tools/index.js +1 -2
- package/out/modules/subscription-paid.d.ts +1 -1
- package/out/modules/subscription-paid.js +2 -2
- package/out/modules/uninstall.d.ts +2 -2
- package/out/modules/uninstall.js +6 -2
- package/out/storage/index.d.ts +3 -2
- package/out/storage/mysql.d.ts +3 -2
- package/out/storage/mysql.js +3 -3
- package/out/storage/postgre.d.ts +3 -2
- package/out/storage/postgre.js +3 -3
- package/out/storage/sqlite.d.ts +3 -2
- package/out/storage/sqlite.js +3 -3
- package/out/storage/types.d.ts +9 -0
- package/out/storage/types.js +2 -0
- package/out/{models/index.d.ts → types.d.ts} +16 -84
- package/out/{models/index.js → types.js} +1 -24
- package/out/util/connection.d.ts +1 -9
- package/out/util/connection.js +54 -150
- package/out/util/handlebars.d.ts +1 -0
- package/out/util/handlebars.js +34 -0
- package/out/util/index.d.ts +2 -3
- package/out/util/index.js +6 -6
- package/out/util/logger.d.ts +1 -1
- package/out/util/subscription.d.ts +9 -0
- package/out/util/subscription.js +111 -0
- package/package.json +1 -1
- package/out/util/cron.d.ts +0 -8
- package/out/util/files.d.ts +0 -10
- package/out/util/webhooks.d.ts +0 -29
- /package/out/{util → modules}/api/base.d.ts +0 -0
- /package/out/{util → modules}/api/base.js +0 -0
- /package/out/{util → modules}/api/components.d.ts +0 -0
- /package/out/{util → modules}/api/components.js +0 -0
- /package/out/{models/job.js → modules/integration/util/types.js} +0 -0
package/out/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Express } from 'express';
|
|
2
|
-
import { ClientConfig, Config, CrowdinAppUtilities, CrowdinMetadataStore } from './
|
|
2
|
+
import { ClientConfig, Config, CrowdinAppUtilities, CrowdinMetadataStore } from './types';
|
|
3
3
|
import express from './util/terminus-express';
|
|
4
|
-
export { ProjectPermissions, Scope, UserPermissions } from './
|
|
4
|
+
export { ProjectPermissions, Scope, UserPermissions } from './types';
|
|
5
5
|
export { express };
|
|
6
6
|
export declare const metadataStore: CrowdinMetadataStore;
|
|
7
|
-
export declare function addCrowdinEndpoints(app: Express, clientConfig: Config | ClientConfig): Partial<CrowdinAppUtilities>;
|
|
8
7
|
export declare function createApp(clientConfig: ClientConfig): void;
|
|
8
|
+
export declare function addCrowdinEndpoints(app: Express, clientConfig: Config | ClientConfig): Partial<CrowdinAppUtilities>;
|
package/out/index.js
CHANGED
|
@@ -35,9 +35,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.
|
|
38
|
+
exports.addCrowdinEndpoints = exports.createApp = exports.metadataStore = exports.express = exports.UserPermissions = exports.Scope = exports.ProjectPermissions = void 0;
|
|
39
39
|
const logsFormatter = __importStar(require("@crowdin/logs-formatter"));
|
|
40
|
-
const express_handlebars_1 = __importDefault(require("express-handlebars"));
|
|
41
40
|
const path_1 = require("path");
|
|
42
41
|
const crowdin_client_1 = __importStar(require("./middlewares/crowdin-client"));
|
|
43
42
|
const json_response_1 = __importDefault(require("./middlewares/json-response"));
|
|
@@ -48,15 +47,16 @@ const manifest_1 = __importDefault(require("./modules/manifest"));
|
|
|
48
47
|
const subscription_paid_1 = __importDefault(require("./modules/subscription-paid"));
|
|
49
48
|
const uninstall_1 = __importDefault(require("./modules/uninstall"));
|
|
50
49
|
const storage = __importStar(require("./storage"));
|
|
50
|
+
const types_1 = require("./types");
|
|
51
51
|
const util_1 = require("./util");
|
|
52
|
-
const api_1 = require("./util/api/api");
|
|
53
52
|
const connection_1 = require("./util/connection");
|
|
54
|
-
const
|
|
53
|
+
const handlebars_1 = require("./util/handlebars");
|
|
55
54
|
const logger = __importStar(require("./util/logger"));
|
|
56
55
|
const logger_1 = require("./util/logger");
|
|
57
56
|
const terminus_express_1 = __importDefault(require("./util/terminus-express"));
|
|
58
57
|
exports.express = terminus_express_1.default;
|
|
59
58
|
//apps
|
|
59
|
+
const apiApp = __importStar(require("./modules/api"));
|
|
60
60
|
const contextMenuApp = __importStar(require("./modules/context-menu"));
|
|
61
61
|
const customMTApp = __importStar(require("./modules/custom-mt"));
|
|
62
62
|
const spellCheckApp = __importStar(require("./modules/custom-spell-check"));
|
|
@@ -71,10 +71,11 @@ const projectMenuApp = __importStar(require("./modules/project-menu"));
|
|
|
71
71
|
const projectMenuCrowdsourceApp = __importStar(require("./modules/project-menu-crowdsource"));
|
|
72
72
|
const projectReportsApp = __importStar(require("./modules/project-reports"));
|
|
73
73
|
const projectToolsApp = __importStar(require("./modules/project-tools"));
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
Object.defineProperty(exports, "
|
|
77
|
-
Object.defineProperty(exports, "
|
|
74
|
+
const subscription_1 = require("./util/subscription");
|
|
75
|
+
var types_2 = require("./types");
|
|
76
|
+
Object.defineProperty(exports, "ProjectPermissions", { enumerable: true, get: function () { return types_2.ProjectPermissions; } });
|
|
77
|
+
Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return types_2.Scope; } });
|
|
78
|
+
Object.defineProperty(exports, "UserPermissions", { enumerable: true, get: function () { return types_2.UserPermissions; } });
|
|
78
79
|
exports.metadataStore = {
|
|
79
80
|
getMetadata: (id) => {
|
|
80
81
|
return storage.getStorage().getMetadata(id);
|
|
@@ -98,8 +99,16 @@ exports.metadataStore = {
|
|
|
98
99
|
}
|
|
99
100
|
}),
|
|
100
101
|
};
|
|
102
|
+
function createApp(clientConfig) {
|
|
103
|
+
const app = (0, terminus_express_1.default)();
|
|
104
|
+
const config = convertClientConfig(clientConfig);
|
|
105
|
+
addCrowdinEndpoints(app, config);
|
|
106
|
+
/* eslint no-console: "off" */
|
|
107
|
+
app.listen(config.port, () => console.log(`App started on port ${config.port}`));
|
|
108
|
+
}
|
|
109
|
+
exports.createApp = createApp;
|
|
101
110
|
function addCrowdinEndpoints(app, clientConfig) {
|
|
102
|
-
const config =
|
|
111
|
+
const config = convertClientConfig(clientConfig);
|
|
103
112
|
if (!config.disableGlobalErrorHandling) {
|
|
104
113
|
handleUncaughtErrors();
|
|
105
114
|
}
|
|
@@ -113,37 +122,11 @@ function addCrowdinEndpoints(app, clientConfig) {
|
|
|
113
122
|
}
|
|
114
123
|
app.use('/assets', terminus_express_1.default.static((0, path_1.join)(__dirname, 'static')));
|
|
115
124
|
app.set('views', (0, path_1.join)(__dirname, 'views'));
|
|
116
|
-
app.engine('handlebars',
|
|
117
|
-
layoutsDir: '',
|
|
118
|
-
defaultLayout: '',
|
|
119
|
-
helpers: {
|
|
120
|
-
ifeq: function (a, b, options) {
|
|
121
|
-
if (a === b) {
|
|
122
|
-
return options.fn(this);
|
|
123
|
-
}
|
|
124
|
-
return options.inverse(this);
|
|
125
|
-
},
|
|
126
|
-
checkLength: function (a, b, options) {
|
|
127
|
-
if (a.length > b) {
|
|
128
|
-
return options.fn(this);
|
|
129
|
-
}
|
|
130
|
-
return options.inverse(this);
|
|
131
|
-
},
|
|
132
|
-
in: function (a, b, options) {
|
|
133
|
-
if (a.toString().includes(b.toString())) {
|
|
134
|
-
return options.fn(this);
|
|
135
|
-
}
|
|
136
|
-
return options.inverse(this);
|
|
137
|
-
},
|
|
138
|
-
or: function (a, b, options) {
|
|
139
|
-
return a || b ? options.fn(this) : options.inverse(this);
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
}));
|
|
125
|
+
app.engine('handlebars', handlebars_1.engine);
|
|
143
126
|
app.set('view engine', 'handlebars');
|
|
144
127
|
app.get((0, util_1.getLogoUrl)(), (req, res) => res.sendFile(config.imagePath));
|
|
145
128
|
app.get('/manifest.json', json_response_1.default, (0, manifest_1.default)(config));
|
|
146
|
-
if (!(0,
|
|
129
|
+
if (!(0, subscription_1.isAppFree)(config)) {
|
|
147
130
|
app.post('/subscription-paid', (0, subscription_paid_1.default)());
|
|
148
131
|
}
|
|
149
132
|
spellCheckApp.register({ config, app });
|
|
@@ -157,7 +140,7 @@ function addCrowdinEndpoints(app, clientConfig) {
|
|
|
157
140
|
modalApp.register({ config, app });
|
|
158
141
|
contextMenuApp.register({ config, app });
|
|
159
142
|
//other apps only work in authorized context
|
|
160
|
-
if (!(0,
|
|
143
|
+
if (!(0, util_1.isAuthorizedConfig)(config)) {
|
|
161
144
|
return {};
|
|
162
145
|
}
|
|
163
146
|
app.post('/installed', (0, install_1.default)(config));
|
|
@@ -168,7 +151,7 @@ function addCrowdinEndpoints(app, clientConfig) {
|
|
|
168
151
|
* /<module-name>
|
|
169
152
|
* index.ts -> registration
|
|
170
153
|
* types.ts -> types, interfaces, etc
|
|
171
|
-
* /util -> folder for utilities
|
|
154
|
+
* /util -> folder for utilities
|
|
172
155
|
* /handlers -> for http handlers
|
|
173
156
|
*/
|
|
174
157
|
integrationApp.register({ config, app });
|
|
@@ -179,19 +162,8 @@ function addCrowdinEndpoints(app, clientConfig) {
|
|
|
179
162
|
fileProcessingApps.registerFilePostImport({ config, app });
|
|
180
163
|
fileProcessingApps.registerFilePreExport({ config, app });
|
|
181
164
|
fileProcessingApps.registerFilePostExport({ config, app });
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
(0, api_1.addDefaultApiEndpoints)(app, config);
|
|
185
|
-
}
|
|
186
|
-
(0, api_1.addSwagerApiDocumentation)(app, config);
|
|
187
|
-
}
|
|
188
|
-
if (Object.keys(config).some((moduleKey) => {
|
|
189
|
-
const moduleConfig = config[moduleKey];
|
|
190
|
-
return typeof moduleConfig === 'object' && moduleConfig.hasOwnProperty('formSchema');
|
|
191
|
-
})) {
|
|
192
|
-
app.get('/api/form-data', json_response_1.default, (0, crowdin_client_1.default)(config), (0, form_data_display_1.default)());
|
|
193
|
-
app.post('/api/form-data', (0, crowdin_client_1.default)(config), (0, form_data_save_1.default)());
|
|
194
|
-
}
|
|
165
|
+
apiApp.register({ config, app });
|
|
166
|
+
addFormSchema({ config, app });
|
|
195
167
|
return Object.assign(Object.assign({}, exports.metadataStore), { establishCrowdinConnection: (authRequest) => {
|
|
196
168
|
let jwtToken = '';
|
|
197
169
|
if (typeof authRequest === 'string') {
|
|
@@ -212,14 +184,35 @@ function addCrowdinEndpoints(app, clientConfig) {
|
|
|
212
184
|
}) });
|
|
213
185
|
}
|
|
214
186
|
exports.addCrowdinEndpoints = addCrowdinEndpoints;
|
|
215
|
-
function
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
187
|
+
function addFormSchema({ app, config }) {
|
|
188
|
+
if (Object.keys(config).some((moduleKey) => {
|
|
189
|
+
const moduleConfig = config[moduleKey];
|
|
190
|
+
return typeof moduleConfig === 'object' && moduleConfig.hasOwnProperty('formSchema');
|
|
191
|
+
})) {
|
|
192
|
+
app.get('/api/form-data', json_response_1.default, (0, crowdin_client_1.default)(config), (0, form_data_display_1.default)());
|
|
193
|
+
app.post('/api/form-data', (0, crowdin_client_1.default)(config), (0, form_data_save_1.default)());
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function convertClientConfig(clientConfig) {
|
|
197
|
+
const baseUrl = clientConfig.baseUrl || process.env.URL;
|
|
198
|
+
const clientId = clientConfig.clientId || process.env.CROWDIN_CLIENT_ID;
|
|
199
|
+
const clientSecret = clientConfig.clientSecret || process.env.CROWDIN_CLIENT_SECRET;
|
|
200
|
+
const port = clientConfig.port || process.env.PORT || 3000;
|
|
201
|
+
const { region = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION, tmpBucketName = process.env.AWS_TMP_BUCKET_NAME, } = clientConfig.awsConfig || {};
|
|
202
|
+
if (!baseUrl) {
|
|
203
|
+
throw new Error('Missing baseUrl parameter');
|
|
204
|
+
}
|
|
205
|
+
if (clientConfig.authenticationType !== types_1.AuthenticationType.NONE) {
|
|
206
|
+
if (!clientId && !clientSecret) {
|
|
207
|
+
throw new Error('Missing [clientId, clientSecret] parameters');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return Object.assign(Object.assign({}, clientConfig), { baseUrl: baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl, clientId,
|
|
211
|
+
clientSecret, awsConfig: {
|
|
212
|
+
tmpBucketName,
|
|
213
|
+
region,
|
|
214
|
+
}, port: Number(port), dbFolder: clientConfig.dbFolder || (0, path_1.join)(process.cwd(), 'db'), imagePath: clientConfig.imagePath || (0, path_1.join)(process.cwd(), 'logo.png') });
|
|
221
215
|
}
|
|
222
|
-
exports.createApp = createApp;
|
|
223
216
|
function handleUncaughtErrors() {
|
|
224
217
|
process
|
|
225
218
|
.on('unhandledRejection', (reason) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
import Crowdin from '@crowdin/crowdin-api-client';
|
|
3
3
|
import { Response } from 'express';
|
|
4
|
-
import { Config, CrowdinClientRequest, CrowdinContextInfo, SubscriptionInfo } from '../
|
|
4
|
+
import { Config, CrowdinClientRequest, CrowdinContextInfo, SubscriptionInfo } from '../types';
|
|
5
5
|
import { LogErrorFunction, LogFunction } from '../util/logger';
|
|
6
6
|
export declare function prepareCrowdinRequest(jwtToken: string, config: Config, optional?: boolean, checkSubscriptionExpiration?: boolean): Promise<{
|
|
7
7
|
context: CrowdinContextInfo;
|
|
@@ -13,9 +13,10 @@ exports.getToken = exports.prepareCrowdinRequest = void 0;
|
|
|
13
13
|
const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
|
|
14
14
|
const storage_1 = require("../storage");
|
|
15
15
|
const util_1 = require("../util");
|
|
16
|
-
const api_1 = require("../
|
|
16
|
+
const api_1 = require("../modules/api/api");
|
|
17
17
|
const connection_1 = require("../util/connection");
|
|
18
18
|
const logger_1 = require("../util/logger");
|
|
19
|
+
const subscription_1 = require("../util/subscription");
|
|
19
20
|
function prepareCrowdinRequest(jwtToken, config, optional = false, checkSubscriptionExpiration = true) {
|
|
20
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
22
|
(0, logger_1.log)('Validating jwt token from incoming request');
|
|
@@ -40,7 +41,7 @@ function prepareCrowdinRequest(jwtToken, config, optional = false, checkSubscrip
|
|
|
40
41
|
const { client, token } = yield (0, connection_1.prepareCrowdinClient)({ config, credentials, autoRenew: true, context });
|
|
41
42
|
let subscriptionInfo;
|
|
42
43
|
if (checkSubscriptionExpiration) {
|
|
43
|
-
subscriptionInfo = yield (0,
|
|
44
|
+
subscriptionInfo = yield (0, subscription_1.checkSubscription)({
|
|
44
45
|
config,
|
|
45
46
|
token,
|
|
46
47
|
organization: credentials.id,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
import { Response } from 'express';
|
|
3
|
-
import { Config } from '../
|
|
3
|
+
import { Config } from '../types';
|
|
4
4
|
import { IntegrationLogic } from '../modules/integration/types';
|
|
5
|
-
export default function handle(config: Config, integration: IntegrationLogic, optional?: boolean): (req: import("../
|
|
5
|
+
export default function handle(config: Config, integration: IntegrationLogic, optional?: boolean): (req: import("../types").CrowdinClientRequest | 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,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { UiModule } from '../
|
|
4
|
-
export default function handle(moduleConfig: UiModule): (req: import("../
|
|
3
|
+
import { UiModule } from '../types';
|
|
4
|
+
export default function handle(moduleConfig: UiModule): (req: import("../types").CrowdinClientRequest | express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
|
-
import { Config, UnauthorizedConfig } from '../
|
|
4
|
-
export default function handle(config: Config | UnauthorizedConfig, allowUnauthorized?: boolean): (req: import("../
|
|
3
|
+
import { Config, UnauthorizedConfig } from '../types';
|
|
4
|
+
export default function handle(config: Config | UnauthorizedConfig, allowUnauthorized?: boolean): (req: import("../types").CrowdinClientRequest | Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -13,15 +13,15 @@ const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
|
|
|
13
13
|
const storage_1 = require("../storage");
|
|
14
14
|
const util_1 = require("../util");
|
|
15
15
|
const connection_1 = require("../util/connection");
|
|
16
|
-
const defaults_1 = require("../util/defaults");
|
|
17
16
|
const logger_1 = require("../util/logger");
|
|
17
|
+
const subscription_1 = require("../util/subscription");
|
|
18
18
|
function handle(config, allowUnauthorized = false) {
|
|
19
19
|
return (0, util_1.runAsyncWrapper)((req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
if (allowUnauthorized) {
|
|
21
21
|
next();
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
if (!(0,
|
|
24
|
+
if (!(0, util_1.isAuthorizedConfig)(config)) {
|
|
25
25
|
throw new Error('Invalid configuration. UI module was configured as authorized but client id and client secret are missing');
|
|
26
26
|
}
|
|
27
27
|
const jwtToken = req.query.jwtToken;
|
|
@@ -45,7 +45,7 @@ function handle(config, allowUnauthorized = false) {
|
|
|
45
45
|
}
|
|
46
46
|
logInfo('Building crowdin client instance');
|
|
47
47
|
const { token } = yield (0, connection_1.prepareCrowdinClient)({ config, credentials, context });
|
|
48
|
-
const { expired, subscribeLink } = yield (0,
|
|
48
|
+
const { expired, subscribeLink } = yield (0, subscription_1.checkSubscription)({
|
|
49
49
|
config,
|
|
50
50
|
token,
|
|
51
51
|
organization: credentials.id,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Express } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { Config, CrowdinClientRequest, CrowdinContextInfo, UnauthorizedConfig } from '../../types';
|
|
3
|
+
import { ApiEndpoints, ApiModule } from './types';
|
|
3
4
|
export declare function getApiManifest(config: Config | UnauthorizedConfig, apiModule: ApiModule): ApiEndpoints[];
|
|
4
5
|
export declare function updateCrowdinContext(req: CrowdinClientRequest, context: CrowdinContextInfo): CrowdinContextInfo;
|
|
5
6
|
export declare function addDefaultApiEndpoints(app: Express, config: Config): void;
|
|
@@ -7,20 +7,20 @@ exports.addSwagerApiDocumentation = exports.addDefaultApiEndpoints = exports.upd
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const redoc_express_1 = __importDefault(require("redoc-express"));
|
|
9
9
|
const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
|
|
10
|
-
const crowdin_file_progress_1 = __importDefault(require("../../modules/integration/handlers/crowdin-file-progress"));
|
|
11
|
-
const crowdin_files_1 = __importDefault(require("../../modules/integration/handlers/crowdin-files"));
|
|
12
|
-
const crowdin_update_1 = __importDefault(require("../../modules/integration/handlers/crowdin-update"));
|
|
13
|
-
const integration_data_1 = __importDefault(require("../../modules/integration/handlers/integration-data"));
|
|
14
|
-
const integration_login_1 = __importDefault(require("../../modules/integration/handlers/integration-login"));
|
|
15
|
-
const integration_update_1 = __importDefault(require("../../modules/integration/handlers/integration-update"));
|
|
16
|
-
const settings_1 = __importDefault(require("../../modules/integration/handlers/settings"));
|
|
17
|
-
const settings_save_1 = __importDefault(require("../../modules/integration/handlers/settings-save"));
|
|
18
|
-
const sync_settings_1 = __importDefault(require("../../modules/integration/handlers/sync-settings"));
|
|
19
|
-
const sync_settings_save_1 = __importDefault(require("../../modules/integration/handlers/sync-settings-save"));
|
|
20
10
|
const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
|
|
21
11
|
const integration_credentials_1 = __importDefault(require("../../middlewares/integration-credentials"));
|
|
22
12
|
const json_response_1 = __importDefault(require("../../middlewares/json-response"));
|
|
23
|
-
const
|
|
13
|
+
const crowdin_file_progress_1 = __importDefault(require("../integration/handlers/crowdin-file-progress"));
|
|
14
|
+
const crowdin_files_1 = __importDefault(require("../integration/handlers/crowdin-files"));
|
|
15
|
+
const crowdin_update_1 = __importDefault(require("../integration/handlers/crowdin-update"));
|
|
16
|
+
const integration_data_1 = __importDefault(require("../integration/handlers/integration-data"));
|
|
17
|
+
const integration_login_1 = __importDefault(require("../integration/handlers/integration-login"));
|
|
18
|
+
const integration_update_1 = __importDefault(require("../integration/handlers/integration-update"));
|
|
19
|
+
const settings_1 = __importDefault(require("../integration/handlers/settings"));
|
|
20
|
+
const settings_save_1 = __importDefault(require("../integration/handlers/settings-save"));
|
|
21
|
+
const sync_settings_1 = __importDefault(require("../integration/handlers/sync-settings"));
|
|
22
|
+
const sync_settings_save_1 = __importDefault(require("../integration/handlers/sync-settings-save"));
|
|
23
|
+
const types_1 = require("./types");
|
|
24
24
|
function getApiManifest(config, apiModule) {
|
|
25
25
|
const apiModuleManifest = [];
|
|
26
26
|
if (apiModule.endpoints) {
|
|
@@ -51,60 +51,60 @@ function getDefaultApiEndpointsManifest(config) {
|
|
|
51
51
|
key: 'crowdin-files-api',
|
|
52
52
|
name: 'Get Crowdin Files',
|
|
53
53
|
url: '/crowdin-files',
|
|
54
|
-
method:
|
|
54
|
+
method: types_1.RequestMethods.GET,
|
|
55
55
|
description: 'Get a list of synced files',
|
|
56
56
|
documentationUrl: '/api-docs#tag/Files/operation/crowdin.files',
|
|
57
57
|
}, {
|
|
58
58
|
key: 'crowdin-files-api',
|
|
59
59
|
name: 'File Translation Progress',
|
|
60
60
|
url: '/file-progress',
|
|
61
|
-
method:
|
|
61
|
+
method: types_1.RequestMethods.GET,
|
|
62
62
|
description: 'Get file translation progress',
|
|
63
63
|
documentationUrl: '/api-docs#tag/Files/operation/file.progress',
|
|
64
64
|
}, {
|
|
65
65
|
key: 'integration-files-api',
|
|
66
66
|
name: 'Get Integration Files',
|
|
67
67
|
url: '/integration-files',
|
|
68
|
-
method:
|
|
68
|
+
method: types_1.RequestMethods.GET,
|
|
69
69
|
description: 'Get integration data',
|
|
70
70
|
documentationUrl: '/api-docs#tag/Files/operation/integration.files',
|
|
71
71
|
}, {
|
|
72
72
|
key: 'crowdin-update-api',
|
|
73
73
|
name: 'Update Crowdin',
|
|
74
74
|
url: '/crowdin-update',
|
|
75
|
-
method:
|
|
75
|
+
method: types_1.RequestMethods.POST,
|
|
76
76
|
description: 'Update crowdin data',
|
|
77
77
|
documentationUrl: '/api-docs#tag/Files/operation/crowdin.update',
|
|
78
78
|
}, {
|
|
79
79
|
key: 'integration-update-api',
|
|
80
80
|
name: 'Update Integration',
|
|
81
81
|
url: '/integration-update',
|
|
82
|
-
method:
|
|
82
|
+
method: types_1.RequestMethods.POST,
|
|
83
83
|
description: 'Update integration data',
|
|
84
84
|
documentationUrl: '/api-docs#tag/Files/operation/integration.update',
|
|
85
85
|
}, {
|
|
86
86
|
key: 'settings-api',
|
|
87
87
|
name: 'Get App Settings',
|
|
88
88
|
url: '/settings',
|
|
89
|
-
method:
|
|
89
|
+
method: types_1.RequestMethods.GET,
|
|
90
90
|
documentationUrl: '/api-docs#tag/Settings/operation/settings.get',
|
|
91
91
|
}, {
|
|
92
92
|
key: 'settings-update-api',
|
|
93
93
|
name: 'Update App Settings',
|
|
94
94
|
url: '/settings',
|
|
95
|
-
method:
|
|
95
|
+
method: types_1.RequestMethods.POST,
|
|
96
96
|
documentationUrl: '/api-docs#tag/Settings/operation/settings.update',
|
|
97
97
|
}, {
|
|
98
98
|
key: 'sync-settings-api',
|
|
99
99
|
name: 'Get Sync Settings',
|
|
100
100
|
url: '/sync-settings',
|
|
101
|
-
method:
|
|
101
|
+
method: types_1.RequestMethods.GET,
|
|
102
102
|
documentationUrl: '/api-docs#tag/Settings/operation/sync.settings.get',
|
|
103
103
|
}, {
|
|
104
104
|
key: 'sync-settings-update-api',
|
|
105
105
|
name: 'Update Sync Settings',
|
|
106
106
|
url: '/sync-settings',
|
|
107
|
-
method:
|
|
107
|
+
method: types_1.RequestMethods.POST,
|
|
108
108
|
documentationUrl: '/api-docs#tag/Settings/operation/sync.settings.update',
|
|
109
109
|
});
|
|
110
110
|
if (config.projectIntegration.loginForm) {
|
|
@@ -112,13 +112,13 @@ function getDefaultApiEndpointsManifest(config) {
|
|
|
112
112
|
key: 'login-data',
|
|
113
113
|
name: 'Get Login Fields',
|
|
114
114
|
url: '/login-fields',
|
|
115
|
-
method:
|
|
115
|
+
method: types_1.RequestMethods.GET,
|
|
116
116
|
documentationUrl: '/api-docs#tag/Login/operation/integration.fields',
|
|
117
117
|
}, {
|
|
118
118
|
key: 'login',
|
|
119
119
|
name: 'Login',
|
|
120
120
|
url: '/login',
|
|
121
|
-
method:
|
|
121
|
+
method: types_1.RequestMethods.POST,
|
|
122
122
|
documentationUrl: '/api-docs#tag/Login/operation/integration.login',
|
|
123
123
|
});
|
|
124
124
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
function register({ config, app }) {
|
|
6
|
+
if (!config.api) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (config.api.default) {
|
|
10
|
+
(0, api_1.addDefaultApiEndpoints)(app, config);
|
|
11
|
+
}
|
|
12
|
+
(0, api_1.addSwagerApiDocumentation)(app, config);
|
|
13
|
+
}
|
|
14
|
+
exports.register = register;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare enum RequestMethods {
|
|
2
|
+
GET = "GET",
|
|
3
|
+
POST = "POST",
|
|
4
|
+
PUT = "PUT",
|
|
5
|
+
PATCH = "PATCH",
|
|
6
|
+
DELETE = "DELETE"
|
|
7
|
+
}
|
|
8
|
+
export interface ApiEndpoints {
|
|
9
|
+
key: string;
|
|
10
|
+
name: string;
|
|
11
|
+
url: string;
|
|
12
|
+
method: RequestMethods;
|
|
13
|
+
description?: string;
|
|
14
|
+
documentationUrl?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ApiModule {
|
|
17
|
+
default?: boolean;
|
|
18
|
+
endpoints?: ApiEndpoints[];
|
|
19
|
+
docFile?: string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestMethods = void 0;
|
|
4
|
+
var RequestMethods;
|
|
5
|
+
(function (RequestMethods) {
|
|
6
|
+
RequestMethods["GET"] = "GET";
|
|
7
|
+
RequestMethods["POST"] = "POST";
|
|
8
|
+
RequestMethods["PUT"] = "PUT";
|
|
9
|
+
RequestMethods["PATCH"] = "PATCH";
|
|
10
|
+
RequestMethods["DELETE"] = "DELETE";
|
|
11
|
+
})(RequestMethods = exports.RequestMethods || (exports.RequestMethods = {}));
|
|
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.register = void 0;
|
|
7
7
|
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
8
8
|
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
9
|
-
const
|
|
9
|
+
const util_1 = require("../../util");
|
|
10
10
|
function register({ config, app }) {
|
|
11
11
|
var _a, _b;
|
|
12
|
-
const allowUnauthorized = !(0,
|
|
12
|
+
const allowUnauthorized = !(0, util_1.isAuthorizedConfig)(config);
|
|
13
13
|
if (((_a = config.contextMenu) === null || _a === void 0 ? void 0 : _a.uiPath) || ((_b = config.contextMenu) === null || _b === void 0 ? void 0 : _b.formSchema)) {
|
|
14
14
|
app.use('/context', (0, ui_module_1.default)(config, allowUnauthorized), (0, render_ui_module_1.default)(config.contextMenu));
|
|
15
15
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SignaturePatterns } from '../../types';
|
|
2
|
+
export interface ContextModule {
|
|
3
|
+
location: ContextOptionsLocations;
|
|
4
|
+
type: ContextOptionsTypes;
|
|
5
|
+
module: string;
|
|
6
|
+
/**
|
|
7
|
+
* Context menu name
|
|
8
|
+
*/
|
|
9
|
+
name?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Support fileName pattern only. Contains fileName field regular expressions used to detect the file type. If the file name matches any of the regular expressions, the context menu will be displayed.
|
|
12
|
+
*/
|
|
13
|
+
signaturePatterns?: SignaturePatterns;
|
|
14
|
+
}
|
|
15
|
+
export declare enum ContextOptionsLocations {
|
|
16
|
+
TM = "tm",
|
|
17
|
+
GLOSSARY = "glossary",
|
|
18
|
+
LANGUAGE = "language",
|
|
19
|
+
SCREENSHOT = "screenshot",
|
|
20
|
+
SOURCE_FILE = "source_file",
|
|
21
|
+
TRANSLATED_FILE = "translated_file"
|
|
22
|
+
}
|
|
23
|
+
export declare enum ContextOptionsTypes {
|
|
24
|
+
MODAL = "modal",
|
|
25
|
+
NEW_TAB = "new_tab",
|
|
26
|
+
REDIRECT = "redirect"
|
|
27
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContextOptionsTypes = exports.ContextOptionsLocations = void 0;
|
|
4
|
+
var ContextOptionsLocations;
|
|
5
|
+
(function (ContextOptionsLocations) {
|
|
6
|
+
ContextOptionsLocations["TM"] = "tm";
|
|
7
|
+
ContextOptionsLocations["GLOSSARY"] = "glossary";
|
|
8
|
+
ContextOptionsLocations["LANGUAGE"] = "language";
|
|
9
|
+
ContextOptionsLocations["SCREENSHOT"] = "screenshot";
|
|
10
|
+
ContextOptionsLocations["SOURCE_FILE"] = "source_file";
|
|
11
|
+
ContextOptionsLocations["TRANSLATED_FILE"] = "translated_file";
|
|
12
|
+
})(ContextOptionsLocations = exports.ContextOptionsLocations || (exports.ContextOptionsLocations = {}));
|
|
13
|
+
var ContextOptionsTypes;
|
|
14
|
+
(function (ContextOptionsTypes) {
|
|
15
|
+
ContextOptionsTypes["MODAL"] = "modal";
|
|
16
|
+
ContextOptionsTypes["NEW_TAB"] = "new_tab";
|
|
17
|
+
ContextOptionsTypes["REDIRECT"] = "redirect";
|
|
18
|
+
})(ContextOptionsTypes = exports.ContextOptionsTypes || (exports.ContextOptionsTypes = {}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
import { Response } from 'express';
|
|
3
|
-
import { CrowdinClientRequest } from '../../../
|
|
3
|
+
import { CrowdinClientRequest } from '../../../types';
|
|
4
4
|
import { CustomMTLogic } from '../types';
|
|
5
5
|
export default function handle(config: CustomMTLogic): (req: CrowdinClientRequest | 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,5 +1,5 @@
|
|
|
1
1
|
import Crowdin, { SourceStringsModel } from '@crowdin/crowdin-api-client';
|
|
2
|
-
import { CrowdinContextInfo } from '../../
|
|
2
|
+
import { CrowdinContextInfo } from '../../types';
|
|
3
3
|
export interface CustomMTLogic {
|
|
4
4
|
withContext?: boolean;
|
|
5
5
|
translate: (client: Crowdin, context: CrowdinContextInfo, projectId: number, source: string, target: string, strings: CustomMtString[]) => Promise<string[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
import { Response } from 'express';
|
|
3
|
-
import { CrowdinClientRequest } from '../../../
|
|
3
|
+
import { CrowdinClientRequest } from '../../../types';
|
|
4
4
|
import { CustomSpellcheckerModule } from '../types';
|
|
5
5
|
export default function handle(customSpellchecker: CustomSpellcheckerModule): (req: CrowdinClientRequest | 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,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
import { Response } from 'express';
|
|
3
|
-
import { CrowdinClientRequest } from '../../../
|
|
3
|
+
import { CrowdinClientRequest } from '../../../types';
|
|
4
4
|
import { CustomSpellcheckerModule } from '../types';
|
|
5
5
|
export default function handle(customSpellchecker: CustomSpellcheckerModule): (req: CrowdinClientRequest | 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;
|
|
@@ -8,14 +8,14 @@ const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-clie
|
|
|
8
8
|
const json_response_1 = __importDefault(require("../../middlewares/json-response"));
|
|
9
9
|
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
10
10
|
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
11
|
-
const
|
|
11
|
+
const util_1 = require("../../util");
|
|
12
12
|
const get_languages_list_1 = __importDefault(require("./handlers/get-languages-list"));
|
|
13
13
|
const spell_check_1 = __importDefault(require("./handlers/spell-check"));
|
|
14
14
|
function register({ config, app }) {
|
|
15
15
|
if (!config.customSpellchecker) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
if ((0,
|
|
18
|
+
if ((0, util_1.isAuthorizedConfig)(config)) {
|
|
19
19
|
if (config.customSpellchecker.settingsUiModule) {
|
|
20
20
|
app.use('/settings', (0, ui_module_1.default)(config), (0, render_ui_module_1.default)(config.customSpellchecker.settingsUiModule));
|
|
21
21
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Crowdin from '@crowdin/crowdin-api-client';
|
|
2
|
-
import { CrowdinContextInfo, Environments, UiModule } from '../../
|
|
2
|
+
import { CrowdinContextInfo, Environments, UiModule } from '../../types';
|
|
3
3
|
export interface CustomSpellCheckRequest {
|
|
4
4
|
language: string;
|
|
5
5
|
texts: string[];
|