refactor(core): 全量语义化客户端迁移并移除历史兼容桥接层
This commit is contained in:
1 parent
29ac24248e
commit
d0f3d2738a
34 files changed
+89
-141
No files matched your search
@@ -8,14 +8,13 @@ import {
|
||||
import {
|
||||
getSessionHeaders,
|
||||
createSessionClient,
|
||||
createEkbClient,
|
||||
} from "./session-client.js";
|
||||
import {
|
||||
createOpenApiClient,
|
||||
getOpenApiHeaders,
|
||||
} from "./openapi-client.js";
|
||||
import { resolveCorpCluster } from "./unity-client.js";
|
||||
import { getScriptEngineClient, getPiperClient } from "./script-engine-client.js";
|
||||
import { getScriptEngineClient } from "./script-engine-client.js";
|
||||
import type { CorpConfig } from "../config/types.js";
|
||||
|
||||
function mockCorp(overrides: Partial<CorpConfig> = {}): CorpConfig {
|
||||
@@ -69,13 +68,10 @@ describe("core/http/session-client", () => {
|
||||
expect(headers["Origin"]).toBe(DEFAULT_ORIGIN);
|
||||
});
|
||||
|
||||
it("createSessionClient and createEkbClient alias produce valid clients", async () => {
|
||||
it("createSessionClient produces valid client", async () => {
|
||||
const corp = mockCorp();
|
||||
const client1 = await createSessionClient(corp);
|
||||
const client2 = await createEkbClient(corp);
|
||||
|
||||
expect(client1).toBeDefined();
|
||||
expect(client2).toBeDefined();
|
||||
const client = await createSessionClient(corp);
|
||||
expect(client).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -110,7 +106,7 @@ describe("core/http/unity-client & script-engine-client", () => {
|
||||
expect(resolveCorpCluster({})).toBe("app");
|
||||
});
|
||||
|
||||
it("getPiperClient alias points to getScriptEngineClient", () => {
|
||||
expect(getPiperClient).toBe(getScriptEngineClient);
|
||||
it("getScriptEngineClient is defined and callable", () => {
|
||||
expect(getScriptEngineClient).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -24,8 +24,6 @@ export {
|
||||
export {
|
||||
createSessionClient,
|
||||
getSessionHeaders,
|
||||
createEkbClient,
|
||||
getEkbHeaders,
|
||||
type CreateSessionClientOptions,
|
||||
} from "./session-client.js";
|
||||
|
||||
@@ -50,6 +48,5 @@ export {
|
||||
// 6. 工作流脚本调试引擎客户端 (Script Engine Client)
|
||||
export {
|
||||
getScriptEngineClient,
|
||||
getPiperClient,
|
||||
fetchEasoJwt,
|
||||
} from "./script-engine-client.js";
|
||||
@@ -110,7 +110,3 @@ export async function getScriptEngineClient(
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ── 向后兼容别名 ─────────────────────────────────────────────────────────────
|
||||
/** @deprecated 推荐使用 getScriptEngineClient */
|
||||
export const getPiperClient = getScriptEngineClient;
|
||||
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { canRefreshCorpAccessToken, resolveLinkExpiresAt } from "../auth/login.js";
|
||||
import { createSessionClient } from "./session-client.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/http/session-client 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 createSessionClient(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();
|
||||
});
|
||||
});
|
||||
@@ -70,10 +70,3 @@ export async function createSessionClient(
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
// ── 向后兼容别名 ─────────────────────────────────────────────────────────────
|
||||
/** @deprecated 推荐使用 getSessionHeaders */
|
||||
export const getEkbHeaders = getSessionHeaders;
|
||||
|
||||
/** @deprecated 推荐使用 createSessionClient */
|
||||
export const createEkbClient = createSessionClient;
|
||||
Reference in new issue
Block a user