Merged in feat/sentry (pull request #1089)
This commit is contained in:
committed by
Joakim Jäderberg
parent
e0c5b59860
commit
3982b1ba56
@@ -1,5 +1,5 @@
|
||||
import { RoomData } from "@/types/hotel"
|
||||
import { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"
|
||||
import type { RoomData } from "@/types/hotel"
|
||||
import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"
|
||||
|
||||
export function getBookedHotelRoom(
|
||||
rooms: RoomData[] | undefined,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import {
|
||||
GetAccountPage,
|
||||
GetAccountPageRefs,
|
||||
@@ -26,6 +25,7 @@ import type {
|
||||
GetAccountPageRefsSchema,
|
||||
GetAccountPageSchema,
|
||||
} from "@/types/trpc/routers/contentstack/accountPage"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
const meter = metrics.getMeter("trpc.accountPage")
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { batchRequest } from "@/lib/graphql/batchRequest"
|
||||
import {
|
||||
GetContentPage,
|
||||
@@ -19,6 +18,7 @@ import {
|
||||
type TrackingSDKPageData,
|
||||
} from "@/types/components/tracking"
|
||||
import type { GetContentPageSchema } from "@/types/trpc/routers/contentstack/contentPage"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
export const contentPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import {
|
||||
GetLoyaltyPage,
|
||||
GetLoyaltyPageRefs,
|
||||
@@ -20,12 +19,13 @@ import { getConnections } from "./utils"
|
||||
|
||||
import {
|
||||
TrackingChannelEnum,
|
||||
TrackingSDKPageData,
|
||||
type TrackingSDKPageData,
|
||||
} from "@/types/components/tracking"
|
||||
import type {
|
||||
GetLoyaltyPageRefsSchema,
|
||||
GetLoyaltyPageSchema,
|
||||
} from "@/types/trpc/routers/contentstack/loyaltyPage"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
const meter = metrics.getMeter("trpc.loyaltyPage")
|
||||
// OpenTelemetry metrics: LoyaltyPage
|
||||
|
||||
+33
-21
@@ -1,3 +1,4 @@
|
||||
import * as Sentry from "@sentry/node"
|
||||
import { initTRPC } from "@trpc/server"
|
||||
import { experimental_nextAppDirCaller } from "@trpc/server/adapters/next-app-dir"
|
||||
import { ZodError } from "zod"
|
||||
@@ -36,31 +37,42 @@ const t = initTRPC
|
||||
},
|
||||
})
|
||||
|
||||
const sentryMiddleware = t.middleware(
|
||||
Sentry.trpcMiddleware({
|
||||
attachRpcInput: true,
|
||||
})
|
||||
)
|
||||
|
||||
export const { createCallerFactory, mergeRouters, router } = t
|
||||
export const publicProcedure = t.procedure
|
||||
export const contentstackBaseProcedure = t.procedure.use(async function (opts) {
|
||||
if (!opts.ctx.lang) {
|
||||
// When fetching data client side with TRPC we don't pass through middlewares and therefore do not get the lang through headers
|
||||
// We can then pass lang as an input in the request and set it to the context in the procedure
|
||||
const input = await opts.getRawInput()
|
||||
const parsedInput = langInput.safeParse(input)
|
||||
if (!parsedInput.success) {
|
||||
throw badRequestError("Missing Lang in tRPC context")
|
||||
const baseProcedure = t.procedure.use(sentryMiddleware)
|
||||
|
||||
export const publicProcedure = baseProcedure
|
||||
|
||||
export const contentstackBaseProcedure = baseProcedure.use(
|
||||
async function (opts) {
|
||||
if (!opts.ctx.lang) {
|
||||
// When fetching data client side with TRPC we don't pass through middlewares and therefore do not get the lang through headers
|
||||
// We can then pass lang as an input in the request and set it to the context in the procedure
|
||||
const input = await opts.getRawInput()
|
||||
const parsedInput = langInput.safeParse(input)
|
||||
if (!parsedInput.success) {
|
||||
throw badRequestError("Missing Lang in tRPC context")
|
||||
}
|
||||
|
||||
return opts.next({
|
||||
ctx: {
|
||||
lang: parsedInput.data.lang,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return opts.next({
|
||||
ctx: {
|
||||
lang: parsedInput.data.lang,
|
||||
lang: opts.ctx.lang,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return opts.next({
|
||||
ctx: {
|
||||
lang: opts.ctx.lang,
|
||||
},
|
||||
})
|
||||
})
|
||||
)
|
||||
export const contentstackExtendedProcedureUID = contentstackBaseProcedure.use(
|
||||
async function (opts) {
|
||||
if (!opts.ctx.uid) {
|
||||
@@ -74,7 +86,7 @@ export const contentstackExtendedProcedureUID = contentstackBaseProcedure.use(
|
||||
})
|
||||
}
|
||||
)
|
||||
export const protectedProcedure = t.procedure.use(async function (opts) {
|
||||
export const protectedProcedure = baseProcedure.use(async function (opts) {
|
||||
const authRequired = opts.meta?.authRequired ?? true
|
||||
const session = await opts.ctx.auth()
|
||||
if (!authRequired && env.NODE_ENV === "development") {
|
||||
@@ -99,7 +111,7 @@ export const protectedProcedure = t.procedure.use(async function (opts) {
|
||||
})
|
||||
})
|
||||
|
||||
export const safeProtectedProcedure = t.procedure.use(async function (opts) {
|
||||
export const safeProtectedProcedure = baseProcedure.use(async function (opts) {
|
||||
const authRequired = opts.meta?.authRequired ?? true
|
||||
|
||||
let session: Session | null = await opts.ctx.auth()
|
||||
@@ -121,7 +133,7 @@ export const safeProtectedProcedure = t.procedure.use(async function (opts) {
|
||||
})
|
||||
})
|
||||
|
||||
export const serviceProcedure = t.procedure.use(async function (opts) {
|
||||
export const serviceProcedure = baseProcedure.use(async (opts) => {
|
||||
const { access_token } = await getServiceToken()
|
||||
if (!access_token) {
|
||||
throw internalServerError(`[serviceProcedure] No service token`)
|
||||
@@ -133,7 +145,7 @@ export const serviceProcedure = t.procedure.use(async function (opts) {
|
||||
})
|
||||
})
|
||||
|
||||
export const serverActionProcedure = t.procedure.experimental_caller(
|
||||
export const serverActionProcedure = baseProcedure.experimental_caller(
|
||||
experimental_nextAppDirCaller({
|
||||
createContext,
|
||||
normalizeFormData: true,
|
||||
|
||||
Reference in New Issue
Block a user