UNPKG

@crowdin/app-project-module

Version:

Module that generates for you all common endpoints for serving standalone Crowdin App

45 lines (44 loc) 2.52 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = require("../../../util"); const webhooks_1 = require("../util/webhooks"); const types_1 = require("../types"); const logger_1 = require("../../../util/logger"); function handle(config, integration) { return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () { var _a, _b; const urlParam = (_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.urlParam; const webhookUrlParam = req.query[urlParam]; if (((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhookInterceptor) && webhookUrlParam) { const webhookData = yield (0, webhooks_1.prepareWebhookData)({ config, integration, webhookUrlParam, provider: types_1.Provider.INTEGRATION, }); if (!(webhookData === null || webhookData === void 0 ? void 0 : webhookData.crowdinClient)) { (0, logger_1.temporaryErrorDebug)('Access denied: integration-webhooks !webhookData.crowdinClient', req); return res.status(403).send({ error: 'Access denied' }); } if (!(webhookData === null || webhookData === void 0 ? void 0 : webhookData.syncSettings)) { return res.status(200).send({ message: 'Sync is not configured' }); } yield (0, webhooks_1.updateCrowdinFromWebhookRequest)({ integration, webhookData, req: [req] }); res.send({}); } else { (0, logger_1.temporaryErrorDebug)('Access denied: integration-webhooks !webhookUrlParam', req); return res.status(403).send({ error: 'Access denied' }); } })); } exports.default = handle;