@crowdin/app-project-module 0.16.1 → 0.16.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.
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const models_1 = require("../models");
3
4
  function handle(config) {
4
5
  return (req, res) => {
5
6
  var _a;
6
7
  const subscriptionInfo = req.subscriptionInfo;
7
- let showInfo = true;
8
- if ((_a = config.pricing) === null || _a === void 0 ? void 0 : _a.infoDisplayDaysThreshold) {
8
+ let showInfo = (subscriptionInfo === null || subscriptionInfo === void 0 ? void 0 : subscriptionInfo.type) === models_1.SubscriptionInfoType.TRIAL;
9
+ if (showInfo && ((_a = config.pricing) === null || _a === void 0 ? void 0 : _a.infoDisplayDaysThreshold)) {
9
10
  showInfo = config.pricing.infoDisplayDaysThreshold >= ((subscriptionInfo === null || subscriptionInfo === void 0 ? void 0 : subscriptionInfo.daysLeft) || 0);
10
11
  }
11
12
  res.send(Object.assign(Object.assign({}, (subscriptionInfo || {})), { showInfo }));
@@ -340,10 +340,15 @@ export interface CrowdinContextInfo {
340
340
  crowdinId: string;
341
341
  clientId: string;
342
342
  }
343
+ export declare enum SubscriptionInfoType {
344
+ TRIAL = "trial",
345
+ SUBSCRIPTION = "subscription"
346
+ }
343
347
  export interface SubscriptionInfo {
344
348
  expired: boolean;
345
349
  subscribeLink?: string;
346
350
  daysLeft?: number;
351
+ type?: SubscriptionInfoType;
347
352
  }
348
353
  export interface IntegrationCredentials {
349
354
  id: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EditorPanelsMode = exports.ProcessFileJobType = exports.AccountType = exports.Scope = void 0;
3
+ exports.EditorPanelsMode = exports.ProcessFileJobType = exports.SubscriptionInfoType = exports.AccountType = exports.Scope = void 0;
4
4
  var Scope;
5
5
  (function (Scope) {
6
6
  Scope["ALL_SCOPES"] = "all";
@@ -22,6 +22,11 @@ var AccountType;
22
22
  AccountType["NORMAL"] = "normal";
23
23
  AccountType["ENTERPRISE"] = "enterprise";
24
24
  })(AccountType = exports.AccountType || (exports.AccountType = {}));
25
+ var SubscriptionInfoType;
26
+ (function (SubscriptionInfoType) {
27
+ SubscriptionInfoType["TRIAL"] = "trial";
28
+ SubscriptionInfoType["SUBSCRIPTION"] = "subscription";
29
+ })(SubscriptionInfoType = exports.SubscriptionInfoType || (exports.SubscriptionInfoType = {}));
25
30
  var ProcessFileJobType;
26
31
  (function (ProcessFileJobType) {
27
32
  ProcessFileJobType["PARSE_FILE"] = "parse-file";
@@ -112,7 +112,7 @@ function prepareIntegrationCredentials(config, integration, integrationCredentia
112
112
  }
113
113
  exports.prepareIntegrationCredentials = prepareIntegrationCredentials;
114
114
  const subscriptionCache = {};
115
- function addToCache(organization, appIdenfifier, validUntil, cachingSeconds, subscribeLink) {
115
+ function addToCache(organization, appIdenfifier, validUntil, type, cachingSeconds, subscribeLink) {
116
116
  if (!cachingSeconds) {
117
117
  return;
118
118
  }
@@ -123,6 +123,7 @@ function addToCache(organization, appIdenfifier, validUntil, cachingSeconds, sub
123
123
  cacheValidUntil: now,
124
124
  validUntil,
125
125
  subscribeLink,
126
+ type,
126
127
  };
127
128
  subscriptionCache[organization] = orgCache;
128
129
  }
@@ -148,25 +149,16 @@ function checkSubscription(config, token, organization, accountType) {
148
149
  if (isAppFree(config)) {
149
150
  return { expired: false };
150
151
  }
151
- //default 2 weeks
152
- const defaultSubscriptionPlan = 14;
153
- let days;
154
- if (organization) {
155
- days = ((_a = config.pricing) === null || _a === void 0 ? void 0 : _a.trialEnterprise) || ((_b = config.pricing) === null || _b === void 0 ? void 0 : _b.trial) || defaultSubscriptionPlan;
156
- }
157
- else {
158
- days = ((_c = config.pricing) === null || _c === void 0 ? void 0 : _c.trialCrowdin) || ((_d = config.pricing) === null || _d === void 0 ? void 0 : _d.trial) || defaultSubscriptionPlan;
159
- }
160
- (0, _1.log)(`Checking subscription plan. Subscriptino plan ${days} days`, config.logger);
152
+ (0, _1.log)('Checking subscription plan', config.logger);
161
153
  const appIdentifier = config.identifier;
162
154
  const cacheEntry = getFromCache(organization, appIdentifier);
163
155
  if (cacheEntry) {
164
- const { cacheValidUntil, validUntil, subscribeLink } = cacheEntry;
156
+ const { cacheValidUntil, validUntil, subscribeLink, type } = cacheEntry;
165
157
  if (cacheValidUntil.getTime() > Date.now()) {
166
- (0, _1.log)(`Loaded data from cache. Subscription is vali until ${validUntil.toISOString()}`, config.logger);
158
+ (0, _1.log)(`Loaded data from cache. Subscription is valid until ${validUntil.toISOString()}`, config.logger);
167
159
  const { expired, daysLeft } = validateSubscription(new Date(validUntil));
168
160
  (0, _1.log)(`expired ${expired}`, config.logger);
169
- return { expired, subscribeLink, daysLeft };
161
+ return { expired, subscribeLink, daysLeft, type };
170
162
  }
171
163
  }
172
164
  try {
@@ -178,19 +170,29 @@ function checkSubscription(config, token, organization, accountType) {
178
170
  (0, _1.log)(`Recieved subscription info. ${JSON.stringify(subscription)}`, config.logger);
179
171
  const { expired, daysLeft } = validateSubscription(new Date(subscription.expires));
180
172
  (0, _1.log)(`expired ${expired}`, config.logger);
181
- addToCache(organization, appIdentifier, new Date(subscription.expires), (_e = config.pricing) === null || _e === void 0 ? void 0 : _e.cachingSeconds);
182
- return { expired, daysLeft };
173
+ addToCache(organization, appIdentifier, new Date(subscription.expires), models_1.SubscriptionInfoType.SUBSCRIPTION, (_a = config.pricing) === null || _a === void 0 ? void 0 : _a.cachingSeconds);
174
+ return { expired, daysLeft, type: models_1.SubscriptionInfoType.SUBSCRIPTION };
183
175
  }
184
176
  catch (e) {
185
177
  if (e instanceof crowdinAppFunctions.PaymentRequiredError) {
186
178
  const { initializedAt, subscribeLink } = e;
187
179
  (0, _1.log)(`Recieved 402 payment error. initializedAt ${initializedAt}`, config.logger);
180
+ //default 2 weeks
181
+ const defaultSubscriptionPlan = 14;
182
+ let days;
183
+ if (organization) {
184
+ days = ((_b = config.pricing) === null || _b === void 0 ? void 0 : _b.trialEnterprise) || ((_c = config.pricing) === null || _c === void 0 ? void 0 : _c.trial) || defaultSubscriptionPlan;
185
+ }
186
+ else {
187
+ days = ((_d = config.pricing) === null || _d === void 0 ? void 0 : _d.trialCrowdin) || ((_e = config.pricing) === null || _e === void 0 ? void 0 : _e.trial) || defaultSubscriptionPlan;
188
+ }
189
+ (0, _1.log)(`Subscriptino trial plan ${days} days`, config.logger);
188
190
  const date = new Date(initializedAt);
189
191
  date.setDate(date.getDate() + days);
190
192
  const { expired, daysLeft } = validateSubscription(date);
191
193
  (0, _1.log)(`expired ${expired}`, config.logger);
192
- addToCache(organization, appIdentifier, new Date(date), (_f = config.pricing) === null || _f === void 0 ? void 0 : _f.cachingSeconds, subscribeLink);
193
- return { expired, subscribeLink, daysLeft };
194
+ addToCache(organization, appIdentifier, new Date(date), models_1.SubscriptionInfoType.TRIAL, (_f = config.pricing) === null || _f === void 0 ? void 0 : _f.cachingSeconds, subscribeLink);
195
+ return { expired, subscribeLink, daysLeft, type: models_1.SubscriptionInfoType.TRIAL };
194
196
  }
195
197
  if (config.onError) {
196
198
  config.onError(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.16.1",
3
+ "version": "0.16.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",