- 彻底移除旧内部狭隘命名与垫片包袱,一步到位全仓整体重命名: * 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 全部通过,类型检查零错误
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { getEasoClient } from "../../core/http/unity-easo-client.js";
|
|
import type { CorpConfig } from "../../core/config/types.js";
|
|
import { fetchStaffs } from "./api.js";
|
|
import type { ContactListResult, ContactSearchOptions, Staff } from "./types.js";
|
|
|
|
export const DEFAULT_STAFF_LIST_LIMIT = 20;
|
|
|
|
export async function listStaffsProtected(
|
|
corp: CorpConfig,
|
|
options: ContactSearchOptions = {}
|
|
): Promise<ContactListResult> {
|
|
const { client } = await getEasoClient(corp);
|
|
const allStaffs = await fetchStaffs(client, options.external ?? false);
|
|
|
|
const total = allStaffs.length;
|
|
const isFull = options.allowFull === true;
|
|
const limit = isFull ? total : options.limit ?? DEFAULT_STAFF_LIST_LIMIT;
|
|
const staffs = allStaffs.slice(0, limit);
|
|
const hasMore = total > staffs.length;
|
|
|
|
return {
|
|
total,
|
|
limit,
|
|
hasMore,
|
|
hint: hasMore
|
|
? `企业员工共 ${total} 人,当前仅展示前 ${staffs.length} 条以防止上下文溢出。可使用 'hose-use contact search <姓名|工号>' 精准检索,或附加 '--limit <数量>' / '-o <文件路径>' / '--full'`
|
|
: undefined,
|
|
staffs,
|
|
};
|
|
}
|
|
|
|
export async function searchStaffs(
|
|
corp: CorpConfig,
|
|
options: { keyword: string; limit?: number; external?: boolean }
|
|
): Promise<Staff[]> {
|
|
const { client } = await getEasoClient(corp);
|
|
const allStaffs = await fetchStaffs(client, options.external ?? false);
|
|
|
|
const kw = options.keyword.trim().toLowerCase();
|
|
if (!kw) {
|
|
return allStaffs.slice(0, options.limit ?? DEFAULT_STAFF_LIST_LIMIT);
|
|
}
|
|
|
|
const matched = allStaffs.filter((s) => {
|
|
const name = s.name?.toLowerCase() || "";
|
|
const email = s.email?.toLowerCase() || "";
|
|
const phone = s.cellphone || "";
|
|
const id = s.id?.toLowerCase() || "";
|
|
return name.includes(kw) || email.includes(kw) || phone.includes(kw) || id.includes(kw);
|
|
});
|
|
|
|
return matched.slice(0, options.limit ?? 50);
|
|
}
|
|
|
|
export async function getStaffById(
|
|
corp: CorpConfig,
|
|
staffId: string
|
|
): Promise<Staff | null> {
|
|
const { client } = await getEasoClient(corp);
|
|
const allStaffs = await fetchStaffs(client, false);
|
|
|
|
const cleanId = staffId.trim();
|
|
const found = allStaffs.find(
|
|
(s) => s.id === cleanId || s.id.endsWith(`:${cleanId}`) || s.id.split(":")[1] === cleanId
|
|
);
|
|
|
|
return found || null;
|
|
}
|