Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
slack app: subscribe to status page (#2318)
Thibault Le Ouayd940385d3483
diff --git a/apps/dashboard/next-env.d.ts b/apps/dashboard/next-env.d.tsindex c4b7818fb..9edff1c7c 100644--- a/apps/dashboard/next-env.d.ts+++ b/apps/dashboard/next-env.d.ts@@ -1,6 +1,6 @@/// <reference types="next" />/// <reference types="next/image-types/global" />-import "./.next/dev/types/routes.d.ts";+import "./.next/types/routes.d.ts";// NOTE: This file should not be edited// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.diff --git a/apps/dashboard/src/app/api/chat/route.ts b/apps/dashboard/src/app/api/chat/route.tsindex ecf80b68b..546e6b96c 100644--- a/apps/dashboard/src/app/api/chat/route.ts+++ b/apps/dashboard/src/app/api/chat/route.ts@@ -26,8 +26,6 @@ import { toAiSdkTools } from "@/lib/agent-tools/adapter";import { getChatServiceContext } from "@/lib/agent-tools/context";import { chatRateLimit } from "@/lib/rate-limit/chat";-export const runtime = "edge";-// Drop tool parts that have no result the SDK can turn into a tool_result// block. `ignoreIncompleteToolCalls` doesn't cover `approval-requested`, so// a mid-confirmation reload would otherwise replay an orphan `tool_use` todiff --git a/apps/dashboard/src/app/api/onboarding/checks/route.ts b/apps/dashboard/src/app/api/onboarding/checks/route.tsindex eb01a9aba..a0ae5d815 100644--- a/apps/dashboard/src/app/api/onboarding/checks/route.ts+++ b/apps/dashboard/src/app/api/onboarding/checks/route.ts@@ -8,8 +8,6 @@ import { z } from "zod";import { getServiceContextFromRequest } from "@/lib/edge-context";-export const runtime = "edge";-const SERVICE_ERROR_STATUS: Record<ServiceErrorCode, number> = {NOT_FOUND: 404,FORBIDDEN: 403,diff --git a/apps/dashboard/src/app/api/trpc/edge/[trpc]/route.ts b/apps/dashboard/src/app/api/trpc/edge/[trpc]/route.tsdeleted file mode 100644index 9dd8225ba..000000000--- a/apps/dashboard/src/app/api/trpc/edge/[trpc]/route.ts+++ /dev/null@@ -1,24 +0,0 @@-import { createTRPCContext } from "@openstatus/api";-import { edgeRouter } from "@openstatus/api/src/edge";-import { fetchRequestHandler } from "@trpc/server/adapters/fetch";-import type { NextRequest } from "next/server";--import { auth } from "@/lib/auth";-import { createOnError, guardTRPCSource } from "@/lib/trpc/shared";--export const runtime = "edge";--const handler = (req: NextRequest) => {- const blocked = guardTRPCSource(req);- if (blocked) return blocked;-- return fetchRequestHandler({- endpoint: "/api/trpc/edge",- router: edgeRouter,- req: req,- createContext: () => createTRPCContext({ req, auth }),- onError: createOnError("edge"),- });-};--export { handler as GET, handler as POST };diff --git a/apps/dashboard/src/app/api/trpc/lambda/[trpc]/route.ts b/apps/dashboard/src/app/api/trpc/lambda/[trpc]/route.tsindex 944ea4af4..0ebe36093 100644--- a/apps/dashboard/src/app/api/trpc/lambda/[trpc]/route.ts+++ b/apps/dashboard/src/app/api/trpc/lambda/[trpc]/route.ts@@ -1,13 +1,13 @@-import { createTRPCContext } from "@openstatus/api";-import { lambdaRouter } from "@openstatus/api/src/lambda";+import { appRouter, createTRPCContext } from "@openstatus/api";import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import type { NextRequest } from "next/server";import { auth } from "@/lib/auth";import { createOnError, guardTRPCSource } from "@/lib/trpc/shared";-// Stripe is incompatible with Edge runtimes due to using Node.js events-// export const runtime = "edge";+// Runs on the Node.js runtime (Vercel Fluid compute). The whole tRPC surface+// is served here — several routers pull Node-only deps (@slack/web-api, email+// and notification SDKs) that are not Edge-safe.const handler = (req: NextRequest) => {const blocked = guardTRPCSource(req);@@ -15,7 +15,7 @@ const handler = (req: NextRequest) => {return fetchRequestHandler({endpoint: "/api/trpc/lambda",- router: lambdaRouter,+ router: appRouter,req: req,createContext: () => createTRPCContext({ req, auth }),onError: createOnError("lambda"),diff --git a/apps/dashboard/src/components/data-table/subscribers/columns.tsx b/apps/dashboard/src/components/data-table/subscribers/columns.tsxindex f011edf23..eccab5285 100644--- a/apps/dashboard/src/components/data-table/subscribers/columns.tsx+++ b/apps/dashboard/src/components/data-table/subscribers/columns.tsx@@ -40,7 +40,9 @@ export const columns: ColumnDef<Subscriber>[] = [const flavor =sub.channelType === "webhook"? detectFlavorBadge(sub.webhookUrl)- : null;+ : sub.channelType === "slack"+ ? "Slack"+ : null;return (<div className="flex items-center gap-2">diff --git a/apps/dashboard/src/components/data-table/subscribers/data-table-row-actions.tsx b/apps/dashboard/src/components/data-table/subscribers/data-table-row-actions.tsxindex 25c6a4304..34b93dacb 100644--- a/apps/dashboard/src/components/data-table/subscribers/data-table-row-actions.tsx+++ b/apps/dashboard/src/components/data-table/subscribers/data-table-row-actions.tsx@@ -61,19 +61,20 @@ export function DataTableRowActions({ row }: DataTableRowActionsProps) {statusPage?.pageComponentGroups ?? [],);- const editDefaults = isVendorAdded- ? {- channelType: sub.channelType,- name: sub.name ?? "",- email: sub.email ?? "",- webhookUrl: sub.webhookUrl ?? "",- headers: parseHeaders(sub.channelConfig),- componentIds: sub.components.map((c) => c.id),- }- : undefined;+ const editDefaults =+ isVendorAdded && sub.channelType !== "slack"+ ? {+ channelType: sub.channelType,+ name: sub.name ?? "",+ email: sub.email ?? "",+ webhookUrl: sub.webhookUrl ?? "",+ headers: parseHeaders(sub.channelConfig),+ componentIds: sub.components.map((c) => c.id),+ }+ : undefined;const actions = [- ...(isVendorAdded+ ...(isVendorAdded && sub.channelType !== "slack"? [{id: "edit",diff --git a/apps/dashboard/src/lib/trpc/shared.ts b/apps/dashboard/src/lib/trpc/shared.tsindex 23187324e..41f74d6f4 100644--- a/apps/dashboard/src/lib/trpc/shared.ts+++ b/apps/dashboard/src/lib/trpc/shared.ts@@ -34,44 +34,18 @@ const getBaseUrl = () => {return "http://localhost:3000"; // Local dev and Docker (internal calls)};-const lambdas = [- "stripeRouter",- "emailRouter",- "apiKeyRouter",- "integrationRouter",- "blob",- "subscriberNotification",-];--export const endingLink = (opts?: {- fetch?: typeof fetch;- headers?: HTTPHeaders | (() => HTTPHeaders | Promise<HTTPHeaders>);-}) =>- ((runtime) => {- const sharedOpts = {+// The whole tRPC surface is served from a single Node.js endpoint — there is+// no longer an Edge/Node split, so all calls go to one link.+export const endingLink =+ (opts?: {+ fetch?: typeof fetch;+ headers?: HTTPHeaders | (() => HTTPHeaders | Promise<HTTPHeaders>);+ }): TRPCLink<AppRouter> =>+ (runtime) =>+ httpBatchLink({headers: opts?.headers,fetch: opts?.fetch,transformer: superjson,- // oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove any- } satisfies Partial<HTTPBatchLinkOptions<any>>;-- const edgeLink = httpBatchLink({- ...sharedOpts,- url: `${getBaseUrl()}/api/trpc/edge`,- })(runtime);- const lambdaLink = httpBatchLink({- ...sharedOpts,url: `${getBaseUrl()}/api/trpc/lambda`,- })(runtime);-- return (ctx) => {- const path = ctx.op.path.split(".") as [string, ...string[]];- const endpoint = lambdas.includes(path[0]) ? "lambda" : "edge";-- const newCtx = {- ...ctx,- op: { ...ctx.op, path: path.join(".") },- };- return endpoint === "edge" ? edgeLink(newCtx) : lambdaLink(newCtx);- };- }) satisfies TRPCLink<AppRouter>;+ // oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove any+ } satisfies Partial<HTTPBatchLinkOptions<any>>)(runtime);diff --git a/apps/server/src/routes/rpc/handlers/status-page/converters.ts b/apps/server/src/routes/rpc/handlers/status-page/converters.tsindex 8803c8473..5452c018b 100644--- a/apps/server/src/routes/rpc/handlers/status-page/converters.ts+++ b/apps/server/src/routes/rpc/handlers/status-page/converters.ts@@ -77,7 +77,7 @@ export type DBPageSubscriber = {updatedAt: Date | null;source: "self_signup" | "vendor" | "import";name: string | null;- channelType: "email" | "webhook";+ channelType: "email" | "webhook" | "slack";webhookUrl: string | null;channelConfig: string | null;componentIds?: number[];diff --git a/apps/server/src/routes/rpc/interceptors/__tests__/tracking.test.ts b/apps/server/src/routes/rpc/interceptors/__tests__/tracking.test.tsindex 234213c13..38a05bdbb 100644--- a/apps/server/src/routes/rpc/interceptors/__tests__/tracking.test.ts+++ b/apps/server/src/routes/rpc/interceptors/__tests__/tracking.test.ts@@ -1,7 +1,7 @@import type { Interceptor } from "@connectrpc/connect";import { Events } from "@openstatus/analytics";// @ts-nocheck — ConnectRPC's deep generic types (AnyFn, UnaryResponse, etc.)-// are incompatible with bun:test mocks. All runtime behavior is correct.+// are incompatible with the test mocks. All runtime behavior is correct.import {beforeEach,describe,diff --git a/apps/server/src/routes/slack/commands.ts b/apps/server/src/routes/slack/commands.tsnew file mode 100644index 000000000..1a4e0900e--- /dev/null+++ b/apps/server/src/routes/slack/commands.ts@@ -0,0 +1,153 @@+import { ForbiddenError } from "@openstatus/services";+import {+ createSlackSubscriber,+ listSlackSubscribersForChannel,+ removeSlackSubscriber,+} from "@openstatus/services/page-subscriber";+import { WebClient } from "@slack/web-api";+import type { Context } from "hono";+import { z } from "zod";++import { resolvePageFromUrl } from "./resolve-page";+import { resolveWorkspace } from "./workspace-resolver";++const slashCommandSchema = z.object({+ text: z.string().optional().default(""),+ team_id: z.string(),+ channel_id: z.string(),+ channel_name: z.string().optional(),+});++const HELP = [+ "*openstatus*",+ "• `/openstatus subscribe <status-page-url>` — subscribe this channel to a status page",+ "• `/openstatus unsubscribe <status-page-url>` — unsubscribe",+ "• `/openstatus subscriptions` — show this channel's subscriptions",+].join("\n");++function ephemeral(c: Context, text: string) {+ return c.json({ response_type: "ephemeral", text });+}++async function joinChannel(teamId: string, channelId: string): Promise<void> {+ try {+ const resolved = await resolveWorkspace(teamId);+ if (!resolved) return;+ const client = new WebClient(resolved.botToken);+ await client.conversations.join({ channel: channelId });+ } catch (error) {+ // Private channels can't be self-joined — the bot must be /invited.+ if (error instanceof Error) {+ console.error(+ `slack: conversations.join failed for ${channelId}: ${error.message}`,+ );+ }+ }+}++export async function handleSlackCommand(c: Context) {+ const parsed = slashCommandSchema.safeParse(c.get("slackBody"));+ if (!parsed.success) {+ return ephemeral(c, "Could not read the command.");+ }+ const { text, team_id, channel_id, channel_name } = parsed.data;++ const tokens = text.trim().split(/\s+/).filter(Boolean);+ const sub = (tokens[0] ?? "help").toLowerCase();+ const arg = tokens[1];++ if (sub === "subscribe") {+ if (!arg) {+ return ephemeral(c, "Usage: `/openstatus subscribe <status-page-url>`");+ }+ const page = await resolvePageFromUrl(arg);+ if (!page) {+ return ephemeral(c, `Couldn't find a status page at \`${arg}\`.`);+ }+ try {+ const result = await createSlackSubscriber({+ input: {+ pageId: page.id,+ teamId: team_id,+ channelId: channel_id,+ channelName: channel_name,+ },+ });+ await joinChannel(team_id, channel_id);+ if (result.alreadySubscribed) {+ return ephemeral(+ c,+ `This channel is already subscribed to *${page.title}*.`,+ );+ }+ return ephemeral(+ c,+ `📡 This channel is now subscribed to *${page.title}*. Incident updates will appear here.`,+ );+ } catch (error) {+ if (error instanceof ForbiddenError) {+ return ephemeral(+ c,+ `*${page.title}* isn't on a plan that supports subscribers.`,+ );+ }+ console.error("slack /openstatus subscribe failed:", error);+ return ephemeral(c, "Something went wrong subscribing this channel.");+ }+ }++ if (sub === "unsubscribe") {+ if (!arg) {+ const subs = await listSlackSubscribersForChannel({+ input: { teamId: team_id, channelId: channel_id },+ });+ if (subs.length === 0) {+ return ephemeral(+ c,+ "This channel isn't subscribed to any status page.",+ );+ }+ if (subs.length === 1) {+ await removeSlackSubscriber({+ input: {+ pageId: subs[0].pageId,+ teamId: team_id,+ channelId: channel_id,+ },+ });+ return ephemeral(c, `Unsubscribed from *${subs[0].pageName}*.`);+ }+ const list = subs.map((s) => `• ${s.pageName}`).join("\n");+ return ephemeral(+ c,+ `This channel is subscribed to several pages — specify which:\n${list}\n\nUsage: \`/openstatus unsubscribe <status-page-url>\``,+ );+ }+ const page = await resolvePageFromUrl(arg);+ if (!page) {+ return ephemeral(c, `Couldn't find a status page at \`${arg}\`.`);+ }+ const { removed } = await removeSlackSubscriber({+ input: { pageId: page.id, teamId: team_id, channelId: channel_id },+ });+ return ephemeral(+ c,+ removed+ ? `Unsubscribed from *${page.title}*.`+ : `This channel wasn't subscribed to *${page.title}*.`,+ );+ }++ if (sub === "subscriptions") {+ const subs = await listSlackSubscribersForChannel({+ input: { teamId: team_id, channelId: channel_id },+ });+ if (subs.length === 0) {+ return ephemeral(c, "This channel isn't subscribed to any status page.");+ }+ const list = subs.map((s) => `• *${s.pageName}*`).join("\n");+ return ephemeral(c, `This channel is subscribed to:\n${list}`);+ }++ return ephemeral(c, HELP);+}diff --git a/apps/server/src/routes/slack/handler.ts b/apps/server/src/routes/slack/handler.tsindex 2e2012f45..1c9723218 100644--- a/apps/server/src/routes/slack/handler.ts+++ b/apps/server/src/routes/slack/handler.ts@@ -1,6 +1,6 @@import { getLogger } from "@logtape/logtape";-import { and, db, eq } from "@openstatus/db";-import { integration } from "@openstatus/db/src/schema";+import { and, db, eq, isNull, sql } from "@openstatus/db";+import { integration, pageSubscriber } from "@openstatus/db/src/schema";import { WebClient } from "@slack/web-api";import type { Context } from "hono";import { z } from "zod";@@ -123,6 +123,16 @@ async function processEvent(body: SlackEvent) {eq(integration.externalId, teamId),),);+ await db+ .update(pageSubscriber)+ .set({ unsubscribedAt: new Date(), updatedAt: new Date() })+ .where(+ and(+ eq(pageSubscriber.channelType, "slack"),+ isNull(pageSubscriber.unsubscribedAt),+ sql`json_extract(${pageSubscriber.channelConfig}, '$.teamId') = ${teamId}`,+ ),+ );logger.info("slack integration cleaned up", { teamId });}return;diff --git a/apps/server/src/routes/slack/index.ts b/apps/server/src/routes/slack/index.tsindex 74dbde0d3..050b687d4 100644--- a/apps/server/src/routes/slack/index.ts+++ b/apps/server/src/routes/slack/index.ts@@ -2,6 +2,7 @@ import { Hono } from "hono";import { env } from "@/env";+import { handleSlackCommand } from "./commands";import { handleSlackEvent } from "./handler";import { handleSlackInteraction } from "./interactions";import { handleSlackInstall, handleSlackOAuthCallback } from "./oauth";@@ -28,5 +29,6 @@ slack.get("/oauth/callback", handleSlackOAuthCallback);slack.post("/events", verifySlackSignature, handleSlackEvent);slack.post("/interactions", verifySlackSignature, handleSlackInteraction);+slack.post("/commands", verifySlackSignature, handleSlackCommand);export { slack as slackRoute };diff --git a/apps/server/src/routes/slack/oauth.ts b/apps/server/src/routes/slack/oauth.tsindex ae88c3ed3..636fedd9d 100644--- a/apps/server/src/routes/slack/oauth.ts+++ b/apps/server/src/routes/slack/oauth.ts@@ -19,7 +19,9 @@ const SLACK_TOKEN_URL = "https://slack.com/api/oauth.v2.access";const BOT_SCOPES = ["app_mentions:read","channels:history",+ "channels:join","chat:write",+ "commands","groups:history","groups:read","groups:write",diff --git a/apps/server/src/routes/slack/resolve-page.ts b/apps/server/src/routes/slack/resolve-page.tsnew file mode 100644index 000000000..6efa62164--- /dev/null+++ b/apps/server/src/routes/slack/resolve-page.ts@@ -0,0 +1,69 @@+import { db, eq, or, sql } from "@openstatus/db";+import { page } from "@openstatus/db/src/schema";++const BASE_DOMAIN_SUFFIX = ".openstatus.dev";++export interface ResolvedPage {+ id: number;+ title: string;+ slug: string;+ customDomain: string | null;+}++function hostFromInput(raw: string): string | null {+ const trimmed = raw.trim();+ if (!trimmed) return null;+ const withScheme = /^https?:\/\//i.test(trimmed)+ ? trimmed+ : `https://${trimmed}`;+ try {+ return new URL(withScheme).hostname.toLowerCase();+ } catch {+ return null;+ }+}++/**+ * Resolve a public status-page URL (or bare host) to its page. Cross-workspace+ * by design — Slack subscriptions are public self-signup, like email.+ */+export async function resolvePageFromUrl(+ raw: string,+): Promise<ResolvedPage | null> {+ const host = hostFromInput(raw);+ if (!host) return null;++ if (host.endsWith(BASE_DOMAIN_SUFFIX)) {+ const slug = host.slice(0, -BASE_DOMAIN_SUFFIX.length);+ if (!slug || slug.includes(".")) return null;+ const row = await db+ .select({+ id: page.id,+ title: page.title,+ slug: page.slug,+ customDomain: page.customDomain,+ })+ .from(page)+ .where(eq(page.slug, slug))+ .get();+ return row ?? null;+ }++ const bareHost = host.startsWith("www.") ? host.slice(4) : host;+ const row = await db+ .select({+ id: page.id,+ title: page.title,+ slug: page.slug,+ customDomain: page.customDomain,+ })+ .from(page)+ .where(+ or(+ sql`LOWER(${page.customDomain}) = ${host}`,+ sql`LOWER(${page.customDomain}) = ${bareHost}`,+ ),+ )+ .get();+ return row ?? null;+}diff --git a/apps/server/src/routes/slack/verify.ts b/apps/server/src/routes/slack/verify.tsindex 3b1d3fa23..569d30f7e 100644--- a/apps/server/src/routes/slack/verify.ts+++ b/apps/server/src/routes/slack/verify.ts@@ -59,7 +59,12 @@ export const verifySlackSignature = createMiddleware<{} else if (contentType.includes("application/x-www-form-urlencoded")) {const params = new URLSearchParams(rawBody);const payload = params.get("payload");- c.set("slackBody", payload ? JSON.parse(payload) : {});+ // Interactions arrive as a `payload` field; slash commands arrive as the+ // flat form fields themselves.+ c.set(+ "slackBody",+ payload ? JSON.parse(payload) : Object.fromEntries(params),+ );}await next();diff --git a/apps/status-page/next-env.d.ts b/apps/status-page/next-env.d.tsindex c4b7818fb..9edff1c7c 100644--- a/apps/status-page/next-env.d.ts+++ b/apps/status-page/next-env.d.ts@@ -1,6 +1,6 @@/// <reference types="next" />/// <reference types="next/image-types/global" />-import "./.next/dev/types/routes.d.ts";+import "./.next/types/routes.d.ts";// NOTE: This file should not be edited// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.diff --git a/apps/status-page/src/app/api/trpc/edge/[trpc]/route.ts b/apps/status-page/src/app/api/trpc/edge/[trpc]/route.tsdeleted file mode 100644index c05e3b01e..000000000--- a/apps/status-page/src/app/api/trpc/edge/[trpc]/route.ts+++ /dev/null@@ -1,24 +0,0 @@-import { createTRPCContext } from "@openstatus/api";-import { edgeRouter } from "@openstatus/api/src/edge";-import { fetchRequestHandler } from "@trpc/server/adapters/fetch";-import type { NextRequest } from "next/server";--import { auth } from "../../../../../lib/auth";-import { createOnError, guardTRPCSource } from "../../../../../lib/trpc/shared";--export const runtime = "edge";--const handler = (req: NextRequest) => {- const blocked = guardTRPCSource(req);- if (blocked) return blocked;-- return fetchRequestHandler({- endpoint: "/api/trpc/edge",- router: edgeRouter,- req: req,- createContext: () => createTRPCContext({ req, auth }),- onError: createOnError("edge"),- });-};--export { handler as GET, handler as POST };diff --git a/apps/status-page/src/app/api/trpc/lambda/[trpc]/route.ts b/apps/status-page/src/app/api/trpc/lambda/[trpc]/route.tsindex f17aa8177..f3c1eef83 100644--- a/apps/status-page/src/app/api/trpc/lambda/[trpc]/route.ts+++ b/apps/status-page/src/app/api/trpc/lambda/[trpc]/route.ts@@ -1,13 +1,13 @@-import { createTRPCContext } from "@openstatus/api";-import { lambdaRouter } from "@openstatus/api/src/lambda";+import { appRouter, createTRPCContext } from "@openstatus/api";import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import type { NextRequest } from "next/server";import { auth } from "../../../../../lib/auth";import { createOnError, guardTRPCSource } from "../../../../../lib/trpc/shared";-// Stripe is incompatible with Edge runtimes due to using Node.js events-// export const runtime = "edge";+// Runs on the Node.js runtime (Vercel Fluid compute). The whole tRPC surface+// is served here — several routers pull Node-only deps (@slack/web-api, email+// and notification SDKs) that are not Edge-safe.const handler = (req: NextRequest) => {const blocked = guardTRPCSource(req);@@ -15,7 +15,7 @@ const handler = (req: NextRequest) => {return fetchRequestHandler({endpoint: "/api/trpc/lambda",- router: lambdaRouter,+ router: appRouter,req: req,createContext: () => createTRPCContext({ req, auth }),onError: createOnError("lambda"),diff --git a/apps/status-page/src/lib/trpc/shared.ts b/apps/status-page/src/lib/trpc/shared.tsindex 23df75bfd..f1b1516da 100644--- a/apps/status-page/src/lib/trpc/shared.ts+++ b/apps/status-page/src/lib/trpc/shared.ts@@ -48,37 +48,18 @@ const getBaseUrl = () => {return "http://localhost:3000"; // Local dev and Docker (internal calls)};-const lambdas = ["stripeRouter", "emailRouter"];--export const endingLink = (opts?: {- fetch?: typeof fetch;- headers?: HTTPHeaders | (() => HTTPHeaders | Promise<HTTPHeaders>);-}) =>- ((runtime) => {- const sharedOpts = {+// The whole tRPC surface is served from a single Node.js endpoint — there is+// no longer an Edge/Node split, so all calls go to one link.+export const endingLink =+ (opts?: {+ fetch?: typeof fetch;+ headers?: HTTPHeaders | (() => HTTPHeaders | Promise<HTTPHeaders>);+ }): TRPCLink<AppRouter> =>+ (runtime) =>+ httpBatchLink({headers: opts?.headers,fetch: opts?.fetch,transformer: superjson,- // oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove any- } satisfies Partial<HTTPBatchLinkOptions<any>>;-- const edgeLink = httpBatchLink({- ...sharedOpts,- url: `${getBaseUrl()}/api/trpc/edge`,- })(runtime);- const lambdaLink = httpBatchLink({- ...sharedOpts,url: `${getBaseUrl()}/api/trpc/lambda`,- })(runtime);-- return (ctx) => {- const path = ctx.op.path.split(".") as [string, ...string[]];- const endpoint = lambdas.includes(path[0]) ? "lambda" : "edge";-- const newCtx = {- ...ctx,- op: { ...ctx.op, path: path.join(".") },- };- return endpoint === "edge" ? edgeLink(newCtx) : lambdaLink(newCtx);- };- }) satisfies TRPCLink<AppRouter>;+ // oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove any+ } satisfies Partial<HTTPBatchLinkOptions<any>>)(runtime);diff --git a/apps/web/next-env.d.ts b/apps/web/next-env.d.tsindex c4b7818fb..9edff1c7c 100644--- a/apps/web/next-env.d.ts+++ b/apps/web/next-env.d.ts@@ -1,6 +1,6 @@/// <reference types="next" />/// <reference types="next/image-types/global" />-import "./.next/dev/types/routes.d.ts";+import "./.next/types/routes.d.ts";// NOTE: This file should not be edited// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.diff --git a/apps/web/src/app/api/trpc/edge/[trpc]/route.ts b/apps/web/src/app/api/trpc/edge/[trpc]/route.tsdeleted file mode 100644index 5a339780e..000000000--- a/apps/web/src/app/api/trpc/edge/[trpc]/route.ts+++ /dev/null@@ -1,23 +0,0 @@-import { createTRPCContext } from "@openstatus/api";-import { edgeRouter } from "@openstatus/api/src/edge";-import { fetchRequestHandler } from "@trpc/server/adapters/fetch";-import type { NextRequest } from "next/server";--import { createOnError, guardTRPCSource } from "../../../../../trpc/shared";--export const runtime = "edge";--const handler = (req: NextRequest) => {- const blocked = guardTRPCSource(req);- if (blocked) return blocked;-- return fetchRequestHandler({- endpoint: "/api/trpc/edge",- router: edgeRouter,- req: req,- createContext: () => createTRPCContext({ req }),- onError: createOnError("edge"),- });-};--export { handler as GET, handler as POST };diff --git a/apps/web/src/app/api/trpc/lambda/[trpc]/route.ts b/apps/web/src/app/api/trpc/lambda/[trpc]/route.tsindex ddbd1dbbd..477427b3d 100644--- a/apps/web/src/app/api/trpc/lambda/[trpc]/route.ts+++ b/apps/web/src/app/api/trpc/lambda/[trpc]/route.ts@@ -1,12 +1,12 @@-import { createTRPCContext } from "@openstatus/api";-import { lambdaRouter } from "@openstatus/api/src/lambda";+import { appRouter, createTRPCContext } from "@openstatus/api";import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import type { NextRequest } from "next/server";import { createOnError, guardTRPCSource } from "../../../../../trpc/shared";-// Stripe is incompatible with Edge runtimes due to using Node.js events-// export const runtime = "edge";+// Runs on the Node.js runtime (Vercel Fluid compute). The whole tRPC surface+// is served here — several routers pull Node-only deps (@slack/web-api, email+// and notification SDKs) that are not Edge-safe.const handler = (req: NextRequest) => {const blocked = guardTRPCSource(req);@@ -14,7 +14,7 @@ const handler = (req: NextRequest) => {return fetchRequestHandler({endpoint: "/api/trpc/lambda",- router: lambdaRouter,+ router: appRouter,req: req,createContext: () => createTRPCContext({ req }),onError: createOnError("lambda"),diff --git a/apps/web/src/trpc/shared.ts b/apps/web/src/trpc/shared.tsindex 22730388a..720877890 100644--- a/apps/web/src/trpc/shared.ts+++ b/apps/web/src/trpc/shared.ts@@ -35,35 +35,16 @@ const getBaseUrl = () => {return "http://localhost:3000"; // Local dev};-const lambdas = ["stripeRouter", "emailRouter"];--export const endingLink = (opts?: {- headers?: HTTPHeaders | (() => HTTPHeaders | Promise<HTTPHeaders>);-}) =>- ((runtime) => {- const sharedOpts = {+// The whole tRPC surface is served from a single Node.js endpoint — there is+// no longer an Edge/Node split, so all calls go to one link.+export const endingLink =+ (opts?: {+ headers?: HTTPHeaders | (() => HTTPHeaders | Promise<HTTPHeaders>);+ }): TRPCLink<AppRouter> =>+ (runtime) =>+ httpBatchLink({headers: opts?.headers, // REMINDER: fails when trying to `getTotalActiveMonitors()`transformer: superjson,- // oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove any- } satisfies Partial<HTTPBatchLinkOptions<any>>;-- const edgeLink = httpBatchLink({- ...sharedOpts,- url: `${getBaseUrl()}/api/trpc/edge`,- })(runtime);- const lambdaLink = httpBatchLink({- ...sharedOpts,url: `${getBaseUrl()}/api/trpc/lambda`,- })(runtime);-- return (ctx) => {- const path = ctx.op.path.split(".") as [string, ...string[]];- const endpoint = lambdas.includes(path[0]) ? "lambda" : "edge";-- const newCtx = {- ...ctx,- op: { ...ctx.op, path: path.join(".") },- };- return endpoint === "edge" ? edgeLink(newCtx) : lambdaLink(newCtx);- };- }) satisfies TRPCLink<AppRouter>;+ // oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove any+ } satisfies Partial<HTTPBatchLinkOptions<any>>)(runtime);diff --git a/deno.lock b/deno.lockindex ce3a1683f..89e71aa78 100644--- a/deno.lock+++ b/deno.lock@@ -264,6 +264,14 @@]}},+ "packages/tinybird": {+ "packageJson": {+ "dependencies": [+ "npm:@jsr/std__expect@^1.0.19",+ "npm:@jsr/std__testing@^1.0.19"+ ]+ }+ },"packages/tracker": {"packageJson": {"dependencies": [diff --git a/packages/analytics/src/server.ts b/packages/analytics/src/server.tsindex 780ef16e8..799266b95 100644--- a/packages/analytics/src/server.ts+++ b/packages/analytics/src/server.ts@@ -3,15 +3,24 @@ import { OpenPanel, type TrackProperties } from "@openpanel/sdk";import { env } from "../env";import type { EventProps } from "./events";-const op = new OpenPanel({- clientId: env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID,- clientSecret: env.OPENPANEL_CLIENT_SECRET,-});+// Lazily instantiate so importing this module has no side effects — a top-level+// `new OpenPanel()` runs the node SDK at import time, which breaks bundling the+// tRPC context into the Edge runtime.+let client: OpenPanel | undefined;-op.setGlobalProperties({- env: process.env.VERCEL_ENV || process.env.NODE_ENV || "localhost",- // app_version-});+function getClient() {+ if (!client) {+ client = new OpenPanel({+ clientId: env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID,+ clientSecret: env.OPENPANEL_CLIENT_SECRET,+ });+ client.setGlobalProperties({+ env: process.env.VERCEL_ENV || process.env.NODE_ENV || "localhost",+ // app_version+ });+ }+ return client;+}export type IdentifyProps = {userId?: string;@@ -29,6 +38,8 @@ export async function setupAnalytics(props: IdentifyProps) {return noop();}+ const op = getClient();+if (props.location) {op.api.addHeader("x-client-ip", props.location);}diff --git a/packages/db/drizzle/0078_yellow_thor_girl.sql b/packages/db/drizzle/0078_yellow_thor_girl.sqlnew file mode 100644index 000000000..c9acaa905--- /dev/null+++ b/packages/db/drizzle/0078_yellow_thor_girl.sql@@ -0,0 +1,28 @@+PRAGMA foreign_keys=OFF;--> statement-breakpoint+CREATE TABLE `__new_page_subscriber` (+ `id` integer PRIMARY KEY NOT NULL,+ `email` text,+ `page_id` integer NOT NULL,+ `channel_type` text DEFAULT 'email' NOT NULL,+ `webhook_url` text,+ `channel_config` text,+ `slack_channel_id` text,+ `source` text DEFAULT 'self_signup' NOT NULL,+ `name` text,+ `token` text,+ `accepted_at` integer,+ `expires_at` integer,+ `unsubscribed_at` integer,+ `created_at` integer DEFAULT (strftime('%s', 'now')),+ `updated_at` integer DEFAULT (strftime('%s', 'now')),+ FOREIGN KEY (`page_id`) REFERENCES `page`(`id`) ON UPDATE no action ON DELETE cascade,+ CONSTRAINT "page_subscriber_channel_check" CHECK(("__new_page_subscriber"."channel_type" = 'email' AND "__new_page_subscriber"."email" IS NOT NULL AND "__new_page_subscriber"."webhook_url" IS NULL) OR ("__new_page_subscriber"."channel_type" = 'webhook' AND "__new_page_subscriber"."webhook_url" IS NOT NULL AND "__new_page_subscriber"."email" IS NULL) OR ("__new_page_subscriber"."channel_type" = 'slack' AND "__new_page_subscriber"."slack_channel_id" IS NOT NULL AND "__new_page_subscriber"."email" IS NULL AND "__new_page_subscriber"."webhook_url" IS NULL))+);+--> statement-breakpoint+INSERT INTO `__new_page_subscriber`("id", "email", "page_id", "channel_type", "webhook_url", "channel_config", "slack_channel_id", "source", "name", "token", "accepted_at", "expires_at", "unsubscribed_at", "created_at", "updated_at") SELECT "id", "email", "page_id", "channel_type", "webhook_url", "channel_config", NULL, "source", "name", "token", "accepted_at", "expires_at", "unsubscribed_at", "created_at", "updated_at" FROM `page_subscriber`;--> statement-breakpoint+DROP TABLE `page_subscriber`;--> statement-breakpoint+ALTER TABLE `__new_page_subscriber` RENAME TO `page_subscriber`;--> statement-breakpoint+PRAGMA foreign_keys=ON;--> statement-breakpoint+CREATE UNIQUE INDEX `idx_page_subscriber_email_page_active` ON `page_subscriber` (LOWER("email"), `page_id`) WHERE "page_subscriber"."unsubscribed_at" IS NULL AND "page_subscriber"."channel_type" = 'email';--> statement-breakpoint+CREATE UNIQUE INDEX `idx_page_subscriber_webhook_page_active` ON `page_subscriber` (LOWER("webhook_url"), `page_id`) WHERE "page_subscriber"."unsubscribed_at" IS NULL AND "page_subscriber"."channel_type" = 'webhook';--> statement-breakpoint+CREATE UNIQUE INDEX `idx_page_subscriber_slack_channel_page_active` ON `page_subscriber` (`slack_channel_id`, `page_id`) WHERE "page_subscriber"."unsubscribed_at" IS NULL AND "page_subscriber"."channel_type" = 'slack';diff --git a/packages/db/drizzle/meta/0078_snapshot.json b/packages/db/drizzle/meta/0078_snapshot.jsonnew file mode 100644index 000000000..8230a90f0--- /dev/null+++ b/packages/db/drizzle/meta/0078_snapshot.json@@ -0,0 +1,4712 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "80571dfe-ab0e-4531-823b-33173cedf9a2",+ "prevId": "e88d56a5-ae87-4b25-9d59-1153f97a63bb",+ "tables": {+ "workspace": {+ "name": "workspace",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "slug": {+ "name": "slug",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "stripe_id": {+ "name": "stripe_id",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "subscription_id": {+ "name": "subscription_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "plan": {+ "name": "plan",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "ends_at": {+ "name": "ends_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "paid_until": {+ "name": "paid_until",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "limits": {+ "name": "limits",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'{}'"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "dsn": {+ "name": "dsn",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "workspace_slug_unique": {+ "name": "workspace_slug_unique",+ "columns": [+ "slug"+ ],+ "isUnique": true+ },+ "workspace_stripe_id_unique": {+ "name": "workspace_stripe_id_unique",+ "columns": [+ "stripe_id"+ ],+ "isUnique": true+ },+ "workspace_id_dsn_unique": {+ "name": "workspace_id_dsn_unique",+ "columns": [+ "id",+ "dsn"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "account": {+ "name": "account",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider_account_id": {+ "name": "provider_account_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "refresh_token": {+ "name": "refresh_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "access_token": {+ "name": "access_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "token_type": {+ "name": "token_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "id_token": {+ "name": "id_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "session_state": {+ "name": "session_state",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "account_user_id_user_id_fk": {+ "name": "account_user_id_user_id_fk",+ "tableFrom": "account",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "account_provider_provider_account_id_pk": {+ "columns": [+ "provider",+ "provider_account_id"+ ],+ "name": "account_provider_provider_account_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "session": {+ "name": "session",+ "columns": {+ "session_token": {+ "name": "session_token",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "session_user_id_user_id_fk": {+ "name": "session_user_id_user_id_fk",+ "tableFrom": "session",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "user": {+ "name": "user",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "tenant_id": {+ "name": "tenant_id",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "first_name": {+ "name": "first_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "last_name": {+ "name": "last_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "photo_url": {+ "name": "photo_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "emailVerified": {+ "name": "emailVerified",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "deleted_at": {+ "name": "deleted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "user_tenant_id_unique": {+ "name": "user_tenant_id_unique",+ "columns": [+ "tenant_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "users_to_workspaces": {+ "name": "users_to_workspaces",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'member'"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "users_to_workspaces_workspace_id_idx": {+ "name": "users_to_workspaces_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "users_to_workspaces_user_id_user_id_fk": {+ "name": "users_to_workspaces_user_id_user_id_fk",+ "tableFrom": "users_to_workspaces",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "users_to_workspaces_workspace_id_workspace_id_fk": {+ "name": "users_to_workspaces_workspace_id_workspace_id_fk",+ "tableFrom": "users_to_workspaces",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "users_to_workspaces_user_id_workspace_id_pk": {+ "columns": [+ "user_id",+ "workspace_id"+ ],+ "name": "users_to_workspaces_user_id_workspace_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "verification_token": {+ "name": "verification_token",+ "columns": {+ "identifier": {+ "name": "identifier",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {+ "verification_token_identifier_token_pk": {+ "columns": [+ "identifier",+ "token"+ ],+ "name": "verification_token_identifier_token_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "status_report": {+ "name": "status_report",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "status_report_workspace_created_idx": {+ "name": "status_report_workspace_created_idx",+ "columns": [+ "workspace_id",+ "created_at"+ ],+ "isUnique": false+ },+ "status_report_page_id_idx": {+ "name": "status_report_page_id_idx",+ "columns": [+ "page_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "status_report_workspace_id_workspace_id_fk": {+ "name": "status_report_workspace_id_workspace_id_fk",+ "tableFrom": "status_report",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "status_report_page_id_page_id_fk": {+ "name": "status_report_page_id_page_id_fk",+ "tableFrom": "status_report",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "status_report_update": {+ "name": "status_report_update",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "date": {+ "name": "date",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status_report_id": {+ "name": "status_report_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "status_report_update_status_report_id_idx": {+ "name": "status_report_update_status_report_id_idx",+ "columns": [+ "status_report_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "status_report_update_status_report_id_status_report_id_fk": {+ "name": "status_report_update_status_report_id_status_report_id_fk",+ "tableFrom": "status_report_update",+ "tableTo": "status_report",+ "columnsFrom": [+ "status_report_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "integration": {+ "name": "integration",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "credential": {+ "name": "credential",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "external_id": {+ "name": "external_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "data": {+ "name": "data",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "integration_workspace_id_idx": {+ "name": "integration_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "integration_workspace_id_workspace_id_fk": {+ "name": "integration_workspace_id_workspace_id_fk",+ "tableFrom": "integration",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "page": {+ "name": "page",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "icon": {+ "name": "icon",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "slug": {+ "name": "slug",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "custom_domain": {+ "name": "custom_domain",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "published": {+ "name": "published",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "force_theme": {+ "name": "force_theme",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'system'"+ },+ "password": {+ "name": "password",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "password_protected": {+ "name": "password_protected",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "access_type": {+ "name": "access_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'public'"+ },+ "auth_email_domains": {+ "name": "auth_email_domains",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "allowed_ip_ranges": {+ "name": "allowed_ip_ranges",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "homepage_url": {+ "name": "homepage_url",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "contact_url": {+ "name": "contact_url",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "default_locale": {+ "name": "default_locale",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'en'"+ },+ "locales": {+ "name": "locales",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "legacy_page": {+ "name": "legacy_page",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": true+ },+ "configuration": {+ "name": "configuration",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "allow_index": {+ "name": "allow_index",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": true+ },+ "show_monitor_values": {+ "name": "show_monitor_values",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": true+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "page_slug_unique": {+ "name": "page_slug_unique",+ "columns": [+ "slug"+ ],+ "isUnique": true+ },+ "page_lower_slug_idx": {+ "name": "page_lower_slug_idx",+ "columns": [+ "LOWER(\"slug\")"+ ],+ "isUnique": false+ },+ "page_lower_custom_domain_idx": {+ "name": "page_lower_custom_domain_idx",+ "columns": [+ "LOWER(\"custom_domain\")"+ ],+ "isUnique": false+ },+ "page_workspace_id_idx": {+ "name": "page_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "page_workspace_id_workspace_id_fk": {+ "name": "page_workspace_id_workspace_id_fk",+ "tableFrom": "page",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor": {+ "name": "monitor",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "job_type": {+ "name": "job_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'http'"+ },+ "periodicity": {+ "name": "periodicity",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'other'"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'active'"+ },+ "active": {+ "name": "active",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "regions": {+ "name": "regions",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "url": {+ "name": "url",+ "type": "text(2048)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "external_name": {+ "name": "external_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "headers": {+ "name": "headers",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "body": {+ "name": "body",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "method": {+ "name": "method",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'GET'"+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "timeout": {+ "name": "timeout",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 45000+ },+ "degraded_after": {+ "name": "degraded_after",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "assertions": {+ "name": "assertions",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "otel_endpoint": {+ "name": "otel_endpoint",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "otel_headers": {+ "name": "otel_headers",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "public": {+ "name": "public",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "retry": {+ "name": "retry",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 3+ },+ "follow_redirects": {+ "name": "follow_redirects",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": true+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "deleted_at": {+ "name": "deleted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "monitor_workspace_id_active_idx": {+ "name": "monitor_workspace_id_active_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false,+ "where": "\"monitor\".\"deleted_at\" IS NULL"+ }+ },+ "foreignKeys": {+ "monitor_workspace_id_workspace_id_fk": {+ "name": "monitor_workspace_id_workspace_id_fk",+ "tableFrom": "monitor",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "page_subscriber": {+ "name": "page_subscriber",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "channel_type": {+ "name": "channel_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'email'"+ },+ "webhook_url": {+ "name": "webhook_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "channel_config": {+ "name": "channel_config",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "slack_channel_id": {+ "name": "slack_channel_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'self_signup'"+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "accepted_at": {+ "name": "accepted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "unsubscribed_at": {+ "name": "unsubscribed_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "idx_page_subscriber_email_page_active": {+ "name": "idx_page_subscriber_email_page_active",+ "columns": [+ "LOWER(\"email\")",+ "page_id"+ ],+ "isUnique": true,+ "where": "\"page_subscriber\".\"unsubscribed_at\" IS NULL AND \"page_subscriber\".\"channel_type\" = 'email'"+ },+ "idx_page_subscriber_webhook_page_active": {+ "name": "idx_page_subscriber_webhook_page_active",+ "columns": [+ "LOWER(\"webhook_url\")",+ "page_id"+ ],+ "isUnique": true,+ "where": "\"page_subscriber\".\"unsubscribed_at\" IS NULL AND \"page_subscriber\".\"channel_type\" = 'webhook'"+ },+ "idx_page_subscriber_slack_channel_page_active": {+ "name": "idx_page_subscriber_slack_channel_page_active",+ "columns": [+ "slack_channel_id",+ "page_id"+ ],+ "isUnique": true,+ "where": "\"page_subscriber\".\"unsubscribed_at\" IS NULL AND \"page_subscriber\".\"channel_type\" = 'slack'"+ }+ },+ "foreignKeys": {+ "page_subscriber_page_id_page_id_fk": {+ "name": "page_subscriber_page_id_page_id_fk",+ "tableFrom": "page_subscriber",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {+ "page_subscriber_channel_check": {+ "name": "page_subscriber_channel_check",+ "value": "(\"page_subscriber\".\"channel_type\" = 'email' AND \"page_subscriber\".\"email\" IS NOT NULL AND \"page_subscriber\".\"webhook_url\" IS NULL) OR (\"page_subscriber\".\"channel_type\" = 'webhook' AND \"page_subscriber\".\"webhook_url\" IS NOT NULL AND \"page_subscriber\".\"email\" IS NULL) OR (\"page_subscriber\".\"channel_type\" = 'slack' AND \"page_subscriber\".\"slack_channel_id\" IS NOT NULL AND \"page_subscriber\".\"email\" IS NULL AND \"page_subscriber\".\"webhook_url\" IS NULL)"+ }+ }+ },+ "page_subscriber_to_page_component": {+ "name": "page_subscriber_to_page_component",+ "columns": {+ "page_subscriber_id": {+ "name": "page_subscriber_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_component_id": {+ "name": "page_component_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "page_subscriber_to_page_component_page_subscriber_id_page_subscriber_id_fk": {+ "name": "page_subscriber_to_page_component_page_subscriber_id_page_subscriber_id_fk",+ "tableFrom": "page_subscriber_to_page_component",+ "tableTo": "page_subscriber",+ "columnsFrom": [+ "page_subscriber_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "page_subscriber_to_page_component_page_component_id_page_component_id_fk": {+ "name": "page_subscriber_to_page_component_page_component_id_page_component_id_fk",+ "tableFrom": "page_subscriber_to_page_component",+ "tableTo": "page_component",+ "columnsFrom": [+ "page_component_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "page_subscriber_to_page_component_page_subscriber_id_page_component_id_pk": {+ "columns": [+ "page_subscriber_id",+ "page_component_id"+ ],+ "name": "page_subscriber_to_page_component_page_subscriber_id_page_component_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "notification": {+ "name": "notification",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "data": {+ "name": "data",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'{}'"+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "notification_workspace_id_idx": {+ "name": "notification_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "notification_workspace_id_workspace_id_fk": {+ "name": "notification_workspace_id_workspace_id_fk",+ "tableFrom": "notification",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "notification_trigger": {+ "name": "notification_trigger",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "notification_id": {+ "name": "notification_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "cron_timestamp": {+ "name": "cron_timestamp",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "notification_id_monitor_id_crontimestampe": {+ "name": "notification_id_monitor_id_crontimestampe",+ "columns": [+ "notification_id",+ "monitor_id",+ "cron_timestamp"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "notification_trigger_monitor_id_monitor_id_fk": {+ "name": "notification_trigger_monitor_id_monitor_id_fk",+ "tableFrom": "notification_trigger",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "notification_trigger_notification_id_notification_id_fk": {+ "name": "notification_trigger_notification_id_notification_id_fk",+ "tableFrom": "notification_trigger",+ "tableTo": "notification",+ "columnsFrom": [+ "notification_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "notifications_to_monitors": {+ "name": "notifications_to_monitors",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "notification_id": {+ "name": "notification_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "notifications_to_monitors_notification_id_idx": {+ "name": "notifications_to_monitors_notification_id_idx",+ "columns": [+ "notification_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "notifications_to_monitors_monitor_id_monitor_id_fk": {+ "name": "notifications_to_monitors_monitor_id_monitor_id_fk",+ "tableFrom": "notifications_to_monitors",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "notifications_to_monitors_notification_id_notification_id_fk": {+ "name": "notifications_to_monitors_notification_id_notification_id_fk",+ "tableFrom": "notifications_to_monitors",+ "tableTo": "notification",+ "columnsFrom": [+ "notification_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "notifications_to_monitors_monitor_id_notification_id_pk": {+ "columns": [+ "monitor_id",+ "notification_id"+ ],+ "name": "notifications_to_monitors_monitor_id_notification_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor_status": {+ "name": "monitor_status",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "region": {+ "name": "region",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'active'"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "monitor_status_idx": {+ "name": "monitor_status_idx",+ "columns": [+ "monitor_id",+ "region"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "monitor_status_monitor_id_monitor_id_fk": {+ "name": "monitor_status_monitor_id_monitor_id_fk",+ "tableFrom": "monitor_status",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "monitor_status_monitor_id_region_pk": {+ "columns": [+ "monitor_id",+ "region"+ ],+ "name": "monitor_status_monitor_id_region_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "invitation": {+ "name": "invitation",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'member'"+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "accepted_at": {+ "name": "accepted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "invitation_workspace_id_idx": {+ "name": "invitation_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "incident": {+ "name": "incident",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "summary": {+ "name": "summary",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'triage'"+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "started_at": {+ "name": "started_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "acknowledged_at": {+ "name": "acknowledged_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "acknowledged_by": {+ "name": "acknowledged_by",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "resolved_at": {+ "name": "resolved_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "resolved_by": {+ "name": "resolved_by",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "incident_screenshot_url": {+ "name": "incident_screenshot_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "recovery_screenshot_url": {+ "name": "recovery_screenshot_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "auto_resolved": {+ "name": "auto_resolved",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "incident_workspace_id_idx": {+ "name": "incident_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ },+ "incident_monitor_id_started_at_unique": {+ "name": "incident_monitor_id_started_at_unique",+ "columns": [+ "monitor_id",+ "started_at"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "incident_monitor_id_monitor_id_fk": {+ "name": "incident_monitor_id_monitor_id_fk",+ "tableFrom": "incident",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set default",+ "onUpdate": "no action"+ },+ "incident_workspace_id_workspace_id_fk": {+ "name": "incident_workspace_id_workspace_id_fk",+ "tableFrom": "incident",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "incident_acknowledged_by_user_id_fk": {+ "name": "incident_acknowledged_by_user_id_fk",+ "tableFrom": "incident",+ "tableTo": "user",+ "columnsFrom": [+ "acknowledged_by"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "incident_resolved_by_user_id_fk": {+ "name": "incident_resolved_by_user_id_fk",+ "tableFrom": "incident",+ "tableTo": "user",+ "columnsFrom": [+ "resolved_by"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor_tag": {+ "name": "monitor_tag",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "monitor_tag_workspace_id_idx": {+ "name": "monitor_tag_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "monitor_tag_workspace_id_workspace_id_fk": {+ "name": "monitor_tag_workspace_id_workspace_id_fk",+ "tableFrom": "monitor_tag",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor_tag_to_monitor": {+ "name": "monitor_tag_to_monitor",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "monitor_tag_id": {+ "name": "monitor_tag_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "monitor_tag_to_monitor_monitor_tag_id_idx": {+ "name": "monitor_tag_to_monitor_monitor_tag_id_idx",+ "columns": [+ "monitor_tag_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "monitor_tag_to_monitor_monitor_id_monitor_id_fk": {+ "name": "monitor_tag_to_monitor_monitor_id_monitor_id_fk",+ "tableFrom": "monitor_tag_to_monitor",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "monitor_tag_to_monitor_monitor_tag_id_monitor_tag_id_fk": {+ "name": "monitor_tag_to_monitor_monitor_tag_id_monitor_tag_id_fk",+ "tableFrom": "monitor_tag_to_monitor",+ "tableTo": "monitor_tag",+ "columnsFrom": [+ "monitor_tag_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "monitor_tag_to_monitor_monitor_id_monitor_tag_id_pk": {+ "columns": [+ "monitor_id",+ "monitor_tag_id"+ ],+ "name": "monitor_tag_to_monitor_monitor_id_monitor_tag_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "application": {+ "name": "application",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "dsn": {+ "name": "dsn",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "application_dsn_unique": {+ "name": "application_dsn_unique",+ "columns": [+ "dsn"+ ],+ "isUnique": true+ },+ "application_workspace_id_idx": {+ "name": "application_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "application_workspace_id_workspace_id_fk": {+ "name": "application_workspace_id_workspace_id_fk",+ "tableFrom": "application",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "maintenance": {+ "name": "maintenance",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "from": {+ "name": "from",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "to": {+ "name": "to",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "maintenance_page_id_idx": {+ "name": "maintenance_page_id_idx",+ "columns": [+ "page_id"+ ],+ "isUnique": false+ },+ "maintenance_workspace_id_idx": {+ "name": "maintenance_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "maintenance_workspace_id_workspace_id_fk": {+ "name": "maintenance_workspace_id_workspace_id_fk",+ "tableFrom": "maintenance",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "maintenance_page_id_page_id_fk": {+ "name": "maintenance_page_id_page_id_fk",+ "tableFrom": "maintenance",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "check": {+ "name": "check",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "regions": {+ "name": "regions",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "url": {+ "name": "url",+ "type": "text(4096)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "headers": {+ "name": "headers",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "body": {+ "name": "body",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "method": {+ "name": "method",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'GET'"+ },+ "count_requests": {+ "name": "count_requests",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 1+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "check_workspace_id_idx": {+ "name": "check_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "check_workspace_id_workspace_id_fk": {+ "name": "check_workspace_id_workspace_id_fk",+ "tableFrom": "check",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor_run": {+ "name": "monitor_run",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "runned_at": {+ "name": "runned_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "monitor_run_workspace_id_idx": {+ "name": "monitor_run_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ },+ "monitor_run_monitor_id_idx": {+ "name": "monitor_run_monitor_id_idx",+ "columns": [+ "monitor_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "monitor_run_workspace_id_workspace_id_fk": {+ "name": "monitor_run_workspace_id_workspace_id_fk",+ "tableFrom": "monitor_run",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "monitor_run_monitor_id_monitor_id_fk": {+ "name": "monitor_run_monitor_id_monitor_id_fk",+ "tableFrom": "monitor_run",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "private_location": {+ "name": "private_location",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "last_seen_at": {+ "name": "last_seen_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "private_location_workspace_id_idx": {+ "name": "private_location_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "private_location_workspace_id_workspace_id_fk": {+ "name": "private_location_workspace_id_workspace_id_fk",+ "tableFrom": "private_location",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "private_location_to_monitor": {+ "name": "private_location_to_monitor",+ "columns": {+ "private_location_id": {+ "name": "private_location_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "deleted_at": {+ "name": "deleted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "private_location_to_monitor_private_location_id_idx": {+ "name": "private_location_to_monitor_private_location_id_idx",+ "columns": [+ "private_location_id"+ ],+ "isUnique": false+ },+ "private_location_to_monitor_monitor_id_idx": {+ "name": "private_location_to_monitor_monitor_id_idx",+ "columns": [+ "monitor_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "private_location_to_monitor_private_location_id_private_location_id_fk": {+ "name": "private_location_to_monitor_private_location_id_private_location_id_fk",+ "tableFrom": "private_location_to_monitor",+ "tableTo": "private_location",+ "columnsFrom": [+ "private_location_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "private_location_to_monitor_monitor_id_monitor_id_fk": {+ "name": "private_location_to_monitor_monitor_id_monitor_id_fk",+ "tableFrom": "private_location_to_monitor",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "monitor_group": {+ "name": "monitor_group",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "monitor_group_workspace_id_idx": {+ "name": "monitor_group_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ },+ "monitor_group_page_id_idx": {+ "name": "monitor_group_page_id_idx",+ "columns": [+ "page_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "monitor_group_workspace_id_workspace_id_fk": {+ "name": "monitor_group_workspace_id_workspace_id_fk",+ "tableFrom": "monitor_group",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "monitor_group_page_id_page_id_fk": {+ "name": "monitor_group_page_id_page_id_fk",+ "tableFrom": "monitor_group",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "viewer": {+ "name": "viewer",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "emailVerified": {+ "name": "emailVerified",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "image": {+ "name": "image",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "viewer_email_unique": {+ "name": "viewer_email_unique",+ "columns": [+ "email"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "viewer_accounts": {+ "name": "viewer_accounts",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "providerAccountId": {+ "name": "providerAccountId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "refresh_token": {+ "name": "refresh_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "access_token": {+ "name": "access_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "token_type": {+ "name": "token_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "id_token": {+ "name": "id_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "session_state": {+ "name": "session_state",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "viewer_accounts_user_id_viewer_id_fk": {+ "name": "viewer_accounts_user_id_viewer_id_fk",+ "tableFrom": "viewer_accounts",+ "tableTo": "viewer",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "viewer_accounts_provider_providerAccountId_pk": {+ "columns": [+ "provider",+ "providerAccountId"+ ],+ "name": "viewer_accounts_provider_providerAccountId_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "viewer_session": {+ "name": "viewer_session",+ "columns": {+ "session_token": {+ "name": "session_token",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "viewer_session_user_id_viewer_id_fk": {+ "name": "viewer_session_user_id_viewer_id_fk",+ "tableFrom": "viewer_session",+ "tableTo": "viewer",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "api_key": {+ "name": "api_key",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "prefix": {+ "name": "prefix",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "hashed_token": {+ "name": "hashed_token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_by_id": {+ "name": "created_by_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "scopes": {+ "name": "scopes",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'[\"write\"]'"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "last_used_at": {+ "name": "last_used_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "api_key_prefix_unique": {+ "name": "api_key_prefix_unique",+ "columns": [+ "prefix"+ ],+ "isUnique": true+ },+ "api_key_hashed_token_unique": {+ "name": "api_key_hashed_token_unique",+ "columns": [+ "hashed_token"+ ],+ "isUnique": true+ },+ "api_key_prefix_idx": {+ "name": "api_key_prefix_idx",+ "columns": [+ "prefix"+ ],+ "isUnique": false+ },+ "api_key_workspace_id_idx": {+ "name": "api_key_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "api_key_workspace_id_workspace_id_fk": {+ "name": "api_key_workspace_id_workspace_id_fk",+ "tableFrom": "api_key",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "api_key_created_by_id_user_id_fk": {+ "name": "api_key_created_by_id_user_id_fk",+ "tableFrom": "api_key",+ "tableTo": "user",+ "columnsFrom": [+ "created_by_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "maintenance_to_page_component": {+ "name": "maintenance_to_page_component",+ "columns": {+ "maintenance_id": {+ "name": "maintenance_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_component_id": {+ "name": "page_component_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "maintenance_to_page_component_page_component_id_idx": {+ "name": "maintenance_to_page_component_page_component_id_idx",+ "columns": [+ "page_component_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "maintenance_to_page_component_maintenance_id_maintenance_id_fk": {+ "name": "maintenance_to_page_component_maintenance_id_maintenance_id_fk",+ "tableFrom": "maintenance_to_page_component",+ "tableTo": "maintenance",+ "columnsFrom": [+ "maintenance_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "maintenance_to_page_component_page_component_id_page_component_id_fk": {+ "name": "maintenance_to_page_component_page_component_id_page_component_id_fk",+ "tableFrom": "maintenance_to_page_component",+ "tableTo": "page_component",+ "columnsFrom": [+ "page_component_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "maintenance_to_page_component_maintenance_id_page_component_id_pk": {+ "columns": [+ "maintenance_id",+ "page_component_id"+ ],+ "name": "maintenance_to_page_component_maintenance_id_page_component_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "page_component": {+ "name": "page_component",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'monitor'"+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "order": {+ "name": "order",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 0+ },+ "group_id": {+ "name": "group_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "group_order": {+ "name": "group_order",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "page_component_workspace_id_idx": {+ "name": "page_component_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ },+ "page_component_page_id_monitor_id_unique": {+ "name": "page_component_page_id_monitor_id_unique",+ "columns": [+ "page_id",+ "monitor_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "page_component_workspace_id_workspace_id_fk": {+ "name": "page_component_workspace_id_workspace_id_fk",+ "tableFrom": "page_component",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "page_component_page_id_page_id_fk": {+ "name": "page_component_page_id_page_id_fk",+ "tableFrom": "page_component",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "page_component_monitor_id_monitor_id_fk": {+ "name": "page_component_monitor_id_monitor_id_fk",+ "tableFrom": "page_component",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "page_component_group_id_page_component_groups_id_fk": {+ "name": "page_component_group_id_page_component_groups_id_fk",+ "tableFrom": "page_component",+ "tableTo": "page_component_groups",+ "columnsFrom": [+ "group_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {+ "page_component_type_check": {+ "name": "page_component_type_check",+ "value": "\"page_component\".\"type\" = 'monitor' AND \"page_component\".\"monitor_id\" IS NOT NULL OR \"page_component\".\"type\" = 'static' AND \"page_component\".\"monitor_id\" IS NULL"+ }+ }+ },+ "status_report_update_to_page_component": {+ "name": "status_report_update_to_page_component",+ "columns": {+ "status_report_update_id": {+ "name": "status_report_update_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_component_id": {+ "name": "page_component_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "impact": {+ "name": "impact",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "status_report_update_to_page_component_page_component_id_idx": {+ "name": "status_report_update_to_page_component_page_component_id_idx",+ "columns": [+ "page_component_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "status_report_update_to_page_component_status_report_update_id_status_report_update_id_fk": {+ "name": "status_report_update_to_page_component_status_report_update_id_status_report_update_id_fk",+ "tableFrom": "status_report_update_to_page_component",+ "tableTo": "status_report_update",+ "columnsFrom": [+ "status_report_update_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "status_report_update_to_page_component_page_component_id_page_component_id_fk": {+ "name": "status_report_update_to_page_component_page_component_id_page_component_id_fk",+ "tableFrom": "status_report_update_to_page_component",+ "tableTo": "page_component",+ "columnsFrom": [+ "page_component_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "status_report_update_to_page_component_status_report_update_id_page_component_id_pk": {+ "columns": [+ "status_report_update_id",+ "page_component_id"+ ],+ "name": "status_report_update_to_page_component_status_report_update_id_page_component_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "status_report_to_page_component": {+ "name": "status_report_to_page_component",+ "columns": {+ "status_report_id": {+ "name": "status_report_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_component_id": {+ "name": "page_component_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "status_report_to_page_component_page_component_id_idx": {+ "name": "status_report_to_page_component_page_component_id_idx",+ "columns": [+ "page_component_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "status_report_to_page_component_status_report_id_status_report_id_fk": {+ "name": "status_report_to_page_component_status_report_id_status_report_id_fk",+ "tableFrom": "status_report_to_page_component",+ "tableTo": "status_report",+ "columnsFrom": [+ "status_report_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "status_report_to_page_component_page_component_id_page_component_id_fk": {+ "name": "status_report_to_page_component_page_component_id_page_component_id_fk",+ "tableFrom": "status_report_to_page_component",+ "tableTo": "page_component",+ "columnsFrom": [+ "page_component_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "status_report_to_page_component_status_report_id_page_component_id_pk": {+ "columns": [+ "status_report_id",+ "page_component_id"+ ],+ "name": "status_report_to_page_component_status_report_id_page_component_id_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "page_component_groups": {+ "name": "page_component_groups",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "default_open": {+ "name": "default_open",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "page_component_groups_page_id_idx": {+ "name": "page_component_groups_page_id_idx",+ "columns": [+ "page_id"+ ],+ "isUnique": false+ },+ "page_component_groups_workspace_id_idx": {+ "name": "page_component_groups_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "page_component_groups_workspace_id_workspace_id_fk": {+ "name": "page_component_groups_workspace_id_workspace_id_fk",+ "tableFrom": "page_component_groups",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "page_component_groups_page_id_page_id_fk": {+ "name": "page_component_groups_page_id_page_id_fk",+ "tableFrom": "page_component_groups",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "feedback": {+ "name": "feedback",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "blocker": {+ "name": "blocker",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "path": {+ "name": "path",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "feedback_workspace_id_idx": {+ "name": "feedback_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "feedback_workspace_id_workspace_id_fk": {+ "name": "feedback_workspace_id_workspace_id_fk",+ "tableFrom": "feedback",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "feedback_user_id_user_id_fk": {+ "name": "feedback_user_id_user_id_fk",+ "tableFrom": "feedback",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "audit_log": {+ "name": "audit_log",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "actor_type": {+ "name": "actor_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "actor_id": {+ "name": "actor_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "actor_user_id": {+ "name": "actor_user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "action": {+ "name": "action",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "entity_type": {+ "name": "entity_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "entity_id": {+ "name": "entity_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "before": {+ "name": "before",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "after": {+ "name": "after",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "changed_fields": {+ "name": "changed_fields",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "audit_log_workspace_created_idx": {+ "name": "audit_log_workspace_created_idx",+ "columns": [+ "workspace_id",+ "created_at"+ ],+ "isUnique": false+ },+ "audit_log_entity_idx": {+ "name": "audit_log_entity_idx",+ "columns": [+ "workspace_id",+ "entity_type",+ "entity_id",+ "created_at"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "external_service": {+ "name": "external_service",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "slug": {+ "name": "slug",+ "type": "text(64)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "aliases": {+ "name": "aliases",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(json_array())"+ },+ "name": {+ "name": "name",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status_page_url": {+ "name": "status_page_url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "industry": {+ "name": "industry",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "api_config": {+ "name": "api_config",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "deleted_at": {+ "name": "deleted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "external_service_slug_unique": {+ "name": "external_service_slug_unique",+ "columns": [+ "slug"+ ],+ "isUnique": true+ },+ "external_service_deleted_at_idx": {+ "name": "external_service_deleted_at_idx",+ "columns": [+ "deleted_at"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "external_service_component": {+ "name": "external_service_component",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "external_service_id": {+ "name": "external_service_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "upstream_component_id": {+ "name": "upstream_component_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "slug": {+ "name": "slug",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "aliases": {+ "name": "aliases",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(json_array())"+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "group_name": {+ "name": "group_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "position": {+ "name": "position",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "indicator": {+ "name": "indicator",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "first_seen_at": {+ "name": "first_seen_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "external_service_component_unique_idx": {+ "name": "external_service_component_unique_idx",+ "columns": [+ "external_service_id",+ "upstream_component_id"+ ],+ "isUnique": true+ },+ "external_service_component_slug_unique_idx": {+ "name": "external_service_component_slug_unique_idx",+ "columns": [+ "external_service_id",+ "slug"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "external_service_component_external_service_id_external_service_id_fk": {+ "name": "external_service_component_external_service_id_external_service_id_fk",+ "tableFrom": "external_service_component",+ "tableTo": "external_service",+ "columnsFrom": [+ "external_service_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "external_service_incident": {+ "name": "external_service_incident",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "external_service_id": {+ "name": "external_service_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider_incident_id": {+ "name": "provider_incident_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "impact": {+ "name": "impact",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "shortlink": {+ "name": "shortlink",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "started_at": {+ "name": "started_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "resolved_at": {+ "name": "resolved_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "affected_component_ids": {+ "name": "affected_component_ids",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'[]'"+ },+ "raw_payload": {+ "name": "raw_payload",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "raw_payload_purged_at": {+ "name": "raw_payload_purged_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "first_seen_at": {+ "name": "first_seen_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "external_service_incident_unique_idx": {+ "name": "external_service_incident_unique_idx",+ "columns": [+ "external_service_id",+ "provider_incident_id"+ ],+ "isUnique": true+ },+ "external_service_incident_started_at_idx": {+ "name": "external_service_incident_started_at_idx",+ "columns": [+ "external_service_id",+ "started_at"+ ],+ "isUnique": false+ },+ "external_service_incident_resolved_at_idx": {+ "name": "external_service_incident_resolved_at_idx",+ "columns": [+ "resolved_at"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "external_service_incident_external_service_id_external_service_id_fk": {+ "name": "external_service_incident_external_service_id_external_service_id_fk",+ "tableFrom": "external_service_incident",+ "tableTo": "external_service",+ "columnsFrom": [+ "external_service_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "external_service_report": {+ "name": "external_service_report",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "external_service_id": {+ "name": "external_service_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "external_service_component_id": {+ "name": "external_service_component_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "reporter_hash": {+ "name": "reporter_hash",+ "type": "text(64)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "country": {+ "name": "country",+ "type": "text(2)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "external_service_report_service_idx": {+ "name": "external_service_report_service_idx",+ "columns": [+ "external_service_id",+ "created_at"+ ],+ "isUnique": false+ },+ "external_service_report_component_idx": {+ "name": "external_service_report_component_idx",+ "columns": [+ "external_service_component_id",+ "created_at"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "external_service_report_external_service_id_external_service_id_fk": {+ "name": "external_service_report_external_service_id_external_service_id_fk",+ "tableFrom": "external_service_report",+ "tableTo": "external_service",+ "columnsFrom": [+ "external_service_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "external_service_report_external_service_component_id_external_service_component_id_fk": {+ "name": "external_service_report_external_service_component_id_external_service_component_id_fk",+ "tableFrom": "external_service_report",+ "tableTo": "external_service_component",+ "columnsFrom": [+ "external_service_component_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "chat_session": {+ "name": "chat_session",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "messages": {+ "name": "messages",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "chat_session_workspace_user_updated_idx": {+ "name": "chat_session_workspace_user_updated_idx",+ "columns": [+ "workspace_id",+ "user_id",+ "updated_at"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "chat_session_workspace_id_workspace_id_fk": {+ "name": "chat_session_workspace_id_workspace_id_fk",+ "tableFrom": "chat_session",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "chat_session_user_id_user_id_fk": {+ "name": "chat_session_user_id_user_id_fk",+ "tableFrom": "chat_session",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "frozen_monitor_uptime": {+ "name": "frozen_monitor_uptime",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "month": {+ "name": "month",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "days": {+ "name": "days",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "frozen_monitor_uptime_workspace_id_idx": {+ "name": "frozen_monitor_uptime_workspace_id_idx",+ "columns": [+ "workspace_id"+ ],+ "isUnique": false+ },+ "frozen_monitor_uptime_monitor_id_month_unique": {+ "name": "frozen_monitor_uptime_monitor_id_month_unique",+ "columns": [+ "monitor_id",+ "month"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "frozen_monitor_uptime_workspace_id_workspace_id_fk": {+ "name": "frozen_monitor_uptime_workspace_id_workspace_id_fk",+ "tableFrom": "frozen_monitor_uptime",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "frozen_monitor_uptime_monitor_id_monitor_id_fk": {+ "name": "frozen_monitor_uptime_monitor_id_monitor_id_fk",+ "tableFrom": "frozen_monitor_uptime",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ }+ },+ "views": {},+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ },+ "internal": {+ "indexes": {+ "page_lower_slug_idx": {+ "columns": {+ "LOWER(\"slug\")": {+ "isExpression": true+ }+ }+ },+ "page_lower_custom_domain_idx": {+ "columns": {+ "LOWER(\"custom_domain\")": {+ "isExpression": true+ }+ }+ },+ "idx_page_subscriber_email_page_active": {+ "columns": {+ "LOWER(\"email\")": {+ "isExpression": true+ }+ }+ },+ "idx_page_subscriber_webhook_page_active": {+ "columns": {+ "LOWER(\"webhook_url\")": {+ "isExpression": true+ }+ }+ }+ }+ }+}diff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.jsonindex 13a807b7b..393d75df1 100644--- a/packages/db/drizzle/meta/_journal.json+++ b/packages/db/drizzle/meta/_journal.json@@ -544,9 +544,16 @@{"idx": 77,"version": "6",- "when": 1782994900937,+ "when": 1782504784306,"tag": "0077_military_jackpot","breakpoints": true+ },+ {+ "idx": 78,+ "version": "6",+ "when": 1782994900937,+ "tag": "0078_yellow_thor_girl",+ "breakpoints": true}]}\ No newline at end of filediff --git a/packages/db/src/schema/page_subscribers/page_subscribers.ts b/packages/db/src/schema/page_subscribers/page_subscribers.tsindex ae77ee022..7e2ceea9f 100644--- a/packages/db/src/schema/page_subscribers/page_subscribers.ts+++ b/packages/db/src/schema/page_subscribers/page_subscribers.ts@@ -22,7 +22,7 @@ export const pageSubscriber = sqliteTable(// Added: channel type discriminatorchannelType: text("channel_type", {- enum: ["email", "webhook"],+ enum: ["email", "webhook", "slack"],}).notNull().default("email"),@@ -31,6 +31,11 @@ export const pageSubscriber = sqliteTable(webhookUrl: text("webhook_url"),channelConfig: text("channel_config"),+ // Slack channel id (null for non-slack channels). teamId + channelName+ // live in channelConfig; the bot token is resolved from the integration+ // row at send time, never persisted here.+ slackChannelId: text("slack_channel_id"),+// How the subscription was created. Vendor-added rows skip verification// and are editable from the dashboard.source: text("source", {@@ -69,10 +74,19 @@ export const pageSubscriber = sqliteTable(sql`${table.unsubscribedAt} IS NULL AND ${table.channelType} = 'webhook'`,),+ // Partial unique index: one active slack subscription per (channel, page).+ slackChannelPageActiveIdx: uniqueIndex(+ "idx_page_subscriber_slack_channel_page_active",+ )+ .on(table.slackChannelId, table.pageId)+ .where(+ sql`${table.unsubscribedAt} IS NULL AND ${table.channelType} = 'slack'`,+ ),+// CHECK constraint: only correct identifier populated per channel typechannelCheck: check("page_subscriber_channel_check",- sql`(${table.channelType} = 'email' AND ${table.email} IS NOT NULL AND ${table.webhookUrl} IS NULL) OR (${table.channelType} = 'webhook' AND ${table.webhookUrl} IS NOT NULL AND ${table.email} IS NULL)`,+ sql`(${table.channelType} = 'email' AND ${table.email} IS NOT NULL AND ${table.webhookUrl} IS NULL) OR (${table.channelType} = 'webhook' AND ${table.webhookUrl} IS NOT NULL AND ${table.email} IS NULL) OR (${table.channelType} = 'slack' AND ${table.slackChannelId} IS NOT NULL AND ${table.email} IS NULL AND ${table.webhookUrl} IS NULL)`,),}),);diff --git a/packages/db/src/schema/page_subscribers/validation.ts b/packages/db/src/schema/page_subscribers/validation.tsindex 0603d3c58..4765fef37 100644--- a/packages/db/src/schema/page_subscribers/validation.ts+++ b/packages/db/src/schema/page_subscribers/validation.ts@@ -22,6 +22,15 @@ export const webhookChannelConfigSchema = z.object({secret: z.string().optional(),});+// Channel config schema for slack. The bot token is resolved from the+// integration row by teamId at send time, never stored here.+export const slackChannelConfigSchema = z.object({+ teamId: z.string().min(1),+ channelId: z.string().min(1),+ channelName: z.string().optional(),+});+export type SlackChannelConfig = z.infer<typeof slackChannelConfigSchema>;+export const subscriberSourceSchema = z.enum(["self_signup", "vendor", "import"]).default("self_signup");@@ -73,11 +82,40 @@ export const pageSubscriberSchema = z.discriminatedUnion("channelType", [createdAt: z.date().nullable(),updatedAt: z.date().nullable(),}),+ // Slack channel+ z.object({+ id: z.number(),+ pageId: z.number(),+ channelType: z.literal("slack"),+ email: z.null(),+ webhookUrl: z.null(),+ slackChannelId: z.string(),+ channelConfig: z+ .string()+ .nullable()+ .transform((str) => {+ if (!str) return null;+ try {+ return JSON.parse(str);+ } catch {+ return null;+ }+ })+ .pipe(slackChannelConfigSchema.nullable()),+ source: subscriberSourceSchema,+ name: z.string().nullable(),+ token: z.string().nullable(),+ acceptedAt: z.date().nullable(),+ expiresAt: z.date().nullable(),+ unsubscribedAt: z.date().nullable(),+ createdAt: z.date().nullable(),+ updatedAt: z.date().nullable(),+ }),]);export type InsertPageSubscriber = z.infer<typeof insertPageSubscriberSchema>;export type PageSubscriber = z.infer<typeof selectPageSubscriberSchema>;-export type ChannelType = "email" | "webhook";+export type ChannelType = "email" | "webhook" | "slack";export type SubscriberSource = z.infer<typeof subscriberSourceSchema>;export type EmailSubscriber = Extract<z.infer<typeof pageSubscriberSchema>,@@ -87,3 +125,7 @@ export type WebhookSubscriber = Extract<z.infer<typeof pageSubscriberSchema>,{ channelType: "webhook" }>;+export type SlackSubscriber = Extract<+ z.infer<typeof pageSubscriberSchema>,+ { channelType: "slack" }+>;diff --git a/packages/services/src/invitation/create.ts b/packages/services/src/invitation/create.tsindex 29eb7c470..98d09f56c 100644--- a/packages/services/src/invitation/create.ts+++ b/packages/services/src/invitation/create.ts@@ -82,7 +82,7 @@ export async function createInvitation(args: {// Dev-mode convenience: echo the invite URL so the developer can// click it straight from the terminal without checking the DB.- // Strict equality on `"development"` so bun:test (which sets+ // Strict equality on `"development"` so the test runner (which sets// `NODE_ENV=test`) and CI (typically `undefined` or `"test"`) don't// leak tokens into logs.if (process.env.NODE_ENV === "development") {diff --git a/packages/services/src/page-subscriber/__tests__/page-subscriber.test.ts b/packages/services/src/page-subscriber/__tests__/page-subscriber.test.tsindex 3fa02a4cd..58f2a1fe3 100644--- a/packages/services/src/page-subscriber/__tests__/page-subscriber.test.ts+++ b/packages/services/src/page-subscriber/__tests__/page-subscriber.test.ts@@ -290,26 +290,28 @@ describe("upsertSelfSignupSubscriber", () => {});test("rejects when the workspace plan disables status-subscribers", async () => {- const freePage = await db- .insert(page)- .values({- workspaceId: SEEDED_WORKSPACE_FREE_ID,- title: "plan-gate",- description: "plan-gate",- slug: `plan-gate-${Date.now()}`,- customDomain: "",- })- .returning()- .get();- try {+ // Rolled-back tx so the free-workspace page never commits — a+ // committed page would trip `page.test.ts`'s free-plan+ // `status-pages` quota assertions under `deno test --parallel`.+ await withTestTransaction(async (tx) => {+ const freePage = await tx+ .insert(page)+ .values({+ workspaceId: SEEDED_WORKSPACE_FREE_ID,+ title: "plan-gate",+ description: "plan-gate",+ slug: `plan-gate-${Date.now()}`,+ customDomain: "",+ })+ .returning()+ .get();await expect(upsertSelfSignupSubscriber({input: { email: EMAILS.planGate, pageId: freePage.id },+ db: tx,}),).rejects.toThrow("Upgrade to use status subscribers");- } finally {- await db.delete(page).where(eq(page.id, freePage.id));- }+ });});});diff --git a/packages/services/src/page-subscriber/__tests__/slack.test.ts b/packages/services/src/page-subscriber/__tests__/slack.test.tsnew file mode 100644index 000000000..84e61bc18--- /dev/null+++ b/packages/services/src/page-subscriber/__tests__/slack.test.ts@@ -0,0 +1,170 @@+import { db, eq, inArray } from "@openstatus/db";+import { pageSubscriber } from "@openstatus/db/src/schema";+import { expect } from "@std/expect";+import { afterAll, beforeAll, describe, test } from "@std/testing/bdd";++import { SEEDED_WORKSPACE_TEAM_ID } from "../../../test/fixtures";+import { expectAuditRow } from "../../../test/helpers";+import {+ createSlackSubscriber,+ listSlackSubscribersForChannel,+ removeSlackSubscriber,+} from "../index";++// page 1 = slug "status", workspace 1 (team plan, status-subscribers=true).+const PAGE_ID = 1;+const TEAM_ID = "T_SLACK_TEST";+const CHANNELS = {+ create: "C_SLACK_CREATE",+ dedup: "C_SLACK_DEDUP",+ reactivate: "C_SLACK_REACTIVATE",+ remove: "C_SLACK_REMOVE",+ list: "C_SLACK_LIST",+};++// Scope cleanup to this suite's own slack channels. A workspace-wide+// clearAuditLog would race sibling suites that share workspace 1 under+// `deno test --parallel`; our assertions filter by unique entityId, so+// stale audit rows can't match anyway.+async function cleanAll() {+ await db+ .delete(pageSubscriber)+ .where(inArray(pageSubscriber.slackChannelId, Object.values(CHANNELS)));+}++beforeAll(cleanAll);+afterAll(cleanAll);++describe("createSlackSubscriber", () => {+ test("creates an auto-accepted self-signup slack row + audit", async () => {+ const result = await createSlackSubscriber({+ input: {+ pageId: PAGE_ID,+ teamId: TEAM_ID,+ channelId: CHANNELS.create,+ channelName: "incidents",+ },+ });++ expect(result.alreadySubscribed).toBe(false);+ expect(result.pageName).toBeDefined();++ const row = await db.query.pageSubscriber.findFirst({+ where: eq(pageSubscriber.id, result.id),+ });+ expect(row?.channelType).toBe("slack");+ expect(row?.slackChannelId).toBe(CHANNELS.create);+ expect(row?.source).toBe("self_signup");+ expect(row?.acceptedAt).not.toBeNull();+ expect(row?.name).toBe("#incidents");++ await expectAuditRow({+ workspaceId: SEEDED_WORKSPACE_TEAM_ID,+ action: "page_subscriber.create",+ entityType: "page_subscriber",+ entityId: result.id,+ actorType: "subscriber",+ });+ });++ test("second call is idempotent (alreadySubscribed, no duplicate)", async () => {+ const first = await createSlackSubscriber({+ input: { pageId: PAGE_ID, teamId: TEAM_ID, channelId: CHANNELS.dedup },+ });+ const second = await createSlackSubscriber({+ input: { pageId: PAGE_ID, teamId: TEAM_ID, channelId: CHANNELS.dedup },+ });++ expect(first.alreadySubscribed).toBe(false);+ expect(second.alreadySubscribed).toBe(true);++ const rows = await db.query.pageSubscriber.findMany({+ where: eq(pageSubscriber.slackChannelId, CHANNELS.dedup),+ });+ expect(rows).toHaveLength(1);+ });++ test("re-activates a previously removed channel", async () => {+ await createSlackSubscriber({+ input: {+ pageId: PAGE_ID,+ teamId: TEAM_ID,+ channelId: CHANNELS.reactivate,+ },+ });+ await removeSlackSubscriber({+ input: {+ pageId: PAGE_ID,+ teamId: TEAM_ID,+ channelId: CHANNELS.reactivate,+ },+ });+ const reactivated = await createSlackSubscriber({+ input: {+ pageId: PAGE_ID,+ teamId: TEAM_ID,+ channelId: CHANNELS.reactivate,+ },+ });++ expect(reactivated.alreadySubscribed).toBe(false);+ const rows = await db.query.pageSubscriber.findMany({+ where: eq(pageSubscriber.slackChannelId, CHANNELS.reactivate),+ });+ expect(rows).toHaveLength(1);+ expect(rows[0]?.unsubscribedAt).toBeNull();+ });+});++describe("removeSlackSubscriber", () => {+ test("soft-deletes the active row and audits the update", async () => {+ const created = await createSlackSubscriber({+ input: { pageId: PAGE_ID, teamId: TEAM_ID, channelId: CHANNELS.remove },+ });+ const result = await removeSlackSubscriber({+ input: { pageId: PAGE_ID, teamId: TEAM_ID, channelId: CHANNELS.remove },+ });++ expect(result.removed).toBe(true);+ const row = await db.query.pageSubscriber.findFirst({+ where: eq(pageSubscriber.id, created.id),+ });+ expect(row?.unsubscribedAt).not.toBeNull();++ await expectAuditRow({+ workspaceId: SEEDED_WORKSPACE_TEAM_ID,+ action: "page_subscriber.update",+ entityType: "page_subscriber",+ entityId: created.id,+ actorType: "subscriber",+ });+ });++ test("returns removed=false when nothing is subscribed", async () => {+ const result = await removeSlackSubscriber({+ input: { pageId: PAGE_ID, teamId: TEAM_ID, channelId: "C_SLACK_NEVER" },+ });+ expect(result.removed).toBe(false);+ });+});++describe("listSlackSubscribersForChannel", () => {+ test("lists active subscriptions for the channel", async () => {+ await createSlackSubscriber({+ input: { pageId: PAGE_ID, teamId: TEAM_ID, channelId: CHANNELS.list },+ });+ const subs = await listSlackSubscribersForChannel({+ input: { teamId: TEAM_ID, channelId: CHANNELS.list },+ });+ expect(subs).toHaveLength(1);+ expect(subs[0]?.pageId).toBe(PAGE_ID);++ await removeSlackSubscriber({+ input: { pageId: PAGE_ID, teamId: TEAM_ID, channelId: CHANNELS.list },+ });+ const after = await listSlackSubscribersForChannel({+ input: { teamId: TEAM_ID, channelId: CHANNELS.list },+ });+ expect(after).toHaveLength(0);+ });+});diff --git a/packages/services/src/page-subscriber/get-by-token.ts b/packages/services/src/page-subscriber/get-by-token.tsindex 62088614b..d746125db 100644--- a/packages/services/src/page-subscriber/get-by-token.ts+++ b/packages/services/src/page-subscriber/get-by-token.ts@@ -23,7 +23,7 @@ export type SubscriberByTokenResult = {pageName: string;pageSlug: string;customDomain: string | null;- channelType: "email" | "webhook";+ channelType: "email" | "webhook" | "slack";email?: string;webhookUrl?: string;acceptedAt: Date | null;diff --git a/packages/services/src/page-subscriber/index.ts b/packages/services/src/page-subscriber/index.tsindex 18deac3d3..793b3503c 100644--- a/packages/services/src/page-subscriber/index.ts+++ b/packages/services/src/page-subscriber/index.ts@@ -10,6 +10,13 @@ export {export { hasPendingSubscriber } from "./has-pending";export { listPageSubscribers, type PageSubscriberListItem } from "./list";export { sendPageSubscriberTestWebhook } from "./send-test-webhook";+export {+ createSlackSubscriber,+ listSlackSubscribersForChannel,+ removeSlackSubscriber,+ type SlackSubscriberResult,+ type SlackSubscriptionSummary,+} from "./slack";export { unsubscribeSubscriber } from "./unsubscribe";export { updatePageSubscriberChannel } from "./update";export { updateSubscriberScope } from "./update-scope";@@ -20,10 +27,13 @@ export {export { type VerifyResult, verifySelfSignupSubscriber } from "./verify";export {CreatePageSubscriberInput,+ CreateSlackSubscriberInput,DeletePageSubscriberInput,GetSubscriberByTokenInput,HasPendingSubscriberInput,ListPageSubscribersInput,+ ListSlackSubscribersInput,+ RemoveSlackSubscriberInput,SendPageSubscriberTestWebhookInput,UnsubscribeSubscriberInput,UpdatePageSubscriberChannelInput,diff --git a/packages/services/src/page-subscriber/list.ts b/packages/services/src/page-subscriber/list.tsindex 2e4343128..b8c3cec54 100644--- a/packages/services/src/page-subscriber/list.ts+++ b/packages/services/src/page-subscriber/list.ts@@ -34,7 +34,7 @@ function webhookUrlForList(export type PageSubscriberListItem = {id: number;- channelType: "email" | "webhook";+ channelType: "email" | "webhook" | "slack";email: string | null;webhookUrl: string | null;channelConfig: string | null;diff --git a/packages/services/src/page-subscriber/schemas.ts b/packages/services/src/page-subscriber/schemas.tsindex da196c5ea..5db26ade8 100644--- a/packages/services/src/page-subscriber/schemas.ts+++ b/packages/services/src/page-subscriber/schemas.ts@@ -38,6 +38,33 @@ export type CreatePageSubscriberInput = z.infer<typeof CreatePageSubscriberInput>;+export const CreateSlackSubscriberInput = z.object({+ pageId: z.number().int().positive(),+ teamId: z.string().min(1),+ channelId: z.string().min(1),+ channelName: z.string().max(255).optional(),+});+export type CreateSlackSubscriberInput = z.infer<+ typeof CreateSlackSubscriberInput+>;++export const RemoveSlackSubscriberInput = z.object({+ pageId: z.number().int().positive(),+ teamId: z.string().min(1),+ channelId: z.string().min(1),+});+export type RemoveSlackSubscriberInput = z.infer<+ typeof RemoveSlackSubscriberInput+>;++export const ListSlackSubscribersInput = z.object({+ teamId: z.string().min(1),+ channelId: z.string().min(1),+});+export type ListSlackSubscribersInput = z.infer<+ typeof ListSlackSubscribersInput+>;+export const UpdatePageSubscriberChannelInput = z.object({subscriberId: z.number().int().positive(),pageId: z.number().int().positive(),diff --git a/packages/services/src/page-subscriber/slack.ts b/packages/services/src/page-subscriber/slack.tsnew file mode 100644index 000000000..dafb488bd--- /dev/null+++ b/packages/services/src/page-subscriber/slack.ts@@ -0,0 +1,255 @@+import { and, eq, isNull, sql } from "@openstatus/db";+import {+ page,+ pageSubscriber,+ selectPageSubscriberSchema,+} from "@openstatus/db/src/schema";++import { emitAudit } from "../audit";+import {+ type DB,+ type ServiceContext,+ getReadDb,+ withTransaction,+} from "../context";+import { NotFoundError } from "../errors";+import { assertSubscribersAllowed, parseWorkspaceForContext } from "./internal";+import {+ type CreateSlackSubscriberInput,+ type ListSlackSubscribersInput,+ type RemoveSlackSubscriberInput,+ CreateSlackSubscriberInput as CreateSlackSubscriberSchema,+ ListSlackSubscribersInput as ListSlackSubscribersSchema,+ RemoveSlackSubscriberInput as RemoveSlackSubscriberSchema,+} from "./schemas";++export interface SlackSubscriberResult {+ id: number;+ pageId: number;+ pageName: string;+ pageSlug: string;+ customDomain: string | null;+ alreadySubscribed: boolean;+}++function channelLabel(channelId: string, channelName?: string): string {+ return channelName ? `#${channelName}` : channelId;+}++/**+ * Self-signup for a Slack channel via `/openstatus add <url>`. There is no+ * authenticated workspace at the call site — both workspace and audit actor+ * are resolved from the page. Auto-accepted (the slash command is consent).+ */+export async function createSlackSubscriber(args: {+ input: CreateSlackSubscriberInput;+ db?: DB;+}): Promise<SlackSubscriberResult> {+ const input = CreateSlackSubscriberSchema.parse(args.input);++ const readDb = getReadDb({ db: args.db } as ServiceContext);+ const pageData = await readDb.query.page.findFirst({+ where: eq(page.id, input.pageId),+ with: { workspace: true },+ });+ if (!pageData) {+ throw new NotFoundError("page", input.pageId);+ }+ const workspace = parseWorkspaceForContext(pageData.workspace);+ assertSubscribersAllowed(workspace);++ const channelConfig = JSON.stringify({+ teamId: input.teamId,+ channelId: input.channelId,+ channelName: input.channelName,+ });+ const name = channelLabel(input.channelId, input.channelName);++ return withTransaction({ db: args.db } as ServiceContext, async (tx) => {+ const existing = await tx.query.pageSubscriber.findFirst({+ where: and(+ eq(pageSubscriber.pageId, input.pageId),+ eq(pageSubscriber.slackChannelId, input.channelId),+ eq(pageSubscriber.channelType, "slack"),+ ),+ });++ if (existing && !existing.unsubscribedAt) {+ return {+ id: existing.id,+ pageId: pageData.id,+ pageName: pageData.title,+ pageSlug: pageData.slug,+ customDomain: pageData.customDomain,+ alreadySubscribed: true,+ };+ }++ if (existing) {+ const before = selectPageSubscriberSchema.parse(existing);+ const updated = await tx+ .update(pageSubscriber)+ .set({+ unsubscribedAt: null,+ acceptedAt: new Date(),+ channelConfig,+ name,+ updatedAt: new Date(),+ })+ .where(eq(pageSubscriber.id, existing.id))+ .returning()+ .get();+ const after = selectPageSubscriberSchema.parse(updated ?? existing);++ const auditCtx: ServiceContext = {+ workspace,+ actor: { type: "subscriber", subscriberId: existing.id },+ db: tx,+ };+ const { token: _bt, ...beforeSnap } = before;+ const { token: _at, ...afterSnap } = after;+ await emitAudit(tx, auditCtx, {+ action: "page_subscriber.update",+ entityType: "page_subscriber",+ entityId: existing.id,+ before: beforeSnap,+ after: afterSnap,+ });++ return {+ id: existing.id,+ pageId: pageData.id,+ pageName: pageData.title,+ pageSlug: pageData.slug,+ customDomain: pageData.customDomain,+ alreadySubscribed: false,+ };+ }++ const inserted = await tx+ .insert(pageSubscriber)+ .values({+ channelType: "slack",+ slackChannelId: input.channelId,+ channelConfig,+ pageId: input.pageId,+ source: "self_signup",+ name,+ acceptedAt: new Date(),+ })+ .returning()+ .get();++ const auditCtx: ServiceContext = {+ workspace,+ actor: { type: "subscriber", subscriberId: inserted.id },+ db: tx,+ };+ const { token: _t, ...after } = selectPageSubscriberSchema.parse(inserted);+ await emitAudit(tx, auditCtx, {+ action: "page_subscriber.create",+ entityType: "page_subscriber",+ entityId: inserted.id,+ after,+ });++ return {+ id: inserted.id,+ pageId: pageData.id,+ pageName: pageData.title,+ pageSlug: pageData.slug,+ customDomain: pageData.customDomain,+ alreadySubscribed: false,+ };+ });+}++export async function removeSlackSubscriber(args: {+ input: RemoveSlackSubscriberInput;+ db?: DB;+}): Promise<{ removed: boolean }> {+ const input = RemoveSlackSubscriberSchema.parse(args.input);++ const readDb = getReadDb({ db: args.db } as ServiceContext);+ const pageData = await readDb.query.page.findFirst({+ where: eq(page.id, input.pageId),+ with: { workspace: true },+ });+ if (!pageData) {+ throw new NotFoundError("page", input.pageId);+ }+ const workspace = parseWorkspaceForContext(pageData.workspace);++ return withTransaction({ db: args.db } as ServiceContext, async (tx) => {+ const existing = await tx.query.pageSubscriber.findFirst({+ where: and(+ eq(pageSubscriber.pageId, input.pageId),+ eq(pageSubscriber.slackChannelId, input.channelId),+ eq(pageSubscriber.channelType, "slack"),+ sql`json_extract(${pageSubscriber.channelConfig}, '$.teamId') = ${input.teamId}`,+ isNull(pageSubscriber.unsubscribedAt),+ ),+ });+ if (!existing) return { removed: false };++ const before = selectPageSubscriberSchema.parse(existing);+ const updated = await tx+ .update(pageSubscriber)+ .set({ unsubscribedAt: new Date(), updatedAt: new Date() })+ .where(eq(pageSubscriber.id, existing.id))+ .returning()+ .get();+ const after = selectPageSubscriberSchema.parse(updated ?? existing);++ const auditCtx: ServiceContext = {+ workspace,+ actor: { type: "subscriber", subscriberId: existing.id },+ db: tx,+ };+ const { token: _bt, ...beforeSnap } = before;+ const { token: _at, ...afterSnap } = after;+ await emitAudit(tx, auditCtx, {+ action: "page_subscriber.update",+ entityType: "page_subscriber",+ entityId: existing.id,+ before: beforeSnap,+ after: afterSnap,+ });++ return { removed: true };+ });+}++export interface SlackSubscriptionSummary {+ id: number;+ pageId: number;+ pageName: string;+ pageSlug: string;+ customDomain: string | null;+}++export async function listSlackSubscribersForChannel(args: {+ input: ListSlackSubscribersInput;+ db?: DB;+}): Promise<SlackSubscriptionSummary[]> {+ const input = ListSlackSubscribersSchema.parse(args.input);+ const readDb = getReadDb({ db: args.db } as ServiceContext);++ const rows = await readDb.query.pageSubscriber.findMany({+ where: and(+ eq(pageSubscriber.slackChannelId, input.channelId),+ eq(pageSubscriber.channelType, "slack"),+ sql`json_extract(${pageSubscriber.channelConfig}, '$.teamId') = ${input.teamId}`,+ isNull(pageSubscriber.unsubscribedAt),+ ),+ with: { page: true },+ });++ return rows.map((row) => ({+ id: row.id,+ pageId: row.pageId,+ pageName: row.page.title,+ pageSlug: row.page.slug,+ customDomain: row.page.customDomain,+ }));+}diff --git a/packages/services/src/page-subscriber/upsert.ts b/packages/services/src/page-subscriber/upsert.tsindex 1d291d9c9..fab85bf9a 100644--- a/packages/services/src/page-subscriber/upsert.ts+++ b/packages/services/src/page-subscriber/upsert.ts@@ -26,7 +26,7 @@ export type UpsertSelfSignupResult = {pageName: string;pageSlug: string;customDomain: string | null;- channelType: "email" | "webhook";+ channelType: "email" | "webhook" | "slack";email: string;token: string | null;acceptedAt: Date | null;diff --git a/packages/services/src/page-subscriber/verify.ts b/packages/services/src/page-subscriber/verify.tsindex 7fa885b7f..f4f96bb80 100644--- a/packages/services/src/page-subscriber/verify.ts+++ b/packages/services/src/page-subscriber/verify.ts@@ -16,7 +16,7 @@ export type VerifyResult = {pageName: string;pageSlug: string;customDomain: string | null;- channelType: "email" | "webhook";+ channelType: "email" | "webhook" | "slack";email: string | null;webhookUrl?: string | null;token: string | null;diff --git a/packages/services/src/workspace/__tests__/workspace.test.ts b/packages/services/src/workspace/__tests__/workspace.test.tsindex 46cc4e385..576efa1b7 100644--- a/packages/services/src/workspace/__tests__/workspace.test.ts+++ b/packages/services/src/workspace/__tests__/workspace.test.ts@@ -46,7 +46,7 @@ describe("getWorkspaceWithUsage", () => {expect(result.id).toBe(SEEDED_WORKSPACE_TEAM_ID);// Iterate the usage object *before* any `toMatchObject` call —- // bun:test's `toMatchObject` implementation mutates the received+ // the `toMatchObject` implementation mutates the received// object in place, replacing number fields with the// `expect.any(Number)` asymmetric-matcher stub on the expected// side. Subsequent reads of `result.usage.<key>` then return thediff --git a/packages/subscriptions/package.json b/packages/subscriptions/package.jsonindex ada827459..1a3537a49 100644--- a/packages/subscriptions/package.json+++ b/packages/subscriptions/package.json@@ -23,6 +23,8 @@"@openstatus/emails": "workspace:*","@openstatus/notification-base": "workspace:*","@openstatus/utils": "workspace:*",+ "@slack/web-api": "catalog:",+ "@upstash/redis": "catalog:","effect": "catalog:","zod": "catalog:"},diff --git a/packages/subscriptions/src/channels/index.test.ts b/packages/subscriptions/src/channels/index.test.tsindex d635918b5..7d2263e07 100644--- a/packages/subscriptions/src/channels/index.test.ts+++ b/packages/subscriptions/src/channels/index.test.ts@@ -23,9 +23,16 @@ describe("getChannel", () => {expect(typeof channel?.validateConfig).toBe("function");});+ test('returns slack channel for "slack"', () => {+ const channel = getChannel("slack");+ expect(channel).not.toBeNull();+ expect(channel?.id).toBe("slack");+ expect(typeof channel?.sendNotifications).toBe("function");+ expect(typeof channel?.validateConfig).toBe("function");+ });+test("returns null for unknown channel types", () => {expect(getChannel("sms")).toBeNull();- expect(getChannel("slack")).toBeNull();expect(getChannel("")).toBeNull();});});diff --git a/packages/subscriptions/src/channels/index.ts b/packages/subscriptions/src/channels/index.tsindex 5bdccda68..5fac4cc16 100644--- a/packages/subscriptions/src/channels/index.ts+++ b/packages/subscriptions/src/channels/index.ts@@ -4,6 +4,7 @@ import {sendEmailVerification,validateEmailConfig,} from "./email";+import { sendSlackNotifications, validateSlackConfig } from "./slack";import {sendWebhookNotifications,sendWebhookVerification,@@ -28,6 +29,13 @@ export function getChannel(channelType: string): SubscriptionChannel | null {validateConfig: validateWebhookConfig,};}+ case "slack": {+ return {+ id: "slack",+ sendNotifications: sendSlackNotifications,+ validateConfig: validateSlackConfig,+ };+ }default:return null;}diff --git a/packages/subscriptions/src/channels/slack-blocks.test.ts b/packages/subscriptions/src/channels/slack-blocks.test.tsnew file mode 100644index 000000000..63f5443ac--- /dev/null+++ b/packages/subscriptions/src/channels/slack-blocks.test.ts@@ -0,0 +1,78 @@+import { expect } from "@std/expect";+import { describe, it as test } from "@std/testing/bdd";++import type { PageUpdate, Subscription } from "../types";+import { buildReplyMessage, buildRootMessage } from "./slack-blocks";++function makeSub(over: Partial<Subscription> = {}): Subscription {+ return {+ id: 1,+ pageId: 1,+ pageName: "Acme Status",+ pageSlug: "acme",+ customDomain: null,+ componentIds: [],+ channelType: "slack",+ slackChannelId: "C1",+ ...over,+ };+}++function makeUpdate(over: Partial<PageUpdate> = {}): PageUpdate {+ return {+ id: 10,+ pageId: 1,+ title: "API degraded",+ status: "investigating",+ message: "We are investigating elevated errors.",+ pageComponentIds: [],+ pageComponents: [],+ date: "2026-01-01T10:00:00.000Z",+ updateId: 100,+ ...over,+ };+}++describe("buildRootMessage", () => {+ test("investigating header carries the magnifier emoji + label", () => {+ const root = buildRootMessage(makeUpdate(), makeSub());+ expect(root.text).toContain("🔍");+ expect(root.text).toContain("Investigating");+ expect(root.text).toContain("API degraded");+ expect(root.attachments[0]?.color).toBeDefined();+ });++ test("resolved switches to the check mark and green bar", () => {+ const resolvedRoot = buildRootMessage(+ makeUpdate({ status: "resolved" }),+ makeSub(),+ );+ const investigatingRoot = buildRootMessage(makeUpdate(), makeSub());+ expect(resolvedRoot.text).toContain("✅");+ expect(resolvedRoot.text).toContain("Resolved");+ expect(resolvedRoot.attachments[0]?.color).not.toBe(+ investigatingRoot.attachments[0]?.color,+ );+ });++ test("uses the custom domain origin when present", () => {+ const root = buildRootMessage(+ makeUpdate(),+ makeSub({ customDomain: "status.acme.com" }),+ );+ expect(JSON.stringify(root.attachments)).toContain(+ "https://status.acme.com",+ );+ });+});++describe("buildReplyMessage", () => {+ test("reply carries status label and message", () => {+ const reply = buildReplyMessage(+ makeUpdate({ status: "monitoring", message: "Fix deployed." }),+ );+ expect(reply.text).toContain("Monitoring");+ expect(reply.text).toContain("Fix deployed.");+ expect(reply.blocks.length).toBeGreaterThan(0);+ });+});diff --git a/packages/subscriptions/src/channels/slack-blocks.ts b/packages/subscriptions/src/channels/slack-blocks.tsnew file mode 100644index 000000000..32004f2b5--- /dev/null+++ b/packages/subscriptions/src/channels/slack-blocks.ts@@ -0,0 +1,140 @@+import { COLORS } from "@openstatus/notification-base";+import type { KnownBlock, MessageAttachment } from "@slack/web-api";++import type { PageUpdate, Subscription } from "../types";++type StatusColor = "red" | "yellow" | "green" | "blue";++const STATUS_EMOJI: Record<PageUpdate["status"], string> = {+ investigating: "🔍",+ identified: "🔴",+ monitoring: "👀",+ resolved: "✅",+ maintenance: "🔧",+};++const STATUS_LABEL: Record<PageUpdate["status"], string> = {+ investigating: "Investigating",+ identified: "Identified",+ monitoring: "Monitoring",+ resolved: "Resolved",+ maintenance: "Maintenance",+};++function statusColor(status: PageUpdate["status"]): StatusColor {+ switch (status) {+ case "investigating":+ case "identified":+ return "red";+ case "monitoring":+ return "yellow";+ case "resolved":+ return "green";+ case "maintenance":+ return "blue";+ }+}++function pageOrigin(subscription: Subscription): string {+ return subscription.customDomain+ ? `https://${subscription.customDomain}`+ : `https://${subscription.pageSlug}.openstatus.dev`;+}++function eventUrl(pageUpdate: PageUpdate, subscription: Subscription): string {+ const kind = pageUpdate.status === "maintenance" ? "maintenance" : "report";+ return `${pageOrigin(subscription)}/events/${kind}/${pageUpdate.id}`;+}++export interface SlackRootMessage {+ text: string;+ attachments: MessageAttachment[];+}++export interface SlackReplyMessage {+ text: string;+ blocks: KnownBlock[];+}++export function buildRootMessage(+ pageUpdate: PageUpdate,+ subscription: Subscription,+): SlackRootMessage {+ const emoji = STATUS_EMOJI[pageUpdate.status];+ const label = STATUS_LABEL[pageUpdate.status];+ const origin = pageOrigin(subscription);++ const blocks: KnownBlock[] = [+ {+ type: "header",+ text: {+ type: "plain_text",+ text: `${emoji} ${pageUpdate.title} — ${label}`,+ emoji: true,+ },+ },+ {+ type: "section",+ fields: [+ { type: "mrkdwn", text: `*Status*\n${label}` },+ {+ type: "mrkdwn",+ text: `*Page*\n<${origin}|${subscription.pageName}>`,+ },+ ],+ },+ ];++ if (pageUpdate.message) {+ blocks.push({+ type: "section",+ text: { type: "mrkdwn", text: pageUpdate.message },+ });+ }++ if (pageUpdate.pageComponents.length > 0) {+ blocks.push({+ type: "section",+ text: {+ type: "mrkdwn",+ text: `*Affected*\n${pageUpdate.pageComponents.join(", ")}`,+ },+ });+ }++ blocks.push({+ type: "context",+ elements: [+ {+ type: "mrkdwn",+ text: `Updated ${pageUpdate.date} · <${eventUrl(pageUpdate, subscription)}|View details> · Manage with \`/openstatus remove\``,+ },+ ],+ });++ return {+ text: `${emoji} ${pageUpdate.title} — ${label}`,+ attachments: [{ color: COLORS[statusColor(pageUpdate.status)], blocks }],+ };+}++export function buildReplyMessage(pageUpdate: PageUpdate): SlackReplyMessage {+ const emoji = STATUS_EMOJI[pageUpdate.status];+ const label = STATUS_LABEL[pageUpdate.status];+ const heading = `${emoji} *${label}* · ${pageUpdate.date}`;++ return {+ text: pageUpdate.message ? `${label}: ${pageUpdate.message}` : label,+ blocks: [+ {+ type: "section",+ text: {+ type: "mrkdwn",+ text: pageUpdate.message+ ? `${heading}\n${pageUpdate.message}`+ : heading,+ },+ },+ ],+ };+}diff --git a/packages/subscriptions/src/channels/slack-store.ts b/packages/subscriptions/src/channels/slack-store.tsnew file mode 100644index 000000000..77d0e38c4--- /dev/null+++ b/packages/subscriptions/src/channels/slack-store.ts@@ -0,0 +1,112 @@+import { Redis } from "@upstash/redis";++export interface SlackThreadAnchor {+ ts: string;+ channelId: string;+}++export interface SlackAnchorStore {+ getAnchor(+ reportId: number,+ subscriberId: number,+ ): Promise<SlackThreadAnchor | null>;+ setAnchor(+ reportId: number,+ subscriberId: number,+ anchor: SlackThreadAnchor,+ ): Promise<void>;+ clearAnchor(reportId: number, subscriberId: number): Promise<void>;+ // Atomically claim delivery of (report, subscriber, update). Returns true only+ // for the caller that wins the claim; concurrent callers get false and must+ // skip. This is the dedupe reservation — a single atomic op, not a+ // read-then-write pair, so two dispatchers can't both post the same message.+ reserveDelivery(+ reportId: number,+ subscriberId: number,+ updateId: number,+ ): Promise<boolean>;+ // Release a reservation whose post failed, so the delivery can be retried.+ releaseDelivery(+ reportId: number,+ subscriberId: number,+ updateId: number,+ ): Promise<void>;+}++const TTL_SECONDS = 90 * 24 * 60 * 60;++function anchorKey(reportId: number, subscriberId: number): string {+ return `slack:report:${reportId}:sub:${subscriberId}`;+}++function deliveredKey(+ reportId: number,+ subscriberId: number,+ updateId: number,+): string {+ return `${anchorKey(reportId, subscriberId)}:update:${updateId}`;+}++let redisClient: Redis | null = null;++function getRedis(): Redis {+ if (!redisClient) {+ redisClient = Redis.fromEnv();+ }+ return redisClient;+}++export function createRedisAnchorStore(): SlackAnchorStore {+ return {+ async getAnchor(reportId, subscriberId) {+ const raw = await getRedis().get<SlackThreadAnchor>(+ anchorKey(reportId, subscriberId),+ );+ return raw ?? null;+ },+ async setAnchor(reportId, subscriberId, anchor) {+ await getRedis().set(anchorKey(reportId, subscriberId), anchor, {+ ex: TTL_SECONDS,+ });+ },+ async clearAnchor(reportId, subscriberId) {+ await getRedis().del(anchorKey(reportId, subscriberId));+ },+ async reserveDelivery(reportId, subscriberId, updateId) {+ const res = await getRedis().set(+ deliveredKey(reportId, subscriberId, updateId),+ 1,+ { ex: TTL_SECONDS, nx: true },+ );+ return res === "OK";+ },+ async releaseDelivery(reportId, subscriberId, updateId) {+ await getRedis().del(deliveredKey(reportId, subscriberId, updateId));+ },+ };+}++export function createMemoryAnchorStore(): SlackAnchorStore {+ const anchors = new Map<string, SlackThreadAnchor>();+ const delivered = new Set<string>();+ return {+ async getAnchor(reportId, subscriberId) {+ return anchors.get(anchorKey(reportId, subscriberId)) ?? null;+ },+ async setAnchor(reportId, subscriberId, anchor) {+ anchors.set(anchorKey(reportId, subscriberId), anchor);+ },+ async clearAnchor(reportId, subscriberId) {+ anchors.delete(anchorKey(reportId, subscriberId));+ },+ async reserveDelivery(reportId, subscriberId, updateId) {+ const key = deliveredKey(reportId, subscriberId, updateId);+ if (delivered.has(key)) return false;+ delivered.add(key);+ return true;+ },+ async releaseDelivery(reportId, subscriberId, updateId) {+ delivered.delete(deliveredKey(reportId, subscriberId, updateId));+ },+ };+}diff --git a/packages/subscriptions/src/channels/slack.test.ts b/packages/subscriptions/src/channels/slack.test.tsnew file mode 100644index 000000000..a9084853e--- /dev/null+++ b/packages/subscriptions/src/channels/slack.test.ts@@ -0,0 +1,267 @@+import { expect } from "@std/expect";+import { describe, it as test } from "@std/testing/bdd";++import type { PageUpdate, Subscription } from "../types";+import {+ type SlackClient,+ createSlackChannel,+ validateSlackConfig,+} from "./slack";+import { createMemoryAnchorStore } from "./slack-store";++interface RecordedCall {+ method: "post" | "update";+ channel: string;+ thread_ts?: string;+ ts?: string;+}++function makeClient(opts: { failPostWith?: string } = {}) {+ const calls: RecordedCall[] = [];+ let counter = 0;+ const client: SlackClient = {+ async postMessage(args) {+ calls.push({+ method: "post",+ channel: args.channel,+ thread_ts: args.thread_ts,+ });+ if (opts.failPostWith) {+ const error = new Error("slack error") as Error & {+ data?: { error?: string };+ };+ error.data = { error: opts.failPostWith };+ throw error;+ }+ counter += 1;+ return { ts: `1700000000.000${counter}` };+ },+ async update(args) {+ calls.push({ method: "update", channel: args.channel, ts: args.ts });+ return { ts: args.ts };+ },+ };+ return { client, calls };+}++function makeSub(over: Partial<Subscription> = {}): Subscription {+ return {+ id: 1,+ pageId: 1,+ pageName: "Acme",+ pageSlug: "acme",+ customDomain: null,+ componentIds: [],+ channelType: "slack",+ slackChannelId: "C1",+ channelConfig: JSON.stringify({ teamId: "T1", channelId: "C1" }),+ ...over,+ };+}++function makeUpdate(over: Partial<PageUpdate> = {}): PageUpdate {+ return {+ id: 10,+ pageId: 1,+ title: "API degraded",+ status: "investigating",+ message: "investigating",+ pageComponentIds: [],+ pageComponents: [],+ date: "2026-01-01T10:00:00.000Z",+ updateId: 100,+ ...over,+ };+}++const noopUnsub = async () => {};+const token = async () => "xoxb-test";++describe("createSlackChannel", () => {+ test("first update opens the thread (root post, no update, anchor set)", async () => {+ const { client, calls } = makeClient();+ const store = createMemoryAnchorStore();+ const channel = createSlackChannel({+ store,+ createClient: () => client,+ getBotToken: token,+ softUnsubscribe: noopUnsub,+ });++ await channel.sendNotifications([makeSub()], makeUpdate());++ expect(calls.filter((c) => c.method === "post").length).toBe(1);+ expect(calls[0]?.thread_ts).toBeUndefined();+ expect(calls.some((c) => c.method === "update")).toBe(false);+ expect(await store.getAnchor(10, 1)).not.toBeNull();+ });++ test("subsequent update replies in thread and re-renders root", async () => {+ const { client, calls } = makeClient();+ const store = createMemoryAnchorStore();+ const channel = createSlackChannel({+ store,+ createClient: () => client,+ getBotToken: token,+ softUnsubscribe: noopUnsub,+ });++ await channel.sendNotifications([makeSub()], makeUpdate({ updateId: 100 }));+ await channel.sendNotifications(+ [makeSub()],+ makeUpdate({ updateId: 101, status: "monitoring" }),+ );++ const posts = calls.filter((c) => c.method === "post");+ expect(posts.length).toBe(2);+ expect(posts[1]?.thread_ts).toBe("1700000000.0001");+ expect(calls.some((c) => c.method === "update")).toBe(true);+ });++ test("same update delivered twice posts once (idempotent)", async () => {+ const { client, calls } = makeClient();+ const store = createMemoryAnchorStore();+ const channel = createSlackChannel({+ store,+ createClient: () => client,+ getBotToken: token,+ softUnsubscribe: noopUnsub,+ });++ await channel.sendNotifications([makeSub()], makeUpdate({ updateId: 100 }));+ await channel.sendNotifications([makeSub()], makeUpdate({ updateId: 100 }));++ expect(calls.filter((c) => c.method === "post").length).toBe(1);+ });++ test("failed post releases the reservation so a retry re-posts", async () => {+ let attempts = 0;+ const posts: number[] = [];+ const client: SlackClient = {+ async postMessage() {+ attempts += 1;+ posts.push(attempts);+ if (attempts === 1) {+ // Non-terminal error: runSlack returns null, no soft-unsubscribe.+ const error = new Error("slack error") as Error & {+ data?: { error?: string };+ };+ error.data = { error: "ratelimited" };+ throw error;+ }+ return { ts: "1700000000.0001" };+ },+ async update(args) {+ return { ts: args.ts };+ },+ };+ const store = createMemoryAnchorStore();+ const channel = createSlackChannel({+ store,+ createClient: () => client,+ getBotToken: token,+ softUnsubscribe: noopUnsub,+ });++ await channel.sendNotifications([makeSub()], makeUpdate({ updateId: 100 }));+ await channel.sendNotifications([makeSub()], makeUpdate({ updateId: 100 }));++ // First attempt failed and released; second attempt reserved again and posted.+ expect(posts.length).toBe(2);+ });++ test("missing bot token delivers nothing", async () => {+ const { client, calls } = makeClient();+ const channel = createSlackChannel({+ store: createMemoryAnchorStore(),+ createClient: () => client,+ getBotToken: async () => null,+ softUnsubscribe: noopUnsub,+ });++ await channel.sendNotifications([makeSub()], makeUpdate());+ expect(calls.length).toBe(0);+ });++ test("terminal error soft-unsubscribes the row", async () => {+ const { client } = makeClient({ failPostWith: "channel_not_found" });+ const unsubscribed: number[] = [];+ const channel = createSlackChannel({+ store: createMemoryAnchorStore(),+ createClient: () => client,+ getBotToken: token,+ softUnsubscribe: async (id) => {+ unsubscribed.push(id);+ },+ });++ await channel.sendNotifications([makeSub({ id: 7 })], makeUpdate());+ expect(unsubscribed).toEqual([7]);+ });++ test("maintenance posts once with no thread and no anchor", async () => {+ const { client, calls } = makeClient();+ const store = createMemoryAnchorStore();+ const channel = createSlackChannel({+ store,+ createClient: () => client,+ getBotToken: token,+ softUnsubscribe: noopUnsub,+ });++ await channel.sendNotifications(+ [makeSub()],+ makeUpdate({ status: "maintenance", updateId: undefined }),+ );++ expect(calls.filter((c) => c.method === "post").length).toBe(1);+ expect(calls.some((c) => c.method === "update")).toBe(false);+ expect(await store.getAnchor(10, 1)).toBeNull();+ });+});++describe("validateSlackConfig", () => {+ test("accepts non-empty teamId and channelId strings", async () => {+ const result = await validateSlackConfig({+ teamId: "T1",+ channelId: "C1",+ });+ expect(result.valid).toBe(true);+ });++ const invalidConfigs: Array<{ label: string; config: unknown }> = [+ { label: "null config", config: null },+ { label: "non-object", config: "T1" },+ { label: "missing teamId", config: { channelId: "C1" } },+ { label: "missing channelId", config: { teamId: "T1" } },+ { label: "null teamId", config: { teamId: null, channelId: "C1" } },+ { label: "numeric channelId", config: { teamId: "T1", channelId: 42 } },+ { label: "empty teamId", config: { teamId: "", channelId: "C1" } },+ { label: "empty channelId", config: { teamId: "T1", channelId: "" } },+ ];++ for (const { label, config } of invalidConfigs) {+ test(`rejects ${label}`, async () => {+ const result = await validateSlackConfig(config);+ expect(result.valid).toBe(false);+ expect(result.error).toBeDefined();+ });+ }+});++describe("reserveDelivery (memory store)", () => {+ test("only the first reservation for a key wins", async () => {+ const store = createMemoryAnchorStore();+ expect(await store.reserveDelivery(1, 2, 3)).toBe(true);+ expect(await store.reserveDelivery(1, 2, 3)).toBe(false);+ // A different updateId is an independent reservation.+ expect(await store.reserveDelivery(1, 2, 4)).toBe(true);+ });++ test("releaseDelivery makes the key reservable again", async () => {+ const store = createMemoryAnchorStore();+ expect(await store.reserveDelivery(1, 2, 3)).toBe(true);+ await store.releaseDelivery(1, 2, 3);+ expect(await store.reserveDelivery(1, 2, 3)).toBe(true);+ });+});diff --git a/packages/subscriptions/src/channels/slack.ts b/packages/subscriptions/src/channels/slack.tsnew file mode 100644index 000000000..e469020af--- /dev/null+++ b/packages/subscriptions/src/channels/slack.ts@@ -0,0 +1,265 @@+import { and, db, eq } from "@openstatus/db";+import { integration, pageSubscriber } from "@openstatus/db/src/schema";+import type {+ ChatPostMessageArguments,+ ChatUpdateArguments,+} from "@slack/web-api";+import { WebClient } from "@slack/web-api";++import type { PageUpdate, Subscription } from "../types";+import { buildReplyMessage, buildRootMessage } from "./slack-blocks";+import { type SlackAnchorStore, createRedisAnchorStore } from "./slack-store";++interface SlackPostResult {+ ts?: string;+}++export interface SlackClient {+ postMessage(args: ChatPostMessageArguments): Promise<SlackPostResult>;+ update(args: ChatUpdateArguments): Promise<SlackPostResult>;+}++export interface SlackChannelDeps {+ store: SlackAnchorStore;+ createClient: (token: string) => SlackClient;+ getBotToken: (teamId: string) => Promise<string | null>;+ softUnsubscribe: (subscriberId: number) => Promise<void>;+}++// Errors that can never succeed on retry — the channel/app is gone, so we+// stop delivering to that subscriber instead of failing on every update.+const TERMINAL_SLACK_ERRORS = new Set([+ "channel_not_found",+ "is_archived",+ "channel_is_archived",+ "account_inactive",+ "token_revoked",+ "not_in_channel",+ "not_authed",+ "invalid_auth",+]);++// WebClient throws `WebAPIPlatformError` carrying `data.error`; this is the+// only place we reach into that SDK error shape.+function slackErrorCode(error: Error): string | undefined {+ const data = (error as Error & { data?: { error?: string } }).data;+ return typeof data?.error === "string" ? data.error : undefined;+}++function parseTeamId(channelConfig?: string): string | null {+ if (!channelConfig) return null;+ try {+ const parsed = JSON.parse(channelConfig) as { teamId?: string };+ return parsed.teamId ?? null;+ } catch {+ return null;+ }+}++async function getBotTokenFromDb(teamId: string): Promise<string | null> {+ const row = await db+ .select({ credential: integration.credential })+ .from(integration)+ .where(+ and(+ eq(integration.name, "slack-agent"),+ eq(integration.externalId, teamId),+ ),+ )+ .get();+ const credential = row?.credential as { botToken?: string } | null;+ return credential?.botToken ?? null;+}++async function softUnsubscribeInDb(subscriberId: number): Promise<void> {+ await db+ .update(pageSubscriber)+ .set({ unsubscribedAt: new Date(), updatedAt: new Date() })+ .where(eq(pageSubscriber.id, subscriberId))+ .run();+}++export function createSlackChannel(deps: SlackChannelDeps) {+ async function runSlack(+ subscriberId: number,+ fn: () => Promise<SlackPostResult>,+ ): Promise<SlackPostResult | null> {+ try {+ return await fn();+ } catch (error) {+ if (error instanceof Error) {+ const code = slackErrorCode(error);+ if (code && TERMINAL_SLACK_ERRORS.has(code)) {+ await deps.softUnsubscribe(subscriberId);+ console.error(+ `slack: terminal error '${code}' for subscriber ${subscriberId} — unsubscribed`,+ );+ return null;+ }+ console.error(+ `slack: delivery failed for subscriber ${subscriberId}: ${error.message}`,+ );+ } else {+ console.error(`slack: delivery failed for subscriber ${subscriberId}`);+ }+ return null;+ }+ }++ async function deliverMaintenance(+ client: SlackClient,+ sub: Subscription,+ channelId: string,+ pageUpdate: PageUpdate,+ ): Promise<void> {+ const root = buildRootMessage(pageUpdate, sub);+ await runSlack(sub.id, () =>+ client.postMessage({+ channel: channelId,+ text: root.text,+ attachments: root.attachments,+ }),+ );+ }++ async function deliverReport(+ client: SlackClient,+ sub: Subscription,+ channelId: string,+ pageUpdate: PageUpdate,+ ): Promise<void> {+ const reportId = pageUpdate.id;+ const updateId = pageUpdate.updateId;+ if (updateId == null) {+ console.error(`slack: status report update ${reportId} missing updateId`);+ return;+ }++ // Atomic dedupe: only the caller that wins this reservation posts. On a+ // failed post we release it below so the delivery stays retriable.+ if (!(await deps.store.reserveDelivery(reportId, sub.id, updateId))) return;++ const anchor = await deps.store.getAnchor(reportId, sub.id);+ const root = buildRootMessage(pageUpdate, sub);++ if (!anchor) {+ const res = await runSlack(sub.id, () =>+ client.postMessage({+ channel: channelId,+ text: root.text,+ attachments: root.attachments,+ }),+ );+ if (!res) {+ await deps.store.releaseDelivery(reportId, sub.id, updateId);+ return;+ }+ if (res.ts) {+ await deps.store.setAnchor(reportId, sub.id, { ts: res.ts, channelId });+ }+ return;+ }++ const reply = buildReplyMessage(pageUpdate);+ const replyRes = await runSlack(sub.id, () =>+ client.postMessage({+ channel: anchor.channelId,+ thread_ts: anchor.ts,+ text: reply.text,+ blocks: reply.blocks,+ }),+ );+ if (!replyRes) {+ await deps.store.releaseDelivery(reportId, sub.id, updateId);+ return;+ }++ // Re-render the root so its emoji/status track the latest state.+ await runSlack(sub.id, () =>+ client.update({+ channel: anchor.channelId,+ ts: anchor.ts,+ text: root.text,+ attachments: root.attachments,+ }),+ );+ }++ async function sendNotifications(+ subscriptions: Subscription[],+ pageUpdate: PageUpdate,+ ): Promise<void> {+ const byTeam = new Map<+ string,+ { sub: Subscription; channelId: string }[]+ >();+ for (const sub of subscriptions) {+ if (sub.channelType !== "slack") continue;+ const channelId = sub.slackChannelId;+ const teamId = parseTeamId(sub.channelConfig);+ if (!channelId || !teamId) {+ console.error(`slack: subscriber ${sub.id} missing channelId/teamId`);+ continue;+ }+ const members = byTeam.get(teamId) ?? [];+ members.push({ sub, channelId });+ byTeam.set(teamId, members);+ }++ await Promise.allSettled(+ [...byTeam.entries()].map(async ([teamId, members]) => {+ const token = await deps.getBotToken(teamId);+ if (!token) {+ console.error(`slack: no bot token for team ${teamId}`);+ return;+ }+ const client = deps.createClient(token);+ await Promise.allSettled(+ members.map(({ sub, channelId }) =>+ pageUpdate.status === "maintenance"+ ? deliverMaintenance(client, sub, channelId, pageUpdate)+ : deliverReport(client, sub, channelId, pageUpdate),+ ),+ );+ }),+ );+ }++ return { sendNotifications };+}++const defaultChannel = createSlackChannel({+ store: createRedisAnchorStore(),+ createClient: (token) => {+ const web = new WebClient(token);+ return {+ postMessage: (args) => web.chat.postMessage(args),+ update: (args) => web.chat.update(args),+ };+ },+ getBotToken: getBotTokenFromDb,+ softUnsubscribe: softUnsubscribeInDb,+});++export async function sendSlackNotifications(+ subscriptions: Subscription[],+ pageUpdate: PageUpdate,+): Promise<void> {+ return defaultChannel.sendNotifications(subscriptions, pageUpdate);+}++export async function validateSlackConfig(+ config: unknown,+): Promise<{ valid: boolean; error?: string }> {+ if (+ config !== null &&+ typeof config === "object" &&+ typeof (config as { teamId?: unknown }).teamId === "string" &&+ (config as { teamId: string }).teamId.length > 0 &&+ typeof (config as { channelId?: unknown }).channelId === "string" &&+ (config as { channelId: string }).channelId.length > 0+ ) {+ return { valid: true };+ }+ return { valid: false, error: "slack config requires teamId and channelId" };+}diff --git a/packages/subscriptions/src/dispatcher.ts b/packages/subscriptions/src/dispatcher.tsindex 08e51301e..f687e5664 100644--- a/packages/subscriptions/src/dispatcher.ts+++ b/packages/subscriptions/src/dispatcher.ts@@ -167,9 +167,10 @@ export async function dispatchPageUpdate(pageUpdate: PageUpdate) {pageName: pageData.name,pageSlug: pageData.slug,customDomain: pageData.customDomain,- channelType: sub.channelType as "email" | "webhook",+ channelType: sub.channelType as "email" | "webhook" | "slack",email: sub.email ?? undefined,webhookUrl: sub.webhookUrl ?? undefined,+ slackChannelId: sub.slackChannelId ?? undefined,channelConfig: sub.channelConfig ?? undefined,token: sub.token ?? undefined,acceptedAt: sub.acceptedAt ?? undefined,diff --git a/packages/subscriptions/src/index.ts b/packages/subscriptions/src/index.tsindex b161ad005..be5a387cf 100644--- a/packages/subscriptions/src/index.ts+++ b/packages/subscriptions/src/index.ts@@ -13,6 +13,18 @@ export {validateWebhookConfig,} from "./channels/webhook";export type { WebhookFlavor } from "./channels/webhook";+export {+ createSlackChannel,+ sendSlackNotifications,+ validateSlackConfig,+} from "./channels/slack";+export type { SlackChannelDeps, SlackClient } from "./channels/slack";+export { buildReplyMessage, buildRootMessage } from "./channels/slack-blocks";+export {+ createMemoryAnchorStore,+ createRedisAnchorStore,+} from "./channels/slack-store";+export type { SlackAnchorStore } from "./channels/slack-store";export { getChannel } from "./channels/index";// Export dispatcher functionsdiff --git a/packages/subscriptions/src/types.ts b/packages/subscriptions/src/types.tsindex f0c95d7cf..d1cdf9c5f 100644--- a/packages/subscriptions/src/types.ts+++ b/packages/subscriptions/src/types.ts@@ -11,10 +11,11 @@ export interface Subscription {componentIds: number[]; // Empty = entire page// Only ONE identifier populated based on channelType- channelType: "email" | "webhook";+ channelType: "email" | "webhook" | "slack";email?: string;webhookUrl?: string;- channelConfig?: string; // JSON string for headers, secrets, etc.+ slackChannelId?: string;+ channelConfig?: string; // JSON string for headers, secrets, slack teamId, etc.token?: string;acceptedAt?: Date;diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex fd4f9cdd8..2853e3e63 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -2740,6 +2740,12 @@ importers:'@openstatus/utils':specifier: workspace:*version: link:../utils+ '@slack/web-api':+ specifier: 'catalog:'+ version: 7.16.0+ '@upstash/redis':+ specifier: 'catalog:'+ version: 1.38.0effect:specifier: 'catalog:'version: 3.21.2