@crowdin/app-project-module 0.45.0 → 0.46.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 (29) hide show
  1. package/out/app-test/crowdin-responses/mock-get-project.json +202 -0
  2. package/out/app-test/crowdin-responses/mock-list-supported-languages.json +7368 -0
  3. package/out/app-test/index.d.ts +6 -0
  4. package/out/app-test/index.js +13 -0
  5. package/out/app-test/integration/get-integration-files.d.ts +6 -0
  6. package/out/app-test/integration/get-integration-files.js +70 -0
  7. package/out/app-test/integration/index.d.ts +15 -0
  8. package/out/app-test/integration/index.js +73 -0
  9. package/out/app-test/integration/mocks/crowdin-storage.d.ts +35 -0
  10. package/out/app-test/integration/mocks/crowdin-storage.js +47 -0
  11. package/out/app-test/integration/mocks/mock-axios.d.ts +1 -0
  12. package/out/app-test/integration/mocks/mock-axios.js +18 -0
  13. package/out/app-test/integration/mocks/mock-crowdin-api-client.d.ts +1 -0
  14. package/out/app-test/integration/mocks/mock-crowdin-api-client.js +132 -0
  15. package/out/app-test/integration/types.d.ts +41 -0
  16. package/out/app-test/integration/types.js +2 -0
  17. package/out/app-test/integration/update-crowdin.d.ts +6 -0
  18. package/out/app-test/integration/update-crowdin.js +137 -0
  19. package/out/app-test/integration/update-integration.d.ts +8 -0
  20. package/out/app-test/integration/update-integration.js +78 -0
  21. package/out/app-test/types.d.ts +4 -0
  22. package/out/app-test/types.js +2 -0
  23. package/out/app-test/util/index.d.ts +1 -0
  24. package/out/app-test/util/index.js +24 -0
  25. package/out/modules/integration/util/job.js +1 -0
  26. package/out/modules/manifest.js +21 -60
  27. package/out/types.d.ts +1 -1
  28. package/out/views/main.handlebars +2 -2
  29. package/package.json +1 -1
@@ -0,0 +1,78 @@
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.updateIntegrationTest = exports.getUpdateIntegrationRequest = void 0;
16
+ const globals_1 = require("@jest/globals");
17
+ const crowdin_api_client_1 = __importDefault(require("@crowdin/crowdin-api-client"));
18
+ const types_1 = require("../../modules/integration/util/types");
19
+ const index_1 = require("./index");
20
+ const crowdin_storage_1 = require("./mocks/crowdin-storage");
21
+ const util_1 = require("../util");
22
+ const getUpdateIntegrationRequest = () => {
23
+ const request = {};
24
+ index_1.mockFiles.forEach((file) => {
25
+ request[file.id] = ['es'];
26
+ });
27
+ return request;
28
+ };
29
+ exports.getUpdateIntegrationRequest = getUpdateIntegrationRequest;
30
+ const updateIntegrationTest = ({ appConfig, integrationTestConfig, }) => __awaiter(void 0, void 0, void 0, function* () {
31
+ if (!appConfig.projectIntegration) {
32
+ throw new Error('The app configuration is missing the projectIntegration module.');
33
+ }
34
+ const { updateIntegration, appSettings, integrationCredentials } = integrationTestConfig;
35
+ const client = new crowdin_api_client_1.default({ token: 'fakeToken' });
36
+ const updateProgressMock = jest.fn(() => __awaiter(void 0, void 0, void 0, function* () {
37
+ return { isCanceled: false };
38
+ }));
39
+ const request = (0, exports.getUpdateIntegrationRequest)();
40
+ const result = yield (0, util_1.assert)(() => {
41
+ var _a;
42
+ return (_a = appConfig.projectIntegration) === null || _a === void 0 ? void 0 : _a.updateIntegration({
43
+ projectId: index_1.mockProjectId,
44
+ client,
45
+ credentials: integrationCredentials,
46
+ request,
47
+ rootFolder: (0, crowdin_storage_1.getRootFolder)(appConfig),
48
+ appSettings,
49
+ job: {
50
+ get: function getJob() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ return {
53
+ id: 'jobId1',
54
+ integrationId: 'string',
55
+ crowdinId: 'string',
56
+ type: types_1.JobType.UPDATE_TO_INTEGRATION,
57
+ title: 'Sync files to ' + appConfig.name,
58
+ progress: 0,
59
+ status: types_1.JobStatus.CREATED,
60
+ createdAt: 0,
61
+ };
62
+ });
63
+ },
64
+ update: updateProgressMock,
65
+ },
66
+ });
67
+ }, 'Fail to run method updateIntegration()');
68
+ if (!(updateIntegration === null || updateIntegration === void 0 ? void 0 : updateIntegration.updateProgressDisabled)) {
69
+ yield (0, util_1.assert)(() => (0, globals_1.expect)(updateProgressMock.mock.calls.length).toBeGreaterThanOrEqual(Object.keys(request).length), 'The sync progress should be updated at least once for each file in request');
70
+ }
71
+ if (updateIntegration === null || updateIntegration === void 0 ? void 0 : updateIntegration.extraChecks) {
72
+ yield (0, util_1.assert)(
73
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
74
+ // @ts-ignore
75
+ () => updateIntegration.extraChecks({ request, result }), 'ExtraChecks for updateIntegration() fails');
76
+ }
77
+ });
78
+ exports.updateIntegrationTest = updateIntegrationTest;
@@ -0,0 +1,4 @@
1
+ import { IntegrationTestConfig } from './integration/types';
2
+ export interface TestSuiteConfig {
3
+ projectIntegration?: IntegrationTestConfig;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare function assert(matcher: Function, error: string): Promise<unknown>;
@@ -0,0 +1,24 @@
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.assert = void 0;
13
+ function assert(matcher, error) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ try {
16
+ return yield matcher();
17
+ }
18
+ catch (e) {
19
+ e.message = error + '\n\n' + e.message;
20
+ throw e;
21
+ }
22
+ });
23
+ }
24
+ exports.assert = assert;
@@ -29,6 +29,7 @@ function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCall
29
29
  if (res) {
30
30
  res.status(202).send({ jobId: existingJob.id, message: 'Another sync is running' });
31
31
  }
32
+ (0, logger_1.log)(`Unable to run new job '${type}', with title '${title}', already running jobId ${existingJob.id}.`);
32
33
  return;
33
34
  }
34
35
  }
@@ -14,14 +14,9 @@ function handle(config) {
14
14
  const modules = {};
15
15
  if (config.projectIntegration) {
16
16
  modules['project-integrations'] = [
17
- {
18
- key: config.identifier + '-int',
19
- name: config.name,
20
- description: config.description,
21
- logo: (0, util_1.getLogoUrl)(config.projectIntegration, '/integration'),
22
- url: '/',
17
+ Object.assign({ key: config.identifier + '-int', name: config.name, description: config.description, logo: (0, util_1.getLogoUrl)(config.projectIntegration, '/integration'), url: '/' }, (!!config.projectIntegration.environments && {
23
18
  environments: normalizeEnvironments(config.projectIntegration.environments),
24
- },
19
+ })),
25
20
  ];
26
21
  }
27
22
  if (config.customFileFormat) {
@@ -77,14 +72,9 @@ function handle(config) {
77
72
  }
78
73
  if (config.customMT) {
79
74
  modules['custom-mt'] = [
80
- {
81
- key: config.identifier + '-mt',
82
- name: config.name,
83
- logo: (0, util_1.getLogoUrl)(config.customMT, '/mt'),
84
- url: '/translate',
75
+ Object.assign({ key: config.identifier + '-mt', name: config.name, logo: (0, util_1.getLogoUrl)(config.customMT, '/mt'), url: '/translate', withContext: !!config.customMT.withContext }, (!!config.customMT.environments && {
85
76
  environments: normalizeEnvironments(config.customMT.environments),
86
- withContext: !!config.customMT.withContext,
87
- },
77
+ })),
88
78
  ];
89
79
  }
90
80
  if (config.organizationMenu) {
@@ -99,46 +89,30 @@ function handle(config) {
99
89
  }
100
90
  if (config.profileResourcesMenu) {
101
91
  modules['profile-resources-menu'] = [
102
- {
103
- key: config.identifier + '-profile-resources-menu',
104
- name: config.profileResourcesMenu.name || config.name,
105
- url: '/resources/' + (config.profileResourcesMenu.fileName || 'index.html'),
106
- icon: (0, util_1.getLogoUrl)(config.profileResourcesMenu, '/resources'),
92
+ Object.assign({ key: config.identifier + '-profile-resources-menu', name: config.profileResourcesMenu.name || config.name, url: '/resources/' + (config.profileResourcesMenu.fileName || 'index.html'), icon: (0, util_1.getLogoUrl)(config.profileResourcesMenu, '/resources') }, (!!config.profileResourcesMenu.environments && {
107
93
  environments: normalizeEnvironments(config.profileResourcesMenu.environments),
108
- },
94
+ })),
109
95
  ];
110
96
  }
111
97
  if (config.editorRightPanel) {
112
98
  modules['editor-right-panel'] = [
113
- {
114
- key: config.identifier + '-editor-panels',
115
- name: config.editorRightPanel.name || config.name,
116
- url: '/editor-panels/' + (config.editorRightPanel.fileName || 'index.html'),
117
- modes: config.editorRightPanel.modes,
99
+ Object.assign({ key: config.identifier + '-editor-panels', name: config.editorRightPanel.name || config.name, url: '/editor-panels/' + (config.editorRightPanel.fileName || 'index.html'), modes: config.editorRightPanel.modes }, (!!config.editorRightPanel.environments && {
118
100
  environments: normalizeEnvironments(config.editorRightPanel.environments),
119
- },
101
+ })),
120
102
  ];
121
103
  }
122
104
  if (config.editorThemes) {
123
105
  modules['editor-themes'] = [
124
- {
125
- key: config.identifier + '-editor-themes',
126
- name: config.editorThemes.name || config.name,
127
- logo: (0, util_1.getLogoUrl)(config.editorThemes, '/editor-themes'),
128
- styles: config.editorThemes.styles,
129
- modes: config.editorThemes.modes,
106
+ Object.assign({ key: config.identifier + '-editor-themes', name: config.editorThemes.name || config.name, logo: (0, util_1.getLogoUrl)(config.editorThemes, '/editor-themes'), styles: config.editorThemes.styles, modes: config.editorThemes.modes }, (!!config.editorThemes.environments && {
130
107
  environments: normalizeEnvironments(config.editorThemes.environments),
131
- },
108
+ })),
132
109
  ];
133
110
  }
134
111
  if (config.projectMenu) {
135
112
  modules['project-menu'] = [
136
- {
137
- key: config.identifier + '-project-menu',
138
- name: config.projectMenu.name || config.name,
139
- url: '/project-menu/' + (config.projectMenu.fileName || 'index.html'),
113
+ Object.assign({ key: config.identifier + '-project-menu', name: config.projectMenu.name || config.name, url: '/project-menu/' + (config.projectMenu.fileName || 'index.html') }, (!!config.projectMenu.environments && {
140
114
  environments: normalizeEnvironments(config.projectMenu.environments),
141
- },
115
+ })),
142
116
  ];
143
117
  }
144
118
  if (config.projectMenuCrowdsource) {
@@ -152,14 +126,9 @@ function handle(config) {
152
126
  }
153
127
  if (config.projectTools) {
154
128
  modules['project-tools'] = [
155
- {
156
- key: config.identifier + '-tools',
157
- name: config.projectTools.name || config.name,
158
- description: config.description,
159
- logo: (0, util_1.getLogoUrl)(config.projectTools, '/tools'),
160
- url: '/tools/' + (config.projectTools.fileName || 'index.html'),
129
+ Object.assign({ key: config.identifier + '-tools', name: config.projectTools.name || config.name, description: config.description, logo: (0, util_1.getLogoUrl)(config.projectTools, '/tools'), url: '/tools/' + (config.projectTools.fileName || 'index.html') }, (!!config.projectTools.environments && {
161
130
  environments: normalizeEnvironments(config.projectTools.environments),
162
- },
131
+ })),
163
132
  ];
164
133
  }
165
134
  if (config.projectReports) {
@@ -175,30 +144,20 @@ function handle(config) {
175
144
  }
176
145
  if (config.modal) {
177
146
  modules['modal'] = [
178
- {
179
- key: config.identifier + '-modal',
180
- name: config.modal.name || config.name,
181
- url: config.modal.url || '/modal/' + (config.modal.fileName || 'index.html'),
182
- environments: normalizeEnvironments(config.modal.environments),
183
- },
147
+ Object.assign({ key: config.identifier + '-modal', name: config.modal.name || config.name, url: config.modal.url || '/modal/' + (config.modal.fileName || 'index.html') }, (!!config.modal.environments && { environments: normalizeEnvironments(config.modal.environments) })),
184
148
  ];
185
149
  }
186
150
  if (config.contextMenu) {
187
151
  modules['context-menu'] = [
188
- {
189
- key: config.identifier + '-context-menu',
190
- name: config.contextMenu.name || config.name,
191
- description: config.description,
192
- options: Object.assign(Object.assign({ location: config.contextMenu.location, type: config.contextMenu.type }, (config.contextMenu.module
152
+ Object.assign({ key: config.identifier + '-context-menu', name: config.contextMenu.name || config.name, description: config.description, options: Object.assign(Object.assign({ location: config.contextMenu.location, type: config.contextMenu.type }, (config.contextMenu.module
193
153
  ? {
194
154
  module: {
195
155
  [config.contextMenu.module]: modules[config.contextMenu.module][0].key,
196
156
  },
197
157
  }
198
- : {})), { url: '/context/' + (config.contextMenu.fileName || 'index.html') }),
199
- signaturePatterns: config.contextMenu.signaturePatterns,
158
+ : {})), { url: '/context/' + (config.contextMenu.fileName || 'index.html') }), signaturePatterns: config.contextMenu.signaturePatterns }, (!!config.contextMenu.environments && {
200
159
  environments: normalizeEnvironments(config.contextMenu.environments),
201
- },
160
+ })),
202
161
  ];
203
162
  }
204
163
  if (config.api) {
@@ -207,7 +166,9 @@ function handle(config) {
207
166
  if (config.customSpellchecker) {
208
167
  const uiModule = config.customSpellchecker.settingsUiModule;
209
168
  modules['custom-spellchecker'] = [
210
- Object.assign({ key: config.identifier + '-spellchecker', name: config.customSpellchecker.name || config.name, description: config.customSpellchecker.description || config.description, listSupportedLanguagesUrl: '/languages', checkSpellingUrl: '/spellcheck', environments: normalizeEnvironments(config.customSpellchecker.environments) }, (uiModule ? { url: '/settings/' + (uiModule.fileName || 'index.html') } : {})),
169
+ Object.assign(Object.assign({ key: config.identifier + '-spellchecker', name: config.customSpellchecker.name || config.name, description: config.customSpellchecker.description || config.description, listSupportedLanguagesUrl: '/languages', checkSpellingUrl: '/spellcheck' }, (!!config.customSpellchecker.environments && {
170
+ environments: normalizeEnvironments(config.customSpellchecker.environments),
171
+ })), (uiModule ? { url: '/settings/' + (uiModule.fileName || 'index.html') } : {})),
211
172
  ];
212
173
  }
213
174
  const events = {
package/out/types.d.ts CHANGED
@@ -173,7 +173,7 @@ export interface ClientConfig extends ImagePath {
173
173
  customSpellchecker?: CustomSpellcheckerModule;
174
174
  }
175
175
  export interface Environments {
176
- environments: Environment | Environment[];
176
+ environments?: Environment | Environment[];
177
177
  }
178
178
  type Environment = 'crowdin' | 'crowdin-enterprise';
179
179
  export type Config = ClientConfig & {
@@ -446,9 +446,9 @@
446
446
  return;
447
447
  }
448
448
 
449
- const selectedIds = selection.map(({id}) => id);
449
+ const selectedIds = selection.map(({id}) => id.toString());
450
450
  tree.forEach((node) => {
451
- selectedIds.includes(node.parent_id) && selectedIds.push(node.id);
451
+ selectedIds.includes(node.parent_id.toString()) && selectedIds.push(node.id.toString());
452
452
  });
453
453
  appIntegrationFiles.setSelected(selectedIds);
454
454
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.45.0",
3
+ "version": "0.46.0",
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",