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:
Linus Flood
2026-01-27 12:38:36 +00:00
parent a5e214f783
commit 5fc93472f4
193 changed files with 489 additions and 9018 deletions

View File

@@ -2,10 +2,7 @@ import { z } from "zod"
import { DestinationOverviewPageEnum } from "../../../types/destinationOverviewPage"
import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
import {
cardGalleryRefsSchema,
cardGallerySchema,
} from "../schemas/blocks/cardGallery"
import { cardGallerySchema } from "../schemas/blocks/cardGallery"
import { mapLocationSchema } from "../schemas/mapLocation"
import { systemSchema } from "../schemas/system"
@@ -37,23 +34,3 @@ export const destinationOverviewPageSchema = z.object({
url: z.string(),
}),
})
/** REFS */
const destinationOverviewPageCardGalleryRef = z
.object({
__typename: z.literal(
DestinationOverviewPageEnum.ContentStack.blocks.CardGallery
),
})
.merge(cardGalleryRefsSchema)
const blocksRefsSchema = z.discriminatedUnion("__typename", [
destinationOverviewPageCardGalleryRef,
])
export const destinationOverviewPageRefsSchema = z.object({
destination_overview_page: z.object({
blocks: discriminatedUnionArray(blocksRefsSchema.options).nullable(),
system: systemSchema,
}),
})

View File

@@ -3,37 +3,25 @@ import { safeTry } from "@scandic-hotels/common/utils/safeTry"
import { router } from "../../.."
import { notFoundError } from "../../../errors"
import {
GetDestinationOverviewPage,
GetDestinationOverviewPageRefs,
} from "../../../graphql/Query/DestinationOverviewPage/DestinationOverviewPage.graphql"
import { GetDestinationOverviewPage } from "../../../graphql/Query/DestinationOverviewPage/DestinationOverviewPage.graphql"
import { request } from "../../../graphql/request"
import {
contentstackExtendedProcedureUID,
serviceProcedure,
} from "../../../procedures"
import { ApiCountry } from "../../../types/country"
import {
generateRefsResponseTag,
generateTag,
} from "../../../utils/generateTag"
import { generateTag } from "../../../utils/generateTag"
import { getCitiesByCountry } from "../../hotels/services/getCitiesByCountry"
import { getCountries } from "../../hotels/services/getCountries"
import { getHotelIdsByCityId } from "../../hotels/services/getHotelIdsByCityId"
import { getCityPageUrls } from "../destinationCityPage/utils"
import { getCountryPageUrls } from "../destinationCountryPage/utils"
import {
destinationOverviewPageRefsSchema,
destinationOverviewPageSchema,
} from "./output"
import { destinationOverviewPageSchema } from "./output"
import { getSortedDestinationsByLanguage } from "./utils"
import type { Country } from "@scandic-hotels/common/constants/country"
import type {
GetDestinationOverviewPageData,
GetDestinationOverviewPageRefsSchema,
} from "../../../types/destinationOverviewPage"
import type { GetDestinationOverviewPageData } from "../../../types/destinationOverviewPage"
import type { City, DestinationsData } from "../../../types/destinationsData"
import type { TrackingPageData } from "../../types"
@@ -41,43 +29,7 @@ export const destinationOverviewPageQueryRouter = router({
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
const { lang, uid } = ctx
const getDestinationOverviewPageRefsCounter = createCounter(
"trpc.contentstack.destinationOverviewPage.get.refs"
)
const metricsGetDestinationOverviewPageRefs =
getDestinationOverviewPageRefsCounter.init({ lang, uid })
metricsGetDestinationOverviewPageRefs.start()
const variables = { locale: lang, uid }
const refsResponse = await request<GetDestinationOverviewPageRefsSchema>(
GetDestinationOverviewPageRefs,
variables,
{
key: generateRefsResponseTag(lang, uid),
ttl: "max",
}
)
if (!refsResponse.data) {
metricsGetDestinationOverviewPageRefs.noDataError()
throw notFoundError({
message: "GetDestinationOverviewPageRefs returned no data",
errorDetails: variables,
})
}
const validatedRefsData = destinationOverviewPageRefsSchema.safeParse(
refsResponse.data
)
if (!validatedRefsData.success) {
metricsGetDestinationOverviewPageRefs.validationError(
validatedRefsData.error
)
return null
}
metricsGetDestinationOverviewPageRefs.success()
const cacheKey = generateTag(lang, uid)
const getDestinationOverviewPageCounter = createCounter(
"trpc.contentstack.destinationOverviewPage.get"
@@ -87,11 +39,12 @@ export const destinationOverviewPageQueryRouter = router({
metricsGetDestinationOverviewPage.start()
const variables = { locale: lang, uid }
const response = await request<GetDestinationOverviewPageData>(
GetDestinationOverviewPage,
variables,
{
key: generateTag(lang, uid),
key: `${cacheKey}:destinationOverviewPage`,
ttl: "max",
}
)