alert_words: Validate parameters with Zod.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-06-21 11:34:42 -07:00 committed by Anders Kaseorg
parent 1ee5c46a20
commit 788552b916
2 changed files with 3 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import _ from "lodash";
import type {Message} from "./message_store";
import * as people from "./people";
import type {StateData} from "./state_data";
// For simplicity, we use a list for our internal
// data, since that matches what the server sends us.
@ -91,6 +92,6 @@ export function notifies(message: Message): boolean {
return !people.is_current_user(message.sender_email) && message.alerted;
}
export const initialize = (params: {alert_words: string[]}): void => {
export const initialize = (params: StateData["alert_words"]): void => {
set_words(params.alert_words);
};

View File

@ -333,7 +333,7 @@ const realm_schema = z.object({
});
export const state_data_schema = z
.object({alert_words: NOT_TYPED_YET})
.object({alert_words: z.array(z.string())})
.transform((alert_words) => ({alert_words}))
.and(z.object({realm_emoji: realm_emoji_map_schema}).transform((emoji) => ({emoji})))
.and(z.object({realm_bots: NOT_TYPED_YET}).transform((bot) => ({bot})))