- 彻底移除旧内部狭隘命名与垫片包袱,一步到位全仓整体重命名: * session-client.ts ➔ hose-web-session-client.ts (合思 Web 主站会话客户端) * script-engine-client.ts ➔ piper-workflow-client.ts (Piper 工作流引擎客户端) * unity-client.ts ➔ unity-easo-client.ts (Unity / EASO 运营中台与动态集群客户端) * sso-client.ts ➔ sso-auth-client.ts (SSO 与扫码鉴权客户端) - 新增 hose-docs-client.ts 纳为第 7 大通信底座客户端,收口 docs.ekuaibao.com 文档站点通信 - 端正 Piper 工作流引擎定位,完整覆盖工作流创建、保存、发布、108 类节点编排与 Job 流转 - 彻底整体替换全仓 import 引用与测试套件,新增 clients-semantics.test.ts 自动化校验 - 全量自动化测试 150 files 1155 tests 全部通过,类型检查零错误
161 lines
5.8 KiB
TypeScript
161 lines
5.8 KiB
TypeScript
import { createSessionClient } from "../../../core/http/hose-web-session-client.js";
|
|
import {
|
|
approveAssistTicket,
|
|
listAssistTickets,
|
|
} from "../../../domains/assist-platform/services.js";
|
|
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
|
import { stringOption } from "../../parser.js";
|
|
import { printJson, printKeyValue } from "../../printer.js";
|
|
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
|
import { resolveAssistClient } from "./common.js";
|
|
|
|
export async function handleApprove(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime
|
|
): Promise<CliResult> {
|
|
const corpOption = stringOption(parsed.options, ["corp", "corpid", "id"]);
|
|
const explicitCorpId = corpOption || parsed.args[0] || runtime.selectedCorp?.id;
|
|
|
|
if (!explicitCorpId) {
|
|
return {
|
|
stdout: "",
|
|
stderr:
|
|
"用法: hose-use assist-platform approve [工单ID] [--corp <企业ID>] [--dry-run/--yes]\n" +
|
|
"示例: hose-use assist-platform approve ID01Xeno3GpoNV --corp ID01ofWoOC1wiX --yes\n" +
|
|
" hose-use assist-platform approve --corp ID01ofWoOC1wiX --yes (自动审批最新待授权工单)\n",
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
// 1. 识别 corpId 与 ticketId
|
|
const allCorps = runtime.corpContext?.getAllCorps?.() || [];
|
|
const findCorp = (id: string) =>
|
|
allCorps.find((c) => c.id === id || c.corpId === id) ||
|
|
(runtime.selectedCorp?.id === id || runtime.selectedCorp?.corpId === id
|
|
? runtime.selectedCorp
|
|
: undefined);
|
|
let targetCorp = findCorp(explicitCorpId);
|
|
const ticketOption = stringOption(parsed.options, ["ticket", "ticket-id"]);
|
|
let positionalTicketId: string | undefined;
|
|
|
|
// 如果第 0 个参数不是企业,可能是工单编号
|
|
if (corpOption) {
|
|
// 显式企业选项下,唯一位置参数始终是工单,不能被本地企业命中结果覆盖。
|
|
positionalTicketId = parsed.args[0];
|
|
} else if (!targetCorp && parsed.args[0]) {
|
|
positionalTicketId = parsed.args[0];
|
|
targetCorp = runtime.selectedCorp ?? undefined;
|
|
} else if (targetCorp && parsed.args[1]) {
|
|
positionalTicketId = parsed.args[1];
|
|
}
|
|
|
|
const maxArgs = !corpOption && parsed.args[0] && findCorp(parsed.args[0]) ? 2 : 1;
|
|
if (parsed.args.length > maxArgs ||
|
|
(ticketOption && positionalTicketId && ticketOption !== positionalTicketId)) {
|
|
return {
|
|
stdout: "",
|
|
stderr: "[ERROR] 企业或工单参数存在歧义或冲突。请使用 approve <工单ID> --corp <企业ID>,且 --ticket 必须与位置工单一致。\n",
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
let ticketId = ticketOption || positionalTicketId;
|
|
|
|
if (!targetCorp) {
|
|
return {
|
|
stdout: "",
|
|
stderr: `[ERROR] 未在本地企业配置中找到企业 [${explicitCorpId}]。审批工单需要企业管理员权限凭证,请先确保目标企业已配置在本地并具备管理员会话。\n`,
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
const corpName = targetCorp.name || targetCorp.id;
|
|
const actualCorpId = targetCorp.corpId || targetCorp.id;
|
|
|
|
// 2. 若未显式传入工单编号,自动查询该企业当前处于【待提供】(status: 0) 的工单
|
|
if (!ticketId) {
|
|
try {
|
|
const assistClient = resolveAssistClient(parsed, runtime);
|
|
const tickets = await listAssistTickets(assistClient, actualCorpId);
|
|
const pendingTicket = tickets.find(
|
|
(t) => t.state === "0" || t.state.includes("待提供")
|
|
);
|
|
if (pendingTicket?.ticketId) {
|
|
ticketId = pendingTicket.ticketId;
|
|
}
|
|
} catch {
|
|
// 容错降级
|
|
}
|
|
}
|
|
|
|
if (!ticketId) {
|
|
return {
|
|
stdout: "",
|
|
stderr: `[WARN] 企业 [${corpName}] (${actualCorpId}) 协助中心未查询到待授权的工单。可指定 --ticket <工单ID>,或使用 hose-use assist-platform tickets ${actualCorpId} 查看工单列表。\n`,
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
const nextConfirmCmd = `hose-use assist-platform approve ${ticketId} --corp ${actualCorpId} --yes`;
|
|
|
|
// 3. 写操作两阶段确认守卫
|
|
if (isDryRun(parsed, runtime)) {
|
|
return mutationPreview(
|
|
parsed,
|
|
runtime,
|
|
"审批通过合思协助授权申请",
|
|
`${corpName} (${actualCorpId})`,
|
|
{
|
|
工单编号: ticketId,
|
|
审批动作: "同意授权 (通过并生效)",
|
|
授权范围: "允许运维与技术实施人员在有效期限内免密进入系统协助",
|
|
}
|
|
);
|
|
}
|
|
|
|
requireMutationConfirmation(
|
|
parsed,
|
|
runtime,
|
|
`审批通过企业 [${corpName}] 的协助授权工单 [${ticketId}]`,
|
|
nextConfirmCmd
|
|
);
|
|
|
|
// 4. 调用企业会话客户端执行审批
|
|
const sessionClient = await createSessionClient(targetCorp);
|
|
const res = await approveAssistTicket(sessionClient, {
|
|
ticketId,
|
|
corporationId: actualCorpId,
|
|
status: 1,
|
|
});
|
|
|
|
if (runtime.jsonMode) {
|
|
return {
|
|
stdout: printJson(res, runtime.outputOptions),
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
const startStr = res.startTime ? new Date(res.startTime).toLocaleString("zh-CN", { hour12: false }) : "-";
|
|
const endStr = res.endTime ? new Date(res.endTime).toLocaleString("zh-CN", { hour12: false }) : "-";
|
|
|
|
const pairs: Record<string, string> = {
|
|
企业名称: corpName,
|
|
企业ID: res.corporationId,
|
|
授权工单: res.id,
|
|
工单状态: "🟢 生效中 (授权已开启)",
|
|
有效期限: `${startStr} 至 ${endStr}`,
|
|
申请事项: res.applyMessage || "-",
|
|
申请人: res.userName || "运营实施人员",
|
|
};
|
|
|
|
return {
|
|
stdout:
|
|
`====== 合思协助工单授权通过成功 ======\n${printKeyValue(pairs)}\n\n后续步骤:\n` +
|
|
` 1. 工单已处于生效状态,可直接换取免密链接调试: hose-use assist-platform enter ${actualCorpId} --save --yes\n` +
|
|
` 2. 查看实时工单列表: hose-use assist-platform tickets ${actualCorpId}\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|