Merged in feat/rework-contentstack (pull request #3493)
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
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import {
|
||||
linkRefsUnionSchema,
|
||||
linkUnionSchema,
|
||||
transformPageLink,
|
||||
} from "../pageLinks"
|
||||
import { linkUnionSchema, transformPageLink } from "../pageLinks"
|
||||
import { sysAssetSchema } from "./sysAsset"
|
||||
|
||||
export const embeddedContentSchema = z.union([linkUnionSchema, sysAssetSchema])
|
||||
@@ -117,95 +113,3 @@ export const accordionSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const globalAccordionConnectionRefs = z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
questions: z.array(
|
||||
z.object({
|
||||
answer: z.object({
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: linkRefsUnionSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export const specificAccordionConnectionRefs = z.object({
|
||||
questions: z.array(
|
||||
z.object({
|
||||
answer: z.object({
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: linkRefsUnionSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export const accordionRefsSchema = z.object({
|
||||
accordion: z
|
||||
.object({
|
||||
accordions: z.array(
|
||||
z.object({
|
||||
__typename: z.nativeEnum(AccordionEnum),
|
||||
global_accordion: z
|
||||
.object({
|
||||
global_accordionConnection: globalAccordionConnectionRefs,
|
||||
})
|
||||
.optional(),
|
||||
specific_accordion: specificAccordionConnectionRefs.optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.accordions.flatMap((accordion) => {
|
||||
switch (accordion.__typename) {
|
||||
case AccordionEnum.CampaignPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.ContentPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.DestinationCityPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.DestinationCountryPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.DestinationFilterBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.PromoCampaignPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
return (
|
||||
accordion.global_accordion?.global_accordionConnection.edges.flatMap(
|
||||
({ node: accordionConnection }) => {
|
||||
return accordionConnection.questions.flatMap((question) =>
|
||||
question.answer.embedded_itemsConnection.edges.flatMap(
|
||||
({ node }) => node.system
|
||||
)
|
||||
)
|
||||
}
|
||||
) || []
|
||||
)
|
||||
case AccordionEnum.CampaignPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
case AccordionEnum.DestinationCityPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
case AccordionEnum.DestinationCountryPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
case AccordionEnum.DestinationFilterBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
case AccordionEnum.PromoCampaignPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
return (
|
||||
accordion.specific_accordion?.questions.flatMap((question) =>
|
||||
question.answer.embedded_itemsConnection.edges.flatMap(
|
||||
({ node }) => node.system
|
||||
)
|
||||
) || []
|
||||
)
|
||||
default:
|
||||
return []
|
||||
}
|
||||
})
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -4,12 +4,7 @@ import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/i
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { HotelPageEnum } from "../../../../types/hotelPageEnum"
|
||||
import {
|
||||
collectionPageRefSchema,
|
||||
collectionPageSchema,
|
||||
contentPageRefSchema,
|
||||
contentPageSchema,
|
||||
} from "../pageLinks"
|
||||
import { collectionPageSchema, contentPageSchema } from "../pageLinks"
|
||||
|
||||
export const activitiesCardSchema = z.object({
|
||||
typename: z
|
||||
@@ -70,26 +65,3 @@ export const activitiesCardSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const activitiesCardRefSchema = z.object({
|
||||
upcoming_activities_card: z
|
||||
.object({
|
||||
hotel_page_activities_content_pageConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
contentPageRefSchema,
|
||||
collectionPageRefSchema,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return (
|
||||
data.hotel_page_activities_content_pageConnection.edges.flatMap(
|
||||
({ node }) => node.system
|
||||
) || []
|
||||
)
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -4,7 +4,6 @@ import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/i
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { campaignPageRefSchema, promoCampaignPageRefSchema } from "../pageLinks"
|
||||
|
||||
export const campaignPageCardSchema = z.object({
|
||||
image: transformedImageVaultAssetSchema,
|
||||
@@ -66,18 +65,3 @@ export const allCampaignsSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const allCampaignsRefsSchema = z.object({
|
||||
all_campaigns: z.object({
|
||||
campaignsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
campaignPageRefSchema,
|
||||
promoCampaignPageRefSchema,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import {
|
||||
contentCardRefSchema,
|
||||
contentCardSchema,
|
||||
transformContentCard,
|
||||
} from "./cards/contentCard"
|
||||
import { contentCardSchema, transformContentCard } from "./cards/contentCard"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "./utils/linkConnection"
|
||||
|
||||
export const cardGallerySchema = z.object({
|
||||
typename: z
|
||||
@@ -77,24 +72,3 @@ export const cardGallerySchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const cardGalleryRefsSchema = z.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.CardGallery)
|
||||
.optional()
|
||||
.default(BlocksEnums.block.CardGallery),
|
||||
card_gallery: z.object({
|
||||
card_groups: z.array(
|
||||
z.object({
|
||||
cardsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: contentCardRefSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
),
|
||||
link: linkConnectionRefsSchema.optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -5,7 +5,6 @@ import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/i
|
||||
import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { systemSchema } from "../../system"
|
||||
import { buttonSchema } from "../utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../utils/linkConnection"
|
||||
|
||||
export const contentCardSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.ContentCard),
|
||||
@@ -19,12 +18,6 @@ export const contentCardSchema = z.object({
|
||||
system: systemSchema,
|
||||
})
|
||||
|
||||
export const contentCardRefSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.ContentCard),
|
||||
card_link: linkConnectionRefsSchema,
|
||||
system: systemSchema,
|
||||
})
|
||||
|
||||
export function transformContentCard(card: typeof contentCardSchema._type) {
|
||||
// Return null if image or image URL is missing
|
||||
if (!card.image?.url) return null
|
||||
|
||||
@@ -6,7 +6,6 @@ import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { systemSchema } from "../../system"
|
||||
import { getInfoCardThemeFromDeprecatedCardTheme } from "../cardsGrid"
|
||||
import { buttonSchema } from "../utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../utils/linkConnection"
|
||||
|
||||
const INFO_CARD_WITH_IMAGE_THEMES = [
|
||||
"one",
|
||||
@@ -62,10 +61,3 @@ export function transformInfoCardWithImageBlock(
|
||||
system: card.system,
|
||||
}
|
||||
}
|
||||
|
||||
export const infoCardWithImageBlockRefsSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.InfoCardWithImage),
|
||||
primary_button: linkConnectionRefsSchema,
|
||||
secondary_button: linkConnectionRefsSchema,
|
||||
system: systemSchema,
|
||||
})
|
||||
|
||||
@@ -5,7 +5,6 @@ import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/i
|
||||
import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { systemSchema } from "../../system"
|
||||
import { buttonSchema } from "../utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../utils/linkConnection"
|
||||
|
||||
export const loyaltyCardBlockSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.LoyaltyCard),
|
||||
@@ -17,9 +16,3 @@ export const loyaltyCardBlockSchema = z.object({
|
||||
system: systemSchema,
|
||||
title: z.string().optional(),
|
||||
})
|
||||
|
||||
export const loyaltyCardBlockRefsSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.LoyaltyCard),
|
||||
link: linkConnectionRefsSchema,
|
||||
system: systemSchema,
|
||||
})
|
||||
|
||||
@@ -21,7 +21,6 @@ import { systemSchema } from "../../system"
|
||||
import { imageContainerSchema } from "../imageContainer"
|
||||
import { sysAssetSchema } from "../sysAsset"
|
||||
import { buttonSchema } from "../utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../utils/linkConnection"
|
||||
|
||||
export const teaserCardBlockSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.TeaserCard),
|
||||
@@ -118,10 +117,3 @@ export function transformTeaserCardBlock(
|
||||
system: card.system,
|
||||
}
|
||||
}
|
||||
|
||||
export const teaserCardBlockRefsSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.TeaserCard),
|
||||
primary_button: linkConnectionRefsSchema,
|
||||
secondary_button: linkConnectionRefsSchema,
|
||||
system: systemSchema,
|
||||
})
|
||||
|
||||
@@ -10,21 +10,15 @@ import {
|
||||
} from "../../../../types/cardsGridEnum"
|
||||
import { systemSchema } from "../system"
|
||||
import {
|
||||
infoCardWithImageBlockRefsSchema,
|
||||
infoCardWithImageBlockSchema,
|
||||
transformInfoCardWithImageBlock,
|
||||
} from "./cards/infoCardWithImage"
|
||||
import { loyaltyCardBlockSchema } from "./cards/loyaltyCard"
|
||||
import {
|
||||
loyaltyCardBlockRefsSchema,
|
||||
loyaltyCardBlockSchema,
|
||||
} from "./cards/loyaltyCard"
|
||||
import {
|
||||
teaserCardBlockRefsSchema,
|
||||
teaserCardBlockSchema,
|
||||
transformTeaserCardBlock,
|
||||
} from "./cards/teaserCard"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "./utils/linkConnection"
|
||||
|
||||
export const infoCardBlockSchema = z.object({
|
||||
__typename: z.literal(CardsGridEnum.cards.InfoCard),
|
||||
@@ -140,67 +134,6 @@ export const cardsGridSchema = z.object({
|
||||
}),
|
||||
})
|
||||
|
||||
export const infoCardBlockRefsSchema = z.object({
|
||||
__typename: z.literal(CardsGridEnum.cards.InfoCard),
|
||||
primary_button: linkConnectionRefsSchema,
|
||||
secondary_button: linkConnectionRefsSchema,
|
||||
system: systemSchema,
|
||||
})
|
||||
|
||||
export function transformCardBlockRefs(
|
||||
card:
|
||||
| typeof infoCardBlockRefsSchema._type
|
||||
| typeof teaserCardBlockRefsSchema._type
|
||||
| typeof infoCardWithImageBlockRefsSchema._type
|
||||
) {
|
||||
const cards = [card.system]
|
||||
if (card.primary_button) {
|
||||
cards.push(card.primary_button)
|
||||
}
|
||||
if (card.secondary_button) {
|
||||
cards.push(card.secondary_button)
|
||||
}
|
||||
return cards
|
||||
}
|
||||
|
||||
export const cardGridRefsSchema = z.object({
|
||||
cards_grid: z
|
||||
.object({
|
||||
cardConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
infoCardBlockRefsSchema,
|
||||
loyaltyCardBlockRefsSchema,
|
||||
teaserCardBlockRefsSchema,
|
||||
infoCardWithImageBlockRefsSchema,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
link: linkConnectionRefsSchema.nullish(),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.cardConnection.edges
|
||||
.map(({ node }) => {
|
||||
if (
|
||||
node.__typename === CardsGridEnum.cards.InfoCard ||
|
||||
node.__typename === CardsGridEnum.cards.TeaserCard ||
|
||||
node.__typename === CardsGridEnum.cards.InfoCardWithImage
|
||||
) {
|
||||
return transformCardBlockRefs(node)
|
||||
} else {
|
||||
const loyaltyCards = [node.system]
|
||||
if (node.link) {
|
||||
loyaltyCards.push(node.link)
|
||||
}
|
||||
return loyaltyCards
|
||||
}
|
||||
})
|
||||
.flat()
|
||||
}),
|
||||
})
|
||||
|
||||
export function getInfoCardThemeFromDeprecatedCardTheme(theme?: string | null) {
|
||||
if (!theme) {
|
||||
return null
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import {
|
||||
contentCardRefSchema,
|
||||
contentCardSchema,
|
||||
transformContentCard,
|
||||
} from "./cards/contentCard"
|
||||
import { contentCardSchema, transformContentCard } from "./cards/contentCard"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "./utils/linkConnection"
|
||||
|
||||
const commonFields = {
|
||||
heading: z.string().optional(),
|
||||
@@ -135,24 +130,3 @@ export const carouselCardsSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const carouselCardsRefsSchema = z.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.CarouselCards)
|
||||
.optional()
|
||||
.default(BlocksEnums.block.CarouselCards),
|
||||
carousel_cards: z.object({
|
||||
card_groups: z.array(
|
||||
z.object({
|
||||
cardConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: contentCardRefSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
),
|
||||
link: linkConnectionRefsSchema.nullish(),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { ContentEnum } from "../../../../types/content"
|
||||
import {
|
||||
rawLinkRefsUnionSchema,
|
||||
rawLinkUnionSchema,
|
||||
transformPageLink,
|
||||
} from "../pageLinks"
|
||||
import {
|
||||
imageContainerRefsSchema,
|
||||
imageContainerSchema,
|
||||
} from "./imageContainer"
|
||||
import { sysAssetRefsSchema, sysAssetSchema } from "./sysAsset"
|
||||
import { rawLinkUnionSchema, transformPageLink } from "../pageLinks"
|
||||
import { imageContainerSchema } from "./imageContainer"
|
||||
import { sysAssetSchema } from "./sysAsset"
|
||||
|
||||
export const contentSchema = z.object({
|
||||
typename: z
|
||||
@@ -50,39 +42,3 @@ export const contentSchema = z.object({
|
||||
return data?.content
|
||||
}),
|
||||
})
|
||||
|
||||
export const contentRefsSchema = z.object({
|
||||
content: z
|
||||
.object({
|
||||
content: z
|
||||
.object({
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
sysAssetRefsSchema,
|
||||
imageContainerRefsSchema,
|
||||
...rawLinkRefsUnionSchema.options,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.nullish(),
|
||||
})
|
||||
.nullish()
|
||||
.transform((data) => {
|
||||
return data?.content?.embedded_itemsConnection.edges
|
||||
.map(({ node }) => {
|
||||
switch (node.__typename) {
|
||||
case ContentEnum.blocks.SysAsset:
|
||||
return node.system && (node.permanent_url || node.url)
|
||||
? { system: node.system, url: node.permanent_url || node.url }
|
||||
: null
|
||||
default:
|
||||
return node.system
|
||||
}
|
||||
})
|
||||
.filter((node) => !!node)
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -2,11 +2,7 @@ import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { DynamicContentEnum } from "../../../../types/dynamicContent"
|
||||
import {
|
||||
linkRefsUnionSchema,
|
||||
linkUnionSchema,
|
||||
transformPageLink,
|
||||
} from "../pageLinks"
|
||||
import { linkUnionSchema, transformPageLink } from "../pageLinks"
|
||||
|
||||
export const dynamicContentSchema = z.object({
|
||||
typename: z
|
||||
@@ -47,24 +43,3 @@ export const dynamicContentSchema = z.object({
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
export const dynamicContentRefsSchema = z.object({
|
||||
dynamic_content: z.object({
|
||||
link: z
|
||||
.object({
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: linkRefsUnionSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
if (data.linkConnection?.edges.length) {
|
||||
return data.linkConnection.edges[0].node.system
|
||||
}
|
||||
return null
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -2,7 +2,6 @@ import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import * as pageLinks from "../../../../routers/contentstack/schemas/pageLinks"
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { systemSchema } from "../system"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
@@ -41,24 +40,3 @@ export const fullWidthCampaignBlockSchema = z
|
||||
.default(BlocksEnums.block.FullWidthCampaign),
|
||||
})
|
||||
.merge(fullWidthCampaignSchema)
|
||||
|
||||
export const fullWidthCampaignBlockRefsSchema = z.object({
|
||||
full_width_campaign: z.object({
|
||||
full_width_campaignConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
pageLinks.accountPageRefSchema,
|
||||
pageLinks.contentPageRefSchema,
|
||||
pageLinks.loyaltyPageRefSchema,
|
||||
pageLinks.collectionPageRefSchema,
|
||||
pageLinks.hotelPageRefSchema,
|
||||
pageLinks.destinationCityPageRefSchema,
|
||||
pageLinks.destinationCountryPageRefSchema,
|
||||
pageLinks.destinationOverviewPageRefSchema,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { HotelPageEnum } from "../../../../types/hotelPageEnum"
|
||||
import {
|
||||
accordionItemsSchema,
|
||||
globalAccordionConnectionRefs,
|
||||
specificAccordionConnectionRefs,
|
||||
} from "./accordion"
|
||||
import { accordionItemsSchema } from "./accordion"
|
||||
|
||||
export const hotelFaqSchema = z
|
||||
.object({
|
||||
@@ -43,33 +38,3 @@ export const hotelFaqSchema = z
|
||||
array.push(data.specific_faq?.questions || [])
|
||||
return { ...data, accordions: array.flat(2) }
|
||||
})
|
||||
|
||||
export const hotelFaqRefsSchema = z
|
||||
.object({
|
||||
__typename: z
|
||||
.literal(HotelPageEnum.ContentStack.blocks.Faq)
|
||||
.optional()
|
||||
.default(HotelPageEnum.ContentStack.blocks.Faq),
|
||||
global_faqConnection: globalAccordionConnectionRefs.optional(),
|
||||
specific_faq: specificAccordionConnectionRefs.optional().nullable(),
|
||||
})
|
||||
.transform((data) => {
|
||||
const array = []
|
||||
array.push(
|
||||
data.global_faqConnection?.edges.flatMap(({ node: faqConnection }) => {
|
||||
return faqConnection.questions.flatMap((question) =>
|
||||
question.answer.embedded_itemsConnection.edges.flatMap(
|
||||
({ node }) => node.system
|
||||
)
|
||||
)
|
||||
}) || []
|
||||
)
|
||||
array.push(
|
||||
data.specific_faq?.questions.flatMap((question) =>
|
||||
question.answer.embedded_itemsConnection.edges.flatMap(
|
||||
({ node }) => node.system
|
||||
)
|
||||
) || []
|
||||
)
|
||||
return array.flat(2)
|
||||
})
|
||||
|
||||
@@ -12,8 +12,3 @@ export const imageContainerSchema = z.object({
|
||||
system: systemSchema,
|
||||
title: z.string().optional(),
|
||||
})
|
||||
|
||||
export const imageContainerRefsSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.ImageContainer),
|
||||
system: systemSchema,
|
||||
})
|
||||
|
||||
@@ -4,7 +4,6 @@ import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/i
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "./utils/linkConnection"
|
||||
|
||||
export const joinScandicFriendsSchema = z.object({
|
||||
join_scandic_friends: z.object({
|
||||
@@ -28,9 +27,3 @@ export const joinScandicFriendsBlockSchema = z
|
||||
.default(BlocksEnums.block.JoinScandicFriends),
|
||||
})
|
||||
.merge(joinScandicFriendsSchema)
|
||||
|
||||
export const joinScandicFriendsBlockRefsSchema = z.object({
|
||||
join_scandic_friends: z.object({
|
||||
primary_button: linkConnectionRefsSchema,
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { systemSchema } from "../system"
|
||||
|
||||
export const jotformSchema = z.object({
|
||||
typename: z
|
||||
@@ -24,19 +23,3 @@ export const jotformSchema = z.object({
|
||||
return data.formConnection.edges[0]?.node || null
|
||||
}),
|
||||
})
|
||||
|
||||
export const jotformRefsSchema = z.object({
|
||||
jotform: z
|
||||
.object({
|
||||
formConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({ system: systemSchema }),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.formConnection.edges[0]?.node || null
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import {
|
||||
linkRefsUnionSchema,
|
||||
linkUnionSchema,
|
||||
transformPageLink,
|
||||
} from "../pageLinks"
|
||||
import { linkUnionSchema, transformPageLink } from "../pageLinks"
|
||||
|
||||
export const shortcutsBlockSchema = z.object({
|
||||
shortcuts: z
|
||||
@@ -91,27 +87,3 @@ export const shortcutsSchema = z
|
||||
.default(BlocksEnums.block.Shortcuts),
|
||||
})
|
||||
.merge(shortcutsBlockSchema)
|
||||
|
||||
export const shortcutsRefsSchema = z.object({
|
||||
shortcuts: z.object({
|
||||
shortcuts: z
|
||||
.array(
|
||||
z.object({
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: linkRefsUnionSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
)
|
||||
.transform((data) =>
|
||||
data
|
||||
.map((shortcut) => {
|
||||
return shortcut.linkConnection.edges.map(({ node }) => node.system)
|
||||
})
|
||||
.flat()
|
||||
),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import { z } from "zod"
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { HotelPageEnum } from "../../../../types/hotelPageEnum"
|
||||
import { collectionPageRefSchema, contentPageRefSchema } from "../pageLinks"
|
||||
|
||||
export const spaPageSchema = z.object({
|
||||
typename: z
|
||||
@@ -46,22 +45,3 @@ export const spaPageSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const spaPageRefSchema = z.object({
|
||||
spa_page: z
|
||||
.object({
|
||||
pageConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
contentPageRefSchema,
|
||||
collectionPageRefSchema,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.pageConnection.edges.flatMap(({ node }) => node.system) || []
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -31,13 +31,3 @@ export const sysAssetSchema = z.object({
|
||||
.nullish()
|
||||
.transform((val) => (val === "Permanent URL Not Defined!" ? null : val)), // ContentStack returns this string when permanent_url is not defined
|
||||
})
|
||||
|
||||
export const sysAssetRefsSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.SysAsset),
|
||||
url: z.string().nullish(),
|
||||
permanent_url: z
|
||||
.string()
|
||||
.nullish()
|
||||
.transform((val) => (val === "Permanent URL Not Defined!" ? null : val)), // ContentStack returns this string when permanent_url is not defined
|
||||
system: assetSystemSchema.nullish(),
|
||||
})
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { ContentEnum } from "../../../../types/content"
|
||||
import {
|
||||
rawLinkRefsUnionSchema,
|
||||
rawLinkUnionSchema,
|
||||
transformPageLink,
|
||||
} from "../pageLinks"
|
||||
import { sysAssetRefsSchema, sysAssetSchema } from "./sysAsset"
|
||||
|
||||
import type { linkUnionSchema } from "../pageLinks"
|
||||
import { rawLinkUnionSchema, transformPageLink } from "../pageLinks"
|
||||
import { sysAssetSchema } from "./sysAsset"
|
||||
|
||||
export const textColsSchema = z.object({
|
||||
typename: z
|
||||
@@ -45,39 +38,3 @@ export const textColsSchema = z.object({
|
||||
),
|
||||
}),
|
||||
})
|
||||
|
||||
type Refs = {
|
||||
node: z.TypeOf<typeof linkUnionSchema>
|
||||
}
|
||||
|
||||
export const textColsRefsSchema = z.object({
|
||||
text_cols: z
|
||||
.object({
|
||||
columns: z.array(
|
||||
z.object({
|
||||
text: z.object({
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
sysAssetRefsSchema,
|
||||
...rawLinkRefsUnionSchema.options,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.columns
|
||||
.map((column) => {
|
||||
const filtered = column.text.embedded_itemsConnection.edges.filter(
|
||||
(block) => block.node.__typename !== ContentEnum.blocks.SysAsset
|
||||
) as unknown as Refs[] // TS issue with filtered out types
|
||||
return filtered.map(({ node }) => node.system)
|
||||
})
|
||||
.flat()
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -2,11 +2,7 @@ import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { UspGridEnum } from "../../../../types/uspGrid"
|
||||
import {
|
||||
linkRefsUnionSchema,
|
||||
linkUnionSchema,
|
||||
transformPageLink,
|
||||
} from "../pageLinks"
|
||||
import { linkUnionSchema, transformPageLink } from "../pageLinks"
|
||||
|
||||
const uspCardSchema = z.object({
|
||||
icon: UspGridEnum.uspIcons,
|
||||
@@ -53,39 +49,3 @@ export const uspGridSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const uspGridRefsSchema = z.object({
|
||||
usp_grid: z
|
||||
.object({
|
||||
cardsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
usp_card: z.array(
|
||||
z.object({
|
||||
text: z.object({
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: linkRefsUnionSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.cardsConnection.edges.flatMap(({ node }) =>
|
||||
node.usp_card.flatMap((card) =>
|
||||
card.text.embedded_itemsConnection.edges.map(
|
||||
({ node }) => node.system
|
||||
)
|
||||
)
|
||||
)
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { linkRefsUnionSchema } from "../../pageLinks"
|
||||
|
||||
export const linkConnectionRefsSchema = z
|
||||
.object({
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: linkRefsUnionSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
if (!data.linkConnection.edges.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
return data.linkConnection.edges[0].node?.system
|
||||
})
|
||||
@@ -1,14 +1,9 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { transformedVideoSchema, videoRefSchema } from "../video"
|
||||
import { transformedVideoSchema } from "../video"
|
||||
|
||||
export const videoBlockSchema = z.object({
|
||||
typename: z.literal(BlocksEnums.block.Video).default(BlocksEnums.block.Video),
|
||||
video: transformedVideoSchema,
|
||||
})
|
||||
|
||||
export const videoBlockRefsSchema = z.object({
|
||||
typename: z.literal(BlocksEnums.block.Video).default(BlocksEnums.block.Video),
|
||||
video: videoRefSchema,
|
||||
})
|
||||
|
||||
@@ -3,8 +3,7 @@ import { z } from "zod"
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { systemSchema } from "../system"
|
||||
import { transformedVideoSchema, videoRefSchema } from "../video"
|
||||
import { transformedVideoSchema } from "../video"
|
||||
|
||||
const cardStyleSchema = z
|
||||
.string()
|
||||
@@ -86,32 +85,3 @@ export const videoCardSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
const videoCardRefSchema = z.object({
|
||||
video: videoRefSchema,
|
||||
system: systemSchema,
|
||||
})
|
||||
|
||||
export const videoCardRefsSchema = z.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.VideoCard)
|
||||
.default(BlocksEnums.block.VideoCard),
|
||||
video_card: z
|
||||
.object({
|
||||
video_cardConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: videoCardRefSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
const videoCard = data.video_cardConnection.edges[0]?.node
|
||||
if (!videoCard?.video) {
|
||||
return null
|
||||
}
|
||||
|
||||
return videoCard
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -7,7 +7,6 @@ import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
|
||||
import { hotelFilterSchema } from "../../hotels/filters/output"
|
||||
import { accordionSchema } from "./blocks/accordion"
|
||||
import { contentSchema } from "./blocks/content"
|
||||
import { systemSchema } from "./system"
|
||||
|
||||
export const destinationFilterBlockContent = z
|
||||
.object({
|
||||
@@ -50,22 +49,6 @@ export const transformedDestinationFiltersSchema =
|
||||
transformDestinationFiltersResponse(data)
|
||||
)
|
||||
|
||||
export const destinationFiltersRefsSchema = z
|
||||
.array(
|
||||
z.object({
|
||||
filterConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
)
|
||||
.nullish()
|
||||
|
||||
export function transformDestinationFiltersResponse(
|
||||
data: typeof destinationFiltersSchema._type
|
||||
) {
|
||||
|
||||
@@ -5,7 +5,3 @@ import { DynamicContentEnum } from "../../../../types/dynamicContent"
|
||||
export const dynamicContentSchema = z.object({
|
||||
component: z.enum(DynamicContentEnum.Headers.enums).nullish(),
|
||||
})
|
||||
|
||||
export const dynamicContentRefsSchema = z.object({
|
||||
component: z.enum(DynamicContentEnum.Headers.enums).nullish(),
|
||||
})
|
||||
|
||||
@@ -2,12 +2,7 @@ import { z } from "zod"
|
||||
|
||||
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
|
||||
|
||||
import {
|
||||
linkRefsUnionSchema,
|
||||
linkUnionSchema,
|
||||
transformPageLink,
|
||||
transformPageLinkRef,
|
||||
} from "./pageLinks"
|
||||
import { linkUnionSchema, transformPageLink } from "./pageLinks"
|
||||
|
||||
const titleSchema = z.object({
|
||||
title: nullableStringValidator,
|
||||
@@ -45,28 +40,3 @@ export const linkAndTitleSchema = z.intersection(
|
||||
linkConnectionSchema,
|
||||
titleSchema
|
||||
)
|
||||
|
||||
export const linkConnectionRefs = z
|
||||
.object({
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: linkRefsUnionSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
if (data.linkConnection.edges.length) {
|
||||
const linkNode = data.linkConnection.edges[0].node
|
||||
if (linkNode) {
|
||||
const link = transformPageLinkRef(linkNode)
|
||||
if (link) {
|
||||
return {
|
||||
link,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return { link: null }
|
||||
})
|
||||
|
||||
@@ -19,11 +19,6 @@ export const accountPageSchema = z
|
||||
})
|
||||
.merge(pageLinkSchema)
|
||||
|
||||
export const accountPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.AccountPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const extendedPageLinkSchema = pageLinkSchema.merge(
|
||||
z.object({
|
||||
web: z
|
||||
@@ -40,121 +35,66 @@ export const campaignOverviewPageSchema = z
|
||||
})
|
||||
.merge(extendedPageLinkSchema)
|
||||
|
||||
export const campaignOverviewPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.CampaignOverviewPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const collectionPageSchema = z
|
||||
.object({
|
||||
__typename: z.literal(ContentEnum.blocks.CollectionPage),
|
||||
})
|
||||
.merge(extendedPageLinkSchema)
|
||||
|
||||
export const collectionPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.CollectionPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const contentPageSchema = z
|
||||
.object({
|
||||
__typename: z.literal(ContentEnum.blocks.ContentPage),
|
||||
})
|
||||
.merge(extendedPageLinkSchema)
|
||||
|
||||
export const contentPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.ContentPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const destinationCityPageSchema = z
|
||||
.object({
|
||||
__typename: z.literal(ContentEnum.blocks.DestinationCityPage),
|
||||
})
|
||||
.merge(pageLinkSchema)
|
||||
|
||||
export const destinationCityPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.DestinationCityPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const campaignPageSchema = z
|
||||
.object({
|
||||
__typename: z.literal(ContentEnum.blocks.CampaignPage),
|
||||
})
|
||||
.merge(pageLinkSchema)
|
||||
|
||||
export const campaignPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.CampaignPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const destinationCountryPageSchema = z
|
||||
.object({
|
||||
__typename: z.literal(ContentEnum.blocks.DestinationCountryPage),
|
||||
})
|
||||
.merge(pageLinkSchema)
|
||||
|
||||
export const destinationCountryPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.DestinationCountryPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const destinationOverviewPageSchema = z
|
||||
.object({
|
||||
__typename: z.literal(ContentEnum.blocks.DestinationOverviewPage),
|
||||
})
|
||||
.merge(pageLinkSchema)
|
||||
|
||||
export const destinationOverviewPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.DestinationOverviewPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const hotelPageSchema = z
|
||||
.object({
|
||||
__typename: z.literal(ContentEnum.blocks.HotelPage),
|
||||
})
|
||||
.merge(pageLinkSchema)
|
||||
|
||||
export const hotelPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.HotelPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const loyaltyPageSchema = z
|
||||
.object({
|
||||
__typename: z.literal(ContentEnum.blocks.LoyaltyPage),
|
||||
})
|
||||
.merge(extendedPageLinkSchema)
|
||||
|
||||
export const loyaltyPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.LoyaltyPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const startPageSchema = z
|
||||
.object({
|
||||
__typename: z.literal(ContentEnum.blocks.StartPage),
|
||||
})
|
||||
.merge(pageLinkSchema)
|
||||
|
||||
export const startPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.StartPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const promoCampaignPageSchema = z
|
||||
.object({
|
||||
__typename: z.literal(ContentEnum.blocks.PromoCampaignPage),
|
||||
})
|
||||
.merge(pageLinkSchema)
|
||||
|
||||
export const promoCampaignPageRefSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.PromoCampaignPage),
|
||||
system: systemSchema.nullable(),
|
||||
})
|
||||
|
||||
export const rawLinkUnionSchema = z.discriminatedUnion("__typename", [
|
||||
accountPageSchema,
|
||||
campaignOverviewPageSchema,
|
||||
@@ -263,55 +203,3 @@ export const internalOrExternalLinkSchema = z
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
export const rawLinkRefsUnionSchema = z.discriminatedUnion("__typename", [
|
||||
accountPageRefSchema,
|
||||
campaignOverviewPageRefSchema,
|
||||
campaignPageRefSchema,
|
||||
collectionPageRefSchema,
|
||||
contentPageRefSchema,
|
||||
destinationCityPageRefSchema,
|
||||
destinationCountryPageRefSchema,
|
||||
destinationOverviewPageRefSchema,
|
||||
hotelPageRefSchema,
|
||||
loyaltyPageRefSchema,
|
||||
startPageRefSchema,
|
||||
promoCampaignPageRefSchema,
|
||||
])
|
||||
|
||||
export const linkRefsUnionSchema = safeUnion(rawLinkRefsUnionSchema)
|
||||
|
||||
type RefData =
|
||||
| z.output<typeof accountPageRefSchema>
|
||||
| z.output<typeof campaignOverviewPageRefSchema>
|
||||
| z.output<typeof campaignPageRefSchema>
|
||||
| z.output<typeof collectionPageRefSchema>
|
||||
| z.output<typeof contentPageRefSchema>
|
||||
| z.output<typeof destinationCityPageRefSchema>
|
||||
| z.output<typeof destinationCountryPageRefSchema>
|
||||
| z.output<typeof destinationOverviewPageRefSchema>
|
||||
| z.output<typeof hotelPageRefSchema>
|
||||
| z.output<typeof loyaltyPageRefSchema>
|
||||
| z.output<typeof startPageRefSchema>
|
||||
| z.output<typeof promoCampaignPageRefSchema>
|
||||
| Object
|
||||
|
||||
export function transformPageLinkRef(data: RefData) {
|
||||
if (data && "__typename" in data) {
|
||||
switch (data.__typename) {
|
||||
case ContentEnum.blocks.AccountPage:
|
||||
case ContentEnum.blocks.CampaignOverviewPage:
|
||||
case ContentEnum.blocks.CampaignPage:
|
||||
case ContentEnum.blocks.CollectionPage:
|
||||
case ContentEnum.blocks.ContentPage:
|
||||
case ContentEnum.blocks.DestinationCityPage:
|
||||
case ContentEnum.blocks.DestinationCountryPage:
|
||||
case ContentEnum.blocks.DestinationOverviewPage:
|
||||
case ContentEnum.blocks.HotelPage:
|
||||
case ContentEnum.blocks.LoyaltyPage:
|
||||
case ContentEnum.blocks.StartPage:
|
||||
case ContentEnum.blocks.PromoCampaignPage:
|
||||
return data.system
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { ContentEnum } from "../../../../types/content"
|
||||
import { SidebarEnums } from "../../../../types/sidebar"
|
||||
import {
|
||||
imageContainerRefsSchema,
|
||||
imageContainerSchema,
|
||||
} from "../blocks/imageContainer"
|
||||
import { sysAssetRefsSchema, sysAssetSchema } from "../blocks/sysAsset"
|
||||
import {
|
||||
rawLinkRefsUnionSchema,
|
||||
rawLinkUnionSchema,
|
||||
transformPageLink,
|
||||
} from "../pageLinks"
|
||||
import { imageContainerSchema } from "../blocks/imageContainer"
|
||||
import { sysAssetSchema } from "../blocks/sysAsset"
|
||||
import { rawLinkUnionSchema, transformPageLink } from "../pageLinks"
|
||||
|
||||
export const contentSchema = z.object({
|
||||
typename: z
|
||||
@@ -50,40 +42,3 @@ export const contentSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
const actualRefs = z.discriminatedUnion("__typename", [
|
||||
imageContainerRefsSchema,
|
||||
...rawLinkRefsUnionSchema.options,
|
||||
])
|
||||
|
||||
export const contentRefsSchema = z.object({
|
||||
content: z
|
||||
.object({
|
||||
content: z.object({
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
sysAssetRefsSchema,
|
||||
...actualRefs.options,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data?.content?.embedded_itemsConnection.edges
|
||||
.map(({ node }) => {
|
||||
switch (node.__typename) {
|
||||
case ContentEnum.blocks.SysAsset:
|
||||
return node.system && (node.permanent_url || node.url)
|
||||
? { system: node.system, url: node.permanent_url || node.url }
|
||||
: null
|
||||
default:
|
||||
return node.system
|
||||
}
|
||||
})
|
||||
.filter((node) => !!node)
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import { z } from "zod"
|
||||
import { JoinLoyaltyContactEnums } from "../../../../types/joinLoyaltyContact"
|
||||
import { SidebarEnums } from "../../../../types/sidebar"
|
||||
import { buttonSchema } from "../blocks/utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../blocks/utils/linkConnection"
|
||||
|
||||
export const contactSchema = z.object({
|
||||
contact: z.array(
|
||||
@@ -49,9 +48,3 @@ export const joinLoyaltyContactSchema = z.object({
|
||||
})
|
||||
.merge(contactSchema),
|
||||
})
|
||||
|
||||
export const joinLoyaltyContactRefsSchema = z.object({
|
||||
join_loyalty_contact: z.object({
|
||||
button: linkConnectionRefsSchema,
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { SidebarEnums } from "../../../../types/sidebar"
|
||||
import { shortcutsBlockSchema, shortcutsRefsSchema } from "../blocks/shortcuts"
|
||||
import { shortcutsBlockSchema } from "../blocks/shortcuts"
|
||||
|
||||
export const quickLinksSchema = z
|
||||
.object({
|
||||
@@ -11,5 +11,3 @@ export const quickLinksSchema = z
|
||||
.default(SidebarEnums.blocks.QuickLinks),
|
||||
})
|
||||
.merge(shortcutsBlockSchema)
|
||||
|
||||
export const quickLinksRefschema = shortcutsRefsSchema
|
||||
|
||||
@@ -4,9 +4,7 @@ import { scriptedCardThemeEnum } from "../../../../enums/scriptedCard"
|
||||
import { SidebarEnums } from "../../../../types/sidebar"
|
||||
import {
|
||||
getInfoCardThemeFromDeprecatedCardTheme,
|
||||
infoCardBlockRefsSchema,
|
||||
infoCardBlockSchema,
|
||||
transformCardBlockRefs,
|
||||
transformInfoCardBlock,
|
||||
} from "../blocks/cardsGrid"
|
||||
|
||||
@@ -41,25 +39,3 @@ export const scriptedCardsSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const scriptedCardRefschema = z.object({
|
||||
scripted_card: z
|
||||
.object({
|
||||
scripted_cardConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: infoCardBlockRefsSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
let card = null
|
||||
if (data.scripted_cardConnection.edges.length) {
|
||||
card = transformCardBlockRefs(
|
||||
data.scripted_cardConnection.edges[0].node
|
||||
)
|
||||
}
|
||||
return card
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -2,11 +2,9 @@ import { z } from "zod"
|
||||
|
||||
import { SidebarEnums } from "../../../../types/sidebar"
|
||||
import {
|
||||
teaserCardBlockRefsSchema,
|
||||
teaserCardBlockSchema,
|
||||
transformTeaserCardBlock,
|
||||
} from "../blocks/cards/teaserCard"
|
||||
import { transformCardBlockRefs } from "../blocks/cardsGrid"
|
||||
|
||||
export const teaserCardsSchema = z.object({
|
||||
typename: z
|
||||
@@ -36,23 +34,3 @@ export const teaserCardsSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const teaserCardRefschema = z.object({
|
||||
teaser_card: z
|
||||
.object({
|
||||
teaser_cardConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: teaserCardBlockRefsSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
let card = null
|
||||
if (data.teaser_cardConnection.edges.length) {
|
||||
card = transformCardBlockRefs(data.teaser_cardConnection.edges[0].node)
|
||||
}
|
||||
return card
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user