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,78 +2,20 @@ import { createCounter } from "@scandic-hotels/common/telemetry"
import { router } from "../../.."
import { notFoundError } from "../../../errors"
import {
GetLoyaltyPage,
GetLoyaltyPageRefs,
} from "../../../graphql/Query/LoyaltyPage/LoyaltyPage.graphql"
import { GetLoyaltyPage } from "../../../graphql/Query/LoyaltyPage/LoyaltyPage.graphql"
import { request } from "../../../graphql/request"
import { contentstackExtendedProcedureUID } from "../../../procedures"
import {
generateRefsResponseTag,
generateTag,
generateTagsFromAssetSystem,
generateTagsFromSystem,
} from "../../../utils/generateTag"
import { loyaltyPageRefsSchema, loyaltyPageSchema } from "./output"
import { getConnections } from "./utils"
import { generateTag } from "../../../utils/generateTag"
import { loyaltyPageSchema } from "./output"
import type {
GetLoyaltyPageRefsSchema,
GetLoyaltyPageSchema,
} from "../../../types/loyaltyPage"
import type { GetLoyaltyPageSchema } from "../../../types/loyaltyPage"
import type { TrackingPageData } from "../../types"
export const loyaltyPageQueryRouter = router({
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
const { lang, uid } = ctx
const getLoyaltyPageRefsCounter = createCounter(
"trpc.contentstack.loyaltyPage.get.refs"
)
const metricsGetLoyaltyPageRefs = getLoyaltyPageRefsCounter.init({
lang,
uid,
})
metricsGetLoyaltyPageRefs.start()
const variables = { locale: lang, uid }
const refsResponse = await request<GetLoyaltyPageRefsSchema>(
GetLoyaltyPageRefs,
variables,
{
key: generateRefsResponseTag(lang, uid),
ttl: "max",
}
)
if (!refsResponse.data) {
metricsGetLoyaltyPageRefs.noDataError()
throw notFoundError({
message: "GetLoyaltyPageRefs returned no data",
errorDetails: { ...variables },
})
}
const validatedLoyaltyPageRefs = loyaltyPageRefsSchema.safeParse(
refsResponse.data
)
if (!validatedLoyaltyPageRefs.success) {
metricsGetLoyaltyPageRefs.validationError(validatedLoyaltyPageRefs.error)
return null
}
metricsGetLoyaltyPageRefs.success()
const { connections, assetConnections } = getConnections(
validatedLoyaltyPageRefs.data
)
const tags = [
generateTagsFromSystem(lang, connections),
generateTagsFromAssetSystem(assetConnections),
generateTag(lang, validatedLoyaltyPageRefs.data.loyalty_page.system.uid),
].flat()
const cacheKey = generateTag(lang, uid)
const getLoyaltyPageCounter = createCounter(
"trpc.contentstack.loyaltyPage.get"
@@ -82,11 +24,12 @@ export const loyaltyPageQueryRouter = router({
metricsGetLoyaltyPage.start()
const variables = { locale: lang, uid }
const response = await request<GetLoyaltyPageSchema>(
GetLoyaltyPage,
variables,
{
key: tags,
key: `${cacheKey}:loyaltyPage`,
ttl: "max",
}
)