@crowdin/app-project-module 0.54.0 → 0.54.2
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/out/app-test/integration/mocks/crowdin-storage.d.ts +3 -1
- package/out/modules/integration/handlers/integration-webhook.js +2 -2
- package/out/modules/integration/util/webhooks.d.ts +7 -0
- package/out/modules/integration/util/webhooks.js +35 -15
- package/out/static/css/styles.css +9 -0
- package/out/static/js/form.js +2 -2
- package/out/types.d.ts +4 -0
- package/out/util/connection.js +38 -2
- package/package.json +8 -8
|
@@ -24,8 +24,10 @@ export declare const crowdinFiles: {
|
|
|
24
24
|
branchId?: number | undefined;
|
|
25
25
|
directoryId?: number | undefined;
|
|
26
26
|
title?: string | undefined;
|
|
27
|
+
context?: string | undefined;
|
|
27
28
|
type?: SourceFilesModel.FileType | undefined;
|
|
28
|
-
|
|
29
|
+
parserVersion?: number | undefined;
|
|
30
|
+
importOptions?: SourceFilesModel.ImportOptions | undefined;
|
|
29
31
|
exportOptions?: SourceFilesModel.GeneralExportOptions | SourceFilesModel.PropertyExportOptions | undefined;
|
|
30
32
|
attachLabelIds?: number[] | undefined;
|
|
31
33
|
excludedTargetLanguages?: string[] | undefined;
|
|
@@ -25,11 +25,11 @@ function handle(config, integration) {
|
|
|
25
25
|
webhookUrlParam,
|
|
26
26
|
provider: types_1.Provider.INTEGRATION,
|
|
27
27
|
});
|
|
28
|
-
if (!webhookData.crowdinClient) {
|
|
28
|
+
if (!(webhookData === null || webhookData === void 0 ? void 0 : webhookData.crowdinClient)) {
|
|
29
29
|
(0, logger_1.temporaryErrorDebug)('Access denied: integration-webhooks !webhookData.crowdinClient', req);
|
|
30
30
|
return res.status(403).send({ error: 'Access denied' });
|
|
31
31
|
}
|
|
32
|
-
if (!webhookData.syncSettings) {
|
|
32
|
+
if (!(webhookData === null || webhookData === void 0 ? void 0 : webhookData.syncSettings)) {
|
|
33
33
|
return res.status(200).send({ message: 'Sync is not configured' });
|
|
34
34
|
}
|
|
35
35
|
yield (0, webhooks_1.updateCrowdinFromWebhookRequest)({ integration, webhookData, req: [req] });
|
|
@@ -29,6 +29,13 @@ export declare function prepareWebhookData({ config, integration, provider, webh
|
|
|
29
29
|
webhookUrlParam: string;
|
|
30
30
|
provider: Provider;
|
|
31
31
|
}): Promise<{
|
|
32
|
+
projectId: number;
|
|
33
|
+
crowdinClient: null;
|
|
34
|
+
rootFolder: undefined;
|
|
35
|
+
appSettings: AppSettings;
|
|
36
|
+
syncSettings: null;
|
|
37
|
+
preparedIntegrationCredentials: null;
|
|
38
|
+
} | {
|
|
32
39
|
projectId: number;
|
|
33
40
|
crowdinClient: {
|
|
34
41
|
client: Crowdin;
|
|
@@ -255,11 +255,16 @@ function prepareWebhookData({ config, integration, provider, webhookUrlParam, })
|
|
|
255
255
|
return __awaiter(this, void 0, void 0, function* () {
|
|
256
256
|
let rootFolder = undefined;
|
|
257
257
|
let syncSettings = null;
|
|
258
|
+
let crowdinClient = null;
|
|
259
|
+
let preparedIntegrationCredentials = null;
|
|
258
260
|
let appSettings = {};
|
|
259
261
|
const { projectId, crowdinId, clientId } = decodedUrlParam(config, webhookUrlParam);
|
|
260
262
|
const crowdinCredentials = yield (0, storage_1.getStorage)().getCrowdinCredentials(crowdinId);
|
|
261
263
|
const integrationCredentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(clientId);
|
|
262
264
|
const integrationConfig = yield (0, storage_1.getStorage)().getIntegrationConfig(clientId);
|
|
265
|
+
if (!crowdinCredentials) {
|
|
266
|
+
return { projectId, crowdinClient, rootFolder, appSettings, syncSettings, preparedIntegrationCredentials };
|
|
267
|
+
}
|
|
263
268
|
const context = {
|
|
264
269
|
jwtPayload: {
|
|
265
270
|
context: {
|
|
@@ -272,18 +277,27 @@ function prepareWebhookData({ config, integration, provider, webhookUrlParam, })
|
|
|
272
277
|
},
|
|
273
278
|
},
|
|
274
279
|
};
|
|
275
|
-
|
|
280
|
+
crowdinClient = yield (0, connection_1.prepareCrowdinClient)({
|
|
276
281
|
config,
|
|
277
282
|
credentials: crowdinCredentials,
|
|
278
283
|
context,
|
|
279
284
|
});
|
|
280
|
-
|
|
285
|
+
if (!integrationCredentials) {
|
|
286
|
+
return { projectId, crowdinClient, rootFolder, appSettings, syncSettings, preparedIntegrationCredentials };
|
|
287
|
+
}
|
|
288
|
+
preparedIntegrationCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
|
281
289
|
if (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.config) {
|
|
282
290
|
appSettings = JSON.parse(integrationConfig.config);
|
|
283
291
|
const isWebhookSync = Number(appSettings.schedule) !== types_1.SyncSchedule.DISABLED;
|
|
284
292
|
if (isWebhookSync) {
|
|
285
293
|
syncSettings = (yield (0, storage_1.getStorage)().getSyncSettings(clientId, crowdinId, 'schedule', provider));
|
|
286
|
-
|
|
294
|
+
// We can get an error in getRootFolder when the project has been deleted but the webhooks have been created
|
|
295
|
+
try {
|
|
296
|
+
rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, crowdinClient.client, projectId);
|
|
297
|
+
}
|
|
298
|
+
catch (e) {
|
|
299
|
+
(0, logger_1.logError)(e);
|
|
300
|
+
}
|
|
287
301
|
}
|
|
288
302
|
}
|
|
289
303
|
return {
|
|
@@ -317,12 +331,14 @@ function updateCrowdinFromWebhookRequest(args) {
|
|
|
317
331
|
parent_id: file.parent_id || file.parentId,
|
|
318
332
|
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
319
333
|
node_type: file.nodeType || file.node_type || '1' }, (file.type ? { type: file.type } : {}));
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
334
|
+
if (syncSettings) {
|
|
335
|
+
if (!syncFiles.find((obj) => obj.id === initFile.id)) {
|
|
336
|
+
yield (0, storage_1.getStorage)().updateSyncSettings(JSON.stringify([...syncFiles, initFile]), syncSettings.integrationId, syncSettings.crowdinId, 'schedule', syncSettings.provider);
|
|
337
|
+
}
|
|
338
|
+
const webhook = yield (0, storage_1.getStorage)().getWebhooks(initFile.id, syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
|
|
339
|
+
if (!webhook) {
|
|
340
|
+
yield (0, storage_1.getStorage)().saveWebhooks(initFile.id, syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
|
|
341
|
+
}
|
|
326
342
|
}
|
|
327
343
|
}
|
|
328
344
|
});
|
|
@@ -387,7 +403,9 @@ function consumer({ channel, config, integration, }) {
|
|
|
387
403
|
webhookUrlParam,
|
|
388
404
|
provider: types_1.Provider.INTEGRATION,
|
|
389
405
|
}).then((res) => {
|
|
390
|
-
|
|
406
|
+
if (res) {
|
|
407
|
+
webhooksInfo[clientId].webhookData = res;
|
|
408
|
+
}
|
|
391
409
|
}));
|
|
392
410
|
}
|
|
393
411
|
else {
|
|
@@ -425,11 +443,13 @@ function processMessages({ channel, msg, webhooksData, webhooksInfo, }) {
|
|
|
425
443
|
return __awaiter(this, void 0, void 0, function* () {
|
|
426
444
|
yield Promise.all(webhooksData);
|
|
427
445
|
for (const { data, integration, webhookData } of Object.values(webhooksInfo)) {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
446
|
+
if (webhookData && webhookData.crowdinClient) {
|
|
447
|
+
yield updateCrowdinFromWebhookRequest({
|
|
448
|
+
integration: integration,
|
|
449
|
+
webhookData: webhookData,
|
|
450
|
+
req: data,
|
|
451
|
+
});
|
|
452
|
+
}
|
|
433
453
|
}
|
|
434
454
|
channel.ack(msg, true);
|
|
435
455
|
});
|