Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
🚀 text body assertions (#895)
Thibault Le Ouayfe20e7c36caa
diff --git a/apps/web/src/components/forms/monitor/section-assertions.tsx b/apps/web/src/components/forms/monitor/section-assertions.tsxindex 5c3b7cc51..ede512b18 100644--- a/apps/web/src/components/forms/monitor/section-assertions.tsx+++ b/apps/web/src/components/forms/monitor/section-assertions.tsx@@ -7,6 +7,7 @@ import type { UseFormReturn } from "react-hook-form";import {numberCompareDictionary,stringCompareDictionary,+ textBodyAssertion,} from "@openstatus/assertions";import type { InsertMonitor } from "@openstatus/db/src/schema";import {@@ -45,6 +46,11 @@ export function SectionAssertions({ form }: Props) {control: form.control,name: "headerAssertions",});+ const textBodyAssertions = useFieldArray({+ control: form.control,+ name: "textBodyAssertions",+ });+return (<div className="grid w-full gap-4"><SectionHeader@@ -90,7 +96,7 @@ export function SectionAssertions({ form }: Props) {<SelectItem key={key} value={key}>{value}</SelectItem>- ),+ ))}</SelectContent></Select>@@ -151,7 +157,7 @@ export function SectionAssertions({ form }: Props) {<SelectItem key={key} value={key}>{value}</SelectItem>- ),+ ))}</SelectContent></Select>@@ -174,6 +180,57 @@ export function SectionAssertions({ form }: Props) {</div></div>))}+ {textBodyAssertions.fields.map((f, i) => (+ <div key={f.id} className="grid grid-cols-12 items-center gap-4">+ <p className="col-span-2 text-muted-foreground text-sm">Body</p>+ <div className="col-span-3" />+ <FormField+ control={form.control}+ name={`statusAssertions.${i}.compare`}+ render={({ field }) => (+ <FormItem className="col-span-3 w-full">+ <Select+ onValueChange={field.onChange}+ defaultValue={field.value}+ >+ <FormControl>+ <SelectTrigger>+ <SelectValue defaultValue="eq" placeholder="Equal" />+ </SelectTrigger>+ </FormControl>+ <SelectContent>+ {Object.entries(stringCompareDictionary).map(+ ([key, value]) => (+ <SelectItem key={key} value={key}>+ {value}+ </SelectItem>+ )+ )}+ </SelectContent>+ </Select>+ </FormItem>+ )}+ />+ <Input+ {...form.register(`textBodyAssertions.${i}.target`, {+ required: true,+ })}+ type="number"+ placeholder="<html>...</html>"+ className="col-span-3"+ />+ <div className="col-span-1">+ <Button+ size="icon"+ onClick={() => textBodyAssertions.remove(i)}+ variant="ghost"+ type="button"+ >+ <Icons.trash className="h-4 w-4" />+ </Button>+ </div>+ </div>+ ))}<div className="flex gap-4"><Buttonvariant="outline"@@ -204,6 +261,21 @@ export function SectionAssertions({ form }: Props) {>Add Header Assertion</Button>++ <Button+ variant="outline"+ type="button"+ onClick={() =>+ textBodyAssertions.append({+ version: "v1",+ type: "textBody",+ compare: "eq",+ target: "",+ })+ }+ >+ Add String Body Assertion+ </Button></div></div></div>diff --git a/packages/db/src/schema/monitors/validation.ts b/packages/db/src/schema/monitors/validation.tsindex 30b9edba8..a03a166d9 100644--- a/packages/db/src/schema/monitors/validation.ts+++ b/packages/db/src/schema/monitors/validation.ts@@ -35,19 +35,16 @@ const bodyToStringSchema = z.preprocess((val) => {return String(val);}, z.string());-const headersToArraySchema = z.preprocess(- (val) => {- // early return in case the header is already an array- if (Array.isArray(val)) {- return val;- }- if (String(val).length > 0) {- return JSON.parse(String(val));- }- return [];- },- z.array(z.object({ key: z.string(), value: z.string() })).default([]),-);+const headersToArraySchema = z.preprocess((val) => {+ // early return in case the header is already an array+ if (Array.isArray(val)) {+ return val;+ }+ if (String(val).length > 0) {+ return JSON.parse(String(val));+ }+ return [];+}, z.array(z.object({ key: z.string(), value: z.string() })).default([]));export const selectMonitorSchema = createSelectSchema(monitor, {periodicity: monitorPeriodicitySchema.default("10m"),@@ -78,6 +75,7 @@ export const insertMonitorSchema = createInsertSchema(monitor, {tags: z.array(z.number()).optional().default([]),statusAssertions: z.array(assertions.statusAssertion).optional(),headerAssertions: z.array(assertions.headerAssertion).optional(),+ textBodyAssertions: z.array(assertions.textBodyAssertion).optional(),});export const selectMonitorToPageSchema = createSelectSchema(monitorsToPages);