Add Seal-native enterprise support
This commit is contained in:
1 parent
2611ce4c85
commit
997ece006a
10 files changed
+176
-9
No files matched your search
@@ -2,23 +2,26 @@ import { CorpConfig } from "../config/types.js";
|
||||
import { SealSession } from "./types.js";
|
||||
|
||||
export async function getDirectSealSession(corp: CorpConfig): Promise<SealSession> {
|
||||
if (corp.source.type !== "direct") {
|
||||
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: "direct",
|
||||
provider: nativeSource ? "seal" : "direct",
|
||||
corpId: corp.source.corpId ?? corp.id,
|
||||
staffId: corp.source.staffId,
|
||||
sealUrl,
|
||||
tenantSlug: corp.seal.tenantSlug,
|
||||
tenantId: nativeSource?.tenantId,
|
||||
tenantSlug: corp.seal.tenantSlug ?? nativeSource?.tenantSlug,
|
||||
tenantName: nativeSource?.tenantName,
|
||||
raw: {
|
||||
sourceType: "direct"
|
||||
sourceType: corp.source.type
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@ async function refreshSealSession(corp: CorpConfig): Promise<SealSession> {
|
||||
case "hose":
|
||||
return getHoseSealSession(corp);
|
||||
case "direct":
|
||||
case "seal":
|
||||
return getDirectSealSession(corp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +57,25 @@ describe("CorpConfigSchema", () => {
|
||||
}
|
||||
expect(config.source.expiresIn).toBe(3600);
|
||||
});
|
||||
|
||||
test("accepts native Seal bearer source", () => {
|
||||
const config = CorpConfigSchema.parse({
|
||||
id: "xiezihao",
|
||||
name: "谢子豪的测试环境",
|
||||
source: {
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://xiezihao.staging.sealai.cc",
|
||||
tenantSlug: "xiezihao",
|
||||
tenantId: "tenant-id"
|
||||
}
|
||||
});
|
||||
|
||||
expect(config.source.type).toBe("seal");
|
||||
if (config.source.type !== "seal") {
|
||||
throw new Error("expected seal source");
|
||||
}
|
||||
expect(config.source.staffId).toBe("seal");
|
||||
expect(config.source.tenantSlug).toBe("xiezihao");
|
||||
});
|
||||
});
|
||||
@@ -37,9 +37,23 @@ export const DirectSealSourceSchema = z.object({
|
||||
corpId: z.string().optional()
|
||||
});
|
||||
|
||||
export const NativeSealSourceSchema = z.object({
|
||||
type: z.literal("seal"),
|
||||
token: z.string(),
|
||||
sealUrl: z.string().url(),
|
||||
expiresIn: z.number().int().positive().default(3600),
|
||||
staffId: z.string().default("seal"),
|
||||
corpId: z.string().optional(),
|
||||
tenantId: z.string().optional(),
|
||||
tenantSlug: z.string().optional(),
|
||||
tenantName: z.string().optional(),
|
||||
providerUserId: z.string().optional()
|
||||
});
|
||||
|
||||
export const SealSourceSchema = z.discriminatedUnion("type", [
|
||||
HoseSealSourceSchema,
|
||||
DirectSealSourceSchema
|
||||
DirectSealSourceSchema,
|
||||
NativeSealSourceSchema
|
||||
]);
|
||||
|
||||
export const SealEndpointSchema = z.object({
|
||||
@@ -70,6 +84,7 @@ export const CorpConfigSchema = z.object({
|
||||
|
||||
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>;
|
||||
export type CorpConfig = z.infer<typeof CorpConfigSchema>;
|
||||
Reference in new issue
Block a user