Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
🔥 Add run api (#870)
Thibault Le Ouay5d867bb286bc
diff --git a/apps/checker/cmd/main.go b/apps/checker/cmd/main.goindex d37e8d52a..676872d59 100644--- a/apps/checker/cmd/main.go+++ b/apps/checker/cmd/main.go@@ -19,7 +19,6 @@ import ("github.com/openstatushq/openstatus/apps/checker/request""github.com/rs/zerolog/log"- unkey "github.com/WilfredAlmeida/unkey-go/features"backoff "github.com/cenkalti/backoff/v4")@@ -61,7 +60,7 @@ func main() {router := gin.New()router.POST("/checker", func(c *gin.Context) {ctx := c.Request.Context()-+ dataSourceName := "ping_response__v8"if c.GetHeader("Authorization") != fmt.Sprintf("Basic %s", cronSecret) {c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})return@@ -112,7 +111,6 @@ func main() {if err != nil {// handle errorreturn fmt.Errorf("unable to unmarshal assertion: %w", err)-}switch assert.AssertionType {case request.AssertionHeader:@@ -183,7 +181,7 @@ func main() {})}- if err := tinybirdClient.SendEvent(ctx, res); err != nil {+ if err := tinybirdClient.SendEvent(ctx, res, dataSourceName); err != nil {log.Ctx(ctx).Error().Err(err).Msg("failed to send event to tinybird")}@@ -202,7 +200,7 @@ func main() {Error: 1,Assertions: assertionAsString,Body: "",- }); err != nil {+ }, dataSourceName); err != nil {log.Ctx(ctx).Error().Err(err).Msg("failed to send event to tinybird")}@@ -226,6 +224,7 @@ func main() {})router.POST("/ping/:region", func(c *gin.Context) {+ dataSourceName := "check_response__v1"region := c.Param("region")if region == "" {c.String(http.StatusBadRequest, "region is required")@@ -233,25 +232,10 @@ func main() {}fmt.Printf("Start of /ping/%s\n", region)- apiKey := c.GetHeader("x-openstatus-key")-- if c.GetHeader("Authorization") != fmt.Sprintf("Basic %s", cronSecret) && apiKey == "" {+ if c.GetHeader("Authorization") != fmt.Sprintf("Basic %s", cronSecret) {c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})return}- if apiKey != "" {- response, err := unkey.KeyVerify(apiKey)- if err != nil {- c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})- return- }-- if !response.Valid {- fmt.Println("Key is not valid valid")- c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})-- }- }if region != flyRegion {c.Header("fly-replay", fmt.Sprintf("region=%s", region))@@ -276,6 +260,10 @@ func main() {if err != nil {return fmt.Errorf("unable to ping: %w", err)}+ r.Region = flyRegion+ if err := tinybirdClient.SendEvent(ctx, res, dataSourceName); err != nil {+ log.Ctx(ctx).Error().Err(err).Msg("failed to send event to tinybird")+ }res = rreturn nil}diff --git a/apps/checker/ping.go b/apps/checker/ping.goindex 7a1ac8abc..0424b4874 100644--- a/apps/checker/ping.go+++ b/apps/checker/ping.go@@ -57,6 +57,7 @@ type Response struct {Timing Timing `json:"timing"`Error string `json:"error,omitempty"`Tags []string `json:"tags,omitempty"`+ Region string `json:"region"`}func Ping(ctx context.Context, client *http.Client, inputData request.CheckerRequest) (PingData, error) {diff --git a/apps/checker/pkg/tinybird/client.go b/apps/checker/pkg/tinybird/client.goindex 0261835be..5179fb74e 100644--- a/apps/checker/pkg/tinybird/client.go+++ b/apps/checker/pkg/tinybird/client.go@@ -14,7 +14,7 @@ import (const baseURL = "https://api.tinybird.co/v0/events"type Client interface {- SendEvent(ctx context.Context, event any) error+ SendEvent(ctx context.Context, event any, dataSourceName string) error}type client struct {@@ -29,7 +29,7 @@ func NewClient(httpClient *http.Client, apiKey string) Client {}}-func (c client) SendEvent(ctx context.Context, event any) error {+func (c client) SendEvent(ctx context.Context, event any, dataSourceName string) error {requestURL, err := url.Parse(baseURL)if err != nil {log.Ctx(ctx).Error().Err(err).Msg("unable to parse url")@@ -37,7 +37,7 @@ func (c client) SendEvent(ctx context.Context, event any) error {}q := requestURL.Query()- q.Add("name", "ping_response__v8")+ q.Add("name", dataSourceName)requestURL.RawQuery = q.Encode()var payload bytes.Bufferdiff --git a/apps/checker/pkg/tinybird/client_test.go b/apps/checker/pkg/tinybird/client_test.goindex 9bf14bcab..806afe18c 100644--- a/apps/checker/pkg/tinybird/client_test.go+++ b/apps/checker/pkg/tinybird/client_test.go@@ -39,7 +39,7 @@ func TestSendEvent(t *testing.T) {client := tinybird.NewClient(interceptor.GetHTTPClient(), "apiKey")- err := client.SendEvent(ctx, "event")+ err := client.SendEvent(ctx, "event", "test")require.Error(t, err)})@@ -54,7 +54,7 @@ func TestSendEvent(t *testing.T) {client := tinybird.NewClient(interceptor.GetHTTPClient(), "apiKey")- err := client.SendEvent(ctx, "event")+ err := client.SendEvent(ctx, "event", "test")require.Error(t, err)})@@ -71,8 +71,8 @@ func TestSendEvent(t *testing.T) {client := tinybird.NewClient(interceptor.GetHTTPClient(), "apiKey")- err := client.SendEvent(ctx, "event")+ err := client.SendEvent(ctx, "event", "test")require.NoError(t, err)- require.Equal(t, "https://api.tinybird.co/v0/events?name=ping_response__v8", url)+ require.Equal(t, "https://api.tinybird.co/v0/events?name=test", url)})}diff --git a/apps/checker/request/request.go b/apps/checker/request/request.goindex 5f85cf999..972643fcd 100644--- a/apps/checker/request/request.go+++ b/apps/checker/request/request.go@@ -59,6 +59,7 @@ type CheckerRequest struct {}type PingRequest struct {+ ID string `json:"id"`URL string `json:"url"`Method string `json:"method"`Body string `json:"body"`diff --git a/apps/server/package.json b/apps/server/package.jsonindex 3626cab77..6122ecc8c 100644--- a/apps/server/package.json+++ b/apps/server/package.json@@ -11,8 +11,8 @@},"dependencies": {"@hono/sentry": "1.1.0",- "@hono/zod-openapi": "0.13.0",- "@hono/zod-validator": "0.2.1",+ "@hono/zod-openapi": "0.14.2",+ "@hono/zod-validator": "0.2.2","@openstatus/analytics": "workspace:^","@openstatus/db": "workspace:*","@openstatus/emails": "workspace:*",@@ -29,8 +29,9 @@"@t3-oss/env-core": "0.7.1","@unkey/api": "0.16.0","@upstash/qstash": "2.1.8",- "hono": "4.0.0",+ "hono": "4.4.5","nanoid": "5.0.2",+ "percentile": "^1.6.0","validator": "13.11.0","zod": "3.22.4"},diff --git a/apps/server/src/v1/check/index.ts b/apps/server/src/v1/check/index.tsnew file mode 100644index 000000000..23de62426--- /dev/null+++ b/apps/server/src/v1/check/index.ts@@ -0,0 +1,14 @@+import { OpenAPIHono } from "@hono/zod-openapi";++import type { Variables } from "../index";++import { handleZodError } from "../../libs/errors";+import { registerPostCheck } from "./post";++const checkAPI = new OpenAPIHono<{ Variables: Variables }>({+ defaultHook: handleZodError,+});++registerPostCheck(checkAPI);++export { checkAPI };diff --git a/apps/server/src/v1/check/post.test.ts b/apps/server/src/v1/check/post.test.tsnew file mode 100644index 000000000..3006c4040--- /dev/null+++ b/apps/server/src/v1/check/post.test.ts@@ -0,0 +1,152 @@+import { expect, test } from "bun:test";++import { api } from "../index";++import { afterEach, mock } from "bun:test";++const mockFetch = mock();++global.fetch = mockFetch;+mock.module("node-fetch", () => mockFetch);++afterEach(() => {+ mockFetch.mockReset();+});++test("Create a single check ", async () => {+ const data = {+ url: "https://www.openstatus.dev",+ regions: ["ams"],+ method: "POST",+ body: '{"hello":"world"}',+ headers: [{ key: "key", value: "value" }],+ };+ mockFetch.mockReturnValue(+ Promise.resolve(+ new Response(+ '{"status":200,"latency":100,"body":"Hello World","headers":{"Content-Type":"application/json"},"timestamp":1234567890,"timing":{"dnsStart":1,"dnsDone":2,"connectStart":3,"connectDone":4,"tlsHandshakeStart":5,"tlsHandshakeDone":6,"firstByteStart":7,"firstByteDone":8,"transferStart":9,"transferDone":10},"region":"ams"}',+ { status: 200, headers: { "content-type": "application/json" } },+ ),+ ),+ );++ const res = await api.request("/check", {+ method: "POST",+ headers: {+ "x-openstatus-key": "1",+ "content-type": "application/json",+ },+ body: JSON.stringify(data),+ });++ expect(res.status).toBe(200);++ expect(await res.json()).toMatchObject({+ id: expect.any(Number),+ raw: [+ {+ connectDone: 4,+ connectStart: 3,+ dnsDone: 2,+ dnsStart: 1,+ firstByteDone: 8,+ firstByteStart: 7,+ tlsHandshakeDone: 6,+ tlsHandshakeStart: 5,+ transferDone: 10,+ transferStart: 9,+ },+ ],+ response: {+ body: "Hello World",+ headers: {+ "Content-Type": "application/json",+ },+ latency: 100,+ region: "ams",+ status: 200,+ timestamp: 1234567890,+ timing: {+ connectDone: 4,+ connectStart: 3,+ dnsDone: 2,+ dnsStart: 1,+ firstByteDone: 8,+ firstByteStart: 7,+ tlsHandshakeDone: 6,+ tlsHandshakeStart: 5,+ transferDone: 10,+ transferStart: 9,+ },+ },+ });+});++test.todo("Create a multiple check ", async () => {+ const data = {+ url: "https://www.openstatus.dev",+ regions: ["ams", "gru"],+ method: "POST",+ body: '{"hello":"world"}',+ headers: [{ key: "key", value: "value" }],+ };+ mockFetch.mockReturnValue(+ Promise.resolve(+ new Response(+ '{"status":200,"latency":100,"body":"Hello World","headers":{"Content-Type":"application/json"},"timestamp":1234567890,"timing":{"dnsStart":1,"dnsDone":2,"connectStart":3,"connectDone":4,"tlsHandshakeStart":5,"tlsHandshakeDone":6,"firstByteStart":7,"firstByteDone":8,"transferStart":9,"transferDone":10},"region":"ams"}',+ { status: 200, headers: { "content-type": "application/json" } },+ ),+ ),+ );++ const res = await api.request("/check", {+ method: "POST",+ headers: {+ "x-openstatus-key": "1",+ "content-type": "application/json",+ },+ body: JSON.stringify(data),+ });++ expect(res.status).toBe(200);++ expect(await res.json()).toMatchObject({+ id: expect.any(Number),+ raw: [+ {+ connectDone: 4,+ connectStart: 3,+ dnsDone: 2,+ dnsStart: 1,+ firstByteDone: 8,+ firstByteStart: 7,+ tlsHandshakeDone: 6,+ tlsHandshakeStart: 5,+ transferDone: 10,+ transferStart: 9,+ },+ ],+ response: {+ body: "Hello World",+ headers: {+ "Content-Type": "application/json",+ },+ latency: 100,+ region: "ams",+ status: 200,+ timestamp: 1234567890,+ timing: {+ connectDone: 4,+ connectStart: 3,+ dnsDone: 2,+ dnsStart: 1,+ firstByteDone: 8,+ firstByteStart: 7,+ tlsHandshakeDone: 6,+ tlsHandshakeStart: 5,+ transferDone: 10,+ transferStart: 9,+ },+ },+ });+});diff --git a/apps/server/src/v1/check/post.ts b/apps/server/src/v1/check/post.tsnew file mode 100644index 000000000..06370da34--- /dev/null+++ b/apps/server/src/v1/check/post.ts@@ -0,0 +1,226 @@+import { createRoute, z } from "@hono/zod-openapi";++import { db } from "@openstatus/db";+import { check } from "@openstatus/db/src/schema/check";+import percentile from "percentile";+import { env } from "../../env";+import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";+import type { checkAPI } from "./index";+import {+ AggregatedResponseSchema,+ CheckPostResponseSchema,+ CheckSchema,+ ResponseSchema,+} from "./schema";++const postRoute = createRoute({+ method: "post",+ tags: ["page"],+ description: "Run a single check",+ path: "/",+ request: {+ body: {+ description: "The run request to create",+ content: {+ "application/json": {+ schema: CheckSchema,+ },+ },+ },+ },+ responses: {+ 200: {+ content: {+ "application/json": {+ schema: CheckPostResponseSchema,+ },+ },+ description: "Return a run result",+ },+ ...openApiErrorResponses,+ },+});++export function registerPostCheck(api: typeof checkAPI) {+ return api.openapi(postRoute, async (c) => {+ const data = c.req.valid("json");+ const workspaceId = c.get("workspaceId");+ const input = c.req.valid("json");++ const { headers, regions, runCount, aggregated, ...rest } = data;++ const newCheck = await db+ .insert(check)+ .values({+ workspaceId: Number(workspaceId),+ regions: regions.join(","),+ countRequests: runCount,+ ...rest,+ })+ .returning()+ .get();+ const result = [];+ for (let count = 0; count < input.runCount; count++) {+ const currentFetch = [];+ for (const region of input.regions) {+ const r = fetch(`https://checker.openstatus.dev/ping/${region}`, {+ headers: {+ Authorization: `Basic ${env.CRON_SECRET}`,+ "Content-Type": "application/json",+ "fly-prefer-region": region,+ },+ method: "POST",+ body: JSON.stringify({+ checkId: newCheck.id,+ workspaceId: workspaceId,+ url: input.url,+ method: input.method,+ headers: input.headers?.reduce((acc, { key, value }) => {+ if (!key) return acc; // key === "" is an invalid header++ return {+ // biome-ignore lint/performance/noAccumulatingSpread: <explanation>+ ...acc,+ [key]: value,+ };+ }, {}),+ body: input.body ? input.body : undefined,+ }),+ });+ currentFetch.push(r);+ }++ const allResults = await Promise.allSettled(currentFetch);+ result.push(...allResults);+ }+ console.log(result);+ const filteredResult = result.filter((r) => r.status === "fulfilled");+ const fulfilledRequest = [];+ for await (const r of filteredResult) {+ if (r.status !== "fulfilled") throw new Error("No value");++ const json = await r.value.json();+ console.log(ResponseSchema.safeParse(json));+ fulfilledRequest.push(ResponseSchema.parse(json));+ }++ let aggregatedResponse = null;+ if (aggregated) {+ // This is ugly+ const dnsArray = fulfilledRequest.map(+ (r) => r.timing.dnsDone - r.timing.dnsStart,+ );+ const connectArray = fulfilledRequest.map(+ (r) => r.timing.connectDone - r.timing.connectStart,+ );+ const tlsArray = fulfilledRequest.map(+ (r) => r.timing.tlsHandshakeDone - r.timing.tlsHandshakeStart,+ );+ const firstArray = fulfilledRequest.map(+ (r) => r.timing.firstByteDone - r.timing.firstByteStart,+ );+ const transferArray = fulfilledRequest.map(+ (r) => r.timing.transferDone - r.timing.transferStart,+ );+ const latencyArray = fulfilledRequest.map((r) => r.latency);++ const dnsPercentile = percentile([50, 75, 95, 99], dnsArray) as number[];+ const connectPercentile = percentile(+ [50, 75, 95, 99],+ connectArray,+ ) as number[];+ const tlsPercentile = percentile([50, 75, 95, 99], tlsArray) as number[];+ const firstPercentile = percentile(+ [50, 75, 95, 99],+ firstArray,+ ) as number[];++ const transferPercentile = percentile(+ [50, 75, 95, 99],+ transferArray,+ ) as number[];+ const latencyPercentile = percentile(+ [50, 75, 95, 99],+ latencyArray,+ ) as number[];++ const aggregate = z.object({+ dms: AggregatedResponseSchema,+ connect: AggregatedResponseSchema,+ tls: AggregatedResponseSchema,+ firstByte: AggregatedResponseSchema,+ transfert: AggregatedResponseSchema,+ latency: AggregatedResponseSchema,+ });+ const aggregatedDNS = AggregatedResponseSchema.parse({+ p50: dnsPercentile[0],+ p75: dnsPercentile[1],+ p95: dnsPercentile[2],+ p99: dnsPercentile[3],+ min: Math.min(...dnsArray),+ max: Math.max(...dnsArray),+ });+ const aggregatedConnect = AggregatedResponseSchema.parse({+ p50: connectPercentile[0],+ p75: connectPercentile[1],+ p95: connectPercentile[2],+ p99: connectPercentile[3],+ min: Math.min(...connectArray),+ max: Math.max(...connectArray),+ });+ const aggregatedTls = AggregatedResponseSchema.parse({+ p50: tlsPercentile[0],+ p75: tlsPercentile[1],+ p95: tlsPercentile[2],+ p99: tlsPercentile[3],+ min: Math.min(...tlsArray),+ max: Math.max(...tlsArray),+ });+ const aggregatedFirst = AggregatedResponseSchema.parse({+ p50: firstPercentile[0],+ p75: firstPercentile[1],+ p95: firstPercentile[2],+ p99: firstPercentile[3],+ min: Math.min(...firstArray),+ max: Math.max(...firstArray),+ });+ const aggregatedTransfer = AggregatedResponseSchema.parse({+ p50: transferPercentile[0],+ p75: transferPercentile[1],+ p95: transferPercentile[2],+ p99: transferPercentile[3],+ min: Math.min(...transferArray),+ max: Math.max(...transferArray),+ });++ const aggregatedLatency = AggregatedResponseSchema.parse({+ p50: latencyPercentile[0],+ p75: latencyPercentile[1],+ p95: latencyPercentile[2],+ p99: latencyPercentile[3],+ min: Math.min(...latencyArray),+ max: Math.max(...latencyArray),+ });++ aggregatedResponse = aggregate.parse({+ dns: aggregatedDNS,+ connection: aggregatedConnect,+ tls: aggregatedTls,+ firstByte: aggregatedFirst,+ transfer: aggregatedTransfer,+ latency: aggregatedLatency,+ });+ }+ const allTimings = fulfilledRequest.map((r) => r.timing);++ const lastResponse = fulfilledRequest[fulfilledRequest.length - 1];+ const responseResult = CheckPostResponseSchema.parse({+ id: newCheck.id,+ raw: allTimings,+ response: lastResponse,+ aggregated: aggregatedResponse,+ });++ return c.json(responseResult);+ });+}diff --git a/apps/server/src/v1/check/schema.ts b/apps/server/src/v1/check/schema.tsnew file mode 100644index 000000000..1ad73bfdb--- /dev/null+++ b/apps/server/src/v1/check/schema.ts@@ -0,0 +1,131 @@+import { z } from "zod";+import { MonitorSchema } from "../monitors/schema";++export const CheckSchema = MonitorSchema.pick({+ url: true,+ body: true,+ headers: true,+ method: true,+ regions: true,+})+ .extend({+ runCount: z+ .number()+ .optional()+ .default(1)+ .openapi({ description: "The number of times to run the check" }),+ aggregated: z+ .boolean()+ .optional()+ .openapi({ description: "Whether to aggregate the results or not" }),+ // webhook: z+ // .string()+ // .optional()+ // .openapi({ description: "The webhook to send the result to" }),+ })+ .openapi({+ description: "The check request",+ });++export const TimingSchema = z.object({+ dnsStart: z+ .number()+ .openapi({ description: "DNS timestamp start time in UTC " }),+ dnsDone: z+ .number()+ .openapi({ description: "DNS timestamp end time in UTC " }),+ connectStart: z+ .number()+ .openapi({ description: "Connect timestamp start time in UTC " }),+ connectDone: z+ .number()+ .openapi({ description: "Connect timestamp end time in UTC " }),+ tlsHandshakeStart: z+ .number()+ .openapi({ description: "TLS handshake timestamp start time in UTC " }),+ tlsHandshakeDone: z+ .number()+ .openapi({ description: "TLS handshake timestamp end time in UTC " }),+ firstByteStart: z+ .number()+ .openapi({ description: "First byte timestamp start time in UTC " }),+ firstByteDone: z+ .number()+ .openapi({ description: "First byte timestamp end time in UTC " }),+ transferStart: z+ .number()+ .openapi({ description: "Transfer timestamp start time in UTC " }),+ transferDone: z+ .number()+ .openapi({ description: "Transfer timestamp end time in UTC " }),+});++export const AggregatedResponseSchema = z+ .object({+ p50: z.number().openapi({ description: "The 50th percentile" }),+ p75: z.number().openapi({ description: "The 75th percentile" }),+ p95: z.number().openapi({ description: "The 95th percentile" }),+ p99: z.number().openapi({ description: "The 99th percentile" }),+ min: z.number().openapi({ description: "The minimum value" }),+ max: z.number().openapi({ description: "The maximum value" }),+ })+ .openapi({+ description: "The aggregated data of the check",+ });++export const ResponseSchema = z.object({+ timestamp: z+ .number()+ .openapi({ description: "The timestamp of the response in UTC" }),+ status: z+ .number()+ .openapi({ description: "The status code of the response" }),+ latency: z.number().openapi({ description: "The latency of the response" }),+ body: z+ .string()+ .optional()+ .openapi({ description: "The body of the response" }),+ headers: z+ .record(z.string())+ .optional()+ .openapi({ description: "The headers of the response" }),+ timing: TimingSchema.openapi({+ description: "The timing metrics of the response",+ }),+ aggregated: z+ .object({+ dns: AggregatedResponseSchema.openapi({+ description: "The aggregated DNS timing of the check",+ }),+ connection: AggregatedResponseSchema.openapi({+ description: "The aggregated connection timing of the check",+ }),+ tls: AggregatedResponseSchema.openapi({+ description: "The aggregated tls timing of the check",+ }),+ firstByte: AggregatedResponseSchema.openapi({+ description: "The aggregated first byte timing of the check",+ }),+ transfer: AggregatedResponseSchema.openapi({+ description: "The aggregated transfer timing of the check",+ }),+ latency: AggregatedResponseSchema.openapi({+ description: "The aggregated latency timing of the check",+ }),+ })+ .optional()+ .openapi({+ description: "The aggregated data dns timing of the check",+ }),+ region: z.string().openapi({ description: "The region where the check ran" }),+});++export const CheckPostResponseSchema = z.object({+ id: z.number().int().openapi({ description: "The id of the check" }),+ raw: z.array(TimingSchema).openapi({+ description: "The raw data of the check",+ }),+ response: ResponseSchema.openapi({+ description: "The last response of the check",+ }),+});diff --git a/apps/server/src/v1/index.ts b/apps/server/src/v1/index.tsindex aabd5d76f..bdba3dfc9 100644--- a/apps/server/src/v1/index.ts+++ b/apps/server/src/v1/index.ts@@ -5,6 +5,7 @@ import { logger } from "hono/logger";import type { Limits } from "@openstatus/plans/src/types";import { handleError, handleZodError } from "../libs/errors";+import { checkAPI } from "./check";import { incidentsApi } from "./incidents";import { middleware } from "./middleware";import { monitorsApi } from "./monitors";@@ -56,3 +57,4 @@ api.route("/page", pagesApi);api.route("/page_subscriber", pageSubscribersApi);api.route("/status_report", statusReportsApi);api.route("/status_report_update", statusReportUpdatesApi);+api.route("/check", checkAPI);diff --git a/apps/server/src/v1/monitors/monitors.test.ts b/apps/server/src/v1/monitors/monitors.test.tsindex dfed05084..a4a128892 100644--- a/apps/server/src/v1/monitors/monitors.test.ts+++ b/apps/server/src/v1/monitors/monitors.test.ts@@ -24,6 +24,7 @@ test("GET one monitor", async () => {headers: [{ key: "key", value: "value" }],active: true,public: false,+ assertions: null,});});@@ -63,6 +64,14 @@ test("Create a monitor", async () => {headers: [{ key: "key", value: "value" }],active: true,public: true,+ assertions: [+ {+ type: "status",+ compare: "eq",+ target: 200,+ },+ { type: "header", compare: "not_eq", key: "key", target: "value" },+ ],};const res = await api.request("/monitor", {@@ -82,6 +91,44 @@ test("Create a monitor", async () => {});});+test("Create a monitor with Assertion ", async () => {+ const data = {+ periodicity: "10m",+ url: "https://www.openstatus.dev",+ name: "OpenStatus",+ description: "OpenStatus website",+ regions: ["ams", "gru", "iad"],+ method: "POST",+ body: '{"hello":"world"}',+ headers: [{ key: "key", value: "value" }],+ active: true,+ public: true,+ assertions: [+ {+ type: "status",+ compare: "eq",+ target: 200,+ },+ { type: "header", compare: "not_eq", key: "key", target: "value" },+ ],+ };+ const res = await api.request("/monitor", {+ method: "POST",+ headers: {+ "x-openstatus-key": "1",+ "content-type": "application/json",+ },+ body: JSON.stringify(data),+ });++ expect(res.status).toBe(200);++ expect(await res.json()).toMatchObject({+ id: expect.any(Number),+ ...data,+ });+});+test("Create a monitor without auth key should return 401", async () => {const data = {periodicity: "10m",diff --git a/apps/server/src/v1/monitors/post.ts b/apps/server/src/v1/monitors/post.tsindex 111913e4d..6b3482f93 100644--- a/apps/server/src/v1/monitors/post.ts+++ b/apps/server/src/v1/monitors/post.ts@@ -5,10 +5,13 @@ import { and, db, eq, isNull, sql } from "@openstatus/db";import { monitor } from "@openstatus/db/src/schema";import { HTTPException } from "hono/http-exception";+import { serialize } from "../../../../../packages/assertions/src";+import { env } from "../../env";import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";import type { monitorsApi } from "./index";import { MonitorSchema } from "./schema";+import { getAssertions } from "./utils";const postRoute = createRoute({method: "post",@@ -42,8 +45,8 @@ export function registerPostMonitor(api: typeof monitorsApi) {return api.openapi(postRoute, async (c) => {const workspaceId = c.get("workspaceId");const workspacePlan = c.get("workspacePlan");- const input = c.req.valid("json");+ const input = c.req.valid("json");const count = (await db.select({ count: sql<number>`count(*)` })@@ -67,7 +70,10 @@ export function registerPostMonitor(api: typeof monitorsApi) {throw new HTTPException(403, { message: "Forbidden" });}- const { headers, regions, ...rest } = input;+ const { headers, regions, assertions, ...rest } = input;++ const assert = assertions ? getAssertions(assertions) : [];+const _newMonitor = await db.insert(monitor).values({@@ -75,10 +81,10 @@ export function registerPostMonitor(api: typeof monitorsApi) {workspaceId: Number(workspaceId),regions: regions ? regions.join(",") : undefined,headers: input.headers ? JSON.stringify(input.headers) : undefined,+ assertions: assert.length > 0 ? serialize(assert) : undefined,}).returning().get();-if (env.JITSU_WRITE_KEY) {trackAnalytics({event: "Monitor Created",diff --git a/apps/server/src/v1/monitors/put.ts b/apps/server/src/v1/monitors/put.tsindex 0610a3029..14bed5676 100644--- a/apps/server/src/v1/monitors/put.ts+++ b/apps/server/src/v1/monitors/put.ts@@ -4,9 +4,11 @@ import { db, eq } from "@openstatus/db";import { monitor } from "@openstatus/db/src/schema";import { HTTPException } from "hono/http-exception";+import { serialize } from "../../../../../packages/assertions/src/serializing";import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";import type { monitorsApi } from "./index";import { MonitorSchema, ParamsSchema } from "./schema";+import { getAssertions } from "./utils";const putRoute = createRoute({method: "put",@@ -62,7 +64,9 @@ export function registerPutMonitor(api: typeof monitorsApi) {throw new HTTPException(401, { message: "Unauthorized" });}- const { headers, regions, ...rest } = input;+ const { headers, regions, assertions, ...rest } = input;++ const assert = assertions ? getAssertions(assertions) : [];const _newMonitor = await db.update(monitor)@@ -70,6 +74,7 @@ export function registerPutMonitor(api: typeof monitorsApi) {...rest,regions: regions ? regions.join(",") : undefined,headers: input.headers ? JSON.stringify(input.headers) : undefined,+ assertions: assert.length > 0 ? serialize(assert) : undefined,}).returning().get();diff --git a/apps/server/src/v1/monitors/schema.ts b/apps/server/src/v1/monitors/schema.tsindex e36394d00..6f74d4821 100644--- a/apps/server/src/v1/monitors/schema.ts+++ b/apps/server/src/v1/monitors/schema.ts@@ -6,6 +6,65 @@ import {monitorPeriodicitySchema,} from "@openstatus/db/src/schema";import { ZodError } from "zod";+import {+ numberCompare,+ stringCompare,+} from "../../../../../packages/assertions/src/v1";++const statusAssertion = z+ .object({+ type: z.literal("status"),+ compare: numberCompare.openapi({+ description: "The comparison to run",+ example: "eq",+ }),+ target: z+ .number()+ .int()+ .positive()+ .openapi({ description: "The target value" }),+ })+ .openapi({+ description: "The status assertion",+ });++const headerAssertion = z+ .object({+ type: z.literal("header"),+ compare: stringCompare,+ key: z.string().openapi({+ description: "The key of the header",+ }),+ target: z.string().openapi({+ description: "the header value",+ }),+ })+ .openapi({ description: "The header assertion" });++const textBodyAssertion = z+ .object({+ type: z.literal("textBody"),+ compare: stringCompare,+ target: z.string().openapi({+ description: "The target value",+ }),+ })+ .openapi({ description: "The text body assertion" });++// Not used yet+const _jsonBodyAssertion = z.object({+ type: z.literal("jsonBody"),+ path: z.string(), // https://www.npmjs.com/package/jsonpath-plus+ compare: stringCompare,+ target: z.string(),+});++export const assertion = z.discriminatedUnion("type", [+ statusAssertion,+ headerAssertion,+ textBodyAssertion,+ // jsonBodyAssertion,+]);export const ParamsSchema = z.object({id: z@@ -109,6 +168,29 @@ export const MonitorSchema = zdescription: "The headers of your request",example: [{ key: "x-apikey", value: "supersecrettoken" }],}),+ assertions: z+ .preprocess((val) => {+ try {+ if (Array.isArray(val)) return val;+ if (String(val).length > 0) {+ return JSON.parse(String(val));+ }+ return [];+ } catch (e) {+ throw new ZodError([+ {+ code: "custom",+ path: ["assertions"],+ message: e instanceof Error ? e.message : "Invalid value",+ },+ ]);+ }+ }, z.array(assertion))+ .nullish()+ .default([])+ .openapi({+ description: "The assertions to run",+ }),active: z.boolean().default(false)diff --git a/apps/server/src/v1/monitors/utils.ts b/apps/server/src/v1/monitors/utils.tsnew file mode 100644index 000000000..c49bba868--- /dev/null+++ b/apps/server/src/v1/monitors/utils.ts@@ -0,0 +1,27 @@+import type { z } from "zod";+import type { Assertion } from "../../../../../packages/assertions/src";+import {+ HeaderAssertion,+ StatusAssertion,+ TextBodyAssertion,+} from "../../../../../packages/assertions/src/v1";+import type { assertion } from "./schema";++export const getAssertions = (+ assertions: z.infer<typeof assertion>[],+): Assertion[] => {+ const assert: Assertion[] = [];++ for (const a of assertions) {+ if (a.type === "header") {+ assert.push(new HeaderAssertion({ ...a, version: "v1" }));+ }+ if (a.type === "textBody") {+ assert.push(new TextBodyAssertion({ ...a, version: "v1" }));+ }+ if (a.type === "status") {+ assert.push(new StatusAssertion({ ...a, version: "v1" }));+ }+ }+ return assert;+};diff --git a/packages/assertions/src/v1.ts b/packages/assertions/src/v1.tsindex 02a11d7c2..92a08850b 100644--- a/packages/assertions/src/v1.ts+++ b/packages/assertions/src/v1.ts@@ -161,7 +161,7 @@ function evaluateString(export const base = z.object({- version: z.enum(["v1"]),+ version: z.enum(["v1"]).default("v1"),type: z.string(),}).passthrough();diff --git a/packages/db/drizzle/0032_hot_swordsman.sql b/packages/db/drizzle/0032_hot_swordsman.sqlnew file mode 100644index 000000000..602fd2521--- /dev/null+++ b/packages/db/drizzle/0032_hot_swordsman.sql@@ -0,0 +1,12 @@+CREATE TABLE `check` (+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,+ `regions` text DEFAULT '' NOT NULL,+ `url` text(4096) NOT NULL,+ `headers` text DEFAULT '',+ `body` text DEFAULT '',+ `method` text DEFAULT 'GET',+ `count_requests` integer DEFAULT 1,+ `workspace_id` integer,+ `created_at` integer DEFAULT (strftime('%s', 'now')),+ FOREIGN KEY (`workspace_id`) REFERENCES `workspace`(`id`) ON UPDATE no action ON DELETE no action+);diff --git a/packages/db/drizzle/meta/0032_snapshot.json b/packages/db/drizzle/meta/0032_snapshot.jsonnew file mode 100644index 000000000..f090484ac--- /dev/null+++ b/packages/db/drizzle/meta/0032_snapshot.json@@ -0,0 +1,2217 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "de3d58e5-d801-4b9e-a35a-39cfc09b7807",+ "prevId": "afc5bf87-9bfd-4753-af9f-edbf7b3351ba",+ "tables": {+ "status_report_to_monitors": {+ "name": "status_report_to_monitors",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "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'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "status_report_to_monitors_monitor_id_monitor_id_fk": {+ "name": "status_report_to_monitors_monitor_id_monitor_id_fk",+ "tableFrom": "status_report_to_monitors",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "status_report_to_monitors_status_report_id_status_report_id_fk": {+ "name": "status_report_to_monitors_status_report_id_status_report_id_fk",+ "tableFrom": "status_report_to_monitors",+ "tableTo": "status_report",+ "columnsFrom": [+ "status_report_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "status_report_to_monitors_monitor_id_status_report_id_pk": {+ "columns": [+ "monitor_id",+ "status_report_id"+ ],+ "name": "status_report_to_monitors_monitor_id_status_report_id_pk"+ }+ },+ "uniqueConstraints": {}+ },+ "status_reports_to_pages": {+ "name": "status_reports_to_pages",+ "columns": {+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "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'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "status_reports_to_pages_page_id_page_id_fk": {+ "name": "status_reports_to_pages_page_id_page_id_fk",+ "tableFrom": "status_reports_to_pages",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "status_reports_to_pages_status_report_id_status_report_id_fk": {+ "name": "status_reports_to_pages_status_report_id_status_report_id_fk",+ "tableFrom": "status_reports_to_pages",+ "tableTo": "status_report",+ "columnsFrom": [+ "status_report_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "status_reports_to_pages_page_id_status_report_id_pk": {+ "columns": [+ "page_id",+ "status_report_id"+ ],+ "name": "status_reports_to_pages_page_id_status_report_id_pk"+ }+ },+ "uniqueConstraints": {}+ },+ "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+ },+ "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": {},+ "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"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "status_report_update": {+ "name": "status_report_update",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text(4)",+ "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": {},+ "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": {}+ },+ "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": {},+ "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": {}+ },+ "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+ },+ "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+ },+ "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+ }+ },+ "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": {}+ },+ "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": "'other'"+ },+ "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": "''"+ },+ "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+ },+ "assertions": {+ "name": "assertions",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "public": {+ "name": "public",+ "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'))"+ },+ "deleted_at": {+ "name": "deleted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "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": {}+ },+ "monitors_to_pages": {+ "name": "monitors_to_pages",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_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'))"+ },+ "order": {+ "name": "order",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 0+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitors_to_pages_monitor_id_monitor_id_fk": {+ "name": "monitors_to_pages_monitor_id_monitor_id_fk",+ "tableFrom": "monitors_to_pages",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "monitors_to_pages_page_id_page_id_fk": {+ "name": "monitors_to_pages_page_id_page_id_fk",+ "tableFrom": "monitors_to_pages",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "monitors_to_pages_monitor_id_page_id_pk": {+ "columns": [+ "monitor_id",+ "page_id"+ ],+ "name": "monitors_to_pages_monitor_id_page_id_pk"+ }+ },+ "uniqueConstraints": {}+ },+ "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": {}+ },+ "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": {}+ },+ "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'))"+ }+ },+ "indexes": {+ "user_tenant_id_unique": {+ "name": "user_tenant_id_unique",+ "columns": [+ "tenant_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "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": {},+ "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": {}+ },+ "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": {}+ },+ "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": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "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+ },+ "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": {},+ "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": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "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+ },+ "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": {}+ },+ "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": {},+ "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": {}+ },+ "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": {},+ "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": {}+ },+ "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": {}+ },+ "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": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "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_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": {}+ },+ "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": {},+ "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": {}+ },+ "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": {},+ "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": {}+ },+ "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+ }+ },+ "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": {}+ },+ "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": {},+ "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": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "maintenance_to_monitor": {+ "name": "maintenance_to_monitor",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "maintenance_id": {+ "name": "maintenance_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": {+ "maintenance_to_monitor_monitor_id_monitor_id_fk": {+ "name": "maintenance_to_monitor_monitor_id_monitor_id_fk",+ "tableFrom": "maintenance_to_monitor",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "maintenance_to_monitor_maintenance_id_maintenance_id_fk": {+ "name": "maintenance_to_monitor_maintenance_id_maintenance_id_fk",+ "tableFrom": "maintenance_to_monitor",+ "tableTo": "maintenance",+ "columnsFrom": [+ "maintenance_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "maintenance_to_monitor_monitor_id_maintenance_id_pk": {+ "columns": [+ "maintenance_id",+ "monitor_id"+ ],+ "name": "maintenance_to_monitor_monitor_id_maintenance_id_pk"+ }+ },+ "uniqueConstraints": {}+ },+ "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": {},+ "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": {}+ }+ },+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ }+}\ No newline at end of filediff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.jsonindex 08e6edede..38c93e0d7 100644--- a/packages/db/drizzle/meta/_journal.json+++ b/packages/db/drizzle/meta/_journal.json@@ -225,6 +225,13 @@"when": 1717837961923,"tag": "0031_lowly_gabe_jones","breakpoints": true+ },+ {+ "idx": 32,+ "version": "6",+ "when": 1718027484219,+ "tag": "0032_hot_swordsman",+ "breakpoints": true}]}\ No newline at end of filediff --git a/packages/db/src/schema/check/check.ts b/packages/db/src/schema/check/check.tsnew file mode 100644index 000000000..713418386--- /dev/null+++ b/packages/db/src/schema/check/check.ts@@ -0,0 +1,21 @@+import { sql } from "drizzle-orm";+import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";+import { monitorMethods } from "../monitors/constants";+import { workspace } from "../workspaces";++export const check = sqliteTable("check", {+ id: integer("id").primaryKey({ autoIncrement: true }),+ regions: text("regions").default("").notNull(),+ url: text("url", { length: 4096 }).notNull(),+ headers: text("headers").default(""),+ body: text("body").default(""),+ method: text("method", { enum: monitorMethods }).default("GET"),++ countRequests: integer("count_requests").default(1),++ workspaceId: integer("workspace_id").references(() => workspace.id),++ createdAt: integer("created_at", { mode: "timestamp" }).default(+ sql`(strftime('%s', 'now'))`,+ ),+});diff --git a/packages/db/src/schema/check/constants.ts b/packages/db/src/schema/check/constants.tsnew file mode 100644index 000000000..59d5ca2a6--- /dev/null+++ b/packages/db/src/schema/check/constants.ts@@ -0,0 +1,9 @@+export const flyCheckerRegions = [+ // TODO: Add more regions+ "ams",+ "iad",+ "hkg",+ "jnb",+ "syd",+ "gru",+] as const;diff --git a/packages/db/src/schema/check/index.ts b/packages/db/src/schema/check/index.tsnew file mode 100644index 000000000..d03eac78c--- /dev/null+++ b/packages/db/src/schema/check/index.ts@@ -0,0 +1,2 @@+export * from "./check";+export * from "./constants";diff --git a/packages/db/src/schema/index.ts b/packages/db/src/schema/index.tsindex 42801bff2..acb63d36f 100644--- a/packages/db/src/schema/index.ts+++ b/packages/db/src/schema/index.ts@@ -13,3 +13,4 @@ export * from "./incidents";export * from "./monitor_tags";export * from "./applications";export * from "./maintenances";+export * from "./check";diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 4b53016e1..1a86f89c1 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -144,13 +144,13 @@ importers:dependencies:'@hono/sentry':specifier: 1.1.0- version: 1.1.0([email protected])+ version: 1.1.0([email protected])'@hono/zod-openapi':- specifier: 0.13.0- version: 0.13.0([email protected])([email protected])+ specifier: 0.14.2+ version: 0.14.2([email protected])([email protected])'@hono/zod-validator':- specifier: 0.2.1- version: 0.2.1([email protected])([email protected])+ specifier: 0.2.2+ version: 0.2.2([email protected])([email protected])'@openstatus/analytics':specifier: workspace:^version: link:../../packages/analytics@@ -200,11 +200,14 @@ importers:specifier: 2.1.8version: 2.1.8hono:- specifier: 4.0.0- version: 4.0.0+ specifier: 4.4.5+ version: 4.4.5nanoid:specifier: 5.0.2version: 5.0.2+ percentile:+ specifier: ^1.6.0+ version: 1.6.0validator:specifier: 13.11.0version: 13.11.0@@ -2387,8 +2390,8 @@ packages:peerDependencies:hono: '>=3.*'- '@hono/[email protected]':- resolution: {integrity: sha512-viL2N3apZOwtsgaUBgWSLof0hOivRPPVy96gIp3FPbkXB5cfYUC4QrY2nB4EnYc4pAwsnIBYd9JW7QJFQ4DMdg==}+ '@hono/[email protected]':+ resolution: {integrity: sha512-nt4TCMwGebajiJ5QEZ2QOVRp3N7GMLs1P7csNQJSu6Aean4D+8TWgZTaAJSytLvVZWy90qnBbpRlVSS6C6M+0g==}engines: {node: '>=16.0.0'}peerDependencies:hono: '>=4.3.6'@@ -2400,6 +2403,12 @@ packages:hono: '>=3.9.0'zod: ^3.19.1+ '@hono/[email protected]':+ resolution: {integrity: sha512-dSDxaPV70Py8wuIU2QNpoVEIOSzSXZ/6/B/h4xA7eOMz7+AarKTSGV8E6QwrdcCbBLkpqfJ4Q2TmBO0eP1tCBQ==}+ peerDependencies:+ hono: '>=3.9.0'+ zod: ^3.19.1+'@hookform/[email protected]':resolution: {integrity: sha512-K7KCKRKjymxIB90nHDQ7b9nli474ru99ZbqxiqDAWYsYhOsU3/4qLxW91y+1n04ic13ajjZ66L3aXbNef8PELQ==}peerDependencies:@@ -5678,10 +5687,6 @@ packages:resolution: {integrity: sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==}- resolution: {integrity: sha512-8dKhuBBpRZEodUttQhrSFJ6PQqHRjXHyeeegfxOf132pvgbf0tOb9qqb7q7eYwAWpOcYrsUOsWdJ0sQIIovhZg==}- engines: {node: '>=16.0.0'}-resolution: {integrity: sha512-mDmjBHF6uBNN3TASdAbDCFsN9FLbrlgXyFZkhLEkU7hUgk0+T9hcsUrL/nho4qV+Xk0RDHx7gop4Q1gelZZVRw==}engines: {node: '>=16.0.0'}@@ -5690,6 +5695,10 @@ packages:resolution: {integrity: sha512-6c5LVE23HnIS8iBhY+XPmYJlPeeClznOi7mBNsAsJCgxo8Ciz75LTjqRUf5wv4RYq8kL+1KPLUZHCtKmbZssNg==}engines: {node: '>=16.0.0'}+ resolution: {integrity: sha512-hyf+1c+gTEo0+xjdYT2e8y4M3HcEy0ARuRZHPRgeRhq/mupkI4j9/qEWVKsyj0se4KhfRnYrld4Tk6z/9veq/Q==}+ engines: {node: '>=16.0.0'}+resolution: {integrity: sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==}@@ -6841,6 +6850,9 @@ packages:resolution: {integrity: sha512-XIxfHpEuSJbITd1H3EeQwpcZbTLHc+VVr8ANI9t5sit565tsI4/xK3KWTUFE2e6QiangUkh3B0jihzmGnNrRsQ==}+ resolution: {integrity: sha512-8vSyjdzwxGDHHwH+cSGch3A9Uj2On3UpgOWxWXMKwUvoAbnujx6DaqmV1duWXNiH/oEWpyVd6nSQccix6DM3Ng==}+resolution: {integrity: sha512-vKiQ8RRtkl9P+r/+oefh25C3fhybptkHKCZSPlcXiJux2tJF55GnEj3BVn4A5gKfq9NWWXXrxkHBwVPUfH0opw==}@@ -9659,26 +9671,26 @@ snapshots:dependencies:- '@hono/[email protected]([email protected])':+ '@hono/[email protected]([email protected])':dependencies:- hono: 4.0.0+ hono: 4.4.5toucan-js: 3.4.0dependencies:'@asteasolutions/zod-to-openapi': 7.0.0([email protected])- '@hono/zod-validator': 0.2.1([email protected])([email protected])- hono: 4.0.0+ '@hono/zod-validator': 0.2.2([email protected])([email protected])+ hono: 4.4.5zod: 3.22.4dependencies:- hono: 4.0.0+ hono: 4.2.2zod: 3.22.4dependencies:- hono: 4.2.2+ hono: 4.4.5zod: 3.22.4@@ -13606,12 +13618,12 @@ snapshots:dependencies:react-is: 16.13.1- [email protected]: {}-+ [email protected]: {}+@@ -15179,6 +15191,8 @@ snapshots:+ [email protected]: {}+dependencies:'@types/estree': 1.0.3