diff --git a/src/integrations/schema.js b/src/integrations/schema.js index f7a5486..d1ff77c 100644 --- a/src/integrations/schema.js +++ b/src/integrations/schema.js @@ -37,6 +37,11 @@ export const INTEGRATIONS = { configFields: ['host', 'port', 'from', 'reply_to'], secretFields: ['user', 'pass'], }, + hosted_tables: { + name: 'Hosted Tables', + configFields: ['site_url'], + secretFields: [], + }, } export const MASKED = '••••••••' diff --git a/src/routes/integrations.js b/src/routes/integrations.js index 056a45e..63964ad 100644 --- a/src/routes/integrations.js +++ b/src/routes/integrations.js @@ -16,6 +16,17 @@ function bustAuthCache() { }).catch(() => {}) } +function syncHostedTables(siteUrl, enabled) { + const secret = process.env.SETTINGS_SECRET || '' + const active = enabled && siteUrl.trim().length > 0 + fetch(`${AUTH_URL}/api/auth/internal/apps/restaurant_bookings`, { + method: 'PATCH', + headers: { Authorization: `Bearer ${secret}`, 'Content-Type': 'application/json' }, + body: JSON.stringify({ base_path: siteUrl.trim() || '/bookings', active }), + signal: AbortSignal.timeout(5000), + }).catch(() => {}) +} + function decryptSecrets(row) { if (!row.secrets) return {} try { return JSON.parse(decrypt(row.secrets)) } catch { return {} } @@ -89,6 +100,7 @@ export async function integrationRoutes(app) { const { rows: [updated] } = await pool.query('SELECT * FROM integrations WHERE slug = $1', [slug]) if (slug === 'workforce' || slug === 'smtp') bustAuthCache() + if (slug === 'hosted_tables') syncHostedTables(config.site_url ?? '', enabled) return maskRow(updated) })