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,73 +2,26 @@ import { createCounter } from "@scandic-hotels/common/telemetry"
import { router } from "../../.."
import { notFoundError } from "../../../errors"
import {
GetDestinationCountryPage,
GetDestinationCountryPageRefs,
} from "../../../graphql/Query/DestinationCountryPage/DestinationCountryPage.graphql"
import { GetDestinationCountryPage } from "../../../graphql/Query/DestinationCountryPage/DestinationCountryPage.graphql"
import { request } from "../../../graphql/request"
import {
contentStackBaseWithServiceProcedure,
contentstackExtendedProcedureUID,
} from "../../../procedures"
import { ApiCountry } from "../../../types/country"
import { generateRefsResponseTag } from "../../../utils/generateTag"
import { generateTag } from "../../../utils/generateTag"
import { getCityPagesInput } from "./input"
import {
destinationCountryPageRefsSchema,
destinationCountryPageSchema,
} from "./output"
import { generatePageTags, getCityPages } from "./utils"
import { destinationCountryPageSchema } from "./output"
import { getCityPages } from "./utils"
import type {
GetDestinationCountryPageData,
GetDestinationCountryPageRefsSchema,
} from "../../../types/destinationCountryPage"
import type { GetDestinationCountryPageData } from "../../../types/destinationCountryPage"
import type { TrackingPageData } from "../../types"
export const destinationCountryPageQueryRouter = router({
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
const { lang, uid } = ctx
const getDestinationCountryPageRefsCounter = createCounter(
"trpc.contentstack.destinationCountryPage.get.refs"
)
const metricsGetDestinationCountryPageRefs =
getDestinationCountryPageRefsCounter.init({ lang, uid })
metricsGetDestinationCountryPageRefs.start()
const variables = { locale: lang, uid }
const refsResponse = await request<GetDestinationCountryPageRefsSchema>(
GetDestinationCountryPageRefs,
variables,
{
key: generateRefsResponseTag(lang, uid),
ttl: "max",
}
)
if (!refsResponse.data) {
metricsGetDestinationCountryPageRefs.noDataError()
throw notFoundError({
message: "GetDestinationCountryPageRefs returned no data",
errorDetails: variables,
})
}
const validatedRefsData = destinationCountryPageRefsSchema.safeParse(
refsResponse.data
)
if (!validatedRefsData.success) {
metricsGetDestinationCountryPageRefs.validationError(
validatedRefsData.error
)
return null
}
metricsGetDestinationCountryPageRefs.success()
const tags = generatePageTags(validatedRefsData.data, lang)
const cacheKey = generateTag(lang, uid)
const getDestinationCountryPageCounter = createCounter(
"trpc.contentstack.destinationCountryPage.get"
@@ -78,11 +31,12 @@ export const destinationCountryPageQueryRouter = router({
metricsGetDestinationCountryPage.start()
const variables = { locale: lang, uid }
const response = await request<GetDestinationCountryPageData>(
GetDestinationCountryPage,
variables,
{
key: tags,
key: `${cacheKey}:destinationCountryPage`,
ttl: "max",
}
)