UNPKG

@crowdin/app-project-module

Version:

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

31 lines (30 loc) 1.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.register = void 0; const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module")); const ui_module_1 = __importDefault(require("../../middlewares/ui-module")); const util_1 = require("../../util"); function register({ config, app }) { var _a, _b; const allowUnauthorized = !(0, util_1.isAuthorizedConfig)(config); if (!config.modal) { return; } if (Array.isArray(config.modal)) { config.modal.forEach((modal) => { if ((modal === null || modal === void 0 ? void 0 : modal.uiPath) || (modal === null || modal === void 0 ? void 0 : modal.formSchema)) { app.use(`/modal-${modal.key}`, (0, ui_module_1.default)({ config, allowUnauthorized, moduleType: modal.key }), (0, render_ui_module_1.default)(modal)); } }); } else { // backward compatibility will be removed after migration if (((_a = config.modal) === null || _a === void 0 ? void 0 : _a.uiPath) || ((_b = config.modal) === null || _b === void 0 ? void 0 : _b.formSchema)) { app.use('/modal', (0, ui_module_1.default)({ config, allowUnauthorized, moduleType: config.modal.key }), (0, render_ui_module_1.default)(config.modal)); } } } exports.register = register;