feat(SW-237): Cache revalidation support
This commit is contained in:
@@ -6,6 +6,7 @@ import { z } from "zod"
|
|||||||
import { Lang } from "@/constants/languages"
|
import { Lang } from "@/constants/languages"
|
||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { internalServerError } from "@/server/errors/next"
|
import { internalServerError } from "@/server/errors/next"
|
||||||
|
import { affix as bookingwidgetAffix } from "@/server/routers/contentstack/bookingwidget/utils"
|
||||||
import { affix as breadcrumbsAffix } from "@/server/routers/contentstack/breadcrumbs/utils"
|
import { affix as breadcrumbsAffix } from "@/server/routers/contentstack/breadcrumbs/utils"
|
||||||
import { languageSwitcherAffix } from "@/server/routers/contentstack/languageSwitcher/utils"
|
import { languageSwitcherAffix } from "@/server/routers/contentstack/languageSwitcher/utils"
|
||||||
|
|
||||||
@@ -29,6 +30,11 @@ const validateJsonBody = z.object({
|
|||||||
locale: z.nativeEnum(Lang),
|
locale: z.nativeEnum(Lang),
|
||||||
uid: z.string(),
|
uid: z.string(),
|
||||||
url: z.string().optional(),
|
url: z.string().optional(),
|
||||||
|
page_settings: z
|
||||||
|
.object({
|
||||||
|
hide_booking_widget: z.boolean(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
@@ -105,6 +111,17 @@ export async function POST(request: NextRequest) {
|
|||||||
revalidateTag(breadcrumbsTag)
|
revalidateTag(breadcrumbsTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entry.page_settings?.hide_booking_widget) {
|
||||||
|
const bookingwidgetTag = generateTag(
|
||||||
|
entry.locale,
|
||||||
|
entry.uid,
|
||||||
|
bookingwidgetAffix
|
||||||
|
)
|
||||||
|
|
||||||
|
console.info(`Revalidating breadcrumbsTag: ${bookingwidgetTag}`)
|
||||||
|
revalidateTag(bookingwidgetTag)
|
||||||
|
}
|
||||||
|
|
||||||
return Response.json({ revalidated: true, now: Date.now() })
|
return Response.json({ revalidated: true, now: Date.now() })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to revalidate tag(s)")
|
console.error("Failed to revalidate tag(s)")
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { metrics } from "@opentelemetry/api"
|
import { metrics } from "@opentelemetry/api"
|
||||||
import { ValueOf } from "next/dist/shared/lib/constants"
|
|
||||||
|
|
||||||
import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
|
import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
|
||||||
import {
|
import {
|
||||||
@@ -14,11 +13,7 @@ import { request } from "@/lib/graphql/request"
|
|||||||
import { notFound } from "@/server/errors/trpc"
|
import { notFound } from "@/server/errors/trpc"
|
||||||
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
||||||
|
|
||||||
import {
|
import { generateRefsResponseTag, generateTag } from "@/utils/generateTag"
|
||||||
generateRefsResponseTag,
|
|
||||||
generateRefTag,
|
|
||||||
generateTag,
|
|
||||||
} from "@/utils/generateTag"
|
|
||||||
|
|
||||||
import { langInput } from "./input"
|
import { langInput } from "./input"
|
||||||
import {
|
import {
|
||||||
@@ -33,8 +28,6 @@ import {
|
|||||||
validateHeaderConfigSchema,
|
validateHeaderConfigSchema,
|
||||||
} from "./output"
|
} from "./output"
|
||||||
|
|
||||||
import { ContentTypeEnum } from "@/types/requests/contentType"
|
|
||||||
|
|
||||||
const meter = metrics.getMeter("trpc.contentstack.base")
|
const meter = metrics.getMeter("trpc.contentstack.base")
|
||||||
// OpenTelemetry metrics: ContactConfig
|
// OpenTelemetry metrics: ContactConfig
|
||||||
const getContactConfigCounter = meter.createCounter(
|
const getContactConfigCounter = meter.createCounter(
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
validateBookingWidgetToggleSchema,
|
validateBookingWidgetToggleSchema,
|
||||||
ValidateBookingWidgetToggleType,
|
ValidateBookingWidgetToggleType,
|
||||||
} from "./output"
|
} from "./output"
|
||||||
|
import { affix as bookingwidgetAffix } from "./utils"
|
||||||
|
|
||||||
import { ContentTypeEnum } from "@/types/requests/contentType"
|
import { ContentTypeEnum } from "@/types/requests/contentType"
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ export const bookingwidgetQueryRouter = router({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
next: {
|
next: {
|
||||||
tags: [generateTag(lang, uid, "bookingwidget")],
|
tags: [generateTag(lang, uid, bookingwidgetAffix)],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
1
server/routers/contentstack/bookingwidget/utils.ts
Normal file
1
server/routers/contentstack/bookingwidget/utils.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const affix = "bookingwidget"
|
||||||
Reference in New Issue
Block a user