Skip to content

Open-source status page, incident response and uptime monitoring

fix: update notification schema (#1617)

Maximilian Kaske22b58ab1b415
diff --git a/apps/dashboard/src/components/data-table/notifications/data-table-row-actions.tsx b/apps/dashboard/src/components/data-table/notifications/data-table-row-actions.tsx
index 9f091cb17..2d61a4c73 100644
--- a/apps/dashboard/src/components/data-table/notifications/data-table-row-actions.tsx
+++ b/apps/dashboard/src/components/data-table/notifications/data-table-row-actions.tsx
@@ -70,10 +70,7 @@ export function DataTableRowActions(props: DataTableRowActionsProps) {
await updateNotifierMutation.mutateAsync({
id: props.row.original.id,
name: values.name,
- data:
- typeof values.data === "string"
- ? { [values.provider]: values.data }
- : values.data,
+ data: { [values.provider]: values.data },
monitors: values.monitors,
});
}}
diff --git a/packages/api/src/router/notification.ts b/packages/api/src/router/notification.ts
index 9c09b57e7..bdc2d55d1 100644
--- a/packages/api/src/router/notification.ts
+++ b/packages/api/src/router/notification.ts
@@ -275,7 +275,7 @@ export const notificationRouter = createTRPCRouter({
id: z.number(),
name: z.string(),
data: z.record(
- z.string(),
+ z.enum(notificationProvider),
z.string().or(z.record(z.string(), z.string())),
),
monitors: z.array(z.number()),
@@ -301,6 +301,15 @@ export const notificationRouter = createTRPCRouter({
});
}
+ const _data = NotificationDataSchema.safeParse(opts.input.data);
+
+ if (!_data.success) {
+ throw new TRPCError({
+ code: "BAD_REQUEST",
+ message: SchemaError.fromZod(_data.error, opts.input).message,
+ });
+ }
+
db.transaction(async (tx) => {
await tx
.update(notification)