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
-1
@@ -235,7 +235,7 @@ function makeConfigEnv(): Record<string, string> {
|
||||
id: "corp-a",
|
||||
name: "Corp A",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://corp-a.seal.test"
|
||||
}
|
||||
|
||||
@@ -193,6 +193,7 @@ describe("corps link onboarding", () => {
|
||||
expect(config.source.provider).toBe("hosecloud");
|
||||
expect(config.source.token).toBe("seal-bearer-token");
|
||||
expect(config.source.expiresIn).toBe(1800);
|
||||
expect(config.source.expiresAt).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/);
|
||||
});
|
||||
|
||||
test("rejects --elevate-hose when passed with a Seal native delegate link", async () => {
|
||||
|
||||
+10
-11
@@ -101,20 +101,12 @@ function formatSafeSourceDetail(source: SealSource) {
|
||||
sealUrl: source.sealUrl,
|
||||
hasToken: Boolean(source.token),
|
||||
tokenMasked: maskSecret(source.token),
|
||||
expiresIn: source.expiresIn
|
||||
expiresIn: source.expiresIn,
|
||||
expiresAt: source.expiresAt
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: "direct",
|
||||
provider: "direct",
|
||||
staffId: source.staffId,
|
||||
corpId: source.corpId,
|
||||
sealUrl: source.sealUrl,
|
||||
hasToken: Boolean(source.token),
|
||||
tokenMasked: maskSecret(source.token),
|
||||
expiresIn: source.expiresIn
|
||||
};
|
||||
throw new Error(`Unsupported enterprise source type: ${(source as { type: string }).type}`);
|
||||
}
|
||||
|
||||
export async function handleCorpsCommand(action: string | undefined, maybeName: string | undefined, args: ParsedArgs) {
|
||||
@@ -1960,12 +1952,14 @@ function writeSealCorpConfig(
|
||||
token: string;
|
||||
sealUrl: string;
|
||||
expiresIn: number;
|
||||
expiresAt?: string;
|
||||
verify: boolean;
|
||||
remote?: RemoteSealIdentity;
|
||||
custom?: { headers?: Record<string, string>; cookies?: Record<string, string> };
|
||||
}
|
||||
) {
|
||||
const { token, sealUrl, expiresIn, verify, remote } = auth;
|
||||
const expiresAt = auth.expiresAt ?? formatUtcTimestampSeconds(Date.now() + expiresIn * 1000);
|
||||
const custom = auth.custom ?? sealCustomHeadersFromInput(input);
|
||||
const remoteUser = remote?.user;
|
||||
const remoteTenant = remote?.tenant;
|
||||
@@ -2004,6 +1998,7 @@ function writeSealCorpConfig(
|
||||
token,
|
||||
sealUrl,
|
||||
expiresIn,
|
||||
expiresAt,
|
||||
staffId,
|
||||
corpId,
|
||||
tenantId,
|
||||
@@ -2035,6 +2030,10 @@ function writeSealCorpConfig(
|
||||
});
|
||||
}
|
||||
|
||||
function formatUtcTimestampSeconds(timestampMs: number): string {
|
||||
return new Date(timestampMs).toISOString().replace(/\.\d{3}Z$/, "Z");
|
||||
}
|
||||
|
||||
async function resolveHoseCorporation(domain: string, appKey: string, appSecurity: string) {
|
||||
const response = await fetch(`${domain.replace(/\/+$/, "")}/api/openapi/v1/auth/getAccessToken`, {
|
||||
method: "POST",
|
||||
|
||||
@@ -49,7 +49,7 @@ function setupMockEnv() {
|
||||
name: "测试资源包企业",
|
||||
environment: "test",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "mock-valid-token",
|
||||
sealUrl: "https://test-pack.sealai.cc"
|
||||
},
|
||||
@@ -115,7 +115,7 @@ describe("Webhook Resource Pack CLI Commands", () => {
|
||||
id: "test-corp-pack",
|
||||
name: "测试企业",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "mock-valid-token",
|
||||
sealUrl: "https://test-pack.sealai.cc",
|
||||
expiresIn: 3600,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -467,7 +467,7 @@ describe("Hose Flow Domain", () => {
|
||||
name: "Direct Corp",
|
||||
environment: "production",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "tok",
|
||||
sealUrl: "https://test.sealai.cc",
|
||||
expiresIn: 3600,
|
||||
|
||||
@@ -199,7 +199,7 @@ describe("exportApprovalRunsToExcel integration", () => {
|
||||
}
|
||||
},
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "test-token",
|
||||
sealUrl: "https://mock.sealai.cc",
|
||||
expiresIn: 3600,
|
||||
|
||||
@@ -110,7 +110,7 @@ describe("insight-export domain", () => {
|
||||
tenantSlug: "test"
|
||||
},
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "fake-token",
|
||||
sealUrl: "https://seal.example.com"
|
||||
}
|
||||
@@ -170,7 +170,7 @@ describe("insight-export domain", () => {
|
||||
}
|
||||
},
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "mock-token",
|
||||
sealUrl: "https://mock.sealai.cc",
|
||||
expiresIn: 3600,
|
||||
@@ -199,7 +199,7 @@ describe("insight-export domain", () => {
|
||||
}
|
||||
},
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "mock-token",
|
||||
sealUrl: "https://mock.sealai.cc",
|
||||
expiresIn: 3600,
|
||||
|
||||
@@ -16,7 +16,7 @@ const mockCorp: CorpConfig = {
|
||||
name: "测试研发企业",
|
||||
environment: "test",
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "mock-token",
|
||||
sealUrl: "https://seal.example.com",
|
||||
expiresIn: 3600,
|
||||
|
||||
@@ -84,7 +84,7 @@ function fakeCorp(): CorpConfig {
|
||||
}
|
||||
},
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "tok",
|
||||
sealUrl: "https://seal.test",
|
||||
expiresIn: 3600,
|
||||
|
||||
@@ -1173,7 +1173,7 @@ function fakeContext(): { corp: CorpConfig } {
|
||||
}
|
||||
},
|
||||
source: {
|
||||
type: "direct",
|
||||
type: "seal",
|
||||
token: "token",
|
||||
sealUrl: "https://seal.test",
|
||||
expiresIn: 3600,
|
||||
|
||||
Reference in new issue
Block a user