@crowdin/app-project-module 0.108.0 → 1.0.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 (202) hide show
  1. package/out/app-test/integration/get-integration-files.js +16 -4
  2. package/out/app-test/integration/types.d.ts +1 -1
  3. package/out/app-test/integration/update-crowdin.js +2 -2
  4. package/out/app-test/integration/update-integration.js +2 -2
  5. package/out/index.d.ts +2 -1
  6. package/out/index.js +73 -30
  7. package/out/middlewares/auto-credentials-masker.d.ts +4 -0
  8. package/out/middlewares/auto-credentials-masker.js +45 -0
  9. package/out/middlewares/crowdin-client.d.ts +1 -1
  10. package/out/middlewares/integration-credentials.d.ts +2 -2
  11. package/out/middlewares/integration-credentials.js +7 -4
  12. package/out/middlewares/render-ui-module.d.ts +3 -3
  13. package/out/middlewares/render-ui-module.js +10 -13
  14. package/out/middlewares/ui-module.d.ts +1 -1
  15. package/out/middlewares/ui-module.js +11 -1
  16. package/out/modules/about.d.ts +2 -1
  17. package/out/modules/about.js +10 -3
  18. package/out/modules/ai-prompt-provider/handlers/compile.d.ts +1 -1
  19. package/out/modules/ai-prompt-provider/handlers/compile.js +7 -1
  20. package/out/modules/ai-prompt-provider/index.js +2 -2
  21. package/out/modules/ai-prompt-provider/types.d.ts +7 -1
  22. package/out/modules/ai-provider/handlers/chat-completions.d.ts +1 -1
  23. package/out/modules/ai-provider/handlers/chat-completions.js +1 -1
  24. package/out/modules/ai-provider/handlers/get-model-list.d.ts +1 -1
  25. package/out/modules/ai-provider/index.js +2 -2
  26. package/out/modules/ai-provider/types.d.ts +4 -4
  27. package/out/modules/ai-request-processors/handler.d.ts +1 -1
  28. package/out/modules/ai-request-processors/handler.js +12 -2
  29. package/out/modules/ai-request-processors/types.d.ts +12 -2
  30. package/out/modules/ai-tools/handlers/tool-calls.d.ts +1 -1
  31. package/out/modules/ai-tools/handlers/tool-calls.js +1 -1
  32. package/out/modules/ai-tools/index.js +1 -1
  33. package/out/modules/ai-tools/types.d.ts +1 -1
  34. package/out/modules/auth-guard/handlers/verify.d.ts +1 -1
  35. package/out/modules/auth-guard/index.js +1 -1
  36. package/out/modules/automation-action/handlers/execute.d.ts +1 -1
  37. package/out/modules/automation-action/handlers/execute.js +1 -1
  38. package/out/modules/automation-action/handlers/input-schema.d.ts +1 -1
  39. package/out/modules/automation-action/handlers/output-schema.d.ts +1 -1
  40. package/out/modules/automation-action/handlers/validate-settings.d.ts +1 -1
  41. package/out/modules/automation-action/handlers/validate-settings.js +1 -1
  42. package/out/modules/automation-action/index.js +1 -1
  43. package/out/modules/automation-action/types.d.ts +4 -4
  44. package/out/modules/automation-action/util/index.js +2 -5
  45. package/out/modules/context-menu/index.js +2 -2
  46. package/out/modules/custom-mt/handlers/translate.d.ts +1 -1
  47. package/out/modules/custom-mt/handlers/translate.js +25 -9
  48. package/out/modules/custom-mt/index.js +3 -3
  49. package/out/modules/custom-mt/types.d.ts +10 -2
  50. package/out/modules/custom-spell-check/handlers/get-languages-list.d.ts +1 -1
  51. package/out/modules/custom-spell-check/handlers/spell-check.d.ts +1 -1
  52. package/out/modules/custom-spell-check/index.js +4 -4
  53. package/out/modules/editor-right-panel/index.js +1 -1
  54. package/out/modules/external-qa-check/handlers/validate.d.ts +1 -1
  55. package/out/modules/external-qa-check/index.js +2 -2
  56. package/out/modules/file-processing/handlers/custom-file-format.d.ts +7 -2
  57. package/out/modules/file-processing/handlers/custom-file-format.js +62 -22
  58. package/out/modules/file-processing/handlers/file-download.d.ts +1 -1
  59. package/out/modules/file-processing/handlers/file-download.js +5 -0
  60. package/out/modules/file-processing/handlers/pre-post-process.d.ts +1 -1
  61. package/out/modules/file-processing/handlers/pre-post-process.js +41 -15
  62. package/out/modules/file-processing/handlers/translations-alignment.d.ts +1 -1
  63. package/out/modules/file-processing/handlers/translations-alignment.js +10 -4
  64. package/out/modules/file-processing/index.js +12 -2
  65. package/out/modules/file-processing/types.d.ts +36 -5
  66. package/out/modules/file-processing/util/defaults.js +50 -6
  67. package/out/modules/file-processing/util/files.js +2 -1
  68. package/out/modules/form-data-display.d.ts +1 -1
  69. package/out/modules/form-data-save.d.ts +1 -1
  70. package/out/modules/install.d.ts +1 -1
  71. package/out/modules/integration/handlers/crowdin-file-progress.d.ts +1 -1
  72. package/out/modules/integration/handlers/crowdin-file-progress.js +5 -1
  73. package/out/modules/integration/handlers/crowdin-files-target-languages.d.ts +5 -0
  74. package/out/modules/integration/handlers/crowdin-files-target-languages.js +103 -0
  75. package/out/modules/integration/handlers/crowdin-files.d.ts +1 -1
  76. package/out/modules/integration/handlers/crowdin-files.js +7 -1
  77. package/out/modules/integration/handlers/crowdin-project.d.ts +1 -1
  78. package/out/modules/integration/handlers/crowdin-update.d.ts +1 -1
  79. package/out/modules/integration/handlers/crowdin-update.js +59 -18
  80. package/out/modules/integration/handlers/crowdin-webhook.d.ts +1 -1
  81. package/out/modules/integration/handlers/crowdin-webhook.js +15 -8
  82. package/out/modules/integration/handlers/integration-data.d.ts +1 -1
  83. package/out/modules/integration/handlers/integration-data.js +13 -6
  84. package/out/modules/integration/handlers/integration-login.d.ts +1 -1
  85. package/out/modules/integration/handlers/integration-logout.d.ts +1 -1
  86. package/out/modules/integration/handlers/integration-logout.js +8 -3
  87. package/out/modules/integration/handlers/integration-update.d.ts +1 -1
  88. package/out/modules/integration/handlers/integration-update.js +44 -6
  89. package/out/modules/integration/handlers/integration-webhook.d.ts +1 -1
  90. package/out/modules/integration/handlers/invite-users.d.ts +1 -1
  91. package/out/modules/integration/handlers/job-cancel.d.ts +1 -1
  92. package/out/modules/integration/handlers/job-info-deprecated.d.ts +1 -1
  93. package/out/modules/integration/handlers/job-info-deprecated.js +3 -2
  94. package/out/modules/integration/handlers/job-info.d.ts +1 -1
  95. package/out/modules/integration/handlers/job-list.d.ts +1 -1
  96. package/out/modules/integration/handlers/main.d.ts +1 -1
  97. package/out/modules/integration/handlers/main.js +32 -2
  98. package/out/modules/integration/handlers/oauth-login.d.ts +1 -1
  99. package/out/modules/integration/handlers/oauth-login.js +28 -6
  100. package/out/modules/integration/handlers/oauth-polling.d.ts +1 -1
  101. package/out/modules/integration/handlers/oauth-url.d.ts +1 -1
  102. package/out/modules/integration/handlers/settings-save.d.ts +1 -1
  103. package/out/modules/integration/handlers/settings-save.js +9 -9
  104. package/out/modules/integration/handlers/settings.d.ts +1 -1
  105. package/out/modules/integration/handlers/sync-settings-save.d.ts +1 -1
  106. package/out/modules/integration/handlers/sync-settings-save.js +5 -9
  107. package/out/modules/integration/handlers/sync-settings.d.ts +1 -1
  108. package/out/modules/integration/handlers/user-errors.d.ts +1 -1
  109. package/out/modules/integration/handlers/users.d.ts +1 -1
  110. package/out/modules/integration/index.js +19 -33
  111. package/out/modules/integration/types.d.ts +133 -29
  112. package/out/modules/integration/types.js +1 -0
  113. package/out/modules/integration/util/cron.d.ts +2 -2
  114. package/out/modules/integration/util/cron.js +40 -24
  115. package/out/modules/integration/util/defaults.d.ts +4 -0
  116. package/out/modules/integration/util/defaults.js +175 -15
  117. package/out/modules/integration/util/files.d.ts +2 -1
  118. package/out/modules/integration/util/files.js +19 -8
  119. package/out/modules/integration/util/job.js +4 -3
  120. package/out/modules/integration/util/snapshot.js +19 -3
  121. package/out/modules/integration/util/types.d.ts +1 -0
  122. package/out/modules/integration/util/types.js +1 -0
  123. package/out/modules/integration/util/webhooks.d.ts +8 -8
  124. package/out/modules/integration/util/webhooks.js +34 -17
  125. package/out/modules/manifest.js +12 -12
  126. package/out/modules/modal/index.js +2 -2
  127. package/out/modules/organization-menu/index.js +5 -4
  128. package/out/modules/organization-settings-menu/index.js +5 -4
  129. package/out/modules/profile-resources-menu/index.js +5 -4
  130. package/out/modules/profile-settings-menu/index.js +5 -4
  131. package/out/modules/project-menu/index.js +1 -1
  132. package/out/modules/project-menu-crowdsource/index.js +1 -1
  133. package/out/modules/project-reports/index.js +3 -2
  134. package/out/modules/project-tools/index.js +3 -2
  135. package/out/modules/status.d.ts +1 -1
  136. package/out/modules/status.js +12 -3
  137. package/out/modules/subscription-paid.d.ts +1 -1
  138. package/out/modules/uninstall.d.ts +1 -1
  139. package/out/modules/uninstall.js +1 -1
  140. package/out/modules/webhooks/handlers/webhook-handler.d.ts +2 -2
  141. package/out/modules/webhooks/handlers/webhook-handler.js +33 -22
  142. package/out/modules/webhooks/types.d.ts +7 -0
  143. package/out/modules/workflow-step-type/handlers/delete-step.d.ts +1 -1
  144. package/out/modules/workflow-step-type/handlers/step-settings-save.d.ts +1 -1
  145. package/out/modules/workflow-step-type/index.js +2 -2
  146. package/out/modules/workflow-step-type/util/index.js +3 -6
  147. package/out/static/js/dependent.js +16 -7
  148. package/out/static/ui/error.bundle.js +474 -0
  149. package/out/static/ui/error.bundle.js.map +1 -0
  150. package/out/static/ui/install.bundle.js +459 -0
  151. package/out/static/ui/install.bundle.js.map +1 -0
  152. package/out/static/ui/login.bundle.js +630 -0
  153. package/out/static/ui/login.bundle.js.map +1 -0
  154. package/out/static/ui/main.bundle.js +2109 -0
  155. package/out/static/ui/main.bundle.js.map +1 -0
  156. package/out/static/ui/oauth.bundle.js +467 -0
  157. package/out/static/ui/oauth.bundle.js.map +1 -0
  158. package/out/storage/d1.d.ts +107 -0
  159. package/out/storage/d1.js +831 -0
  160. package/out/storage/index.js +8 -1
  161. package/out/storage/mysql.js +22 -19
  162. package/out/storage/postgre.d.ts +0 -1
  163. package/out/storage/postgre.js +20 -30
  164. package/out/storage/sqlite.d.ts +2 -5
  165. package/out/storage/sqlite.js +29 -69
  166. package/out/types.d.ts +78 -18
  167. package/out/util/connection.js +1 -1
  168. package/out/util/credentials-masker.d.ts +3 -3
  169. package/out/util/credentials-masker.js +14 -20
  170. package/out/util/cron.d.ts +29 -0
  171. package/out/util/cron.js +87 -0
  172. package/out/util/index.d.ts +14 -1
  173. package/out/util/index.js +121 -10
  174. package/out/util/jsx-renderer.d.ts +14 -0
  175. package/out/util/jsx-renderer.js +35 -0
  176. package/out/util/logger.d.ts +1 -0
  177. package/out/util/logger.js +2 -2
  178. package/out/util/static-files.d.ts +19 -0
  179. package/out/util/static-files.js +87 -0
  180. package/out/util/subscription.js +1 -1
  181. package/out/views/AboutPage.d.ts +10 -0
  182. package/out/views/AboutPage.js +76 -0
  183. package/out/views/FormPage.d.ts +14 -0
  184. package/out/views/FormPage.js +28 -0
  185. package/out/views/SubscriptionPage.d.ts +7 -0
  186. package/out/views/SubscriptionPage.js +26 -0
  187. package/out/views/index.d.ts +8 -0
  188. package/out/views/index.js +15 -0
  189. package/out/views/layout/Head.d.ts +9 -0
  190. package/out/views/layout/Head.js +54 -0
  191. package/package.json +43 -41
  192. package/out/util/handlebars.d.ts +0 -1
  193. package/out/util/handlebars.js +0 -46
  194. package/out/views/about.handlebars +0 -102
  195. package/out/views/error.handlebars +0 -54
  196. package/out/views/form.handlebars +0 -31
  197. package/out/views/install.handlebars +0 -16
  198. package/out/views/login.handlebars +0 -332
  199. package/out/views/main.handlebars +0 -2042
  200. package/out/views/oauth.handlebars +0 -11
  201. package/out/views/partials/head.handlebars +0 -53
  202. package/out/views/subscription.handlebars +0 -26
@@ -17,9 +17,11 @@ const path_1 = __importDefault(require("path"));
17
17
  const util_1 = require("../../../util");
18
18
  const files_1 = require("../util/files");
19
19
  const types_1 = require("../types");
20
- function handle(baseUrl, folder, config) {
21
- if (!fs_1.default.existsSync(path_1.default.join(folder, 'custom-file-format'))) {
22
- fs_1.default.mkdirSync(path_1.default.join(folder, 'custom-file-format'), { recursive: true });
20
+ function handle({ baseUrl, folder, config, fileStore, }) {
21
+ if (!fileStore) {
22
+ if (!fs_1.default.existsSync(path_1.default.join(folder, 'custom-file-format'))) {
23
+ fs_1.default.mkdirSync(path_1.default.join(folder, 'custom-file-format'), { recursive: true });
24
+ }
23
25
  }
24
26
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
25
27
  const baseFilesUrl = `${baseUrl}/file/download`;
@@ -43,12 +45,32 @@ function handle(baseUrl, folder, config) {
43
45
  let error;
44
46
  switch (body.jobType) {
45
47
  case types_1.ProcessFileJobType.BUILD_FILE:
46
- const buildFileResult = yield handleBuildFile(baseFilesUrl, folder, config, body, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id, file);
48
+ const buildFileResult = yield handleBuildFile({
49
+ baseUrl: baseFilesUrl,
50
+ dataFolder: folder,
51
+ config,
52
+ req: body,
53
+ client: req.crowdinApiClient,
54
+ context: req.crowdinContext,
55
+ projectId: req.crowdinContext.jwtPayload.context.project_id,
56
+ file,
57
+ fileStore,
58
+ });
47
59
  response = buildFileResult.response;
48
60
  error = buildFileResult.error;
49
61
  break;
50
62
  case types_1.ProcessFileJobType.PARSE_FILE:
51
- const parseFileResult = yield handleParseFile(baseFilesUrl, folder, config, body, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id, file);
63
+ const parseFileResult = yield handleParseFile({
64
+ baseUrl: baseFilesUrl,
65
+ dataFolder: folder,
66
+ config,
67
+ req: body,
68
+ client: req.crowdinApiClient,
69
+ context: req.crowdinContext,
70
+ projectId: req.crowdinContext.jwtPayload.context.project_id,
71
+ file,
72
+ fileStore,
73
+ });
52
74
  response = parseFileResult.response;
53
75
  error = parseFileResult.error;
54
76
  break;
@@ -59,7 +81,7 @@ function handle(baseUrl, folder, config) {
59
81
  }));
60
82
  }
61
83
  exports.default = handle;
62
- function handleBuildFile(baseUrl, dataFolder, config, req, client, context, projectId, file) {
84
+ function handleBuildFile({ baseUrl, dataFolder, config, req, client, context, projectId, file, fileStore, }) {
63
85
  return __awaiter(this, void 0, void 0, function* () {
64
86
  const response = {};
65
87
  if (!req.strings && !req.stringsUrl) {
@@ -74,10 +96,10 @@ function handleBuildFile(baseUrl, dataFolder, config, req, client, context, proj
74
96
  }
75
97
  let res;
76
98
  if ((req.file.id || !file) && config.exportStrings) {
77
- res = yield config.exportStrings(req, strings, client, context, projectId);
99
+ res = yield config.exportStrings({ request: req, strings, client, context, projectId });
78
100
  }
79
101
  else if (file && config.buildFile) {
80
- res = yield config.buildFile(file, req, strings, client, context, projectId);
102
+ res = yield config.buildFile({ fileContent: file, request: req, strings, client, context, projectId });
81
103
  }
82
104
  else {
83
105
  return { response };
@@ -88,25 +110,31 @@ function handleBuildFile(baseUrl, dataFolder, config, req, client, context, proj
88
110
  }
89
111
  else {
90
112
  let url;
91
- if (config.storeFile) {
92
- url = yield config.storeFile(res.contentFile);
113
+ if (fileStore) {
114
+ const fileRef = yield fileStore.storeFile(res.contentFile);
115
+ url = `${baseUrl}?file=${fileRef}`;
93
116
  }
94
117
  else {
95
- const storedFile = yield (0, files_1.storeFile)(res.contentFile, path_1.default.join(dataFolder, 'custom-file-format'));
96
- url = `${baseUrl}?file=${storedFile}`;
118
+ if (config.storeFile) {
119
+ url = yield config.storeFile(res.contentFile);
120
+ }
121
+ else {
122
+ const storedFile = yield (0, files_1.storeFile)(res.contentFile, path_1.default.join(dataFolder, 'custom-file-format'));
123
+ url = `${baseUrl}?file=${storedFile}`;
124
+ }
97
125
  }
98
126
  response.contentUrl = url;
99
127
  }
100
128
  return { response, error: res.error };
101
129
  });
102
130
  }
103
- function handleParseFile(baseUrl, dataFolder, config, req, client, context, projectId, file) {
131
+ function handleParseFile({ baseUrl, dataFolder, config, req, client, context, projectId, file, fileStore, }) {
104
132
  return __awaiter(this, void 0, void 0, function* () {
105
133
  const response = {};
106
134
  if (!config.parseFile || !file) {
107
135
  return { response };
108
136
  }
109
- const res = yield config.parseFile(file, req, client, context, projectId);
137
+ const res = yield config.parseFile({ fileContent: file, request: req, client, context, projectId });
110
138
  let maxSize = files_1.MAX_BODY_SIZE;
111
139
  if (res.strings && res.previewFile) {
112
140
  maxSize = maxSize / 2;
@@ -117,12 +145,18 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
117
145
  }
118
146
  else {
119
147
  let url;
120
- if (config.storeFile) {
121
- url = yield config.storeFile(res.previewFile);
148
+ if (fileStore) {
149
+ const fileRef = yield fileStore.storeFile(res.previewFile);
150
+ url = `${baseUrl}?file=${fileRef}`;
122
151
  }
123
152
  else {
124
- const storedFile = yield (0, files_1.storeFile)(res.previewFile, path_1.default.join(dataFolder, 'custom-file-format'));
125
- url = `${baseUrl}?file=${storedFile}`;
153
+ if (config.storeFile) {
154
+ url = yield config.storeFile(res.previewFile);
155
+ }
156
+ else {
157
+ const storedFile = yield (0, files_1.storeFile)(res.previewFile, path_1.default.join(dataFolder, 'custom-file-format'));
158
+ url = `${baseUrl}?file=${storedFile}`;
159
+ }
126
160
  }
127
161
  response.previewUrl = url;
128
162
  }
@@ -145,12 +179,18 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
145
179
  }
146
180
  else {
147
181
  let url;
148
- if (config.storeFile) {
149
- url = yield config.storeFile(bufferData);
182
+ if (fileStore) {
183
+ const fileRef = yield fileStore.storeFile(bufferData);
184
+ url = `${baseUrl}?file=${fileRef}`;
150
185
  }
151
186
  else {
152
- const storedFile = yield (0, files_1.storeFile)(bufferData, path_1.default.join(dataFolder, 'custom-file-format'));
153
- url = `${baseUrl}?file=${storedFile}`;
187
+ if (config.storeFile) {
188
+ url = yield config.storeFile(bufferData);
189
+ }
190
+ else {
191
+ const storedFile = yield (0, files_1.storeFile)(bufferData, path_1.default.join(dataFolder, 'custom-file-format'));
192
+ url = `${baseUrl}?file=${storedFile}`;
193
+ }
154
194
  }
155
195
  response.stringsUrl = url;
156
196
  }
@@ -2,4 +2,4 @@
2
2
  import { Request, Response } from 'express';
3
3
  import { Config } from '../../../types';
4
4
  import { FileProcessLogic } from '../types';
5
- export default function handle(config: Config, processingConfig: FileProcessLogic, folderName: string): (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;
5
+ export default function handle(config: Config, processingConfig: FileProcessLogic, folderName: string): (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> | import("../../../types").CrowdinClientRequest, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -19,6 +19,11 @@ const logger_1 = require("../../../util/logger");
19
19
  function handle(config, processingConfig, folderName) {
20
20
  const folder = processingConfig.filesFolder || config.dbFolder;
21
21
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
22
+ if (config.fileStore) {
23
+ const fileContent = yield config.fileStore.getFile(req.query.file);
24
+ res.send(fileContent);
25
+ return;
26
+ }
22
27
  const filePath = path_1.default.join(folder, folderName, req.query.file);
23
28
  (0, logger_1.log)(`Downloading file ${filePath}`);
24
29
  res.download(filePath, function (err) {
@@ -2,4 +2,4 @@
2
2
  import { Response } from 'express';
3
3
  import { Config, CrowdinClientRequest } from '../../../types';
4
4
  import { FileImportExportLogic } from '../types';
5
- export default function handle(baseConfig: Config, config: FileImportExportLogic, folderName: string): (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;
5
+ export default function handle(baseConfig: Config, config: FileImportExportLogic, folderName: string): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> | CrowdinClientRequest, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -19,8 +19,10 @@ const types_1 = require("../types");
19
19
  const files_1 = require("../util/files");
20
20
  function handle(baseConfig, config, folderName) {
21
21
  const folderPath = config.filesFolder || baseConfig.dbFolder;
22
- if (!fs_1.default.existsSync(path_1.default.join(folderPath, folderName))) {
23
- fs_1.default.mkdirSync(path_1.default.join(folderPath, folderName), { recursive: true });
22
+ if (!baseConfig.fileStore) {
23
+ if (!fs_1.default.existsSync(path_1.default.join(folderPath, folderName))) {
24
+ fs_1.default.mkdirSync(path_1.default.join(folderPath, folderName), { recursive: true });
25
+ }
24
26
  }
25
27
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
26
28
  var _a;
@@ -57,7 +59,13 @@ function handle(baseConfig, config, folderName) {
57
59
  return rawContent;
58
60
  });
59
61
  }
60
- const fileProcessResult = yield config.fileProcess(body, fileContent, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id);
62
+ const fileProcessResult = yield config.fileProcess({
63
+ request: body,
64
+ content: fileContent,
65
+ client: req.crowdinApiClient,
66
+ context: req.crowdinContext,
67
+ projectId: req.crowdinContext.jwtPayload.context.project_id,
68
+ });
61
69
  if (fileProcessResult.notModified) {
62
70
  res.sendStatus(304);
63
71
  return;
@@ -72,12 +80,18 @@ function handle(baseConfig, config, folderName) {
72
80
  }
73
81
  else {
74
82
  let url;
75
- if (config.storeFile) {
76
- url = yield config.storeFile(contentFile);
83
+ if (baseConfig.fileStore) {
84
+ const fileRef = yield baseConfig.fileStore.storeFile(contentFile);
85
+ url = `${baseFilesUrl}?file=${fileRef}`;
77
86
  }
78
87
  else {
79
- const storedFile = yield (0, files_1.storeFile)(contentFile, path_1.default.join(folderPath, folderName));
80
- url = `${baseFilesUrl}?file=${storedFile}`;
88
+ if (config.storeFile) {
89
+ url = yield config.storeFile(contentFile);
90
+ }
91
+ else {
92
+ const storedFile = yield (0, files_1.storeFile)(contentFile, path_1.default.join(folderPath, folderName));
93
+ url = `${baseFilesUrl}?file=${storedFile}`;
94
+ }
81
95
  }
82
96
  response.contentUrl = url;
83
97
  }
@@ -103,12 +117,18 @@ function handle(baseConfig, config, folderName) {
103
117
  }
104
118
  else {
105
119
  let url;
106
- if (config.storeFile) {
107
- url = yield config.storeFile(previewFile);
120
+ if (baseConfig.fileStore) {
121
+ const fileRef = yield baseConfig.fileStore.storeFile(previewFile);
122
+ url = `${baseFilesUrl}?file=${fileRef}`;
108
123
  }
109
124
  else {
110
- const storedFile = yield (0, files_1.storeFile)(previewFile, path_1.default.join(folderPath, folderName));
111
- url = `${baseFilesUrl}?file=${storedFile}`;
125
+ if (config.storeFile) {
126
+ url = yield config.storeFile(previewFile);
127
+ }
128
+ else {
129
+ const storedFile = yield (0, files_1.storeFile)(previewFile, path_1.default.join(folderPath, folderName));
130
+ url = `${baseFilesUrl}?file=${storedFile}`;
131
+ }
112
132
  }
113
133
  response.previewUrl = url;
114
134
  }
@@ -121,12 +141,18 @@ function handle(baseConfig, config, folderName) {
121
141
  }
122
142
  else {
123
143
  let url;
124
- if (config.storeFile) {
125
- url = yield config.storeFile(bufferData);
144
+ if (baseConfig.fileStore) {
145
+ const fileRef = yield baseConfig.fileStore.storeFile(bufferData);
146
+ url = `${baseFilesUrl}?file=${fileRef}`;
126
147
  }
127
148
  else {
128
- const storedFile = yield (0, files_1.storeFile)(bufferData, path_1.default.join(folderPath, folderName));
129
- url = `${baseFilesUrl}?file=${storedFile}`;
149
+ if (config.storeFile) {
150
+ url = yield config.storeFile(bufferData);
151
+ }
152
+ else {
153
+ const storedFile = yield (0, files_1.storeFile)(bufferData, path_1.default.join(folderPath, folderName));
154
+ url = `${baseFilesUrl}?file=${storedFile}`;
155
+ }
130
156
  }
131
157
  response.stringsUrl = url;
132
158
  }
@@ -2,4 +2,4 @@
2
2
  import { Response } from 'express';
3
3
  import { Config, CrowdinClientRequest } from '../../../types';
4
4
  import { TranslationsAlignmentLogic } from '../types';
5
- export default function handle(baseConfig: Config, config: TranslationsAlignmentLogic, folderName: string): (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;
5
+ export default function handle(baseConfig: Config, config: TranslationsAlignmentLogic, folderName: string): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> | CrowdinClientRequest, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -37,10 +37,16 @@ function handle(baseConfig, config, folderName) {
37
37
  const fileTranslationsContent = body.translationStringsUrl
38
38
  ? (yield (0, files_1.getFileStrings)(body.translationStringsUrl))
39
39
  : body.translationStrings;
40
- const fileProcessResult = yield config.fileProcess(body, {
41
- sourceStrings: fileSourceStringsContent,
42
- translations: fileTranslationsContent,
43
- }, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id);
40
+ const fileProcessResult = yield config.fileProcess({
41
+ request: body,
42
+ content: {
43
+ sourceStrings: fileSourceStringsContent,
44
+ translations: fileTranslationsContent,
45
+ },
46
+ client: req.crowdinApiClient,
47
+ context: req.crowdinContext,
48
+ projectId: req.crowdinContext.jwtPayload.context.project_id,
49
+ });
44
50
  const { strings, error: processingErrorMessage } = fileProcessResult;
45
51
  if (!strings) {
46
52
  response.translations = [];
@@ -21,13 +21,23 @@ function registerCustomFileFormat({ config, app }) {
21
21
  optional: false,
22
22
  checkSubscriptionExpiration: true,
23
23
  moduleKey: config.customFileFormat.key,
24
- }), (0, custom_file_format_1.default)(config.baseUrl, config.customFileFormat.filesFolder || config.dbFolder, config.customFileFormat));
24
+ }), (0, custom_file_format_1.default)({
25
+ baseUrl: config.baseUrl,
26
+ folder: config.customFileFormat.filesFolder || config.dbFolder,
27
+ config: config.customFileFormat,
28
+ fileStore: config.fileStore,
29
+ }));
25
30
  // TEMPORARY CODE: it needs to support old path
26
31
  app.post('/process', (0, crowdin_client_1.default)({
27
32
  config,
28
33
  optional: false,
29
34
  checkSubscriptionExpiration: true,
30
- }), (0, custom_file_format_1.default)(config.baseUrl, config.customFileFormat.filesFolder || config.dbFolder, config.customFileFormat));
35
+ }), (0, custom_file_format_1.default)({
36
+ baseUrl: config.baseUrl,
37
+ folder: config.customFileFormat.filesFolder || config.dbFolder,
38
+ config: config.customFileFormat,
39
+ fileStore: config.fileStore,
40
+ }));
31
41
  // END TEMPORARY CODE
32
42
  app.get('/file/download', (0, file_download_1.default)(config, config.customFileFormat, 'custom-file-format'));
33
43
  }
@@ -48,15 +48,34 @@ export interface CustomFileFormatLogic extends FileProcessLogic {
48
48
  /**
49
49
  * Used for initial source file upload, source file update, and translation upload
50
50
  */
51
- parseFile?: (fileContent: Buffer, req: Omit<ProcessFileRequest, 'jobType' | 'file'>, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<ParseFileResponse>;
51
+ parseFile?: (options: {
52
+ fileContent: Buffer;
53
+ request: Omit<ProcessFileRequest, 'jobType' | 'file'>;
54
+ client: Crowdin;
55
+ context: CrowdinContextInfo;
56
+ projectId: number;
57
+ }) => Promise<ParseFileResponse>;
52
58
  /**
53
59
  * Used for translation download
54
60
  */
55
- buildFile?: (fileContent: Buffer, req: Omit<ProcessFileRequest, 'jobType' | 'file'>, strings: ProcessFileString[], client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>;
61
+ buildFile?: (options: {
62
+ fileContent: Buffer;
63
+ request: Omit<ProcessFileRequest, 'jobType' | 'file'>;
64
+ strings: ProcessFileString[];
65
+ client: Crowdin;
66
+ context: CrowdinContextInfo;
67
+ projectId: number;
68
+ }) => Promise<BuildFileResponse>;
56
69
  /**
57
70
  * Used for strings export
58
71
  */
59
- exportStrings?: (req: Omit<ProcessFileRequest, 'jobType'>, strings: ProcessFileString[], client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>;
72
+ exportStrings?: (options: {
73
+ request: Omit<ProcessFileRequest, 'jobType'>;
74
+ strings: ProcessFileString[];
75
+ client: Crowdin;
76
+ context: CrowdinContextInfo;
77
+ projectId: number;
78
+ }) => Promise<BuildFileResponse>;
60
79
  }
61
80
  export type FileImportExportLogic = FilePreImportLogic | FilePostImportLogic | FilePreExportLogic | FilePostExportLogic;
62
81
  export type FileImportExportContent = ProcessFileString[] | Buffer | undefined;
@@ -66,10 +85,22 @@ export interface FileTranslationAlignmentContent {
66
85
  translations: TranslationAlignmentContent;
67
86
  }
68
87
  export interface BaseFileProcessLogic<T> {
69
- fileProcess: (req: ProcessFileRequest, content: FileImportExportContent, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<T>;
88
+ fileProcess: (options: {
89
+ request: ProcessFileRequest;
90
+ content: FileImportExportContent;
91
+ client: Crowdin;
92
+ context: CrowdinContextInfo;
93
+ projectId: number;
94
+ }) => Promise<T>;
70
95
  }
71
96
  export interface TranslationAlignmentProcessLogin<T> {
72
- fileProcess: (req: ProcessTranslationAlignmentRequest, content: FileTranslationAlignmentContent, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<T>;
97
+ fileProcess: (options: {
98
+ request: ProcessTranslationAlignmentRequest;
99
+ content: FileTranslationAlignmentContent;
100
+ client: Crowdin;
101
+ context: CrowdinContextInfo;
102
+ projectId: number;
103
+ }) => Promise<T>;
73
104
  }
74
105
  export interface FilePreImportLogic extends FileProcessLogic, BaseFileProcessLogic<ContentFileResponse> {
75
106
  /**
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -10,20 +33,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
33
  };
11
34
  Object.defineProperty(exports, "__esModule", { value: true });
12
35
  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");
36
+ function loadAwsSdk() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ try {
39
+ const [s3Client, s3Presigner] = yield Promise.all([
40
+ Promise.resolve().then(() => __importStar(require('@aws-sdk/client-s3'))),
41
+ Promise.resolve().then(() => __importStar(require('@aws-sdk/s3-request-presigner'))),
42
+ ]);
43
+ return {
44
+ S3Client: s3Client.S3Client,
45
+ GetObjectCommand: s3Client.GetObjectCommand,
46
+ PutObjectCommand: s3Client.PutObjectCommand,
47
+ getSignedUrl: s3Presigner.getSignedUrl,
48
+ };
49
+ }
50
+ catch (_a) {
51
+ throw new Error('AWS SDK is not installed. To use S3 file storage, install required packages:\n' +
52
+ 'npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner');
53
+ }
54
+ });
55
+ }
15
56
  function applyFileProcessorsModuleDefaults(config, fileModule) {
16
57
  var _a, _b;
17
58
  const AWS_TMP_BUCKET_NAME = (_a = config.awsConfig) === null || _a === void 0 ? void 0 : _a.tmpBucketName;
18
59
  const AWS_REGION = (_b = config.awsConfig) === null || _b === void 0 ? void 0 : _b.region;
19
60
  if (AWS_TMP_BUCKET_NAME && AWS_REGION && !fileModule.storeFile) {
20
- const s3 = new client_s3_1.S3Client({ region: AWS_REGION });
61
+ let initPromise = null;
62
+ const getS3 = () => (initPromise !== null && initPromise !== void 0 ? initPromise : (initPromise = loadAwsSdk().then((sdk) => ({ sdk, s3: new sdk.S3Client({ region: AWS_REGION }) }))));
21
63
  fileModule.storeFile = (content) => __awaiter(this, void 0, void 0, function* () {
64
+ const { sdk, s3 } = yield getS3();
65
+ const { GetObjectCommand, PutObjectCommand, getSignedUrl } = sdk;
22
66
  const fileName = `file-${config.identifier}-${Date.now()}`;
23
- const command = new client_s3_1.PutObjectCommand({ Bucket: AWS_TMP_BUCKET_NAME, Key: fileName, Body: content });
67
+ const command = new PutObjectCommand({ Bucket: AWS_TMP_BUCKET_NAME, Key: fileName, Body: content });
24
68
  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 });
69
+ const getObjectCommand = new GetObjectCommand({ Bucket: AWS_TMP_BUCKET_NAME, Key: fileName });
70
+ return getSignedUrl(s3, getObjectCommand, { expiresIn: 3600 });
27
71
  });
28
72
  }
29
73
  }
@@ -32,7 +32,8 @@ exports.storeFile = storeFile;
32
32
  function getFileContent(url) {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
34
  const response = (yield axios_1.default.get(url, { responseType: 'arraybuffer' })).data;
35
- return response;
35
+ // Support for both Node.js (returns Buffer) and Cloudflare Workers (returns ArrayBuffer)
36
+ return Buffer.isBuffer(response) ? response : Buffer.from(response);
36
37
  });
37
38
  }
38
39
  exports.getFileContent = getFileContent;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Config, CrowdinClientRequest } from '../types';
3
3
  import { Response } from 'express';
4
- export default function handle(config: Config): (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;
4
+ export default function handle(config: Config): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> | CrowdinClientRequest, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Config, CrowdinClientRequest } from '../types';
3
3
  import { Response } from 'express';
4
- export default function handle(config: Config): (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;
4
+ export default function handle(config: Config): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> | CrowdinClientRequest, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Request, Response } from 'express';
3
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;
4
+ export default function handle(config: Config): (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> | import("../types").CrowdinClientRequest, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -2,4 +2,4 @@
2
2
  import { Response } from 'express';
3
3
  import { CrowdinClientRequest } from '../../../types';
4
4
  import { IntegrationLogic } from '../types';
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;
5
+ export default function handle(integration: IntegrationLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> | CrowdinClientRequest, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -24,7 +24,11 @@ function handle(integration) {
24
24
  req.logInfo(`Loading translation progress for file ${fileId}`);
25
25
  if (integration.getFileProgress) {
26
26
  try {
27
- const progress = yield integration.getFileProgress(req.crowdinContext.jwtPayload.context.project_id, req.crowdinApiClient, fileId);
27
+ const progress = yield integration.getFileProgress({
28
+ projectId: req.crowdinContext.jwtPayload.context.project_id,
29
+ client: req.crowdinApiClient,
30
+ fileId,
31
+ });
28
32
  req.logInfo(`Translation progress for file ${fileId} ${JSON.stringify(progress, null, 2)}`);
29
33
  res.send(progress);
30
34
  }
@@ -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("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> | import("../../../types").CrowdinClientRequest, res: Response<any, Record<string, any>>, next: Function) => void;