Files
DataStack/app/api/clients/route.ts
T
i vib fcc4f4db2d chore: publish current DataStack updates
Publish the current application, design, and Phase 1 deployment updates. Excludes ignored personal notes, local MCP config, and generated TypeScript build info.
2026-10-23 19:56:38 -07:00

50 lines
1.4 KiB
TypeScript

import { SDKManager } from "@/core/sdk/sdkManager";
import { NextRequest, NextResponse } from "next/server";
export async function GET() {
try {
const clients = SDKManager.listClients().map(
({ secret, token, ...client }) => client,
);
return NextResponse.json({ clients, count: clients.length });
} catch (err: unknown) {
const message =
err instanceof Error ? err.message : "Failed to list clients";
return NextResponse.json({ error: message }, { status: 500 });
}
}
export async function POST(req: NextRequest) {
try {
const body = await req.json();
const { clientId, name, rateLimit } = body;
if (!clientId || !name) {
return NextResponse.json(
{ error: "clientId and name are required" },
{ status: 400 },
);
}
const existing = SDKManager.getClient(clientId);
if (existing) {
return NextResponse.json(
{ error: `Client '${clientId}' already exists` },
{ status: 409 },
);
}
const newClient = SDKManager.registerClient({
clientId,
name,
rateLimit: rateLimit ? Number(rateLimit) : 100,
});
return NextResponse.json({ client: newClient }, { status: 201 });
} catch (err: unknown) {
const message =
err instanceof Error ? err.message : "Client creation failed";
return NextResponse.json({ error: message }, { status: 500 });
}
}