- Add SSO QR status poller and assist platform HTTP client - Add assist-platform session store with 0600 secure permissions - Implement domains/assist-platform (api, services, types) for corporation search, detail, tickets, staff query and passwordless token generation - Implement cli/commands/assist-platform with aliases assist-center and ap - Support seamless --save --switch --elevate pipeline to import tenant and extract persistent OpenAPI credentials - Update embedded skill documentation, reference guide, and test suites
101 lines
3.2 KiB
TypeScript
101 lines
3.2 KiB
TypeScript
import {
|
|
loadAssistPlatformSession,
|
|
saveAssistPlatformSession,
|
|
clearAssistPlatformSession,
|
|
} from "../../../core/auth/assist-platform-store.js";
|
|
import { createAssistPlatformClient } from "../../../core/http/assist-platform-client.js";
|
|
import { searchCorporations } from "../../../domains/assist-platform/services.js";
|
|
import { booleanOption, stringOption } from "../../parser.js";
|
|
import { printJson, printKeyValue } from "../../printer.js";
|
|
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
|
|
|
export async function handleLogin(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime
|
|
): Promise<CliResult> {
|
|
const logout = booleanOption(parsed.options, ["logout"]);
|
|
if (logout) {
|
|
clearAssistPlatformSession();
|
|
return {
|
|
stdout: "[SUCCESS] 已成功注销并清理协助平台本地会话。\n",
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
const explicitToken = stringOption(parsed.options, ["token", "t"]);
|
|
const userName = stringOption(parsed.options, ["user", "name", "u"]);
|
|
const hoseAccessToken = stringOption(parsed.options, ["hose-token", "jwt"]);
|
|
|
|
if (explicitToken) {
|
|
// 验证 Token 连通性
|
|
const testClient = createAssistPlatformClient({
|
|
token: explicitToken,
|
|
hoseAccessToken,
|
|
});
|
|
try {
|
|
await searchCorporations(testClient, { limit: { start: 0, count: 1 } });
|
|
} catch (err) {
|
|
return {
|
|
stdout: "",
|
|
stderr: `[ERROR] 协助平台 Token 校验失败: ${err instanceof Error ? err.message : String(err)}\n`,
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
saveAssistPlatformSession({
|
|
token: explicitToken,
|
|
hoseAccessToken,
|
|
userName: userName || "运营实施人员",
|
|
baseUrl: "https://unity.ekuaibao.com/api",
|
|
updatedAt: Date.now(),
|
|
});
|
|
|
|
if (runtime.jsonMode) {
|
|
return {
|
|
stdout: printJson({ success: true, token: explicitToken, userName }),
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
return {
|
|
stdout: `[SUCCESS] 协助平台登录凭证保存成功!\n操作人员: ${userName || "运营人员"}\n会话 Token: ${explicitToken}\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
// 查看当前协助平台会话状态
|
|
const existing = loadAssistPlatformSession();
|
|
if (!existing || !existing.token) {
|
|
return {
|
|
stdout: "",
|
|
stderr: `未检测到协助平台登录凭证。\n用法:\n hose-use assist-platform login --token <TOKEN> [--user <姓名>]\n hose-use assist-platform login --logout (清理凭证)\n`,
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
if (runtime.jsonMode) {
|
|
return {
|
|
stdout: printJson(existing),
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
const pairs: Record<string, string> = {
|
|
协助平台状态: "🟢 已登录",
|
|
操作员工姓名: existing.userName || "运营实施人员",
|
|
基础服务地址: existing.baseUrl || "https://unity.ekuaibao.com/api",
|
|
当前会话凭证: existing.token.replace(/(.{4}).*(.{4})/, "$1****$2"),
|
|
最后更新时间: new Date(existing.updatedAt).toLocaleString("zh-CN", { hour12: false }),
|
|
};
|
|
|
|
return {
|
|
stdout: `====== 合思协助平台当前会话 ======\n${printKeyValue(pairs)}\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|