Files
web/apps/scandic-web/server/routers/contentstack/collectionPage/query.ts
Joakim Jäderberg fa63b20ed0 Merged in feature/redis (pull request #1478)
Distributed cache

* cache deleteKey now uses an options object instead of a lonely argument variable fuzzy

* merge

* remove debug logs and cleanup

* cleanup

* add fault handling

* add fault handling

* add pid when logging redis client creation

* add identifier when logging redis client creation

* cleanup

* feat: add redis-api as it's own app

* feature: use http wrapper for redis

* feat: add the possibility to fallback to unstable_cache

* Add error handling if redis cache is unresponsive

* add logging for unstable_cache

* merge

* don't cache errors

* fix: metadatabase on branchdeploys

* Handle when /en/destinations throws
add ErrorBoundary

* Add sentry-logging when ErrorBoundary catches exception

* Fix error handling for distributed cache

* cleanup code

* Added Application Insights back

* Update generateApiKeys script and remove duplicate

* Merge branch 'feature/redis' of bitbucket.org:scandic-swap/web into feature/redis

* merge


Approved-by: Linus Flood
2025-03-14 07:54:21 +00:00

79 lines
2.3 KiB
TypeScript

import { GetCollectionPage } from "@/lib/graphql/Query/CollectionPage/CollectionPage.graphql"
import { request } from "@/lib/graphql/request"
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
import { collectionPageSchema } from "./output"
import {
fetchCollectionPageRefs,
generatePageTags,
getCollectionPageCounter,
validateCollectionPageRefs,
} from "./utils"
import {
TrackingChannelEnum,
type TrackingSDKPageData,
} from "@/types/components/tracking"
import type { GetCollectionPageSchema } from "@/types/trpc/routers/contentstack/collectionPage"
export const collectionPageQueryRouter = router({
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
const { lang, uid } = ctx
const collectionPageRefsData = await fetchCollectionPageRefs(lang, uid)
const collectionPageRefs = validateCollectionPageRefs(
collectionPageRefsData,
lang,
uid
)
if (!collectionPageRefs) {
return null
}
const tags = generatePageTags(collectionPageRefs, lang)
getCollectionPageCounter.add(1, { lang, uid })
console.info(
"contentstack.collectionPage start",
JSON.stringify({
query: { lang, uid },
})
)
const response = await request<GetCollectionPageSchema>(
GetCollectionPage,
{ locale: lang, uid },
{
key: tags,
ttl: "max",
}
)
const collectionPage = collectionPageSchema.safeParse(response.data)
if (!collectionPage.success) {
console.error(
`Failed to validate CollectionPage Data - (lang: ${lang}, uid: ${uid})`
)
console.error(collectionPage.error?.format())
return null
}
const tracking: TrackingSDKPageData = {
pageId: collectionPage.data.collection_page.system.uid,
domainLanguage: lang,
publishDate: collectionPage.data.collection_page.system.updated_at,
createDate: collectionPage.data.collection_page.system.created_at,
channel: TrackingChannelEnum["collection-page"],
pageType: "collectionpage",
pageName: collectionPage.data.trackingProps.url,
siteSections: collectionPage.data.trackingProps.url,
siteVersion: "new-web",
}
return {
collectionPage: collectionPage.data.collection_page,
tracking,
}
}),
})