Initial settings service
Fastify API for storing third-party integration credentials (Newbook, Resos, Nextcloud, Azure, SambaPOS) with AES-256-GCM encryption for sensitive fields. Includes Newbook room sync endpoint and global_config store for shared app data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
e7b08ccf31
13 changed files with 381 additions and 0 deletions
33
src/db.js
Normal file
33
src/db.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import pg from 'pg'
|
||||
import { INTEGRATIONS } from './integrations/schema.js'
|
||||
|
||||
const { Pool } = pg
|
||||
export const pool = new Pool({ connectionString: process.env.DATABASE_URL })
|
||||
|
||||
export async function initDb() {
|
||||
await pool.query(`
|
||||
CREATE TABLE IF NOT EXISTS integrations (
|
||||
slug TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
config JSONB NOT NULL DEFAULT '{}',
|
||||
secrets TEXT,
|
||||
enabled BOOLEAN NOT NULL DEFAULT true,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS global_config (
|
||||
key TEXT PRIMARY KEY,
|
||||
value JSONB,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
`)
|
||||
|
||||
// Seed known integrations (idempotent — never overwrites existing config/secrets)
|
||||
const slugs = Object.entries(INTEGRATIONS).map(([slug, { name }]) => ({ slug, name }))
|
||||
for (const { slug, name } of slugs) {
|
||||
await pool.query(
|
||||
`INSERT INTO integrations (slug, name) VALUES ($1, $2) ON CONFLICT (slug) DO NOTHING`,
|
||||
[slug, name]
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue