Files
web/server/routers/contentstack/destinationCityPage/output.ts
T
Erik Tiekstra bf76c6277f Merged in feat/support-for-all-page-links (pull request #1212)
Feat/support for all page links

* feat: added all page link connections to queries

* feat: updated output files


Approved-by: Fredrik Thorsson
Approved-by: Matilda Landström
2025-01-27 11:21:37 +00:00

171 lines
4.9 KiB
TypeScript

import { z } from "zod"
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
import {
destinationCountryPageRefSchema,
linkRefsUnionSchema,
linkUnionSchema,
transformPageLink,
} from "../schemas/pageLinks"
import { systemSchema } from "../schemas/system"
import type { ImageVaultAsset } from "@/types/components/imageVault"
import {
TrackingChannelEnum,
type TrackingSDKPageData,
} from "@/types/components/tracking"
import { Country } from "@/types/enums/country"
export const destinationCityPageSchema = z
.object({
destination_city_page: z.object({
title: z.string(),
destination_settings: z
.object({
countryConnection: z
.object({
edges: z.array(
z.object({
node: z.object({
destination_settings: z.object({
country: z.nativeEnum(Country),
}),
}),
})
),
})
.transform(
(countryConnection) =>
countryConnection.edges[0].node.destination_settings.country
),
city_denmark: z.string().optional().nullable(),
city_finland: z.string().optional().nullable(),
city_germany: z.string().optional().nullable(),
city_poland: z.string().optional().nullable(),
city_norway: z.string().optional().nullable(),
city_sweden: z.string().optional().nullable(),
})
.transform(
({
countryConnection: country,
city_denmark,
city_finland,
city_germany,
city_norway,
city_poland,
city_sweden,
}) => {
switch (country) {
case Country.Denmark:
return { country, city: city_denmark }
case Country.Finland:
return { country, city: city_finland }
case Country.Germany:
return { country, city: city_germany }
case Country.Poland:
return { country, city: city_poland }
case Country.Norway:
return { country, city: city_norway }
case Country.Sweden:
return { country, city: city_sweden }
default:
throw new Error(`Invalid country: ${country}`)
}
}
),
heading: z.string(),
preamble: z.string(),
experiences: z
.object({
destination_experiences: z.array(z.string()),
})
.transform(({ destination_experiences }) => destination_experiences),
images: z
.array(z.object({ image: tempImageVaultAssetSchema }))
.transform((images) =>
images
.map((image) => image.image)
.filter((image): image is ImageVaultAsset => !!image)
),
has_sidepeek: z.boolean().default(false),
sidepeek_button_text: z.string().default(""),
sidepeek_content: z.object({
heading: z.string(),
content: z.object({
json: z.any(),
embedded_itemsConnection: z.object({
edges: z.array(
z.object({
node: linkUnionSchema.transform((data) => {
const link = transformPageLink(data)
if (link) {
return link
}
return data
}),
})
),
}),
}),
}),
system: systemSchema.merge(
z.object({
created_at: z.string(),
updated_at: z.string(),
})
),
}),
trackingProps: z.object({
url: z.string(),
}),
})
.transform((data) => {
const destinationCityPage = data.destination_city_page
const system = destinationCityPage.system
const trackingUrl = data.trackingProps.url
const tracking: TrackingSDKPageData = {
pageId: system.uid,
domainLanguage: system.locale,
publishDate: system.updated_at,
createDate: system.created_at,
channel: TrackingChannelEnum["destination-page"],
pageType: "staticcontentpage",
pageName: trackingUrl,
siteSections: trackingUrl,
siteVersion: "new-web",
}
return {
destinationCityPage,
tracking,
}
})
/** REFS */
export const destinationCityPageRefsSchema = z.object({
destination_city_page: z.object({
destination_settings: z.object({
countryConnection: z.object({
edges: z.array(
z.object({
node: destinationCountryPageRefSchema,
})
),
}),
}),
sidepeek_content: z.object({
content: z.object({
embedded_itemsConnection: z.object({
edges: z.array(
z.object({
node: linkRefsUnionSchema,
})
),
}),
}),
}),
system: systemSchema,
}),
})