feat: add clients delete command

Add 'routstrd clients delete <id>' CLI command and POST /clients/delete
HTTP endpoint to remove a client by its ID.
This commit is contained in:
redshift
2026-04-27 19:22:56 +05:30
parent 69e5dfac90
commit 2b6876ccd6
2 changed files with 87 additions and 0 deletions
+28
View File
@@ -734,6 +734,34 @@ clientsCmd
} }
}); });
clientsCmd
.command("delete <id>")
.description("Delete a client by its ID")
.action(async (id: string) => {
await ensureDaemonRunning();
const result = await callDaemon("/clients/delete", {
method: "POST",
body: { id },
});
if (result.error) {
console.log(result.error);
process.exit(1);
}
const output = result.output as
| {
message: string;
id: string;
}
| undefined;
if (output) {
console.log(output.message);
}
});
clientsCmd clientsCmd
.command("add") .command("add")
.description("Add a new client or set up client integrations") .description("Add a new client or set up client integrations")
+59
View File
@@ -831,6 +831,65 @@ export function createDaemonRequestHandler(deps: {
return; return;
} }
if (req.method === "POST" && url.pathname === "/clients/delete") {
try {
const bodyText = await readBody(req);
const body = bodyText ? JSON.parse(bodyText) : {};
const id = body.id as string | undefined;
if (!id || typeof id !== "string" || id.trim() === "") {
res.writeHead(400, { "Content-Type": "application/json" });
res.end(
JSON.stringify({
error:
"Missing required 'id' field (must be a non-empty string).",
}),
);
return;
}
const state = deps.store.getState();
const existingClients = state.clientIds || [];
const index = existingClients.findIndex(
(c: { clientId: string }) => c.clientId === id,
);
if (index === -1) {
res.writeHead(404, { "Content-Type": "application/json" });
res.end(
JSON.stringify({
error: `Client with id '${id}' not found.`,
}),
);
return;
}
const removedClient = existingClients[index];
const updatedClients = existingClients.filter(
(_c: unknown, i: number) => i !== index,
);
deps.store.getState().setClientIds(updatedClients);
logger.log(
`Deleted client '${removedClient.name}' with id '${id}'`,
);
res.writeHead(200, { "Content-Type": "application/json" });
res.end(
JSON.stringify({
output: {
message: `Client '${removedClient.name}' deleted successfully`,
id,
},
}),
);
} catch (error) {
respondWithError(res, error);
}
return;
}
if (req.method === "GET" && url.pathname === "/providers") { if (req.method === "GET" && url.pathname === "/providers") {
try { try {
const state = deps.store.getState(); const state = deps.store.getState();