Merge pull request #129 from yunyingk/feat/assist-platform-apply-and-trust-rules
CI / validate (push) Has been cancelled
CI / validate (push) Has been cancelled
feat(assist-platform): add ticket application command and enforce local config trust rules
This commit is contained in:
10 files changed
+661
-387
No files matched your search
Vendored
+398
-384
File diff suppressed because it is too large.
Load diff
@@ -52,6 +52,10 @@ metadata:
|
||||
10. **单据检索服务端过滤优先(Server-Side Filtering First)**:
|
||||
- 查询单据列表优先使用服务端时间过滤 `--since=7d`、`--since=30d`、`--start-date`、`--end-date` 或指定 `--code`,服务端毫秒级利用索引返回;
|
||||
- 在海量单据租户下,严禁无参数滥用全量检索,优先引导用户查看个人发起单据(`hose-use bill list --mine`)或待办(`hose-use task todo`)。
|
||||
11. **本地企业名录最高可信度与合思 payType 混淆防范(Local Config as Source of Truth & PayType Trap)**:
|
||||
- **本地配置具有最高权威性**:本地企业名录(`hose-use corps list` / `enterprises/*.json`)标注的环境类别(🏭 正式 / 🧪 测试 / 🎪 演示)经过人工审核确认,是判断企业真实性质的唯一权威来源;
|
||||
- **合思云端 payType 极度混乱陷阱**:合思数据库中的元数据 `payType`(如 `TRYOUT` 试用 / `PAY` 付费)存在严重的业务历史包袱,**大量真实商业付费的正式客户租户在系统底层依然被标记为 `TRYOUT`(试用)**;
|
||||
- **严禁仅凭云端标记臆断测试沙箱**:严禁仅凭云端返回的 `payType: "TRYOUT"`、或企业名称简短/包含英文就盲目认定为测试沙箱。任何写操作(包括发起协助工单 `assist-platform apply`、单据或配置变更)必须严格核对本地企业环境,仅在明确标记为 🧪 测试 的企业中进行,正式企业必须有用户显式指令与二次确认。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -59,6 +59,11 @@ hose-use assist-platform tickets <企业ID> --all --limit 20
|
||||
|
||||
工单信息包含:工单编号 (`ticketId`)、申请人、申请事由、起始时间与过期时间。
|
||||
|
||||
> [!WARNING] 合思底层 payType 混淆与本地企业名录可信度原则
|
||||
> 1. **合思付费模式混乱**:合思数据库中的 `payType`(`TRYOUT` 试用 / `PAY` 付费)存在严重的业务历史包袱,**大量真实商业付费的正式生产客户在系统中依然被标记为 `TRYOUT`(试用)**。
|
||||
> 2. **严禁仅凭云端标记臆断沙箱**:严禁仅凭云端返回的 `payType: "TRYOUT"` 擅自推断企业为测试沙箱!
|
||||
> 3. **本地配置权威优先**:判断企业性质必须以本地企业配置(`hose-use corps list` / `enterprises/*.json`)标注的环境类别(🏭 正式 / 🧪 测试 / 🎪 演示)为准,本地配置具有最高权威性。任何写操作(如发起协助工单 `apply`)严禁在未经授权的正式企业上执行。
|
||||
|
||||
---
|
||||
|
||||
## 4. 员工名录检索 (`staff`)
|
||||
@@ -75,7 +80,23 @@ hose-use assist-platform staff <企业ID> --mobile "13800000000"
|
||||
|
||||
---
|
||||
|
||||
## 5. 免密代客进入与自动落盘 (`enter`)
|
||||
## 5. 发起协助申请工单 (`apply`)
|
||||
|
||||
当企业名下没有生效工单或工单已过期时,可向目标企业发起新的协助授权申请。**注意:写操作仅限在本地确认的 🧪 测试企业中进行,正式企业必须获得用户明确指示。**
|
||||
|
||||
```bash
|
||||
# 查看变更预览(安全 Dry-Run)
|
||||
hose-use assist-platform apply ID01KrLMQJWdMH --dry-run
|
||||
|
||||
# 向测试企业发起 24 小时协助工单申请
|
||||
hose-use assist-platform apply ID01KrLMQJWdMH --message "测试环境接口联调" --hours 24 --yes
|
||||
```
|
||||
|
||||
提交后工单初始状态为 `🟡 待提供`,等待企业管理员登录合思 Web/桌面端确认开启授权即可激活。
|
||||
|
||||
---
|
||||
|
||||
## 6. 免密代客进入与自动落盘 (`enter`)
|
||||
|
||||
基于选定工单与身份(管理员或指定员工),向协助平台换取免密直通链接,并支持一键落盘到本地企业库和自动提权。
|
||||
|
||||
|
||||
@@ -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 落盘为本地工作企业)
|
||||
|
||||
常用选项:
|
||||
|
||||
@@ -121,6 +121,9 @@ export async function searchAssistTicketsApi(
|
||||
? `${new Date(startTime).toLocaleString("zh-CN", { hour12: false })} 至 ${new Date(endTime).toLocaleString("zh-CN", { hour12: false })}`
|
||||
: undefined;
|
||||
|
||||
const rawStatus = item.state ?? item.status;
|
||||
const stateStr = rawStatus !== undefined && rawStatus !== null ? String(rawStatus) : "未知状态";
|
||||
|
||||
return {
|
||||
id: String(item.id || item.ticketId || ""),
|
||||
ticketId: String(item.ticketId || item.id || item.authCode || ""),
|
||||
@@ -128,7 +131,7 @@ export async function searchAssistTicketsApi(
|
||||
applicantId: item.applicantId ? String(item.applicantId) : undefined,
|
||||
principal: item.principal ? String(item.principal) : (item.operationUserName ? String(item.operationUserName) : undefined),
|
||||
principalId: item.principalId ? String(item.principalId) : undefined,
|
||||
state: String(item.state || item.status || "未知状态"),
|
||||
state: stateStr,
|
||||
duration: typeof item.duration === "number" ? item.duration : (typeof item.hours === "number" ? item.hours : undefined),
|
||||
startTime,
|
||||
endTime,
|
||||
@@ -245,3 +248,64 @@ export async function getAssistTokenApi(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export interface CreateAssistTicketApiParams {
|
||||
corporationId: string;
|
||||
applyMessage?: string;
|
||||
assistTime?: number; // 毫秒,默认 24 小时
|
||||
}
|
||||
|
||||
export interface CreateAssistTicketApiResponse {
|
||||
id: string;
|
||||
corporationId: string;
|
||||
applyMessage: string;
|
||||
assistTime: number;
|
||||
userName?: string;
|
||||
responsibleUserName?: string;
|
||||
status: number;
|
||||
}
|
||||
|
||||
export async function createAssistTicketApi(
|
||||
client: KyInstance,
|
||||
params: CreateAssistTicketApiParams
|
||||
): Promise<CreateAssistTicketApiResponse> {
|
||||
const { corporationId, applyMessage, assistTime } = params;
|
||||
if (!corporationId || !corporationId.trim()) {
|
||||
throw new BusinessError("必须指定目标企业 ID");
|
||||
}
|
||||
|
||||
const durationMs = assistTime ?? 24 * 3600 * 1000;
|
||||
const message = applyMessage?.trim() || "自动化联调与测试";
|
||||
|
||||
try {
|
||||
const res = await client
|
||||
.post("assistPlatform/create", {
|
||||
json: {
|
||||
corporationId: corporationId.trim(),
|
||||
applyMessage: message,
|
||||
assistTime: durationMs,
|
||||
},
|
||||
})
|
||||
.json<{
|
||||
value?: Record<string, unknown>;
|
||||
}>();
|
||||
|
||||
const val = res.value || {};
|
||||
return {
|
||||
id: String(val.id || ""),
|
||||
corporationId: String(val.corporationId || corporationId),
|
||||
applyMessage: String(val.applyMessage || message),
|
||||
assistTime: typeof val.assistTime === "number" ? val.assistTime : durationMs,
|
||||
userName: val.userName ? String(val.userName) : undefined,
|
||||
responsibleUserName: val.responsibleUserName ? String(val.responsibleUserName) : undefined,
|
||||
status: typeof val.status === "number" ? val.status : 0,
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof Error && (error.name === "AuthenticationError" || error.name === "BusinessError")) {
|
||||
throw error;
|
||||
}
|
||||
throw new EkbApiError(
|
||||
`发起协助工单申请失败: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import ky from "ky";
|
||||
import {
|
||||
applyAssistTicket,
|
||||
findStaff,
|
||||
generateAssistSession,
|
||||
getCorporationDetail,
|
||||
@@ -191,4 +192,30 @@ describe("domains/assist-platform - 协助平台业务编排", () => {
|
||||
expect(result.isAdmin).toBe(false);
|
||||
expect(result.staffId).toBe("Cxa3oOtQi2eS$g:2HQbkGx2DgnM00");
|
||||
});
|
||||
|
||||
it("applyAssistTicket 发起新的协助工单申请", async () => {
|
||||
const client = createMockClient(async (req) => {
|
||||
expect(req.url).toContain("assistPlatform/create");
|
||||
const body = (await req.json()) as any;
|
||||
expect(body.corporationId).toBe("ID01KrLMQJWdMH");
|
||||
expect(body.assistTime).toBe(86400000);
|
||||
return Response.json({
|
||||
value: {
|
||||
id: "ID01XelIEeCbw3",
|
||||
corporationId: "ID01KrLMQJWdMH",
|
||||
applyMessage: "测试环境接口联调",
|
||||
assistTime: 86400000,
|
||||
status: 0,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const res = await applyAssistTicket(client, {
|
||||
corporationId: "ID01KrLMQJWdMH",
|
||||
applyMessage: "测试环境接口联调",
|
||||
assistTime: 86400000,
|
||||
});
|
||||
expect(res.id).toBe("ID01XelIEeCbw3");
|
||||
expect(res.status).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -3,11 +3,14 @@ import { BusinessError, NotFoundError } from "../../core/errors.js";
|
||||
import { importFromLink, type ImportFromLinkOptions } from "../../core/auth/link-import.js";
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
import {
|
||||
createAssistTicketApi,
|
||||
getAssistTokenApi,
|
||||
getCorporationDetailApi,
|
||||
getStaffApi,
|
||||
searchAssistTicketsApi,
|
||||
searchCorporationsApi,
|
||||
type CreateAssistTicketApiParams,
|
||||
type CreateAssistTicketApiResponse,
|
||||
type SearchCorporationsApiParams,
|
||||
type SearchCorporationsApiResponse,
|
||||
} from "./api.js";
|
||||
@@ -48,6 +51,13 @@ export async function findStaff(
|
||||
return await getStaffApi(client, corpId, name);
|
||||
}
|
||||
|
||||
export async function applyAssistTicket(
|
||||
client: KyInstance,
|
||||
params: CreateAssistTicketApiParams
|
||||
): Promise<CreateAssistTicketApiResponse> {
|
||||
return await createAssistTicketApi(client, params);
|
||||
}
|
||||
|
||||
export interface GenerateAssistSessionParams {
|
||||
corpId: string;
|
||||
ticketId?: string;
|
||||
|
||||
Reference in new issue
Block a user