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,82 +2,31 @@ import { createCounter } from "@scandic-hotels/common/telemetry"
import { router } from "../../.."
import { notFoundError } from "../../../errors"
import {
GetAccountPage,
GetAccountPageRefs,
} from "../../../graphql/Query/AccountPage/AccountPage.graphql"
import { GetAccountPage } from "../../../graphql/Query/AccountPage/AccountPage.graphql"
import { request } from "../../../graphql/request"
import { contentstackExtendedProcedureUID } from "../../../procedures"
import {
generateRefsResponseTag,
generateTag,
generateTagsFromSystem,
} from "../../../utils/generateTag"
import { accountPageRefsSchema, accountPageSchema } from "./output"
import { getConnections } from "./utils"
import { generateTag } from "../../../utils/generateTag"
import { accountPageSchema } from "./output"
import type {
GetAccountPageRefsSchema,
GetAccountPageSchema,
} from "../../../types/accountPage"
import type { GetAccountPageSchema } from "../../../types/accountPage"
import type { TrackingPageData } from "../../types"
export const accountPageQueryRouter = router({
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
const { lang, uid } = ctx
const getAccountPageRefsCounter = createCounter(
"trpc.contentstack.accountPage.get.refs"
)
const metricsRefs = getAccountPageRefsCounter.init({ lang, uid })
metricsRefs.start()
const variables = { locale: lang, uid }
const refsResponse = await request<GetAccountPageRefsSchema>(
GetAccountPageRefs,
variables,
{
key: generateRefsResponseTag(lang, uid),
ttl: "max",
}
)
if (!refsResponse.data) {
metricsRefs.noDataError()
throw notFoundError({
message: "GetAccountPageRefs returned no data",
errorDetails: variables,
})
}
const validatedAccountPageRefs = accountPageRefsSchema.safeParse(
refsResponse.data
)
if (!validatedAccountPageRefs.success) {
metricsRefs.validationError(validatedAccountPageRefs.error)
return null
}
const connections = getConnections(validatedAccountPageRefs.data)
const tags = [
generateTagsFromSystem(lang, connections),
generateTag(lang, validatedAccountPageRefs.data.account_page.system.uid),
].flat()
metricsRefs.success()
const getAccountPageCounter = createCounter(
"trpc.contentstack.accountPage.get"
)
const metrics = getAccountPageCounter.init({ lang, uid })
metrics.start()
const variables = { locale: lang, uid }
const response = await request<GetAccountPageSchema>(
GetAccountPage,
variables,
{
key: tags,
key: generateTag(lang, uid),
ttl: "max",
}
)