Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
chore: remove dead code (#1882)
Thibault Le Ouayc57f2a887047
diff --git a/.gitignore b/.gitignoreindex 7dabd15da..4037c271c 100644--- a/.gitignore+++ b/.gitignore@@ -78,3 +78,5 @@ research.mdplan.md.zed++*.tsbuildinfodiff --git a/packages/api/src/router/domain.ts b/packages/api/src/router/domain.tsindex 526e660a8..6533d89d8 100644--- a/packages/api/src/router/domain.ts+++ b/packages/api/src/router/domain.ts@@ -1,6 +1,5 @@import { z } from "zod";-import { TRPCError } from "@trpc/server";import { env } from "../env";import { createTRPCRouter, protectedProcedure } from "../trpc";@@ -52,59 +51,6 @@ export type DomainVerificationStatusProps =| "Unknown Error";export const domainRouter = createTRPCRouter({- addDomainToVercel: protectedProcedure- .input(z.object({ domain: z.string() }))- .mutation(async (opts) => {- if (opts.input.domain.toLowerCase().includes("openstatus")) {- throw new TRPCError({- code: "BAD_REQUEST",- message: "Domain cannot contain 'openstatus'",- });- }-- const data = await fetch(- `https://api.vercel.com/v9/projects/${env.PROJECT_ID_VERCEL}/domains?teamId=${env.TEAM_ID_VERCEL}`,- {- body: `{\n "name": "${opts.input.domain}"\n}`,- headers: {- Authorization: `Bearer ${env.VERCEL_AUTH_BEARER_TOKEN}`,- "Content-Type": "application/json",- },- method: "POST",- },- );- const json = await data.json();- console.log({ json });- return domainResponseSchema.parse(json);- }),- removeDomainFromVercelProject: protectedProcedure- .input(z.object({ domain: z.string() }))- .mutation(async (opts) => {- const data = await fetch(- `https://api.vercel.com/v9/projects/${env.PROJECT_ID_VERCEL}/domains/${opts.input.domain}?teamId=${env.TEAM_ID_VERCEL}`,- {- headers: {- Authorization: `Bearer ${env.VERCEL_AUTH_BEARER_TOKEN}`,- },- method: "DELETE",- },- );- return await data.json();- }),- // removeDomainFromVercelTeam: protectedProcedure- // .input(z.object({ domain: z.string() }))- // .mutation(async (opts) => {- // const data = await fetch(- // `https://api.vercel.com/v6/domains/${opts.input.domain}?teamId=${env.TEAM_ID_VERCEL}`,- // {- // headers: {- // Authorization: `Bearer ${env.VERCEL_AUTH_BEARER_TOKEN}`,- // },- // method: "DELETE",- // },- // );- // return await data.json();- // }),getDomainResponse: protectedProcedure.input(z.object({ domain: z.string().optional() })).query(async (opts) => {diff --git a/packages/api/src/router/integration.ts b/packages/api/src/router/integration.tsindex fdfafde3e..348f96a2c 100644--- a/packages/api/src/router/integration.ts+++ b/packages/api/src/router/integration.ts@@ -3,10 +3,7 @@ import crypto from "crypto";import { z } from "zod";import { and, eq, sql } from "@openstatus/db";-import {- insertIntegrationSchema,- integration,-} from "@openstatus/db/src/schema";+import { integration } from "@openstatus/db/src/schema";import { createTRPCRouter, protectedProcedure } from "../trpc";@@ -28,32 +25,6 @@ function safeJsonParse(value: string | null): Record<string, unknown> {}export const integrationRouter = createTRPCRouter({- createIntegration: protectedProcedure- .input(- z.object({ workspaceSlug: z.string(), input: insertIntegrationSchema }),- )- .mutation(async (opts) => {- const exists = await opts.ctx.db- .select()- .from(integration)- .where(- and(- eq(integration.workspaceId, opts.ctx.workspace.id),- eq(integration.externalId, opts.input.input.externalId),- ),- )- .get();-- if (exists) {- return;- }- await opts.ctx.db- .insert(integration)- .values({ ...opts.input.input, workspaceId: opts.ctx.workspace.id })- .returning()- .get();- }),-list: protectedProcedure.query(async (opts) => {const rows = await opts.ctx.db.select({diff --git a/packages/api/src/router/notification.ts b/packages/api/src/router/notification.tsindex 35ca07c74..84a1c6560 100644--- a/packages/api/src/router/notification.ts+++ b/packages/api/src/router/notification.ts@@ -6,7 +6,6 @@ import {NotificationDataSchema,googleChatDataSchema,grafanaOncallDataSchema,- insertNotificationSchema,monitor,notification,notificationProvider,@@ -27,225 +26,6 @@ import { sendTest as sendWhatsAppTest } from "@openstatus/notification-twillio-wimport { createTRPCRouter, protectedProcedure } from "../trpc";export const notificationRouter = createTRPCRouter({- create: protectedProcedure- .meta({ track: Events.CreateNotification, trackProps: ["provider"] })- .input(insertNotificationSchema)- .mutation(async (opts) => {- const { monitors, ...props } = opts.input;-- const notificationLimit =- opts.ctx.workspace.limits["notification-channels"];-- const notificationNumber = (- await opts.ctx.db.query.notification.findMany({- where: eq(notification.workspaceId, opts.ctx.workspace.id),- })- ).length;-- // the user has reached the limits- if (notificationNumber >= notificationLimit) {- throw new TRPCError({- code: "FORBIDDEN",- message: "You reached your notification limits.",- });- }-- const limitedProviders = [- "sms",- "pagerduty",- "opsgenie",- "grafana-oncall",- "whatsapp",- ];- if (limitedProviders.includes(props.provider)) {- const isAllowed =- opts.ctx.workspace.limits[- props.provider as- | "sms"- | "pagerduty"- | "opsgenie"- | "grafana-oncall"- | "whatsapp"- ];-- if (!isAllowed) {- throw new TRPCError({- code: "FORBIDDEN",- message: "Upgrade to use the notification channel.",- });- }- }-- const _data = NotificationDataSchema.safeParse(JSON.parse(props.data));-- if (!_data.success) {- throw new TRPCError({- code: "BAD_REQUEST",- message: SchemaError.fromZod(_data.error, props).message,- });- }-- const _notification = await opts.ctx.db- .insert(notification)- .values({ ...props, workspaceId: opts.ctx.workspace.id })- .returning()- .get();-- const values = monitors.map((monitorId) => ({- notificationId: _notification.id,- monitorId,- }));-- if (values.length) {- await opts.ctx.db.insert(notificationsToMonitors).values(values);- }-- return _notification;- }),-- update: protectedProcedure- .meta({ track: Events.UpdateNotification })- .input(insertNotificationSchema)- .mutation(async (opts) => {- if (!opts.input.id) return;-- const { monitors, ...props } = opts.input;-- const _data = NotificationDataSchema.safeParse(JSON.parse(props.data));-- if (!_data.success) {- throw new TRPCError({- code: "BAD_REQUEST",- message: SchemaError.fromZod(_data.error, props).message,- });- }-- const currentNotification = await opts.ctx.db- .update(notification)- .set({ ...props, updatedAt: new Date() })- .where(- and(- eq(notification.id, opts.input.id),- eq(notification.workspaceId, opts.ctx.workspace.id),- ),- )- .returning()- .get();-- // TODO: relation-- if (monitors.length) {- const allMonitors = await opts.ctx.db.query.monitor.findMany({- where: and(- eq(monitor.workspaceId, opts.ctx.workspace.id),- inArray(monitor.id, monitors),- ),- });-- if (allMonitors.length !== monitors.length) {- throw new TRPCError({- code: "FORBIDDEN",- message: "You don't have access to all the monitors.",- });- }- }-- const currentMonitorsToNotifications = await opts.ctx.db- .select()- .from(notificationsToMonitors)- .where(- eq(notificationsToMonitors.notificationId, currentNotification.id),- )- .all();-- const removedMonitors = currentMonitorsToNotifications- .map(({ monitorId }) => monitorId)- .filter((x) => !monitors?.includes(x));-- if (removedMonitors.length) {- await opts.ctx.db- .delete(notificationsToMonitors)- .where(- and(- inArray(notificationsToMonitors.monitorId, removedMonitors),- eq(- notificationsToMonitors.notificationId,- currentNotification.id,- ),- ),- );- }-- const values = monitors.map((monitorId) => ({- notificationId: currentNotification.id,- monitorId,- }));-- if (values.length) {- await opts.ctx.db- .insert(notificationsToMonitors)- .values(values)- .onConflictDoNothing();- }-- return currentNotification;- }),-- getNotificationById: protectedProcedure- .input(z.object({ id: z.number() }))- .query(async (opts) => {- const _notification = await opts.ctx.db.query.notification.findFirst({- where: and(- eq(notification.id, opts.input.id),- eq(notification.workspaceId, opts.ctx.workspace.id),- ),- // FIXME: plural- with: { monitor: { with: { monitor: true } } },- });-- const schema = selectNotificationSchema.extend({- monitor: z.array(- z.object({- monitor: selectMonitorSchema,- }),- ),- });-- return schema.parse(_notification);- }),-- getNotificationsByWorkspace: protectedProcedure.query(async (opts) => {- const notifications = await opts.ctx.db.query.notification.findMany({- where: and(eq(notification.workspaceId, opts.ctx.workspace.id)),- with: {- // FIXME: first should be plurals!- monitor: { with: { monitor: true } },- },- });-- const schema = selectNotificationSchema.extend({- monitor: z.array(- z.object({- monitor: selectMonitorSchema,- }),- ),- });-- return z.array(schema).parse(notifications);- }),-- isNotificationLimitReached: protectedProcedure.query(async (opts) => {- const notificationLimit =- opts.ctx.workspace.limits["notification-channels"];- const notificationNumbers = (- await opts.ctx.db.query.notification.findMany({- where: eq(notification.workspaceId, opts.ctx.workspace.id),- })- ).length;-- return notificationNumbers >= notificationLimit;- }),-list: protectedProcedure.query(async (opts) => {const notifications = await opts.ctx.db.query.notification.findMany({where: eq(notification.workspaceId, opts.ctx.workspace.id),diff --git a/packages/api/src/router/page.ts b/packages/api/src/router/page.tsindex 3a23ccbe5..116c34889 100644--- a/packages/api/src/router/page.ts+++ b/packages/api/src/router/page.ts@@ -179,31 +179,6 @@ export const pageRouter = createTRPCRouter({return !(result?.length > 0);}),- addCustomDomain: protectedProcedure- .input(- z.object({ customDomain: z.string().toLowerCase(), pageId: z.number() }),- )- .mutation(async (opts) => {- if (opts.input.customDomain.toLowerCase().includes("openstatus")) {- throw new TRPCError({- code: "BAD_REQUEST",- message: "Domain cannot contain 'openstatus'",- });- }-- await opts.ctx.db- .update(page)- .set({ customDomain: opts.input.customDomain, updatedAt: new Date() })- .where(- and(- eq(page.id, opts.input.pageId),- eq(page.workspaceId, opts.ctx.workspace.id),- ),- )- .returning()- .get();- }),-list: protectedProcedure.input(zdiff --git a/packages/api/src/router/tinybird/index.ts b/packages/api/src/router/tinybird/index.tsindex 1d7300903..184230702 100644--- a/packages/api/src/router/tinybird/index.ts+++ b/packages/api/src/router/tinybird/index.ts@@ -73,48 +73,6 @@ export function getMetricsProcedure(period: Period, type: Type) {}}-export function getMetricsByRegionProcedure(period: Period, type: Type) {- switch (period) {- case "1d":- return type === "http"- ? tb.httpMetricsByRegionDaily- : tb.tcpMetricsByRegionDaily;- case "7d":- return type === "http"- ? tb.httpMetricsByRegionWeekly- : tb.tcpMetricsByRegionWeekly;- case "14d":- return type === "http"- ? tb.httpMetricsByRegionBiweekly- : tb.tcpMetricsByRegionBiweekly;- default:- return type === "http"- ? tb.httpMetricsByRegionDaily- : tb.tcpMetricsByRegionDaily;- }-}--export function getMetricsByIntervalProcedure(period: Period, type: Type) {- switch (period) {- case "1d":- return type === "http"- ? tb.httpMetricsByIntervalDaily- : tb.tcpMetricsByIntervalDaily;- case "7d":- return type === "http"- ? tb.httpMetricsByIntervalWeekly- : tb.tcpMetricsByIntervalWeekly;- case "14d":- return type === "http"- ? tb.httpMetricsByIntervalBiweekly- : tb.tcpMetricsByIntervalBiweekly;- default:- return type === "http"- ? tb.httpMetricsByIntervalDaily- : tb.tcpMetricsByIntervalDaily;- }-}-// FIXME: tb pipes are deprecated, we need new onesexport function getMetricsRegionsProcedure(period: Period, type: Type) {switch (period) {@@ -220,20 +178,6 @@ export function getTimingPhasesProcedure(type: Type) {}export const tinybirdRouter = createTRPCRouter({- // Legacy procedure for backward compatibility- httpGetMonthly: protectedProcedure- .input(- z.object({- monitorId: z.string(),- region: z.enum(monitorRegions).or(z.string()).optional(),- cronTimestamp: z.int().optional(),- }),- )- .query(async (opts) => {- return await tb.httpGetMonthly(opts.input);- }),-- // Simplified procedures that handle period/type logic on serverlist: protectedProcedure.input(z.object({@@ -372,74 +316,6 @@ export const tinybirdRouter = createTRPCRouter({return await procedure(opts.input);}),- metricsByRegion: protectedProcedure- .input(- z.object({- monitorId: z.string(),- period: z.enum(periods),- type: z.enum(types).prefault("http"),- region: z.enum(monitorRegions).or(z.string()).optional(),- cronTimestamp: z.int().optional(),- }),- )- .query(async (opts) => {- const whereConditions: SQL[] = [- eq(monitor.id, Number.parseInt(opts.input.monitorId)),- eq(monitor.workspaceId, opts.ctx.workspace.id),- ];-- const _monitor = await db.query.monitor.findFirst({- where: and(...whereConditions),- });-- if (!_monitor) {- throw new TRPCError({- code: "NOT_FOUND",- message: "Monitor not found",- });- }-- const procedure = getMetricsByRegionProcedure(- opts.input.period,- opts.input.type,- );- return await procedure(opts.input);- }),-- metricsByInterval: protectedProcedure- .input(- z.object({- monitorId: z.string(),- period: z.enum(periods),- type: z.enum(types).prefault("http"),- region: z.enum(monitorRegions).or(z.string()).optional(),- cronTimestamp: z.int().optional(),- }),- )- .query(async (opts) => {- const whereConditions: SQL[] = [- eq(monitor.id, Number.parseInt(opts.input.monitorId)),- eq(monitor.workspaceId, opts.ctx.workspace.id),- ];-- const _monitor = await db.query.monitor.findFirst({- where: and(...whereConditions),- });-- if (!_monitor) {- throw new TRPCError({- code: "NOT_FOUND",- message: "Monitor not found",- });- }-- const procedure = getMetricsByIntervalProcedure(- opts.input.period,- opts.input.type,- );- return await procedure(opts.input);- }),-metricsRegions: protectedProcedure.input(z.object({@@ -482,37 +358,6 @@ export const tinybirdRouter = createTRPCRouter({return await procedure(opts.input);}),- status: protectedProcedure- .input(- z.object({- monitorIds: z.string().array(),- period: z.enum(["45d"]),- type: z.enum(types).prefault("http"),- region: z.enum(monitorRegions).or(z.string()).optional(),- cronTimestamp: z.int().optional(),- }),- )- .query(async (opts) => {- const whereConditions: SQL[] = [- inArray(monitor.id, opts.input.monitorIds.map(Number)),- eq(monitor.workspaceId, opts.ctx.workspace.id),- ];-- const _monitors = await db.query.monitor.findMany({- where: and(...whereConditions),- });-- if (_monitors.length !== opts.input.monitorIds.length) {- throw new TRPCError({- code: "NOT_FOUND",- message: "Some monitors not found",- });- }-- const procedure = getStatusProcedure(opts.input.period, opts.input.type);- return await procedure(opts.input);- }),-get: protectedProcedure.input(z.object({@@ -623,22 +468,6 @@ export const tinybirdRouter = createTRPCRouter({return await procedure(opts.input);}),- metricsLatencyMulti: protectedProcedure- .input(- z.object({- monitorIds: z.string().array(),- period: z.enum(["1d"]).prefault("1d"),- type: z.enum(types).prefault("http"),- }),- )- .query(async (opts) => {- const procedure = getMetricsLatencyMultiProcedure(- opts.input.period,- opts.input.type,- );- return await procedure(opts.input);- }),-workspace30d: protectedProcedure.input(z.object({