Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
fix: exclude deleted monitors from private location reads (#2661)
Ephraim Duncan10a42901fece
diff --git a/packages/services/src/private-location/__tests__/private-location.test.ts b/packages/services/src/private-location/__tests__/private-location.test.tsindex a23f9bc17..e103fb5f6 100644--- a/packages/services/src/private-location/__tests__/private-location.test.ts+++ b/packages/services/src/private-location/__tests__/private-location.test.ts@@ -11,8 +11,8 @@ import { expect } from "@std/expect";import { afterAll, beforeAll, describe, test } from "@std/testing/bdd";import {- expectAuditRow,createWorkspaceFixture,+ expectAuditRow,makeApiKeyCtx,makeUserCtx,readAuditLog,@@ -646,6 +646,35 @@ describe("getPrivateLocation", () => {});});+ test("excludes soft-deleted monitors from get and list without losing healthy monitors", async () => {+ await withTestTransaction(async (tx) => {+ const ctx = { ...teamCtx, db: tx };+ const created = await createPrivateLocation({+ ctx,+ input: {+ name: `${TEST_PREFIX}-deleted-attachment`,+ monitors: [teamMonitorId, secondMonitorId],+ },+ });+ await tx+ .update(monitor)+ .set({ active: false, deletedAt: new Date() })+ .where(eq(monitor.id, secondMonitorId));++ const found = await getPrivateLocation({+ ctx,+ input: { id: created.id },+ });+ const listed = await listPrivateLocations({ ctx });+ expect({+ get: found.monitors.map((m) => m.id),+ list: listed.items+ .find((item) => item.id === created.id)+ ?.monitors.map((m) => m.id),+ }).toEqual({ get: [teamMonitorId], list: [teamMonitorId] });+ });+ });+test("throws NotFoundError for an unknown id", async () => {await withTestTransaction(async (tx) => {await expect(diff --git a/packages/services/src/private-location/get.ts b/packages/services/src/private-location/get.tsindex 5df3be235..83d569ad8 100644--- a/packages/services/src/private-location/get.ts+++ b/packages/services/src/private-location/get.ts@@ -1,7 +1,7 @@import { and, eq } from "@openstatus/db";import { privateLocation } from "@openstatus/db/src/schema";-import { type ServiceContext, getReadDb } from "../context";+import { getReadDb, type ServiceContext } from "../context";import { NotFoundError } from "../errors";import { GetPrivateLocationInput } from "./schemas";@@ -36,6 +36,8 @@ export async function getPrivateLocation(args: {...row,monitors: row.privateLocationToMonitors.map((link) => link.monitor)- .filter((m) => m !== null),+ .filter(+ (m): m is NonNullable<typeof m> => m !== null && m.deletedAt === null,+ ),};}diff --git a/packages/services/src/private-location/list.ts b/packages/services/src/private-location/list.tsindex 6ad121428..265ab8ff0 100644--- a/packages/services/src/private-location/list.ts+++ b/packages/services/src/private-location/list.ts@@ -1,7 +1,7 @@import { count, desc, eq } from "@openstatus/db";import { privateLocation } from "@openstatus/db/src/schema";-import { type ServiceContext, getReadDb } from "../context";+import { getReadDb, type ServiceContext } from "../context";import { ListPrivateLocationsInput } from "./schemas";const LIMIT_DEFAULT = 50;@@ -9,7 +9,7 @@ const LIMIT_DEFAULT = 50;/*** List private locations in the caller's workspace, each one flattened to* include the monitors it's attached to (the relational join's `monitor`- * link lifted onto `monitors`, filtered to non-null).+ * link lifted onto `monitors`, excluding deleted monitors).** Return type is deliberately inferred from drizzle's relational query* rather than annotated: pulling the shape out of `@openstatus/db`'s@@ -46,7 +46,9 @@ export async function listPrivateLocations(args: {...row,monitors: row.privateLocationToMonitors.map((link) => link.monitor)- .filter((m) => m !== null),+ .filter(+ (m): m is NonNullable<typeof m> => m !== null && m.deletedAt === null,+ ),})),totalSize: total?.count ?? 0,};