@crowdin/app-project-module 0.44.0 → 0.45.0

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.
Files changed (149) hide show
  1. package/out/index.d.ts +3 -3
  2. package/out/index.js +52 -59
  3. package/out/middlewares/crowdin-client.d.ts +1 -1
  4. package/out/middlewares/crowdin-client.js +3 -2
  5. package/out/middlewares/integration-credentials.d.ts +2 -2
  6. package/out/middlewares/render-ui-module.d.ts +2 -2
  7. package/out/middlewares/ui-module.d.ts +2 -2
  8. package/out/middlewares/ui-module.js +3 -3
  9. package/out/{util → modules}/api/api.d.ts +2 -1
  10. package/out/{util → modules}/api/api.js +22 -22
  11. package/out/modules/api/index.d.ts +6 -0
  12. package/out/modules/api/index.js +14 -0
  13. package/out/modules/api/types.d.ts +20 -0
  14. package/out/modules/api/types.js +11 -0
  15. package/out/modules/context-menu/index.d.ts +1 -1
  16. package/out/modules/context-menu/index.js +2 -2
  17. package/out/modules/context-menu/types.d.ts +27 -0
  18. package/out/modules/context-menu/types.js +18 -0
  19. package/out/modules/custom-mt/handlers/translate.d.ts +1 -1
  20. package/out/modules/custom-mt/index.d.ts +1 -1
  21. package/out/modules/custom-mt/types.d.ts +1 -1
  22. package/out/modules/custom-spell-check/handlers/get-languages-list.d.ts +1 -1
  23. package/out/modules/custom-spell-check/handlers/spell-check.d.ts +1 -1
  24. package/out/modules/custom-spell-check/index.d.ts +1 -1
  25. package/out/modules/custom-spell-check/index.js +2 -2
  26. package/out/modules/custom-spell-check/types.d.ts +1 -1
  27. package/out/modules/editor-right-panel/index.d.ts +1 -1
  28. package/out/modules/editor-right-panel/index.js +2 -2
  29. package/out/modules/editor-right-panel/types.d.ts +1 -1
  30. package/out/modules/editor-themes/index.d.ts +1 -1
  31. package/out/modules/editor-themes/types.d.ts +17 -0
  32. package/out/modules/editor-themes/types.js +2 -0
  33. package/out/modules/file-processing/handlers/custom-file-format.d.ts +1 -1
  34. package/out/modules/file-processing/handlers/custom-file-format.js +1 -1
  35. package/out/modules/file-processing/handlers/file-download.d.ts +2 -2
  36. package/out/modules/file-processing/handlers/pre-post-process.d.ts +1 -1
  37. package/out/modules/file-processing/handlers/pre-post-process.js +1 -1
  38. package/out/modules/file-processing/index.d.ts +1 -1
  39. package/out/modules/file-processing/index.js +1 -1
  40. package/out/modules/file-processing/types.d.ts +1 -1
  41. package/out/modules/file-processing/util/defaults.d.ts +3 -0
  42. package/out/modules/file-processing/util/defaults.js +30 -0
  43. package/out/modules/file-processing/util/files.d.ts +6 -0
  44. package/out/modules/file-processing/util/files.js +47 -0
  45. package/out/modules/form-data-display.d.ts +1 -1
  46. package/out/modules/form-data-save.d.ts +1 -1
  47. package/out/modules/install.d.ts +2 -2
  48. package/out/modules/install.js +3 -3
  49. package/out/modules/integration/handlers/crowdin-file-progress.d.ts +1 -1
  50. package/out/modules/integration/handlers/crowdin-files.d.ts +2 -2
  51. package/out/modules/integration/handlers/crowdin-files.js +1 -1
  52. package/out/modules/integration/handlers/crowdin-project.d.ts +1 -1
  53. package/out/modules/integration/handlers/crowdin-update.d.ts +2 -2
  54. package/out/modules/integration/handlers/crowdin-update.js +7 -7
  55. package/out/modules/integration/handlers/crowdin-webhook.d.ts +2 -2
  56. package/out/modules/integration/handlers/crowdin-webhook.js +16 -5
  57. package/out/modules/integration/handlers/integration-data.d.ts +1 -1
  58. package/out/modules/integration/handlers/integration-data.js +2 -2
  59. package/out/modules/integration/handlers/integration-login.d.ts +1 -1
  60. package/out/modules/integration/handlers/integration-logout.d.ts +2 -2
  61. package/out/modules/integration/handlers/integration-logout.js +11 -4
  62. package/out/modules/integration/handlers/integration-update.d.ts +2 -2
  63. package/out/modules/integration/handlers/integration-update.js +7 -6
  64. package/out/modules/integration/handlers/integration-webhook.d.ts +2 -2
  65. package/out/modules/integration/handlers/integration-webhook.js +7 -2
  66. package/out/modules/integration/handlers/job-cancel.d.ts +1 -1
  67. package/out/modules/integration/handlers/job-cancel.js +2 -2
  68. package/out/modules/integration/handlers/job-info.d.ts +1 -1
  69. package/out/modules/integration/handlers/job-info.js +2 -2
  70. package/out/modules/integration/handlers/main.d.ts +2 -2
  71. package/out/modules/integration/handlers/main.js +3 -3
  72. package/out/modules/integration/handlers/oauth-login.d.ts +2 -2
  73. package/out/modules/integration/handlers/oauth-login.js +1 -1
  74. package/out/modules/integration/handlers/oauth-url.d.ts +1 -1
  75. package/out/modules/integration/handlers/oauth-url.js +1 -1
  76. package/out/modules/integration/handlers/settings-save.d.ts +2 -2
  77. package/out/modules/integration/handlers/settings-save.js +25 -8
  78. package/out/modules/integration/handlers/settings.d.ts +1 -1
  79. package/out/modules/integration/handlers/subscription-info.d.ts +1 -1
  80. package/out/modules/integration/handlers/subscription-info.js +2 -2
  81. package/out/modules/integration/handlers/sync-settings-save.d.ts +2 -2
  82. package/out/modules/integration/handlers/sync-settings-save.js +15 -7
  83. package/out/modules/integration/handlers/sync-settings.d.ts +1 -1
  84. package/out/modules/integration/handlers/user-errors.d.ts +1 -1
  85. package/out/modules/integration/index.d.ts +1 -1
  86. package/out/modules/integration/index.js +15 -10
  87. package/out/modules/integration/types.d.ts +2 -13
  88. package/out/modules/integration/util/cron.d.ts +27 -0
  89. package/out/{util → modules/integration/util}/cron.js +92 -23
  90. package/out/{util → modules/integration/util}/defaults.d.ts +2 -6
  91. package/out/{util → modules/integration/util}/defaults.js +1 -46
  92. package/out/modules/integration/util/files.d.ts +5 -0
  93. package/out/{util → modules/integration/util}/files.js +9 -40
  94. package/out/{util → modules/integration/util}/job.d.ts +1 -1
  95. package/out/{util → modules/integration/util}/job.js +11 -11
  96. package/out/{util/file-snapshot.d.ts → modules/integration/util/snapshot.d.ts} +2 -4
  97. package/out/{util/file-snapshot.js → modules/integration/util/snapshot.js} +4 -63
  98. package/out/{models/job.d.ts → modules/integration/util/types.d.ts} +14 -0
  99. package/out/modules/integration/util/webhooks.d.ts +48 -0
  100. package/out/{util → modules/integration/util}/webhooks.js +92 -46
  101. package/out/modules/manifest.d.ts +1 -1
  102. package/out/modules/manifest.js +6 -6
  103. package/out/modules/modal/index.d.ts +1 -1
  104. package/out/modules/modal/index.js +2 -2
  105. package/out/modules/organization-menu/index.d.ts +1 -1
  106. package/out/modules/organization-menu/index.js +1 -2
  107. package/out/modules/profile-resources-menu/index.d.ts +1 -1
  108. package/out/modules/profile-resources-menu/index.js +1 -2
  109. package/out/modules/project-menu/index.d.ts +1 -1
  110. package/out/modules/project-menu/index.js +2 -2
  111. package/out/modules/project-menu-crowdsource/index.d.ts +1 -1
  112. package/out/modules/project-menu-crowdsource/index.js +2 -2
  113. package/out/modules/project-reports/index.d.ts +1 -1
  114. package/out/modules/project-reports/index.js +1 -2
  115. package/out/modules/project-tools/index.d.ts +1 -1
  116. package/out/modules/project-tools/index.js +1 -2
  117. package/out/modules/subscription-paid.d.ts +1 -1
  118. package/out/modules/subscription-paid.js +2 -2
  119. package/out/modules/uninstall.d.ts +2 -2
  120. package/out/modules/uninstall.js +6 -2
  121. package/out/storage/index.d.ts +3 -2
  122. package/out/storage/mysql.d.ts +3 -2
  123. package/out/storage/mysql.js +3 -3
  124. package/out/storage/postgre.d.ts +3 -2
  125. package/out/storage/postgre.js +3 -3
  126. package/out/storage/sqlite.d.ts +3 -2
  127. package/out/storage/sqlite.js +3 -3
  128. package/out/storage/types.d.ts +9 -0
  129. package/out/storage/types.js +2 -0
  130. package/out/{models/index.d.ts → types.d.ts} +15 -83
  131. package/out/{models/index.js → types.js} +1 -24
  132. package/out/util/connection.d.ts +1 -9
  133. package/out/util/connection.js +54 -150
  134. package/out/util/handlebars.d.ts +1 -0
  135. package/out/util/handlebars.js +34 -0
  136. package/out/util/index.d.ts +2 -3
  137. package/out/util/index.js +6 -6
  138. package/out/util/logger.d.ts +1 -1
  139. package/out/util/subscription.d.ts +9 -0
  140. package/out/util/subscription.js +111 -0
  141. package/package.json +1 -1
  142. package/out/util/cron.d.ts +0 -8
  143. package/out/util/files.d.ts +0 -10
  144. package/out/util/webhooks.d.ts +0 -29
  145. /package/out/{util → modules}/api/base.d.ts +0 -0
  146. /package/out/{util → modules}/api/base.js +0 -0
  147. /package/out/{util → modules}/api/components.d.ts +0 -0
  148. /package/out/{util → modules}/api/components.js +0 -0
  149. /package/out/{models/job.js → modules/integration/util/types.js} +0 -0
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.clearCache = exports.checkSubscription = exports.isAppFree = void 0;
13
+ const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
14
+ const types_1 = require("../types");
15
+ const logger_1 = require("./logger");
16
+ const subscriptionCache = {};
17
+ function isAppFree(config) {
18
+ return !config.pricing || config.pricing.planType === 'free';
19
+ }
20
+ exports.isAppFree = isAppFree;
21
+ function checkSubscription({ config, token, organization, accountType, }) {
22
+ var _a, _b, _c, _d, _e, _f, _g;
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ if (isAppFree(config)) {
25
+ return { expired: false };
26
+ }
27
+ (0, logger_1.log)('Checking subscription plan');
28
+ const appIdentifier = config.identifier;
29
+ const cacheEntry = getFromCache(organization, appIdentifier);
30
+ if (cacheEntry) {
31
+ const { cacheValidUntil, validUntil, subscribeLink, type } = cacheEntry;
32
+ if (cacheValidUntil.getTime() > Date.now()) {
33
+ (0, logger_1.log)(`Loaded data from cache. Subscription is valid until ${validUntil.toISOString()}`);
34
+ const { expired, daysLeft } = validateSubscription(new Date(validUntil));
35
+ (0, logger_1.log)(`expired ${expired}`);
36
+ return { expired, subscribeLink, daysLeft, type };
37
+ }
38
+ }
39
+ try {
40
+ const subscription = yield (0, crowdin_apps_functions_1.getSubscription)({
41
+ appIdentifier,
42
+ organization: accountType === types_1.AccountType.ENTERPRISE ? organization : undefined,
43
+ token,
44
+ baseUrl: (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.subscriptionUrl,
45
+ });
46
+ (0, logger_1.log)(`Recieved subscription info. ${JSON.stringify(subscription)}`);
47
+ const { expired, daysLeft } = validateSubscription(new Date(subscription.expires));
48
+ (0, logger_1.log)(`expired ${expired}`);
49
+ addToCache(organization, appIdentifier, new Date(subscription.expires), types_1.SubscriptionInfoType.SUBSCRIPTION, (_b = config.pricing) === null || _b === void 0 ? void 0 : _b.cachingSeconds);
50
+ return { expired, daysLeft, type: types_1.SubscriptionInfoType.SUBSCRIPTION };
51
+ }
52
+ catch (e) {
53
+ if (e instanceof crowdin_apps_functions_1.PaymentRequiredError) {
54
+ const { initializedAt, subscribeLink } = e;
55
+ (0, logger_1.log)(`Recieved 402 payment error. initializedAt ${initializedAt}`);
56
+ //default 2 weeks
57
+ const defaultSubscriptionPlan = 14;
58
+ let days;
59
+ if (accountType === types_1.AccountType.ENTERPRISE) {
60
+ days = ((_c = config.pricing) === null || _c === void 0 ? void 0 : _c.trialEnterprise) || ((_d = config.pricing) === null || _d === void 0 ? void 0 : _d.trial) || defaultSubscriptionPlan;
61
+ }
62
+ else {
63
+ days = ((_e = config.pricing) === null || _e === void 0 ? void 0 : _e.trialCrowdin) || ((_f = config.pricing) === null || _f === void 0 ? void 0 : _f.trial) || defaultSubscriptionPlan;
64
+ }
65
+ (0, logger_1.log)(`Subscriptino trial plan ${days} days`);
66
+ const date = new Date(initializedAt);
67
+ date.setDate(date.getDate() + days);
68
+ const { expired, daysLeft } = validateSubscription(date);
69
+ (0, logger_1.log)(`expired ${expired}`);
70
+ addToCache(organization, appIdentifier, new Date(date), types_1.SubscriptionInfoType.TRIAL, (_g = config.pricing) === null || _g === void 0 ? void 0 : _g.cachingSeconds, subscribeLink);
71
+ return { expired, subscribeLink, daysLeft, type: types_1.SubscriptionInfoType.TRIAL };
72
+ }
73
+ if (config.onError) {
74
+ config.onError(e);
75
+ }
76
+ else {
77
+ console.error(e);
78
+ }
79
+ (0, logger_1.log)('Recieved http error from subscription request. Returning expired=false');
80
+ return { expired: false };
81
+ }
82
+ });
83
+ }
84
+ exports.checkSubscription = checkSubscription;
85
+ function clearCache(organization) {
86
+ delete subscriptionCache[organization];
87
+ }
88
+ exports.clearCache = clearCache;
89
+ function addToCache(organization, appIdentifier, validUntil, type, cachingSeconds, subscribeLink) {
90
+ if (!cachingSeconds) {
91
+ return;
92
+ }
93
+ const orgCache = subscriptionCache[organization] || {};
94
+ const now = new Date();
95
+ now.setSeconds(now.getSeconds() + cachingSeconds);
96
+ orgCache[appIdentifier] = {
97
+ cacheValidUntil: now,
98
+ validUntil,
99
+ subscribeLink,
100
+ type,
101
+ };
102
+ subscriptionCache[organization] = orgCache;
103
+ }
104
+ function getFromCache(organization, appIdentifier) {
105
+ return (subscriptionCache[organization] || {})[appIdentifier];
106
+ }
107
+ function validateSubscription(date) {
108
+ const expired = date.getTime() < Date.now();
109
+ const daysLeft = Math.round((date.getTime() - Date.now()) / (1000 * 60 * 60 * 24));
110
+ return { expired, daysLeft };
111
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
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",
@@ -1,8 +0,0 @@
1
- import Crowdin from '@crowdin/crowdin-api-client';
2
- import { Config } from '../models';
3
- import { CronJob, IntegrationLogic, IntegrationRequest, Provider, UpdateIntegrationRequest } from '../modules/integration/types';
4
- export declare function runJob(config: Config, integration: IntegrationLogic, job: CronJob): Promise<void>;
5
- export declare function filesCron(config: Config, integration: IntegrationLogic, period: string): Promise<void>;
6
- export declare function skipFoldersFromIntegrationRequest(config: Config, integration: IntegrationLogic, projectId: number, crowdinFiles: UpdateIntegrationRequest, crowdinClient: Crowdin): Promise<UpdateIntegrationRequest>;
7
- export declare function createOrUpdateSyncSettings(config: Config, req: IntegrationRequest, files: any, provider: Provider, onlyCreate?: boolean): Promise<void>;
8
- export declare function removeFinishedJobs(): Promise<void>;
@@ -1,10 +0,0 @@
1
- /// <reference types="node" />
2
- import { IntegrationFile, IntegrationLogic, IntegrationRequest, SkipIntegrationNodes, TreeItem } from '../modules/integration/types';
3
- import { JobClient } from '../models/job';
4
- import { ProcessFileString } from '../modules/file-processing/types';
5
- export declare const MAX_BODY_SIZE: number;
6
- export declare function storeFile(fileContent: Buffer, folder: string): Promise<string>;
7
- export declare function getFileContent(url: string): Promise<Buffer>;
8
- export declare function getFileStrings(url: string): Promise<ProcessFileString[]>;
9
- export declare function skipFilesByRegex(files: TreeItem[] | undefined, skipIntegrationNodes?: SkipIntegrationNodes): TreeItem[];
10
- export declare function expandFilesTree(nodes: IntegrationFile[], req: IntegrationRequest, integration: IntegrationLogic, job?: JobClient): Promise<IntegrationFile[]>;
@@ -1,29 +0,0 @@
1
- import Crowdin from '@crowdin/crowdin-api-client';
2
- import { WebhooksModel } from '@crowdin/crowdin-api-client/out/webhooks';
3
- import { Config, CrowdinContextInfo } from '../models';
4
- import { AppSettings, IntegrationLogic, IntegrationSyncSettings, Provider, UpdateCrowdinWebhookPayloadsArgs, WebhookUrlParams } from '../modules/integration/types';
5
- export declare const HookEvents: any;
6
- export declare function encodedUrlParam(config: Config, integration: IntegrationLogic, crowdinContext: CrowdinContextInfo): string;
7
- export declare function decodedUrlParam(config: Config, data: string): WebhookUrlParams;
8
- export declare function makeCrowdinWebhookUrl(config: Config, integration: IntegrationLogic, crowdinContext: CrowdinContextInfo): string;
9
- export declare function registerWebhooks(config: Config, integration: IntegrationLogic, client: Crowdin, crowdinContext: CrowdinContextInfo, apiCredentials: any, appSettings: AppSettings): Promise<void>;
10
- export declare function unregisterWebhooks(config: Config, integration: IntegrationLogic, client: Crowdin, crowdinContext: CrowdinContextInfo, apiCredentials: any, appSettings: AppSettings): Promise<void>;
11
- export declare function getCrowdinProjectWebhook(config: Config, client: Crowdin, projectId: number, name: string): Promise<WebhooksModel.Webhook | undefined>;
12
- export declare function getAllCrowdinProjectWebhooks(config: Config, client: Crowdin, projectId: number): Promise<WebhooksModel.Webhook[]>;
13
- export declare function registerCrowdinWebhook(config: Config, url: string, client: Crowdin, crowdinContext: CrowdinContextInfo, events: WebhooksModel.Event[]): Promise<void>;
14
- export declare function updateCrowdinWebhooks(config: Config, client: Crowdin, projectId: number, webhook: WebhooksModel.Webhook, events: WebhooksModel.Event[], url: string): Promise<void>;
15
- export declare function unregisterCrowdinWebhooks(config: Config, client: Crowdin, projectId: number, webhook: WebhooksModel.Webhook): Promise<void>;
16
- export declare function unregisterAllCrowdinWebhooks(config: Config, integration: IntegrationLogic, crowdinId: string): Promise<void>;
17
- export declare function prepareWebhookData(config: Config, integration: IntegrationLogic, webhookUrlParam: string, provider: Provider): Promise<{
18
- projectId: number;
19
- crowdinClient: {
20
- client: Crowdin;
21
- token: string;
22
- };
23
- preparedIntegrationCredentials: any;
24
- rootFolder: import("@crowdin/crowdin-api-client").SourceFilesModel.Directory | undefined;
25
- appSettings: AppSettings;
26
- syncSettings: IntegrationSyncSettings | null;
27
- }>;
28
- export declare function updateCrowdinFromWebhookRequest(args: UpdateCrowdinWebhookPayloadsArgs): Promise<void>;
29
- export declare function listenQueueMessage(config: Config, integration: IntegrationLogic, queueUrl: string, queueName: string): Promise<void>;
File without changes
File without changes
File without changes
File without changes