@crowdin/app-project-module 1.7.1 → 1.8.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.
@@ -10,6 +10,7 @@ exports.registerFilePreExport = registerFilePreExport;
10
10
  exports.registerFilePostExport = registerFilePostExport;
11
11
  exports.registerFileTranslationsAlignmentExport = registerFileTranslationsAlignmentExport;
12
12
  const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
13
+ const normalize_module_1 = require("../../util/normalize-module");
13
14
  const custom_file_format_1 = __importDefault(require("./handlers/custom-file-format"));
14
15
  const file_download_1 = __importDefault(require("./handlers/file-download"));
15
16
  const pre_post_process_1 = __importDefault(require("./handlers/pre-post-process"));
@@ -17,97 +18,147 @@ const translations_alignment_1 = __importDefault(require("./handlers/translation
17
18
  const types_1 = require("./types");
18
19
  const defaults_1 = require("./util/defaults");
19
20
  function registerCustomFileFormat({ config, app }) {
21
+ var _a;
20
22
  if (!config.customFileFormat) {
21
23
  return;
22
24
  }
23
- (0, defaults_1.applyFileProcessorsModuleDefaults)(config, config.customFileFormat);
24
- app.post('/file/process', (0, crowdin_client_1.default)({
25
- config,
26
- optional: false,
27
- checkSubscriptionExpiration: true,
28
- moduleKey: config.customFileFormat.key,
29
- }), (0, custom_file_format_1.default)({
30
- baseUrl: config.baseUrl,
31
- folder: config.customFileFormat.filesFolder || config.dbFolder,
32
- config: config.customFileFormat,
33
- fileStore: config.fileStore,
34
- }));
35
- // TEMPORARY CODE: it needs to support old path
36
- app.post('/process', (0, crowdin_client_1.default)({
37
- config,
38
- optional: false,
39
- checkSubscriptionExpiration: true,
40
- }), (0, custom_file_format_1.default)({
41
- baseUrl: config.baseUrl,
42
- folder: config.customFileFormat.filesFolder || config.dbFolder,
43
- config: config.customFileFormat,
44
- fileStore: config.fileStore,
45
- }));
46
- // END TEMPORARY CODE
47
- app.get('/file/download', (0, file_download_1.default)(config, config.customFileFormat, 'custom-file-format'));
25
+ const items = (0, normalize_module_1.normalizeToArray)(config.customFileFormat);
26
+ const isSingle = items.length === 1;
27
+ for (const [index, ff] of items.entries()) {
28
+ const key = (_a = ff.key) !== null && _a !== void 0 ? _a : (0, normalize_module_1.resolveInstanceKey)({ identifier: config.identifier, suffix: 'ff', item: ff, index, isSingle });
29
+ (0, defaults_1.applyFileProcessorsModuleDefaults)(config, ff);
30
+ const processUrl = isSingle ? '/file/process' : `/file/${key}/process`;
31
+ app.post(processUrl, (0, crowdin_client_1.default)({
32
+ config,
33
+ optional: false,
34
+ checkSubscriptionExpiration: true,
35
+ moduleKey: key,
36
+ }), (0, custom_file_format_1.default)({
37
+ baseUrl: config.baseUrl,
38
+ folder: ff.filesFolder || config.dbFolder,
39
+ config: ff,
40
+ fileStore: config.fileStore,
41
+ }));
42
+ app.get(isSingle ? '/file/download' : `/file/${key}/download`, (0, file_download_1.default)(config, ff, 'custom-file-format'));
43
+ }
44
+ if (isSingle) {
45
+ const ff = items[0];
46
+ // TEMPORARY CODE: it needs to support old path
47
+ app.post('/process', (0, crowdin_client_1.default)({
48
+ config,
49
+ optional: false,
50
+ checkSubscriptionExpiration: true,
51
+ }), (0, custom_file_format_1.default)({
52
+ baseUrl: config.baseUrl,
53
+ folder: ff.filesFolder || config.dbFolder,
54
+ config: ff,
55
+ fileStore: config.fileStore,
56
+ }));
57
+ // END TEMPORARY CODE
58
+ }
48
59
  }
49
60
  function registerFilePreImport({ config, app }) {
61
+ var _a;
50
62
  if (!config.filePreImport) {
51
63
  return;
52
64
  }
53
- (0, defaults_1.applyFileProcessorsModuleDefaults)(config, config.filePreImport);
54
- app.post('/pre-import', (0, crowdin_client_1.default)({
55
- config,
56
- optional: false,
57
- checkSubscriptionExpiration: true,
58
- moduleKey: config.filePreImport.key,
59
- }), (0, pre_post_process_1.default)(config, config.filePreImport, types_1.ProcessFileJobType.PRE_IMPORT));
60
- app.get(`/file/download/${types_1.ProcessFileJobType.PRE_IMPORT}`, (0, file_download_1.default)(config, config.filePreImport, types_1.ProcessFileJobType.PRE_IMPORT));
65
+ const items = (0, normalize_module_1.normalizeToArray)(config.filePreImport);
66
+ const isSingle = items.length === 1;
67
+ for (const [index, item] of items.entries()) {
68
+ const key = (_a = item.key) !== null && _a !== void 0 ? _a : (0, normalize_module_1.resolveInstanceKey)({ identifier: config.identifier, suffix: 'pri', item, index, isSingle });
69
+ (0, defaults_1.applyFileProcessorsModuleDefaults)(config, item);
70
+ const processUrl = isSingle ? '/pre-import' : `/pre-import/${key}`;
71
+ app.post(processUrl, (0, crowdin_client_1.default)({
72
+ config,
73
+ optional: false,
74
+ checkSubscriptionExpiration: true,
75
+ moduleKey: key,
76
+ }), (0, pre_post_process_1.default)(config, item, types_1.ProcessFileJobType.PRE_IMPORT));
77
+ }
78
+ // Register download route once — shared across all instances
79
+ app.get(`/file/download/${types_1.ProcessFileJobType.PRE_IMPORT}`, (0, file_download_1.default)(config, items[0], types_1.ProcessFileJobType.PRE_IMPORT));
61
80
  }
62
81
  function registerFilePostImport({ config, app }) {
82
+ var _a;
63
83
  if (!config.filePostImport) {
64
84
  return;
65
85
  }
66
- (0, defaults_1.applyFileProcessorsModuleDefaults)(config, config.filePostImport);
67
- app.post('/post-import', (0, crowdin_client_1.default)({
68
- config,
69
- optional: false,
70
- checkSubscriptionExpiration: true,
71
- moduleKey: config.filePostImport.key,
72
- }), (0, pre_post_process_1.default)(config, config.filePostImport, types_1.ProcessFileJobType.POST_IMPORT));
73
- app.get(`/file/download/${types_1.ProcessFileJobType.POST_IMPORT}`, (0, file_download_1.default)(config, config.filePostImport, types_1.ProcessFileJobType.POST_IMPORT));
86
+ const items = (0, normalize_module_1.normalizeToArray)(config.filePostImport);
87
+ const isSingle = items.length === 1;
88
+ for (const [index, item] of items.entries()) {
89
+ const key = (_a = item.key) !== null && _a !== void 0 ? _a : (0, normalize_module_1.resolveInstanceKey)({ identifier: config.identifier, suffix: 'poi', item, index, isSingle });
90
+ (0, defaults_1.applyFileProcessorsModuleDefaults)(config, item);
91
+ const processUrl = isSingle ? '/post-import' : `/post-import/${key}`;
92
+ app.post(processUrl, (0, crowdin_client_1.default)({
93
+ config,
94
+ optional: false,
95
+ checkSubscriptionExpiration: true,
96
+ moduleKey: key,
97
+ }), (0, pre_post_process_1.default)(config, item, types_1.ProcessFileJobType.POST_IMPORT));
98
+ }
99
+ // Register download route once — shared across all instances
100
+ app.get(`/file/download/${types_1.ProcessFileJobType.POST_IMPORT}`, (0, file_download_1.default)(config, items[0], types_1.ProcessFileJobType.POST_IMPORT));
74
101
  }
75
102
  function registerFilePreExport({ config, app }) {
103
+ var _a;
76
104
  if (!config.filePreExport) {
77
105
  return;
78
106
  }
79
- (0, defaults_1.applyFileProcessorsModuleDefaults)(config, config.filePreExport);
80
- app.post('/pre-export', (0, crowdin_client_1.default)({
81
- config,
82
- optional: false,
83
- checkSubscriptionExpiration: true,
84
- moduleKey: config.filePreExport.key,
85
- }), (0, pre_post_process_1.default)(config, config.filePreExport, types_1.ProcessFileJobType.PRE_EXPORT));
86
- app.get(`/file/download/${types_1.ProcessFileJobType.PRE_EXPORT}`, (0, file_download_1.default)(config, config.filePreExport, types_1.ProcessFileJobType.PRE_EXPORT));
107
+ const items = (0, normalize_module_1.normalizeToArray)(config.filePreExport);
108
+ const isSingle = items.length === 1;
109
+ for (const [index, item] of items.entries()) {
110
+ const key = (_a = item.key) !== null && _a !== void 0 ? _a : (0, normalize_module_1.resolveInstanceKey)({ identifier: config.identifier, suffix: 'pre', item, index, isSingle });
111
+ (0, defaults_1.applyFileProcessorsModuleDefaults)(config, item);
112
+ const processUrl = isSingle ? '/pre-export' : `/pre-export/${key}`;
113
+ app.post(processUrl, (0, crowdin_client_1.default)({
114
+ config,
115
+ optional: false,
116
+ checkSubscriptionExpiration: true,
117
+ moduleKey: key,
118
+ }), (0, pre_post_process_1.default)(config, item, types_1.ProcessFileJobType.PRE_EXPORT));
119
+ }
120
+ // Register download route once — shared across all instances
121
+ app.get(`/file/download/${types_1.ProcessFileJobType.PRE_EXPORT}`, (0, file_download_1.default)(config, items[0], types_1.ProcessFileJobType.PRE_EXPORT));
87
122
  }
88
123
  function registerFilePostExport({ config, app }) {
124
+ var _a;
89
125
  if (!config.filePostExport) {
90
126
  return;
91
127
  }
92
- (0, defaults_1.applyFileProcessorsModuleDefaults)(config, config.filePostExport);
93
- app.post('/post-export', (0, crowdin_client_1.default)({
94
- config,
95
- optional: false,
96
- checkSubscriptionExpiration: true,
97
- moduleKey: config.filePostExport.key,
98
- }), (0, pre_post_process_1.default)(config, config.filePostExport, types_1.ProcessFileJobType.POST_EXPORT));
99
- app.get(`/file/download/${types_1.ProcessFileJobType.POST_EXPORT}`, (0, file_download_1.default)(config, config.filePostExport, types_1.ProcessFileJobType.POST_EXPORT));
128
+ const items = (0, normalize_module_1.normalizeToArray)(config.filePostExport);
129
+ const isSingle = items.length === 1;
130
+ for (const [index, item] of items.entries()) {
131
+ const key = (_a = item.key) !== null && _a !== void 0 ? _a : (0, normalize_module_1.resolveInstanceKey)({ identifier: config.identifier, suffix: 'poe', item, index, isSingle });
132
+ (0, defaults_1.applyFileProcessorsModuleDefaults)(config, item);
133
+ const processUrl = isSingle ? '/post-export' : `/post-export/${key}`;
134
+ app.post(processUrl, (0, crowdin_client_1.default)({
135
+ config,
136
+ optional: false,
137
+ checkSubscriptionExpiration: true,
138
+ moduleKey: key,
139
+ }), (0, pre_post_process_1.default)(config, item, types_1.ProcessFileJobType.POST_EXPORT));
140
+ }
141
+ // Register download route once — shared across all instances
142
+ app.get(`/file/download/${types_1.ProcessFileJobType.POST_EXPORT}`, (0, file_download_1.default)(config, items[0], types_1.ProcessFileJobType.POST_EXPORT));
100
143
  }
101
144
  function registerFileTranslationsAlignmentExport({ config, app }) {
145
+ var _a;
102
146
  if (!config.fileTranslationsAlignmentExport) {
103
147
  return;
104
148
  }
105
- (0, defaults_1.applyFileProcessorsModuleDefaults)(config, config.fileTranslationsAlignmentExport);
106
- app.post('/translations-alignment', (0, crowdin_client_1.default)({
107
- config,
108
- optional: false,
109
- checkSubscriptionExpiration: true,
110
- moduleKey: config.fileTranslationsAlignmentExport.key,
111
- }), (0, translations_alignment_1.default)(config, config.fileTranslationsAlignmentExport, types_1.ProcessFileJobType.TRANSLATIONS_ALIGNMENT));
112
- app.get(`/file/download/${types_1.ProcessFileJobType.POST_EXPORT}`, (0, file_download_1.default)(config, config.fileTranslationsAlignmentExport, types_1.ProcessFileJobType.TRANSLATIONS_ALIGNMENT));
149
+ const items = (0, normalize_module_1.normalizeToArray)(config.fileTranslationsAlignmentExport);
150
+ const isSingle = items.length === 1;
151
+ for (const [index, item] of items.entries()) {
152
+ const key = (_a = item.key) !== null && _a !== void 0 ? _a : (0, normalize_module_1.resolveInstanceKey)({ identifier: config.identifier, suffix: 'ftae', item, index, isSingle });
153
+ (0, defaults_1.applyFileProcessorsModuleDefaults)(config, item);
154
+ const processUrl = isSingle ? '/translations-alignment' : `/translations-alignment/${key}`;
155
+ app.post(processUrl, (0, crowdin_client_1.default)({
156
+ config,
157
+ optional: false,
158
+ checkSubscriptionExpiration: true,
159
+ moduleKey: key,
160
+ }), (0, translations_alignment_1.default)(config, item, types_1.ProcessFileJobType.TRANSLATIONS_ALIGNMENT));
161
+ }
162
+ // Register download route once — shared across all instances
163
+ app.get(`/file/download/${types_1.ProcessFileJobType.POST_EXPORT}`, (0, file_download_1.default)(config, items[0], types_1.ProcessFileJobType.TRANSLATIONS_ALIGNMENT));
113
164
  }