@crowdin/app-project-module 0.44.0 → 0.45.1

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 +27 -66
  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} +16 -84
  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
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const job_1 = require("../../../models/job");
12
+ const types_1 = require("../util/types");
13
13
  const util_1 = require("../../../util");
14
14
  const storage_1 = require("../../../storage");
15
15
  function getHumanETA(ms) {
@@ -43,7 +43,7 @@ function handle() {
43
43
  }
44
44
  req.logInfo(`Get job info for id ${id}`);
45
45
  const job = yield (0, storage_1.getStorage)().getJob({ id });
46
- if (job && job.status === job_1.JobStatus.IN_PROGRESS && job.progress > 5 && job.updatedAt) {
46
+ if (job && job.status === types_1.JobStatus.IN_PROGRESS && job.progress > 5 && job.updatedAt) {
47
47
  job.eta = ((Date.now() - job.createdAt) / job.progress) * (100 - job.progress);
48
48
  job.info = getHumanETA(job.eta) + (job.info ? `\n${job.info}` : '');
49
49
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config } from '../../../models';
3
+ import { Config } from '../../../types';
4
4
  import { IntegrationLogic } from '../types';
5
- export default function handle(config: Config, integration: IntegrationLogic): (req: import("../../../models").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
5
+ export default function handle(config: Config, integration: IntegrationLogic): (req: import("../../../types").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -10,9 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const util_1 = require("../../../util");
13
- const connection_1 = require("../../../util/connection");
14
- const defaults_1 = require("../../../util/defaults");
15
13
  const logger_1 = require("../../../util/logger");
14
+ const subscription_1 = require("../../../util/subscription");
15
+ const defaults_1 = require("../util/defaults");
16
16
  function handle(config, integration) {
17
17
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
18
18
  var _a, _b;
@@ -57,7 +57,7 @@ function handle(config, integration) {
57
57
  : {};
58
58
  options.integrationOneLevelFetching = integration.integrationOneLevelFetching;
59
59
  options.integrationSearchListener = integration.integrationSearchListener;
60
- options.checkSubscription = !(0, connection_1.isAppFree)(config);
60
+ options.checkSubscription = !(0, subscription_1.isAppFree)(config);
61
61
  options.uploadTranslations = integration.uploadTranslations;
62
62
  options.sentryData = process.env.SENTRY_DSN
63
63
  ? {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="qs" />
2
2
  import { Request, Response } from 'express';
3
- import { Config } from '../../../models';
3
+ import { Config } from '../../../types';
4
4
  import { IntegrationLogic } from '../types';
5
- export default function handle(config: Config, integration: IntegrationLogic): (req: import("../../../models").CrowdinClientRequest | Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
5
+ export default function handle(config: Config, integration: IntegrationLogic): (req: import("../../../types").CrowdinClientRequest | Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const axios_1 = __importDefault(require("axios"));
16
16
  const util_1 = require("../../../util");
17
- const defaults_1 = require("../../../util/defaults");
17
+ const defaults_1 = require("../util/defaults");
18
18
  const logger_1 = require("../../../util/logger");
19
19
  function handle(config, integration) {
20
20
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config, CrowdinClientRequest } from '../../../models';
3
+ import { Config, CrowdinClientRequest } from '../../../types';
4
4
  import { IntegrationLogic } from '../types';
5
5
  export default function handle(config: Config, integration: IntegrationLogic): (req: CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const util_1 = require("../../../util");
13
- const defaults_1 = require("../../../util/defaults");
13
+ const defaults_1 = require("../util/defaults");
14
14
  function handle(config, integration) {
15
15
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
16
  req.logInfo('Received OAuth login url request');
@@ -1,5 +1,5 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config } from '../../../models';
3
+ import { Config } from '../../../types';
4
4
  import { IntegrationLogic } from '../types';
5
- export default function handle(config: Config, integration: IntegrationLogic): (req: import("../../../models").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
5
+ export default function handle(config: Config, integration: IntegrationLogic): (req: import("../../../types").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -11,10 +11,10 @@ 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 cron_1 = require("../../../util/cron");
15
- const file_snapshot_1 = require("../../../util/file-snapshot");
16
- const webhooks_1 = require("../../../util/webhooks");
14
+ const snapshot_1 = require("../util/snapshot");
15
+ const webhooks_1 = require("../util/webhooks");
17
16
  const types_1 = require("../types");
17
+ const cron_1 = require("../util/cron");
18
18
  function handle(config, integration) {
19
19
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
20
20
  const appSettings = req.body.config;
@@ -28,19 +28,36 @@ function handle(config, integration) {
28
28
  yield (0, storage_1.getStorage)().updateIntegrationConfig(clientId, JSON.stringify(appSettings));
29
29
  }
30
30
  if (integration.webhooks) {
31
- yield (0, webhooks_1.registerWebhooks)(config, integration, req.crowdinApiClient, req.crowdinContext, req.integrationCredentials, appSettings);
31
+ yield (0, webhooks_1.registerWebhooks)({
32
+ config,
33
+ integration,
34
+ client: req.crowdinApiClient,
35
+ crowdinContext: req.crowdinContext,
36
+ apiCredentials: req.integrationCredentials,
37
+ appSettings,
38
+ });
32
39
  }
33
40
  else {
34
41
  if (appSettings['new-crowdin-files']) {
35
- (0, file_snapshot_1.createOrUpdateFileSnapshot)(config, integration, req, types_1.Provider.CROWDIN);
42
+ (0, snapshot_1.createOrUpdateFileSnapshot)(config, integration, req, types_1.Provider.CROWDIN);
36
43
  }
37
44
  if (appSettings['new-integration-files']) {
38
- (0, file_snapshot_1.createOrUpdateFileSnapshot)(config, integration, req, types_1.Provider.INTEGRATION);
45
+ (0, snapshot_1.createOrUpdateFileSnapshot)(config, integration, req, types_1.Provider.INTEGRATION);
39
46
  }
40
47
  }
41
48
  if (integration.syncNewElements) {
42
- yield (0, cron_1.createOrUpdateSyncSettings)(config, req, {}, types_1.Provider.CROWDIN, true);
43
- yield (0, cron_1.createOrUpdateSyncSettings)(config, req, [], types_1.Provider.INTEGRATION, true);
49
+ yield (0, cron_1.createOrUpdateSyncSettings)({
50
+ req,
51
+ files: {},
52
+ provider: types_1.Provider.CROWDIN,
53
+ onlyCreate: true,
54
+ });
55
+ yield (0, cron_1.createOrUpdateSyncSettings)({
56
+ req,
57
+ files: [],
58
+ provider: types_1.Provider.INTEGRATION,
59
+ onlyCreate: true,
60
+ });
44
61
  }
45
62
  res.status(204).end();
46
63
  }));
@@ -1,3 +1,3 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- export default function handle(): (req: import("../../../models").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
3
+ export default function handle(): (req: import("../../../types").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -1,3 +1,3 @@
1
1
  import { Request, Response } from 'express';
2
- import { Config } from '../../../models';
2
+ import { Config } from '../../../types';
3
3
  export default function handle(config: Config): (req: Request, res: Response) => void;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const models_1 = require("../../../models");
3
+ const types_1 = require("../../../types");
4
4
  function handle(config) {
5
5
  return (req, res) => {
6
6
  var _a;
7
7
  const subscriptionInfo = req.subscriptionInfo;
8
- let showInfo = (subscriptionInfo === null || subscriptionInfo === void 0 ? void 0 : subscriptionInfo.type) === models_1.SubscriptionInfoType.TRIAL;
8
+ let showInfo = (subscriptionInfo === null || subscriptionInfo === void 0 ? void 0 : subscriptionInfo.type) === types_1.SubscriptionInfoType.TRIAL;
9
9
  if (showInfo && ((_a = config.pricing) === null || _a === void 0 ? void 0 : _a.infoDisplayDaysThreshold)) {
10
10
  showInfo = config.pricing.infoDisplayDaysThreshold >= ((subscriptionInfo === null || subscriptionInfo === void 0 ? void 0 : subscriptionInfo.daysLeft) || 0);
11
11
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config } from '../../../models';
3
+ import { Config } from '../../../types';
4
4
  import { IntegrationLogic } from '../types';
5
- export default function handle(config: Config, integration: IntegrationLogic): (req: import("../../../models").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
5
+ export default function handle(config: Config, integration: IntegrationLogic): (req: import("../../../types").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -14,10 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const lodash_uniqby_1 = __importDefault(require("lodash.uniqby"));
16
16
  const util_1 = require("../../../util");
17
- const cron_1 = require("../../../util/cron");
18
- const file_snapshot_1 = require("../../../util/file-snapshot");
19
- const files_1 = require("../../../util/files");
20
- const job_1 = require("../../../util/job");
17
+ const cron_1 = require("../util/cron");
18
+ const snapshot_1 = require("../util/snapshot");
19
+ const files_1 = require("../util/files");
20
+ const job_1 = require("../util/job");
21
21
  function handle(config, integration) {
22
22
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
23
23
  const { files, provider, expandIntegrationFolders } = req.body;
@@ -42,14 +42,22 @@ function handle(config, integration) {
42
42
  sync: false,
43
43
  type: node.type,
44
44
  }));
45
- yield (0, cron_1.createOrUpdateSyncSettings)(config, req, (0, lodash_uniqby_1.default)([...files, ...allFiles], 'id'), provider);
45
+ yield (0, cron_1.createOrUpdateSyncSettings)({
46
+ req,
47
+ files: (0, lodash_uniqby_1.default)([...files, ...allFiles], 'id'),
48
+ provider,
49
+ });
46
50
  }
47
51
  else {
48
- yield (0, cron_1.createOrUpdateSyncSettings)(config, req, files, provider);
52
+ yield (0, cron_1.createOrUpdateSyncSettings)({
53
+ req,
54
+ files,
55
+ provider,
56
+ });
49
57
  }
50
58
  const appSettings = req.integrationSettings || {};
51
59
  if (((_a = integration.syncNewElements) === null || _a === void 0 ? void 0 : _a[provider]) && appSettings[`new-${provider}-files`]) {
52
- yield (0, file_snapshot_1.createOrUpdateFileSnapshot)(config, integration, req, provider);
60
+ yield (0, snapshot_1.createOrUpdateFileSnapshot)(config, integration, req, provider);
53
61
  }
54
62
  }),
55
63
  });
@@ -1,3 +1,3 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- export default function handle(): (req: import("../../../models").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
3
+ export default function handle(): (req: import("../../../types").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -1,3 +1,3 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- export default function handle(): (req: import("../../../models").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
3
+ export default function handle(): (req: import("../../../types").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -1,5 +1,5 @@
1
1
  import { Express } from 'express';
2
- import { Config } from '../../models';
2
+ import { Config } from '../../types';
3
3
  export declare function register({ config, app }: {
4
4
  config: Config;
5
5
  app: Express;
@@ -32,9 +32,8 @@ const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-clie
32
32
  const integration_credentials_1 = __importDefault(require("../../middlewares/integration-credentials"));
33
33
  const json_response_1 = __importDefault(require("../../middlewares/json-response"));
34
34
  const util_1 = require("../../util");
35
- const cron_1 = require("../../util/cron");
36
- const defaults_1 = require("../../util/defaults");
37
- const webhooks_1 = require("../../util/webhooks");
35
+ const defaults_1 = require("./util/defaults");
36
+ const webhooks_1 = require("./util/webhooks");
38
37
  const crowdin_file_progress_1 = __importDefault(require("./handlers/crowdin-file-progress"));
39
38
  const crowdin_files_1 = __importDefault(require("./handlers/crowdin-files"));
40
39
  const crowdin_project_1 = __importDefault(require("./handlers/crowdin-project"));
@@ -55,6 +54,7 @@ const subscription_info_1 = __importDefault(require("./handlers/subscription-inf
55
54
  const sync_settings_1 = __importDefault(require("./handlers/sync-settings"));
56
55
  const sync_settings_save_1 = __importDefault(require("./handlers/sync-settings-save"));
57
56
  const user_errors_1 = __importDefault(require("./handlers/user-errors"));
57
+ const cron_1 = require("./util/cron");
58
58
  function register({ config, app }) {
59
59
  var _a, _b, _c;
60
60
  const integrationLogic = config.projectIntegration;
@@ -84,15 +84,15 @@ function register({ config, app }) {
84
84
  }
85
85
  if (integrationLogic.cronJobs) {
86
86
  integrationLogic.cronJobs.forEach((job) => {
87
- cron.schedule(job.expression, () => (0, cron_1.runJob)(config, integrationLogic, job).catch(console.error));
87
+ cron.schedule(job.expression, () => (0, cron_1.runJob)({ config, integration: integrationLogic, job }).catch(console.error));
88
88
  });
89
89
  }
90
90
  if (integrationLogic.withCronSync) {
91
- cron.schedule('0 * * * *', () => (0, cron_1.filesCron)(config, integrationLogic, '1').catch(console.error));
92
- cron.schedule('0 */3 * * *', () => (0, cron_1.filesCron)(config, integrationLogic, '3').catch(console.error));
93
- cron.schedule('0 */6 * * *', () => (0, cron_1.filesCron)(config, integrationLogic, '6').catch(console.error));
94
- cron.schedule('0 */12 * * *', () => (0, cron_1.filesCron)(config, integrationLogic, '12').catch(console.error));
95
- cron.schedule('0 0 * * *', () => (0, cron_1.filesCron)(config, integrationLogic, '24').catch(console.error));
91
+ cron.schedule('0 * * * *', () => (0, cron_1.filesCron)({ config, integration: integrationLogic, period: '1' }).catch(console.error));
92
+ cron.schedule('0 */3 * * *', () => (0, cron_1.filesCron)({ config, integration: integrationLogic, period: '3' }).catch(console.error));
93
+ cron.schedule('0 */6 * * *', () => (0, cron_1.filesCron)({ config, integration: integrationLogic, period: '6' }).catch(console.error));
94
+ cron.schedule('0 */12 * * *', () => (0, cron_1.filesCron)({ config, integration: integrationLogic, period: '12' }).catch(console.error));
95
+ cron.schedule('0 0 * * *', () => (0, cron_1.filesCron)({ config, integration: integrationLogic, period: '24' }).catch(console.error));
96
96
  }
97
97
  if (integrationLogic.webhooks) {
98
98
  app.post(`${integrationLogic.webhooks.crowdinWebhookUrl
@@ -104,7 +104,12 @@ function register({ config, app }) {
104
104
  : '/api/integration/webhook'}`, (0, integration_webhook_1.default)(config, integrationLogic));
105
105
  }
106
106
  if ((_c = integrationLogic.webhooks) === null || _c === void 0 ? void 0 : _c.queueUrl) {
107
- (0, webhooks_1.listenQueueMessage)(config, integrationLogic, integrationLogic.webhooks.queueUrl, config.identifier);
107
+ (0, webhooks_1.listenQueueMessage)({
108
+ config,
109
+ integration: integrationLogic,
110
+ queueUrl: integrationLogic.webhooks.queueUrl,
111
+ queueName: config.identifier,
112
+ });
108
113
  }
109
114
  }
110
115
  app.get('/api/user-errors', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, user_errors_1.default)());
@@ -1,7 +1,7 @@
1
1
  import Crowdin, { SourceFilesModel, TranslationStatusModel } from '@crowdin/crowdin-api-client';
2
2
  import { Request } from 'express';
3
- import { Config, CrowdinClientRequest } from '../../models';
4
- import { JobClient } from '../../models/job';
3
+ import { CrowdinClientRequest } from '../../types';
4
+ import { JobClient } from './util/types';
5
5
  export interface IntegrationLogic {
6
6
  /**
7
7
  * Customize your app login form
@@ -413,17 +413,6 @@ export type WebhookUrlParams = {
413
413
  crowdinId: string;
414
414
  clientId: string;
415
415
  };
416
- export interface GetAllNewFilesArgs {
417
- config: Config;
418
- integration: IntegrationLogic;
419
- crowdinApiClient: Crowdin;
420
- crowdinId: string;
421
- integrationCredentials: any;
422
- integrationId: string;
423
- projectId: number;
424
- integrationSettings: any;
425
- syncSettings: IntegrationSyncSettings;
426
- }
427
416
  export interface UpdateCrowdinWebhookPayloadsArgs {
428
417
  integration: IntegrationLogic;
429
418
  webhookData: any;
@@ -0,0 +1,27 @@
1
+ import Crowdin from '@crowdin/crowdin-api-client';
2
+ import { Config } from '../../../types';
3
+ import { CronJob, IntegrationLogic, IntegrationRequest, Provider, UpdateIntegrationRequest } from '../types';
4
+ export declare function runJob({ config, integration, job, }: {
5
+ config: Config;
6
+ integration: IntegrationLogic;
7
+ job: CronJob;
8
+ }): Promise<void>;
9
+ export declare function filesCron({ config, integration, period, }: {
10
+ config: Config;
11
+ integration: IntegrationLogic;
12
+ period: string;
13
+ }): Promise<void>;
14
+ export declare function skipFoldersFromIntegrationRequest({ config, integration, projectId, crowdinClient, crowdinFiles, }: {
15
+ config: Config;
16
+ integration: IntegrationLogic;
17
+ projectId: number;
18
+ crowdinFiles: UpdateIntegrationRequest;
19
+ crowdinClient: Crowdin;
20
+ }): Promise<UpdateIntegrationRequest>;
21
+ export declare function createOrUpdateSyncSettings({ req, files, provider, onlyCreate, }: {
22
+ req: IntegrationRequest;
23
+ files: any;
24
+ provider: Provider;
25
+ onlyCreate?: boolean;
26
+ }): Promise<void>;
27
+ export declare function removeFinishedJobs(): Promise<void>;
@@ -34,15 +34,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.removeFinishedJobs = exports.createOrUpdateSyncSettings = exports.skipFoldersFromIntegrationRequest = exports.filesCron = exports.runJob = void 0;
36
36
  const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
37
- const job_1 = require("../models/job");
38
- const storage_1 = require("../storage");
39
- const connection_1 = require("./connection");
37
+ const storage_1 = require("../../../storage");
38
+ const connection_1 = require("../../../util/connection");
40
39
  const defaults_1 = require("./defaults");
41
- const file_snapshot_1 = require("./file-snapshot");
42
- const logger_1 = require("./logger");
43
- const job_2 = require("./job");
44
- const types_1 = require("../modules/integration/types");
45
- function runJob(config, integration, job) {
40
+ const snapshot_1 = require("./snapshot");
41
+ const logger_1 = require("../../../util/logger");
42
+ const types_1 = require("../types");
43
+ const job_1 = require("./job");
44
+ const types_2 = require("./types");
45
+ const subscription_1 = require("../../../util/subscription");
46
+ function runJob({ config, integration, job, }) {
46
47
  return __awaiter(this, void 0, void 0, function* () {
47
48
  (0, logger_1.log)(`Starting cron job with expression [${job.expression}]`);
48
49
  const crowdinCredentialsList = yield (0, storage_1.getStorage)().getAllCrowdinCredentials();
@@ -52,7 +53,7 @@ function runJob(config, integration, job) {
52
53
  credentials: crowdinCredentials,
53
54
  autoRenew: true,
54
55
  });
55
- const { expired } = yield (0, connection_1.checkSubscription)({
56
+ const { expired } = yield (0, subscription_1.checkSubscription)({
56
57
  config,
57
58
  token,
58
59
  organization: crowdinCredentials.id,
@@ -79,7 +80,7 @@ function runJob(config, integration, job) {
79
80
  });
80
81
  }
81
82
  exports.runJob = runJob;
82
- function filesCron(config, integration, period) {
83
+ function filesCron({ config, integration, period, }) {
83
84
  return __awaiter(this, void 0, void 0, function* () {
84
85
  (0, logger_1.log)(`Starting files cron job with period [${period}]`);
85
86
  const syncSettingsList = yield (0, storage_1.getStorage)().getAllSyncSettingsByType('schedule');
@@ -120,7 +121,7 @@ function filesCron(config, integration, period) {
120
121
  autoRenew: true,
121
122
  context,
122
123
  });
123
- const { expired } = yield (0, connection_1.checkSubscription)({
124
+ const { expired } = yield (0, subscription_1.checkSubscription)({
124
125
  config,
125
126
  token,
126
127
  organization: crowdinCredentials.id,
@@ -135,7 +136,7 @@ function filesCron(config, integration, period) {
135
136
  if (!integration.webhooks &&
136
137
  ((_a = integration.syncNewElements) === null || _a === void 0 ? void 0 : _a[syncSettings.provider]) &&
137
138
  intConfig[`new-${syncSettings.provider}-files`]) {
138
- newFiles = yield (0, file_snapshot_1.getAllNewFiles)({
139
+ newFiles = yield getAllNewFiles({
139
140
  config,
140
141
  integration,
141
142
  crowdinApiClient: crowdinClient,
@@ -164,13 +165,25 @@ function filesCron(config, integration, period) {
164
165
  yield (0, storage_1.getStorage)().deleteWebhooks(webhooksFileIds, syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
165
166
  }
166
167
  if (syncSettings.provider === types_1.Provider.CROWDIN) {
167
- const crowdinFiles = yield skipFoldersFromIntegrationRequest(config, integration, projectId, Object.assign(Object.assign({}, files), newFiles), crowdinClient);
168
+ const crowdinFiles = yield skipFoldersFromIntegrationRequest({
169
+ config,
170
+ integration,
171
+ projectId,
172
+ crowdinFiles: Object.assign(Object.assign({}, files), newFiles),
173
+ crowdinClient,
174
+ });
168
175
  const onlyTranslated = +intConfig.condition === types_1.SyncCondition.TRANSLATED;
169
176
  const onlyApproved = +intConfig.condition === types_1.SyncCondition.APPROVED;
170
177
  const all = +intConfig.condition === types_1.SyncCondition.ALL || intConfig.condition === undefined;
171
178
  const filesToProcess = all
172
179
  ? crowdinFiles
173
- : yield getOnlyTranslatedOrApprovedFiles(config, projectId, crowdinFiles, crowdinClient, onlyApproved, onlyTranslated);
180
+ : yield getOnlyTranslatedOrApprovedFiles({
181
+ projectId,
182
+ crowdinFiles,
183
+ crowdinClient,
184
+ onlyApproved,
185
+ onlyTranslated,
186
+ });
174
187
  (0, logger_1.log)(`Executing updateIntegration task for files cron job with period [${period}] for project ${projectId}.Files ${Object.keys(filesToProcess).length}`);
175
188
  if (!all) {
176
189
  if (Object.keys(filesToProcess).length === 0) {
@@ -180,10 +193,10 @@ function filesCron(config, integration, period) {
180
193
  }
181
194
  const apiCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
182
195
  try {
183
- yield (0, job_2.runAsJob)({
196
+ yield (0, job_1.runAsJob)({
184
197
  integrationId: syncSettings.integrationId,
185
198
  crowdinId: syncSettings.crowdinId,
186
- type: job_1.JobType.UPDATE_TO_INTEGRATION,
199
+ type: types_2.JobType.UPDATE_TO_INTEGRATION,
187
200
  title: `Sync files to ${config.name} [scheduled]`,
188
201
  payload: filesToProcess,
189
202
  jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
@@ -205,7 +218,7 @@ function filesCron(config, integration, period) {
205
218
  }
206
219
  if (Object.keys(newFiles).length) {
207
220
  yield (0, storage_1.getStorage)().updateSyncSettings(JSON.stringify(Object.assign(Object.assign({}, files), newFiles)), syncSettings.integrationId, syncSettings.crowdinId, 'schedule', syncSettings.provider);
208
- const currentFileSnapshot = yield (0, file_snapshot_1.getCrowdinSnapshot)(config, integration, crowdinClient, projectId, intConfig);
221
+ const currentFileSnapshot = yield (0, snapshot_1.getCrowdinSnapshot)(config, integration, crowdinClient, projectId, intConfig);
209
222
  yield (0, storage_1.getStorage)().updateFilesSnapshot(JSON.stringify(currentFileSnapshot), syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
210
223
  }
211
224
  (0, logger_1.log)(`updateIntegration task for files cron job with period [${period}] for project ${projectId} completed`);
@@ -220,10 +233,10 @@ function filesCron(config, integration, period) {
220
233
  (0, logger_1.log)(`Executing updateCrowdin task for files cron job with period [${period}] for project ${projectId}. Files ${intFiles.length}`);
221
234
  const apiCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
222
235
  try {
223
- yield (0, job_2.runAsJob)({
236
+ yield (0, job_1.runAsJob)({
224
237
  integrationId: syncSettings.integrationId,
225
238
  crowdinId: syncSettings.crowdinId,
226
- type: job_1.JobType.UPDATE_TO_CROWDIN,
239
+ type: types_2.JobType.UPDATE_TO_CROWDIN,
227
240
  title: 'Sync files to Crowdin [scheduled]',
228
241
  payload: intFiles,
229
242
  jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
@@ -246,7 +259,7 @@ function filesCron(config, integration, period) {
246
259
  if (Object.keys(newFiles).length) {
247
260
  const newSyncSettingsFields = allIntFiles.map((file) => (Object.assign(Object.assign({}, file), { schedule: true, sync: false })));
248
261
  yield (0, storage_1.getStorage)().updateSyncSettings(JSON.stringify(newSyncSettingsFields), syncSettings.integrationId, syncSettings.crowdinId, 'schedule', syncSettings.provider);
249
- const currentFileSnapshot = yield (0, file_snapshot_1.getIntegrationSnapshot)(integration, apiCredentials, intConfig);
262
+ const currentFileSnapshot = yield (0, snapshot_1.getIntegrationSnapshot)(integration, apiCredentials, intConfig);
250
263
  yield (0, storage_1.getStorage)().updateFilesSnapshot(JSON.stringify(currentFileSnapshot), syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
251
264
  }
252
265
  (0, logger_1.log)(`updateCrowdin task for files cron job with period [${period}] for project ${projectId} completed`);
@@ -256,7 +269,63 @@ function filesCron(config, integration, period) {
256
269
  });
257
270
  }
258
271
  exports.filesCron = filesCron;
259
- function getOnlyTranslatedOrApprovedFiles(config, projectId, crowdinFiles, crowdinClient, onlyApproved, onlyTranslated) {
272
+ function getFileDiff(currentFiles, savedFiles) {
273
+ return currentFiles.filter((x) => !savedFiles.some((x2) => x2.id === x.id));
274
+ }
275
+ function getAllNewFiles(args) {
276
+ return __awaiter(this, void 0, void 0, function* () {
277
+ const { config, integration, crowdinApiClient, crowdinId, integrationCredentials, integrationId, projectId, integrationSettings, syncSettings, } = args;
278
+ let currentFileSnapshot = [];
279
+ const fileSnapshotData = yield (0, storage_1.getStorage)().getFilesSnapshot(integrationId, crowdinId, syncSettings.provider);
280
+ const snapshotFiles = (fileSnapshotData === null || fileSnapshotData === void 0 ? void 0 : fileSnapshotData.files) ? JSON.parse(fileSnapshotData.files) : [];
281
+ if (syncSettings.provider === types_1.Provider.CROWDIN) {
282
+ currentFileSnapshot = yield (0, snapshot_1.getCrowdinSnapshot)(config, integration, crowdinApiClient, projectId, integrationSettings);
283
+ }
284
+ else {
285
+ currentFileSnapshot = yield (0, snapshot_1.getIntegrationSnapshot)(integration, integrationCredentials, integrationSettings);
286
+ }
287
+ const difference = getFileDiff(currentFileSnapshot, snapshotFiles);
288
+ const onlyFiles = difference.filter((file) => 'type' in file);
289
+ const synFiles = JSON.parse(syncSettings.files);
290
+ if (syncSettings.provider === types_1.Provider.INTEGRATION) {
291
+ if (integrationSettings[`new-${syncSettings.provider}-files`]) {
292
+ return onlyFiles;
293
+ }
294
+ const syncFolders = synFiles.filter((file) => !('type' in file));
295
+ return getNewFoldersFile(syncFolders, difference);
296
+ }
297
+ else {
298
+ const files = {};
299
+ const projectData = yield crowdinApiClient.projectsGroupsApi.getProject(projectId);
300
+ const targetLanguages = projectData.data.targetLanguageIds;
301
+ if (integrationSettings[`new-${syncSettings.provider}-files`]) {
302
+ for (const file of onlyFiles) {
303
+ files[file.id] = targetLanguages;
304
+ }
305
+ }
306
+ else {
307
+ const syncFolders = currentFileSnapshot.filter((file) => !('type' in file) && Object.keys(synFiles).includes(file.id));
308
+ const newFiles = getNewFoldersFile(syncFolders, difference);
309
+ for (const file of newFiles) {
310
+ files[file.id] = targetLanguages;
311
+ }
312
+ }
313
+ return files;
314
+ }
315
+ });
316
+ }
317
+ function getNewFoldersFile(folders, snapshotFiles) {
318
+ let files = [];
319
+ for (const folder of folders) {
320
+ const newFiles = snapshotFiles.find((file) => file.parentId === folder.id);
321
+ if (newFiles) {
322
+ files = files.concat(newFiles);
323
+ }
324
+ }
325
+ files = files.filter((file) => 'type' in file);
326
+ return files;
327
+ }
328
+ function getOnlyTranslatedOrApprovedFiles({ projectId, crowdinFiles, crowdinClient, onlyApproved, onlyTranslated, }) {
260
329
  return __awaiter(this, void 0, void 0, function* () {
261
330
  (0, logger_1.log)(`Filtering files to process only ${onlyApproved ? 'approved' : 'translated'} files`);
262
331
  const filesInfo = yield Promise.all(Object.keys(crowdinFiles).map((fileId) => __awaiter(this, void 0, void 0, function* () {
@@ -309,7 +378,7 @@ function getOnlyTranslatedOrApprovedFiles(config, projectId, crowdinFiles, crowd
309
378
  return filteredFiles;
310
379
  });
311
380
  }
312
- function skipFoldersFromIntegrationRequest(config, integration, projectId, crowdinFiles, crowdinClient) {
381
+ function skipFoldersFromIntegrationRequest({ config, integration, projectId, crowdinClient, crowdinFiles, }) {
313
382
  var _a;
314
383
  return __awaiter(this, void 0, void 0, function* () {
315
384
  let folders;
@@ -336,7 +405,7 @@ function skipFoldersFromIntegrationRequest(config, integration, projectId, crowd
336
405
  });
337
406
  }
338
407
  exports.skipFoldersFromIntegrationRequest = skipFoldersFromIntegrationRequest;
339
- function createOrUpdateSyncSettings(config, req, files, provider, onlyCreate = false) {
408
+ function createOrUpdateSyncSettings({ req, files, provider, onlyCreate = false, }) {
340
409
  return __awaiter(this, void 0, void 0, function* () {
341
410
  const existingSettings = yield (0, storage_1.getStorage)().getSyncSettings(req.crowdinContext.clientId, req.crowdinContext.crowdinId, 'schedule', provider);
342
411
  if (!existingSettings) {
@@ -1,11 +1,7 @@
1
1
  import Crowdin, { SourceFilesModel } from '@crowdin/crowdin-api-client';
2
- import { ClientConfig, Config, UnauthorizedConfig } from '../models';
3
- import { IntegrationLogic } from '../modules/integration/types';
4
- import { FileProcessLogic } from '../modules/file-processing/types';
2
+ import { Config } from '../../../types';
3
+ import { IntegrationLogic } from '../types';
5
4
  export declare function getRootFolder(config: Config, integration: IntegrationLogic, client: Crowdin, projectId: number): Promise<SourceFilesModel.Directory | undefined>;
6
5
  export declare function getOauthRoute(integration: IntegrationLogic): string;
7
6
  export declare function applyIntegrationModuleDefaults(config: Config, integration: IntegrationLogic): void;
8
- export declare function applyFileProcessorsModuleDefaults(config: Config, fileModule: FileProcessLogic): void;
9
7
  export declare function constructOauthUrl(config: Config, integration: IntegrationLogic): string;
10
- export declare function isAuthorizedConfig(config: Config | UnauthorizedConfig): config is Config;
11
- export declare function convertClientConfig(clientConfig: ClientConfig): Config | UnauthorizedConfig;