refactor: switch SDK methods to asynchronous

Migrate SDK interactions to asynchronous calls, relax admin setup email constraints, and add event retrieval functionality.
This commit is contained in:
Team Dark Devil committed 2026-11-17 20:05:00 +06:00
1 parent 81c5e4e2fd
commit bb938c33c0
36 files changed
+1679 -754

No files matched your search

+4 -4
View File
@@ -6,7 +6,7 @@ export async function GET(
{ params }: { params: Promise<{ id: string }> },
) {
const { id } = await params;
const client = SDKManager.getClient(id);
const client = await SDKManager.getClientAsync(id);
if (!client) {
return NextResponse.json({ error: "Client not found" }, { status: 404 });
}
@@ -24,7 +24,7 @@ export async function PATCH(
// Special action: regenerate token
if (body.action === "regenerate_token") {
const refreshed = SDKManager.regenerateToken(id);
const refreshed = await SDKManager.regenerateTokenAsync(id);
if (!refreshed) {
return NextResponse.json(
{ error: "Client not found" },
@@ -34,7 +34,7 @@ export async function PATCH(
return NextResponse.json({ client: refreshed });
}
const updated = SDKManager.updateClient(id, body);
const updated = await SDKManager.updateClientAsync(id, body);
if (!updated) {
return NextResponse.json({ error: "Client not found" }, { status: 404 });
}
@@ -50,7 +50,7 @@ export async function DELETE(
{ params }: { params: Promise<{ id: string }> },
) {
const { id } = await params;
const deleted = SDKManager.deleteClient(id);
const deleted = await SDKManager.deleteClientAsync(id);
if (!deleted) {
return NextResponse.json({ error: "Client not found" }, { status: 404 });
}
+14 -8
View File
@@ -3,9 +3,11 @@ import { NextRequest, NextResponse } from "next/server";
export async function GET() {
try {
const clients = SDKManager.listClients().map(
({ secret, token, ...client }) => client,
);
const allClients = await SDKManager.listClientsAsync();
const clients = allClients.map(({ secret, ...client }) => {
void secret;
return client;
});
return NextResponse.json({ clients, count: clients.length });
} catch (err: unknown) {
const message =
@@ -26,17 +28,21 @@ export async function POST(req: NextRequest) {
);
}
const existing = SDKManager.getClient(clientId);
const safeClientId = String(clientId)
.trim()
.toLowerCase()
.replace(/[^a-z0-9_-]/g, "_");
const existing = await SDKManager.getClientAsync(safeClientId);
if (existing) {
return NextResponse.json(
{ error: `Client '${clientId}' already exists` },
{ error: `Client '${safeClientId}' already exists` },
{ status: 409 },
);
}
const newClient = SDKManager.registerClient({
clientId,
name,
const newClient = await SDKManager.registerClientAsync({
clientId: safeClientId,
name: String(name),
rateLimit: rateLimit ? Number(rateLimit) : 100,
});