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.
1.8 kB ยท 56 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import { db as defaultDb } from "@openstatus/db";import type { ImportSummary } from "@openstatus/importers";
import type { ServiceContext } from "../context";import { ValidationError } from "../errors";import { addLimitWarnings } from "./limits";import { buildProviderConfig, createProvider } from "./provider";import { PreviewImportInput } from "./schemas";
/** * Dry-run an import: fetches the source provider's resources, validates * credentials, and returns the full phase summary including warnings for * limits that would be hit if `run` were invoked with the same input. * Never writes to the db. */export async function previewImport(args: { ctx: ServiceContext; input: PreviewImportInput;}): Promise<ImportSummary> { const { ctx } = args; const input = PreviewImportInput.parse(args.input); const db = ctx.db ?? defaultDb;
const provider = createProvider(input.provider); const providerConfig = buildProviderConfig({ provider: input.provider, apiKey: input.apiKey, statuspagePageId: input.statuspagePageId, betterstackStatusPageId: input.betterstackStatusPageId, instatusPageId: input.instatusPageId, checklyAccountId: input.checklyAccountId, checklyStatusPageId: input.checklyStatusPageId, workspaceId: ctx.workspace.id, pageId: input.pageId, });
const validation = await provider.validate({ ...providerConfig, dryRun: true, }); if (!validation.valid) { throw new ValidationError( `Provider validation failed: ${validation.error ?? "unknown error"}`, ); }
const summary = await provider.run({ ...providerConfig, dryRun: true }); await addLimitWarnings(summary, { limits: ctx.workspace.limits, workspaceId: ctx.workspace.id, pageId: input.pageId, db, options: input.options, }); return summary;}