Pilot for the command-directory form: 1077-line corps.ts becomes
corps/{index,shared,query,context,link,credentials,probe}.ts with
verbatim code moves. index.ts keeps the dispatch switch plus
re-exports so auth.ts and registry.ts consumers stay source-compatible.
No behavior change: tsc clean, 316 tests pass.
71 lines
2.7 KiB
TypeScript
71 lines
2.7 KiB
TypeScript
import { fetchHoseRoleDefGroups, listHoseStaffsByOpenApi, probeHoseDomain } from "../../../core/auth/login.js";
|
|
import { stringOption } from "../../parser.js";
|
|
import { printJson, printKeyValue, printTable } from "../../printer.js";
|
|
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
|
|
|
export async function handleProbeHose(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
|
const appKey = stringOption(parsed.options, ["app-key", "appKey"]);
|
|
const appSecurity = stringOption(parsed.options, ["app-security", "appSecurity", "secret"]);
|
|
const domain = stringOption(parsed.options, ["domain", "base-url"]);
|
|
|
|
if (!appKey || !appSecurity) {
|
|
return {
|
|
stdout: "",
|
|
stderr: "用法: hose-use corps probe-hose --app-key=<key> --app-security=<secret> [--domain=<url>]\n",
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
const probe = await probeHoseDomain(appKey, appSecurity, domain);
|
|
const roleGroups = await fetchHoseRoleDefGroups(probe.domain, probe.openapiToken).catch(() => []);
|
|
const payload = {
|
|
domain: probe.domain,
|
|
corpId: probe.corpId,
|
|
name: probe.corpName || probe.corpId,
|
|
roleCount: roleGroups.reduce((acc, g) => acc + g.roleDefs.length, 0),
|
|
roleGroups,
|
|
};
|
|
|
|
if (runtime.jsonMode) {
|
|
return { stdout: printJson(payload, runtime.outputOptions), stderr: "", exitCode: 0 };
|
|
}
|
|
|
|
return {
|
|
stdout: `====== OpenAPI 域名与企业探测结果 ======\n${printKeyValue({
|
|
"企业 ID": payload.corpId,
|
|
"企业名称": payload.name,
|
|
"服务节点": payload.domain,
|
|
"角色数量": payload.roleCount,
|
|
})}\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
export async function handleHoseStaffs(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
|
const appKey = stringOption(parsed.options, ["app-key", "appKey"]);
|
|
const appSecurity = stringOption(parsed.options, ["app-security", "appSecurity", "secret"]);
|
|
const domain = stringOption(parsed.options, ["domain", "base-url"]);
|
|
const role = stringOption(parsed.options, ["role", "roleDefId"]);
|
|
|
|
if (!appKey || !appSecurity) {
|
|
return {
|
|
stdout: "",
|
|
stderr: "用法: hose-use corps hose-staffs --app-key=<key> --app-security=<secret> [--role=admin]\n",
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
const res = await listHoseStaffsByOpenApi({ appKey, appSecurity, domain, role });
|
|
if (runtime.jsonMode) {
|
|
return { stdout: printJson(res, runtime.outputOptions), stderr: "", exitCode: 0 };
|
|
}
|
|
|
|
const rows = res.staffs.map((s, i) => [i + 1, s.id, s.name, s.cellphone || "-", s.active ? "在职" : "离职"]);
|
|
return {
|
|
stdout: `====== 角色成员列表 (${res.roleName || res.roleId}) ======\n${printTable(["#", "员工 ID", "姓名", "手机号", "状态"], rows)}\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|