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
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { SidebarEnums } from "../../../../types/sidebar"
|
|
import { imageContainerSchema } from "../blocks/imageContainer"
|
|
import { sysAssetSchema } from "../blocks/sysAsset"
|
|
import { rawLinkUnionSchema, transformPageLink } from "../pageLinks"
|
|
|
|
export const contentSchema = z.object({
|
|
typename: z
|
|
.literal(SidebarEnums.blocks.Content)
|
|
.optional()
|
|
.default(SidebarEnums.blocks.Content),
|
|
content: z
|
|
.object({
|
|
content: z.object({
|
|
json: z.any(), // JSON
|
|
embedded_itemsConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: z
|
|
.discriminatedUnion("__typename", [
|
|
imageContainerSchema,
|
|
sysAssetSchema,
|
|
...rawLinkUnionSchema.options,
|
|
])
|
|
.transform((data) => {
|
|
const link = transformPageLink(data)
|
|
if (link) {
|
|
return link
|
|
}
|
|
return data
|
|
}),
|
|
})
|
|
),
|
|
}),
|
|
}),
|
|
})
|
|
.transform((data) => {
|
|
return {
|
|
embedded_itemsConnection: data.content.embedded_itemsConnection,
|
|
json: data.content.json,
|
|
}
|
|
}),
|
|
})
|