From 70a2f2d7138da73aab39d49e945806dd691d368c Mon Sep 17 00:00:00 2001 From: soup Date: Sun, 19 Nov 2023 21:32:09 +0100 Subject: [PATCH] fix(filters): validate external filters (#1250) * fix(filters): Set webhook method default to POST * fix: details.tsx * feat(filters): validate external filters --------- Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com> --- web/src/screens/filters/Details.tsx | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/web/src/screens/filters/Details.tsx b/web/src/screens/filters/Details.tsx index 3c5e70e..4d066f2 100644 --- a/web/src/screens/filters/Details.tsx +++ b/web/src/screens/filters/Details.tsx @@ -223,6 +223,48 @@ const externalFilterSchema = z.object({ webhook_retry_status: z.string().optional(), webhook_retry_attempts: z.number().optional(), webhook_retry_delay_seconds: z.number().optional(), +}).superRefine((value, ctx) => { + if (!value.name) { + ctx.addIssue({ + message: "Must have a name", + code: z.ZodIssueCode.custom, + path: ["name"] + }); + } + + if (value.type == "WEBHOOK") { + if (!value.webhook_method) { + ctx.addIssue({ + message: "Must select method", + code: z.ZodIssueCode.custom, + path: ["webhook_method"] + }); + } + if (!value.webhook_host) { + ctx.addIssue({ + message: "Must have webhook host", + code: z.ZodIssueCode.custom, + path: ["webhook_host"] + }); + } + if (!value.webhook_expect_status) { + ctx.addIssue({ + message: "Must have webhook expect status", + code: z.ZodIssueCode.custom, + path: ["webhook_expect_status"] + }); + } + } + + if (value.type == "EXEC") { + if (!value.exec_cmd) { + ctx.addIssue({ + message: "Must have exec cmd", + code: z.ZodIssueCode.custom, + path: ["exec_cmd"] + }); + } + } }); const indexerSchema = z.object({