Merged in fix/book-453-linkconnection (pull request #2972)

fix(BOOK-453): avoid linkConnection invalid

* fix(BOOK-453): avoid linkConnection invalid

* test

* test

* test

* Merge master
This commit is contained in:
Linus Flood
2025-10-22 12:39:17 +00:00
parent 03f17acbbe
commit acdc3dcec1
17 changed files with 79 additions and 46 deletions

View File

@@ -3,8 +3,8 @@ import { z } from "zod"
import { BlocksEnums } from "../../../../types/blocksEnum"
import { ContentEnum } from "../../../../types/content"
import {
linkRefsUnionSchema,
linkUnionSchema,
rawLinkRefsUnionSchema,
rawLinkUnionSchema,
transformPageLink,
} from "../pageLinks"
import {
@@ -30,7 +30,7 @@ export const contentSchema = z.object({
.discriminatedUnion("__typename", [
imageContainerSchema,
sysAssetSchema,
...linkUnionSchema.options,
...rawLinkUnionSchema.options,
])
.transform((data) => {
const link = transformPageLink(data)
@@ -62,7 +62,7 @@ export const contentRefsSchema = z.object({
node: z.discriminatedUnion("__typename", [
sysAssetRefsSchema,
imageContainerRefsSchema,
...linkRefsUnionSchema.options,
...rawLinkRefsUnionSchema.options,
]),
})
),

View File

@@ -3,12 +3,14 @@ import { z } from "zod"
import { BlocksEnums } from "../../../../types/blocksEnum"
import { ContentEnum } from "../../../../types/content"
import {
linkRefsUnionSchema,
linkUnionSchema,
rawLinkRefsUnionSchema,
rawLinkUnionSchema,
transformPageLink,
} from "../pageLinks"
import { sysAssetRefsSchema, sysAssetSchema } from "./sysAsset"
import type { linkUnionSchema } from "../pageLinks"
export const textColsSchema = z.object({
typename: z
.literal(BlocksEnums.block.TextCols)
@@ -26,7 +28,7 @@ export const textColsSchema = z.object({
node: z
.discriminatedUnion("__typename", [
sysAssetSchema,
...linkUnionSchema.options,
...rawLinkUnionSchema.options,
])
.transform((data) => {
const link = transformPageLink(data)
@@ -59,7 +61,7 @@ export const textColsRefsSchema = z.object({
z.object({
node: z.discriminatedUnion("__typename", [
sysAssetRefsSchema,
...linkRefsUnionSchema.options,
...rawLinkRefsUnionSchema.options,
]),
})
),

View File

@@ -17,5 +17,5 @@ export const linkConnectionRefsSchema = z
return null
}
return data.linkConnection.edges[0].node.system
return data.linkConnection.edges[0].node?.system
})

View File

@@ -4,6 +4,7 @@ import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
import { ContentEnum } from "../../../types/content"
import { safeUnion } from "../base/utils"
import { systemSchema } from "./system"
export const pageLinkSchema = z.object({
@@ -20,7 +21,7 @@ export const accountPageSchema = z
export const accountPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.AccountPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const extendedPageLinkSchema = pageLinkSchema.merge(
@@ -41,7 +42,7 @@ export const campaignOverviewPageSchema = z
export const campaignOverviewPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.CampaignOverviewPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const collectionPageSchema = z
@@ -52,7 +53,7 @@ export const collectionPageSchema = z
export const collectionPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.CollectionPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const contentPageSchema = z
@@ -63,7 +64,7 @@ export const contentPageSchema = z
export const contentPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.ContentPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const destinationCityPageSchema = z
@@ -74,7 +75,7 @@ export const destinationCityPageSchema = z
export const destinationCityPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.DestinationCityPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const campaignPageSchema = z
@@ -85,7 +86,7 @@ export const campaignPageSchema = z
export const campaignPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.CampaignPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const destinationCountryPageSchema = z
@@ -96,7 +97,7 @@ export const destinationCountryPageSchema = z
export const destinationCountryPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.DestinationCountryPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const destinationOverviewPageSchema = z
@@ -107,7 +108,7 @@ export const destinationOverviewPageSchema = z
export const destinationOverviewPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.DestinationOverviewPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const hotelPageSchema = z
@@ -118,7 +119,7 @@ export const hotelPageSchema = z
export const hotelPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.HotelPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const loyaltyPageSchema = z
@@ -129,7 +130,7 @@ export const loyaltyPageSchema = z
export const loyaltyPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.LoyaltyPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const startPageSchema = z
@@ -140,7 +141,7 @@ export const startPageSchema = z
export const startPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.StartPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const promoCampaignPageSchema = z
@@ -151,10 +152,10 @@ export const promoCampaignPageSchema = z
export const promoCampaignPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.PromoCampaignPage),
system: systemSchema,
system: systemSchema.nullable(),
})
export const linkUnionSchema = z.discriminatedUnion("__typename", [
export const rawLinkUnionSchema = z.discriminatedUnion("__typename", [
accountPageSchema,
campaignOverviewPageSchema,
campaignPageSchema,
@@ -169,6 +170,7 @@ export const linkUnionSchema = z.discriminatedUnion("__typename", [
promoCampaignPageSchema,
])
export const linkUnionSchema = safeUnion(rawLinkUnionSchema)
type Data =
| z.output<typeof accountPageSchema>
| z.output<typeof campaignOverviewPageSchema>
@@ -262,7 +264,7 @@ export const internalOrExternalLinkSchema = z
}
)
export const linkRefsUnionSchema = z.discriminatedUnion("__typename", [
export const rawLinkRefsUnionSchema = z.discriminatedUnion("__typename", [
accountPageRefSchema,
campaignOverviewPageRefSchema,
campaignPageRefSchema,
@@ -277,6 +279,8 @@ export const linkRefsUnionSchema = z.discriminatedUnion("__typename", [
promoCampaignPageRefSchema,
])
export const linkRefsUnionSchema = safeUnion(rawLinkRefsUnionSchema)
type RefData =
| z.output<typeof accountPageRefSchema>
| z.output<typeof campaignOverviewPageRefSchema>

View File

@@ -8,8 +8,8 @@ import {
} from "../blocks/imageContainer"
import { sysAssetRefsSchema, sysAssetSchema } from "../blocks/sysAsset"
import {
linkRefsUnionSchema,
linkUnionSchema,
rawLinkRefsUnionSchema,
rawLinkUnionSchema,
transformPageLink,
} from "../pageLinks"
@@ -29,7 +29,7 @@ export const contentSchema = z.object({
.discriminatedUnion("__typename", [
imageContainerSchema,
sysAssetSchema,
...linkUnionSchema.options,
...rawLinkUnionSchema.options,
])
.transform((data) => {
const link = transformPageLink(data)
@@ -53,7 +53,7 @@ export const contentSchema = z.object({
const actualRefs = z.discriminatedUnion("__typename", [
imageContainerRefsSchema,
...linkRefsUnionSchema.options,
...rawLinkRefsUnionSchema.options,
])
type Ref = typeof actualRefs._type