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
43 lines
864 B
TypeScript
43 lines
864 B
TypeScript
import { z } from "zod"
|
|
|
|
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
|
|
|
|
import { linkUnionSchema, transformPageLink } from "./pageLinks"
|
|
|
|
const titleSchema = z.object({
|
|
title: nullableStringValidator,
|
|
})
|
|
|
|
export const linkConnectionSchema = z
|
|
.object({
|
|
linkConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: linkUnionSchema,
|
|
})
|
|
),
|
|
}),
|
|
})
|
|
.transform((data) => {
|
|
if (data.linkConnection.edges.length) {
|
|
const linkNode = data.linkConnection.edges[0].node
|
|
if (linkNode) {
|
|
const link = transformPageLink(linkNode)
|
|
if (link) {
|
|
return {
|
|
link,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
link: null,
|
|
}
|
|
})
|
|
|
|
export const linkAndTitleSchema = z.intersection(
|
|
linkConnectionSchema,
|
|
titleSchema
|
|
)
|