@crowdin/app-project-module 0.16.3 → 0.16.5

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.
package/README.md CHANGED
@@ -173,9 +173,6 @@ const configuration = {
173
173
  crowdinModule.createApp(configuration);
174
174
  ```
175
175
 
176
-
177
-
178
-
179
176
  ## Payment
180
177
 
181
178
  By default App does not have any subscription and it's free to use. But you can override this.
@@ -540,14 +537,10 @@ const configuration = {
540
537
  extensions: [
541
538
  '.resx'
542
539
  ],
543
- parseFile: async (file, req, client, context, projectId) => {
544
- //parse logic
545
- return { strings: [] };
546
- },
547
- buildFile: async (file, req, strings, client, context, projectId) => {
548
- const isStringsExport = !!req.file.path;
540
+ exportStrings: async (req, strings, client, context, projectId) => {
541
+ const file = req.file;
549
542
  //export logic
550
- return { contentFile: {} }
543
+ return { contentFile: '' }
551
544
  }
552
545
  }
553
546
  };
@@ -29,7 +29,7 @@ function storeFile(fileContent, folder) {
29
29
  }
30
30
  }));
31
31
  }
32
- function handleBuildFile(baseUrl, dataFolder, config, file, req, client, context, projectId) {
32
+ function handleBuildFile(baseUrl, dataFolder, config, req, client, context, projectId, file) {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
34
  const response = {};
35
35
  if (!req.strings && !req.stringsUrl) {
@@ -42,7 +42,16 @@ function handleBuildFile(baseUrl, dataFolder, config, file, req, client, context
42
42
  else {
43
43
  strings = (yield axios_1.default.get(req.stringsUrl)).data;
44
44
  }
45
- const res = yield config.buildFile(file, req, strings, client, context, projectId);
45
+ let res;
46
+ if ((req.file.id || !file) && config.exportStrings) {
47
+ res = yield config.exportStrings(req, strings, client, context, projectId);
48
+ }
49
+ else if (file && config.buildFile) {
50
+ res = yield config.buildFile(file, req, strings, client, context, projectId);
51
+ }
52
+ else {
53
+ return response;
54
+ }
46
55
  const contentFileEncoded = Buffer.from(res.contentFile).toString('base64');
47
56
  if (Buffer.byteLength(contentFileEncoded, 'utf8') < MAX_BODY_SIZE) {
48
57
  response.content = contentFileEncoded;
@@ -54,9 +63,12 @@ function handleBuildFile(baseUrl, dataFolder, config, file, req, client, context
54
63
  return response;
55
64
  });
56
65
  }
57
- function handleParseFile(baseUrl, dataFolder, config, file, req, client, context, projectId) {
66
+ function handleParseFile(baseUrl, dataFolder, config, req, client, context, projectId, file) {
58
67
  return __awaiter(this, void 0, void 0, function* () {
59
68
  const response = {};
69
+ if (!config.parseFile || !file) {
70
+ return response;
71
+ }
60
72
  const res = yield config.parseFile(file, req, client, context, projectId);
61
73
  if (res.previewFile) {
62
74
  const previewFileEncoded = Buffer.from(res.previewFile).toString('base64');
@@ -103,16 +115,16 @@ function handle(baseConfig, baseUrl, folder, config) {
103
115
  if (body.file.content) {
104
116
  file = Buffer.from(body.file.content, 'base64').toString();
105
117
  }
106
- else {
107
- file = (yield axios_1.default.get(body.file.contentUrl || '')).data;
118
+ else if (body.file.contentUrl) {
119
+ file = (yield axios_1.default.get(body.file.contentUrl)).data;
108
120
  }
109
121
  let response = {};
110
122
  switch (body.jobType) {
111
123
  case models_1.ProcessFileJobType.BUILD_FILE:
112
- response = yield handleBuildFile(baseFilesUrl, folder, config, file, body, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id);
124
+ response = yield handleBuildFile(baseFilesUrl, folder, config, body, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id, file);
113
125
  break;
114
126
  case models_1.ProcessFileJobType.PARSE_FILE:
115
- response = yield handleParseFile(baseFilesUrl, folder, config, file, body, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id);
127
+ response = yield handleParseFile(baseFilesUrl, folder, config, body, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id, file);
116
128
  break;
117
129
  }
118
130
  (0, util_1.log)(`Returning response from process file action ${JSON.stringify(response, null, 2)}`, baseConfig.logger);
@@ -15,28 +15,17 @@ function handle(config) {
15
15
  ];
16
16
  }
17
17
  if (config.customFileFormat) {
18
- if (config.customFileFormat.stringsExport) {
19
- modules['custom-file-format'] = [
20
- {
21
- key: config.identifier + '-ff',
22
- type: config.customFileFormat.type,
23
- stringsExport: true,
24
- extensions: config.customFileFormat.extensions,
25
- url: '/process',
26
- },
27
- ];
28
- }
29
- else {
30
- modules['custom-file-format'] = [
31
- {
32
- key: config.identifier + '-ff',
33
- type: config.customFileFormat.type,
34
- multilingual: !!config.customFileFormat.multilingual,
35
- signaturePatterns: config.customFileFormat.signaturePatterns,
36
- url: '/process',
37
- },
38
- ];
39
- }
18
+ modules['custom-file-format'] = [
19
+ {
20
+ key: config.identifier + '-ff',
21
+ type: config.customFileFormat.type,
22
+ stringsExport: !!config.customFileFormat.stringsExport,
23
+ multilingual: !!config.customFileFormat.multilingual,
24
+ extensions: config.customFileFormat.extensions,
25
+ signaturePatterns: config.customFileFormat.signaturePatterns,
26
+ url: '/process',
27
+ },
28
+ ];
40
29
  }
41
30
  if (config.customMT) {
42
31
  modules['custom-mt'] = [
@@ -401,11 +401,15 @@ export interface CustomFileFormatLogic {
401
401
  /**
402
402
  * Used for initial source file upload, source file update, and translation upload
403
403
  */
404
- parseFile: (fileContent: string | object, req: Omit<ProcessFileRequest, 'jobType' | 'file'>, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<ParseFileResponse>;
404
+ parseFile?: (fileContent: string | object, req: Omit<ProcessFileRequest, 'jobType' | 'file'>, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<ParseFileResponse>;
405
405
  /**
406
406
  * Used for translation download
407
407
  */
408
- buildFile: (fileContent: string | object, req: Omit<ProcessFileRequest, 'jobType'>, strings: ProcessFileString[], client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>;
408
+ buildFile?: (fileContent: string | object, req: Omit<ProcessFileRequest, 'jobType' | 'file'>, strings: ProcessFileString[], client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>;
409
+ /**
410
+ * Used for strings export
411
+ */
412
+ exportStrings?: (req: Omit<ProcessFileRequest, 'jobType'>, strings: ProcessFileString[], client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>;
409
413
  }
410
414
  export interface SignaturePatterns {
411
415
  fileName?: string;
@@ -423,6 +427,8 @@ export interface ProcessFileRecord {
423
427
  content?: string;
424
428
  contentUrl?: string;
425
429
  path?: string;
430
+ id?: number;
431
+ name?: string;
426
432
  }
427
433
  export declare enum ProcessFileJobType {
428
434
  PARSE_FILE = "parse-file",
@@ -180,7 +180,7 @@ function checkSubscription(config, token, organization, accountType) {
180
180
  //default 2 weeks
181
181
  const defaultSubscriptionPlan = 14;
182
182
  let days;
183
- if (organization) {
183
+ if (accountType === models_1.AccountType.ENTERPRISE) {
184
184
  days = ((_b = config.pricing) === null || _b === void 0 ? void 0 : _b.trialEnterprise) || ((_c = config.pricing) === null || _c === void 0 ? void 0 : _c.trial) || defaultSubscriptionPlan;
185
185
  }
186
186
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.16.3",
3
+ "version": "0.16.5",
4
4
  "description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",