@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
@@ -32,12 +32,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.convertClientConfig = exports.isAuthorizedConfig = exports.constructOauthUrl = exports.applyFileProcessorsModuleDefaults = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
36
- const client_s3_1 = require("@aws-sdk/client-s3");
37
- const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
35
+ exports.constructOauthUrl = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
38
36
  const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
39
- const path_1 = require("path");
40
- const models_1 = require("../models");
41
37
  function getRootFolder(config, integration, client, projectId) {
42
38
  return __awaiter(this, void 0, void 0, function* () {
43
39
  if (!integration.withRootFolder) {
@@ -240,22 +236,6 @@ function applyIntegrationModuleDefaults(config, integration) {
240
236
  }
241
237
  }
242
238
  exports.applyIntegrationModuleDefaults = applyIntegrationModuleDefaults;
243
- function applyFileProcessorsModuleDefaults(config, fileModule) {
244
- var _a, _b;
245
- const AWS_TMP_BUCKET_NAME = (_a = config.awsConfig) === null || _a === void 0 ? void 0 : _a.tmpBucketName;
246
- const AWS_REGION = (_b = config.awsConfig) === null || _b === void 0 ? void 0 : _b.region;
247
- if (AWS_TMP_BUCKET_NAME && AWS_REGION && !fileModule.storeFile) {
248
- const s3 = new client_s3_1.S3Client({ region: AWS_REGION });
249
- fileModule.storeFile = (content) => __awaiter(this, void 0, void 0, function* () {
250
- const fileName = `file-${config.identifier}-${Date.now()}`;
251
- const command = new client_s3_1.PutObjectCommand({ Bucket: AWS_TMP_BUCKET_NAME, Key: fileName, Body: content });
252
- yield s3.send(command);
253
- const getObjectCommand = new client_s3_1.GetObjectCommand({ Bucket: AWS_TMP_BUCKET_NAME, Key: fileName });
254
- return (0, s3_request_presigner_1.getSignedUrl)(s3, getObjectCommand, { expiresIn: 3600 });
255
- });
256
- }
257
- }
258
- exports.applyFileProcessorsModuleDefaults = applyFileProcessorsModuleDefaults;
259
239
  function constructOauthUrl(config, integration) {
260
240
  var _a, _b, _c;
261
241
  const oauth = integration.oauthLogin;
@@ -271,28 +251,3 @@ function constructOauthUrl(config, integration) {
271
251
  return url;
272
252
  }
273
253
  exports.constructOauthUrl = constructOauthUrl;
274
- function isAuthorizedConfig(config) {
275
- return !!config.clientId && !!config.clientSecret && config.authenticationType !== models_1.AuthenticationType.NONE;
276
- }
277
- exports.isAuthorizedConfig = isAuthorizedConfig;
278
- function convertClientConfig(clientConfig) {
279
- const baseUrl = clientConfig.baseUrl || process.env.URL;
280
- const clientId = clientConfig.clientId || process.env.CROWDIN_CLIENT_ID;
281
- const clientSecret = clientConfig.clientSecret || process.env.CROWDIN_CLIENT_SECRET;
282
- const port = clientConfig.port || process.env.PORT || 3000;
283
- const { region = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION, tmpBucketName = process.env.AWS_TMP_BUCKET_NAME, } = clientConfig.awsConfig || {};
284
- if (!baseUrl) {
285
- throw new Error('Missing baseUrl parameter');
286
- }
287
- if (clientConfig.authenticationType !== models_1.AuthenticationType.NONE) {
288
- if (!clientId && !clientSecret) {
289
- throw new Error('Missing [clientId, clientSecret] parameters');
290
- }
291
- }
292
- return Object.assign(Object.assign({}, clientConfig), { baseUrl: baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl, clientId,
293
- clientSecret, awsConfig: {
294
- tmpBucketName,
295
- region,
296
- }, port: Number(port), dbFolder: clientConfig.dbFolder || (0, path_1.join)(process.cwd(), 'db'), imagePath: clientConfig.imagePath || (0, path_1.join)(process.cwd(), 'logo.png') });
297
- }
298
- exports.convertClientConfig = convertClientConfig;
@@ -0,0 +1,5 @@
1
+ import { ExtendedResult, IntegrationFile, IntegrationLogic, IntegrationRequest, SkipIntegrationNodes, TreeItem } from '../types';
2
+ import { JobClient } from './types';
3
+ export declare function skipFilesByRegex(files: TreeItem[] | undefined, skipIntegrationNodes?: SkipIntegrationNodes): TreeItem[];
4
+ export declare function expandFilesTree(nodes: IntegrationFile[], req: IntegrationRequest, integration: IntegrationLogic, job?: JobClient): Promise<IntegrationFile[]>;
5
+ export declare function isExtendedResultType<T>(data?: T | ExtendedResult<T>): data is ExtendedResult<T>;
@@ -8,45 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.expandFilesTree = exports.skipFilesByRegex = exports.getFileStrings = exports.getFileContent = exports.storeFile = exports.MAX_BODY_SIZE = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const fs_1 = __importDefault(require("fs"));
18
- const path_1 = __importDefault(require("path"));
19
- const index_1 = require("./index");
20
- const job_1 = require("../models/job");
21
- exports.MAX_BODY_SIZE = 4.9 * 1024 * 1024; //4.9mb
22
- function storeFile(fileContent, folder) {
23
- const fileName = `file${Date.now()}`;
24
- return new Promise((res, rej) => fs_1.default.writeFile(path_1.default.join(folder, fileName), fileContent, (err) => {
25
- if (err) {
26
- rej(err);
27
- }
28
- else {
29
- res(fileName);
30
- }
31
- }));
32
- }
33
- exports.storeFile = storeFile;
34
- function getFileContent(url) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- const response = (yield axios_1.default.get(url, { responseType: 'arraybuffer' })).data;
37
- return response;
38
- });
39
- }
40
- exports.getFileContent = getFileContent;
41
- function getFileStrings(url) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const response = (yield axios_1.default.get(url)).data;
44
- // the response is presented in the ndjson format
45
- const jsonRows = response.split(/\n|\n\r/).filter(Boolean);
46
- return jsonRows.map((jsonStringRow) => JSON.parse(jsonStringRow));
47
- });
48
- }
49
- exports.getFileStrings = getFileStrings;
12
+ exports.isExtendedResultType = exports.expandFilesTree = exports.skipFilesByRegex = void 0;
13
+ const types_1 = require("./types");
50
14
  function skipFilesByRegex(files, skipIntegrationNodes) {
51
15
  if (!Array.isArray(files)) {
52
16
  return [];
@@ -68,14 +32,14 @@ exports.skipFilesByRegex = skipFilesByRegex;
68
32
  function expandFilesTree(nodes, req, integration, job) {
69
33
  var _a;
70
34
  return __awaiter(this, void 0, void 0, function* () {
71
- if (job && job_1.JobStatus.CANCELED === ((_a = (yield job.get())) === null || _a === void 0 ? void 0 : _a.status)) {
35
+ if (job && types_1.JobStatus.CANCELED === ((_a = (yield job.get())) === null || _a === void 0 ? void 0 : _a.status)) {
72
36
  throw new Error('Job canceled');
73
37
  }
74
38
  const files = nodes.filter((file) => file.nodeType === undefined || file.nodeType === '1');
75
39
  const folders = nodes.filter((folder) => folder.nodeType === '0' && !nodes.find((node) => node.parentId === folder.id));
76
40
  for (const { id } of folders) {
77
41
  const integrationData = yield integration.getIntegrationFiles(req.integrationCredentials, req.integrationSettings, id);
78
- const integrationTreeItems = (0, index_1.isExtendedResultType)(integrationData)
42
+ const integrationTreeItems = isExtendedResultType(integrationData)
79
43
  ? integrationData.data
80
44
  : integrationData;
81
45
  const checkNodes = integrationTreeItems.map((item) => (Object.assign(Object.assign({}, item), { nodeType: item.nodeType || ('type' in item ? '1' : '0') })));
@@ -86,3 +50,8 @@ function expandFilesTree(nodes, req, integration, job) {
86
50
  });
87
51
  }
88
52
  exports.expandFilesTree = expandFilesTree;
53
+ function isExtendedResultType(data) {
54
+ const dataTyped = data;
55
+ return !!dataTyped && !Array.isArray(dataTyped);
56
+ }
57
+ exports.isExtendedResultType = isExtendedResultType;
@@ -1,4 +1,4 @@
1
- import { JobClient, JobType } from '../models/job';
1
+ import { JobClient, JobType } from './types';
2
2
  import { Response } from 'express';
3
3
  export declare function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCallback, onError, }: {
4
4
  integrationId: string;
@@ -10,14 +10,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.runAsJob = void 0;
13
- const job_1 = require("../models/job");
14
- const storage_1 = require("../storage");
15
- const logger_1 = require("./logger");
13
+ const types_1 = require("./types");
14
+ const storage_1 = require("../../../storage");
15
+ const logger_1 = require("../../../util/logger");
16
16
  const blockingJobs = {
17
- [job_1.JobType.UPDATE_TO_CROWDIN]: [job_1.JobType.UPDATE_TO_CROWDIN, job_1.JobType.UPDATE_TO_INTEGRATION],
18
- [job_1.JobType.UPDATE_TO_INTEGRATION]: [job_1.JobType.UPDATE_TO_CROWDIN, job_1.JobType.UPDATE_TO_INTEGRATION],
19
- [job_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE]: [job_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE],
20
- [job_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE]: [job_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE],
17
+ [types_1.JobType.UPDATE_TO_CROWDIN]: [types_1.JobType.UPDATE_TO_CROWDIN, types_1.JobType.UPDATE_TO_INTEGRATION],
18
+ [types_1.JobType.UPDATE_TO_INTEGRATION]: [types_1.JobType.UPDATE_TO_CROWDIN, types_1.JobType.UPDATE_TO_INTEGRATION],
19
+ [types_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE]: [types_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE],
20
+ [types_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE]: [types_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE],
21
21
  };
22
22
  function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCallback, onError, }) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -51,13 +51,13 @@ function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCall
51
51
  update: function updateProgress({ progress, status, info, data }) {
52
52
  return __awaiter(this, void 0, void 0, function* () {
53
53
  const prevData = yield this.get();
54
- if ((prevData === null || prevData === void 0 ? void 0 : prevData.status) === job_1.JobStatus.CANCELED) {
54
+ if ((prevData === null || prevData === void 0 ? void 0 : prevData.status) === types_1.JobStatus.CANCELED) {
55
55
  return { isCanceled: true };
56
56
  }
57
57
  yield storage.updateJob({
58
58
  id: jobId,
59
59
  progress,
60
- status: status || job_1.JobStatus.IN_PROGRESS,
60
+ status: status || types_1.JobStatus.IN_PROGRESS,
61
61
  info,
62
62
  data: JSON.stringify(data),
63
63
  });
@@ -69,13 +69,13 @@ function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCall
69
69
  const data = yield jobCallback(job);
70
70
  yield job.update({
71
71
  progress: 100,
72
- status: job_1.JobStatus.FINISHED,
72
+ status: types_1.JobStatus.FINISHED,
73
73
  data,
74
74
  });
75
75
  }
76
76
  catch (e) {
77
77
  yield job.update({
78
- status: job_1.JobStatus.FAILED,
78
+ status: types_1.JobStatus.FAILED,
79
79
  info: (0, logger_1.getErrorMessage)(e),
80
80
  });
81
81
  if (onError) {
@@ -1,8 +1,6 @@
1
1
  import Crowdin from '@crowdin/crowdin-api-client';
2
- import { Config } from '../models';
3
- import { GetAllNewFilesArgs, IntegrationLogic, IntegrationRequest, Provider, TreeItem, UpdateIntegrationRequest } from '../modules/integration/types';
4
- export declare function getFileDiff(currentFiles: TreeItem[], savedFiles: TreeItem[]): TreeItem[];
5
- export declare function getAllNewFiles(args: GetAllNewFilesArgs): Promise<TreeItem[] | UpdateIntegrationRequest>;
2
+ import { Config } from '../../../types';
3
+ import { IntegrationLogic, IntegrationRequest, Provider, TreeItem } from '../types';
6
4
  export declare function getCrowdinSnapshot(config: Config, integration: IntegrationLogic, crowdinApiClient: Crowdin, projectId: number, integrationSettings: any): Promise<TreeItem[]>;
7
5
  export declare function getIntegrationSnapshot(integration: IntegrationLogic, integrationCredentials: any, integrationSettings: any): Promise<TreeItem[]>;
8
6
  export declare function createOrUpdateFileSnapshot(config: Config, integration: IntegrationLogic, req: IntegrationRequest, provider: Provider): Promise<void>;
@@ -9,70 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createOrUpdateFileSnapshot = exports.getIntegrationSnapshot = exports.getCrowdinSnapshot = exports.getAllNewFiles = exports.getFileDiff = void 0;
13
- const storage_1 = require("../storage");
12
+ exports.createOrUpdateFileSnapshot = exports.getIntegrationSnapshot = exports.getCrowdinSnapshot = void 0;
13
+ const types_1 = require("../types");
14
+ const storage_1 = require("../../../storage");
14
15
  const defaults_1 = require("./defaults");
15
- const index_1 = require("./index");
16
16
  const files_1 = require("./files");
17
- const types_1 = require("../modules/integration/types");
18
- function getFileDiff(currentFiles, savedFiles) {
19
- return currentFiles.filter((x) => !savedFiles.some((x2) => x2.id === x.id));
20
- }
21
- exports.getFileDiff = getFileDiff;
22
- function getAllNewFiles(args) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const { config, integration, crowdinApiClient, crowdinId, integrationCredentials, integrationId, projectId, integrationSettings, syncSettings, } = args;
25
- let currentFileSnapshot = [];
26
- const fileSnapshotData = yield (0, storage_1.getStorage)().getFilesSnapshot(integrationId, crowdinId, syncSettings.provider);
27
- const snapshotFiles = (fileSnapshotData === null || fileSnapshotData === void 0 ? void 0 : fileSnapshotData.files) ? JSON.parse(fileSnapshotData.files) : [];
28
- if (syncSettings.provider === types_1.Provider.CROWDIN) {
29
- currentFileSnapshot = yield getCrowdinSnapshot(config, integration, crowdinApiClient, projectId, integrationSettings);
30
- }
31
- else {
32
- currentFileSnapshot = yield getIntegrationSnapshot(integration, integrationCredentials, integrationSettings);
33
- }
34
- const difference = getFileDiff(currentFileSnapshot, snapshotFiles);
35
- const onlyFiles = difference.filter((file) => 'type' in file);
36
- const synFiles = JSON.parse(syncSettings.files);
37
- if (syncSettings.provider === types_1.Provider.INTEGRATION) {
38
- if (integrationSettings[`new-${syncSettings.provider}-files`]) {
39
- return onlyFiles;
40
- }
41
- const syncFolders = synFiles.filter((file) => !('type' in file));
42
- return getNewFoldersFile(syncFolders, difference);
43
- }
44
- else {
45
- const files = {};
46
- const projectData = yield crowdinApiClient.projectsGroupsApi.getProject(projectId);
47
- const targetLanguages = projectData.data.targetLanguageIds;
48
- if (integrationSettings[`new-${syncSettings.provider}-files`]) {
49
- for (const file of onlyFiles) {
50
- files[file.id] = targetLanguages;
51
- }
52
- }
53
- else {
54
- const syncFolders = currentFileSnapshot.filter((file) => !('type' in file) && Object.keys(synFiles).includes(file.id));
55
- const newFiles = getNewFoldersFile(syncFolders, difference);
56
- for (const file of newFiles) {
57
- files[file.id] = targetLanguages;
58
- }
59
- }
60
- return files;
61
- }
62
- });
63
- }
64
- exports.getAllNewFiles = getAllNewFiles;
65
- function getNewFoldersFile(folders, snapshotFiles) {
66
- let files = [];
67
- for (const folder of folders) {
68
- const newFiles = snapshotFiles.find((file) => file.parentId === folder.id);
69
- if (newFiles) {
70
- files = files.concat(newFiles);
71
- }
72
- }
73
- files = files.filter((file) => 'type' in file);
74
- return files;
75
- }
76
17
  function getCrowdinSnapshot(config, integration, crowdinApiClient, projectId, integrationSettings) {
77
18
  return __awaiter(this, void 0, void 0, function* () {
78
19
  let files = [];
@@ -86,7 +27,7 @@ function getCrowdinSnapshot(config, integration, crowdinApiClient, projectId, in
86
27
  exports.getCrowdinSnapshot = getCrowdinSnapshot;
87
28
  function getTreeItems(integrationData) {
88
29
  let files = [];
89
- if ((0, index_1.isExtendedResultType)(integrationData)) {
30
+ if ((0, files_1.isExtendedResultType)(integrationData)) {
90
31
  files = integrationData.data;
91
32
  }
92
33
  else {
@@ -1,3 +1,6 @@
1
+ import Crowdin from '@crowdin/crowdin-api-client';
2
+ import { Config } from '../../../types';
3
+ import { IntegrationLogic, IntegrationSyncSettings } from '../types';
1
4
  export declare enum JobType {
2
5
  UPDATE_TO_CROWDIN = "updateCrowdin",
3
6
  UPDATE_TO_INTEGRATION = "updateIntegration",
@@ -44,3 +47,14 @@ export type JobClient = {
44
47
  export type UpdateJobProgress = ({ progress, status, info, data, }: Omit<UpdateJobParams, 'id'>) => Promise<{
45
48
  isCanceled: boolean;
46
49
  }>;
50
+ export interface GetAllNewFilesArgs {
51
+ config: Config;
52
+ integration: IntegrationLogic;
53
+ crowdinApiClient: Crowdin;
54
+ crowdinId: string;
55
+ integrationCredentials: any;
56
+ integrationId: string;
57
+ projectId: number;
58
+ integrationSettings: any;
59
+ syncSettings: IntegrationSyncSettings;
60
+ }
@@ -0,0 +1,48 @@
1
+ import Crowdin from '@crowdin/crowdin-api-client';
2
+ import { AppSettings, IntegrationLogic, IntegrationSyncSettings, Provider, UpdateCrowdinWebhookPayloadsArgs } from '../types';
3
+ import { Config, CrowdinContextInfo } from '../../../types';
4
+ export declare const HookEvents: any;
5
+ export declare function registerWebhooks({ config, apiCredentials, appSettings, client, crowdinContext, integration, }: {
6
+ config: Config;
7
+ integration: IntegrationLogic;
8
+ client: Crowdin;
9
+ crowdinContext: CrowdinContextInfo;
10
+ apiCredentials: any;
11
+ appSettings: AppSettings;
12
+ }): Promise<void>;
13
+ export declare function unregisterWebhooks({ apiCredentials, appSettings, client, config, crowdinContext, integration, }: {
14
+ config: Config;
15
+ integration: IntegrationLogic;
16
+ client: Crowdin;
17
+ crowdinContext: CrowdinContextInfo;
18
+ apiCredentials: any;
19
+ appSettings: AppSettings;
20
+ }): Promise<void>;
21
+ export declare function unregisterAllCrowdinWebhooks({ config, crowdinId, integration, }: {
22
+ config: Config;
23
+ integration: IntegrationLogic;
24
+ crowdinId: string;
25
+ }): Promise<void>;
26
+ export declare function prepareWebhookData({ config, integration, provider, webhookUrlParam, }: {
27
+ config: Config;
28
+ integration: IntegrationLogic;
29
+ webhookUrlParam: string;
30
+ provider: Provider;
31
+ }): Promise<{
32
+ projectId: number;
33
+ crowdinClient: {
34
+ client: Crowdin;
35
+ token: string;
36
+ };
37
+ preparedIntegrationCredentials: any;
38
+ rootFolder: import("@crowdin/crowdin-api-client").SourceFilesModel.Directory | undefined;
39
+ appSettings: AppSettings;
40
+ syncSettings: IntegrationSyncSettings | null;
41
+ }>;
42
+ export declare function updateCrowdinFromWebhookRequest(args: UpdateCrowdinWebhookPayloadsArgs): Promise<void>;
43
+ export declare function listenQueueMessage({ config, integration, queueName, queueUrl, }: {
44
+ config: Config;
45
+ integration: IntegrationLogic;
46
+ queueUrl: string;
47
+ queueName: string;
48
+ }): Promise<void>;