Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.0 kB ยท 74 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475import type { ServiceContext } from "../context";import { resolveWorkOS } from "./client";import { isWorkOSConfigured } from "./client";import { listSsoDomains } from "./internal";import { reconcileSsoDomains } from "./sync-domains";
export type SsoConnectionState = "none" | "pending" | "active" | "inactive";
export type SsoConfig = { configured: boolean; enabled: boolean; organizationId: string | null; connection: SsoConnectionState; domains: { domain: string; verifiedAt: Date | null; }[]; ready: boolean;};
/** * Connection state is read live from WorkOS rather than mirrored; domain rows * are mirrored, so this read also reconciles them against WorkOS. */export async function getSsoConfig(args: { ctx: ServiceContext;}): Promise<SsoConfig> { const { ctx } = args;
const rows = await listSsoDomains(ctx); let domains = rows.map((row) => ({ domain: row.domain, verifiedAt: row.verifiedAt, }));
const organizationId = ctx.workspace.workosOrganizationId ?? null;
let connection: SsoConnectionState = "none"; if (organizationId && isWorkOSConfigured()) { const workos = resolveWorkOS(ctx.workos); domains = await reconcileSsoDomains({ ctx, organizationId, workos, local: domains, }); const list = await workos.sso.listConnections({ organizationId, limit: 1, }); const first = list.data[0]; if (!first) { connection = "pending"; } else if (first.state === "active") { connection = "active"; } else if (first.state === "inactive") { connection = "inactive"; } else { connection = "pending"; } }
const hasVerifiedDomain = domains.some((entry) => entry.verifiedAt !== null);
return { configured: Boolean(organizationId), enabled: ctx.workspace.ssoEnabled, organizationId, connection, domains, ready: ctx.workspace.ssoEnabled && connection === "active" && hasVerifiedDomain, };}