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.5 kB ยท 73 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374import type { ImportProvider } from "@openstatus/importers";import { createBetterstackProvider } from "@openstatus/importers/betterstack";import { createChecklyProvider } from "@openstatus/importers/checkly";import { createInstatusProvider } from "@openstatus/importers/instatus";import { createStatuspageProvider } from "@openstatus/importers/statuspage";
import type { ImportProviderName } from "./schemas";
/** * Factory for a specific provider adapter. Used by both preview and run. * Unknown names throw โ silently defaulting would mask a typo'd provider * by running the Statuspage adapter against a non-Statuspage API key. */export function createProvider(name: ImportProviderName): ImportProvider { switch (name) { case "betterstack": return createBetterstackProvider(); case "instatus": return createInstatusProvider(); case "statuspage": return createStatuspageProvider(); case "checkly": return createChecklyProvider(); default: { const exhaustive: never = name; throw new Error(`Unknown import provider: ${String(exhaustive)}`); } }}
export type ProviderConfig = { provider: ImportProviderName; apiKey: string; workspaceId: number; pageId?: number; statuspagePageId?: string; betterstackStatusPageId?: string; instatusPageId?: string; checklyAccountId?: string; checklyStatusPageId?: string;};
/** * Strip the discriminator and reshape provider-specific ids so the * provider adapter receives exactly the fields it expects. Mirrors * `createProvider`'s exhaustive-switch pattern โ silently falling * through to Statuspage for a typo'd provider would pass the wrong * page id field and produce a confusing validation failure. */export function buildProviderConfig(config: ProviderConfig) { const { provider, ...rest } = config; switch (provider) { case "betterstack": return { ...rest, betterstackStatusPageId: config.betterstackStatusPageId, }; case "instatus": return { ...rest, instatusPageId: config.instatusPageId }; case "statuspage": return { ...rest, statuspagePageId: config.statuspagePageId }; case "checkly": return { ...rest, checklyAccountId: config.checklyAccountId, checklyStatusPageId: config.checklyStatusPageId, }; default: { const exhaustive: never = provider; throw new Error(`Unknown import provider: ${String(exhaustive)}`); } }}