feat: release v0.5.2 with protected contact domain and bill web link
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled

This commit is contained in:
gitea committed 2026-09-03 15:58:20 +08:00
1 parent 188a0fb5dc
commit 68d570022d
19 files changed
+679 -146

No files matched your search

+62 -1
View File
@@ -195,7 +195,68 @@ export async function handleBillCommand(
};
}
case "link":
case "url": {
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id", "c"]);
if (!target) {
return {
stdout: "",
stderr: "用法: hose bill link <单号或ID>",
exitCode: 1,
};
}
const items = await getBillByCodeOrId(client, corpId, target);
if (!items || items.length === 0) {
return {
stdout: "",
stderr: `未找到单据: ${target}`,
exitCode: 1,
};
}
const item = items[0];
const billId = item.billId;
const billCode = item.billCode || target;
const baseUrl = (corp.baseUrl || "https://app.ekuaibao.com").replace(/\/+$/, "");
const webUrl = `${baseUrl}/#/invoice/detail?id=${encodeURIComponent(billId)}&corporationId=${encodeURIComponent(corpId)}`;
if (runtime.jsonMode) {
return {
stdout: printJson(
{
code: billCode,
id: billId,
corpId,
corpName: corp.name,
url: webUrl,
},
runtime.outputOptions
),
stderr: "",
exitCode: 0,
};
}
const text = [
`====== 合思单据 Web 直达链接 ======`,
` 单据编号: ${billCode}`,
` 单据 ID : ${billId}`,
` 所属企业: ${corp.name} (${corpId})`,
` 直达链接:`,
` ${webUrl}`,
``,
`Markdown 链接: [查看单据 ${billCode}](${webUrl})`,
].join("\n");
return {
stdout: text + "\n",
stderr: "",
exitCode: 0,
};
}
default:
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, schema`);
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, schema, link <单号>`);
}
}
+155
View File
@@ -0,0 +1,155 @@
import { numberOption, stringOption } from "../parser.js";
import { printJson, printKeyValue, printTable } from "../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import {
getStaffById,
listStaffsProtected,
searchStaffs,
DEFAULT_STAFF_LIST_LIMIT,
} from "../../domains/contact/tools.js";
export async function handleContactCommand(
parsed: CliParsedArgs,
runtime: CliRuntime
): Promise<CliResult> {
const corp = runtime.selectedCorp;
if (!corp) {
return {
stdout: "",
stderr: "未指定或未找到有效企业配置。请运行 'hose corps list' 或指定 '--corp=<id>'",
exitCode: 1,
};
}
const action = parsed.action || parsed.args[0] || "list";
const limit = numberOption(parsed.options, ["limit", "l"]);
// 1. 搜索: hose contact search <keyword> 或 hose contact find <keyword>
if (action === "search" || action === "find") {
const keyword = parsed.args[0] || stringOption(parsed.options, ["keyword", "query", "k"]) || "";
if (!keyword.trim()) {
return {
stdout: "",
stderr: "用法: hose contact search <关键词 (姓名/邮箱/工号)>",
exitCode: 1,
};
}
const results = await searchStaffs(corp, { keyword, limit });
if (runtime.jsonMode) {
return {
stdout: printJson({ count: results.length, keyword, staffs: results }, runtime.outputOptions),
stderr: "",
exitCode: 0,
};
}
if (results.length === 0) {
return {
stdout: `未找到匹配关键词 "${keyword}" 的员工。\n`,
stderr: "",
exitCode: 0,
};
}
const headers = ["姓名", "工号 / staffId", "邮箱", "手机号"];
const rows = results.map((s) => [
s.name || "-",
s.id,
s.email || "-",
s.cellphone || "-",
]);
return {
stdout: `====== 员工搜索结果 (关键词: "${keyword}", 找到 ${results.length} 人) ======\n${printTable(headers, rows)}\n`,
stderr: "",
exitCode: 0,
};
}
// 2. 详情: hose contact get <staffId>
if (action === "get") {
const staffId = parsed.args[0] || stringOption(parsed.options, ["id", "staff-id"]);
if (!staffId) {
return {
stdout: "",
stderr: "用法: hose contact get <staffId>",
exitCode: 1,
};
}
const staff = await getStaffById(corp, staffId);
if (!staff) {
return {
stdout: "",
stderr: `未找到员工档案: ${staffId}`,
exitCode: 1,
};
}
if (runtime.jsonMode) {
return {
stdout: printJson(staff, runtime.outputOptions),
stderr: "",
exitCode: 0,
};
}
const pairs: Record<string, unknown> = {
"员工姓名": staff.name,
"工号/staffId": staff.id,
"电子邮箱": staff.email || "-",
"联系手机": staff.cellphone || "-",
"所属部门": staff.department || "-",
};
return {
stdout: `====== 员工详细档案 ======\n${printKeyValue(pairs)}\n`,
stderr: "",
exitCode: 0,
};
}
// 3. 列表采样: hose contact list (默认限流截断防爆)
if (action === "list") {
const isFull = runtime.outputOptions?.allowFull === true;
const result = await listStaffsProtected(corp, {
limit: limit ?? (isFull ? undefined : DEFAULT_STAFF_LIST_LIMIT),
allowFull: isFull,
});
if (runtime.jsonMode) {
return {
stdout: printJson(result, runtime.outputOptions),
stderr: "",
exitCode: 0,
};
}
const headers = ["姓名", "工号 / staffId", "邮箱", "手机号"];
const rows = result.staffs.map((s) => [
s.name || "-",
s.id,
s.email || "-",
s.cellphone || "-",
]);
let output = `====== 企业通讯录采样 (共 ${result.total} 人,当前显示 ${result.staffs.length} 条) ======\n`;
output += printTable(headers, rows) + "\n";
if (result.hint) {
output += `\n💡 提示: ${result.hint}\n`;
}
return {
stdout: output,
stderr: "",
exitCode: 0,
};
}
return {
stdout: "",
stderr: `未知通讯录子命令: ${action}。支持的子命令: list, search <关键词>, get <staffId>`,
exitCode: 1,
};
}