Add internal service-to-service integration endpoint

This commit is contained in:
jtricerolph 2026-07-01 19:33:08 +00:00
parent f5f87fdd1f
commit 31f8bba377

View file

@ -139,6 +139,19 @@ export async function integrationRoutes(app) {
return value return value
}) })
// GET /settings/api/internal/integration/:slug — service-to-service, no user session required
// Authenticated by SETTINGS_SECRET bearer token; returns unmasked credentials.
app.get('/internal/integration/:slug', async (req, reply) => {
const token = (req.headers.authorization || '').replace(/^Bearer\s+/i, '')
if (!token || token !== process.env.SETTINGS_SECRET) {
return reply.status(401).send({ error: 'Unauthorized' })
}
const { rows: [row] } = await pool.query('SELECT * FROM integrations WHERE slug = $1', [req.params.slug])
if (!row) return reply.status(404).send({ error: 'Integration not found' })
if (!row.enabled) return reply.status(403).send({ error: 'Integration is disabled' })
return { ...row.config, ...decryptSecrets(row) }
})
// PUT /settings/api/integrations/newbook/rooms — save reorder + colour changes // PUT /settings/api/integrations/newbook/rooms — save reorder + colour changes
app.put('/integrations/newbook/rooms', { preHandler: requireAdmin }, async (req, reply) => { app.put('/integrations/newbook/rooms', { preHandler: requireAdmin }, async (req, reply) => {
const { rows: [row] } = await pool.query(`SELECT value FROM global_config WHERE key = 'newbook.rooms'`) const { rows: [row] } = await pool.query(`SELECT value FROM global_config WHERE key = 'newbook.rooms'`)