@crowdin/app-project-module 0.15.0 → 0.15.2

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
@@ -185,7 +185,7 @@ configuration.pricing = {
185
185
  plantType: 'recurring',
186
186
  trial: 14, //amount of days to use app for free
187
187
  trialCrowdin: 14, //amount of days specifically in crowdin workspace
188
- trialEnterprise: 30 //amount of days specifically for enterprise
188
+ trialEnterprise: 30, //amount of days specifically for enterprise
189
189
  cachingSeconds: 12 * 60 * 60 //time in seconds of how long to cache subscription info
190
190
  };
191
191
  ```
@@ -11,10 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const storage_1 = require("../storage");
13
13
  const util_1 = require("../util");
14
+ const connection_1 = require("../util/connection");
14
15
  function handle(config) {
15
16
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
17
  (0, util_1.log)('Recieved integration logout request', config.logger);
17
18
  yield (0, storage_1.deleteIntegrationCredentials)(req.crowdinContext.clientId);
19
+ (0, connection_1.clearCache)(req.crowdinContext.crowdinId);
18
20
  res.status(204).end();
19
21
  }), config.onError);
20
22
  }
package/out/index.js CHANGED
@@ -92,7 +92,7 @@ function addCrowdinEndpoints(app, config) {
92
92
  app.post('/installed', (0, install_1.default)(config));
93
93
  app.post('/uninstall', (0, uninstall_1.default)(config));
94
94
  app.get('/manifest.json', json_response_1.default, (0, manifest_1.default)(config));
95
- const integrationLogic = config.integration || config.projectIntegration;
95
+ const integrationLogic = config.projectIntegration;
96
96
  if (integrationLogic) {
97
97
  (0, defaults_1.applyDefaults)(config, integrationLogic);
98
98
  app.get('/logo/integration/logo.png', (req, res) => res.sendFile(integrationLogic.imagePath || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')));
@@ -38,10 +38,6 @@ export interface Config extends ImagePath {
38
38
  * folder where module will create sqlite db file to persist credentials (e.g. {@example __dirname})
39
39
  */
40
40
  dbFolder: string;
41
- /**
42
- * integration module logic
43
- */
44
- integration?: IntegrationLogic & ImagePath;
45
41
  /**
46
42
  * integration module logic
47
43
  */
@@ -54,10 +50,6 @@ export interface Config extends ImagePath {
54
50
  * custom MT module logic
55
51
  */
56
52
  customMT?: CustomMTLogic;
57
- /**
58
- * resources module
59
- */
60
- resources?: UiModule & ImagePath;
61
53
  /**
62
54
  * resources module
63
55
  */
@@ -66,10 +58,6 @@ export interface Config extends ImagePath {
66
58
  * organization-menu module
67
59
  */
68
60
  organizationMenu?: UiModule & ImagePath;
69
- /**
70
- * editor-panels module
71
- */
72
- editorPanels?: EditorPanels;
73
61
  /**
74
62
  * editor-right-panel module
75
63
  */
@@ -78,18 +66,10 @@ export interface Config extends ImagePath {
78
66
  * project menu module
79
67
  */
80
68
  projectMenu?: UiModule;
81
- /**
82
- * tools module
83
- */
84
- tools?: UiModule & ImagePath;
85
69
  /**
86
70
  * tools module
87
71
  */
88
72
  projectTools?: UiModule & ImagePath;
89
- /**
90
- * reports module
91
- */
92
- reports?: UiModule & ImagePath;
93
73
  /**
94
74
  * reports module
95
75
  */
@@ -5,6 +5,7 @@ export declare function prepareCrowdinClient(config: Config, credentials: Crowdi
5
5
  token: string;
6
6
  }>;
7
7
  export declare function prepareIntegrationCredentials(config: Config, integration: IntegrationLogic, integrationCredentials: IntegrationCredentials): Promise<any>;
8
+ export declare function clearCache(organization: string): void;
8
9
  export declare function checkSubscription(config: Config, token: string, organization: string, accountType: AccountType): Promise<{
9
10
  expired: boolean;
10
11
  subscribeLink?: string;
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.checkSubscription = exports.prepareIntegrationCredentials = exports.prepareCrowdinClient = void 0;
34
+ exports.checkSubscription = exports.clearCache = exports.prepareIntegrationCredentials = exports.prepareCrowdinClient = void 0;
35
35
  const crowdin_api_client_1 = __importDefault(require("@crowdin/crowdin-api-client"));
36
36
  const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
37
37
  const axios_1 = __importDefault(require("axios"));
@@ -112,18 +112,27 @@ function prepareIntegrationCredentials(config, integration, integrationCredentia
112
112
  }
113
113
  exports.prepareIntegrationCredentials = prepareIntegrationCredentials;
114
114
  const subscriptionCache = {};
115
- function addToCache(organization, validUntil, cachingSeconds, subscribeLink) {
115
+ function addToCache(organization, appIdenfifier, validUntil, cachingSeconds, subscribeLink) {
116
116
  if (!cachingSeconds) {
117
117
  return;
118
118
  }
119
+ const orgCache = subscriptionCache[organization] || {};
119
120
  const now = new Date();
120
121
  now.setSeconds(now.getSeconds() + cachingSeconds);
121
- subscriptionCache[organization] = {
122
+ orgCache[appIdenfifier] = {
122
123
  cacheValidUntil: now,
123
124
  validUntil,
124
125
  subscribeLink,
125
126
  };
127
+ subscriptionCache[organization] = orgCache;
126
128
  }
129
+ function getFromCache(organization, appIdenfifier) {
130
+ return (subscriptionCache[organization] || {})[appIdenfifier];
131
+ }
132
+ function clearCache(organization) {
133
+ delete subscriptionCache[organization];
134
+ }
135
+ exports.clearCache = clearCache;
127
136
  function checkSubscription(config, token, organization, accountType) {
128
137
  return __awaiter(this, void 0, void 0, function* () {
129
138
  if (!config.pricing || config.pricing.planType === 'free') {
@@ -139,8 +148,10 @@ function checkSubscription(config, token, organization, accountType) {
139
148
  days = config.pricing.trialCrowdin || config.pricing.trial || defaultSubscriptionPlan;
140
149
  }
141
150
  (0, _1.log)(`Checking subscription plan. Subscriptino plan ${days} days`, config.logger);
142
- if (subscriptionCache[organization]) {
143
- const { cacheValidUntil, validUntil, subscribeLink } = subscriptionCache[organization];
151
+ const appIdentifier = config.identifier;
152
+ const cacheEntry = getFromCache(organization, appIdentifier);
153
+ if (cacheEntry) {
154
+ const { cacheValidUntil, validUntil, subscribeLink } = cacheEntry;
144
155
  if (cacheValidUntil.getTime() > Date.now()) {
145
156
  (0, _1.log)(`Loaded data from cache. Subscription is vali until ${validUntil.toISOString()}`, config.logger);
146
157
  const expired = new Date(validUntil).getTime() < Date.now();
@@ -149,7 +160,6 @@ function checkSubscription(config, token, organization, accountType) {
149
160
  }
150
161
  }
151
162
  try {
152
- const appIdentifier = config.identifier;
153
163
  const subscription = yield crowdinAppFunctions.getSubscription({
154
164
  appIdentifier,
155
165
  organization: accountType === models_1.AccountType.ENTERPRISE ? organization : undefined,
@@ -158,7 +168,7 @@ function checkSubscription(config, token, organization, accountType) {
158
168
  (0, _1.log)(`Recieved subscription info. ${JSON.stringify(subscription)}`, config.logger);
159
169
  const expired = new Date(subscription.expires).getTime() < Date.now();
160
170
  (0, _1.log)(`expired ${expired}`, config.logger);
161
- addToCache(organization, new Date(subscription.expires), config.pricing.cachingSeconds);
171
+ addToCache(organization, appIdentifier, new Date(subscription.expires), config.pricing.cachingSeconds);
162
172
  return { expired };
163
173
  }
164
174
  catch (e) {
@@ -169,7 +179,7 @@ function checkSubscription(config, token, organization, accountType) {
169
179
  date.setDate(date.getDate() + days);
170
180
  const expired = date.getTime() < Date.now();
171
181
  (0, _1.log)(`expired ${expired}`, config.logger);
172
- addToCache(organization, new Date(date), config.pricing.cachingSeconds, subscribeLink);
182
+ addToCache(organization, appIdentifier, new Date(date), config.pricing.cachingSeconds, subscribeLink);
173
183
  return { expired, subscribeLink };
174
184
  }
175
185
  if (config.onError) {
@@ -178,8 +188,8 @@ function checkSubscription(config, token, organization, accountType) {
178
188
  else {
179
189
  console.error(e);
180
190
  }
181
- (0, _1.log)('Recieved http error from subscription request. Returning expired=true', config.logger);
182
- return { expired: true };
191
+ (0, _1.log)('Recieved http error from subscription request. Returning expired=false', config.logger);
192
+ return { expired: false };
183
193
  }
184
194
  });
185
195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
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",