@crowdin/app-project-module 0.43.1 → 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 (193) hide show
  1. package/out/index.d.ts +3 -3
  2. package/out/index.js +103 -219
  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 +3 -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 +5 -1
  9. package/out/{util → modules}/api/api.d.ts +3 -2
  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 +6 -0
  16. package/out/modules/context-menu/index.js +17 -0
  17. package/out/modules/context-menu/types.d.ts +27 -0
  18. package/out/modules/context-menu/types.js +18 -0
  19. package/out/{handlers/custom-mt → modules/custom-mt/handlers}/translate.d.ts +2 -1
  20. package/out/{handlers/custom-mt → modules/custom-mt/handlers}/translate.js +2 -2
  21. package/out/modules/custom-mt/index.d.ts +6 -0
  22. package/out/modules/custom-mt/index.js +17 -0
  23. package/out/modules/custom-mt/types.d.ts +22 -0
  24. package/out/modules/custom-mt/types.js +2 -0
  25. package/out/{handlers/custom-spell-check → modules/custom-spell-check/handlers}/get-languages-list.d.ts +2 -1
  26. package/out/{handlers/custom-spell-check → modules/custom-spell-check/handlers}/get-languages-list.js +2 -2
  27. package/out/{handlers/custom-spell-check → modules/custom-spell-check/handlers}/spell-check.d.ts +2 -1
  28. package/out/{handlers/custom-spell-check → modules/custom-spell-check/handlers}/spell-check.js +5 -3
  29. package/out/modules/custom-spell-check/index.d.ts +6 -0
  30. package/out/modules/custom-spell-check/index.js +32 -0
  31. package/out/modules/custom-spell-check/types.d.ts +56 -0
  32. package/out/modules/custom-spell-check/types.js +2 -0
  33. package/out/modules/editor-right-panel/index.d.ts +6 -0
  34. package/out/modules/editor-right-panel/index.js +17 -0
  35. package/out/modules/editor-right-panel/types.d.ts +7 -0
  36. package/out/modules/editor-right-panel/types.js +2 -0
  37. package/out/modules/editor-themes/index.d.ts +6 -0
  38. package/out/modules/editor-themes/index.js +11 -0
  39. package/out/modules/editor-themes/types.d.ts +17 -0
  40. package/out/modules/editor-themes/types.js +2 -0
  41. package/out/{handlers/file-processing → modules/file-processing/handlers}/custom-file-format.d.ts +2 -1
  42. package/out/{handlers/file-processing → modules/file-processing/handlers}/custom-file-format.js +5 -5
  43. package/out/modules/file-processing/handlers/file-download.d.ts +5 -0
  44. package/out/{handlers/file-processing → modules/file-processing/handlers}/file-download.js +2 -2
  45. package/out/{handlers/file-processing → modules/file-processing/handlers}/pre-post-process.d.ts +2 -1
  46. package/out/{handlers/file-processing → modules/file-processing/handlers}/pre-post-process.js +8 -8
  47. package/out/modules/file-processing/index.d.ts +22 -0
  48. package/out/modules/file-processing/index.js +57 -0
  49. package/out/modules/file-processing/types.d.ts +133 -0
  50. package/out/modules/file-processing/types.js +12 -0
  51. package/out/modules/file-processing/util/defaults.d.ts +3 -0
  52. package/out/modules/file-processing/util/defaults.js +30 -0
  53. package/out/modules/file-processing/util/files.d.ts +6 -0
  54. package/out/modules/file-processing/util/files.js +47 -0
  55. package/out/{handlers/integration/crowdin-project.d.ts → modules/form-data-display.d.ts} +1 -1
  56. package/out/modules/form-data-save.d.ts +4 -0
  57. package/out/modules/install.d.ts +4 -0
  58. package/out/{handlers → modules}/install.js +3 -3
  59. package/out/{handlers/integration → modules/integration/handlers}/crowdin-file-progress.d.ts +2 -1
  60. package/out/{handlers/integration → modules/integration/handlers}/crowdin-file-progress.js +2 -2
  61. package/out/modules/integration/handlers/crowdin-files.d.ts +5 -0
  62. package/out/{handlers/integration → modules/integration/handlers}/crowdin-files.js +3 -3
  63. package/out/modules/integration/handlers/crowdin-project.d.ts +4 -0
  64. package/out/{handlers/integration → modules/integration/handlers}/crowdin-project.js +1 -1
  65. package/out/modules/integration/handlers/crowdin-update.d.ts +5 -0
  66. package/out/{handlers/integration → modules/integration/handlers}/crowdin-update.js +9 -9
  67. package/out/modules/integration/handlers/crowdin-webhook.d.ts +5 -0
  68. package/out/{handlers/integration → modules/integration/handlers}/crowdin-webhook.js +19 -8
  69. package/out/modules/integration/handlers/integration-data.d.ts +4 -0
  70. package/out/{handlers/integration → modules/integration/handlers}/integration-data.js +5 -5
  71. package/out/{handlers/integration → modules/integration/handlers}/integration-login.d.ts +2 -1
  72. package/out/{handlers/integration → modules/integration/handlers}/integration-login.js +3 -3
  73. package/out/modules/integration/handlers/integration-logout.d.ts +5 -0
  74. package/out/{handlers/integration → modules/integration/handlers}/integration-logout.js +14 -7
  75. package/out/modules/integration/handlers/integration-update.d.ts +5 -0
  76. package/out/{handlers/integration → modules/integration/handlers}/integration-update.js +9 -8
  77. package/out/modules/integration/handlers/integration-webhook.d.ts +5 -0
  78. package/out/{handlers/integration → modules/integration/handlers}/integration-webhook.js +9 -4
  79. package/out/modules/integration/handlers/job-cancel.d.ts +3 -0
  80. package/out/{handlers/integration → modules/integration/handlers}/job-cancel.js +4 -4
  81. package/out/modules/integration/handlers/job-info.d.ts +3 -0
  82. package/out/{handlers/integration → modules/integration/handlers}/job-info.js +4 -4
  83. package/out/modules/integration/handlers/main.d.ts +5 -0
  84. package/out/{handlers/integration → modules/integration/handlers}/main.js +5 -5
  85. package/out/modules/integration/handlers/oauth-login.d.ts +5 -0
  86. package/out/{handlers/integration → modules/integration/handlers}/oauth-login.js +3 -3
  87. package/out/{handlers/integration → modules/integration/handlers}/oauth-url.d.ts +2 -1
  88. package/out/{handlers/integration → modules/integration/handlers}/oauth-url.js +2 -2
  89. package/out/modules/integration/handlers/settings-save.d.ts +5 -0
  90. package/out/{handlers/integration → modules/integration/handlers}/settings-save.js +28 -11
  91. package/out/modules/integration/handlers/settings.d.ts +3 -0
  92. package/out/{handlers/integration → modules/integration/handlers}/settings.js +1 -1
  93. package/out/{handlers/integration → modules/integration/handlers}/subscription-info.d.ts +1 -1
  94. package/out/{handlers/integration → modules/integration/handlers}/subscription-info.js +2 -2
  95. package/out/modules/integration/handlers/sync-settings-save.d.ts +5 -0
  96. package/out/{handlers/integration → modules/integration/handlers}/sync-settings-save.js +16 -8
  97. package/out/modules/integration/handlers/sync-settings.d.ts +3 -0
  98. package/out/{handlers/integration → modules/integration/handlers}/sync-settings.js +2 -2
  99. package/out/modules/integration/handlers/user-errors.d.ts +3 -0
  100. package/out/{handlers/integration → modules/integration/handlers}/user-errors.js +2 -2
  101. package/out/modules/integration/index.d.ts +6 -0
  102. package/out/modules/integration/index.js +118 -0
  103. package/out/modules/integration/types.d.ts +435 -0
  104. package/out/modules/integration/types.js +19 -0
  105. package/out/modules/integration/util/cron.d.ts +27 -0
  106. package/out/{util → modules/integration/util}/cron.js +97 -28
  107. package/out/{util → modules/integration/util}/defaults.d.ts +2 -3
  108. package/out/{util → modules/integration/util}/defaults.js +1 -36
  109. package/out/modules/integration/util/files.d.ts +5 -0
  110. package/out/{util → modules/integration/util}/files.js +9 -40
  111. package/out/{util → modules/integration/util}/job.d.ts +1 -1
  112. package/out/{util → modules/integration/util}/job.js +11 -11
  113. package/out/{util/file-snapshot.d.ts → modules/integration/util/snapshot.d.ts} +2 -3
  114. package/out/{util/file-snapshot.js → modules/integration/util/snapshot.js} +6 -65
  115. package/out/{models/job.d.ts → modules/integration/util/types.d.ts} +14 -0
  116. package/out/modules/integration/util/webhooks.d.ts +48 -0
  117. package/out/{util → modules/integration/util}/webhooks.js +95 -49
  118. package/out/modules/manifest.d.ts +3 -0
  119. package/out/{handlers → modules}/manifest.js +22 -16
  120. package/out/modules/modal/index.d.ts +6 -0
  121. package/out/modules/modal/index.js +17 -0
  122. package/out/modules/organization-menu/index.d.ts +6 -0
  123. package/out/modules/organization-menu/index.js +18 -0
  124. package/out/modules/profile-resources-menu/index.d.ts +6 -0
  125. package/out/modules/profile-resources-menu/index.js +18 -0
  126. package/out/modules/project-menu/index.d.ts +6 -0
  127. package/out/modules/project-menu/index.js +17 -0
  128. package/out/modules/project-menu-crowdsource/index.d.ts +6 -0
  129. package/out/modules/project-menu-crowdsource/index.js +17 -0
  130. package/out/modules/project-reports/index.d.ts +6 -0
  131. package/out/modules/project-reports/index.js +18 -0
  132. package/out/modules/project-tools/index.d.ts +6 -0
  133. package/out/modules/project-tools/index.js +18 -0
  134. package/out/modules/subscription-paid.d.ts +3 -0
  135. package/out/{handlers → modules}/subscription-paid.js +2 -2
  136. package/out/modules/uninstall.d.ts +4 -0
  137. package/out/{handlers → modules}/uninstall.js +6 -2
  138. package/out/storage/index.d.ts +5 -3
  139. package/out/storage/mysql.d.ts +4 -2
  140. package/out/storage/mysql.js +3 -3
  141. package/out/storage/postgre.d.ts +4 -2
  142. package/out/storage/postgre.js +3 -3
  143. package/out/storage/sqlite.d.ts +4 -2
  144. package/out/storage/sqlite.js +3 -3
  145. package/out/storage/types.d.ts +9 -0
  146. package/out/storage/types.js +2 -0
  147. package/out/types.d.ts +374 -0
  148. package/out/types.js +59 -0
  149. package/out/util/connection.d.ts +2 -9
  150. package/out/util/connection.js +54 -150
  151. package/out/util/handlebars.d.ts +1 -0
  152. package/out/util/handlebars.js +34 -0
  153. package/out/util/index.d.ts +2 -2
  154. package/out/util/index.js +6 -6
  155. package/out/util/logger.d.ts +2 -2
  156. package/out/util/subscription.d.ts +9 -0
  157. package/out/util/subscription.js +111 -0
  158. package/package.json +1 -1
  159. package/out/handlers/file-processing/file-download.d.ts +0 -4
  160. package/out/handlers/form-data-display.d.ts +0 -3
  161. package/out/handlers/form-data-save.d.ts +0 -3
  162. package/out/handlers/install.d.ts +0 -4
  163. package/out/handlers/integration/crowdin-files.d.ts +0 -4
  164. package/out/handlers/integration/crowdin-update.d.ts +0 -4
  165. package/out/handlers/integration/crowdin-webhook.d.ts +0 -4
  166. package/out/handlers/integration/integration-data.d.ts +0 -4
  167. package/out/handlers/integration/integration-logout.d.ts +0 -4
  168. package/out/handlers/integration/integration-update.d.ts +0 -4
  169. package/out/handlers/integration/integration-webhook.d.ts +0 -4
  170. package/out/handlers/integration/job-cancel.d.ts +0 -3
  171. package/out/handlers/integration/job-info.d.ts +0 -3
  172. package/out/handlers/integration/main.d.ts +0 -4
  173. package/out/handlers/integration/oauth-login.d.ts +0 -4
  174. package/out/handlers/integration/settings-save.d.ts +0 -4
  175. package/out/handlers/integration/settings.d.ts +0 -3
  176. package/out/handlers/integration/sync-settings-save.d.ts +0 -4
  177. package/out/handlers/integration/sync-settings.d.ts +0 -3
  178. package/out/handlers/integration/user-errors.d.ts +0 -3
  179. package/out/handlers/manifest.d.ts +0 -3
  180. package/out/handlers/subscription-paid.d.ts +0 -3
  181. package/out/handlers/uninstall.d.ts +0 -4
  182. package/out/models/index.d.ts +0 -1088
  183. package/out/models/index.js +0 -106
  184. package/out/util/cron.d.ts +0 -7
  185. package/out/util/files.d.ts +0 -9
  186. package/out/util/webhooks.d.ts +0 -28
  187. /package/out/{util → modules}/api/base.d.ts +0 -0
  188. /package/out/{util → modules}/api/base.js +0 -0
  189. /package/out/{util → modules}/api/components.d.ts +0 -0
  190. /package/out/{util → modules}/api/components.js +0 -0
  191. /package/out/{handlers → modules}/form-data-display.js +0 -0
  192. /package/out/{handlers → modules}/form-data-save.js +0 -0
  193. /package/out/{models/job.js → modules/integration/util/types.js} +0 -0
@@ -0,0 +1,133 @@
1
+ /// <reference types="node" />
2
+ import Crowdin, { LanguagesModel, SourceStringsModel } from '@crowdin/crowdin-api-client';
3
+ import { CrowdinContextInfo, SignaturePatterns } from '../../types';
4
+ export interface FileProcessLogic {
5
+ /**
6
+ * Folder where larger file will be temporary stored (default "{@link dbFolder}/custom-file-format")
7
+ */
8
+ filesFolder?: string;
9
+ /**
10
+ * Contains fileName and/or fileContent regular expressions used to detect file type when uploading a new source file via UI (or via API without specified type parameter). If the file matches regular expressions, it's labeled as a custom format file.
11
+ */
12
+ signaturePatterns?: SignaturePatterns;
13
+ /**
14
+ * Override to store huge responses (by default they will be stored in fs)
15
+ */
16
+ storeFile?: (content: Buffer) => Promise<string>;
17
+ }
18
+ export interface CustomFileFormatLogic extends FileProcessLogic {
19
+ /**
20
+ * The type parameter value for a custom file format. Used for a custom format file upload via API.
21
+ */
22
+ type: string;
23
+ /**
24
+ * This parameter is used to combine the content of multiple languages into one request when uploading and downloading translations in your Crowdin project.
25
+ */
26
+ multilingual?: boolean;
27
+ /**
28
+ * Flag to automatically upload translations
29
+ */
30
+ autoUploadTranslations?: boolean;
31
+ /**
32
+ * Enable strings export
33
+ */
34
+ stringsExport?: boolean;
35
+ /**
36
+ * File extensions (used for strings export)
37
+ */
38
+ extensions?: string[];
39
+ /**
40
+ * Enable custom srx
41
+ */
42
+ customSrxSupported?: boolean;
43
+ /**
44
+ * Enable multi language strings export
45
+ */
46
+ multilingualExport?: boolean;
47
+ /**
48
+ * Used for initial source file upload, source file update, and translation upload
49
+ */
50
+ parseFile?: (fileContent: Buffer, req: Omit<ProcessFileRequest, 'jobType' | 'file'>, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<ParseFileResponse>;
51
+ /**
52
+ * Used for translation download
53
+ */
54
+ buildFile?: (fileContent: Buffer, req: Omit<ProcessFileRequest, 'jobType' | 'file'>, strings: ProcessFileString[], client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>;
55
+ /**
56
+ * Used for strings export
57
+ */
58
+ exportStrings?: (req: Omit<ProcessFileRequest, 'jobType'>, strings: ProcessFileString[], client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>;
59
+ }
60
+ export type FileImportExportLogic = FilePreImportLogic | FilePostImportLogic | FilePreExportLogic | FilePostExportLogic;
61
+ export type FileImportExportContent = ProcessFileString[] | Buffer | undefined;
62
+ export interface FilePreImportLogic extends FileProcessLogic {
63
+ fileProcess: (req: ProcessFileRequest, content: FileImportExportContent, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<ContentFileResponse>;
64
+ }
65
+ export interface FilePostImportLogic extends FileProcessLogic {
66
+ fileProcess: (req: ProcessFileRequest, content: FileImportExportContent, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<StringsFileResponse>;
67
+ }
68
+ export interface FilePreExportLogic extends FileProcessLogic {
69
+ fileProcess: (req: ProcessFileRequest, content: FileImportExportContent, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<StringsFileResponse>;
70
+ }
71
+ export interface FilePostExportLogic extends FileProcessLogic {
72
+ fileProcess: (req: ProcessFileRequest, content: FileImportExportContent, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<ContentFileResponse>;
73
+ }
74
+ export interface ProcessFileRequest {
75
+ jobType: ProcessFileJobType;
76
+ file: ProcessFileRecord;
77
+ sourceLanguage: LanguagesModel.Language;
78
+ targetLanguages: LanguagesModel.Language[];
79
+ strings: ProcessFileString[];
80
+ stringsUrl: string;
81
+ getRawContent?: (encoding: BufferEncoding) => Promise<string | Buffer>;
82
+ }
83
+ export interface ProcessFileRecord {
84
+ content?: string;
85
+ contentUrl?: string;
86
+ path?: string;
87
+ id?: number;
88
+ name?: string;
89
+ }
90
+ export declare enum ProcessFileJobType {
91
+ PARSE_FILE = "parse-file",
92
+ BUILD_FILE = "build-file",
93
+ PRE_IMPORT = "pre-import-file",
94
+ POST_IMPORT = "post-import-file",
95
+ PRE_EXPORT = "pre-export-file",
96
+ POST_EXPORT = "post-export-file"
97
+ }
98
+ export interface ParseFileResponse {
99
+ previewFile?: Buffer;
100
+ strings?: ProcessFileString[];
101
+ error?: string;
102
+ }
103
+ export interface BuildFileResponse {
104
+ contentFile: Buffer;
105
+ error?: string;
106
+ fileName?: string;
107
+ fileType?: string;
108
+ }
109
+ export interface StringsFileResponse extends Omit<ParseFileResponse, 'previewFile'> {
110
+ notModified?: boolean;
111
+ }
112
+ export interface ContentFileResponse extends BuildFileResponse {
113
+ notModified?: boolean;
114
+ }
115
+ export interface ProcessFileString {
116
+ previewId?: number;
117
+ id: number;
118
+ identifier: string;
119
+ context?: string;
120
+ customData?: string;
121
+ maxLength?: number;
122
+ isHidden?: boolean;
123
+ hasPlurals?: boolean;
124
+ labels?: string[];
125
+ text: string | SourceStringsModel.PluralText;
126
+ translations?: StringTranslations;
127
+ uniqId?: string;
128
+ }
129
+ export interface StringTranslations {
130
+ [language: string]: {
131
+ text: string | SourceStringsModel.PluralText;
132
+ };
133
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProcessFileJobType = void 0;
4
+ var ProcessFileJobType;
5
+ (function (ProcessFileJobType) {
6
+ ProcessFileJobType["PARSE_FILE"] = "parse-file";
7
+ ProcessFileJobType["BUILD_FILE"] = "build-file";
8
+ ProcessFileJobType["PRE_IMPORT"] = "pre-import-file";
9
+ ProcessFileJobType["POST_IMPORT"] = "post-import-file";
10
+ ProcessFileJobType["PRE_EXPORT"] = "pre-export-file";
11
+ ProcessFileJobType["POST_EXPORT"] = "post-export-file";
12
+ })(ProcessFileJobType = exports.ProcessFileJobType || (exports.ProcessFileJobType = {}));
@@ -0,0 +1,3 @@
1
+ import { Config } from '../../../types';
2
+ import { FileProcessLogic } from '../types';
3
+ export declare function applyFileProcessorsModuleDefaults(config: Config, fileModule: FileProcessLogic): void;
@@ -0,0 +1,30 @@
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.applyFileProcessorsModuleDefaults = void 0;
13
+ const client_s3_1 = require("@aws-sdk/client-s3");
14
+ const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
15
+ function applyFileProcessorsModuleDefaults(config, fileModule) {
16
+ var _a, _b;
17
+ const AWS_TMP_BUCKET_NAME = (_a = config.awsConfig) === null || _a === void 0 ? void 0 : _a.tmpBucketName;
18
+ const AWS_REGION = (_b = config.awsConfig) === null || _b === void 0 ? void 0 : _b.region;
19
+ if (AWS_TMP_BUCKET_NAME && AWS_REGION && !fileModule.storeFile) {
20
+ const s3 = new client_s3_1.S3Client({ region: AWS_REGION });
21
+ fileModule.storeFile = (content) => __awaiter(this, void 0, void 0, function* () {
22
+ const fileName = `file-${config.identifier}-${Date.now()}`;
23
+ const command = new client_s3_1.PutObjectCommand({ Bucket: AWS_TMP_BUCKET_NAME, Key: fileName, Body: content });
24
+ yield s3.send(command);
25
+ const getObjectCommand = new client_s3_1.GetObjectCommand({ Bucket: AWS_TMP_BUCKET_NAME, Key: fileName });
26
+ return (0, s3_request_presigner_1.getSignedUrl)(s3, getObjectCommand, { expiresIn: 3600 });
27
+ });
28
+ }
29
+ }
30
+ exports.applyFileProcessorsModuleDefaults = applyFileProcessorsModuleDefaults;
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import { ProcessFileString } from '../types';
3
+ export declare const MAX_BODY_SIZE: number;
4
+ export declare function storeFile(fileContent: Buffer, folder: string): Promise<string>;
5
+ export declare function getFileContent(url: string): Promise<Buffer>;
6
+ export declare function getFileStrings(url: string): Promise<ProcessFileString[]>;
@@ -0,0 +1,47 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ 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
+ exports.MAX_BODY_SIZE = 4.9 * 1024 * 1024; //4.9mb
20
+ function storeFile(fileContent, folder) {
21
+ const fileName = `file${Date.now()}`;
22
+ return new Promise((res, rej) => fs_1.default.writeFile(path_1.default.join(folder, fileName), fileContent, (err) => {
23
+ if (err) {
24
+ rej(err);
25
+ }
26
+ else {
27
+ res(fileName);
28
+ }
29
+ }));
30
+ }
31
+ exports.storeFile = storeFile;
32
+ function getFileContent(url) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const response = (yield axios_1.default.get(url, { responseType: 'arraybuffer' })).data;
35
+ return response;
36
+ });
37
+ }
38
+ exports.getFileContent = getFileContent;
39
+ function getFileStrings(url) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const response = (yield axios_1.default.get(url)).data;
42
+ // the response is presented in the ndjson format
43
+ const jsonRows = response.split(/\n|\n\r/).filter(Boolean);
44
+ return jsonRows.map((jsonStringRow) => JSON.parse(jsonStringRow));
45
+ });
46
+ }
47
+ exports.getFileStrings = getFileStrings;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
+ import { CrowdinClientRequest } from '../types';
2
3
  import { Response } from 'express';
3
- import { CrowdinClientRequest } from '../../models';
4
4
  export default function handle(): (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;
@@ -0,0 +1,4 @@
1
+ /// <reference types="qs" />
2
+ import { CrowdinClientRequest } from '../types';
3
+ import { Response } from 'express';
4
+ export default function handle(): (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;
@@ -0,0 +1,4 @@
1
+ /// <reference types="qs" />
2
+ import { Request, Response } from 'express';
3
+ import { Config } from '../types';
4
+ export default function handle(config: Config): (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;
@@ -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 crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
13
- const models_1 = require("../models");
13
+ const types_1 = require("../types");
14
14
  const storage_1 = require("../storage");
15
15
  const util_1 = require("../util");
16
16
  const logger_1 = require("../util/logger");
@@ -29,7 +29,7 @@ function handle(config) {
29
29
  accessToken: token.accessToken,
30
30
  refreshToken: token.refreshToken,
31
31
  expire: (Date.now() / 1000 + token.expiresIn).toString(),
32
- type: event.domain ? models_1.AccountType.ENTERPRISE : models_1.AccountType.NORMAL,
32
+ type: event.domain ? types_1.AccountType.ENTERPRISE : types_1.AccountType.NORMAL,
33
33
  };
34
34
  const existingCredentials = yield (0, storage_1.getStorage)().getCrowdinCredentials(credentials.id);
35
35
  if (!!existingCredentials) {
@@ -47,7 +47,7 @@ exports.default = handle;
47
47
  function fetchToken(config, event) {
48
48
  var _a, _b;
49
49
  return __awaiter(this, void 0, void 0, function* () {
50
- if (config.authenticationType === models_1.AuthenticationType.CODE) {
50
+ if (config.authenticationType === types_1.AuthenticationType.CODE) {
51
51
  const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)({
52
52
  clientId: config.clientId,
53
53
  clientSecret: config.clientSecret,
@@ -1,4 +1,5 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { CrowdinClientRequest, IntegrationLogic } from '../../models';
3
+ import { CrowdinClientRequest } from '../../../types';
4
+ import { IntegrationLogic } from '../types';
4
5
  export default function handle(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;
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const util_1 = require("../../util");
13
- const logger_1 = require("../../util/logger");
12
+ const util_1 = require("../../../util");
13
+ const logger_1 = require("../../../util/logger");
14
14
  function handle(integration) {
15
15
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
16
  const fileId = Number(req.params.fileId || req.body.fileId);
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import { Response } from 'express';
3
+ import { Config } from '../../../types';
4
+ import { IntegrationLogic } from '../types';
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;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const util_1 = require("../../util");
13
- const defaults_1 = require("../../util/defaults");
14
- const logger_1 = require("../../util/logger");
12
+ const util_1 = require("../../../util");
13
+ const defaults_1 = require("../util/defaults");
14
+ const logger_1 = require("../../../util/logger");
15
15
  function handle(config, integration) {
16
16
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
17
17
  req.logInfo('Loading crowdin files');
@@ -0,0 +1,4 @@
1
+ /// <reference types="qs" />
2
+ import { Response } from 'express';
3
+ import { CrowdinClientRequest } from '../../../types';
4
+ export default function handle(): (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;
@@ -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 util_1 = require("../../util");
12
+ const util_1 = require("../../../util");
13
13
  function handle() {
14
14
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
15
15
  const projectId = req.crowdinContext.jwtPayload.context.project_id;
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import { Response } from 'express';
3
+ import { Config } from '../../../types';
4
+ import { IntegrationLogic } from '../types';
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;
@@ -13,12 +13,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const lodash_uniqby_1 = __importDefault(require("lodash.uniqby"));
16
- const job_1 = require("../../models/job");
17
- const util_1 = require("../../util");
18
- const defaults_1 = require("../../util/defaults");
19
- const logger_1 = require("../../util/logger");
20
- const job_2 = require("../../util/job");
21
- const files_1 = require("../../util/files");
16
+ const types_1 = require("../util/types");
17
+ const util_1 = require("../../../util");
18
+ const defaults_1 = require("../util/defaults");
19
+ const logger_1 = require("../../../util/logger");
20
+ const job_1 = require("../util/job");
21
+ const files_1 = require("../util/files");
22
22
  function handle(config, integration) {
23
23
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
24
24
  var _a, _b;
@@ -33,10 +33,10 @@ function handle(config, integration) {
33
33
  if (((_b = config.api) === null || _b === void 0 ? void 0 : _b.default) && req.body.files) {
34
34
  req.body = req.body.files;
35
35
  }
36
- yield (0, job_2.runAsJob)({
36
+ yield (0, job_1.runAsJob)({
37
37
  integrationId: req.crowdinContext.clientId,
38
38
  crowdinId: req.crowdinContext.crowdinId,
39
- type: job_1.JobType.UPDATE_TO_CROWDIN,
39
+ type: types_1.JobType.UPDATE_TO_CROWDIN,
40
40
  title: 'Sync files to Crowdin',
41
41
  payload: req.body,
42
42
  res,
@@ -57,7 +57,7 @@ function handle(config, integration) {
57
57
  job,
58
58
  });
59
59
  let message;
60
- if ((0, util_1.isExtendedResultType)(result)) {
60
+ if ((0, files_1.isExtendedResultType)(result)) {
61
61
  message = result.message;
62
62
  }
63
63
  return { message };
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import { Request, Response } from 'express';
3
+ import { Config } from '../../../types';
4
+ import { IntegrationLogic } from '../types';
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;
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const storage_1 = require("../../storage");
13
- const logger_1 = require("../../util/logger");
14
- const util_1 = require("../../util");
15
- const cron_1 = require("../../util/cron");
16
- const webhooks_1 = require("../../util/webhooks");
17
- const models_1 = require("../../models");
12
+ const storage_1 = require("../../../storage");
13
+ const util_1 = require("../../../util");
14
+ const logger_1 = require("../../../util/logger");
15
+ const webhooks_1 = require("../util/webhooks");
16
+ const types_1 = require("../types");
17
+ const cron_1 = require("../util/cron");
18
18
  function filterSyncFiles(args) {
19
19
  var _a, _b;
20
20
  return __awaiter(this, void 0, void 0, function* () {
@@ -71,7 +71,12 @@ function handle(config, integration) {
71
71
  const webhookUrlParam = req.query[urlParam];
72
72
  let filesToSync;
73
73
  if (webhookUrlParam) {
74
- const { projectId, crowdinClient, rootFolder, appSettings, syncSettings } = yield (0, webhooks_1.prepareWebhookData)(config, integration, webhookUrlParam, models_1.Provider.CROWDIN);
74
+ const { projectId, crowdinClient, rootFolder, appSettings, syncSettings } = yield (0, webhooks_1.prepareWebhookData)({
75
+ config,
76
+ integration,
77
+ webhookUrlParam,
78
+ provider: types_1.Provider.CROWDIN,
79
+ });
75
80
  if (!crowdinClient) {
76
81
  return res.status(403).send({ error: 'Access denied' });
77
82
  }
@@ -98,7 +103,13 @@ function handle(config, integration) {
98
103
  delete syncFileSettings[eventPayload.fileId];
99
104
  }
100
105
  }
101
- const crowdinFiles = yield (0, cron_1.skipFoldersFromIntegrationRequest)(config, integration, projectId, filesToSync, crowdinClient.client);
106
+ const crowdinFiles = yield (0, cron_1.skipFoldersFromIntegrationRequest)({
107
+ config,
108
+ integration,
109
+ projectId,
110
+ crowdinFiles: filesToSync,
111
+ crowdinClient: crowdinClient.client,
112
+ });
102
113
  for (const fileId in crowdinFiles) {
103
114
  const webhook = yield (0, storage_1.getStorage)().getWebhooks(fileId, syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
104
115
  if (!webhook) {
@@ -0,0 +1,4 @@
1
+ /// <reference types="qs" />
2
+ import { Response } from 'express';
3
+ import { IntegrationLogic } from '../types';
4
+ export default function handle(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;
@@ -9,19 +9,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const util_1 = require("../../util");
13
- const logger_1 = require("../../util/logger");
14
- const files_1 = require("../../util/files");
12
+ const util_1 = require("../../../util");
13
+ const logger_1 = require("../../../util/logger");
14
+ const files_1 = require("../util/files");
15
15
  function handle(integration) {
16
16
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
17
17
  const { parent_id: parentId, search, page } = req.query;
18
- req.logInfo('Recieved request to get integration data');
18
+ req.logInfo('Received request to get integration data');
19
19
  let message;
20
20
  let stopPagination;
21
21
  let files;
22
22
  try {
23
23
  const result = yield integration.getIntegrationFiles(req.integrationCredentials, req.integrationSettings, parentId, search, page);
24
- if ((0, util_1.isExtendedResultType)(result)) {
24
+ if ((0, files_1.isExtendedResultType)(result)) {
25
25
  files = result.data;
26
26
  message = result.message;
27
27
  stopPagination = result.stopPagination;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config, CrowdinClientRequest, IntegrationLogic } from '../../models';
3
+ import { Config, CrowdinClientRequest } from '../../../types';
4
+ import { IntegrationLogic } from '../types';
4
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;
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const storage_1 = require("../../storage");
13
- const util_1 = require("../../util");
14
- const logger_1 = require("../../util/logger");
12
+ const storage_1 = require("../../../storage");
13
+ const util_1 = require("../../../util");
14
+ const logger_1 = require("../../../util/logger");
15
15
  function handle(config, integration) {
16
16
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
17
17
  req.logInfo('Received integration login request');
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import { Response } from 'express';
3
+ import { Config } from '../../../types';
4
+ import { IntegrationLogic } from '../types';
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;
@@ -9,11 +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
- const storage_1 = require("../../storage");
13
- const util_1 = require("../../util");
14
- const connection_1 = require("../../util/connection");
15
- const webhooks_1 = require("../../util/webhooks");
16
- const logger_1 = require("../../util/logger");
12
+ const storage_1 = require("../../../storage");
13
+ const util_1 = require("../../../util");
14
+ const logger_1 = require("../../../util/logger");
15
+ const subscription_1 = require("../../../util/subscription");
16
+ const webhooks_1 = require("../util/webhooks");
17
17
  function handle(config, integration) {
18
18
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
19
19
  req.logInfo('Received integration logout request');
@@ -34,9 +34,16 @@ function handle(config, integration) {
34
34
  }
35
35
  req.logInfo(`Deleting integration credentials for ${req.crowdinContext.clientId} client`);
36
36
  yield (0, storage_1.getStorage)().deleteIntegrationCredentials(req.crowdinContext.clientId);
37
- (0, connection_1.clearCache)(req.crowdinContext.crowdinId);
37
+ (0, subscription_1.clearCache)(req.crowdinContext.crowdinId);
38
38
  if (integration.webhooks) {
39
- yield (0, webhooks_1.unregisterWebhooks)(config, integration, req.crowdinApiClient, req.crowdinContext, req.integrationCredentials, req.integrationSettings);
39
+ yield (0, webhooks_1.unregisterWebhooks)({
40
+ config,
41
+ integration,
42
+ client: req.crowdinApiClient,
43
+ crowdinContext: req.crowdinContext,
44
+ apiCredentials: req.integrationCredentials,
45
+ appSettings: req.integrationSettings,
46
+ });
40
47
  }
41
48
  res.status(204).end();
42
49
  }));
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import { Response } from 'express';
3
+ import { Config } from '../../../types';
4
+ import { IntegrationLogic } from '../types';
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;
@@ -9,11 +9,12 @@ 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");
13
- const util_1 = require("../../util");
14
- const defaults_1 = require("../../util/defaults");
15
- const job_2 = require("../../util/job");
16
- const logger_1 = require("../../util/logger");
12
+ const types_1 = require("../util/types");
13
+ const util_1 = require("../../../util");
14
+ const defaults_1 = require("../util/defaults");
15
+ const job_1 = require("../util/job");
16
+ const logger_1 = require("../../../util/logger");
17
+ const files_1 = require("../util/files");
17
18
  function handle(config, integration) {
18
19
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
19
20
  var _a;
@@ -26,10 +27,10 @@ function handle(config, integration) {
26
27
  if (((_a = config.api) === null || _a === void 0 ? void 0 : _a.default) && req.body.files) {
27
28
  req.body = req.body.files;
28
29
  }
29
- yield (0, job_2.runAsJob)({
30
+ yield (0, job_1.runAsJob)({
30
31
  integrationId: req.crowdinContext.clientId,
31
32
  crowdinId: req.crowdinContext.crowdinId,
32
- type: job_1.JobType.UPDATE_TO_INTEGRATION,
33
+ type: types_1.JobType.UPDATE_TO_INTEGRATION,
33
34
  title: 'Sync files to ' + config.name,
34
35
  payload: req.body,
35
36
  res,
@@ -44,7 +45,7 @@ function handle(config, integration) {
44
45
  job,
45
46
  });
46
47
  let message;
47
- if ((0, util_1.isExtendedResultType)(result)) {
48
+ if ((0, files_1.isExtendedResultType)(result)) {
48
49
  message = result.message;
49
50
  }
50
51
  return { message };
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import { Request, Response } from 'express';
3
+ import { Config } from '../../../types';
4
+ import { IntegrationLogic } from '../types';
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;
@@ -9,16 +9,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const models_1 = require("../../models");
13
- const util_1 = require("../../util");
14
- const webhooks_1 = require("../../util/webhooks");
12
+ const util_1 = require("../../../util");
13
+ const webhooks_1 = require("../util/webhooks");
14
+ const types_1 = require("../types");
15
15
  function handle(config, integration) {
16
16
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
17
17
  var _a, _b;
18
18
  const urlParam = (_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.urlParam;
19
19
  const webhookUrlParam = req.query[urlParam];
20
20
  if (((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhookInterceptor) && webhookUrlParam) {
21
- const webhookData = yield (0, webhooks_1.prepareWebhookData)(config, integration, webhookUrlParam, models_1.Provider.INTEGRATION);
21
+ const webhookData = yield (0, webhooks_1.prepareWebhookData)({
22
+ config,
23
+ integration,
24
+ webhookUrlParam,
25
+ provider: types_1.Provider.INTEGRATION,
26
+ });
22
27
  if (!webhookData.crowdinClient) {
23
28
  return res.status(403).send({ error: 'Access denied' });
24
29
  }