Files
web/packages/trpc/lib/routers/contentstack/base/utils.ts
Linus Flood 5fc93472f4 Merged in feat/rework-contentstack (pull request #3493)
Feat(SW-3708): refactor contentstack fetching (removing all refs) and cache invalidation

* Remove all REFS

* Revalidate correct language

* PR fixes

* PR fixes

* Throw when errors from contentstack api


Approved-by: Joakim Jäderberg
2026-01-27 12:38:36 +00:00

39 lines
1012 B
TypeScript

import * as Sentry from "@sentry/nextjs"
import { z } from "zod"
import { logger } from "@scandic-hotels/common/logger"
import { getValueFromContactConfig } from "../../../utils/contactConfig"
import type { AlertOutput } from "../../../types/siteConfig"
import type { ContactConfig } from "./output"
export function getAlertPhoneContactData(
alert: AlertOutput,
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 = <T extends z.ZodTypeAny>(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)