29 lines
942 B
TypeScript
29 lines
942 B
TypeScript
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
|
|
}
|
|
}
|
|
};
|
|
}
|