Remove legacy direct enterprise source
This commit is contained in:
1 parent
01ef5b37cb
commit
2e941f0842
29 files changed
+117
-132
No files matched your search
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -55,7 +55,7 @@ describe("loadCorpConfigs", () => {
|
||||
id: "direct",
|
||||
name: "Direct",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://direct.sealai.cc"
|
||||
}
|
||||
@@ -70,7 +70,7 @@ describe("loadCorpConfigs", () => {
|
||||
id: "direct-use",
|
||||
name: "Direct Use",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://direct.sealai.cc"
|
||||
}
|
||||
@@ -233,7 +233,7 @@ function writeCorpConfig(path: string, id: string, name: string) {
|
||||
id,
|
||||
name,
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: `https://${id}.sealai.cc`
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ function corp(id: string, name = id): CorpConfig {
|
||||
}
|
||||
},
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: `${id}-token`,
|
||||
sealUrl: `https://${id}.seal.test`,
|
||||
expiresIn: 3600,
|
||||
|
||||
@@ -45,22 +45,24 @@ describe("CorpConfigSchema", () => {
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
test("accepts direct Seal bearer source", () => {
|
||||
test("accepts Seal Bearer source with expiry metadata", () => {
|
||||
const config = CorpConfigSchema.parse({
|
||||
id: "direct",
|
||||
name: "Direct",
|
||||
id: "seal",
|
||||
name: "Seal",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://direct.sealai.cc"
|
||||
sealUrl: "https://seal.sealai.cc",
|
||||
expiresAt: "2026-09-22T05:30:00Z"
|
||||
}
|
||||
});
|
||||
|
||||
expect(config.source.type).toBe("direct");
|
||||
if (config.source.type !== "direct") {
|
||||
throw new Error("expected direct source");
|
||||
expect(config.source.type).toBe("seal");
|
||||
if (config.source.type !== "seal") {
|
||||
throw new Error("expected seal source");
|
||||
}
|
||||
expect(config.source.expiresIn).toBe(3600);
|
||||
expect(config.source.expiresAt).toBe("2026-09-22T05:30:00Z");
|
||||
});
|
||||
|
||||
test("accepts native Seal bearer source", () => {
|
||||
@@ -86,12 +88,12 @@ describe("CorpConfigSchema", () => {
|
||||
|
||||
test("leaves custom headers and cookies absent by default", () => {
|
||||
const config = CorpConfigSchema.parse({
|
||||
id: "direct",
|
||||
name: "Direct",
|
||||
id: "seal",
|
||||
name: "Seal",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://direct.sealai.cc"
|
||||
sealUrl: "https://seal.sealai.cc"
|
||||
}
|
||||
});
|
||||
|
||||
@@ -109,9 +111,9 @@ describe("CorpConfigSchema", () => {
|
||||
environment: "production",
|
||||
testCorpId: "test-corp",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://direct.sealai.cc"
|
||||
sealUrl: "https://seal.sealai.cc"
|
||||
}
|
||||
});
|
||||
expect(prodConfig.environment).toBe("production");
|
||||
@@ -123,9 +125,9 @@ describe("CorpConfigSchema", () => {
|
||||
environment: "test",
|
||||
prodCorpId: "prod-corp",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://direct.sealai.cc"
|
||||
sealUrl: "https://seal.sealai.cc"
|
||||
}
|
||||
});
|
||||
expect(testConfig.environment).toBe("test");
|
||||
@@ -142,7 +144,7 @@ describe("CorpConfigSchema", () => {
|
||||
cookies: { sdp_app_session_20142: "abc" }
|
||||
},
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://gated.sealai.cc"
|
||||
}
|
||||
|
||||
@@ -28,20 +28,17 @@ export const HoseSealSourceSchema = z.object({
|
||||
}
|
||||
});
|
||||
|
||||
export const DirectSealSourceSchema = z.object({
|
||||
type: z.literal("direct"),
|
||||
token: z.string(),
|
||||
sealUrl: z.string().url(),
|
||||
expiresIn: z.number().int().positive().default(3600),
|
||||
staffId: z.string().default("direct"),
|
||||
corpId: z.string().optional()
|
||||
});
|
||||
const UtcSecondTimestampSchema = z.string().regex(
|
||||
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/,
|
||||
"Timestamp must be an ISO 8601 UTC timestamp without milliseconds"
|
||||
);
|
||||
|
||||
export const NativeSealSourceSchema = z.object({
|
||||
type: z.literal("seal"),
|
||||
token: z.string(),
|
||||
sealUrl: z.string().url(),
|
||||
expiresIn: z.number().int().positive().default(3600),
|
||||
expiresAt: UtcSecondTimestampSchema.optional(),
|
||||
staffId: z.string().default("seal"),
|
||||
corpId: z.string().optional(),
|
||||
tenantId: z.string().optional(),
|
||||
@@ -54,7 +51,6 @@ export const NativeSealSourceSchema = z.object({
|
||||
|
||||
export const SealSourceSchema = z.discriminatedUnion("type", [
|
||||
HoseSealSourceSchema,
|
||||
DirectSealSourceSchema,
|
||||
NativeSealSourceSchema
|
||||
]);
|
||||
|
||||
@@ -137,7 +133,6 @@ export const GlobalConfigSchema = z.object({
|
||||
|
||||
export type CorpEnvironment = z.infer<typeof CorpEnvironmentSchema>;
|
||||
export type HoseSealSource = z.infer<typeof HoseSealSourceSchema>;
|
||||
export type DirectSealSource = z.infer<typeof DirectSealSourceSchema>;
|
||||
export type NativeSealSource = z.infer<typeof NativeSealSourceSchema>;
|
||||
export type SealSource = z.infer<typeof SealSourceSchema>;
|
||||
export type CorpAuthConfig = z.infer<typeof CorpAuthConfigSchema>;
|
||||
|
||||
@@ -21,7 +21,7 @@ function makeCorp(id: string, name: string, overrides: Partial<CorpConfig> = {})
|
||||
}
|
||||
},
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: `${id}-token`,
|
||||
sealUrl: `https://${id}.seal.test`,
|
||||
expiresIn: 3600,
|
||||
|
||||
Reference in new issue
Block a user