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:
@@ -11,7 +11,7 @@ export function getConnections({ account_page }: AccountPageRefs) {
|
||||
switch (block.__typename) {
|
||||
case AccountPageEnum.ContentStack.blocks.ShortCuts: {
|
||||
if (block.shortcuts.shortcuts.length) {
|
||||
connections.push(...block.shortcuts.shortcuts)
|
||||
connections.push(...block.shortcuts.shortcuts.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
linkRefsUnionSchema,
|
||||
linkUnionSchema,
|
||||
rawLinkUnionSchema,
|
||||
transformPageLink,
|
||||
transformPageLinkRef,
|
||||
} from "../schemas/pageLinks"
|
||||
@@ -410,7 +411,7 @@ const linkSchema = z
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: discriminatedUnion(linkUnionSchema.options),
|
||||
node: discriminatedUnion(rawLinkUnionSchema.options),
|
||||
})
|
||||
),
|
||||
}),
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import * as Sentry from "@sentry/nextjs"
|
||||
import { z } from "zod"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { getValueFromContactConfig } from "../../../utils/contactConfig"
|
||||
|
||||
import type { Edges } from "../../../types/edges"
|
||||
@@ -95,7 +100,9 @@ export function getSiteConfigConnections(refs: GetSiteConfigRefData) {
|
||||
}
|
||||
node.sidepeek_content.content.embedded_itemsConnection.edges.forEach(
|
||||
({ node }) => {
|
||||
connections.push(node.system)
|
||||
if (node.system) {
|
||||
connections.push(node.system)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -120,3 +127,14 @@ export function getAlertPhoneContactData(
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export const safeUnion = <T extends z.ZodTypeAny>(schema: T) =>
|
||||
z.preprocess((val) => {
|
||||
try {
|
||||
return schema.parse(val)
|
||||
} catch (err) {
|
||||
Sentry.captureException(err)
|
||||
logger.warn("Invalid node in safeUnion", err)
|
||||
return null
|
||||
}
|
||||
}, schema)
|
||||
|
||||
@@ -49,7 +49,9 @@ export function getConnections({
|
||||
}
|
||||
case CampaignOverviewPageEnum.ContentStack.blocks.AllCampaigns: {
|
||||
block.all_campaigns.campaignsConnection.edges.forEach(({ node }) => {
|
||||
connections.push(node.system)
|
||||
if (node.system) {
|
||||
connections.push(node.system)
|
||||
}
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ export function getConnections({ campaign_page }: CampaignPageRefs) {
|
||||
}
|
||||
case CampaignPageEnum.ContentStack.blocks.Accordion: {
|
||||
if (block.accordion.length) {
|
||||
connections.push(...block.accordion)
|
||||
connections.push(...block.accordion.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ export function getConnections({ collection_page }: CollectionPageRefs) {
|
||||
switch (block.__typename) {
|
||||
case CollectionPageEnum.ContentStack.blocks.Shortcuts: {
|
||||
if (block.shortcuts.shortcuts.length) {
|
||||
connections.push(...block.shortcuts.shortcuts)
|
||||
connections.push(...block.shortcuts.shortcuts.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -109,7 +109,7 @@ export function getConnections({ collection_page }: CollectionPageRefs) {
|
||||
}
|
||||
case CollectionPageEnum.ContentStack.blocks.UspGrid: {
|
||||
if (block.usp_grid.length) {
|
||||
connections.push(...block.usp_grid)
|
||||
connections.push(...block.usp_grid.filter((c) => !!c))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
||||
switch (block.__typename) {
|
||||
case ContentPageEnum.ContentStack.blocks.Accordion: {
|
||||
if (block.accordion.length) {
|
||||
connections.push(...block.accordion)
|
||||
connections.push(...block.accordion.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -112,7 +112,7 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
||||
}
|
||||
case ContentPageEnum.ContentStack.blocks.Shortcuts: {
|
||||
if (block.shortcuts.shortcuts.length) {
|
||||
connections.push(...block.shortcuts.shortcuts)
|
||||
connections.push(...block.shortcuts.shortcuts.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -124,7 +124,7 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
||||
}
|
||||
case ContentPageEnum.ContentStack.blocks.UspGrid: {
|
||||
if (block.usp_grid.length) {
|
||||
connections.push(...block.usp_grid)
|
||||
connections.push(...block.usp_grid.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -145,7 +145,7 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
||||
switch (block.__typename) {
|
||||
case ContentPageEnum.ContentStack.sidebar.Content:
|
||||
if (block.content.length) {
|
||||
connections.push(...block.content)
|
||||
connections.push(...block.content.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
case ContentPageEnum.ContentStack.sidebar.JoinLoyaltyContact:
|
||||
@@ -165,7 +165,7 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
||||
break
|
||||
case ContentPageEnum.ContentStack.sidebar.QuickLinks:
|
||||
if (block.shortcuts.shortcuts.length) {
|
||||
connections.push(...block.shortcuts.shortcuts)
|
||||
connections.push(...block.shortcuts.shortcuts.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
default:
|
||||
|
||||
@@ -41,7 +41,7 @@ export function getConnections({
|
||||
switch (block.__typename) {
|
||||
case DestinationCityPageEnum.ContentStack.blocks.Accordion: {
|
||||
if (block.accordion.length) {
|
||||
connections.push(...block.accordion)
|
||||
connections.push(...block.accordion.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -60,7 +60,9 @@ export function getConnections({
|
||||
if (destination_city_page.sidepeek_content) {
|
||||
destination_city_page.sidepeek_content?.content?.embedded_itemsConnection.edges.forEach(
|
||||
({ node }) => {
|
||||
connections.push(node.system)
|
||||
if (node.system) {
|
||||
connections.push(node.system)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ export function getConnections({
|
||||
switch (block.__typename) {
|
||||
case DestinationCountryPageEnum.ContentStack.blocks.Accordion: {
|
||||
if (block.accordion.length) {
|
||||
connections.push(...block.accordion)
|
||||
connections.push(...block.accordion.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -58,7 +58,9 @@ export function getConnections({
|
||||
if (destination_country_page.sidepeek_content) {
|
||||
destination_country_page.sidepeek_content?.content?.embedded_itemsConnection.edges.forEach(
|
||||
({ node }) => {
|
||||
connections.push(node.system)
|
||||
if (node.system) {
|
||||
connections.push(node.system)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export function getConnections({ loyalty_page }: LoyaltyPageRefs) {
|
||||
break
|
||||
case LoyaltyPageEnum.ContentStack.blocks.Shortcuts:
|
||||
if (block.shortcuts.shortcuts.length) {
|
||||
connections.push(...block.shortcuts.shortcuts)
|
||||
connections.push(...block.shortcuts.shortcuts.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
default:
|
||||
|
||||
@@ -27,7 +27,7 @@ export function getConnections({ promo_campaign_page }: PromoCampaignPageRefs) {
|
||||
switch (block.__typename) {
|
||||
case PromoCampaignPageEnum.ContentStack.blocks.Accordion: {
|
||||
if (block.accordion.length) {
|
||||
connections.push(...block.accordion)
|
||||
connections.push(...block.accordion.filter((c) => !!c))
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
]),
|
||||
})
|
||||
),
|
||||
|
||||
@@ -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,
|
||||
]),
|
||||
})
|
||||
),
|
||||
|
||||
@@ -17,5 +17,5 @@ export const linkConnectionRefsSchema = z
|
||||
return null
|
||||
}
|
||||
|
||||
return data.linkConnection.edges[0].node.system
|
||||
return data.linkConnection.edges[0].node?.system
|
||||
})
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -25,7 +25,9 @@ export function getConnections({ start_page }: StartPageRefs) {
|
||||
case StartPageEnum.ContentStack.blocks.FullWidthCampaign: {
|
||||
block.full_width_campaign.full_width_campaignConnection.edges.forEach(
|
||||
({ node }) => {
|
||||
connections.push(node.system)
|
||||
if (node.system) {
|
||||
connections.push(node.system)
|
||||
}
|
||||
}
|
||||
)
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user