Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f510efc1b |
No files matched your search
@@ -1,4 +1,4 @@
|
||||
# hose-use (v0.3.0)
|
||||
# hose-use (v0.3.1)
|
||||
|
||||
合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
openapi: 3.1.0
|
||||
info:
|
||||
title: hose-use API & MCP Tools Specification
|
||||
version: 0.3.0
|
||||
version: 0.3.1
|
||||
description: >-
|
||||
Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows.
|
||||
servers:
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hose-use",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"module": "src/server.ts",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
fullSmsLogin,
|
||||
fullBrowserSyncLogin,
|
||||
sendSmsVerificationCode,
|
||||
importCredentials,
|
||||
importF12Credentials,
|
||||
parseHeadersOrCurl,
|
||||
refreshAccountCorporations,
|
||||
@@ -14,7 +15,7 @@ import {
|
||||
} from "../../core/auth/account-store.js";
|
||||
import { createEkbClient } from "../../core/auth/ekb.js";
|
||||
import { stringOption, booleanOption } from "../parser.js";
|
||||
import { printJson, printKeyValue, printTable } from "../printer.js";
|
||||
import { printJson, printKeyValue, printTable, formatSourceLabel, formatExpiresAt } from "../printer.js";
|
||||
import { prompt } from "../helpers.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
||||
|
||||
@@ -171,13 +172,41 @@ async function handleStatus(parsed: CliParsedArgs, runtime: CliRuntime): Promise
|
||||
return { stdout: printJson(statusObj), stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
const summary = printKeyValue({
|
||||
const pairs: Record<string, unknown> = {
|
||||
"当前活跃账号": activeAccount?.accountId || "未登录",
|
||||
"当前激活企业": currentCorp ? `${currentCorp.name} (${currentCorp.id})` : "未配置",
|
||||
"当前员工工号": currentCorp?.credentials.staffId || "-",
|
||||
"凭证来源类型": currentCorp?.source || "-",
|
||||
"员工真实姓名": currentCorp?.staffName || currentCorp?.session?.staffName || "-",
|
||||
"凭证来源类型": formatSourceLabel(currentCorp?.source),
|
||||
"Token 有效性": sessionValid ? "✅ 有效 (已通过 Session 验证)" : "❌ 无效或未连接",
|
||||
});
|
||||
"Token 过期时间": formatExpiresAt(currentCorp?.auth?.expiresAt || currentCorp?.session?.expTime),
|
||||
};
|
||||
|
||||
if (currentCorp?.session) {
|
||||
if (currentCorp.session.loginTime) {
|
||||
pairs["会话创建时间"] = new Date(currentCorp.session.loginTime).toLocaleString("zh-CN", { hour12: false });
|
||||
}
|
||||
if (currentCorp.session.platform) {
|
||||
pairs["官方平台类型"] = currentCorp.session.platform;
|
||||
}
|
||||
if (currentCorp.session.isAssistPlatform) {
|
||||
pairs["协助调试模式"] = "是 (Assist Platform)";
|
||||
if (currentCorp.session.operationUserName || currentCorp.session.operationUserId) {
|
||||
pairs["协助操作人员"] = `${currentCorp.session.operationUserName || ""} (${currentCorp.session.operationUserId || ""})`.trim();
|
||||
}
|
||||
if (currentCorp.session.assistId) {
|
||||
pairs["协助会话 ID"] = currentCorp.session.assistId;
|
||||
}
|
||||
}
|
||||
if (currentCorp.session.cellphone) {
|
||||
pairs["绑定手机号码"] = currentCorp.session.cellphone;
|
||||
}
|
||||
if (currentCorp.session.isAdmin !== undefined) {
|
||||
pairs["是否企业管理"] = currentCorp.session.isAdmin ? "是" : "否";
|
||||
}
|
||||
}
|
||||
|
||||
const summary = printKeyValue(pairs);
|
||||
|
||||
return {
|
||||
stdout: `====== 当前登录与企业状态 ======\n${summary}\n`,
|
||||
@@ -209,7 +238,7 @@ async function handleImport(parsed: CliParsedArgs, runtime: CliRuntime): Promise
|
||||
let name = stringOption(parsed.options, ["name"]);
|
||||
|
||||
if (!raw && !accessToken) {
|
||||
raw = await prompt("请粘贴 F12 抓包文本 / cURL 命令行 (直接回车则手动逐项输入): ");
|
||||
raw = await prompt("请粘贴抓包文本 / cURL 命令行 (直接回车则手动逐项输入): ");
|
||||
}
|
||||
|
||||
if (raw) {
|
||||
@@ -227,7 +256,7 @@ async function handleImport(parsed: CliParsedArgs, runtime: CliRuntime): Promise
|
||||
return { stdout: "", stderr: "accessToken, corpId, staffId 均为必填!\n", exitCode: 1 };
|
||||
}
|
||||
|
||||
const imported = await importF12Credentials({
|
||||
const imported = await importCredentials({
|
||||
accessToken,
|
||||
corpId,
|
||||
staffId,
|
||||
@@ -238,8 +267,30 @@ async function handleImport(parsed: CliParsedArgs, runtime: CliRuntime): Promise
|
||||
return { stdout: printJson(imported), stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
const summaryPairs: Record<string, unknown> = {
|
||||
"企业名称": imported.name,
|
||||
"企业 ID": imported.id,
|
||||
"员工工号": imported.credentials.staffId,
|
||||
"员工姓名": imported.staffName || imported.session?.staffName || "-",
|
||||
"凭证来源": formatSourceLabel(imported.source),
|
||||
"过期时间": formatExpiresAt(imported.auth?.expiresAt || imported.session?.expTime),
|
||||
"保存路径": `enterprises/${imported.id}.json`,
|
||||
};
|
||||
|
||||
if (imported.session?.isAssistPlatform) {
|
||||
summaryPairs["协助平台"] = "是 (Assist Platform 调试授权)";
|
||||
if (imported.session.operationUserName || imported.session.operationUserId) {
|
||||
summaryPairs["协助操作人"] = `${imported.session.operationUserName || ""} (${imported.session.operationUserId || ""})`.trim();
|
||||
}
|
||||
if (imported.session.assistId) {
|
||||
summaryPairs["协助会话 ID"] = imported.session.assistId;
|
||||
}
|
||||
}
|
||||
|
||||
const summaryText = printKeyValue(summaryPairs);
|
||||
|
||||
return {
|
||||
stdout: `[SUCCESS] 成功导入并保存企业凭证!\n企业名称: ${imported.name}\n企业 ID: ${imported.id}\n员工工号: ${imported.credentials.staffId}\n保存路径: enterprises/${imported.id}.json\n`,
|
||||
stdout: `[SUCCESS] 成功导入并保存企业凭证!\n${summaryText}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { printJson, printKeyValue, printTable } from "../printer.js";
|
||||
import { printJson, printKeyValue, printTable, formatSourceLabel, formatExpiresAt } from "../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
||||
|
||||
export async function handleCorpsCommand(
|
||||
@@ -48,11 +48,12 @@ async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Promise<C
|
||||
c.name,
|
||||
c.staffId,
|
||||
c.source || "manual",
|
||||
formatExpiresAt(c.expiresAt),
|
||||
c.accountId || "-",
|
||||
]);
|
||||
|
||||
const table = printTable(
|
||||
["#", "企业 ID", "企业名称", "员工工号", "来源", "所属账号"],
|
||||
["#", "企业 ID", "企业名称", "员工工号", "来源", "Token 过期时间", "所属账号"],
|
||||
rows
|
||||
);
|
||||
|
||||
@@ -100,14 +101,42 @@ async function handleCurrent(parsed: CliParsedArgs, runtime: CliRuntime): Promis
|
||||
return { stdout: printJson(current), stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
const output = printKeyValue({
|
||||
const pairs: Record<string, unknown> = {
|
||||
"企业 ID": current.id,
|
||||
"企业名称": current.name,
|
||||
"员工工号": current.credentials.staffId,
|
||||
"来源类型": current.source || "manual",
|
||||
"员工姓名": current.staffName || current.session?.staffName || "-",
|
||||
"凭证来源": formatSourceLabel(current.source),
|
||||
"Token 过期时间": formatExpiresAt(current.auth?.expiresAt || current.session?.expTime),
|
||||
"所属账号": current.accountId || "-",
|
||||
"主站地址": current.baseUrl || "https://app.ekuaibao.com",
|
||||
});
|
||||
};
|
||||
|
||||
if (current.session) {
|
||||
if (current.session.loginTime) {
|
||||
pairs["会话创建时间"] = new Date(current.session.loginTime).toLocaleString("zh-CN", { hour12: false });
|
||||
}
|
||||
if (current.session.platform) {
|
||||
pairs["官方平台类型"] = current.session.platform;
|
||||
}
|
||||
if (current.session.isAssistPlatform) {
|
||||
pairs["协助登录模式"] = "是 (Assist Platform)";
|
||||
if (current.session.operationUserName || current.session.operationUserId) {
|
||||
pairs["协助操作人员"] = `${current.session.operationUserName || ""} (${current.session.operationUserId || ""})`.trim();
|
||||
}
|
||||
if (current.session.assistId) {
|
||||
pairs["协助会话 ID"] = current.session.assistId;
|
||||
}
|
||||
}
|
||||
if (current.session.cellphone) {
|
||||
pairs["绑定手机号码"] = current.session.cellphone;
|
||||
}
|
||||
if (current.session.isAdmin !== undefined) {
|
||||
pairs["是否企业管理"] = current.session.isAdmin ? "是" : "否";
|
||||
}
|
||||
}
|
||||
|
||||
const output = printKeyValue(pairs);
|
||||
|
||||
return {
|
||||
stdout: `====== 当前激活企业 ======\n${output}\n`,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createClientsForCorp } from "../helpers.js";
|
||||
import * as api from "../../domains/platform/api.js";
|
||||
import { printJson, printKeyValue } from "../printer.js";
|
||||
import { printJson, printKeyValue, formatSourceLabel, formatExpiresAt } from "../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
||||
|
||||
export async function handleProbeCommand(
|
||||
@@ -79,14 +79,26 @@ export async function handleProbeCommand(
|
||||
return { stdout: printJson(results), stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
const summary = printKeyValue({
|
||||
const probePairs: Record<string, unknown> = {
|
||||
"企业名称": currentCorp.name,
|
||||
"企业 ID": currentCorp.id,
|
||||
"员工工号": currentCorp.credentials.staffId,
|
||||
"员工姓名": currentCorp.staffName || currentCorp.session?.staffName || "-",
|
||||
"凭证来源": formatSourceLabel(currentCorp.source),
|
||||
"Token 过期时间": formatExpiresAt(currentCorp.auth?.expiresAt || currentCorp.session?.expTime),
|
||||
"主站 Session 连通": (results.ekbSession as any).status === "ok" ? "🟢 正常" : "🔴 异常",
|
||||
"EASO 引擎鉴权换票": (results.easoToken as any).status === "ok" ? "🟢 握手成功" : "🔴 失败",
|
||||
"自建应用扫描": (results.platformAccess as any).status === "ok" ? `🟢 可访问 (${(results.platformAccess as any).totalPlatforms} 个自建应用)` : "🔴 失败",
|
||||
});
|
||||
};
|
||||
|
||||
if (currentCorp.session?.isAssistPlatform) {
|
||||
probePairs["协助操作人"] = `${currentCorp.session.operationUserName || ""} (${currentCorp.session.operationUserId || ""})`.trim();
|
||||
if (currentCorp.session.assistId) {
|
||||
probePairs["协助会话 ID"] = currentCorp.session.assistId;
|
||||
}
|
||||
}
|
||||
|
||||
const summary = printKeyValue(probePairs);
|
||||
|
||||
return {
|
||||
stdout: `====== 诊断结果 (Enterprise Probe) ======\n${summary}\n`,
|
||||
|
||||
@@ -4,6 +4,43 @@ export function printJson(data: unknown): string {
|
||||
return JSON.stringify(data, null, 2);
|
||||
}
|
||||
|
||||
export function formatSourceLabel(source?: string): string {
|
||||
switch (source) {
|
||||
case "assist":
|
||||
return "官方协助/代客平台 (Assist Platform)";
|
||||
case "account":
|
||||
return "统一认证中心 (IDP 账密/短信)";
|
||||
case "browser":
|
||||
return "浏览器会话同步 (WebBridge)";
|
||||
case "curl":
|
||||
case "f12":
|
||||
return "cURL 抓包导入 (cURL/F12)";
|
||||
case "manual":
|
||||
return "手动配置";
|
||||
default:
|
||||
return source || "未知来源";
|
||||
}
|
||||
}
|
||||
|
||||
export function formatExpiresAt(expiresAt?: number): string {
|
||||
if (!expiresAt || expiresAt <= 0) return "长期有效 / 服务端未显式限制";
|
||||
const diffMs = expiresAt - Date.now();
|
||||
const dateStr = new Date(expiresAt).toLocaleString("zh-CN", { hour12: false });
|
||||
if (diffMs <= 0) {
|
||||
return `${dateStr} (⚠️ 已过期)`;
|
||||
}
|
||||
const diffMins = Math.floor(diffMs / 60000);
|
||||
if (diffMins < 60) {
|
||||
return `${dateStr} (约剩余 ${diffMins} 分钟)`;
|
||||
}
|
||||
const diffHours = (diffMs / 3600000).toFixed(1);
|
||||
if (Number(diffHours) < 24) {
|
||||
return `${dateStr} (约剩余 ${diffHours} 小时)`;
|
||||
}
|
||||
const diffDays = Math.floor(diffMs / 86400000);
|
||||
return `${dateStr} (约剩余 ${diffDays} 天)`;
|
||||
}
|
||||
|
||||
export function printKeyValue(pairs: Record<string, unknown>): string {
|
||||
const lines: string[] = [];
|
||||
const maxKeyLen = Math.max(...Object.keys(pairs).map((k) => k.length), 0);
|
||||
|
||||
+148
-7
@@ -263,13 +263,35 @@ export function parseHeadersOrCurl(rawInput: string): Partial<F12ImportParams> {
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 从 URL 中提取 query 参数(例如 ?corpId=xxx 或 &corpId=xxx)
|
||||
if (!result.corpId) {
|
||||
const urlCorpMatch = /(?:[?&]corpId=)([^&'"\s]+)/i.exec(rawInput);
|
||||
if (urlCorpMatch) {
|
||||
result.corpId = decodeURIComponent(urlCorpMatch[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 从 Cookie (-b / Cookie header) 中提取 ekb-access-token 或 corpId
|
||||
if (!result.accessToken) {
|
||||
const cookieTokenMatch = /ekb-access-token=([^;'"\s]+)/i.exec(rawInput);
|
||||
if (cookieTokenMatch) {
|
||||
result.accessToken = decodeURIComponent(cookieTokenMatch[1]);
|
||||
}
|
||||
}
|
||||
if (!result.corpId) {
|
||||
const cookieCorpMatch = /(?:^|;\s*)corpId=([^;'"\s]+)/i.exec(rawInput);
|
||||
if (cookieCorpMatch) {
|
||||
result.corpId = decodeURIComponent(cookieCorpMatch[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并导入单个 F12 抓包/手动凭证,保存到企业配置
|
||||
* 校验并导入单个抓包/手动凭证,自动探测官方 Session 平台类型并保存到企业配置
|
||||
*/
|
||||
export async function importF12Credentials(
|
||||
export async function importCredentials(
|
||||
params: F12ImportParams
|
||||
): Promise<CorpConfig> {
|
||||
const { accessToken, corpId, staffId } = params;
|
||||
@@ -279,8 +301,25 @@ export async function importF12Credentials(
|
||||
throw new AuthenticationError("导入凭证失败:accessToken、corpId、staffId 均为必填项");
|
||||
}
|
||||
|
||||
// 验证凭证有效性并尝试自动获取企业名称
|
||||
let corpName = params.name;
|
||||
// 1. 验证凭证有效性并提取官方服务端 Session 元数据
|
||||
let sessionData: {
|
||||
id?: string;
|
||||
userId?: string;
|
||||
loginStaffId?: string;
|
||||
corporationId?: string;
|
||||
platform?: string;
|
||||
isAssistPlatform?: boolean;
|
||||
isShortTermToken?: boolean;
|
||||
assistId?: string;
|
||||
operationUserId?: string;
|
||||
operationUserName?: string;
|
||||
privilege?: string;
|
||||
deviceType?: string;
|
||||
loginAccountType?: string;
|
||||
loginTime?: number;
|
||||
expTime?: number;
|
||||
} | undefined;
|
||||
|
||||
try {
|
||||
const res = await ky
|
||||
.get(`${baseUrl}/api/account/v2/session`, {
|
||||
@@ -290,20 +329,102 @@ export async function importF12Credentials(
|
||||
staffid: staffId,
|
||||
},
|
||||
})
|
||||
.json<{ value?: { corporationId?: string; loginStaffId?: string; expTime?: number } }>();
|
||||
.json<{
|
||||
value?: {
|
||||
id?: string;
|
||||
userId?: string;
|
||||
loginStaffId?: string;
|
||||
corporationId?: string;
|
||||
platform?: string;
|
||||
isAssistPlatform?: boolean;
|
||||
isShortTermToken?: boolean;
|
||||
assistId?: string;
|
||||
operationUserId?: string;
|
||||
operationUserName?: string;
|
||||
privilege?: string;
|
||||
deviceType?: string;
|
||||
loginAccountType?: string;
|
||||
loginTime?: number;
|
||||
expTime?: number;
|
||||
};
|
||||
}>();
|
||||
|
||||
if (!res.value?.corporationId) {
|
||||
sessionData = res.value;
|
||||
if (!sessionData || (!sessionData.corporationId && !sessionData.id && !sessionData.userId)) {
|
||||
throw new Error("服务端未返回有效 Session");
|
||||
}
|
||||
} catch (err) {
|
||||
throw new AuthenticationError(`凭证校验失败,请检查 token 是否已过期: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
|
||||
// 2. 尝试通过 $UNITY JWT 获取真实企业名称与员工详细信息 (如果未手动指定)
|
||||
let corpName = params.name;
|
||||
let staffName = sessionData?.privilege;
|
||||
let cellphone: string | undefined;
|
||||
let isAdmin: boolean | undefined;
|
||||
let sourceChannel: string | undefined;
|
||||
let jwtExpMs: number | undefined;
|
||||
|
||||
try {
|
||||
const jwtRes = await ky
|
||||
.get(`${baseUrl}/api/engine/realm/$UNITY/actions/jwt`, {
|
||||
searchParams: { corpId },
|
||||
headers: {
|
||||
accesstoken: accessToken,
|
||||
corpid: corpId,
|
||||
staffid: staffId,
|
||||
},
|
||||
})
|
||||
.json<{ id?: string; value?: string }>();
|
||||
const token = jwtRes.id || jwtRes.value;
|
||||
if (token) {
|
||||
const parts = token.split(".");
|
||||
if (parts.length >= 2) {
|
||||
const payload = JSON.parse(Buffer.from(parts[1], "base64").toString("utf-8"));
|
||||
if (!corpName && payload.corporationName) {
|
||||
corpName = payload.corporationName;
|
||||
}
|
||||
if (payload.staffName) {
|
||||
staffName = payload.staffName;
|
||||
}
|
||||
if (payload.cellphone) {
|
||||
cellphone = payload.cellphone;
|
||||
}
|
||||
if (payload.isAdmin !== undefined) {
|
||||
isAdmin = payload.isAdmin === "true" || payload.isAdmin === true;
|
||||
}
|
||||
if (payload.exp) {
|
||||
jwtExpMs = Number(payload.exp) * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// 忽略尝试获取企业名失败
|
||||
}
|
||||
|
||||
// 3. 智能判断语义化凭证来源
|
||||
let source: import("../config/types.js").CredentialSource = "curl";
|
||||
if (sessionData?.isAssistPlatform || sessionData?.platform === "ASSIST") {
|
||||
source = "assist";
|
||||
}
|
||||
|
||||
// 4. 计算 Token 过期时间戳 (ms)
|
||||
let expiresAt: number | undefined;
|
||||
if (sessionData?.expTime && sessionData.expTime > 0) {
|
||||
expiresAt = sessionData.expTime;
|
||||
} else if (jwtExpMs && jwtExpMs > 0) {
|
||||
expiresAt = jwtExpMs;
|
||||
} else if (sessionData?.isAssistPlatform && sessionData?.loginTime) {
|
||||
// 协助平台短期调试 Token 通常 2 小时有效
|
||||
expiresAt = sessionData.loginTime + 2 * 3600 * 1000;
|
||||
}
|
||||
|
||||
const corpConfig: CorpConfig = {
|
||||
id: corpId,
|
||||
name: corpName || `企业-${corpId}`,
|
||||
baseUrl,
|
||||
source: "f12",
|
||||
source,
|
||||
staffName,
|
||||
credentials: {
|
||||
accessToken,
|
||||
corpId,
|
||||
@@ -311,6 +432,23 @@ export async function importF12Credentials(
|
||||
},
|
||||
auth: {
|
||||
refreshTtl: 300,
|
||||
expiresAt,
|
||||
},
|
||||
session: {
|
||||
platform: sessionData?.platform,
|
||||
isAssistPlatform: sessionData?.isAssistPlatform,
|
||||
isShortTermToken: sessionData?.isShortTermToken,
|
||||
assistId: sessionData?.assistId,
|
||||
operationUserId: sessionData?.operationUserId,
|
||||
operationUserName: sessionData?.operationUserName,
|
||||
staffName,
|
||||
cellphone,
|
||||
isAdmin,
|
||||
deviceType: sessionData?.deviceType,
|
||||
loginAccountType: sessionData?.loginAccountType,
|
||||
loginTime: sessionData?.loginTime,
|
||||
expTime: expiresAt || sessionData?.expTime,
|
||||
sourceChannel,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -318,6 +456,9 @@ export async function importF12Credentials(
|
||||
return corpConfig;
|
||||
}
|
||||
|
||||
// 保持历史命名兼容
|
||||
export const importF12Credentials = importCredentials;
|
||||
|
||||
// ── 企业管理与主站 OAuth2 令牌换取 ─────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@ export interface CorpSummary {
|
||||
staffId: string;
|
||||
baseUrl?: string;
|
||||
current: boolean;
|
||||
expiresAt?: number;
|
||||
}
|
||||
|
||||
export function resolveCorpConfig(
|
||||
@@ -145,6 +146,7 @@ export class CorpContext {
|
||||
staffId: corp.credentials.staffId,
|
||||
baseUrl: corp.baseUrl,
|
||||
current: corp.id === this.current?.id,
|
||||
expiresAt: corp.auth?.expiresAt || corp.session?.expTime,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,13 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const CredentialSourceSchema = z.enum(["account", "manual", "browser", "f12"]);
|
||||
export const CredentialSourceSchema = z.enum([
|
||||
"account", // 官方统一认证中心 (IDP) 账密/短信登录
|
||||
"assist", // 官方协助/代客平台 (Assist Platform) 调试授权会话
|
||||
"browser", // 浏览器会话 / Cookie 同步
|
||||
"manual", // 手动配置
|
||||
"curl", // cURL 抓包 / HTTP Headers 导入
|
||||
"f12", // 兼容旧版抓包标识
|
||||
]);
|
||||
export type CredentialSource = z.infer<typeof CredentialSourceSchema>;
|
||||
|
||||
export const CorpCredentialsSchema = z.object({
|
||||
@@ -15,17 +22,37 @@ export const CorpAuthConfigSchema = z.object({
|
||||
expiresAt: z.number().optional().describe("AccessToken 到期时间戳 (ms)"),
|
||||
});
|
||||
|
||||
export const CorpSessionInfoSchema = z.object({
|
||||
platform: z.string().optional().describe("官方会话平台类型 (如 ASSIST, WEB, MOBILE, OPENAPI)"),
|
||||
isAssistPlatform: z.boolean().optional().describe("是否为官方协助/代客平台登录"),
|
||||
isShortTermToken: z.boolean().optional().describe("是否为短期临时 Token"),
|
||||
assistId: z.string().optional().describe("协助会话/工单 ID"),
|
||||
operationUserId: z.string().optional().describe("协助操作人 ID (如内部运维/实施账号)"),
|
||||
operationUserName: z.string().optional().describe("协助操作人姓名"),
|
||||
staffName: z.string().optional().describe("当前员工真实姓名"),
|
||||
cellphone: z.string().optional().describe("绑定手机号"),
|
||||
isAdmin: z.boolean().optional().describe("是否管理员"),
|
||||
deviceType: z.string().optional().describe("设备类型"),
|
||||
loginAccountType: z.string().optional().describe("登录账号类型"),
|
||||
loginTime: z.number().optional().describe("登录时间戳 (ms)"),
|
||||
expTime: z.number().optional().describe("过期时间戳 (ms)"),
|
||||
sourceChannel: z.string().optional().describe("来源渠道 (如 APP, WEB)"),
|
||||
});
|
||||
export type CorpSessionInfo = z.infer<typeof CorpSessionInfoSchema>;
|
||||
|
||||
export const CorpConfigSchema = z.object({
|
||||
id: z.string().describe("配置/身份唯一标识 (默认等于 corpId,同企业多身份时形如 corpId@accountId 或 corpId:staffId)"),
|
||||
name: z.string().describe("企业名称"),
|
||||
corpId: z.string().optional().describe("底层企业物理 ID (未填时默认等于 id)"),
|
||||
userId: z.string().optional().describe("所属用户 ID"),
|
||||
staffId: z.string().optional().describe("员工工号 (默认取 credentials.staffId)"),
|
||||
staffName: z.string().optional().describe("员工真实姓名"),
|
||||
baseUrl: z.string().url().optional().default("https://app.ekuaibao.com"),
|
||||
source: CredentialSourceSchema.optional().default("manual").describe("凭证来源: account/manual/browser/f12"),
|
||||
source: CredentialSourceSchema.optional().default("manual").describe("凭证来源: account/assist/browser/manual/curl/f12"),
|
||||
accountId: z.string().optional().describe("所属主账号标识(如手机号)"),
|
||||
credentials: CorpCredentialsSchema,
|
||||
auth: CorpAuthConfigSchema.optional(),
|
||||
session: CorpSessionInfoSchema.optional().describe("官方服务端 Session 与操作人元数据"),
|
||||
});
|
||||
|
||||
export type CorpCredentials = z.infer<typeof CorpCredentialsSchema>;
|
||||
|
||||
@@ -11,6 +11,53 @@ import {
|
||||
import { CorpContext } from "../../core/config/manager.js";
|
||||
import { createEkbClient } from "../../core/auth/ekb.js";
|
||||
|
||||
// ── 通用内置字段中文 Label 字典 ───────────────────────────────────────────────
|
||||
|
||||
const COMMON_FIELD_LABELS: Record<string, string> = {
|
||||
code: "单据编号",
|
||||
name: "单据名称",
|
||||
stage: "业务阶段",
|
||||
state: "审批状态",
|
||||
title: "单据标题",
|
||||
amount: "单据金额",
|
||||
expenseMoney: "报销金额",
|
||||
payMoney: "支付金额",
|
||||
apportionMoney: "分摊金额",
|
||||
submitDate: "提交时间",
|
||||
submitterId: "提交人ID",
|
||||
ownerId: "归属人ID",
|
||||
description: "事由说明",
|
||||
detailType: "明细类型",
|
||||
entityType: "实体类型",
|
||||
settleStatus: "结算状态",
|
||||
settleTime: "结算时间",
|
||||
billingStatus: "开票状态",
|
||||
voucherStatus: "凭证状态",
|
||||
voucherCreateTime: "凭证生成时间",
|
||||
writtenOffAmount: "已核销金额",
|
||||
unwrittenOffAmount: "未核销金额",
|
||||
linkType: "关联类型",
|
||||
linkId: "关联审批流ID",
|
||||
detailId: "明细ID",
|
||||
detailNo: "明细序号",
|
||||
feeTypeId: "费用类型ID",
|
||||
attachments: "附件列表",
|
||||
invoiceForm: "发票表单",
|
||||
submitCount: "提交次数",
|
||||
rejectionNum: "驳回次数",
|
||||
reviewStatus: "审核状态",
|
||||
preApprovedNodeName: "上一审批节点",
|
||||
preNodeApprovedTime: "节点审批通过时间",
|
||||
accountPropertyMoney: "核算属性金额",
|
||||
accountPropertyDate: "核算属性日期",
|
||||
flowSpecificationId: "流程规范ID",
|
||||
feeDetailSpecificationId: "费用明细规范ID",
|
||||
printState: "打印状态",
|
||||
printCount: "打印次数",
|
||||
onlyOwnerPrint: "仅提交人可打印",
|
||||
ownerAndApproverPrintNodeFlag: "节点打印控制标识",
|
||||
};
|
||||
|
||||
// ── 字段元数据内存缓存 ─────────────────────────────────────────────────────────
|
||||
|
||||
const schemaCache = new Map<string, { timestamp: number; dictionary: Map<string, { label: string; type: string }>; entities: EntityMeta[] }>();
|
||||
@@ -88,10 +135,8 @@ export function formatSingleBill(
|
||||
|
||||
// 字典 Label 还原
|
||||
const meta = dictionary.get(k);
|
||||
let readableKey = meta ? meta.label : k.replace(/^E_[^_]+_/, "");
|
||||
if (readableKey.startsWith("E_")) {
|
||||
readableKey = readableKey.replace(/^E_/, "");
|
||||
}
|
||||
const bareKey = k.replace(/^E_[^_]+_/, "").replace(/^E_/, "");
|
||||
let readableKey = meta ? meta.label : (COMMON_FIELD_LABELS[k] || COMMON_FIELD_LABELS[bareKey] || bareKey);
|
||||
|
||||
// 格式化字段值
|
||||
let formattedVal = v;
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
export const VERSION = "0.3.0";
|
||||
export const VERSION = "0.3.1";
|
||||
Reference in new issue
Block a user