Convert lib/settings.ts, lib/notifications/{in-app,email,capa-escalation,
effectiveness-recheck}.ts from Supabase PostgREST to Drizzle asAdmin queries.
Drop supabase arg from all call sites in app/api/ and cron routes. Rewrite
notification unit tests to mock @/lib/db/with-user instead of SupabaseClient.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
22 lines
646 B
TypeScript
22 lines
646 B
TypeScript
import 'server-only'
|
|
import { asAdmin } from '@/lib/db/with-user'
|
|
import { appSettings } from '@/lib/db/schema'
|
|
import { eq } from 'drizzle-orm'
|
|
|
|
export async function getApiKey(key: string): Promise<string> {
|
|
try {
|
|
const rows = await asAdmin(db =>
|
|
db.select({ value: appSettings.value })
|
|
.from(appSettings)
|
|
.where(eq(appSettings.key, key))
|
|
.limit(1)
|
|
)
|
|
if (rows[0]?.value) return rows[0].value
|
|
} catch {
|
|
// fall through to env
|
|
}
|
|
const env = process.env[key]
|
|
if (env) return env
|
|
throw new Error(`${key} not configured. Add it in Settings (/hse/settings) or as an environment variable.`)
|
|
}
|