import * as Sentry from "@sentry/nextjs" import { z } from "zod" import { logger } from "@scandic-hotels/common/logger" import { getValueFromContactConfig } from "../../../utils/contactConfig" import type { Alert } from "../schemas/alert" import type { ContactConfig } from "./output" export function getAlertPhoneContactData( alert: Alert, contactConfig: ContactConfig ) { if (alert.phoneContact) { const { displayText, phoneNumber, footnote } = alert.phoneContact return { displayText, phoneNumber: getValueFromContactConfig(phoneNumber, contactConfig), footnote: footnote ? getValueFromContactConfig(footnote, contactConfig) : null, } } return null } export const safeUnion = (schema: T) => z.preprocess((val) => { try { return schema.parse(val) } catch (err) { Sentry.captureException(err) logger.warn("Invalid node in safeUnion", err) return null } }, schema)