@crowdin/app-project-module 0.28.11 → 0.29.1

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 (41) hide show
  1. package/out/handlers/crowdin-file-progress.js +1 -1
  2. package/out/handlers/crowdin-update.js +7 -2
  3. package/out/handlers/crowdin-webhook.js +4 -3
  4. package/out/handlers/integration-update.js +5 -0
  5. package/out/handlers/integration-webhook.js +2 -1
  6. package/out/handlers/main.js +1 -0
  7. package/out/handlers/manifest.js +4 -0
  8. package/out/handlers/settings-save.js +11 -0
  9. package/out/handlers/settings.d.ts +4 -0
  10. package/out/handlers/settings.js +22 -0
  11. package/out/handlers/sync-settings-save.d.ts +2 -2
  12. package/out/handlers/sync-settings-save.js +8 -11
  13. package/out/handlers/sync-settings.js +1 -1
  14. package/out/index.js +18 -2
  15. package/out/middlewares/crowdin-client.d.ts +2 -1
  16. package/out/middlewares/crowdin-client.js +7 -1
  17. package/out/models/index.d.ts +57 -4
  18. package/out/models/index.js +14 -1
  19. package/out/static/js/dependent.js +1 -2
  20. package/out/storage/index.d.ts +8 -5
  21. package/out/storage/mysql.d.ts +4 -1
  22. package/out/storage/mysql.js +35 -1
  23. package/out/storage/postgre.d.ts +4 -1
  24. package/out/storage/postgre.js +35 -1
  25. package/out/storage/sqlite.d.ts +4 -1
  26. package/out/storage/sqlite.js +33 -1
  27. package/out/util/api/api.d.ts +6 -0
  28. package/out/util/api/api.js +444 -0
  29. package/out/util/api/base.d.ts +7 -0
  30. package/out/util/api/base.js +8 -0
  31. package/out/util/api/components.d.ts +227 -0
  32. package/out/util/api/components.js +228 -0
  33. package/out/util/cron.d.ts +2 -1
  34. package/out/util/cron.js +76 -9
  35. package/out/util/defaults.js +26 -3
  36. package/out/util/file-snapshot.d.ts +7 -0
  37. package/out/util/file-snapshot.js +144 -0
  38. package/out/util/webhooks.d.ts +4 -3
  39. package/out/util/webhooks.js +29 -5
  40. package/out/views/main.handlebars +140 -8
  41. package/package.json +5 -1
@@ -99,6 +99,16 @@ class PostgreStorage {
99
99
  data varchar
100
100
  )
101
101
  `);
102
+ yield client.query(`
103
+ create table if not exists files_snapshot
104
+ (
105
+ id serial primary key,
106
+ integration_id varchar not null,
107
+ crowdin_id varchar not null,
108
+ files varchar,
109
+ provider varchar not null
110
+ )
111
+ `);
102
112
  });
103
113
  }
104
114
  saveCrowdinCredentials(credentials) {
@@ -159,6 +169,7 @@ class PostgreStorage {
159
169
  yield client.query('DELETE FROM crowdin_credentials where id = $1', [id]);
160
170
  yield client.query('DELETE FROM integration_credentials where crowdin_id = $1', [id]);
161
171
  yield client.query('DELETE FROM sync_settings WHERE crowdin_id = $1', [id]);
172
+ yield client.query('DELETE FROM files_snapshot WHERE crowdin_id = $1', [id]);
162
173
  }));
163
174
  });
164
175
  }
@@ -208,6 +219,7 @@ class PostgreStorage {
208
219
  yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
209
220
  yield client.query('DELETE FROM integration_credentials where id = $1', [id]);
210
221
  yield client.query('DELETE FROM sync_settings where integration_id = $1', [id]);
222
+ yield client.query('DELETE FROM files_snapshot where integration_id = $1', [id]);
211
223
  }));
212
224
  });
213
225
  }
@@ -217,6 +229,7 @@ class PostgreStorage {
217
229
  yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
218
230
  yield client.query('DELETE FROM integration_credentials where crowdin_id = $1', [crowdinId]);
219
231
  yield client.query('DELETE FROM sync_settings where crowdin_id = $1', [crowdinId]);
232
+ yield client.query('DELETE FROM files_snapshot where crowdin_id = $1', [crowdinId]);
220
233
  }));
221
234
  });
222
235
  }
@@ -283,7 +296,28 @@ class PostgreStorage {
283
296
  return __awaiter(this, void 0, void 0, function* () {
284
297
  yield this.dbPromise;
285
298
  return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
286
- const res = yield client.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type FROM sync_settings WHERE integration_id = $1 AND crowdin_id = $2 AND type = $3 AND provider = $4', [integrationId, crowdinId, type, provider]);
299
+ const res = yield client.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE integration_id = $1 AND crowdin_id = $2 AND type = $3 AND provider = $4', [integrationId, crowdinId, type, provider]);
300
+ return res === null || res === void 0 ? void 0 : res.rows[0];
301
+ }));
302
+ });
303
+ }
304
+ saveFilesSnapshot(files, integrationId, crowdinId, provider) {
305
+ return __awaiter(this, void 0, void 0, function* () {
306
+ yield this.dbPromise;
307
+ yield this.executeQuery((client) => client.query('INSERT INTO files_snapshot(integration_id, crowdin_id, files, provider) VALUES ($1, $2, $3, $4)', [files, integrationId, crowdinId, provider]));
308
+ });
309
+ }
310
+ updateFilesSnapshot(files, integrationId, crowdinId, provider) {
311
+ return __awaiter(this, void 0, void 0, function* () {
312
+ yield this.dbPromise;
313
+ yield this.executeQuery((client) => client.query('UPDATE files_snapshot SET files = $1 WHERE integration_id = $2 AND crowdin_id = $3 AND provider = $4', [files, integrationId, crowdinId, provider]));
314
+ });
315
+ }
316
+ getFilesSnapshot(integrationId, crowdinId, provider) {
317
+ return __awaiter(this, void 0, void 0, function* () {
318
+ yield this.dbPromise;
319
+ return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
320
+ const res = yield client.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId" FROM files_snapshot WHERE integration_id = $1 AND crowdin_id = $2 AND provider = $3', [integrationId, crowdinId, provider]);
287
321
  return res === null || res === void 0 ? void 0 : res.rows[0];
288
322
  }));
289
323
  });
@@ -1,5 +1,5 @@
1
1
  import { Storage } from '.';
2
- import { CrowdinCredentials, IntegrationCredentials, IntegrationSyncSettings } from '../models';
2
+ import { CrowdinCredentials, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings } from '../models';
3
3
  export interface SQLiteStorageConfig {
4
4
  dbFolder: string;
5
5
  }
@@ -37,4 +37,7 @@ export declare class SQLiteStorage implements Storage {
37
37
  saveSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: string): Promise<void>;
38
38
  updateSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: string): Promise<void>;
39
39
  getSyncSettings(integrationId: string, crowdinId: string, type: string, provider: string): Promise<IntegrationSyncSettings | undefined>;
40
+ saveFilesSnapshot(files: any, integrationId: string, crowdinId: string, provider: string): Promise<void>;
41
+ updateFilesSnapshot(files: any, integrationId: string, crowdinId: string, provider: string): Promise<void>;
42
+ getFilesSnapshot(integrationId: string, crowdinId: string, provider: string): Promise<IntegrationFilesSnapshot | undefined>;
40
43
  }
@@ -169,6 +169,16 @@ class SQLiteStorage {
169
169
  id varchar not null primary key,
170
170
  data varchar null
171
171
  );
172
+ `, []);
173
+ yield this._run(`
174
+ create table if not exists files_snapshot
175
+ (
176
+ id integer not null primary key autoincrement,
177
+ integration_id varchar not null,
178
+ crowdin_id varchar not null,
179
+ files varchar null,
180
+ provider varchar not null
181
+ );
172
182
  `, []);
173
183
  this._res && this._res();
174
184
  // TODO: temporary code
@@ -222,6 +232,7 @@ class SQLiteStorage {
222
232
  yield this.run('DELETE FROM crowdin_credentials where id = ?', [id]);
223
233
  yield this.run('DELETE FROM integration_credentials where crowdin_id = ?', [id]);
224
234
  yield this.run('DELETE FROM sync_settings WHERE crowdin_id = ?', [id]);
235
+ yield this.run('DELETE FROM files_snapshot WHERE crowdin_id = ?', [id]);
225
236
  });
226
237
  }
227
238
  saveIntegrationCredentials(id, credentials, crowdinId) {
@@ -252,12 +263,14 @@ class SQLiteStorage {
252
263
  return __awaiter(this, void 0, void 0, function* () {
253
264
  yield this.run('DELETE FROM integration_credentials where id = ?', [id]);
254
265
  yield this.run('DELETE FROM sync_settings where integration_id = ?', [id]);
266
+ yield this.run('DELETE FROM files_snapshot where integration_id = ?', [id]);
255
267
  });
256
268
  }
257
269
  deleteAllIntegrationCredentials(crowdinId) {
258
270
  return __awaiter(this, void 0, void 0, function* () {
259
271
  yield this.run('DELETE FROM integration_credentials where crowdin_id = ?', [crowdinId]);
260
272
  yield this.run('DELETE FROM sync_settings where crowdin_id = ?', [crowdinId]);
273
+ yield this.run('DELETE FROM files_snapshot where crowdin_id = ?', [crowdinId]);
261
274
  });
262
275
  }
263
276
  saveMetadata(id, metadata) {
@@ -298,7 +311,26 @@ class SQLiteStorage {
298
311
  }
299
312
  getSyncSettings(integrationId, crowdinId, type, provider) {
300
313
  return __awaiter(this, void 0, void 0, function* () {
301
- const row = yield this.get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type FROM sync_settings WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?', [integrationId, crowdinId, type, provider]);
314
+ const row = yield this.get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, provider FROM sync_settings WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?', [integrationId, crowdinId, type, provider]);
315
+ if (row) {
316
+ return row;
317
+ }
318
+ });
319
+ }
320
+ saveFilesSnapshot(files, integrationId, crowdinId, provider) {
321
+ return this.run('INSERT INTO files_snapshot(files, integration_id, crowdin_id, provider) VALUES (?, ?, ?, ?)', [
322
+ files,
323
+ integrationId,
324
+ crowdinId,
325
+ provider,
326
+ ]);
327
+ }
328
+ updateFilesSnapshot(files, integrationId, crowdinId, provider) {
329
+ return this.run('UPDATE files_snapshot SET files = ? WHERE integration_id = ? AND crowdin_id = ? AND provider = ? ', [files, integrationId, crowdinId, provider]);
330
+ }
331
+ getFilesSnapshot(integrationId, crowdinId, provider) {
332
+ return __awaiter(this, void 0, void 0, function* () {
333
+ const row = yield this.get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, provider FROM files_snapshot WHERE integration_id = ? AND crowdin_id = ? AND provider = ?', [integrationId, crowdinId, provider]);
302
334
  if (row) {
303
335
  return row;
304
336
  }
@@ -0,0 +1,6 @@
1
+ import { ApiEndpoints, ApiModule, Config, CrowdinClientRequest, CrowdinContextInfo } from '../../models';
2
+ import { Express } from 'express';
3
+ export declare function getApiManifest(config: Config, apiModule: ApiModule): ApiEndpoints[];
4
+ export declare function updateCrowdinContext(req: CrowdinClientRequest, context: CrowdinContextInfo): CrowdinContextInfo;
5
+ export declare function addDefaultApiEndpoints(app: Express, config: Config): void;
6
+ export declare function addSwagerApiDocumentation(app: Express, config: Config): void;
@@ -0,0 +1,444 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addSwagerApiDocumentation = exports.addDefaultApiEndpoints = exports.updateCrowdinContext = exports.getApiManifest = void 0;
7
+ const models_1 = require("../../models");
8
+ const redoc_express_1 = __importDefault(require("redoc-express"));
9
+ const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
10
+ const json_response_1 = __importDefault(require("../../middlewares/json-response"));
11
+ const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
12
+ const integration_credentials_1 = __importDefault(require("../../middlewares/integration-credentials"));
13
+ const crowdin_files_1 = __importDefault(require("../../handlers/crowdin-files"));
14
+ const integration_data_1 = __importDefault(require("../../handlers/integration-data"));
15
+ const crowdin_file_progress_1 = __importDefault(require("../../handlers/crowdin-file-progress"));
16
+ const crowdin_update_1 = __importDefault(require("../../handlers/crowdin-update"));
17
+ const sync_settings_1 = __importDefault(require("../../handlers/sync-settings"));
18
+ const sync_settings_save_1 = __importDefault(require("../../handlers/sync-settings-save"));
19
+ const settings_save_1 = __importDefault(require("../../handlers/settings-save"));
20
+ const settings_1 = __importDefault(require("../../handlers/settings"));
21
+ const integration_update_1 = __importDefault(require("../../handlers/integration-update"));
22
+ const path_1 = __importDefault(require("path"));
23
+ const integration_login_1 = __importDefault(require("../../handlers/integration-login"));
24
+ function getApiManifest(config, apiModule) {
25
+ const apiModuleManifest = [];
26
+ if (apiModule.endpoints) {
27
+ const userEndpoints = getUsersApiManifest(apiModule.endpoints);
28
+ apiModuleManifest.push(...userEndpoints);
29
+ }
30
+ if (apiModule.default) {
31
+ const defaultEndpoints = getDefaultApiEndpointsManifest(config);
32
+ apiModuleManifest.push(...defaultEndpoints);
33
+ }
34
+ return apiModuleManifest;
35
+ }
36
+ exports.getApiManifest = getApiManifest;
37
+ function generateModuleKey(moduleName) {
38
+ return moduleName.toLowerCase().split(' ').join('-') + '-api';
39
+ }
40
+ function getUsersApiManifest(endpoints) {
41
+ const apiModuleManifest = [];
42
+ for (const endpoint of endpoints) {
43
+ apiModuleManifest.push(Object.assign({ key: generateModuleKey(endpoint.name), name: endpoint.name, url: endpoint.url, method: endpoint.method, description: endpoint.description }, (endpoint.documentationUrl ? { documentationUrl: endpoint.documentationUrl } : {})));
44
+ }
45
+ return apiModuleManifest;
46
+ }
47
+ function getDefaultApiEndpointsManifest(config) {
48
+ const apiModuleManifest = [];
49
+ if (config.projectIntegration) {
50
+ apiModuleManifest.push({
51
+ key: 'crowdin-files-api',
52
+ name: 'Get Crowdin Files',
53
+ url: '/crowdin-files',
54
+ method: models_1.RequestMethods.GET,
55
+ description: 'Get a list of synced files',
56
+ documentationUrl: '/api-docs#tag/Files/operation/crowdin.files',
57
+ }, {
58
+ key: 'crowdin-files-api',
59
+ name: 'File Translation Progress',
60
+ url: '/file-progress',
61
+ method: models_1.RequestMethods.GET,
62
+ description: 'Get file translation progress',
63
+ documentationUrl: '/api-docs#tag/Files/operation/file.progress',
64
+ }, {
65
+ key: 'integration-files-api',
66
+ name: 'Get Integration Files',
67
+ url: '/integration-files',
68
+ method: models_1.RequestMethods.GET,
69
+ description: 'Get integration data',
70
+ documentationUrl: '/api-docs#tag/Files/operation/integration.files',
71
+ }, {
72
+ key: 'crowdin-update-api',
73
+ name: 'Update Crowdin',
74
+ url: '/crowdin-update',
75
+ method: models_1.RequestMethods.POST,
76
+ description: 'Update crowdin data',
77
+ documentationUrl: '/api-docs#tag/Files/operation/crowdin.update',
78
+ }, {
79
+ key: 'integration-update-api',
80
+ name: 'Update Integration',
81
+ url: '/integration-update',
82
+ method: models_1.RequestMethods.POST,
83
+ description: 'Update integration data',
84
+ documentationUrl: '/api-docs#tag/Files/operation/integration.update',
85
+ }, {
86
+ key: 'settings-api',
87
+ name: 'Get App Settings',
88
+ url: '/settings',
89
+ method: models_1.RequestMethods.GET,
90
+ documentationUrl: '/api-docs#tag/Settings/operation/settings.get',
91
+ }, {
92
+ key: 'settings-update-api',
93
+ name: 'Update App Settings',
94
+ url: '/settings',
95
+ method: models_1.RequestMethods.POST,
96
+ documentationUrl: '/api-docs#tag/Settings/operation/settings.update',
97
+ }, {
98
+ key: 'sync-settings-api',
99
+ name: 'Get Sync Settings',
100
+ url: '/sync-settings',
101
+ method: models_1.RequestMethods.GET,
102
+ documentationUrl: '/api-docs#tag/Settings/operation/sync.settings.get',
103
+ }, {
104
+ key: 'sync-settings-update-api',
105
+ name: 'Update Sync Settings',
106
+ url: '/sync-settings',
107
+ method: models_1.RequestMethods.POST,
108
+ documentationUrl: '/api-docs#tag/Settings/operation/sync.settings.update',
109
+ });
110
+ if (config.projectIntegration.loginForm) {
111
+ apiModuleManifest.push({
112
+ key: 'login-data',
113
+ name: 'Get Login Fields',
114
+ url: '/login-fields',
115
+ method: models_1.RequestMethods.GET,
116
+ documentationUrl: '/api-docs#tag/Login/operation/integration.fields',
117
+ }, {
118
+ key: 'login',
119
+ name: 'Login',
120
+ url: '/login',
121
+ method: models_1.RequestMethods.POST,
122
+ documentationUrl: '/api-docs#tag/Login/operation/integration.login',
123
+ });
124
+ }
125
+ }
126
+ return apiModuleManifest;
127
+ }
128
+ function updateCrowdinContext(req, context) {
129
+ var _a, _b, _c;
130
+ if ((_a = req.body) === null || _a === void 0 ? void 0 : _a.projectId) {
131
+ if (context.clientId.includes('undefined')) {
132
+ context.clientId = `${context.jwtPayload.domain || context.jwtPayload.context.organization_id}__${(_b = req.body) === null || _b === void 0 ? void 0 : _b.projectId}__${context.jwtPayload.sub}`;
133
+ }
134
+ // eslint-disable-next-line @typescript-eslint/camelcase
135
+ context.jwtPayload.context.project_id = (_c = req.body) === null || _c === void 0 ? void 0 : _c.projectId;
136
+ }
137
+ return context;
138
+ }
139
+ exports.updateCrowdinContext = updateCrowdinContext;
140
+ function getFormFields(fields) {
141
+ const formFields = [];
142
+ for (const field of fields) {
143
+ if (field === null || field === void 0 ? void 0 : field.key) {
144
+ formFields.push({
145
+ name: field.label,
146
+ key: field.key,
147
+ });
148
+ }
149
+ }
150
+ return formFields;
151
+ }
152
+ function addDefaultApiEndpoints(app, config) {
153
+ if (config.projectIntegration) {
154
+ /**
155
+ * @openapi
156
+ * /crowdin-files:
157
+ * get:
158
+ * summary: List Crowdin Files
159
+ * operationId: crowdin.files
160
+ * tags:
161
+ * - 'Files'
162
+ * parameters:
163
+ * - $ref: '#/components/parameters/ProjectId'
164
+ * responses:
165
+ * 200:
166
+ * description: 'Project files list'
167
+ * content:
168
+ * application/json:
169
+ * schema:
170
+ * properties:
171
+ * data:
172
+ * $ref: '#/components/schemas/CrowdinFiles'
173
+ */
174
+ app.get('/crowdin-files', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, config.projectIntegration), (0, crowdin_files_1.default)(config, config.projectIntegration));
175
+ /**
176
+ * @openapi
177
+ * /file-progress:
178
+ * get:
179
+ * tags:
180
+ * - 'Files'
181
+ * summary: 'Get File Progress'
182
+ * operationId: file.progress
183
+ * parameters:
184
+ * - $ref: '#/components/parameters/ProjectId'
185
+ * -
186
+ * name: fileId
187
+ * in: query
188
+ * required: true
189
+ * description: 'Filter branch by name. Get via [List Crowdin Files](#operation/crowdin.files)'
190
+ * schema:
191
+ * type: integer
192
+ * example: 102
193
+ * responses:
194
+ * 200:
195
+ * description: 'File translation progress'
196
+ * content:
197
+ * application/json:
198
+ * schema:
199
+ * properties:
200
+ * data:
201
+ * $ref: '#/components/schemas/FileProgress'
202
+ */
203
+ app.get('/file-progress', (0, crowdin_client_1.default)(config), (0, crowdin_file_progress_1.default)(config, config.projectIntegration));
204
+ /**
205
+ * @openapi
206
+ * /integration-files:
207
+ * get:
208
+ * summary: 'List Integration Files'
209
+ * operationId: integration.files
210
+ * tags:
211
+ * - 'Files'
212
+ * parameters:
213
+ * - $ref: '#/components/parameters/ProjectId'
214
+ * responses:
215
+ * 200:
216
+ * description: 'Integration files list'
217
+ * content:
218
+ * application/json:
219
+ * schema:
220
+ * properties:
221
+ * data:
222
+ * $ref: '#/components/schemas/IntegrationFiles'
223
+ *
224
+ */
225
+ app.get('/integration-files', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, config.projectIntegration), (0, integration_data_1.default)(config, config.projectIntegration));
226
+ /**
227
+ * @openapi
228
+ * /crowdin-update:
229
+ * post:
230
+ * tags:
231
+ * - 'Files'
232
+ * summary: 'Update Crowdin Files'
233
+ * operationId: crowdin.update
234
+ * requestBody:
235
+ * content:
236
+ * application/json:
237
+ * schema:
238
+ * $ref: '#/components/schemas/UpdateCrowdinFiles'
239
+ * responses:
240
+ * 200:
241
+ * content:
242
+ * application/json:
243
+ * schema:
244
+ * properties:
245
+ * data:
246
+ * $ref: '#/components/schemas/UpdateResponse'
247
+ */
248
+ app.post('/crowdin-update', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, config.projectIntegration), (0, crowdin_update_1.default)(config, config.projectIntegration));
249
+ /**
250
+ * @openapi
251
+ * /integration-update:
252
+ * post:
253
+ * tags:
254
+ * - 'Files'
255
+ * summary: 'Update Integration Files'
256
+ * operationId: integration.update
257
+ * requestBody:
258
+ * content:
259
+ * application/json:
260
+ * schema:
261
+ * $ref: '#/components/schemas/FileLanguagePair'
262
+ * responses:
263
+ * 200:
264
+ * content:
265
+ * application/json:
266
+ * schema:
267
+ * properties:
268
+ * data:
269
+ * $ref: '#/components/schemas/UpdateResponse'
270
+ */
271
+ app.post('/integration-update', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, config.projectIntegration), (0, integration_update_1.default)(config, config.projectIntegration));
272
+ /**
273
+ * @openapi
274
+ * /settings:
275
+ * get:
276
+ * tags:
277
+ * - 'Settings'
278
+ * summary: 'Get Application Settings'
279
+ * operationId: settings.get
280
+ * parameters:
281
+ * - $ref: '#/components/parameters/ProjectId'
282
+ * responses:
283
+ * 200:
284
+ * description: 'File translation progress'
285
+ * content:
286
+ * application/json:
287
+ * schema:
288
+ * properties:
289
+ * data:
290
+ * $ref: '#/components/schemas/SettingsResponse'
291
+ */
292
+ app.get('/settings', (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, config.projectIntegration), (0, settings_1.default)(config));
293
+ /**
294
+ * @openapi
295
+ * /settings:
296
+ * post:
297
+ * tags:
298
+ * - 'Settings'
299
+ * summary: 'Update Application Settings'
300
+ * operationId: settings.update
301
+ * requestBody:
302
+ * content:
303
+ * application/json:
304
+ * schema:
305
+ * $ref: '#/components/schemas/UpdateSettingsData'
306
+ * responses:
307
+ * 204:
308
+ * description: 'Application Settings was successfully update'
309
+ */
310
+ app.post('/settings', (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, config.projectIntegration), (0, settings_save_1.default)(config, config.projectIntegration));
311
+ /**
312
+ * @openapi
313
+ * /sync-settings:
314
+ * get:
315
+ * tags:
316
+ * - 'Settings'
317
+ * summary: 'Get Sync Settings'
318
+ * operationId: sync.settings.get
319
+ * parameters:
320
+ * - $ref: '#/components/parameters/ProjectId'
321
+ * - name: provider
322
+ * in: query
323
+ * required: true
324
+ * schema:
325
+ * type: string
326
+ * enum:
327
+ * - crowdin
328
+ * - integration
329
+ * responses:
330
+ * 200:
331
+ * description: 'Application Sync Settings'
332
+ * content:
333
+ * application/json:
334
+ * schema:
335
+ * properties:
336
+ * data:
337
+ * oneOf:
338
+ * - { $ref: '#/components/schemas/CrowdinSyncSettingsResponse' }
339
+ * - { $ref: '#/components/schemas/IntegrationSyncSettingsResponse' }
340
+ */
341
+ app.get('/sync-settings', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, config.projectIntegration), (0, sync_settings_1.default)(config));
342
+ /**
343
+ * @openapi
344
+ * /sync-settings:
345
+ * post:
346
+ * tags:
347
+ * - 'Settings'
348
+ * summary: 'Update Sync Settings'
349
+ * operationId: sync.settings.update
350
+ * requestBody:
351
+ * content:
352
+ * application/json:
353
+ * schema:
354
+ * $ref: '#/components/schemas/UpdateSyncSettingsData'
355
+ * responses:
356
+ * 204:
357
+ * description: 'Application Sync Settings was successfully update'
358
+ */
359
+ app.post('/sync-settings', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, config.projectIntegration), (0, sync_settings_save_1.default)(config, config.projectIntegration));
360
+ if (config.projectIntegration.loginForm) {
361
+ /**
362
+ * @openapi
363
+ * /login-fields:
364
+ * get:
365
+ * tags:
366
+ * - 'Login'
367
+ * summary: 'Integration Login Form Fields'
368
+ * operationId: integration.fields
369
+ * responses:
370
+ * 200:
371
+ * description: 'File translation progress'
372
+ * content:
373
+ * application/json:
374
+ * schema:
375
+ * properties:
376
+ * data:
377
+ * $ref: '#/components/schemas/LoginFieldsResponse'
378
+ */
379
+ app.get('/login-fields', json_response_1.default, (0, crowdin_client_1.default)(config), (req, res) => {
380
+ var _a;
381
+ let fields = [];
382
+ if ((_a = config.projectIntegration) === null || _a === void 0 ? void 0 : _a.loginForm.fields) {
383
+ fields = getFormFields(config === null || config === void 0 ? void 0 : config.projectIntegration.loginForm.fields);
384
+ }
385
+ res.send({ fields });
386
+ });
387
+ /**
388
+ * @openapi
389
+ * /login:
390
+ * post:
391
+ * tags:
392
+ * - 'Login'
393
+ * summary: 'Integration Login'
394
+ * operationId: integration.login
395
+ * requestBody:
396
+ * content:
397
+ * application/json:
398
+ * schema:
399
+ * $ref: '#/components/schemas/Login'
400
+ * responses:
401
+ * 204:
402
+ * description: 'Login successful'
403
+ */
404
+ app.post('/login', (0, crowdin_client_1.default)(config, false, false), (0, integration_login_1.default)(config, config.projectIntegration));
405
+ }
406
+ }
407
+ }
408
+ exports.addDefaultApiEndpoints = addDefaultApiEndpoints;
409
+ function addSwagerApiDocumentation(app, config) {
410
+ var _a, _b;
411
+ const options = {
412
+ swaggerDefinition: {
413
+ openapi: '3.0.0',
414
+ info: {
415
+ title: `${config.name} Application API`,
416
+ version: '1.0.0',
417
+ 'x-logo': {
418
+ url: 'https://support.crowdin.com/assets/crowdin-logo.svg',
419
+ },
420
+ },
421
+ servers: [
422
+ {
423
+ url: `{protocol}//{host}/api/v2/applications/${config.identifier}/api`,
424
+ },
425
+ ],
426
+ },
427
+ apis: [path_1.default.resolve(__dirname, './base.js'), path_1.default.resolve(__dirname, './components.js'), __filename],
428
+ };
429
+ if ((_a = config.api) === null || _a === void 0 ? void 0 : _a.docFile) {
430
+ options.apis.push(config.api.docFile);
431
+ }
432
+ const swaggerSpec = (0, swagger_jsdoc_1.default)(options);
433
+ // remove Login info from doc
434
+ if (!((_b = config.projectIntegration) === null || _b === void 0 ? void 0 : _b.loginForm)) {
435
+ delete swaggerSpec.paths['/login'];
436
+ delete swaggerSpec.paths['/login-fields'];
437
+ delete swaggerSpec.components.schemas['Login'];
438
+ delete swaggerSpec.components.schemas['LoginData'];
439
+ swaggerSpec.tags = swaggerSpec.tags.filter((tag) => tag.name !== 'Login');
440
+ }
441
+ app.get('/api-docs/swagger.json', (req, res) => res.send(swaggerSpec));
442
+ app.use('/api-docs', (0, redoc_express_1.default)({ title: '', specUrl: '/api-docs/swagger.json' }));
443
+ }
444
+ exports.addSwagerApiDocumentation = addSwagerApiDocumentation;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @openapi
3
+ * tags:
4
+ * - name: 'Files'
5
+ * - name: 'Settings'
6
+ * - name: 'Login'
7
+ */
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * @openapi
4
+ * tags:
5
+ * - name: 'Files'
6
+ * - name: 'Settings'
7
+ * - name: 'Login'
8
+ */