mirror of
https://github.com/Routstr/routstrd.git
synced 2026-10-05 20:38:22 +00:00
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:
+28
@@ -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")
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user