Fix Seal contact search and SSO errors

This commit is contained in:
gitea committed 2026-08-05 18:48:52 +08:00
1 parent 8435ed7fd9
commit 48d20a788f
4 files changed
+53 -13

No files matched your search

+2
View File
@@ -34,6 +34,8 @@ describe("CLI version & help handling", () => {
expect(result.status).toBe(0);
expect(result.stdout).toContain("seal-home CLI");
expect(result.stdout).toContain("Usage:");
expect(result.stdout).toContain("seal-home users search <keyword>");
expect(result.stdout).toContain("seal-home users delegation <userIdOrPhone|name>");
});
test("invalid command displays unknown command error with help hint", () => {
+2
View File
@@ -1233,6 +1233,8 @@ Usage:
seal-home delegation create [--note <note>] [--corp <corpId>]
seal-home delegation revoke <tokenId> [--corp <corpId>]
seal-home users create --name <name> --phone <phone> [--dept <deptId>] [--corp <corpId>]
seal-home users search <keyword> [--corp <corpId>]
seal-home users delegation <userIdOrPhone|name> [--note <note>] [--corp <corpId>]
seal-home users reset-password <userId> [--corp <corpId>]
seal-home users get <userId> [--corp <corpId>]
seal-home users delete <userId> [--corp <corpId>]
+30
View File
@@ -0,0 +1,30 @@
import { describe, expect, test } from "bun:test";
import type { KyInstance } from "ky";
import { searchUsers } from "./api.js";
describe("Seal contact API", () => {
test("sends the contact search term as query", async () => {
let requestedUrl = "";
let requestedParams: Record<string, string> | undefined;
const client = {
get: (url: string, options?: { searchParams?: Record<string, string> }) => {
requestedUrl = url;
requestedParams = options?.searchParams;
return {
json: async () => ({
data: {
departments: [],
users: [{ _id: "user-1", name: "欧阳楠楠" }]
}
})
};
}
} as unknown as KyInstance;
const result = await searchUsers(client, "欧阳楠楠");
expect(requestedUrl).toBe("api/v1/contacts/search");
expect(requestedParams).toEqual({ query: "欧阳楠楠" });
expect(result.users).toEqual([{ _id: "user-1", name: "欧阳楠楠", departmentIds: [], permissions: [] }]);
});
});
+19 -13
View File
@@ -1,4 +1,4 @@
import ky, { KyInstance } from "ky";
import ky, { HTTPError, KyInstance } from "ky";
import { z } from "zod";
import { CorpConfig } from "../../core/config/types.js";
import { ensureHoseOpenapiToken, fetchHoseCloseApiToken, defaultSealUrl, normalizeBaseUrl } from "../../core/auth/hose.js";
@@ -419,7 +419,7 @@ export async function searchUsers(
keyword = ""
): Promise<SealContactSearchResult> {
return unwrap(
await client.get("api/v1/contacts/search", { searchParams: { keyword } }),
await client.get("api/v1/contacts/search", { searchParams: { query: keyword } }),
SealContactSearchResultSchema
);
}
@@ -524,15 +524,23 @@ export async function createDelegationForUser(
const closeapiToken = provisional.token;
const sealUrl = defaultSealUrl(corp, corp.source);
const sealResponse = await ky
.get(`${normalizeBaseUrl(sealUrl)}/api/auth/oauth2/session/oem-hosecloud`, {
searchParams: {
token: closeapiToken,
returnToken: "1"
},
timeout: 30000
})
.json<{ token?: string; accessToken?: string; data?: { token?: string } }>();
let sealResponse: { token?: string; accessToken?: string; data?: { token?: string } };
try {
sealResponse = await ky
.get(`${normalizeBaseUrl(sealUrl)}/api/auth/oauth2/session/oem-hosecloud`, {
searchParams: {
token: closeapiToken,
returnToken: "1"
},
timeout: 30000
})
.json<{ token?: string; accessToken?: string; data?: { token?: string } }>();
} catch (error: unknown) {
if (error instanceof HTTPError && error.response.status === 400) {
throw new Error(`Seal AI 用户“${user.name}”未绑定合思账号,无法生成个人协助链接。`);
}
throw error;
}
const targetUserSealToken =
sealResponse.token ?? sealResponse.accessToken ?? sealResponse.data?.token;
@@ -619,5 +627,3 @@ export async function listBillingFeatures(client: KyInstance): Promise<unknown>
const json = (await response.json()) as { data?: unknown };
return JsonResponseSchema.parse(json.data ?? json);
}