feat(SW-2541): Adjust for ImageVault custom field return types changes
Approved-by: Bianca Widstam Approved-by: Matilda Landström
This commit is contained in:
@@ -60,6 +60,7 @@ fragment Content_ContentPageRefs on ContentPageBlocksContent {
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
...ImageContainerRef
|
||||
...AccountPageRef
|
||||
...CampaignOverviewPageRef
|
||||
...CampaignPageRef
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { AccountPageEnum } from "../../../types/accountPageEnum"
|
||||
import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
|
||||
import {
|
||||
@@ -15,7 +17,6 @@ import {
|
||||
shortcutsSchema,
|
||||
} from "../schemas/blocks/shortcuts"
|
||||
import { textContentSchema } from "../schemas/blocks/textContent"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
const accountPageAccordions = z
|
||||
@@ -54,7 +55,7 @@ export const accountPageSchema = z.object({
|
||||
content: discriminatedUnionArray(blocksSchema.options),
|
||||
heading: z.string().nullable(),
|
||||
preamble: z.string().nullable(),
|
||||
hero_image: tempImageVaultAssetSchema,
|
||||
hero_image: transformedImageVaultAssetSchema,
|
||||
hero_image_active: z
|
||||
.boolean()
|
||||
.nullable()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { CampaignPageEnum } from "../../../types/campaignPage"
|
||||
@@ -14,7 +15,6 @@ import {
|
||||
} from "../schemas/blocks/carouselCards"
|
||||
import { essentialsBlockSchema } from "../schemas/blocks/essentials"
|
||||
import { campaignPageHotelListingSchema } from "../schemas/blocks/hotelListing"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import {
|
||||
linkConnectionRefs,
|
||||
linkConnectionSchema,
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
import { systemSchema } from "../schemas/system"
|
||||
import { getCarouselCardsBlockWithBookingCodeLinks } from "./utils"
|
||||
|
||||
import type { ImageVaultAsset } from "../../../types/imageVault"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
const campaignPageEssentials = z
|
||||
.object({
|
||||
@@ -56,7 +56,7 @@ export const blocksSchema = z.discriminatedUnion("__typename", [
|
||||
])
|
||||
|
||||
export const heroSchema = z.object({
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
heading: z.string(),
|
||||
theme: z.enum(["Peach", "Burgundy"]).default("Peach"),
|
||||
benefits: z
|
||||
@@ -206,7 +206,7 @@ export const campaignPagesByHotelUidSchema = z
|
||||
sort_order: z.number().nullish(),
|
||||
card_content: z
|
||||
.object({
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
heading: z.string().nullish(),
|
||||
text: z.string().nullish(),
|
||||
})
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { CollectionPageEnum } from "../../../types/collectionPage"
|
||||
import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
|
||||
import {
|
||||
@@ -15,7 +17,6 @@ import {
|
||||
shortcutsSchema,
|
||||
} from "../schemas/blocks/shortcuts"
|
||||
import { uspGridRefsSchema, uspGridSchema } from "../schemas/blocks/uspGrid"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import {
|
||||
linkAndTitleSchema,
|
||||
linkConnectionRefs,
|
||||
@@ -87,7 +88,7 @@ const topPrimaryButtonSchema = linkAndTitleSchema
|
||||
// Content Page Schema and types
|
||||
export const collectionPageSchema = z.object({
|
||||
collection_page: z.object({
|
||||
hero_image: tempImageVaultAssetSchema,
|
||||
hero_image: transformedImageVaultAssetSchema,
|
||||
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
||||
title: z.string(),
|
||||
header: z.object({
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { ContentPageEnum } from "../../../types/contentPage"
|
||||
import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
|
||||
import {
|
||||
@@ -30,7 +32,6 @@ import {
|
||||
dynamicContentRefsSchema as headerDynamicContentRefsSchema,
|
||||
dynamicContentSchema as headerDynamicContentSchema,
|
||||
} from "../schemas/headers/dynamicContent"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import {
|
||||
linkAndTitleSchema,
|
||||
linkConnectionRefs,
|
||||
@@ -203,7 +204,7 @@ const topPrimaryButtonSchema = linkAndTitleSchema
|
||||
// Content Page Schema and types
|
||||
export const contentPageSchema = z.object({
|
||||
content_page: z.object({
|
||||
hero_image: tempImageVaultAssetSchema,
|
||||
hero_image: transformedImageVaultAssetSchema,
|
||||
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
||||
sidebar: discriminatedUnionArray(sidebarSchema.options).nullable(),
|
||||
title: z.string(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { DestinationCityPageEnum } from "../../../types/destinationCityPage"
|
||||
@@ -10,7 +11,6 @@ import {
|
||||
accordionSchema,
|
||||
} from "../schemas/blocks/accordion"
|
||||
import { contentRefsSchema, contentSchema } from "../schemas/blocks/content"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import { mapLocationSchema } from "../schemas/mapLocation"
|
||||
import {
|
||||
linkRefsUnionSchema,
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
} from "../schemas/pageLinks"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
import type { ImageVaultAsset } from "../../../types/imageVault"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
export const destinationCityPageDestinationSettingsSchema = z
|
||||
.object({
|
||||
@@ -73,7 +73,7 @@ export const destinationCityListDataSchema = z
|
||||
)
|
||||
.nullish(),
|
||||
images: z
|
||||
.array(z.object({ image: tempImageVaultAssetSchema }))
|
||||
.array(z.object({ image: transformedImageVaultAssetSchema }))
|
||||
.transform((images) =>
|
||||
images
|
||||
.map((image) => image.image)
|
||||
@@ -128,7 +128,7 @@ export const destinationCityPageSchema = z.object({
|
||||
.nullish()
|
||||
.transform((experiences) => experiences?.destination_experiences ?? []),
|
||||
images: z
|
||||
.array(z.object({ image: tempImageVaultAssetSchema }))
|
||||
.array(z.object({ image: transformedImageVaultAssetSchema }))
|
||||
.transform((images) =>
|
||||
images
|
||||
.map((image) => image.image)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { Country } from "../../../types/country"
|
||||
@@ -10,7 +11,6 @@ import {
|
||||
accordionSchema,
|
||||
} from "../schemas/blocks/accordion"
|
||||
import { contentRefsSchema, contentSchema } from "../schemas/blocks/content"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import { mapLocationSchema } from "../schemas/mapLocation"
|
||||
import {
|
||||
linkRefsUnionSchema,
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
} from "../schemas/pageLinks"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
import type { ImageVaultAsset } from "../../../types/imageVault"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
export const destinationCountryPageContent = z
|
||||
.object({
|
||||
@@ -57,7 +57,7 @@ export const destinationCountryPageSchema = z.object({
|
||||
})
|
||||
.transform(({ destination_experiences }) => destination_experiences),
|
||||
images: z
|
||||
.array(z.object({ image: tempImageVaultAssetSchema }))
|
||||
.array(z.object({ image: transformedImageVaultAssetSchema }))
|
||||
.transform((images) =>
|
||||
images
|
||||
.map((image) => image.image)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { LoyaltyPageEnum } from "../../../enums/loyaltyPage"
|
||||
import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
|
||||
import {
|
||||
@@ -18,7 +20,6 @@ import {
|
||||
shortcutsRefsSchema,
|
||||
shortcutsSchema,
|
||||
} from "../schemas/blocks/shortcuts"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import {
|
||||
contentRefsSchema as sidebarContentRefsSchema,
|
||||
contentSchema as sidebarContentSchema,
|
||||
@@ -166,7 +167,7 @@ export const loyaltyPageSchema = z.object({
|
||||
.object({
|
||||
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
||||
heading: z.string().optional(),
|
||||
hero_image: tempImageVaultAssetSchema,
|
||||
hero_image: transformedImageVaultAssetSchema,
|
||||
preamble: z.string().optional(),
|
||||
sidebar: discriminatedUnionArray(sidebarSchema.options).nullable(),
|
||||
title: z.string().optional(),
|
||||
|
||||
@@ -2,18 +2,18 @@ import { z } from "zod"
|
||||
|
||||
import { findMyBooking } from "@scandic-hotels/common/constants/routes/findMyBooking"
|
||||
import { myStay } from "@scandic-hotels/common/constants/routes/myStay"
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { attributesSchema as hotelAttributesSchema } from "../../../routers/hotels/schemas/hotel"
|
||||
import { Country } from "../../../types/country"
|
||||
import { RTETypeEnum } from "../../../types/RTEenums"
|
||||
import { additionalDataAttributesSchema } from "../../hotels/schemas/hotel/include/additionalData"
|
||||
import { imageSchema } from "../../hotels/schemas/image"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import type { ImageVaultAsset } from "../../../types/imageVault"
|
||||
import type { LanguageSwitcherData } from "../../../types/languageSwitcher"
|
||||
|
||||
const metaDataJsonSchema = z.object({
|
||||
@@ -56,7 +56,7 @@ export const rawMetadataSchema = z.object({
|
||||
title: z.string().nullish(),
|
||||
description: z.string().nullish(),
|
||||
noindex: z.boolean().nullish(),
|
||||
seo_image: tempImageVaultAssetSchema.nullable(),
|
||||
seo_image: transformedImageVaultAssetSchema,
|
||||
})
|
||||
.nullish(),
|
||||
breadcrumbs: z
|
||||
@@ -97,12 +97,12 @@ export const rawMetadataSchema = z.object({
|
||||
.object({
|
||||
heading: z.string().nullish(),
|
||||
preamble: z.string().nullish(),
|
||||
hero_image: tempImageVaultAssetSchema.nullable(),
|
||||
hero_image: transformedImageVaultAssetSchema,
|
||||
})
|
||||
.nullish(),
|
||||
hero_image: tempImageVaultAssetSchema.nullable(),
|
||||
hero_image: transformedImageVaultAssetSchema,
|
||||
images: z
|
||||
.array(z.object({ image: tempImageVaultAssetSchema }).nullish())
|
||||
.array(z.object({ image: transformedImageVaultAssetSchema }).nullish())
|
||||
.transform((images) =>
|
||||
images
|
||||
.map((image) => image?.image)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { HotelPageEnum } from "../../../../types/hotelPageEnum"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import {
|
||||
collectionPageRefSchema,
|
||||
collectionPageSchema,
|
||||
@@ -18,7 +18,7 @@ export const activitiesCardSchema = z.object({
|
||||
.default(HotelPageEnum.ContentStack.blocks.ActivitiesCard),
|
||||
upcoming_activities_card: z
|
||||
.object({
|
||||
background_image: tempImageVaultAssetSchema,
|
||||
background_image: transformedImageVaultAssetSchema,
|
||||
body_text: z.string(),
|
||||
cta_text: z.string(),
|
||||
sidepeek_cta_text: z.string(),
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { campaignPageRefSchema } from "../pageLinks"
|
||||
|
||||
export const campaignPageCardSchema = z.object({
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
heading: z.string(),
|
||||
text: z.string(),
|
||||
})
|
||||
@@ -29,7 +29,7 @@ export const allCampaignsSchema = z.object({
|
||||
url: z.string(),
|
||||
card_content: z
|
||||
.object({
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
heading: z.string().nullish(),
|
||||
text: z.string().nullish(),
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { tempImageVaultAssetSchema } from "../../imageVault"
|
||||
import { systemSchema } from "../../system"
|
||||
import { buttonSchema } from "../utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../utils/linkConnection"
|
||||
@@ -10,7 +11,7 @@ export const contentCardSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.ContentCard),
|
||||
title: z.string(),
|
||||
heading: z.string(),
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
body_text: z.string(),
|
||||
promo_text: z.string().optional(),
|
||||
has_card_link: z.boolean(),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { tempImageVaultAssetSchema } from "../../imageVault"
|
||||
import { systemSchema } from "../../system"
|
||||
import { buttonSchema } from "../utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../utils/linkConnection"
|
||||
@@ -19,7 +20,7 @@ export const infoCardBlockSchema = z.object({
|
||||
scripted_top_title: z.string().optional(),
|
||||
heading: z.string().optional().default(""),
|
||||
body_text: z.string().optional().default(""),
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
theme: z.enum(INFO_CARD_THEMES).nullable(),
|
||||
title: z.string().optional(),
|
||||
primary_button: buttonSchema.optional().nullable(),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { tempImageVaultAssetSchema } from "../../imageVault"
|
||||
import { systemSchema } from "../../system"
|
||||
import { buttonSchema } from "../utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../utils/linkConnection"
|
||||
@@ -11,7 +12,7 @@ export const loyaltyCardBlockSchema = z.object({
|
||||
body_text: z.string().optional(),
|
||||
heading: z.string().optional().default(""),
|
||||
// JSON - ImageVault Image
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
link: buttonSchema,
|
||||
system: systemSchema,
|
||||
title: z.string().optional(),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { tempImageVaultAssetSchema } from "../../imageVault"
|
||||
import {
|
||||
accountPageSchema,
|
||||
campaignOverviewPageSchema,
|
||||
@@ -26,7 +27,7 @@ export const teaserCardBlockSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.TeaserCard),
|
||||
heading: z.string().default(""),
|
||||
body_text: z.string().default(""),
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
primary_button: buttonSchema,
|
||||
secondary_button: buttonSchema,
|
||||
has_primary_button: z.boolean().default(false),
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { scriptedCardThemeEnum } from "../../../../enums/scriptedCard"
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import {
|
||||
CardsGridEnum,
|
||||
CardsGridLayoutEnum,
|
||||
} from "../../../../types/cardsGridEnum"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { systemSchema } from "../system"
|
||||
import {
|
||||
infoCardBlockRefsSchema,
|
||||
@@ -28,7 +29,7 @@ import { linkConnectionRefsSchema } from "./utils/linkConnection"
|
||||
export const cardBlockSchema = z.object({
|
||||
__typename: z.literal(CardsGridEnum.cards.Card),
|
||||
// JSON - ImageVault Image
|
||||
background_image: tempImageVaultAssetSchema,
|
||||
background_image: transformedImageVaultAssetSchema,
|
||||
body_text: z.string().optional().default(""),
|
||||
has_primary_button: z.boolean().default(false),
|
||||
has_secondary_button: z.boolean().default(false),
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
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 { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { systemSchema } from "../system"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
|
||||
@@ -13,7 +14,7 @@ export const fullWidthCampaignSchema = z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
background_image: tempImageVaultAssetSchema,
|
||||
background_image: transformedImageVaultAssetSchema,
|
||||
heading: z.string().optional(),
|
||||
body_text: z.string().optional(),
|
||||
scripted_top_title: z.string().optional(),
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { ContentEnum } from "../../../../types/content"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { systemSchema } from "../system"
|
||||
|
||||
export const imageContainerSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.ImageContainer),
|
||||
// JSON - ImageVault Image
|
||||
image_left: tempImageVaultAssetSchema,
|
||||
// JSON - ImageVault Image
|
||||
image_right: tempImageVaultAssetSchema,
|
||||
image_left: transformedImageVaultAssetSchema,
|
||||
image_right: transformedImageVaultAssetSchema,
|
||||
system: systemSchema,
|
||||
title: z.string().optional(),
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "./utils/linkConnection"
|
||||
|
||||
@@ -11,7 +12,7 @@ export const joinScandicFriendsSchema = z.object({
|
||||
scripted_top_title: z.string(),
|
||||
title: z.string(),
|
||||
preamble: z.string(),
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
show_usp: z.boolean().default(false),
|
||||
usp: z.array(z.string()),
|
||||
has_primary_button: z.boolean().default(false),
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { insertResponseToImageVaultAsset } from "../../../utils/imageVault"
|
||||
|
||||
import type { ImageVaultAssetResponse } from "../../../types/imageVault"
|
||||
|
||||
const metaData = z.object({
|
||||
DefinitionType: z.number().nullable().optional(),
|
||||
Description: z.string().nullable(),
|
||||
LanguageId: z.number().nullable(),
|
||||
MetadataDefinitionId: z.number(),
|
||||
Name: z.string(),
|
||||
Value: z.string().nullable(),
|
||||
})
|
||||
|
||||
export const focalPointSchema = z.object({
|
||||
x: z.number(),
|
||||
y: z.number(),
|
||||
})
|
||||
|
||||
/**
|
||||
* Defines a media asset, original or conversion
|
||||
*/
|
||||
const mediaConversion = z.object({
|
||||
/**
|
||||
* Aspect ratio of the conversion
|
||||
*/
|
||||
AspectRatio: z.number(),
|
||||
/**
|
||||
* Content type of the conversion
|
||||
*/
|
||||
ContentType: z.string(),
|
||||
/**
|
||||
* Aspect ratio of the selected/requested format
|
||||
*/
|
||||
FormatAspectRatio: z.number(),
|
||||
/**
|
||||
* Height of the selected/requested format
|
||||
*/
|
||||
FormatHeight: z.number(),
|
||||
/**
|
||||
* Width of the selected/requested format
|
||||
*/
|
||||
FormatWidth: z.number(),
|
||||
/**
|
||||
* Height, in pixels, of the conversion
|
||||
*/
|
||||
Height: z.number(),
|
||||
/**
|
||||
* Html representing the conversion
|
||||
*/
|
||||
Html: z.string(),
|
||||
/**
|
||||
* Id of the selected media format
|
||||
*/
|
||||
MediaFormatId: z.number(),
|
||||
/**
|
||||
* Name of the media format
|
||||
*/
|
||||
MediaFormatName: z.string(),
|
||||
/**
|
||||
* Name of the conversion
|
||||
*/
|
||||
Name: z.string(),
|
||||
/**
|
||||
* The url to the conversion
|
||||
*/
|
||||
Url: z.string(),
|
||||
/**
|
||||
* Width, in pixels, of the conversion
|
||||
*/
|
||||
Width: z.number(),
|
||||
})
|
||||
|
||||
/**
|
||||
* The response from ImageVault when inserting an asset
|
||||
*/
|
||||
export const imageVaultAssetSchema = z.object({
|
||||
/**
|
||||
* The media item id of the asset
|
||||
*/
|
||||
Id: z.number(),
|
||||
/**
|
||||
* The id of the vault where the asset resides
|
||||
*/
|
||||
VaultId: z.number(),
|
||||
/**
|
||||
* The name of the asset
|
||||
*/
|
||||
Name: z.string(),
|
||||
/**
|
||||
* The conversion selected by the user. Is an array but will only contain one object
|
||||
*/
|
||||
MediaConversions: z.array(mediaConversion),
|
||||
Metadata: z.array(metaData),
|
||||
/**
|
||||
* Date when the asset was added to ImageVault
|
||||
*/
|
||||
DateAdded: z.string(),
|
||||
/**
|
||||
* Name of the user that added the asset to ImageVault
|
||||
*/
|
||||
AddedBy: z.string(),
|
||||
FocalPoint: focalPointSchema.optional(),
|
||||
})
|
||||
|
||||
export const imageVaultAssetTransformedSchema = imageVaultAssetSchema.transform(
|
||||
(rawData) => {
|
||||
const alt = rawData.Metadata?.find((meta) =>
|
||||
meta.Name.includes("AltText_")
|
||||
)?.Value
|
||||
|
||||
const caption = rawData.Metadata?.find((meta) =>
|
||||
meta.Name.includes("Title_")
|
||||
)?.Value
|
||||
const mediaConversion = rawData.MediaConversions[0]
|
||||
const aspectRatio =
|
||||
mediaConversion.FormatAspectRatio ||
|
||||
mediaConversion.AspectRatio ||
|
||||
mediaConversion.Width / mediaConversion.Height
|
||||
|
||||
return {
|
||||
url: mediaConversion.Url,
|
||||
id: rawData.Id,
|
||||
meta: {
|
||||
alt,
|
||||
caption,
|
||||
},
|
||||
title: rawData.Name,
|
||||
dimensions: {
|
||||
width: mediaConversion.Width,
|
||||
height: mediaConversion.Height,
|
||||
aspectRatio,
|
||||
},
|
||||
focalPoint: rawData.FocalPoint || { x: 50, y: 50 },
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
export const tempImageVaultAssetSchema = imageVaultAssetSchema
|
||||
.nullable()
|
||||
.optional()
|
||||
.or(
|
||||
// Temp since there is a bug in Contentstack
|
||||
// sending empty objects when there has been an
|
||||
// image selected previously but has since been
|
||||
// deleted
|
||||
z.object({})
|
||||
)
|
||||
.transform((data) => {
|
||||
if (data) {
|
||||
if ("Name" in data) {
|
||||
return makeImageVaultImage(data)
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
|
||||
function makeImageVaultImage(image: any) {
|
||||
return image && !!Object.keys(image).length
|
||||
? insertResponseToImageVaultAsset(image as ImageVaultAssetResponse)
|
||||
: undefined
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
|
||||
import {
|
||||
cardGridRefsSchema,
|
||||
@@ -17,7 +19,6 @@ import {
|
||||
joinScandicFriendsBlockRefsSchema,
|
||||
joinScandicFriendsBlockSchema,
|
||||
} from "../schemas/blocks/joinScandicFriends"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
import { StartPageEnum } from "./utils"
|
||||
|
||||
@@ -57,7 +58,7 @@ export const startPageSchema = z.object({
|
||||
title: z.string(),
|
||||
header: z.object({
|
||||
heading: z.string(),
|
||||
hero_image: tempImageVaultAssetSchema,
|
||||
hero_image: transformedImageVaultAssetSchema,
|
||||
}),
|
||||
blocks: discriminatedUnionArray(blocksSchema.options)
|
||||
.nullable()
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
export interface FocalPoint {
|
||||
x: number
|
||||
y: number
|
||||
}
|
||||
|
||||
export interface Image {
|
||||
description?: string | null
|
||||
dimension: {
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
* @file TypeScript typings for ImageVault
|
||||
*
|
||||
* The types in this file are based on the source maps of the downloaded
|
||||
* distribution at https://clientscript.imagevault.se/Installation/ImageVaultInsertMedia
|
||||
*
|
||||
* They have been clean up and amended to.
|
||||
*/
|
||||
|
||||
import type { z } from "zod"
|
||||
|
||||
import type { imageVaultAssetSchema } from "../routers/contentstack/schemas/imageVault"
|
||||
import type { FocalPoint } from "./image"
|
||||
|
||||
export type ImageVaultAssetResponse = z.infer<typeof imageVaultAssetSchema>
|
||||
|
||||
export type ImageVaultAsset = {
|
||||
id: number
|
||||
title: string
|
||||
url: string
|
||||
dimensions: {
|
||||
width: number
|
||||
height: number
|
||||
aspectRatio: number
|
||||
}
|
||||
meta: { alt: string | undefined | null; caption: string | undefined | null }
|
||||
focalPoint: FocalPoint
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import type {
|
||||
ImageVaultAsset,
|
||||
ImageVaultAssetResponse,
|
||||
} from "../types/imageVault"
|
||||
|
||||
export function insertResponseToImageVaultAsset(
|
||||
response: ImageVaultAssetResponse
|
||||
): ImageVaultAsset {
|
||||
const alt = response.Metadata?.find((meta) =>
|
||||
meta.Name.includes("AltText_")
|
||||
)?.Value
|
||||
|
||||
const caption = response.Metadata?.find((meta) =>
|
||||
meta.Name.includes("Title_")
|
||||
)?.Value
|
||||
|
||||
const mediaConversion = response.MediaConversions[0]
|
||||
const aspectRatio =
|
||||
mediaConversion.FormatAspectRatio ||
|
||||
mediaConversion.AspectRatio ||
|
||||
mediaConversion.Width / mediaConversion.Height
|
||||
|
||||
return {
|
||||
url: mediaConversion.Url,
|
||||
id: response.Id,
|
||||
meta: {
|
||||
alt,
|
||||
caption,
|
||||
},
|
||||
title: response.Name,
|
||||
dimensions: {
|
||||
width: mediaConversion.Width,
|
||||
height: mediaConversion.Height,
|
||||
aspectRatio,
|
||||
},
|
||||
focalPoint: response.FocalPoint || { x: 50, y: 50 },
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user