import { Analytics } from '@rocket.chat/core-services'; import express, { type Request } from 'express'; import { WebApp } from 'meteor/webapp'; import { getSeatsRequestLink } from './lib/license/getSeatsRequestLink'; import { authenticationMiddleware, hasPermissionMiddleware } from '../../server/api/v1/middlewares/authentication'; import { getCheckoutUrl, fallback } from '../../server/lib/cloud/getCheckoutUrl'; const apiServer = express(); WebApp.connectHandlers.use(apiServer); // eslint-disable-next-line new-cap const router = express.Router(); apiServer.use('/requestSeats', router); apiServer.use('/links/manage-subscription', router); router.use(authenticationMiddleware({ rejectUnauthorized: false, cookies: true })); router.use( hasPermissionMiddleware('manage-cloud', { rejectUnauthorized: false, }), ); router.get('/', async (req: Request, res) => { const url = await getSeatsRequestLink(req.unauthorized ? fallback : (await getCheckoutUrl()).url, req.query as Record); await Analytics.saveSeatRequest(); res.writeHead(302, { Location: url }); res.end(); });