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
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { BlocksEnums } from "../../../../types/blocksEnum"
|
|
import { UspGridEnum } from "../../../../types/uspGrid"
|
|
import { linkUnionSchema, transformPageLink } from "../pageLinks"
|
|
|
|
const uspCardSchema = z.object({
|
|
icon: UspGridEnum.uspIcons,
|
|
text: z.object({
|
|
json: z.any(), // JSON
|
|
embedded_itemsConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: linkUnionSchema.transform((data) => {
|
|
const link = transformPageLink(data)
|
|
if (link) {
|
|
return link
|
|
}
|
|
return data
|
|
}),
|
|
})
|
|
),
|
|
}),
|
|
}),
|
|
})
|
|
|
|
export const uspGridSchema = z.object({
|
|
typename: z
|
|
.literal(BlocksEnums.block.UspGrid)
|
|
.optional()
|
|
.default(BlocksEnums.block.UspGrid),
|
|
usp_grid: z
|
|
.object({
|
|
cardsConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: z.object({
|
|
usp_card: z.array(uspCardSchema),
|
|
}),
|
|
})
|
|
),
|
|
}),
|
|
})
|
|
.transform((data) => {
|
|
return {
|
|
usp_card: data.cardsConnection.edges.flatMap(
|
|
(edge) => edge.node.usp_card
|
|
),
|
|
}
|
|
}),
|
|
})
|