@crowdin/app-project-module 0.17.7 → 0.17.9

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 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
- [![npm](https://img.shields.io/npm/v/@crowdin/app-project-module?logo=npm&cacheSeconds=1800)](https://www.npmjs.com/package/@crowdin/app-project-module)
25
- [![Build Status](https://dev.azure.com/crowdin/app-project-module/_apis/build/status/Basic?branchName=master)](https://dev.azure.com/crowdin/app-project-module/_build/latest?definitionId=39&branchName=master)
26
- [![npm](https://img.shields.io/npm/dt/@crowdin/app-project-module?cacheSeconds=1800)](https://www.npmjs.com/package/@crowdin/app-project-module)
27
- <!-- [![GitHub issues](https://img.shields.io/github/issues/crowdin/app-project-module?cacheSeconds=3600)](https://github.com/crowdin/app-project-module/issues)
28
- [![License](https://img.shields.io/github/license/crowdin/app-project-module?cacheSeconds=3600)](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
- // crowdinBaseUrl: 'https://local.crowdin.dev/api/v2',
76
+ crowdinUrls: { // custom urls to override
77
+ // apiUrl: 'https://<copy_name>.crowdin.dev/api/v2', // 'https://<org_name>.<copy_name>.crowdin.dev/api/v2' for enterprise
78
+ // accountUrl: 'https://accounts.<copy_name>.crowdin.dev/oauth/token', // (default https://accounts.crowdin.com/oauth/token)
79
+ // subscriptionUrl: 'https://<copy_name>.crowdin.dev' // (default https://crowdin.com or https://org.api.crowdin.com)
80
+ },
85
81
  projectIntegration: {
86
82
  withRootFolder: true,
87
83
  withCronSync: {
@@ -17,7 +17,7 @@ const fs_1 = __importDefault(require("fs"));
17
17
  const path_1 = __importDefault(require("path"));
18
18
  const models_1 = require("../../models");
19
19
  const util_1 = require("../../util");
20
- const MAX_BODY_SIZE = 5 * 1024 * 1024; //5mb
20
+ const MAX_BODY_SIZE = 4.9 * 1024 * 1024; //4.9mb
21
21
  function storeFile(fileContent, folder) {
22
22
  const fileName = `file${Date.now()}`;
23
23
  return new Promise((res, rej) => fs_1.default.writeFile(path_1.default.join(folder, 'custom-file-format', fileName), fileContent, err => {
@@ -70,9 +70,13 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
70
70
  return { response };
71
71
  }
72
72
  const res = yield config.parseFile(file, req, client, context, projectId);
73
+ let maxSize = MAX_BODY_SIZE;
74
+ if (res.strings && res.previewFile) {
75
+ maxSize = maxSize / 2;
76
+ }
73
77
  if (res.previewFile) {
74
78
  const previewFileEncoded = Buffer.from(res.previewFile).toString('base64');
75
- if (Buffer.byteLength(previewFileEncoded, 'utf8') < MAX_BODY_SIZE) {
79
+ if (Buffer.byteLength(previewFileEncoded, 'utf8') < maxSize) {
76
80
  response.preview = previewFileEncoded;
77
81
  }
78
82
  else {
@@ -92,7 +96,7 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
92
96
  });
93
97
  }
94
98
  const stringsJson = JSON.stringify(strings);
95
- if (Buffer.byteLength(stringsJson, 'utf8') < MAX_BODY_SIZE) {
99
+ if (Buffer.byteLength(stringsJson, 'utf8') < maxSize) {
96
100
  response.strings = strings;
97
101
  }
98
102
  else {
@@ -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,
@@ -19,9 +19,9 @@ export interface Config extends ImagePath {
19
19
  */
20
20
  baseUrl: string;
21
21
  /**
22
- * define Crowdin API url (e.g. to work against local Crowdin server)
22
+ * define custom Crowdin urls (e.g. to work against local Crowdin server)
23
23
  */
24
- crowdinBaseUrl?: string;
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",
@@ -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.crowdinBaseUrl }),
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({ token: newCredentials.accessToken, organization, baseUrl: config.crowdinBaseUrl }),
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, (_a = config.pricing) === null || _a === void 0 ? void 0 : _a.cachingSeconds);
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 = ((_b = config.pricing) === null || _b === void 0 ? void 0 : _b.trialEnterprise) || ((_c = config.pricing) === null || _c === void 0 ? void 0 : _c.trial) || defaultSubscriptionPlan;
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 = ((_d = config.pricing) === null || _d === void 0 ? void 0 : _d.trialCrowdin) || ((_e = config.pricing) === null || _e === void 0 ? void 0 : _e.trial) || defaultSubscriptionPlan;
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, (_f = config.pricing) === null || _f === void 0 ? void 0 : _f.cachingSeconds, subscribeLink);
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.7",
3
+ "version": "0.17.9",
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.3",
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",