Skip to content

Open-source status page, incident response and uptime monitoring

Revert "fix: api depreacted regions monitor schema (#1442)" (#1444)

Maximilian Kaske2c6d7d73c2c5
diff --git a/apps/server/src/routes/v1/monitors/post.test.ts b/apps/server/src/routes/v1/monitors/post.test.ts
index f3aefcf44..3bf77cb54 100644
--- a/apps/server/src/routes/v1/monitors/post.test.ts
+++ b/apps/server/src/routes/v1/monitors/post.test.ts
@@ -1,7 +1,6 @@
import { expect, test } from "bun:test";
import { app } from "@/index";
-import { createErrorSchema } from "@/libs/errors";
import { MonitorSchema } from "./schema";
test("create a valid monitor", async () => {
@@ -92,30 +91,3 @@ test("no auth key should return 401", async () => {
expect(res.status).toBe(401);
});
-
-test("create a monitor with deprecated regions should return 400", async () => {
- const res = await app.request("/v1/monitor", {
- method: "POST",
- headers: {
- "x-openstatus-key": "1",
- "content-type": "application/json",
- },
- body: JSON.stringify({
- regions: ["ams", "jnb", "hkg", "waw"],
- name: "Testing Deprecated Regions",
- description: "Testing Deprecated Regions",
- url: "https://www.openstatus.dev",
- method: "GET",
- active: true,
- }),
- });
-
- const json = await res.json();
- const errorSchema = createErrorSchema("BAD_REQUEST").safeParse(json);
-
- expect(res.status).toBe(400);
- expect(errorSchema.success).toBe(true);
- expect(errorSchema.data?.message).toMatch(
- "Deprecated regions are not allowed: hkg, waw",
- );
-});
diff --git a/apps/server/src/routes/v1/monitors/schema.ts b/apps/server/src/routes/v1/monitors/schema.ts
index 0e2098fd8..d528cad55 100644
--- a/apps/server/src/routes/v1/monitors/schema.ts
+++ b/apps/server/src/routes/v1/monitors/schema.ts
@@ -6,7 +6,6 @@ import {
monitorPeriodicitySchema,
monitorRegions,
} from "@openstatus/db/src/schema/constants";
-import { regionDict } from "@openstatus/utils";
import { ZodError } from "zod";
const statusAssertion = z
@@ -95,34 +94,21 @@ export const MonitorSchema = z
regions: z
.preprocess(
(val) => {
- let regions: Array<unknown> = [];
- if (Array.isArray(val)) {
- regions = val;
- }
- if (String(val).length > 0) {
- regions = String(val).split(",");
- }
-
- const deprecatedRegions = regions.filter((r) => {
- const deprecated =
- regionDict[r as keyof typeof regionDict].deprecated;
- if (deprecated) return true;
- return false;
- });
-
- if (deprecatedRegions.length > 0) {
+ try {
+ if (Array.isArray(val)) return val;
+ if (String(val).length > 0) {
+ return String(val).split(",");
+ }
+ return [];
+ } catch (e) {
throw new ZodError([
{
code: "custom",
- path: ["regions"],
- message: `Deprecated regions are not allowed: ${deprecatedRegions.join(
- ", ",
- )}`,
+ path: ["headers"],
+ message: e instanceof Error ? e.message : "Invalid value",
},
]);
}
-
- return regions;
},
z.array(z.enum(monitorRegions)),
)
@@ -357,45 +343,9 @@ const baseRequest = z.object({
description: "Whether the monitor is public",
default: false,
}),
- regions: z
- .preprocess(
- (val) => {
- let regions: Array<unknown> = [];
- if (Array.isArray(val)) {
- regions = val;
- }
- if (String(val).length > 0) {
- regions = String(val).split(",");
- }
-
- const deprecatedRegions = regions.filter((r) => {
- const deprecated =
- regionDict[r as keyof typeof regionDict].deprecated;
- if (deprecated) return true;
- return false;
- });
-
- if (deprecatedRegions.length > 0) {
- throw new ZodError([
- {
- code: "custom",
- path: ["regions"],
- message: `Deprecated regions are not allowed: ${deprecatedRegions.join(
- ", ",
- )}`,
- },
- ]);
- }
-
- return regions;
- },
- z.array(z.enum(monitorRegions)),
- )
- .default([])
- .openapi({
- example: ["ams"],
- description: "Where we should monitor it",
- }),
+ regions: z.array(z.enum(monitorRegions)).openapi({
+ description: "Regions to run the request in",
+ }),
openTelemetry: z
.object({
endpoint: z