refactor(core): 全量语义化客户端迁移并移除历史兼容桥接层
This commit is contained in:
1 parent
29ac24248e
commit
d0f3d2738a
34 files changed
+89
-141
No files matched your search
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* @deprecated 兼容历史导出。请优先从 "src/core/http/index.js" 导入 getUnityClient 与 getEasoClient
|
||||
*/
|
||||
export {
|
||||
resolveCorpCluster,
|
||||
fetchUnityJwt,
|
||||
fetchHoseToken,
|
||||
fetchEasoRealmToken,
|
||||
getEasoClient,
|
||||
getUnityClient,
|
||||
EASO_BASE_URL,
|
||||
BUSINESS_CENTER_URL,
|
||||
EKB_BASE_URL,
|
||||
} from "../http/unity-client.js";
|
||||
@@ -1,52 +0,0 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { canRefreshCorpAccessToken, resolveLinkExpiresAt } from "./login.js";
|
||||
import { createEkbClient } from "./ekb.js";
|
||||
import type { CorpConfig } from "../config/types.js";
|
||||
|
||||
function corp(overrides: Partial<CorpConfig> = {}): CorpConfig {
|
||||
return {
|
||||
id: "corp-1",
|
||||
name: "测试企业",
|
||||
source: "link",
|
||||
credentials: { accessToken: "token", corpId: "corp-1", staffId: "staff-1" },
|
||||
...overrides,
|
||||
baseUrl: overrides.baseUrl ?? "https://app.ekuaibao.com",
|
||||
};
|
||||
}
|
||||
|
||||
describe("core/auth/ekb refresh policy", () => {
|
||||
it("only allows account credentials with an explicit account binding to refresh", () => {
|
||||
expect(canRefreshCorpAccessToken(corp())).toBe(false);
|
||||
expect(canRefreshCorpAccessToken(corp({ source: "browser", accountId: "86-1" }))).toBe(false);
|
||||
expect(canRefreshCorpAccessToken(corp({ source: "account" }))).toBe(false);
|
||||
expect(canRefreshCorpAccessToken(corp({ source: "account", accountId: "86-1" }))).toBe(true);
|
||||
expect(canRefreshCorpAccessToken(corp({ source: "account", accountId: "86-1", session: { isShortTermToken: true } }))).toBe(false);
|
||||
});
|
||||
|
||||
it("fails expired temporary credentials without retrying or refreshing", async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
let calls = 0;
|
||||
globalThis.fetch = (async () => {
|
||||
calls += 1;
|
||||
return new Response("expired", { status: 401 });
|
||||
}) as unknown as typeof fetch;
|
||||
|
||||
try {
|
||||
const client = await createEkbClient(corp());
|
||||
await expect(client.get("api/test")).rejects.toThrow("临时凭证已过期,请使用 hose-use corps add-link 重新导入");
|
||||
expect(calls).toBe(1);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("core/auth/login link expiry", () => {
|
||||
it("parses explicit ttl and expires durations", () => {
|
||||
const base = 1_700_000_000_000;
|
||||
expect(resolveLinkExpiresAt({ ttl: "72h" }, base)).toBe(base + 72 * 60 * 60 * 1000);
|
||||
expect(resolveLinkExpiresAt({ ttl: "3d" }, base)).toBe(base + 3 * 24 * 60 * 60 * 1000);
|
||||
expect(resolveLinkExpiresAt({ expires: "3" }, base)).toBe(base + 3 * 24 * 60 * 60 * 1000);
|
||||
expect(resolveLinkExpiresAt({}, base)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -1,10 +0,0 @@
|
||||
/**
|
||||
* @deprecated 兼容历史导出。请优先从 "src/core/http/index.js" 导入 createSessionClient 与 getSessionHeaders
|
||||
*/
|
||||
export {
|
||||
createSessionClient,
|
||||
getSessionHeaders,
|
||||
createEkbClient,
|
||||
getEkbHeaders,
|
||||
type CreateSessionClientOptions,
|
||||
} from "../http/session-client.js";
|
||||
@@ -5,7 +5,7 @@ import { join } from "node:path";
|
||||
import { AuthenticationError } from "../errors.js";
|
||||
import { CorpConfig } from "../config/types.js";
|
||||
import { saveCorpConfig, saveMultipleCorpConfigs, resolveWritableEnterprisesDir } from "../config/loader.js";
|
||||
import { resolveCorpCluster } from "./easo.js";
|
||||
import { resolveCorpCluster } from "../http/unity-client.js";
|
||||
import {
|
||||
saveAccount,
|
||||
getAccount,
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
/**
|
||||
* @deprecated 兼容历史导出。请优先从 "src/core/http/index.js" 导入 getScriptEngineClient 与 getPiperClient
|
||||
*/
|
||||
export {
|
||||
getScriptEngineClient,
|
||||
getPiperClient,
|
||||
fetchEasoJwt,
|
||||
SCRIPT_ENGINE_BASE_URL,
|
||||
PIPER_BASE_URL,
|
||||
} from "../http/script-engine-client.js";
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { CorpContext } from "../config/manager.js";
|
||||
import { createEkbClient } from "./ekb.js";
|
||||
import { createSessionClient } from "../http/session-client.js";
|
||||
|
||||
// ── 精简 MCP Auth Tools (其余复杂登录/刷新均由 CLI 直接提供) ───────────────────
|
||||
|
||||
@@ -54,7 +54,7 @@ export const authTools = [
|
||||
let sessionValid = false;
|
||||
let sessionData: unknown = null;
|
||||
try {
|
||||
const client = await createEkbClient(current);
|
||||
const client = await createSessionClient(current);
|
||||
const res = await client.get("api/account/v2/session").json<{ value?: unknown }>();
|
||||
sessionData = res.value;
|
||||
sessionValid = !!res.value;
|
||||
|
||||
Reference in new issue
Block a user