Merged in feature/wrap-logging (pull request #2511)
Feature/wrap logging * feat: change all logging to go through our own logger function so that we can control log levels * move packages/trpc to using our own logger * merge Approved-by: Linus Flood
This commit is contained in:
@@ -2,6 +2,7 @@ import { type NextRequest, NextResponse } from "next/server"
|
||||
import { AuthError } from "next-auth"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
import { internalServerError } from "@/server/errors/next"
|
||||
@@ -20,7 +21,7 @@ export async function GET(
|
||||
const returnUrl = request.headers.get("x-returnurl")
|
||||
const isSeamless = request.headers.get("x-logout-source") === "seamless"
|
||||
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[logout] source: ${request.headers.get("x-logout-source") || "normal"}`
|
||||
)
|
||||
|
||||
@@ -32,7 +33,7 @@ export async function GET(
|
||||
if (returnUrl) {
|
||||
redirectTo = returnUrl
|
||||
} else {
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[login] missing returnUrl, using fallback: ${redirectToFallback}`
|
||||
)
|
||||
redirectTo = redirectToFallback
|
||||
@@ -42,9 +43,9 @@ export async function GET(
|
||||
|
||||
// Make relative URL to absolute URL
|
||||
if (redirectTo.startsWith("/")) {
|
||||
console.log(`[logout] make redirectTo absolute, from ${redirectTo}`)
|
||||
logger.debug(`[logout] make redirectTo absolute, from ${redirectTo}`)
|
||||
redirectTo = new URL(redirectTo, publicURL).href
|
||||
console.log(`[logout] make redirectTo absolute, to ${redirectTo}`)
|
||||
logger.debug(`[logout] make redirectTo absolute, to ${redirectTo}`)
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -72,21 +73,21 @@ export async function GET(
|
||||
break
|
||||
}
|
||||
const redirectUrl = new URL(redirectUrlValue)
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[logout] creating redirect to seamless logout: ${redirectUrl}`
|
||||
)
|
||||
redirectTo = redirectUrl.toString()
|
||||
} catch (e) {
|
||||
console.error(
|
||||
"Unable to create URL for seamless logout, proceeding without it."
|
||||
logger.error(
|
||||
"Unable to create URL for seamless logout, proceeding without it.",
|
||||
e
|
||||
)
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
redirectTo = `${env.CURITY_ISSUER_USER}/authn/authenticate/logout?redirect_uri=${encodeURIComponent(redirectTo)}`
|
||||
console.log(`[logout] final redirectUrl: ${redirectTo}`)
|
||||
logger.debug(`[logout] final redirectUrl: ${redirectTo}`)
|
||||
|
||||
/**
|
||||
* Passing `redirect: false` to `signOut` will return a result object
|
||||
@@ -99,16 +100,16 @@ export async function GET(
|
||||
})
|
||||
|
||||
if (redirectUrlObj) {
|
||||
console.log(`[logout] redirecting to: ${redirectUrlObj.redirect}`)
|
||||
logger.debug(`[logout] redirecting to: ${redirectUrlObj.redirect}`)
|
||||
return NextResponse.redirect(redirectUrlObj.redirect)
|
||||
} else {
|
||||
console.error(`[logout] missing redirectUrlObj reponse from signOut()`)
|
||||
logger.error(`[logout] missing redirectUrlObj reponse from signOut()`)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
console.log({ signOutAuthError: error })
|
||||
logger.error("signOutAuthError", { signOutAuthError: error })
|
||||
} else {
|
||||
console.log({ signOutError: error })
|
||||
logger.error("signOutError", { signOutError: error })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as Sentry from "@sentry/nextjs"
|
||||
import { useEffect } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
export default function Error({
|
||||
error,
|
||||
}: {
|
||||
@@ -14,7 +16,7 @@ export default function Error({
|
||||
useEffect(() => {
|
||||
if (!error) return
|
||||
|
||||
console.error({ breadcrumbsError: error })
|
||||
logger.error("Breadcrumbs Error", { breadcrumbsError: error })
|
||||
Sentry.captureException(error)
|
||||
}, [error])
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as Sentry from "@sentry/nextjs"
|
||||
import { useEffect } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
export default function Error({
|
||||
error,
|
||||
}: {
|
||||
@@ -14,7 +16,7 @@ export default function Error({
|
||||
useEffect(() => {
|
||||
if (!error) return
|
||||
|
||||
console.error(error)
|
||||
logger.error("My Pages", error)
|
||||
Sentry.captureException(error)
|
||||
}, [error])
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as Sentry from "@sentry/nextjs"
|
||||
import { useEffect } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { DestinationOverviewPageError } from "@/components/ContentType/DestinationPage/DestinationOverviewPage/error"
|
||||
|
||||
export default function Error({
|
||||
@@ -16,7 +18,7 @@ export default function Error({
|
||||
useEffect(() => {
|
||||
if (!error) return
|
||||
|
||||
console.error(error)
|
||||
logger.error("Destination overview page", error)
|
||||
Sentry.captureException(error)
|
||||
}, [error])
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { AuthError } from "next-auth"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { dtmcApiCallback } from "@/constants/routes/dtmc"
|
||||
import { env } from "@/env/server"
|
||||
import { internalServerError, serviceUnavailable } from "@/server/errors/next"
|
||||
@@ -21,22 +23,22 @@ export async function GET() {
|
||||
)
|
||||
|
||||
if (redirectUrl) {
|
||||
console.log(`[dtmc] redirecting to: ${redirectUrl}`)
|
||||
logger.debug(`[dtmc] redirecting to: ${redirectUrl}`)
|
||||
return NextResponse.redirect(redirectUrl)
|
||||
} else {
|
||||
console.error(`[dtmc] missing redirectUrl response from signIn()`)
|
||||
logger.error(`[dtmc] missing redirectUrl response from signIn()`)
|
||||
return internalServerError(
|
||||
"[dtmc] Missing redirect URL from authentication service"
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
console.error({ signInAuthError: error })
|
||||
logger.error("signInAuthError", { signInAuthError: error })
|
||||
return serviceUnavailable(
|
||||
"[dtmc] Microsoft authentication service unavailable"
|
||||
)
|
||||
} else {
|
||||
console.error({ signInError: error })
|
||||
logger.error("signInError", { signInError: error })
|
||||
return internalServerError(
|
||||
"[dtmc] Unexpected error during authentication"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { myStay } from "@scandic-hotels/common/constants/routes/myStay"
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { BookingErrorCodeEnum } from "@scandic-hotels/trpc/enums/bookingErrorCode"
|
||||
|
||||
import { PaymentCallbackStatusEnum } from "@/constants/booking"
|
||||
@@ -25,7 +26,7 @@ export default async function GuaranteePaymentCallbackPage(
|
||||
) {
|
||||
const searchParams = await props.searchParams
|
||||
const params = await props.params
|
||||
console.log(`[gla-payment-callback] callback started`)
|
||||
logger.debug(`[gla-payment-callback] callback started`)
|
||||
const lang = params.lang
|
||||
const status = searchParams.status
|
||||
const confirmationNumber = searchParams.confirmationNumber
|
||||
@@ -49,7 +50,7 @@ export default async function GuaranteePaymentCallbackPage(
|
||||
/>
|
||||
)
|
||||
}
|
||||
console.log(`[gla-payment-callback] redirecting to: ${myStayUrl}`)
|
||||
logger.debug(`[gla-payment-callback] redirecting to: ${myStayUrl}`)
|
||||
return <TrackGuarantee status={status} redirectUrl={myStayUrl} />
|
||||
}
|
||||
|
||||
@@ -76,7 +77,7 @@ export default async function GuaranteePaymentCallbackPage(
|
||||
: BookingErrorCodeEnum.TransactionFailed
|
||||
)
|
||||
} catch {
|
||||
console.error(
|
||||
logger.error(
|
||||
`[gla-payment-callback] failed to get booking status for ${confirmationNumber}, status: ${status}`
|
||||
)
|
||||
if (status === PaymentCallbackStatusEnum.Cancel) {
|
||||
@@ -86,7 +87,10 @@ export default async function GuaranteePaymentCallbackPage(
|
||||
errorMessage = `Failed to get booking status for ${confirmationNumber}, status: ${status}`
|
||||
}
|
||||
}
|
||||
console.log(errorMessage)
|
||||
|
||||
if (errorMessage) {
|
||||
logger.error(errorMessage)
|
||||
}
|
||||
|
||||
if (isAncillaryFlow) {
|
||||
searchObject.set("ancillary", "ancillary")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { getServiceToken } from "@scandic-hotels/common/tokenManager"
|
||||
import { BookingErrorCodeEnum } from "@scandic-hotels/trpc/enums/bookingErrorCode"
|
||||
import { getBooking } from "@scandic-hotels/trpc/routers/booking/utils"
|
||||
@@ -31,13 +32,13 @@ export default async function PaymentCallbackPage(
|
||||
) {
|
||||
const searchParams = await props.searchParams
|
||||
const params = await props.params
|
||||
console.log(`[payment-callback] callback started`)
|
||||
logger.debug(`[payment-callback] callback started`)
|
||||
const lang = params.lang
|
||||
const status = searchParams.status
|
||||
const confirmationNumber = searchParams.confirmationNumber
|
||||
|
||||
if (!status || !confirmationNumber) {
|
||||
console.error(
|
||||
logger.error(
|
||||
`[payment-callback] missing status or confirmationNumber in search params`
|
||||
)
|
||||
notFound()
|
||||
@@ -71,7 +72,7 @@ export default async function PaymentCallbackPage(
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
console.error(
|
||||
logger.error(
|
||||
`[payment-callback] no token found for user, cannot fetch booking`
|
||||
)
|
||||
notFound()
|
||||
@@ -89,7 +90,7 @@ export default async function PaymentCallbackPage(
|
||||
const expire = Math.floor(Date.now() / 1000) + 60
|
||||
const sig = encrypt(expire.toString())
|
||||
const confirmationUrl = `${bookingConfirmation(lang)}?RefId=${encodeURIComponent(refId)}`
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[payment-callback] rendering success callback with confirmation number: ${confirmationNumber}`
|
||||
)
|
||||
|
||||
@@ -126,7 +127,7 @@ export default async function PaymentCallbackPage(
|
||||
: BookingErrorCodeEnum.TransactionFailed
|
||||
)
|
||||
} catch {
|
||||
console.error(
|
||||
logger.error(
|
||||
`[payment-callback] failed to get booking status for ${confirmationNumber}, status: ${status}`
|
||||
)
|
||||
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionFailed)
|
||||
@@ -135,7 +136,7 @@ export default async function PaymentCallbackPage(
|
||||
}
|
||||
|
||||
if (status === PaymentCallbackStatusEnum.Error) {
|
||||
console.error(
|
||||
logger.error(
|
||||
`[payment-callback] error status received for ${confirmationNumber}, status: ${status}`
|
||||
)
|
||||
searchObject.set("errorCode", BookingErrorCodeEnum.TransactionFailed)
|
||||
|
||||
@@ -2,6 +2,7 @@ import { type NextRequest, NextResponse } from "next/server"
|
||||
import { AuthError } from "next-auth"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
import { internalServerError } from "@/server/errors/next"
|
||||
@@ -25,7 +26,7 @@ export async function GET(
|
||||
const isSeamlessMagicLink =
|
||||
request.headers.get("x-login-source") === "seamless-magiclink"
|
||||
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[login] source: ${request.headers.get("x-login-source") || "normal"}`
|
||||
)
|
||||
|
||||
@@ -34,8 +35,8 @@ export async function GET(
|
||||
request.nextUrl.searchParams.get("redirectTo")
|
||||
const redirectToFallback = "/"
|
||||
|
||||
console.log(`[login] redirectTo cookie value: ${redirectToCookieValue}`)
|
||||
console.log(
|
||||
logger.debug(`[login] redirectTo cookie value: ${redirectToCookieValue}`)
|
||||
logger.debug(
|
||||
`[login] redirectTo search param value: ${redirectToSearchParamValue}`
|
||||
)
|
||||
|
||||
@@ -43,7 +44,7 @@ export async function GET(
|
||||
if (returnUrl) {
|
||||
redirectTo = returnUrl
|
||||
} else {
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[login] missing returnUrl, using fallback: ${redirectToFallback}`
|
||||
)
|
||||
redirectTo = redirectToFallback
|
||||
@@ -54,9 +55,9 @@ export async function GET(
|
||||
|
||||
// Make relative URL to absolute URL
|
||||
if (redirectTo.startsWith("/")) {
|
||||
console.log(`[login] make redirectTo absolute, from ${redirectTo}`)
|
||||
logger.debug(`[login] make redirectTo absolute, from ${redirectTo}`)
|
||||
redirectTo = new URL(redirectTo, publicURL).href
|
||||
console.log(`[login] make redirectTo absolute, to ${redirectTo}`)
|
||||
logger.debug(`[login] make redirectTo absolute, to ${redirectTo}`)
|
||||
}
|
||||
|
||||
// Clean up cookie from authRequired middleware
|
||||
@@ -90,9 +91,11 @@ export async function GET(
|
||||
break
|
||||
}
|
||||
const redirectUrl = new URL(redirectUrlValue)
|
||||
console.log(`[login] creating redirect to seamless login: ${redirectUrl}`)
|
||||
logger.debug(
|
||||
`[login] creating redirect to seamless login: ${redirectUrl}`
|
||||
)
|
||||
redirectUrl.searchParams.set("returnurl", redirectTo)
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[login] returnurl for seamless login: ${redirectUrl.searchParams.get("returnurl")}`
|
||||
)
|
||||
redirectTo = redirectUrl.toString()
|
||||
@@ -105,7 +108,7 @@ export async function GET(
|
||||
"; Max-Age=300; Path=/; HttpOnly; SameSite=Lax"
|
||||
)
|
||||
} catch (e) {
|
||||
console.error(
|
||||
logger.error(
|
||||
"[login] unable to create URL for seamless login, proceeding without it.",
|
||||
e
|
||||
)
|
||||
@@ -113,7 +116,7 @@ export async function GET(
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`[login] final redirectUrl: ${redirectTo}`)
|
||||
logger.debug(`[login] final redirectUrl: ${redirectTo}`)
|
||||
|
||||
/** Record<string, any> is next-auth typings */
|
||||
const params: Record<string, any> = {
|
||||
@@ -174,16 +177,16 @@ export async function GET(
|
||||
const redirectOpts = {
|
||||
headers: redirectHeaders,
|
||||
}
|
||||
console.log(`[login] redirecting to: ${redirectUrl}`, redirectOpts)
|
||||
logger.debug(`[login] redirecting to: ${redirectUrl}`, redirectOpts)
|
||||
return NextResponse.redirect(redirectUrl, redirectOpts)
|
||||
} else {
|
||||
console.error(`[login] missing redirectUrl reponse from signIn()`)
|
||||
logger.error(`[login] missing redirectUrl reponse from signIn()`)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
console.error({ signInAuthError: error })
|
||||
logger.error("signInAuthError", { signInAuthError: error })
|
||||
} else {
|
||||
console.error({ signInError: error })
|
||||
logger.error("signInError", { signInError: error })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
import { AuthError } from "next-auth"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { badRequest, internalServerError } from "@/server/errors/next"
|
||||
import { getPublicURL } from "@/server/utils"
|
||||
|
||||
@@ -16,7 +18,7 @@ export async function GET(
|
||||
|
||||
const loginKey = request.nextUrl.searchParams.get("loginKey")
|
||||
if (!loginKey) {
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[verifymagiclink] missing required loginKey, aborting bad request`
|
||||
)
|
||||
return badRequest()
|
||||
@@ -24,14 +26,14 @@ export async function GET(
|
||||
|
||||
let redirectTo: string
|
||||
|
||||
console.log(`[verifymagiclink] verifying callback`)
|
||||
logger.debug(`[verifymagiclink] verifying callback`)
|
||||
|
||||
const redirectToCookieValue = request.cookies.get(
|
||||
"magicLinkRedirectTo"
|
||||
)?.value // Set redirect url from the magicLinkRedirect Cookie which is set when intiating login
|
||||
const redirectToFallback = "/"
|
||||
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[verifymagiclink] magicLinkRedirectTo cookie value: ${redirectToCookieValue}`
|
||||
)
|
||||
|
||||
@@ -39,11 +41,11 @@ export async function GET(
|
||||
|
||||
// Make relative URL to absolute URL
|
||||
if (redirectTo.startsWith("/")) {
|
||||
console.log(
|
||||
logger.debug(
|
||||
`[verifymagiclink] make redirectTo absolute, from ${redirectTo}`
|
||||
)
|
||||
redirectTo = new URL(redirectTo, publicURL).href
|
||||
console.log(`[verifymagiclink] make redirectTo absolute, to ${redirectTo}`)
|
||||
logger.debug(`[verifymagiclink] make redirectTo absolute, to ${redirectTo}`)
|
||||
}
|
||||
|
||||
// Update Seamless login url as Magic link login has a different authenticator in Curity
|
||||
@@ -59,7 +61,7 @@ export async function GET(
|
||||
)
|
||||
|
||||
try {
|
||||
console.log(`[verifymagiclink] final redirectUrl: ${redirectTo}`)
|
||||
logger.debug(`[verifymagiclink] final redirectUrl: ${redirectTo}`)
|
||||
|
||||
const params = await context.params
|
||||
/**
|
||||
@@ -92,18 +94,18 @@ export async function GET(
|
||||
)
|
||||
|
||||
if (redirectUrl) {
|
||||
console.log(`[verifymagiclink] redirecting to: ${redirectUrl}`)
|
||||
logger.debug(`[verifymagiclink] redirecting to: ${redirectUrl}`)
|
||||
return NextResponse.redirect(redirectUrl)
|
||||
} else {
|
||||
console.error(
|
||||
logger.error(
|
||||
`[verifymagiclink] missing redirectUrl reponse from signIn()`
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
console.error({ signInAuthError: error })
|
||||
logger.error("signInAuthError", { signInAuthError: error })
|
||||
} else {
|
||||
console.error({ signInError: error })
|
||||
logger.error("signInError", { signInError: error })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useParams, useRouter, useSearchParams } from "next/navigation"
|
||||
import { startTransition, useEffect, useRef } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { SESSION_EXPIRED } from "@scandic-hotels/trpc/errors"
|
||||
|
||||
import { login } from "@/constants/routes/handleAuth"
|
||||
@@ -31,14 +32,13 @@ export default function Error({
|
||||
useEffect(() => {
|
||||
if (!error) return
|
||||
|
||||
console.error(error)
|
||||
|
||||
if (error.message === SESSION_EXPIRED) {
|
||||
const loginUrl = login[params.lang]
|
||||
window.location.assign(loginUrl)
|
||||
return
|
||||
}
|
||||
|
||||
logger.error("(live)/error", error)
|
||||
Sentry.captureException(error)
|
||||
}, [error, params.lang])
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import * as Sentry from "@sentry/nextjs"
|
||||
import { useEffect } from "react"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
export default function Error({
|
||||
error,
|
||||
}: {
|
||||
@@ -11,7 +13,7 @@ export default function Error({
|
||||
useEffect(() => {
|
||||
if (!error) return
|
||||
|
||||
console.error(error)
|
||||
logger.error("header", error)
|
||||
Sentry.captureException(error)
|
||||
}, [error])
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { GetCurrentBlockPage } from "@scandic-hotels/trpc/graphql/Query/Current/CurrentBlockPage.graphql"
|
||||
import { GetCurrentBlockPageTrackingData } from "@scandic-hotels/trpc/graphql/Query/Current/CurrentBlockPageTrackingData.graphql"
|
||||
import { request } from "@scandic-hotels/trpc/graphql/request"
|
||||
@@ -34,9 +35,12 @@ export default async function CurrentContentPage(
|
||||
)
|
||||
|
||||
if (!response.data?.all_current_blocks_page?.total) {
|
||||
console.log("#### DATA ####")
|
||||
console.log(response.data)
|
||||
console.log("SearchParams URI: ", searchParams.uri)
|
||||
logger.debug(
|
||||
"#### DATA ####",
|
||||
response.data,
|
||||
"SearchParams URI: ",
|
||||
searchParams.uri
|
||||
)
|
||||
throw new Error("Not found")
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { cookies } from "next/headers"
|
||||
import { redirect } from "next/navigation"
|
||||
import { z } from "zod"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||
import { SAS_TOKEN_STORAGE_KEY } from "@scandic-hotels/trpc/constants/partnerSAS"
|
||||
|
||||
@@ -35,7 +36,7 @@ export async function GET(
|
||||
})
|
||||
|
||||
if (!result.success) {
|
||||
console.error("[SAS] Invalid search params", result.error)
|
||||
logger.error("[SAS] Invalid search params", result.error)
|
||||
redirect(`/${lang}/sas-x-scandic/error?errorCode=invalid_query`)
|
||||
}
|
||||
const { code, state } = result.data
|
||||
@@ -62,7 +63,7 @@ export async function GET(
|
||||
|
||||
if (!tokenResponse.ok) {
|
||||
const error = await tokenResponse.text()
|
||||
console.error("[SAS] Failed to get token", error)
|
||||
logger.error("[SAS] Failed to get token", error)
|
||||
redirect(`/${lang}/sas-x-scandic/error?errorCode=token_error`)
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ export async function GET(
|
||||
const caller = await serverClient()
|
||||
const [data, error] = await safeTry(caller.partner.sas.requestOtp())
|
||||
if (!data || error) {
|
||||
console.error("[SAS] Failed to request OTP", error)
|
||||
logger.error("[SAS] Failed to request OTP", error)
|
||||
redirect(`/${lang}/sas-x-scandic/error`)
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ export async function GET(
|
||||
throw new Error(`Unhandled request OTP status ${data.status}`)
|
||||
}
|
||||
|
||||
console.log("[SAS] Request OTP response", data)
|
||||
logger.debug("[SAS] Request OTP response", data)
|
||||
|
||||
const otpUrl = new URL(
|
||||
`/${lang}/sas-x-scandic/otp`,
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as Sentry from "@sentry/nextjs"
|
||||
import { useEffect } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { GenericError } from "./components/GenericError"
|
||||
@@ -19,7 +20,7 @@ export default function Error({
|
||||
useEffect(() => {
|
||||
if (!error) return
|
||||
|
||||
console.error(error)
|
||||
logger.error("sas-x-scandic", error)
|
||||
Sentry.captureException(error)
|
||||
}, [error])
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { redirect } from "next/navigation"
|
||||
import { z } from "zod"
|
||||
|
||||
import { myPages } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||
import {
|
||||
SAS_TOKEN_STORAGE_KEY,
|
||||
@@ -173,7 +174,7 @@ async function handleLinkAccount({
|
||||
const caller = await serverClient()
|
||||
const [res, error] = await safeTry(caller.partner.sas.linkAccount())
|
||||
if (!res || error) {
|
||||
console.error("[SAS] link account error", error)
|
||||
logger.error("[SAS] link account error", error)
|
||||
return {
|
||||
url: `/${lang}/sas-x-scandic/error`,
|
||||
}
|
||||
@@ -216,7 +217,7 @@ async function handleUnlinkAccount({
|
||||
const caller = await serverClient()
|
||||
const [res, error] = await safeTry(caller.partner.sas.unlinkAccount())
|
||||
if (!res || error) {
|
||||
console.error("[SAS] unlink account error", error)
|
||||
logger.error("[SAS] unlink account error", error)
|
||||
return {
|
||||
url: `/${lang}/sas-x-scandic/error`,
|
||||
}
|
||||
@@ -266,7 +267,7 @@ async function handleTransferPoints({
|
||||
)
|
||||
|
||||
if (!res || error || res.transferState === "error") {
|
||||
console.error("[SAS] transfer points error", error)
|
||||
logger.error("[SAS] transfer points error", error)
|
||||
return {
|
||||
url: `/${lang}/sas-x-scandic/error`,
|
||||
type: "replace",
|
||||
@@ -274,14 +275,14 @@ async function handleTransferPoints({
|
||||
}
|
||||
|
||||
if (res.transferState === "notLinked") {
|
||||
console.warn("[SAS] transfer points not linked")
|
||||
logger.warn("[SAS] transfer points not linked")
|
||||
return {
|
||||
url: `/${lang}/sas-x-scandic/link`,
|
||||
type: "replace",
|
||||
}
|
||||
}
|
||||
|
||||
console.log("[SAS] transfer points response", res)
|
||||
logger.debug("[SAS] transfer points response", res)
|
||||
|
||||
return {
|
||||
url: `/${lang}/sas-x-scandic/transfer/success?p=${points}`,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import AccountPage from "@/components/Webviews/AccountPage"
|
||||
import LoyaltyPage from "@/components/Webviews/LoyaltyPage"
|
||||
|
||||
@@ -22,7 +24,7 @@ export default async function ContentTypePage(
|
||||
return <AccountPage />
|
||||
default:
|
||||
const type: never = params.contentType
|
||||
console.error(`Unsupported content type given: ${type}`)
|
||||
logger.error(`Unsupported content type given: ${type}`)
|
||||
notFound()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as Sentry from "@sentry/nextjs"
|
||||
import { headers } from "next/headers"
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { getProfile } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { getIntl } from "@/i18n"
|
||||
@@ -17,7 +20,7 @@ export default async function Layout(
|
||||
const user = await getProfile()
|
||||
|
||||
if (!user) {
|
||||
console.log(`[webview:page] unable to load user`)
|
||||
logger.debug(`[webview:page] unable to load user`)
|
||||
return (
|
||||
<p>
|
||||
{intl.formatMessage({
|
||||
@@ -35,7 +38,9 @@ export default async function Layout(
|
||||
const headersList = await headers()
|
||||
const returnURL = `/${params.lang}/webview${headersList.get("x-pathname")!}`
|
||||
const redirectURL = `/${params.lang}/webview/refresh?returnUrl=${encodeURIComponent(returnURL)}`
|
||||
console.log(`[webview:page] user error, redirecting to: ${redirectURL}`)
|
||||
logger.debug(
|
||||
`[webview:page] user error, redirecting to: ${redirectURL}`
|
||||
)
|
||||
redirect(redirectURL)
|
||||
case "notfound":
|
||||
return (
|
||||
@@ -55,7 +60,8 @@ export default async function Layout(
|
||||
)
|
||||
default:
|
||||
const u: never = user
|
||||
console.log("[webview:page] unhandled user loading error", u)
|
||||
logger.error("[webview:page] unhandled user loading error", u)
|
||||
Sentry.captureMessage("[webview:page] unhandled user loading error", u)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
@@ -11,6 +13,6 @@ export const GET = async () => {
|
||||
}
|
||||
|
||||
const user = await auth()
|
||||
console.log("[DEBUG] access-token", user?.token)
|
||||
logger.debug("[DEBUG] access-token", user?.token)
|
||||
return NextResponse.json(user)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { languageSchema } from "@scandic-hotels/common/utils/languages"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
@@ -9,7 +10,7 @@ export const dynamic = "force-dynamic"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
if (!env.ENABLE_WARMUP_HOTEL) {
|
||||
console.log("[WARMUP] Warmup hotel data is disabled")
|
||||
logger.info("[WARMUP] Warmup hotel data is disabled")
|
||||
return NextResponse.json(
|
||||
{ message: "Warmup hotel data is disabled" },
|
||||
{ status: 200 }
|
||||
@@ -32,7 +33,7 @@ export async function GET(request: NextRequest) {
|
||||
})
|
||||
return NextResponse.json(hotels)
|
||||
} catch (error) {
|
||||
console.error("[WARMUP] error", error)
|
||||
logger.error("[WARMUP] error", error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: "Failed to fetch all hotels",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { profile } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
import { getPublicURL } from "@/server/utils"
|
||||
@@ -10,10 +11,12 @@ export async function GET(
|
||||
request: NextRequest,
|
||||
props: { params: Promise<{ lang: string }> }
|
||||
) {
|
||||
const addCardLogger = createLogger("add-card")
|
||||
|
||||
const params = await props.params
|
||||
const publicURL = getPublicURL(request)
|
||||
|
||||
console.log(`[add-card] callback started`)
|
||||
addCardLogger.debug(`[add-card] callback started`)
|
||||
const lang = params.lang as Lang
|
||||
const returnUrl = new URL(`${publicURL}/${profile[lang ?? Lang.en]}`)
|
||||
|
||||
@@ -32,28 +35,28 @@ export async function GET(
|
||||
})
|
||||
|
||||
if (saveCardSuccess) {
|
||||
console.log(`[add-card] planet success: card saved success`)
|
||||
addCardLogger.debug(`[add-card] planet success: card saved success`)
|
||||
returnUrl.searchParams.set("success", "true")
|
||||
} else {
|
||||
console.log(`[add-card] planet success: card saved fail`)
|
||||
addCardLogger.debug(`[add-card] planet success: card saved fail`)
|
||||
returnUrl.searchParams.set("failure", "true")
|
||||
}
|
||||
} else {
|
||||
console.log(`[add-card] planet success: missing datatransTrxId`)
|
||||
addCardLogger.debug(`[add-card] planet success: missing datatransTrxId`)
|
||||
returnUrl.searchParams.set("error", "true")
|
||||
}
|
||||
} else if (failure) {
|
||||
console.log(`[add-card] planet fail`)
|
||||
addCardLogger.debug(`[add-card] planet fail`)
|
||||
returnUrl.searchParams.set("failure", "true")
|
||||
} else if (cancel) {
|
||||
console.log(`[add-card] planet cancel`)
|
||||
addCardLogger.debug(`[add-card] planet cancel`)
|
||||
returnUrl.searchParams.set("cancel", "true")
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`[add-card] error saving credit card`, e)
|
||||
addCardLogger.error(`[add-card] error saving credit card`, e)
|
||||
returnUrl.searchParams.set("error", "true")
|
||||
}
|
||||
|
||||
console.log(`[add-card] redirecting to: ${returnUrl}`)
|
||||
addCardLogger.debug(`[add-card] redirecting to: ${returnUrl}`)
|
||||
return Response.redirect(returnUrl)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
|
||||
import { overview } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
import * as api from "@scandic-hotels/trpc/api"
|
||||
import { isValidSession } from "@scandic-hotels/trpc/utils/session"
|
||||
|
||||
@@ -13,6 +14,7 @@ import { auth } from "@/auth"
|
||||
import { auth as dtmcAuth } from "@/auth.dtmc"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
|
||||
const dtmcLogger = createLogger("dtmc")
|
||||
interface LinkEmployeeSuccessResult {
|
||||
success: true
|
||||
}
|
||||
@@ -32,7 +34,7 @@ async function linkEmployeeToUser(
|
||||
employeeId: string,
|
||||
accessToken: string
|
||||
): Promise<LinkEmployeeResult> {
|
||||
console.log(`[dtmc] Linking employee ID ${employeeId}`)
|
||||
dtmcLogger.debug(`Linking employee ID ${employeeId}`)
|
||||
let response: Response
|
||||
try {
|
||||
response = await api.post(
|
||||
@@ -45,7 +47,7 @@ async function linkEmployeeToUser(
|
||||
}
|
||||
)
|
||||
} catch (networkError) {
|
||||
console.error("[dtmc] Network error during API request:", networkError)
|
||||
dtmcLogger.error("Network error during API request:", networkError)
|
||||
return {
|
||||
success: false,
|
||||
statusCode: 0,
|
||||
@@ -53,17 +55,17 @@ async function linkEmployeeToUser(
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(`[dtmc] API returned error status ${response.status}`)
|
||||
dtmcLogger.error(`API returned error status ${response.status}`)
|
||||
try {
|
||||
const errorResponse = await response.json()
|
||||
console.error(`[dtmc] API error response:`, errorResponse)
|
||||
dtmcLogger.error(`API error response:`, errorResponse)
|
||||
} catch (parseError) {
|
||||
console.warn(`[dtmc] Could not parse API error response:`, parseError)
|
||||
dtmcLogger.warn(`Could not parse API error response:`, parseError)
|
||||
try {
|
||||
const errorText = await response.text()
|
||||
console.error(`[dtmc] Raw error response:`, errorText)
|
||||
dtmcLogger.error(`Raw error response:`, errorText)
|
||||
} catch {
|
||||
console.error(`[dtmc] Could not read error response body`)
|
||||
dtmcLogger.error(`Could not read error response body`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,19 +89,19 @@ async function linkEmployeeToUser(
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[dtmc] API call successful - Status: ${response.status}`)
|
||||
console.log(
|
||||
`[dtmc] Response headers:`,
|
||||
dtmcLogger.debug(`API call successful - Status: ${response.status}`)
|
||||
dtmcLogger.debug(
|
||||
`Response headers:`,
|
||||
Object.fromEntries(response.headers.entries())
|
||||
)
|
||||
try {
|
||||
const responseBody = await response.json()
|
||||
console.log(`[dtmc] Response body:`, responseBody)
|
||||
dtmcLogger.debug(`Response body:`, responseBody)
|
||||
} catch (parseError) {
|
||||
console.warn(`[dtmc] Could not parse success response body:`, parseError)
|
||||
dtmcLogger.warn(`Could not parse success response body:`, parseError)
|
||||
}
|
||||
|
||||
console.log(`[dtmc] Successfully linked employee ID ${employeeId}`)
|
||||
dtmcLogger.debug(`Successfully linked employee ID ${employeeId}`)
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
@@ -114,20 +116,18 @@ export async function GET(request: NextRequest) {
|
||||
const dtmcSession = await dtmcAuth()
|
||||
const session = await auth()
|
||||
const baseUrl = getPublicURL(request)
|
||||
console.log("[dtmc] DTMC Callback handler - using baseUrl:", baseUrl)
|
||||
dtmcLogger.debug("DTMC Callback handler - using baseUrl:", baseUrl)
|
||||
|
||||
if (!isValidSession(session)) {
|
||||
console.error(
|
||||
"[dtmc] DTMC Callback handler - No valid user session found"
|
||||
)
|
||||
dtmcLogger.error("DTMC Callback handler - No valid user session found")
|
||||
const errorUrl = new URL(linkEmploymentError[lang], baseUrl)
|
||||
errorUrl.searchParams.set("error", "no_session")
|
||||
return NextResponse.redirect(errorUrl)
|
||||
}
|
||||
|
||||
if (!isValidSession(dtmcSession)) {
|
||||
console.error(
|
||||
"[dtmc] DTMC Callback handler - No valid entra id session found"
|
||||
dtmcLogger.error(
|
||||
"DTMC Callback handler - No valid entra id session found"
|
||||
)
|
||||
const errorUrl = new URL(linkEmploymentError[lang], baseUrl)
|
||||
errorUrl.searchParams.set("error", "no_entra_id_session")
|
||||
@@ -136,40 +136,40 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
const employeeId = dtmcSession.employeeId
|
||||
|
||||
console.log(
|
||||
"[dtmc] DTMC Callback handler - Extracted employeeId:",
|
||||
dtmcLogger.debug(
|
||||
"DTMC Callback handler - Extracted employeeId:",
|
||||
employeeId
|
||||
)
|
||||
|
||||
if (!employeeId) {
|
||||
console.error("[dtmc] DTMC Callback handler - No employeeId in session")
|
||||
dtmcLogger.error("DTMC Callback handler - No employeeId in session")
|
||||
const errorUrl = new URL(linkEmploymentError[lang], baseUrl)
|
||||
errorUrl.searchParams.set("error", "missing_employee_id")
|
||||
return NextResponse.redirect(errorUrl)
|
||||
}
|
||||
|
||||
console.log(
|
||||
"[dtmc] DTMC Callback handler - Calling linkEmployeeToUser with ID:",
|
||||
dtmcLogger.debug(
|
||||
"DTMC Callback handler - Calling linkEmployeeToUser with ID:",
|
||||
employeeId
|
||||
)
|
||||
|
||||
const accessToken = session.token.access_token
|
||||
if (!accessToken) {
|
||||
console.error("[dtmc] DTMC Callback handler - No access token in session")
|
||||
dtmcLogger.error("DTMC Callback handler - No access token in session")
|
||||
const errorUrl = new URL(linkEmploymentError[lang], baseUrl)
|
||||
errorUrl.searchParams.set("error", "missing_access_token")
|
||||
return NextResponse.redirect(errorUrl)
|
||||
}
|
||||
|
||||
const result = await linkEmployeeToUser(employeeId, accessToken)
|
||||
console.log(
|
||||
"[dtmc] DTMC Callback handler - linkEmployeeToUser result:",
|
||||
dtmcLogger.debug(
|
||||
"DTMC Callback handler - linkEmployeeToUser result:",
|
||||
result
|
||||
)
|
||||
|
||||
if (!result.success) {
|
||||
console.error(
|
||||
"[dtmc] DTMC Callback handler - Failed to verify employment:",
|
||||
dtmcLogger.error(
|
||||
"DTMC Callback handler - Failed to verify employment:",
|
||||
`Status: ${result.statusCode}, Error: ${result.queryParam}`
|
||||
)
|
||||
|
||||
@@ -182,21 +182,21 @@ export async function GET(request: NextRequest) {
|
||||
return NextResponse.redirect(errorUrl)
|
||||
}
|
||||
|
||||
console.log(
|
||||
"[dtmc] DTMC Callback handler - Success! Employee linked with ID:",
|
||||
dtmcLogger.debug(
|
||||
"DTMC Callback handler - Success! Employee linked with ID:",
|
||||
employeeId
|
||||
)
|
||||
|
||||
console.log("[dtmc] overview[lang]:", overview[lang])
|
||||
dtmcLogger.debug("overview[lang]:", overview[lang])
|
||||
const successUrl = new URL(overview[lang], baseUrl)
|
||||
successUrl.searchParams.set(DTMC_SUCCESS_BANNER_KEY, "true")
|
||||
console.log(
|
||||
"[dtmc] DTMC Callback handler - Redirecting to success URL:",
|
||||
dtmcLogger.debug(
|
||||
"DTMC Callback handler - Redirecting to success URL:",
|
||||
successUrl.toString()
|
||||
)
|
||||
return NextResponse.redirect(successUrl)
|
||||
} catch (error) {
|
||||
console.error("[dtmc] DTMC Callback handler - Error in handler:", error)
|
||||
dtmcLogger.error("DTMC Callback handler - Error in handler:", error)
|
||||
return internalServerError()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { z } from "zod"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { getCacheClient } from "@scandic-hotels/common/dataCache"
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
import { generateHotelUrlTag } from "@scandic-hotels/trpc/utils/generateTag"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
@@ -24,22 +25,25 @@ const validateJsonBody = z.object({
|
||||
}),
|
||||
})
|
||||
|
||||
const revalidateHotelLogger = createLogger("revalidate-hotel")
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const headersList = await headers()
|
||||
const secret = headersList.get("x-revalidate-secret")
|
||||
|
||||
if (secret !== env.REVALIDATE_SECRET) {
|
||||
console.error(`Invalid Secret`)
|
||||
console.error({ secret })
|
||||
revalidateHotelLogger.error(`Invalid Secret`, { secret })
|
||||
return badRequest({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
|
||||
const data = await request.json()
|
||||
const validatedData = validateJsonBody.safeParse(data)
|
||||
if (!validatedData.success) {
|
||||
console.error("Bad validation for `validatedData` in hotel revalidation")
|
||||
console.error(validatedData.error)
|
||||
revalidateHotelLogger.error(
|
||||
"Bad validation for `validatedData` in hotel revalidation",
|
||||
validatedData.error
|
||||
)
|
||||
return internalServerError({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
|
||||
@@ -56,21 +60,20 @@ export async function POST(request: NextRequest) {
|
||||
if (content_type.uid === "hotel_page") {
|
||||
tag = generateHotelUrlTag(locale, entry.hotel_page_id)
|
||||
} else {
|
||||
console.error(
|
||||
revalidateHotelLogger.error(
|
||||
`Invalid content_type, received ${content_type.uid}, expected "hotel_page"`
|
||||
)
|
||||
return notFound({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
|
||||
console.info(`Revalidating hotel url tag: ${tag}`)
|
||||
revalidateHotelLogger.info(`Revalidating hotel url tag: ${tag}`)
|
||||
revalidateTag(tag)
|
||||
const cacheClient = await getCacheClient()
|
||||
await cacheClient.deleteKey(tag, { fuzzy: true })
|
||||
|
||||
return Response.json({ revalidated: true, now: Date.now() })
|
||||
} catch (error) {
|
||||
console.error("Failed to revalidate tag(s) for hotel")
|
||||
console.error(error)
|
||||
revalidateHotelLogger.error("Failed to revalidate tag(s) for hotel", error)
|
||||
return internalServerError({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { z } from "zod"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { getCacheClient } from "@scandic-hotels/common/dataCache"
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
import { generateLoyaltyConfigTag } from "@scandic-hotels/trpc/utils/generateTag"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
@@ -16,6 +17,8 @@ enum LoyaltyConfigContentTypes {
|
||||
reward = "reward",
|
||||
}
|
||||
|
||||
const loyaltyRevalidateLogger = createLogger("loyalty-revalidate")
|
||||
|
||||
const validateJsonBody = z.object({
|
||||
data: z.object({
|
||||
content_type: z.object({
|
||||
@@ -35,18 +38,18 @@ export async function POST(request: NextRequest) {
|
||||
const secret = headersList.get("x-revalidate-secret")
|
||||
|
||||
if (secret !== env.REVALIDATE_SECRET) {
|
||||
console.error(`Invalid Secret`)
|
||||
console.error({ secret })
|
||||
loyaltyRevalidateLogger.error(`Invalid Secret`, { secret })
|
||||
return badRequest({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
|
||||
const data = await request.json()
|
||||
const validatedData = validateJsonBody.safeParse(data)
|
||||
if (!validatedData.success) {
|
||||
console.error(
|
||||
"Bad validation for `validatedData` in loyaltyConfig revalidation"
|
||||
loyaltyRevalidateLogger.error(
|
||||
"Bad validation for `validatedData` in loyaltyConfig revalidation",
|
||||
validatedData.error
|
||||
)
|
||||
console.error(validatedData.error)
|
||||
|
||||
return internalServerError({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
|
||||
@@ -76,11 +79,11 @@ export async function POST(request: NextRequest) {
|
||||
entry.reward_id
|
||||
)
|
||||
} else {
|
||||
console.error("Invalid content_type")
|
||||
loyaltyRevalidateLogger.error("Invalid content_type")
|
||||
return notFound({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
|
||||
console.info(`Revalidating loyalty config tag: ${tag}`)
|
||||
loyaltyRevalidateLogger.info(`Revalidating loyalty config tag: ${tag}`)
|
||||
revalidateTag(tag)
|
||||
|
||||
const cacheClient = await getCacheClient()
|
||||
@@ -88,8 +91,10 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
return Response.json({ revalidated: true, now: Date.now() })
|
||||
} catch (error) {
|
||||
console.error("Failed to revalidate tag(s) for loyalty config")
|
||||
console.error(error)
|
||||
loyaltyRevalidateLogger.error(
|
||||
"Failed to revalidate tag(s) for loyalty config",
|
||||
error
|
||||
)
|
||||
return internalServerError({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { revalidateTag } from "next/cache"
|
||||
import { headers } from "next/headers"
|
||||
|
||||
import { getCacheClient } from "@scandic-hotels/common/dataCache"
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
import { generateTag } from "@scandic-hotels/trpc/utils/generateTag"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
@@ -9,6 +10,7 @@ import { badRequest, internalServerError } from "@/server/errors/next"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
const revalidateManuallyLogger = createLogger("revalidate-manually")
|
||||
// This file is primarily to be used locally to test
|
||||
// purging your cache for new (and old) requests
|
||||
export async function POST() {
|
||||
@@ -17,8 +19,7 @@ export async function POST() {
|
||||
const secret = headersList.get("x-revalidate-secret")
|
||||
|
||||
if (secret !== env.REVALIDATE_SECRET) {
|
||||
console.error(`Invalid Secret`)
|
||||
console.error({ secret })
|
||||
revalidateManuallyLogger.error(`Invalid Secret`, { secret })
|
||||
return badRequest({
|
||||
now: Date.now(),
|
||||
revalidated: false,
|
||||
@@ -30,8 +31,8 @@ export async function POST() {
|
||||
const lang = headersList.get("x-lang")
|
||||
|
||||
if (!lang || !identifier) {
|
||||
console.info(`Missing lang and/or identifier`)
|
||||
console.info(`lang: ${lang}, identifier: ${identifier}`)
|
||||
revalidateManuallyLogger.info(`Missing lang and/or identifier`)
|
||||
revalidateManuallyLogger.info(`lang: ${lang}, identifier: ${identifier}`)
|
||||
return badRequest({
|
||||
now: Date.now(),
|
||||
revalidated: false,
|
||||
@@ -42,18 +43,17 @@ export async function POST() {
|
||||
|
||||
const tag = generateTag(lang as Lang, identifier, affix)
|
||||
|
||||
console.info(
|
||||
revalidateManuallyLogger.info(
|
||||
`Revalidated tag for [lang: ${lang}, identifier: ${identifier}${affix ? `, affix: ${affix}` : ""}]`
|
||||
)
|
||||
console.info(`Tag: ${tag}`)
|
||||
revalidateManuallyLogger.info(`Tag: ${tag}`)
|
||||
|
||||
revalidateTag(tag)
|
||||
cacheClient.deleteKey(tag, { fuzzy: true })
|
||||
|
||||
return Response.json({ revalidated: true, now: Date.now() })
|
||||
} catch (error) {
|
||||
console.error("Failed to revalidate tag(s)")
|
||||
console.error(error)
|
||||
revalidateManuallyLogger.error("Failed to revalidate tag(s)", error)
|
||||
return internalServerError({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { z } from "zod"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { getCacheClient } from "@scandic-hotels/common/dataCache"
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
import { affix as breadcrumbsAffix } from "@scandic-hotels/trpc/routers/contentstack/breadcrumbs/utils"
|
||||
import { destinationCityPageDestinationSettingsSchema } from "@scandic-hotels/trpc/routers/contentstack/destinationCityPage/output"
|
||||
import { languageSwitcherAffix } from "@scandic-hotels/trpc/routers/contentstack/languageSwitcher/utils"
|
||||
@@ -47,14 +48,14 @@ const validateJsonBody = z.object({
|
||||
}),
|
||||
})
|
||||
|
||||
const revalidateLogger = createLogger("revalidate")
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const headersList = await headers()
|
||||
const secret = headersList.get("x-revalidate-secret")
|
||||
|
||||
if (secret !== env.REVALIDATE_SECRET) {
|
||||
console.error(`Invalid Secret`)
|
||||
console.error({ secret })
|
||||
revalidateLogger.error(`Invalid Secret`, { secret })
|
||||
return badRequest({
|
||||
now: Date.now(),
|
||||
revalidated: false,
|
||||
@@ -64,8 +65,10 @@ export async function POST(request: NextRequest) {
|
||||
const data = await request.json()
|
||||
const validatedData = validateJsonBody.safeParse(data)
|
||||
if (!validatedData.success) {
|
||||
console.error("Bad validation for `validatedData`")
|
||||
console.error(validatedData.error)
|
||||
revalidateLogger.error(
|
||||
"Bad validation for `validatedData`",
|
||||
validatedData.error
|
||||
)
|
||||
return internalServerError({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
|
||||
@@ -95,37 +98,41 @@ export async function POST(request: NextRequest) {
|
||||
const cacheClient = await getCacheClient()
|
||||
|
||||
const contentTypeUidTag = generateTag(entryLocale, content_type.uid)
|
||||
console.info(`Revalidating tag by content_type_uid: ${contentTypeUidTag}`)
|
||||
revalidateLogger.info(
|
||||
`Revalidating tag by content_type_uid: ${contentTypeUidTag}`
|
||||
)
|
||||
revalidateTag(contentTypeUidTag)
|
||||
await cacheClient.deleteKey(contentTypeUidTag, { fuzzy: true })
|
||||
|
||||
console.info(`Revalidating refsTag: ${refsTag}`)
|
||||
revalidateLogger.info(`Revalidating refsTag: ${refsTag}`)
|
||||
revalidateTag(refsTag)
|
||||
await cacheClient.deleteKey(refsTag, { fuzzy: true })
|
||||
|
||||
console.info(`Revalidating refTag: ${refTag}`)
|
||||
revalidateLogger.info(`Revalidating refTag: ${refTag}`)
|
||||
revalidateTag(refTag)
|
||||
await cacheClient.deleteKey(refTag, { fuzzy: true })
|
||||
|
||||
console.info(`Revalidating tag: ${tag}`)
|
||||
revalidateLogger.info(`Revalidating tag: ${tag}`)
|
||||
revalidateTag(tag)
|
||||
await cacheClient.deleteKey(tag, { fuzzy: true })
|
||||
|
||||
console.info(`Revalidating language switcher tag: ${languageSwitcherTag}`)
|
||||
revalidateLogger.info(
|
||||
`Revalidating language switcher tag: ${languageSwitcherTag}`
|
||||
)
|
||||
revalidateTag(languageSwitcherTag)
|
||||
await cacheClient.deleteKey(languageSwitcherTag, { fuzzy: true })
|
||||
|
||||
console.info(`Revalidating metadataTag: ${metadataTag}`)
|
||||
revalidateLogger.info(`Revalidating metadataTag: ${metadataTag}`)
|
||||
revalidateTag(metadataTag)
|
||||
await cacheClient.deleteKey(metadataTag, { fuzzy: true })
|
||||
|
||||
console.info(`Revalidating contentEntryTag: ${contentEntryTag}`)
|
||||
revalidateLogger.info(`Revalidating contentEntryTag: ${contentEntryTag}`)
|
||||
revalidateTag(contentEntryTag)
|
||||
await cacheClient.deleteKey(contentEntryTag, { fuzzy: true })
|
||||
|
||||
if (entry.url) {
|
||||
const resolveEntryTag = resolveEntryCacheKey(entryLocale, entry.url)
|
||||
console.info(`Revalidating url: ${resolveEntryTag}`)
|
||||
revalidateLogger.info(`Revalidating url: ${resolveEntryTag}`)
|
||||
|
||||
await cacheClient.deleteKey(resolveEntryTag, { fuzzy: true })
|
||||
}
|
||||
@@ -142,11 +149,13 @@ export async function POST(request: NextRequest) {
|
||||
breadcrumbsAffix
|
||||
)
|
||||
|
||||
console.info(`Revalidating breadcrumbsRefsTag: ${breadcrumbsRefsTag}`)
|
||||
revalidateLogger.info(
|
||||
`Revalidating breadcrumbsRefsTag: ${breadcrumbsRefsTag}`
|
||||
)
|
||||
revalidateTag(breadcrumbsRefsTag)
|
||||
await cacheClient.deleteKey(breadcrumbsRefsTag, { fuzzy: true })
|
||||
|
||||
console.info(`Revalidating breadcrumbsTag: ${breadcrumbsTag}`)
|
||||
revalidateLogger.info(`Revalidating breadcrumbsTag: ${breadcrumbsTag}`)
|
||||
revalidateTag(breadcrumbsTag)
|
||||
await cacheClient.deleteKey(breadcrumbsTag, { fuzzy: true })
|
||||
}
|
||||
@@ -158,7 +167,7 @@ export async function POST(request: NextRequest) {
|
||||
pageSettingsAffix
|
||||
)
|
||||
|
||||
console.info(`Revalidating pageSettingsTag: ${pageSettingsTag}`)
|
||||
revalidateLogger.info(`Revalidating pageSettingsTag: ${pageSettingsTag}`)
|
||||
revalidateTag(pageSettingsTag)
|
||||
await cacheClient.deleteKey(pageSettingsTag, { fuzzy: true })
|
||||
}
|
||||
@@ -177,8 +186,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
return Response.json({ revalidated: true, now: Date.now() })
|
||||
} catch (error) {
|
||||
console.error("Failed to revalidate tag(s)")
|
||||
console.error(error)
|
||||
revalidateLogger.error("Failed to revalidate tag(s)", error)
|
||||
return internalServerError({ revalidated: false, now: Date.now() })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import { warmup } from "@/services/warmup"
|
||||
import { isWarmupKey } from "@/services/warmup/warmupKeys"
|
||||
import { createLogger } from "@/utils/logger"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
const logger = createLogger("Warmup")
|
||||
const logger = createLogger("warmup")
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const url = new URL(req.url)
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import * as Sentry from "@sentry/nextjs"
|
||||
import { useEffect } from "react"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import Image from "@/components/Image"
|
||||
|
||||
/* eslint-disable formatjs/no-literal-string-in-jsx */
|
||||
@@ -11,7 +13,7 @@ export default function GlobalError({
|
||||
}: {
|
||||
error: Error & { digest?: string }
|
||||
}) {
|
||||
console.log({ global_error: error })
|
||||
logger.error("Global Error", { global_error: error })
|
||||
|
||||
useEffect(() => {
|
||||
Sentry.captureException(error)
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
|
||||
import { getSitemapDataById } from "@/utils/sitemap"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
const sitemapLogger = createLogger("sitemap")
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
context: { params: Promise<{ sitemapId: string }> }
|
||||
@@ -13,7 +16,7 @@ export async function GET(
|
||||
const params = await context.params
|
||||
const sitemapId = params.sitemapId
|
||||
|
||||
console.log("[SITEMAP] Fetching sitemap by ID", sitemapId)
|
||||
sitemapLogger.debug("Fetching sitemap by ID", sitemapId)
|
||||
|
||||
if (!sitemapId) {
|
||||
return notFound()
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import { getLastUpdated, getSitemapIds } from "@/utils/sitemap"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
const sitemapLogger = createLogger("sitemap")
|
||||
export async function GET() {
|
||||
console.log(`[SITEMAP] Fetching sitemap`)
|
||||
sitemapLogger.debug(`Fetching sitemap`)
|
||||
|
||||
const lastUpdated = await getLastUpdated()
|
||||
|
||||
@@ -15,7 +18,7 @@ export async function GET() {
|
||||
return new Response("No sitemaps found", { status: 404 })
|
||||
}
|
||||
|
||||
console.log(`[SITEMAP] Sitemaps retrieved: ${sitemaps.length}`)
|
||||
sitemapLogger.debug(`Sitemaps retrieved: ${sitemaps.length}`)
|
||||
|
||||
const urls = sitemaps.map(
|
||||
(id) => `<sitemap>
|
||||
|
||||
Reference in New Issue
Block a user