rules delete / documents delete / webhook delete all gate behind --yes, but users delete, users reset-password and simulation clean reached the API with no confirmation at all — a bare invocation deleted live data. Add the same confirmationRequired gate (exit 10, no API call) the other destructive commands use, and update the help registry plus the skill reference so the usage lines show --yes.
84 lines
3.7 KiB
TypeScript
84 lines
3.7 KiB
TypeScript
import type { CorpConfig } from "../../core/config/types.js";
|
|
import type { createSealClient } from "../../core/http/factory.js";
|
|
import { confirmationRequired } from "../errors.js";
|
|
import { runTool } from "../helpers.js";
|
|
import { booleanOption, stringOption } from "../parser.js";
|
|
import { outputOptions } from "../printer.js";
|
|
import type { ParsedArgs } from "../types.js";
|
|
|
|
export async function handleUsersCommand(
|
|
action: string | undefined,
|
|
maybeName: string | undefined,
|
|
client: Awaited<ReturnType<typeof createSealClient>>,
|
|
corp: CorpConfig,
|
|
args: ParsedArgs
|
|
) {
|
|
if (action === "create") {
|
|
const name = stringOption(args.options.name) ?? maybeName;
|
|
const phone = stringOption(args.options.phone);
|
|
if (!name || !phone) throw new Error("Usage: seal-use users create --name <name> --phone <phone> [--dept <deptId>]");
|
|
const deptId = stringOption(args.options.dept) ?? stringOption(args.options.departmentId);
|
|
const departmentIds = deptId ? [deptId] : undefined;
|
|
await runTool("seal_user_create", client, corp, { name, phone, departmentIds }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "reset-password") {
|
|
const userId = maybeName ?? stringOption(args.options.userId);
|
|
if (!userId) throw new Error("Usage: seal-use users reset-password <userId> --yes");
|
|
const confirmed = booleanOption(args.options.yes) === true || booleanOption(args.options.confirm) === true;
|
|
if (!confirmed) {
|
|
throw confirmationRequired(
|
|
`Refusing to reset password of user '${userId}' without --yes.`,
|
|
`seal-use users reset-password ${userId} --corp ${corp.id} --yes`
|
|
);
|
|
}
|
|
await runTool("seal_user_reset_password", client, corp, { userId }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "search" || action === "list") {
|
|
const keyword = maybeName ?? stringOption(args.options.keyword) ?? stringOption(args.options.query) ?? "";
|
|
await runTool("seal_user_search", client, corp, { keyword }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "get") {
|
|
const userId = maybeName ?? stringOption(args.options.userId);
|
|
if (!userId) throw new Error("Usage: seal-use users get <userId>");
|
|
await runTool("seal_user_get", client, corp, { userId }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "delete") {
|
|
const userId = maybeName ?? stringOption(args.options.userId);
|
|
if (!userId) throw new Error("Usage: seal-use users delete <userId> --yes");
|
|
const confirmed = booleanOption(args.options.yes) === true || booleanOption(args.options.confirm) === true;
|
|
if (!confirmed) {
|
|
throw confirmationRequired(
|
|
`Refusing to delete user '${userId}' without --yes.`,
|
|
`seal-use users delete ${userId} --corp ${corp.id} --yes`
|
|
);
|
|
}
|
|
await runTool("seal_user_delete", client, corp, { userId }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "activate") {
|
|
const userId = maybeName ?? stringOption(args.options.userId);
|
|
if (!userId) throw new Error("Usage: seal-use users activate <userId>");
|
|
await runTool("seal_user_activate", client, corp, { userId }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "delegation" || action === "impersonate") {
|
|
const userIdOrPhone = maybeName ?? stringOption(args.options.userId) ?? stringOption(args.options.phone);
|
|
if (!userIdOrPhone) throw new Error("Usage: seal-use users delegation <userIdOrPhone> [--note <note>]");
|
|
const note = stringOption(args.options.note);
|
|
await runTool("seal_user_delegation_create", client, corp, { userIdOrPhone, note }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
throw new Error(`Unknown users command: ${action ?? ""}. Run 'seal-use help' for available commands.`);
|
|
}
|