2026-10-23 19:56:38 -07:00
|
|
|
import { SDKManager } from "@/core/sdk/sdkManager";
|
|
|
|
|
import { NextRequest, NextResponse } from "next/server";
|
2026-10-23 11:43:49 -05:00
|
|
|
|
|
|
|
|
export async function GET() {
|
|
|
|
|
try {
|
2026-10-23 19:56:38 -07:00
|
|
|
const clients = SDKManager.listClients().map(
|
|
|
|
|
({ secret, token, ...client }) => client,
|
|
|
|
|
);
|
2026-10-23 11:43:49 -05:00
|
|
|
return NextResponse.json({ clients, count: clients.length });
|
|
|
|
|
} catch (err: unknown) {
|
2026-10-23 19:56:38 -07:00
|
|
|
const message =
|
|
|
|
|
err instanceof Error ? err.message : "Failed to list clients";
|
2026-10-23 11:43:49 -05:00
|
|
|
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(
|
2026-10-23 19:56:38 -07:00
|
|
|
{ error: "clientId and name are required" },
|
|
|
|
|
{ status: 400 },
|
2026-10-23 11:43:49 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const existing = SDKManager.getClient(clientId);
|
|
|
|
|
if (existing) {
|
|
|
|
|
return NextResponse.json(
|
|
|
|
|
{ error: `Client '${clientId}' already exists` },
|
2026-10-23 19:56:38 -07:00
|
|
|
{ status: 409 },
|
2026-10-23 11:43:49 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const newClient = SDKManager.registerClient({
|
|
|
|
|
clientId,
|
|
|
|
|
name,
|
|
|
|
|
rateLimit: rateLimit ? Number(rateLimit) : 100,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return NextResponse.json({ client: newClient }, { status: 201 });
|
|
|
|
|
} catch (err: unknown) {
|
2026-10-23 19:56:38 -07:00
|
|
|
const message =
|
|
|
|
|
err instanceof Error ? err.message : "Client creation failed";
|
2026-10-23 11:43:49 -05:00
|
|
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
|
|
|
}
|
|
|
|
|
}
|