@crowdin/app-project-module 0.17.7 → 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.
- package/README.md +5 -9
- package/out/handlers/install.js +2 -1
- package/out/models/index.d.ts +7 -2
- package/out/util/connection.js +14 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,14 +19,6 @@ In both options you will need to provide Crowdin App configuration file. Please
|
|
|
19
19
|
- `getUserSettings` to get settings that users manage in the integration module
|
|
20
20
|
- `establishCrowdinConnection` method that accept jwt token that you may forward from module UI and it will return back Crowdin client instance and the context.
|
|
21
21
|
|
|
22
|
-
## Status
|
|
23
|
-
|
|
24
|
-
[](https://www.npmjs.com/package/@crowdin/app-project-module)
|
|
25
|
-
[](https://dev.azure.com/crowdin/app-project-module/_build/latest?definitionId=39&branchName=master)
|
|
26
|
-
[](https://www.npmjs.com/package/@crowdin/app-project-module)
|
|
27
|
-
<!-- [](https://github.com/crowdin/app-project-module/issues)
|
|
28
|
-
[](https://github.com/crowdin/app-project-module/blob/master/LICENSE) -->
|
|
29
|
-
|
|
30
22
|
## Table of Contents
|
|
31
23
|
|
|
32
24
|
- [Installation](#installation)
|
|
@@ -81,7 +73,11 @@ const configuration = {
|
|
|
81
73
|
description: 'Sample App description',
|
|
82
74
|
dbFolder: __dirname,
|
|
83
75
|
imagePath: __dirname + '/' + 'logo.png',
|
|
84
|
-
//
|
|
76
|
+
crowdinUrls: { // custom urls to override
|
|
77
|
+
// apiUrl: 'https://local.crowdin.dev/api/v2'
|
|
78
|
+
// accountUrl: 'https://local.crowdin.dev/oauth/token' // (default https://accounts.crowdin.com/oauth/token)
|
|
79
|
+
// subscriptionUrl: 'https://local.crowdin.dev' // (default https://crowdin.com or https://org.api.crowdin.com)
|
|
80
|
+
},
|
|
85
81
|
projectIntegration: {
|
|
86
82
|
withRootFolder: true,
|
|
87
83
|
withCronSync: {
|
package/out/handlers/install.js
CHANGED
|
@@ -15,9 +15,10 @@ const storage_1 = require("../storage");
|
|
|
15
15
|
const util_1 = require("../util");
|
|
16
16
|
function handle(config) {
|
|
17
17
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
18
19
|
const event = req.body;
|
|
19
20
|
(0, util_1.log)(`Recieved install request ${JSON.stringify(event, null, 2)}`, config.logger);
|
|
20
|
-
const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)(config.clientId, config.clientSecret, event.code);
|
|
21
|
+
const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)(config.clientId, config.clientSecret, event.code, (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.accountUrl);
|
|
21
22
|
const credentials = {
|
|
22
23
|
id: (event.domain || event.organizationId).toString(),
|
|
23
24
|
appSecret: event.appSecret,
|
package/out/models/index.d.ts
CHANGED
|
@@ -19,9 +19,9 @@ export interface Config extends ImagePath {
|
|
|
19
19
|
*/
|
|
20
20
|
baseUrl: string;
|
|
21
21
|
/**
|
|
22
|
-
* define Crowdin
|
|
22
|
+
* define custom Crowdin urls (e.g. to work against local Crowdin server)
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
crowdinUrls?: CrowdinUrls;
|
|
25
25
|
/**
|
|
26
26
|
* Set of scopes requested by this app (default 'project')
|
|
27
27
|
*/
|
|
@@ -99,6 +99,11 @@ export interface Config extends ImagePath {
|
|
|
99
99
|
*/
|
|
100
100
|
pricing?: Pricing;
|
|
101
101
|
}
|
|
102
|
+
export interface CrowdinUrls {
|
|
103
|
+
apiUrl?: string;
|
|
104
|
+
accountUrl?: string;
|
|
105
|
+
subscriptionUrl?: string;
|
|
106
|
+
}
|
|
102
107
|
export declare enum Scope {
|
|
103
108
|
ALL_SCOPES = "all",
|
|
104
109
|
NOTIFICATIONS = "notification",
|
package/out/util/connection.js
CHANGED
|
@@ -39,18 +39,19 @@ const _1 = require(".");
|
|
|
39
39
|
const models_1 = require("../models");
|
|
40
40
|
const storage_1 = require("../storage");
|
|
41
41
|
function prepareCrowdinClient(config, credentials) {
|
|
42
|
+
var _a, _b, _c;
|
|
42
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
44
|
const isExpired = +credentials.expire < +new Date().getTime() / 1000;
|
|
44
45
|
const organization = credentials.type === models_1.AccountType.ENTERPRISE ? credentials.id : undefined;
|
|
45
46
|
if (!isExpired) {
|
|
46
47
|
const token = (0, _1.decryptData)(config, credentials.accessToken);
|
|
47
48
|
return {
|
|
48
|
-
client: new crowdin_api_client_1.default({ token, organization, baseUrl: config.
|
|
49
|
+
client: new crowdin_api_client_1.default({ token, organization, baseUrl: (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.apiUrl }),
|
|
49
50
|
token,
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
(0, _1.log)('Crowdin credentials have expired. Requesting a new credentials', config.logger);
|
|
53
|
-
const newCredentials = yield crowdinAppFunctions.refreshOAuthToken(config.clientId, config.clientSecret, (0, _1.decryptData)(config, credentials.refreshToken));
|
|
54
|
+
const newCredentials = yield crowdinAppFunctions.refreshOAuthToken(config.clientId, config.clientSecret, (0, _1.decryptData)(config, credentials.refreshToken), (_b = config.crowdinUrls) === null || _b === void 0 ? void 0 : _b.accountUrl);
|
|
54
55
|
(0, _1.log)('Saving updated crowdin credentials in the database', config.logger);
|
|
55
56
|
yield (0, storage_1.updateCrowdinCredentials)({
|
|
56
57
|
id: credentials.id,
|
|
@@ -65,7 +66,11 @@ function prepareCrowdinClient(config, credentials) {
|
|
|
65
66
|
type: credentials.type,
|
|
66
67
|
});
|
|
67
68
|
return {
|
|
68
|
-
client: new crowdin_api_client_1.default({
|
|
69
|
+
client: new crowdin_api_client_1.default({
|
|
70
|
+
token: newCredentials.accessToken,
|
|
71
|
+
organization,
|
|
72
|
+
baseUrl: (_c = config.crowdinUrls) === null || _c === void 0 ? void 0 : _c.apiUrl,
|
|
73
|
+
}),
|
|
69
74
|
token: newCredentials.accessToken,
|
|
70
75
|
};
|
|
71
76
|
});
|
|
@@ -147,7 +152,7 @@ function validateSubscription(date) {
|
|
|
147
152
|
return { expired, daysLeft };
|
|
148
153
|
}
|
|
149
154
|
function checkSubscription(config, token, organization, accountType) {
|
|
150
|
-
var _a, _b, _c, _d, _e, _f;
|
|
155
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
151
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
157
|
if (isAppFree(config)) {
|
|
153
158
|
return { expired: false };
|
|
@@ -169,11 +174,12 @@ function checkSubscription(config, token, organization, accountType) {
|
|
|
169
174
|
appIdentifier,
|
|
170
175
|
organization: accountType === models_1.AccountType.ENTERPRISE ? organization : undefined,
|
|
171
176
|
token,
|
|
177
|
+
baseUrl: (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.subscriptionUrl,
|
|
172
178
|
});
|
|
173
179
|
(0, _1.log)(`Recieved subscription info. ${JSON.stringify(subscription)}`, config.logger);
|
|
174
180
|
const { expired, daysLeft } = validateSubscription(new Date(subscription.expires));
|
|
175
181
|
(0, _1.log)(`expired ${expired}`, config.logger);
|
|
176
|
-
addToCache(organization, appIdentifier, new Date(subscription.expires), models_1.SubscriptionInfoType.SUBSCRIPTION, (
|
|
182
|
+
addToCache(organization, appIdentifier, new Date(subscription.expires), models_1.SubscriptionInfoType.SUBSCRIPTION, (_b = config.pricing) === null || _b === void 0 ? void 0 : _b.cachingSeconds);
|
|
177
183
|
return { expired, daysLeft, type: models_1.SubscriptionInfoType.SUBSCRIPTION };
|
|
178
184
|
}
|
|
179
185
|
catch (e) {
|
|
@@ -184,17 +190,17 @@ function checkSubscription(config, token, organization, accountType) {
|
|
|
184
190
|
const defaultSubscriptionPlan = 14;
|
|
185
191
|
let days;
|
|
186
192
|
if (accountType === models_1.AccountType.ENTERPRISE) {
|
|
187
|
-
days = ((
|
|
193
|
+
days = ((_c = config.pricing) === null || _c === void 0 ? void 0 : _c.trialEnterprise) || ((_d = config.pricing) === null || _d === void 0 ? void 0 : _d.trial) || defaultSubscriptionPlan;
|
|
188
194
|
}
|
|
189
195
|
else {
|
|
190
|
-
days = ((
|
|
196
|
+
days = ((_e = config.pricing) === null || _e === void 0 ? void 0 : _e.trialCrowdin) || ((_f = config.pricing) === null || _f === void 0 ? void 0 : _f.trial) || defaultSubscriptionPlan;
|
|
191
197
|
}
|
|
192
198
|
(0, _1.log)(`Subscriptino trial plan ${days} days`, config.logger);
|
|
193
199
|
const date = new Date(initializedAt);
|
|
194
200
|
date.setDate(date.getDate() + days);
|
|
195
201
|
const { expired, daysLeft } = validateSubscription(date);
|
|
196
202
|
(0, _1.log)(`expired ${expired}`, config.logger);
|
|
197
|
-
addToCache(organization, appIdentifier, new Date(date), models_1.SubscriptionInfoType.TRIAL, (
|
|
203
|
+
addToCache(organization, appIdentifier, new Date(date), models_1.SubscriptionInfoType.TRIAL, (_g = config.pricing) === null || _g === void 0 ? void 0 : _g.cachingSeconds, subscribeLink);
|
|
198
204
|
return { expired, subscribeLink, daysLeft, type: models_1.SubscriptionInfoType.TRIAL };
|
|
199
205
|
}
|
|
200
206
|
if (config.onError) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crowdin/app-project-module",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.8",
|
|
4
4
|
"description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
|
|
5
5
|
"main": "out/index.js",
|
|
6
6
|
"types": "out/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"test": "echo \"test not implemented\""
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@crowdin/crowdin-apps-functions": "0.1.
|
|
15
|
+
"@crowdin/crowdin-apps-functions": "0.1.4",
|
|
16
16
|
"crypto-js": "^4.0.0",
|
|
17
17
|
"express": "4.17.1",
|
|
18
18
|
"express-handlebars": "^5.3.4",
|