Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
🚀 Update incident and monitor endpoints (#443)
Thibault Le Ouay0a811248a740
diff --git a/apps/docs/api-reference/incident/post-incident:idupdate.mdx b/apps/docs/api-reference/incident/post-incident:idupdate.mdxindex 3e363a531..39a8c48d8 100644--- a/apps/docs/api-reference/incident/post-incident:idupdate.mdx+++ b/apps/docs/api-reference/incident/post-incident:idupdate.mdx@@ -1,4 +1,4 @@----title: Update Incident+title: Create Incident Updateopenapi: post /incident/:id/update---diff --git a/apps/server/src/v1/incidentUpdate.ts b/apps/server/src/v1/incidentUpdate.tsindex bc7a69197..5b5b3f972 100644--- a/apps/server/src/v1/incidentUpdate.ts+++ b/apps/server/src/v1/incidentUpdate.ts@@ -54,7 +54,7 @@ const getUpdateRoute = createRoute({200: {content: {"application/json": {- schema: z.object({}),+ schema: incidentUpdateSchema,},},description: "Get all incidents",diff --git a/apps/server/src/v1/monitor.test.ts b/apps/server/src/v1/monitor.test.tsindex bceb89b56..5f91fd273 100644--- a/apps/server/src/v1/monitor.test.ts+++ b/apps/server/src/v1/monitor.test.ts@@ -14,7 +14,7 @@ test("GET one monitor", async () => {id: 1,periodicity: "1m",url: "https://www.openstatus.dev",- regions: "ams",+ regions: ["ams"],name: "OpenStatus",description: "OpenStatus website",method: "POST",@@ -31,31 +31,41 @@ test("GET all monitor", async () => {},});expect(res.status).toBe(200);+});- expect(await res.json()).toMatchObject([- {- id: 1,- periodicity: "1m",- url: "https://www.openstatus.dev",- regions: "ams",- name: "OpenStatus",- description: "OpenStatus website",- method: "POST",- body: '{"hello":"world"}',- headers: [{ key: "key", value: "value" }],- active: true,- },- {- active: false,- body: "",- description: "",- headers: [],- id: 2,- method: "GET",- name: "",- periodicity: "10m",- regions: "gru",- url: "https://www.google.com",+test("Create a monitor", async () => {+ const data = {+ periodicity: "10m",+ url: "https://www.openstatus.dev",+ name: "OpenStatus",+ description: "OpenStatus website",+ regions: ["ams", "gru"],+ method: "POST",+ body: '{"hello":"world"}',+ headers: [{ key: "key", value: "value" }],+ active: true,+ };+ const res = await api.request("/monitor", {+ method: "POST",+ headers: {+ "x-openstatus-key": "1",+ "content-type": "application/json",},- ]);+ body: JSON.stringify(data),+ });+ // console.log(await res.text());+ expect(res.status).toBe(200);++ expect(await res.json()).toMatchObject({+ id: expect.any(Number),+ periodicity: "10m",+ url: "https://www.openstatus.dev",+ regions: ["ams", "gru"],+ name: "OpenStatus",+ description: "OpenStatus website",+ method: "POST",+ body: '{"hello":"world"}',+ headers: [{ key: "key", value: "value" }],+ active: true,+ });});diff --git a/apps/server/src/v1/monitor.ts b/apps/server/src/v1/monitor.tsindex 01bb5877e..59757e2db 100644--- a/apps/server/src/v1/monitor.ts+++ b/apps/server/src/v1/monitor.ts@@ -26,10 +26,8 @@ const ParamsSchema = z.object({});export const periodicityEnum = z.enum(monitorPeriodicity);-export const regionEnum = z- .enum(flyRegions)- .or(z.literal(""))- .transform((val) => (val === "" ? "" : val));++const regionInput = z.array(z.enum(flyRegions)).transform((val) => String(val));const MonitorSchema = z.object({@@ -45,10 +43,22 @@ const MonitorSchema = zexample: "https://www.documenso.co",description: "The url to monitor",}),- regions: regionEnum.openapi({- example: "ams",- description: "The regions to use",- }),+ regions: z+ .preprocess(+ (val) => {+ if (String(val).length > 0) {+ return String(val).split(",");+ } else {+ return [];+ }+ },+ z.array(z.enum(flyRegions)),+ )+ .default([])+ .openapi({+ example: ["ams"],+ description: "The regions to use",+ }),name: z.string().openapi({@@ -108,7 +118,7 @@ const monitorInput = zexample: "https://www.documenso.co",description: "The url to monitor",}),- regions: regionEnum.openapi({+ regions: regionInput.openapi({example: "ams",description: "The regions to use",}),@@ -240,7 +250,6 @@ monitorApi.openapi(getRoute, async (c) => {const { id } = c.req.valid("param");const monitorId = Number(id);- console.log({ monitorId, workspaceId });const _monitor = await db.select().from(monitor)@@ -303,7 +312,6 @@ const postRoute = createRoute({monitorApi.openapi(postRoute, async (c) => {const workspaceId = Number(c.get("workspaceId"));const workspacePlan = c.get("workspacePlan");- console.log({ workspaceId });const input = c.req.valid("json");const count = (@@ -312,7 +320,6 @@ monitorApi.openapi(postRoute, async (c) => {if (count >= workspacePlan.limits.monitors)return c.jsonT({ code: 403, message: "Forbidden" });-if (!workspacePlan.limits.periodicity.includes(input.periodicity))return c.jsonT({ code: 403, message: "Forbidden" });diff --git a/packages/api/src/router/workspace.test.ts b/packages/api/src/router/workspace.test.tsindex 0163692da..3b9cf04db 100644--- a/packages/api/src/router/workspace.test.ts+++ b/packages/api/src/router/workspace.test.ts@@ -24,9 +24,9 @@ test("Get Test Workspace", async () => {id: 1,slug: "test",name: "test",- plan: "free",+ plan: "pro",paidUntil: null,- stripeId: "stripeId",+ stripeId: "stripeId1",subscriptionId: "subscriptionId",updatedAt: expect.any(Date),createdAt: expect.any(Date),@@ -52,9 +52,9 @@ test("by default we get the first workspace", async () => {id: 1,slug: "test",name: "test",- plan: "free",+ plan: "pro",paidUntil: null,- stripeId: "stripeId",+ stripeId: "stripeId1",subscriptionId: "subscriptionId",updatedAt: expect.any(Date),createdAt: expect.any(Date),@@ -93,9 +93,9 @@ test("All workspaces", async () => {id: 1,name: "test",paidUntil: null,- plan: "free",+ plan: "pro",slug: "test",- stripeId: "stripeId",+ stripeId: "stripeId1",subscriptionId: "subscriptionId",updatedAt: expect.any(Date),},diff --git a/packages/db/src/seed.mts b/packages/db/src/seed.mtsindex 8addb7101..b2c861a75 100644--- a/packages/db/src/seed.mts+++ b/packages/db/src/seed.mts@@ -22,16 +22,28 @@ async function main() {console.log("Seeding database ");await db.insert(workspace)- .values({- id: 1,- slug: "test",- stripeId: "stripeId",- name: "test",- subscriptionId: "subscriptionId",- plan: "free",- endsAt: null,- paidUntil: null,- })+ .values([+ {+ id: 1,+ slug: "test",+ stripeId: "stripeId1",+ name: "test",+ subscriptionId: "subscriptionId",+ plan: "pro",+ endsAt: null,+ paidUntil: null,+ },+ {+ id: 2,+ slug: "test2",+ stripeId: "stripeId2",+ name: "test2",+ subscriptionId: "subscriptionId2",+ plan: "free",+ endsAt: null,+ paidUntil: null,+ },+ ]).run();await db.insert(monitor)