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
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
|
|
|
import { AccountPageEnum } from "../../../types/accountPageEnum"
|
|
import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
|
|
import { accordionSchema } from "../schemas/blocks/accordion"
|
|
import { dynamicContentSchema } from "../schemas/blocks/dynamicContent"
|
|
import { shortcutsSchema } from "../schemas/blocks/shortcuts"
|
|
import { textContentSchema } from "../schemas/blocks/textContent"
|
|
import { systemSchema } from "../schemas/system"
|
|
|
|
const accountPageAccordions = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.Accordion),
|
|
})
|
|
.merge(accordionSchema)
|
|
|
|
const accountPageDynamicContent = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.DynamicContent),
|
|
})
|
|
.merge(dynamicContentSchema)
|
|
|
|
const accountPageShortcuts = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.ShortCuts),
|
|
})
|
|
.merge(shortcutsSchema)
|
|
|
|
const accountPageTextContent = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.TextContent),
|
|
})
|
|
.merge(textContentSchema)
|
|
|
|
export const blocksSchema = z.discriminatedUnion("__typename", [
|
|
accountPageAccordions,
|
|
accountPageDynamicContent,
|
|
accountPageShortcuts,
|
|
accountPageTextContent,
|
|
])
|
|
|
|
export const accountPageSchema = z.object({
|
|
account_page: z.object({
|
|
content: discriminatedUnionArray(blocksSchema.options),
|
|
heading: z.string().nullable(),
|
|
preamble: z.string().nullable(),
|
|
hero_image: transformedImageVaultAssetSchema,
|
|
hero_image_active: z
|
|
.boolean()
|
|
.nullable()
|
|
.transform((val) => val ?? false),
|
|
title: z.string(),
|
|
url: z.string(),
|
|
system: systemSchema.merge(
|
|
z.object({
|
|
created_at: z.string(),
|
|
updated_at: z.string(),
|
|
})
|
|
),
|
|
}),
|
|
trackingProps: z.object({
|
|
url: z.string(),
|
|
}),
|
|
})
|