Surfaces the federatedRegistrationOpen flag (Task 1 schema column) on the admin settings GET/PATCH endpoints and the public /api/instance/info endpoint. Closes the 3 deferred TypeScript errors from Task 2 by populating the now-required InstanceAdminSettings/InstanceInfoResponse field. Adds smoke tests (routes/instance.test.ts, routes/settings.test.ts) that lock in the JSON contract the Connections UI (Task 21) and admin RegistrationPanel (Task 15) consume, plus boolean-validation coverage for the PATCH path. Updates docs/systems/admin.md with the new field in both InstanceAdminSettings and the public info response schema.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import type { FastifyInstance } from 'fastify';
|
|
import { eq } from 'drizzle-orm';
|
|
import { getDb, schema } from '../db/index.js';
|
|
import { config } from '../config.js';
|
|
import type { InstanceInfoResponse } from '@backspace/shared';
|
|
|
|
const BACKSPACE_VERSION = '1.0.0';
|
|
|
|
export async function instanceRoutes(app: FastifyInstance): Promise<void> {
|
|
app.get('/api/instance/info', async (_request, reply) => {
|
|
const db = getDb();
|
|
|
|
const settings = db.select().from(schema.instanceSettings).where(eq(schema.instanceSettings.id, 1)).get();
|
|
const instanceName = settings?.instanceName ?? 'Backspace';
|
|
|
|
// DB setting overrides env var if explicitly set by admin
|
|
const registrationOpen = settings?.registrationOpen !== null && settings?.registrationOpen !== undefined
|
|
? settings.registrationOpen === 1
|
|
: config.registrationOpen;
|
|
|
|
const response: InstanceInfoResponse = {
|
|
name: instanceName,
|
|
version: BACKSPACE_VERSION,
|
|
registrationOpen,
|
|
federatedRegistrationOpen: settings?.federatedRegistrationOpen === 1,
|
|
};
|
|
|
|
return reply.code(200).send(response);
|
|
});
|
|
}
|