feat(assist-platform): add ticket application command and enforce local config trust rules
This commit is contained in:
1 parent
2e6fe1a94a
commit
1e45c441c6
10 files changed
+661
-387
No files matched your search
@@ -780,6 +780,7 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"detail": "查看企业详细业务配置与开通商品能力",
|
||||
"tickets": "查询指定企业的协助工单与授权码",
|
||||
"staff": "查询企业内部员工工号与角色",
|
||||
"apply": "向目标企业发起新的协助授权工单申请",
|
||||
"enter": "一键换取免密直通链接并落盘为本地工作企业",
|
||||
"help": "查看帮助信息"
|
||||
},
|
||||
@@ -800,12 +801,16 @@ export const COMMAND_METADATA: Record<string, CliCommandMetadata> = {
|
||||
"orders": "tickets",
|
||||
"user": "staff",
|
||||
"users": "staff",
|
||||
"apply": "apply",
|
||||
"create": "apply",
|
||||
"request": "apply",
|
||||
"new": "apply",
|
||||
"import": "enter",
|
||||
"token": "enter",
|
||||
"get-token": "enter"
|
||||
},
|
||||
flags: {
|
||||
...flagList("token t user name u hose-token jwt ticket ticket-id auth-code staff alias corp-name count limit n start offset state status corpid id keyword query q", "value"),
|
||||
...flagList("token t user name u hose-token jwt ticket ticket-id auth-code staff alias corp-name count limit n start offset state status corpid id keyword query q message msg reason matter hours hour duration", "value"),
|
||||
...flagList("logout admin save import persist switch current overwrite", "boolean")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,4 +127,26 @@ describe("CLI Commands - assist-platform (合思协助平台)", () => {
|
||||
expect(res.stdout).toContain("[DRY-RUN]");
|
||||
expect(res.stdout).toContain("Cxa3oOtQi2eS$g");
|
||||
});
|
||||
|
||||
it("assist-platform apply --dry-run 能够输出申请工单变更预览", async () => {
|
||||
saveAssistPlatformSession({
|
||||
token: "mock-token",
|
||||
userName: "测试人员",
|
||||
baseUrl: "https://unity.ekuaibao.com/api",
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
|
||||
const runtime = createMockRuntime(tempDir);
|
||||
const parsed: CliParsedArgs = {
|
||||
action: "apply",
|
||||
args: ["ID01KrLMQJWdMH"],
|
||||
options: { dryRun: true, hours: 12, message: "测试联调" },
|
||||
raw: ["assist-platform", "apply", "ID01KrLMQJWdMH", "--dry-run", "--hours", "12"],
|
||||
};
|
||||
|
||||
const res = await handleAssistPlatformCommand(parsed, runtime);
|
||||
expect(res.stdout).toContain("[DRY-RUN]");
|
||||
expect(res.stdout).toContain("ID01KrLMQJWdMH");
|
||||
expect(res.stdout).toContain("12 小时");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
import { applyAssistTicket } from "../../../domains/assist-platform/services.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
import { numberOption, 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 handleApply(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const client = resolveAssistClient(parsed, runtime);
|
||||
const corpId =
|
||||
parsed.args[0] ||
|
||||
stringOption(parsed.options, ["corp", "corpid", "id"]) ||
|
||||
runtime.selectedCorp?.id;
|
||||
|
||||
if (!corpId) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose-use assist-platform apply <企业ID> [--message <事由>] [--hours <小时数(1-24)>] [--dry-run/--yes]\n示例: hose-use assist-platform apply ID01KrLMQJWdMH --message \"测试环境接口联调\" --hours 24 --yes\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const hours = numberOption(parsed.options, ["hours", "hour", "duration"]) ?? 24;
|
||||
if (hours < 1 || hours > 24) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `[ERROR] 申请协助时长必须介于 1 到 24 小时之间,当前传入: ${hours}\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const message =
|
||||
stringOption(parsed.options, ["message", "msg", "reason", "matter"]) ||
|
||||
"测试环境接口联调与问题排查";
|
||||
|
||||
const targetCorp =
|
||||
runtime.corpContext?.getAllCorps?.()?.find((c) => c.id === corpId || c.corpId === corpId) ||
|
||||
(runtime.selectedCorp?.id === corpId || runtime.selectedCorp?.corpId === corpId
|
||||
? runtime.selectedCorp
|
||||
: undefined);
|
||||
const corpName = targetCorp?.name || corpId;
|
||||
|
||||
const nextConfirmCmd = `hose-use assist-platform apply ${corpId} --message "${message}" --hours ${hours} --yes`;
|
||||
|
||||
// 写操作两阶段确认守卫
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(
|
||||
parsed,
|
||||
runtime,
|
||||
"发起合思协助工单申请",
|
||||
`${corpName} (${corpId})`,
|
||||
{
|
||||
申请事项: message,
|
||||
申请时长: `${hours} 小时 (${hours * 3600 * 1000} ms)`,
|
||||
初始状态: "待提供 (需企业管理员在端内开启授权)",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
requireMutationConfirmation(
|
||||
parsed,
|
||||
runtime,
|
||||
`向企业 [${corpName}] 发起协助授权申请 (时长: ${hours}h, 事由: ${message})`,
|
||||
nextConfirmCmd
|
||||
);
|
||||
|
||||
const res = await applyAssistTicket(client, {
|
||||
corporationId: corpId,
|
||||
applyMessage: message,
|
||||
assistTime: hours * 3600 * 1000,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(res, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const pairs: Record<string, string> = {
|
||||
企业名称: corpName,
|
||||
企业ID: res.corporationId,
|
||||
新建工单ID: res.id,
|
||||
工单状态: "🟡 待提供 (等待客户管理员在企业端授权)",
|
||||
申请时长: `${hours} 小时`,
|
||||
申请事项: res.applyMessage,
|
||||
申请人: res.userName || "运营实施人员",
|
||||
};
|
||||
|
||||
return {
|
||||
stdout: `====== 合思协助工单申请提交成功 ======\n${printKeyValue(pairs)}\n\n后续步骤:\n 1. 提示企业管理员登录合思 Web/桌面端,在【远程协助/授权中心】确认开启授权;\n 2. 授权通过后工单变为【🟢 生效中】,即可运行: hose-use assist-platform enter ${corpId} --staff <员工姓名> --save --yes\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { handleDetail } from "./detail.js";
|
||||
import { handleTickets } from "./tickets.js";
|
||||
import { handleStaff } from "./staff.js";
|
||||
import { handleEnter } from "./enter.js";
|
||||
import { handleApply } from "./apply.js";
|
||||
|
||||
export async function handleAssistPlatformCommand(
|
||||
parsed: CliParsedArgs,
|
||||
@@ -46,6 +47,12 @@ export async function handleAssistPlatformCommand(
|
||||
case "get-token":
|
||||
return handleEnter(parsed, runtime);
|
||||
|
||||
case "apply":
|
||||
case "create":
|
||||
case "request":
|
||||
case "new":
|
||||
return handleApply(parsed, runtime);
|
||||
|
||||
case "help":
|
||||
case "--help":
|
||||
case "-h":
|
||||
@@ -68,6 +75,7 @@ function printHelp(): CliResult {
|
||||
detail <企业ID> 查看企业全量业务配置(套餐规格、基础参数、已开通商品扩展能力)
|
||||
tickets <企业ID> 查询指定企业的协助工单(申请人、授权码、剩余时长、工单状态)
|
||||
staff <企业ID> <姓名> 查询企业内部指定员工的工号、账号、邮箱及 admin 属性
|
||||
apply <企业ID> 向目标企业发起新的协助授权工单申请(待客户管理员审批)
|
||||
enter <企业ID> 一键换取协助免密直通链接并进入(可选 --save 落盘为本地工作企业)
|
||||
|
||||
常用选项:
|
||||
|
||||
Reference in new issue
Block a user