Remove legacy direct enterprise source

This commit is contained in:
gitea committed 2026-09-22 14:06:13 +08:00
1 parent 01ef5b37cb
commit 2e941f0842
29 files changed
+117 -132

No files matched your search

-28
View File
@@ -1,28 +0,0 @@
import { CorpConfig } from "../config/types.js";
import { SealSession } from "./types.js";
export async function getDirectSealSession(corp: CorpConfig): Promise<SealSession> {
if (corp.source.type !== "direct" && corp.source.type !== "seal") {
throw new Error(`Unsupported Seal source: ${corp.source.type}`);
}
const sealUrl = corp.seal.url ?? corp.source.sealUrl;
const nativeSource = corp.source.type === "seal" ? corp.source : undefined;
return {
token: corp.source.token,
expiresAt: Date.now() + corp.source.expiresIn * 1000,
enterprise: {
provider: nativeSource ? "seal" : "direct",
corpId: corp.source.corpId ?? corp.id,
staffId: corp.source.staffId,
sealUrl,
tenantId: nativeSource?.tenantId,
tenantSlug: corp.seal.tenantSlug ?? nativeSource?.tenantSlug,
tenantName: nativeSource?.tenantName,
raw: {
sourceType: corp.source.type
}
}
};
}
@@ -1,45 +1,45 @@
import { describe, expect, test } from "bun:test";
import { CorpConfig } from "../config/types.js";
import { getDirectSealSession } from "./direct.js";
import { getNativeSealSession } from "./native.js";
describe("getDirectSealSession", () => {
test("resolves direct source session correctly", async () => {
describe("getNativeSealSession", () => {
test("resolves native Seal source session correctly", async () => {
const corp: CorpConfig = {
id: "corp-direct-1",
name: "Direct Corp",
id: "corp-native-1",
name: "Native Seal Corp",
environment: "production",
seal: {
url: "https://seal.example.com",
tenantSlug: "direct-slug",
tenantSlug: "native-slug",
endpoints: {
approvalStylePreferences: "api/v1/agent/ai-approval/config"
}
},
source: {
type: "direct",
token: "bearer-token-direct",
type: "seal",
token: "bearer-token-native",
sealUrl: "https://seal.example.com",
expiresIn: 3600,
staffId: "staff-123",
corpId: "corp-direct-1"
corpId: "corp-native-1"
},
auth: {
refreshTtl: 300
}
};
const session = await getDirectSealSession(corp);
expect(session.token).toBe("bearer-token-direct");
const session = await getNativeSealSession(corp);
expect(session.token).toBe("bearer-token-native");
expect(session.enterprise).toEqual({
provider: "direct",
corpId: "corp-direct-1",
provider: "seal",
corpId: "corp-native-1",
staffId: "staff-123",
sealUrl: "https://seal.example.com",
tenantId: undefined,
tenantSlug: "direct-slug",
tenantSlug: "native-slug",
tenantName: undefined,
raw: {
sourceType: "direct"
sourceType: "seal"
}
});
expect(session.expiresAt).toBeGreaterThan(Date.now());
@@ -62,6 +62,7 @@ describe("getDirectSealSession", () => {
token: "bearer-token-native",
sealUrl: "https://tenant.sealai.cc",
expiresIn: 7200,
expiresAt: "2026-09-22T05:30:00Z",
staffId: "seal-admin",
tenantId: "tenant-100",
tenantSlug: "tenant-slug",
@@ -72,11 +73,12 @@ describe("getDirectSealSession", () => {
}
};
const session = await getDirectSealSession(corp);
const session = await getNativeSealSession(corp);
expect(session.token).toBe("bearer-token-native");
expect(session.enterprise.provider).toBe("seal");
expect(session.enterprise.tenantId).toBe("tenant-100");
expect(session.enterprise.tenantName).toBe("Tenant 100 Name");
expect(session.expiresAt).toBe(new Date("2026-09-22T05:30:00Z").getTime());
});
test("throws error for unsupported source type", async () => {
@@ -88,6 +90,6 @@ describe("getDirectSealSession", () => {
auth: { refreshTtl: 300 }
} as unknown as CorpConfig;
expect(getDirectSealSession(invalidCorp)).rejects.toThrow("Unsupported Seal source");
expect(getNativeSealSession(invalidCorp)).rejects.toThrow("Unsupported Seal source");
});
});
+30
View File
@@ -0,0 +1,30 @@
import { CorpConfig } from "../config/types.js";
import { SealSession } from "./types.js";
export async function getNativeSealSession(corp: CorpConfig): Promise<SealSession> {
if (corp.source.type !== "seal") {
throw new Error(`Unsupported Seal source: ${corp.source.type}`);
}
const sealUrl = corp.seal.url ?? corp.source.sealUrl;
const expiresAt = corp.source.expiresAt
? new Date(corp.source.expiresAt).getTime()
: Date.now() + corp.source.expiresIn * 1000;
return {
token: corp.source.token,
expiresAt,
enterprise: {
provider: corp.source.provider ?? "seal",
corpId: corp.source.corpId ?? corp.id,
staffId: corp.source.staffId,
sealUrl,
tenantId: corp.source.tenantId,
tenantSlug: corp.seal.tenantSlug ?? corp.source.tenantSlug,
tenantName: corp.source.tenantName,
raw: {
sourceType: corp.source.type
}
}
};
}
+2 -3
View File
@@ -1,5 +1,5 @@
import { CorpConfig } from "../config/types.js";
import { getDirectSealSession } from "./direct.js";
import { getNativeSealSession } from "./native.js";
import { getHoseSealSession } from "./hose.js";
import { clearSealSession, getSealSession, setSealSession } from "./token-store.js";
import { SealEnterpriseConfig, SealSession } from "./types.js";
@@ -14,9 +14,8 @@ async function refreshSealSession(corp: CorpConfig): Promise<SealSession> {
switch (corp.source.type) {
case "hose":
return getHoseSealSession(corp);
case "direct":
case "seal":
return getDirectSealSession(corp);
return getNativeSealSession(corp);
}
}
+2 -2
View File
@@ -66,7 +66,7 @@ describe("token-store", () => {
token: "test-token-123",
expiresAt: Date.now() + 3600_000,
enterprise: {
provider: "direct",
provider: "seal",
corpId: "corp-1",
staffId: "staff-1",
sealUrl: "https://seal.example.com"
@@ -108,7 +108,7 @@ describe("token-store", () => {
token: "legacy-token-456",
expiresAt: Date.now() + 3600_000,
enterprise: {
provider: "direct",
provider: "seal",
corpId: "corp-legacy",
staffId: "staff-legacy",
sealUrl: "https://seal.example.com"