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
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { scriptedCardThemeEnum } from "../../../../enums/scriptedCard"
|
|
import { SidebarEnums } from "../../../../types/sidebar"
|
|
import {
|
|
getInfoCardThemeFromDeprecatedCardTheme,
|
|
infoCardBlockSchema,
|
|
transformInfoCardBlock,
|
|
} from "../blocks/cardsGrid"
|
|
|
|
export const scriptedCardsSchema = z.object({
|
|
typename: z
|
|
.literal(SidebarEnums.blocks.InfoCard)
|
|
.optional()
|
|
.default(SidebarEnums.blocks.InfoCard),
|
|
scripted_card: z
|
|
.object({
|
|
theme: z
|
|
.nativeEnum(scriptedCardThemeEnum)
|
|
.nullable()
|
|
.transform(getInfoCardThemeFromDeprecatedCardTheme),
|
|
scripted_cardConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: infoCardBlockSchema,
|
|
})
|
|
),
|
|
}),
|
|
})
|
|
.nullish()
|
|
.transform((data) => {
|
|
if (!data?.scripted_cardConnection?.edges.length) {
|
|
return null
|
|
}
|
|
|
|
return {
|
|
theme: data.theme,
|
|
...transformInfoCardBlock(data.scripted_cardConnection.edges[0].node),
|
|
}
|
|
}),
|
|
})
|