31 lines
919 B
TypeScript
31 lines
919 B
TypeScript
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
|
|
}
|
|
}
|
|
};
|
|
}
|