From 846fd904a6c6c207bace221cac0a2817f3e1fd53 Mon Sep 17 00:00:00 2001 From: Anton Gunnarsson Date: Wed, 18 Jun 2025 12:14:20 +0000 Subject: [PATCH] Merged in feat/sw-2859-set-up-shared-trpc-package (pull request #2319) feat(SW-2859): Create trpc package * Add isEdge, safeTry and dataCache to new common package * Add eslint and move prettier config * Clean up tests * Create trpc package and move initialization * Move errors and a few procedures * Move telemetry to common package * Move tokenManager to common package * Add Sentry to procedures * Clean up procedures * Fix self-referencing imports * Add exports to packages and lint rule to prevent relative imports * Add env to trpc package * Add eslint to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * Fix lang imports Approved-by: Linus Flood --- .../[lang]/(live)/(protected)/logout/route.ts | 3 +- .../payment-callback/page.tsx | 3 +- .../app/[lang]/(live)/(public)/login/route.ts | 3 +- .../(live)/(public)/verifymagiclink/route.ts | 2 +- apps/scandic-web/app/[lang]/(live)/error.tsx | 3 +- apps/scandic-web/app/[lang]/(live)/layout.tsx | 3 +- .../app/[lang]/(live-current)/layout.tsx | 9 +- .../app/[lang]/(no-layout)/layout.tsx | 13 +- .../(protected)/sas-x-scandic/login/page.tsx | 11 +- .../(protected)/sas-x-scandic/otp/page.tsx | 2 +- .../sas-x-scandic/transfer/success/page.tsx | 3 +- .../app/[lang]/(partner)/layout.tsx | 3 +- .../scandic-web/app/[lang]/webview/layout.tsx | 3 +- .../api/web/add-card-callback/[lang]/route.ts | 3 +- .../app/api/web/revalidate/hotel/route.ts | 2 +- .../api/web/revalidate/loyaltyConfig/route.ts | 2 +- .../app/api/web/revalidate/manually/route.ts | 2 +- .../app/api/web/revalidate/route.ts | 2 +- apps/scandic-web/app/api/web/sitemap/route.ts | 3 +- apps/scandic-web/app/api/web/sitemap/sync.ts | 3 +- apps/scandic-web/app/api/web/sitemap/utils.ts | 6 +- .../app/api/web/trpc/[trpc]/route.ts | 4 +- .../Overview/Stats/ExpiringPoints/index.tsx | 3 +- .../SAS/TransferPoints/TransferPointsForm.tsx | 2 +- .../TransferPointsFormClient.tsx | 3 +- .../HotelPage/DialogshiftWidget/Client.tsx | 2 +- .../components/ContentType/HotelPage/utils.ts | 2 +- .../Current/Aside/Contacts/Contact.tsx | 2 +- .../Header/LanguageSwitcher/Desktop/index.tsx | 4 +- .../Header/LanguageSwitcher/Mobile/index.tsx | 4 +- .../components/Current/LangPopup/index.tsx | 4 +- .../components/Current/NotFound/Texts.ts | 2 +- .../components/DatePicker/Range/Desktop.tsx | 2 +- .../components/DatePicker/Range/Mobile.tsx | 2 +- .../components/DatePicker/Single/Desktop.tsx | 2 +- .../components/DatePicker/Single/Mobile.tsx | 3 +- .../components/DatePicker/locales.ts | 2 +- .../components/Forms/Edit/Profile/index.tsx | 8 +- .../BookingConfirmation/Tracking/tracking.ts | 3 +- .../EnterDetails/Summary/_summary._test.tsx | 2 +- .../EnterDetails/Tracking/index.tsx | 3 +- .../EnterDetails/Tracking/tracking.ts | 3 +- .../HotelReservation/HotelCard/index.tsx | 3 +- .../Ancillaries/GuaranteeCallback/index.tsx | 2 +- .../ChangeDates/Steps/Confirmation/index.tsx | 2 +- .../SelectHotel/SelectHotelMap/tracking.ts | 3 +- .../HotelReservation/SelectHotel/tracking.ts | 3 +- .../SelectRate/Tracking/tracking.ts | 3 +- .../HotelReservation/SelectRate/index.tsx | 3 +- .../LanguageSwitcherContent/index.tsx | 4 +- .../components/MyPages/Profile/index.tsx | 3 +- .../TempDesignSystem/Form/Date/date.test.tsx | 3 +- apps/scandic-web/constants/contactSupport.ts | 4 +- apps/scandic-web/constants/languages.ts | 11 +- .../constants/routes/hotelReservation.js | 2 +- apps/scandic-web/constants/webHrefs.ts | 2 +- apps/scandic-web/env/client.ts | 2 +- apps/scandic-web/env/getLiveStatus.ts | 3 +- apps/scandic-web/env/isLangLive.test.ts | 2 +- apps/scandic-web/env/isLangLive.ts | 2 +- apps/scandic-web/env/server.ts | 2 +- apps/scandic-web/hooks/useLang.ts | 2 +- apps/scandic-web/i18n/index.ts | 2 +- apps/scandic-web/i18n/serverContext.ts | 2 +- apps/scandic-web/lib/graphql/_request.ts | 3 +- apps/scandic-web/lib/trpc/Provider.tsx | 5 +- .../lib/trpc/memoizedRequests/index.ts | 3 +- apps/scandic-web/lib/trpc/server.ts | 47 +++- apps/scandic-web/middleware.ts | 2 +- apps/scandic-web/middlewares/redirect.ts | 3 +- apps/scandic-web/middlewares/sasXScandic.ts | 2 +- apps/scandic-web/middlewares/webView.ts | 3 +- apps/scandic-web/netlify/utils/hoteldata.ts | 2 +- apps/scandic-web/next.config.ts | 2 +- apps/scandic-web/package.json | 1 - apps/scandic-web/providers/MyStay.tsx | 3 +- apps/scandic-web/server/context.ts | 72 ------ apps/scandic-web/server/index.ts | 3 +- .../plugins/refIdToConfirmationNumber.ts | 4 +- .../routers/autocomplete/destinations.ts | 4 +- .../server/routers/autocomplete/index.ts | 2 +- .../server/routers/booking/index.ts | 2 +- .../server/routers/booking/input.ts | 4 +- .../server/routers/booking/mutation.ts | 6 +- .../server/routers/booking/query.ts | 16 +- .../server/routers/booking/utils.ts | 10 +- .../routers/contentstack/accountPage/index.ts | 2 +- .../routers/contentstack/accountPage/query.ts | 8 +- .../server/routers/contentstack/base/index.ts | 2 +- .../routers/contentstack/base/output.ts | 3 +- .../server/routers/contentstack/base/query.ts | 11 +- .../routers/contentstack/breadcrumbs/index.ts | 2 +- .../routers/contentstack/breadcrumbs/query.ts | 11 +- .../routers/contentstack/breadcrumbs/utils.ts | 2 +- .../contentstack/campaignPage/index.ts | 2 +- .../contentstack/campaignPage/query.ts | 8 +- .../contentstack/campaignPage/utils.ts | 3 +- .../contentstack/collectionPage/index.ts | 2 +- .../contentstack/collectionPage/query.ts | 6 +- .../contentstack/collectionPage/utils.ts | 8 +- .../routers/contentstack/contentPage/index.ts | 2 +- .../routers/contentstack/contentPage/query.ts | 6 +- .../routers/contentstack/contentPage/utils.ts | 8 +- .../contentstack/destinationCityPage/index.ts | 2 +- .../contentstack/destinationCityPage/query.ts | 8 +- .../contentstack/destinationCityPage/utils.ts | 6 +- .../destinationCountryPage/index.ts | 2 +- .../destinationCountryPage/query.ts | 15 +- .../destinationCountryPage/utils.ts | 6 +- .../destinationOverviewPage/index.ts | 2 +- .../destinationOverviewPage/query.ts | 16 +- .../destinationOverviewPage/utils.ts | 2 +- .../routers/contentstack/hotelPage/index.ts | 2 +- .../routers/contentstack/hotelPage/query.ts | 8 +- .../routers/contentstack/hotelPage/utils.ts | 6 +- .../server/routers/contentstack/index.ts | 2 +- .../contentstack/languageSwitcher/index.ts | 2 +- .../contentstack/languageSwitcher/input.ts | 2 +- .../contentstack/languageSwitcher/query.ts | 3 +- .../contentstack/languageSwitcher/utils.ts | 7 +- .../contentstack/loyaltyLevel/index.ts | 2 +- .../contentstack/loyaltyLevel/input.ts | 3 +- .../contentstack/loyaltyLevel/query.ts | 28 +-- .../routers/contentstack/loyaltyPage/index.ts | 2 +- .../routers/contentstack/loyaltyPage/query.ts | 8 +- .../routers/contentstack/metadata/index.ts | 2 +- .../routers/contentstack/metadata/output.ts | 2 +- .../routers/contentstack/metadata/query.ts | 10 +- .../contentstack/metadata/utils/index.ts | 3 +- .../contentstack/pageSettings/index.ts | 2 +- .../contentstack/pageSettings/query.ts | 4 +- .../routers/contentstack/partner/index.ts | 2 +- .../routers/contentstack/partner/query.ts | 23 +- .../routers/contentstack/reward/index.ts | 2 +- .../routers/contentstack/reward/query.ts | 15 +- .../routers/contentstack/reward/utils.ts | 7 +- .../routers/contentstack/schemas/system.ts | 2 +- .../routers/contentstack/startPage/index.ts | 2 +- .../routers/contentstack/startPage/query.ts | 8 +- .../server/routers/hotels/index.ts | 2 +- .../server/routers/hotels/input.ts | 2 +- .../server/routers/hotels/query.ts | 24 +- .../server/routers/hotels/utils.ts | 6 +- .../server/routers/navigation/index.ts | 2 +- .../navigation/mypages/getPrimaryLinks.ts | 3 +- .../navigation/mypages/getSecondaryLinks.ts | 3 +- .../routers/navigation/mypages/index.ts | 5 +- .../server/routers/partners/index.ts | 2 +- .../server/routers/partners/jobylon/query.ts | 6 +- .../server/routers/partners/sas/index.ts | 2 +- .../routers/partners/sas/linkAccount.ts | 3 +- .../partners/sas/otp/request/requestOtp.ts | 3 +- .../partners/sas/otp/verify/verifyOtp.ts | 3 +- .../partners/sas/performLevelUpgrade.ts | 3 +- .../routers/partners/sas/transferPoints.ts | 4 +- .../routers/partners/sas/unlinkAccount.ts | 3 +- apps/scandic-web/server/routers/user/index.ts | 2 +- apps/scandic-web/server/routers/user/input.ts | 2 +- .../server/routers/user/mutation.ts | 11 +- apps/scandic-web/server/routers/user/query.ts | 9 +- apps/scandic-web/server/routers/user/utils.ts | 5 +- apps/scandic-web/server/trpc.ts | 208 +----------------- apps/scandic-web/server/utils.ts | 3 +- .../cms/getUidAndContentTypeByPath.ts | 2 +- apps/scandic-web/services/warmup/index.ts | 2 +- .../warmup/wamupAutoCompleteLocations.ts | 8 +- .../services/warmup/warmupCountries.ts | 8 +- .../services/warmup/warmupHotelData.ts | 3 +- .../warmup/warmupHotelIdsByCountry.ts | 4 +- .../scandic-web/services/warmup/warmupKeys.ts | 2 +- .../hotelReservation/myStay/changeDates.ts | 2 +- .../components/myPages/myPage/earnAndBurn.ts | 2 +- .../components/myPages/stays/upcoming.ts | 1 - apps/scandic-web/types/components/tracking.ts | 3 +- apps/scandic-web/types/enums/country.ts | 2 +- apps/scandic-web/types/params.ts | 3 +- .../types/requests/asides/contact.ts | 3 +- apps/scandic-web/types/routes.ts | 2 +- apps/scandic-web/types/rte/attrs.ts | 9 +- apps/scandic-web/types/sitemap.ts | 3 +- apps/scandic-web/types/tokens.ts | 6 - .../types/transitionTypes/rte/attrs.ts | 7 +- apps/scandic-web/types/trpc/meta.ts | 3 - apps/scandic-web/utils/dateFormatting.ts | 2 +- apps/scandic-web/utils/entry.ts | 3 +- apps/scandic-web/utils/generateMetadata.ts | 2 +- apps/scandic-web/utils/generateTag.ts | 3 +- apps/scandic-web/utils/languages.ts | 2 +- apps/scandic-web/utils/url.ts | 3 +- apps/scandic-web/utils/webviews.ts | 2 +- packages/common/constants/language.ts | 8 + packages/common/env/server.ts | 6 + packages/common/package.json | 13 ++ .../common}/telemetry/index.test.ts | 4 +- .../common}/telemetry/index.ts | 0 packages/common/tokenManager/index.ts | 2 + .../common/tokenManager}/tokenManager.ts | 14 +- packages/trpc/env/server.ts | 18 ++ packages/trpc/eslint.config.mjs | 89 ++++++++ packages/trpc/global.d.ts | 5 + packages/trpc/lib/context.ts | 34 +++ .../trpc.ts => packages/trpc/lib/errors.ts | 0 packages/trpc/lib/index.ts | 39 ++++ packages/trpc/lib/procedures.ts | 164 ++++++++++++++ .../trpc/lib}/transformer.ts | 0 packages/trpc/lib/utils.ts | 7 + packages/trpc/lint-staged.config.mjs | 6 + packages/trpc/package.json | 38 ++++ packages/trpc/prettier.config.cjs | 8 + packages/trpc/tsconfig.json | 10 + yarn.lock | 29 ++- 211 files changed, 989 insertions(+), 627 deletions(-) delete mode 100644 apps/scandic-web/server/context.ts delete mode 100644 apps/scandic-web/types/tokens.ts delete mode 100644 apps/scandic-web/types/trpc/meta.ts create mode 100644 packages/common/constants/language.ts rename {apps/scandic-web/server => packages/common}/telemetry/index.test.ts (97%) rename {apps/scandic-web/server => packages/common}/telemetry/index.ts (100%) create mode 100644 packages/common/tokenManager/index.ts rename {apps/scandic-web/server => packages/common/tokenManager}/tokenManager.ts (92%) create mode 100644 packages/trpc/env/server.ts create mode 100644 packages/trpc/eslint.config.mjs create mode 100644 packages/trpc/global.d.ts create mode 100644 packages/trpc/lib/context.ts rename apps/scandic-web/server/errors/trpc.ts => packages/trpc/lib/errors.ts (100%) create mode 100644 packages/trpc/lib/index.ts create mode 100644 packages/trpc/lib/procedures.ts rename {apps/scandic-web/server => packages/trpc/lib}/transformer.ts (100%) create mode 100644 packages/trpc/lib/utils.ts create mode 100644 packages/trpc/lint-staged.config.mjs create mode 100644 packages/trpc/package.json create mode 100644 packages/trpc/prettier.config.cjs create mode 100644 packages/trpc/tsconfig.json diff --git a/apps/scandic-web/app/[lang]/(live)/(protected)/logout/route.ts b/apps/scandic-web/app/[lang]/(live)/(protected)/logout/route.ts index 8adfe8d98..c877c0335 100644 --- a/apps/scandic-web/app/[lang]/(live)/(protected)/logout/route.ts +++ b/apps/scandic-web/app/[lang]/(live)/(protected)/logout/route.ts @@ -1,7 +1,8 @@ import { type NextRequest, NextResponse } from "next/server" import { AuthError } from "next-auth" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { env } from "@/env/server" import { internalServerError } from "@/server/errors/next" import { getPublicURL } from "@/server/utils" diff --git a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(payment-callback)/payment-callback/page.tsx b/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(payment-callback)/payment-callback/page.tsx index 4327d8410..2ab29ae71 100644 --- a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(payment-callback)/payment-callback/page.tsx +++ b/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(payment-callback)/payment-callback/page.tsx @@ -1,5 +1,7 @@ import { notFound } from "next/navigation" +import { getServiceToken } from "@scandic-hotels/common/tokenManager" + import { BookingErrorCodeEnum, PaymentCallbackStatusEnum, @@ -10,7 +12,6 @@ import { } from "@/constants/routes/hotelReservation" import { serverClient } from "@/lib/trpc/server" import { getBooking } from "@/server/routers/booking/utils" -import { getServiceToken } from "@/server/tokenManager" import { auth } from "@/auth" import HandleErrorCallback from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleErrorCallback" diff --git a/apps/scandic-web/app/[lang]/(live)/(public)/login/route.ts b/apps/scandic-web/app/[lang]/(live)/(public)/login/route.ts index 4dd995926..0e1fca3d5 100644 --- a/apps/scandic-web/app/[lang]/(live)/(public)/login/route.ts +++ b/apps/scandic-web/app/[lang]/(live)/(public)/login/route.ts @@ -1,7 +1,8 @@ import { type NextRequest, NextResponse } from "next/server" import { AuthError } from "next-auth" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { env } from "@/env/server" import { internalServerError } from "@/server/errors/next" import { getPublicURL } from "@/server/utils" diff --git a/apps/scandic-web/app/[lang]/(live)/(public)/verifymagiclink/route.ts b/apps/scandic-web/app/[lang]/(live)/(public)/verifymagiclink/route.ts index 87b29a889..dbc162dd2 100644 --- a/apps/scandic-web/app/[lang]/(live)/(public)/verifymagiclink/route.ts +++ b/apps/scandic-web/app/[lang]/(live)/(public)/verifymagiclink/route.ts @@ -6,7 +6,7 @@ import { getPublicURL } from "@/server/utils" import { signIn } from "@/auth" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" export async function GET( request: NextRequest, diff --git a/apps/scandic-web/app/[lang]/(live)/error.tsx b/apps/scandic-web/app/[lang]/(live)/error.tsx index 0dad8ad60..9a25c0283 100644 --- a/apps/scandic-web/app/[lang]/(live)/error.tsx +++ b/apps/scandic-web/app/[lang]/(live)/error.tsx @@ -5,9 +5,10 @@ import { useParams, useRouter, useSearchParams } from "next/navigation" import { startTransition, useEffect, useRef } from "react" import { useIntl } from "react-intl" +import { SESSION_EXPIRED } from "@scandic-hotels/trpc/errors" + import { login } from "@/constants/routes/handleAuth" import { env } from "@/env/client" -import { SESSION_EXPIRED } from "@/server/errors/trpc" import styles from "./error.module.css" diff --git a/apps/scandic-web/app/[lang]/(live)/layout.tsx b/apps/scandic-web/app/[lang]/(live)/layout.tsx index 3110fc9f6..6249748f1 100644 --- a/apps/scandic-web/app/[lang]/(live)/layout.tsx +++ b/apps/scandic-web/app/[lang]/(live)/layout.tsx @@ -7,7 +7,8 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools" import Script from "next/script" import { SessionProvider } from "next-auth/react" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import TrpcProvider from "@/lib/trpc/Provider" import { SessionRefresher } from "@/components/Auth/TokenRefresher" diff --git a/apps/scandic-web/app/[lang]/(live-current)/layout.tsx b/apps/scandic-web/app/[lang]/(live-current)/layout.tsx index 126810ccf..e4411e973 100644 --- a/apps/scandic-web/app/[lang]/(live-current)/layout.tsx +++ b/apps/scandic-web/app/[lang]/(live-current)/layout.tsx @@ -7,7 +7,7 @@ import "@scandic-hotels/design-system/style.css" import Script from "next/script" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import TokenRefresher from "@/components/Auth/TokenRefresher" import CookieBotConsent from "@/components/CookieBot" @@ -35,12 +35,9 @@ export default async function RootLayout( LayoutArgs & { header: React.ReactNode } > ) { - const params = await props.params; + const params = await props.params - const { - children, - header - } = props; + const { children, header } = props setLang(params.lang) const messages = await getMessages(params.lang) diff --git a/apps/scandic-web/app/[lang]/(no-layout)/layout.tsx b/apps/scandic-web/app/[lang]/(no-layout)/layout.tsx index 8bb303798..0a9fb1d8b 100644 --- a/apps/scandic-web/app/[lang]/(no-layout)/layout.tsx +++ b/apps/scandic-web/app/[lang]/(no-layout)/layout.tsx @@ -7,7 +7,8 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools" import Script from "next/script" import { SessionProvider } from "next-auth/react" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import TrpcProvider from "@/lib/trpc/Provider" import { SessionRefresher } from "@/components/Auth/TokenRefresher" @@ -23,12 +24,12 @@ import { setLang } from "@/i18n/serverContext" import type { LangParams, LayoutArgs } from "@/types/params" -export default async function RootLayout(props: React.PropsWithChildren>) { - const params = await props.params; +export default async function RootLayout( + props: React.PropsWithChildren> +) { + const params = await props.params - const { - children - } = props; + const { children } = props setLang(params.lang) const messages = await getMessages(params.lang) diff --git a/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/login/page.tsx b/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/login/page.tsx index f5973c4e2..d149687af 100644 --- a/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/login/page.tsx +++ b/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/login/page.tsx @@ -14,8 +14,9 @@ import { getIntl } from "@/i18n" import { SASModal } from "../components/SASModal" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { LangParams, PageArgs, SearchParams } from "@/types/params" -import type { Lang } from "@/constants/languages" import type { State } from "../sasUtils" const searchParamsSchema = z.object({ @@ -24,9 +25,11 @@ const searchParamsSchema = z.object({ type Intent = z.infer["intent"] -export default async function SASxScandicLoginPage(props: PageArgs & SearchParams) { - const params = await props.params; - const searchParams = await props.searchParams; +export default async function SASxScandicLoginPage( + props: PageArgs & SearchParams +) { + const params = await props.params + const searchParams = await props.searchParams const result = searchParamsSchema.safeParse(searchParams) if (!result.success) { // TOOD where to redirect? diff --git a/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/otp/page.tsx b/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/otp/page.tsx index ae2f925f1..e10bd8a1d 100644 --- a/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/otp/page.tsx +++ b/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/otp/page.tsx @@ -14,10 +14,10 @@ import OneTimePasswordForm, { type OnSubmitHandler, } from "./OneTimePasswordForm" +import type { Lang } from "@scandic-hotels/common/constants/language" import type { ReactNode } from "react" import type { LangParams, PageArgs, SearchParams } from "@/types/params" -import type { Lang } from "@/constants/languages" const otpError = z.enum(["invalidCode", "expiredCode"]) const intent = z.enum(["link", "unlink", "transfer"]) diff --git a/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/transfer/success/page.tsx b/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/transfer/success/page.tsx index c3e455395..95f563515 100644 --- a/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/transfer/success/page.tsx +++ b/apps/scandic-web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/transfer/success/page.tsx @@ -17,8 +17,9 @@ import { SASModal } from "../../components/SASModal" import styles from "./transferSuccess.module.css" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { LangParams, PageArgs, SearchParams } from "@/types/params" -import type { Lang } from "@/constants/languages" export default async function SASxScandicTransferSuccessPage( props: PageArgs & SearchParams<{ p?: string }> diff --git a/apps/scandic-web/app/[lang]/(partner)/layout.tsx b/apps/scandic-web/app/[lang]/(partner)/layout.tsx index 7e7aa3c1b..7f2d7f895 100644 --- a/apps/scandic-web/app/[lang]/(partner)/layout.tsx +++ b/apps/scandic-web/app/[lang]/(partner)/layout.tsx @@ -6,7 +6,8 @@ import "@scandic-hotels/design-system/style.css" import { ReactQueryDevtools } from "@tanstack/react-query-devtools" import Script from "next/script" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { env } from "@/env/server" import TrpcProvider from "@/lib/trpc/Provider" diff --git a/apps/scandic-web/app/[lang]/webview/layout.tsx b/apps/scandic-web/app/[lang]/webview/layout.tsx index c0e641aa9..83c1ab851 100644 --- a/apps/scandic-web/app/[lang]/webview/layout.tsx +++ b/apps/scandic-web/app/[lang]/webview/layout.tsx @@ -5,7 +5,8 @@ import "@scandic-hotels/design-system/style.css" import Script from "next/script" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import TrpcProvider from "@/lib/trpc/Provider" import { ToastHandler } from "@/components/TempDesignSystem/Toasts" diff --git a/apps/scandic-web/app/api/web/add-card-callback/[lang]/route.ts b/apps/scandic-web/app/api/web/add-card-callback/[lang]/route.ts index 72b18c93b..daccebdc0 100644 --- a/apps/scandic-web/app/api/web/add-card-callback/[lang]/route.ts +++ b/apps/scandic-web/app/api/web/add-card-callback/[lang]/route.ts @@ -1,4 +1,5 @@ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { profile } from "@/constants/routes/myPages" import { serverClient } from "@/lib/trpc/server" import { getPublicURL } from "@/server/utils" diff --git a/apps/scandic-web/app/api/web/revalidate/hotel/route.ts b/apps/scandic-web/app/api/web/revalidate/hotel/route.ts index d7d38ac45..420d31b07 100644 --- a/apps/scandic-web/app/api/web/revalidate/hotel/route.ts +++ b/apps/scandic-web/app/api/web/revalidate/hotel/route.ts @@ -2,9 +2,9 @@ import { revalidateTag } from "next/cache" import { headers } from "next/headers" import { z } from "zod" +import { Lang } from "@scandic-hotels/common/constants/language" import { getCacheClient } from "@scandic-hotels/common/dataCache" -import { Lang } from "@/constants/languages" import { env } from "@/env/server" import { badRequest, internalServerError, notFound } from "@/server/errors/next" diff --git a/apps/scandic-web/app/api/web/revalidate/loyaltyConfig/route.ts b/apps/scandic-web/app/api/web/revalidate/loyaltyConfig/route.ts index 16e401e48..5a312b00e 100644 --- a/apps/scandic-web/app/api/web/revalidate/loyaltyConfig/route.ts +++ b/apps/scandic-web/app/api/web/revalidate/loyaltyConfig/route.ts @@ -2,9 +2,9 @@ import { revalidateTag } from "next/cache" import { headers } from "next/headers" import { z } from "zod" +import { Lang } from "@scandic-hotels/common/constants/language" import { getCacheClient } from "@scandic-hotels/common/dataCache" -import { Lang } from "@/constants/languages" import { env } from "@/env/server" import { badRequest, internalServerError, notFound } from "@/server/errors/next" diff --git a/apps/scandic-web/app/api/web/revalidate/manually/route.ts b/apps/scandic-web/app/api/web/revalidate/manually/route.ts index 17794e25c..0d1a561fd 100644 --- a/apps/scandic-web/app/api/web/revalidate/manually/route.ts +++ b/apps/scandic-web/app/api/web/revalidate/manually/route.ts @@ -8,7 +8,7 @@ import { badRequest, internalServerError } from "@/server/errors/next" import { generateTag } from "@/utils/generateTag" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" // This file is primarily to be used locally to test // purging your cache for new (and old) requests diff --git a/apps/scandic-web/app/api/web/revalidate/route.ts b/apps/scandic-web/app/api/web/revalidate/route.ts index b6a764a5c..e122c5340 100644 --- a/apps/scandic-web/app/api/web/revalidate/route.ts +++ b/apps/scandic-web/app/api/web/revalidate/route.ts @@ -2,9 +2,9 @@ import { revalidateTag } from "next/cache" import { headers } from "next/headers" import { z } from "zod" +import { Lang } from "@scandic-hotels/common/constants/language" import { getCacheClient } from "@scandic-hotels/common/dataCache" -import { Lang } from "@/constants/languages" import { env } from "@/env/server" import { badRequest, internalServerError } from "@/server/errors/next" import { affix as breadcrumbsAffix } from "@/server/routers/contentstack/breadcrumbs/utils" diff --git a/apps/scandic-web/app/api/web/sitemap/route.ts b/apps/scandic-web/app/api/web/sitemap/route.ts index 87ca49f8d..93031c12f 100644 --- a/apps/scandic-web/app/api/web/sitemap/route.ts +++ b/apps/scandic-web/app/api/web/sitemap/route.ts @@ -1,8 +1,9 @@ import { type NextRequest, NextResponse } from "next/server" +import { createCounter } from "@scandic-hotels/common/telemetry" + import { env } from "@/env/server" import { dt } from "@/lib/dt" -import { createCounter } from "@/server/telemetry" import { getEntries, diff --git a/apps/scandic-web/app/api/web/sitemap/sync.ts b/apps/scandic-web/app/api/web/sitemap/sync.ts index f90106282..3b54bdb93 100644 --- a/apps/scandic-web/app/api/web/sitemap/sync.ts +++ b/apps/scandic-web/app/api/web/sitemap/sync.ts @@ -1,7 +1,8 @@ import { Region, Stack } from "contentstack" +import { createCounter } from "@scandic-hotels/common/telemetry" + import { env } from "@/env/server" -import { createCounter } from "@/server/telemetry" import type { SyncResponse } from "@/types/sitemap" diff --git a/apps/scandic-web/app/api/web/sitemap/utils.ts b/apps/scandic-web/app/api/web/sitemap/utils.ts index 7c87b1093..375f0e472 100644 --- a/apps/scandic-web/app/api/web/sitemap/utils.ts +++ b/apps/scandic-web/app/api/web/sitemap/utils.ts @@ -1,10 +1,12 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" + import { env } from "@/env/server" -import { createCounter } from "@/server/telemetry" import { removeTrailingSlash } from "@/utils/url" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { SyncItem } from "@/types/sitemap" -import type { Lang } from "@/constants/languages" export function mergeEntries( currentEntries: SyncItem[], diff --git a/apps/scandic-web/app/api/web/trpc/[trpc]/route.ts b/apps/scandic-web/app/api/web/trpc/[trpc]/route.ts index 72978cedb..b1eac0bd1 100644 --- a/apps/scandic-web/app/api/web/trpc/[trpc]/route.ts +++ b/apps/scandic-web/app/api/web/trpc/[trpc]/route.ts @@ -1,11 +1,11 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch" +import { createAppContext } from "@/lib/trpc/server" import { appRouter } from "@/server" -import { createContext } from "@/server/context" async function handler(req: Request) { return fetchRequestHandler({ - createContext, + createContext: createAppContext, endpoint: "/api/web/trpc", req, router: appRouter, diff --git a/apps/scandic-web/components/Blocks/DynamicContent/Overview/Stats/ExpiringPoints/index.tsx b/apps/scandic-web/components/Blocks/DynamicContent/Overview/Stats/ExpiringPoints/index.tsx index 8e26c79be..379fa5e76 100644 --- a/apps/scandic-web/components/Blocks/DynamicContent/Overview/Stats/ExpiringPoints/index.tsx +++ b/apps/scandic-web/components/Blocks/DynamicContent/Overview/Stats/ExpiringPoints/index.tsx @@ -1,4 +1,5 @@ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { dt } from "@/lib/dt" import Body from "@/components/TempDesignSystem/Text/Body" diff --git a/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsForm.tsx b/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsForm.tsx index d2c63de9d..e8adff665 100644 --- a/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsForm.tsx +++ b/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsForm.tsx @@ -12,7 +12,7 @@ import { TransferPointsFormClient } from "./TransferPointsFormClient" import styles from "./transferPoints.module.css" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" export async function TransferPointsForm({ lang }: { lang: Lang }) { const profile = await getProfileWithExtendedPartnerData() diff --git a/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsFormClient.tsx b/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsFormClient.tsx index c1a23438e..c4fc1be4d 100644 --- a/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsFormClient.tsx +++ b/apps/scandic-web/components/Blocks/DynamicContent/SAS/TransferPoints/TransferPointsFormClient.tsx @@ -26,8 +26,9 @@ import Button from "@/components/TempDesignSystem/Button" import styles from "./transferPoints.module.css" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { LangParams } from "@/types/params" -import type { Lang } from "@/constants/languages" type TransferPointsFormClientProps = { sasPoints: number | null diff --git a/apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/Client.tsx b/apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/Client.tsx index a4d588456..f0907281a 100644 --- a/apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/Client.tsx +++ b/apps/scandic-web/components/ContentType/HotelPage/DialogshiftWidget/Client.tsx @@ -4,7 +4,7 @@ import "dialogshift-webchat-sdk/bundles/dialogshift-webchat-sdk.min.css" import { useEffect, useRef } from "react" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" interface DialogshiftWidgetClientProps { widgetId: string diff --git a/apps/scandic-web/components/ContentType/HotelPage/utils.ts b/apps/scandic-web/components/ContentType/HotelPage/utils.ts index d77d5e952..2b570abbc 100644 --- a/apps/scandic-web/components/ContentType/HotelPage/utils.ts +++ b/apps/scandic-web/components/ContentType/HotelPage/utils.ts @@ -1,3 +1,4 @@ +import type { Lang } from "@scandic-hotels/common/constants/language" import type { IntlShape } from "react-intl" import { HealthFacilitiesEnum } from "@/types/components/hotelPage/facilities" @@ -13,7 +14,6 @@ import { import { HotelHashValues } from "@/types/enums/hotelPage" import type { Hotel, HotelData } from "@/types/hotel" import type { HotelPage } from "@/types/trpc/routers/contentstack/hotelPage" -import type { Lang } from "@/constants/languages" export function getRoomNameAsParam(roomName: string) { return roomName diff --git a/apps/scandic-web/components/Current/Aside/Contacts/Contact.tsx b/apps/scandic-web/components/Current/Aside/Contacts/Contact.tsx index ceda3edc3..5a6dfe6da 100644 --- a/apps/scandic-web/components/Current/Aside/Contacts/Contact.tsx +++ b/apps/scandic-web/components/Current/Aside/Contacts/Contact.tsx @@ -1,6 +1,6 @@ /* eslint-disable formatjs/no-literal-string-in-jsx */ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import styles from "./contact.module.css" diff --git a/apps/scandic-web/components/Current/Header/LanguageSwitcher/Desktop/index.tsx b/apps/scandic-web/components/Current/Header/LanguageSwitcher/Desktop/index.tsx index 7f8d15879..9630f1836 100644 --- a/apps/scandic-web/components/Current/Header/LanguageSwitcher/Desktop/index.tsx +++ b/apps/scandic-web/components/Current/Header/LanguageSwitcher/Desktop/index.tsx @@ -3,7 +3,7 @@ "use client" import { useCallback, useEffect, useRef, useState } from "react" -import { type Lang, languages } from "@/constants/languages" +import { languages } from "@/constants/languages" import { env } from "@/env/client" import Link from "@/components/TempDesignSystem/Link" @@ -11,6 +11,8 @@ import useLang from "@/hooks/useLang" import styles from "./desktop.module.css" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { LanguageSwitcherProps } from "@/types/components/current/languageSwitcher" export default function Desktop({ urls }: LanguageSwitcherProps) { diff --git a/apps/scandic-web/components/Current/Header/LanguageSwitcher/Mobile/index.tsx b/apps/scandic-web/components/Current/Header/LanguageSwitcher/Mobile/index.tsx index 255cc8712..08a96c8af 100644 --- a/apps/scandic-web/components/Current/Header/LanguageSwitcher/Mobile/index.tsx +++ b/apps/scandic-web/components/Current/Header/LanguageSwitcher/Mobile/index.tsx @@ -3,13 +3,15 @@ "use client" import { useState } from "react" -import { type Lang, languages } from "@/constants/languages" +import { languages } from "@/constants/languages" import { env } from "@/env/client" import useLang from "@/hooks/useLang" import styles from "./mobile.module.css" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { LanguageSwitcherProps } from "@/types/components/current/languageSwitcher" export default function Mobile({ urls }: LanguageSwitcherProps) { diff --git a/apps/scandic-web/components/Current/LangPopup/index.tsx b/apps/scandic-web/components/Current/LangPopup/index.tsx index 108548730..13c577a60 100644 --- a/apps/scandic-web/components/Current/LangPopup/index.tsx +++ b/apps/scandic-web/components/Current/LangPopup/index.tsx @@ -2,7 +2,9 @@ import { headers } from "next/headers" -import { Lang, localeToLang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + +import { localeToLang } from "@/constants/languages" import { getLang } from "@/i18n/serverContext" diff --git a/apps/scandic-web/components/Current/NotFound/Texts.ts b/apps/scandic-web/components/Current/NotFound/Texts.ts index c07b406ba..5c3cbb0bd 100644 --- a/apps/scandic-web/components/Current/NotFound/Texts.ts +++ b/apps/scandic-web/components/Current/NotFound/Texts.ts @@ -1,4 +1,4 @@ -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" type Texts = { title: string diff --git a/apps/scandic-web/components/DatePicker/Range/Desktop.tsx b/apps/scandic-web/components/DatePicker/Range/Desktop.tsx index e57274c42..5e4653c25 100644 --- a/apps/scandic-web/components/DatePicker/Range/Desktop.tsx +++ b/apps/scandic-web/components/DatePicker/Range/Desktop.tsx @@ -4,11 +4,11 @@ import { useState } from "react" import { DayPicker } from "react-day-picker" import { useIntl } from "react-intl" +import { Lang } from "@scandic-hotels/common/constants/language" import { Divider } from "@scandic-hotels/design-system/Divider" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { Typography } from "@scandic-hotels/design-system/Typography" -import { Lang } from "@/constants/languages" import { dt } from "@/lib/dt" import Button from "@/components/TempDesignSystem/Button" diff --git a/apps/scandic-web/components/DatePicker/Range/Mobile.tsx b/apps/scandic-web/components/DatePicker/Range/Mobile.tsx index a477bb97a..61e09286c 100644 --- a/apps/scandic-web/components/DatePicker/Range/Mobile.tsx +++ b/apps/scandic-web/components/DatePicker/Range/Mobile.tsx @@ -3,10 +3,10 @@ import { useEffect, useRef, useState } from "react" import { type DateRange, DayPicker } from "react-day-picker" import { useIntl } from "react-intl" +import { Lang } from "@scandic-hotels/common/constants/language" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { Typography } from "@scandic-hotels/design-system/Typography" -import { Lang } from "@/constants/languages" import { dt } from "@/lib/dt" import Button from "@/components/TempDesignSystem/Button" diff --git a/apps/scandic-web/components/DatePicker/Single/Desktop.tsx b/apps/scandic-web/components/DatePicker/Single/Desktop.tsx index 2c0e6887f..0cbad7005 100644 --- a/apps/scandic-web/components/DatePicker/Single/Desktop.tsx +++ b/apps/scandic-web/components/DatePicker/Single/Desktop.tsx @@ -4,10 +4,10 @@ import { useState } from "react" import { DayPicker } from "react-day-picker" import { useIntl } from "react-intl" +import { Lang } from "@scandic-hotels/common/constants/language" import { Divider } from "@scandic-hotels/design-system/Divider" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" -import { Lang } from "@/constants/languages" import { dt } from "@/lib/dt" import Button from "@/components/TempDesignSystem/Button" diff --git a/apps/scandic-web/components/DatePicker/Single/Mobile.tsx b/apps/scandic-web/components/DatePicker/Single/Mobile.tsx index f224f7a7c..a1be77e60 100644 --- a/apps/scandic-web/components/DatePicker/Single/Mobile.tsx +++ b/apps/scandic-web/components/DatePicker/Single/Mobile.tsx @@ -2,7 +2,8 @@ import { DayPicker } from "react-day-picker" import { useIntl } from "react-intl" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { dt } from "@/lib/dt" import Button from "@/components/TempDesignSystem/Button" diff --git a/apps/scandic-web/components/DatePicker/locales.ts b/apps/scandic-web/components/DatePicker/locales.ts index e670123d0..17d97a36a 100644 --- a/apps/scandic-web/components/DatePicker/locales.ts +++ b/apps/scandic-web/components/DatePicker/locales.ts @@ -1,6 +1,6 @@ import { da, de, fi, nb, sv } from "date-fns/locale" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" export const locales = { [Lang.da]: da, diff --git a/apps/scandic-web/components/Forms/Edit/Profile/index.tsx b/apps/scandic-web/components/Forms/Edit/Profile/index.tsx index 4b3da1ff0..2d5c6c421 100644 --- a/apps/scandic-web/components/Forms/Edit/Profile/index.tsx +++ b/apps/scandic-web/components/Forms/Edit/Profile/index.tsx @@ -5,11 +5,7 @@ import { useEffect, useState } from "react" import { FormProvider, useForm } from "react-hook-form" import { useIntl } from "react-intl" -import { - getDefaultCountryFromLang, - type Lang, - langToApiLang, -} from "@/constants/languages" +import { getDefaultCountryFromLang, langToApiLang } from "@/constants/languages" import { logout } from "@/constants/routes/handleAuth" import { profile } from "@/constants/routes/myPages" import { trpc } from "@/lib/trpc/client" @@ -28,6 +24,8 @@ import { type EditProfileSchema, editProfileSchema } from "./schema" import styles from "./form.module.css" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { type EditFormProps, Status, diff --git a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/tracking.ts b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/tracking.ts index afa68e1d9..54782eca7 100644 --- a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/tracking.ts +++ b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/tracking.ts @@ -6,6 +6,8 @@ import { getSpecialRoomType } from "@/utils/specialRoomType" import { invertedBedTypeMap } from "../../utils" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter" import { TrackingChannelEnum, @@ -20,7 +22,6 @@ import { RateEnum } from "@/types/enums/rate" import type { Room } from "@/types/stores/booking-confirmation" import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation" import type { RateDefinition } from "@/types/trpc/routers/hotel/roomAvailability" -import type { Lang } from "@/constants/languages" function getRate(cancellationRule: RateDefinition["cancellationRule"] | null) { switch (cancellationRule) { diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/_summary._test.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/_summary._test.tsx index 13428034d..b7db2b39c 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/_summary._test.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/_summary._test.tsx @@ -2,7 +2,7 @@ // import { act, cleanup, render, screen, within } from "@testing-library/react" // import { type IntlConfig, IntlProvider } from "react-intl" -// import { Lang } from "@/constants/languages" +// import { Lang } from "@scandic-hotels/common/constants/language" // import { // bedType, diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/index.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/index.tsx index 6711f38c6..d1a34f4cf 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/index.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/index.tsx @@ -7,10 +7,11 @@ import { useSearchHistory } from "@/hooks/useSearchHistory" import { getTracking } from "./tracking" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { DetailsBooking } from "@/types/components/hotelReservation/enterDetails/details" import type { Hotel } from "@/types/hotel" import type { Room } from "@/types/providers/details/room" -import type { Lang } from "@/constants/languages" interface TrackingWrapperProps { booking: DetailsBooking diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/tracking.ts b/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/tracking.ts index edb1451d4..6a4d0dc76 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/tracking.ts +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/tracking.ts @@ -5,6 +5,8 @@ import { REDEMPTION } from "@/constants/booking" import { sumPackages } from "@/components/HotelReservation/utils" import { getSpecialRoomType } from "@/utils/specialRoomType" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums" import type { BreakfastPackages } from "@/types/components/hotelReservation/breakfast" import type { DetailsBooking } from "@/types/components/hotelReservation/enterDetails/details" @@ -24,7 +26,6 @@ import type { PriceProduct, Product, } from "@/types/trpc/routers/hotel/roomAvailability" -import type { Lang } from "@/constants/languages" export function getTracking( booking: DetailsBooking, diff --git a/apps/scandic-web/components/HotelReservation/HotelCard/index.tsx b/apps/scandic-web/components/HotelReservation/HotelCard/index.tsx index f1adb3288..ba0c19e47 100644 --- a/apps/scandic-web/components/HotelReservation/HotelCard/index.tsx +++ b/apps/scandic-web/components/HotelReservation/HotelCard/index.tsx @@ -37,10 +37,11 @@ import { hotelCardVariants } from "./variants" import styles from "./hotelCard.module.css" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { HotelCardListingTypeEnum } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps" import type { HotelCardProps } from "@/types/components/hotelReservation/selectHotel/hotelCardProps" import { SidePeekEnum } from "@/types/components/hotelReservation/sidePeek" -import type { Lang } from "@/constants/languages" function HotelCard({ hotelData: { availability, hotel }, diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/GuaranteeCallback/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/GuaranteeCallback/index.tsx index 2e908cbf7..4ce2b76bf 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/GuaranteeCallback/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/GuaranteeCallback/index.tsx @@ -15,7 +15,7 @@ import { trackAncillarySuccess, } from "@/utils/tracking/myStay" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" export default function GuaranteeAncillaryHandler({ confirmationNumber, diff --git a/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/ChangeDates/Steps/Confirmation/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/ChangeDates/Steps/Confirmation/index.tsx index a9929574a..57d3fcce2 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/ChangeDates/Steps/Confirmation/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/ChangeDates/Steps/Confirmation/index.tsx @@ -16,7 +16,7 @@ import PriceAndDate from "./PriceAndDate" import styles from "./confirmation.module.css" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" interface ConfirmationProps { checkInDate: string diff --git a/apps/scandic-web/components/HotelReservation/SelectHotel/SelectHotelMap/tracking.ts b/apps/scandic-web/components/HotelReservation/SelectHotel/SelectHotelMap/tracking.ts index 8f09bfbf2..7c0921682 100644 --- a/apps/scandic-web/components/HotelReservation/SelectHotel/SelectHotelMap/tracking.ts +++ b/apps/scandic-web/components/HotelReservation/SelectHotel/SelectHotelMap/tracking.ts @@ -1,12 +1,13 @@ import { differenceInCalendarDays, format, isWeekend } from "date-fns" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums" import { TrackingChannelEnum, type TrackingSDKHotelInfo, type TrackingSDKPageData, } from "@/types/components/tracking" -import type { Lang } from "@/constants/languages" import type { ChildrenInRoom } from "@/utils/hotelSearchDetails" export function getTracking( diff --git a/apps/scandic-web/components/HotelReservation/SelectHotel/tracking.ts b/apps/scandic-web/components/HotelReservation/SelectHotel/tracking.ts index b62e59953..cd42d2681 100644 --- a/apps/scandic-web/components/HotelReservation/SelectHotel/tracking.ts +++ b/apps/scandic-web/components/HotelReservation/SelectHotel/tracking.ts @@ -1,12 +1,13 @@ import { differenceInCalendarDays, format, isWeekend } from "date-fns" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums" import { TrackingChannelEnum, type TrackingSDKHotelInfo, type TrackingSDKPageData, } from "@/types/components/tracking" -import type { Lang } from "@/constants/languages" import type { ChildrenInRoom } from "@/utils/hotelSearchDetails" export function getTracking( diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/Tracking/tracking.ts b/apps/scandic-web/components/HotelReservation/SelectRate/Tracking/tracking.ts index b6f119d90..a913702a4 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/Tracking/tracking.ts +++ b/apps/scandic-web/components/HotelReservation/SelectRate/Tracking/tracking.ts @@ -1,5 +1,7 @@ import { differenceInCalendarDays, format, isWeekend } from "date-fns" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums" import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter" import type { Room } from "@/types/components/hotelReservation/selectRate/selectRate" @@ -8,7 +10,6 @@ import { type TrackingSDKHotelInfo, type TrackingSDKPageData, } from "@/types/components/tracking" -import type { Lang } from "@/constants/languages" import type { ChildrenInRoom } from "@/utils/hotelSearchDetails" export function getTracking( diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx b/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx index 92ed1d949..7cdc7e6ee 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx @@ -12,8 +12,9 @@ import FnFNotAllowedAlert from "../FnFNotAllowedAlert/FnFNotAllowedAlert" import AvailabilityError from "./AvailabilityError" import Tracking from "./Tracking" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { SelectRateBooking } from "@/types/components/hotelReservation/selectRate/selectRate" -import type { Lang } from "@/constants/languages" export default async function SelectRatePage({ lang, diff --git a/apps/scandic-web/components/LanguageSwitcher/LanguageSwitcherContent/index.tsx b/apps/scandic-web/components/LanguageSwitcher/LanguageSwitcherContent/index.tsx index b7166c891..d8594c0eb 100644 --- a/apps/scandic-web/components/LanguageSwitcher/LanguageSwitcherContent/index.tsx +++ b/apps/scandic-web/components/LanguageSwitcher/LanguageSwitcherContent/index.tsx @@ -6,7 +6,7 @@ import { useIntl } from "react-intl" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { Typography } from "@scandic-hotels/design-system/Typography" -import { type Lang, languages } from "@/constants/languages" +import { languages } from "@/constants/languages" import { env } from "@/env/client" import Link from "@/components/TempDesignSystem/Link" @@ -17,6 +17,8 @@ import { replaceUrlPart } from "./utils" import styles from "./languageSwitcherContent.module.css" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { LanguageSwitcherContentProps } from "@/types/components/languageSwitcher/languageSwitcher" export default function LanguageSwitcherContent({ diff --git a/apps/scandic-web/components/MyPages/Profile/index.tsx b/apps/scandic-web/components/MyPages/Profile/index.tsx index 18036d911..51f11d8df 100644 --- a/apps/scandic-web/components/MyPages/Profile/index.tsx +++ b/apps/scandic-web/components/MyPages/Profile/index.tsx @@ -1,9 +1,10 @@ +import { Lang } from "@scandic-hotels/common/constants/language" import { Divider } from "@scandic-hotels/design-system/Divider" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { Typography } from "@scandic-hotels/design-system/Typography" import { countriesMap } from "@/constants/countries" -import { Lang, languages } from "@/constants/languages" +import { languages } from "@/constants/languages" import { profileEdit } from "@/constants/routes/myPages" import { getProfile } from "@/lib/trpc/memoizedRequests" diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Date/date.test.tsx b/apps/scandic-web/components/TempDesignSystem/Form/Date/date.test.tsx index 15e31140b..01ccb7c57 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Date/date.test.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/Date/date.test.tsx @@ -5,7 +5,8 @@ import { render, screen } from "@testing-library/react" import { type UserEvent, userEvent } from "@testing-library/user-event" import { FormProvider, useForm } from "react-hook-form" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { dt } from "@/lib/dt" import { getLocalizedMonthName } from "@/utils/dateFormatting" diff --git a/apps/scandic-web/constants/contactSupport.ts b/apps/scandic-web/constants/contactSupport.ts index c6943eddd..736d5fa4f 100644 --- a/apps/scandic-web/constants/contactSupport.ts +++ b/apps/scandic-web/constants/contactSupport.ts @@ -1,5 +1,3 @@ -import { Lang } from "./languages" - /** * Contact support information (phone numbers and emails) by language. * @@ -9,6 +7,8 @@ import { Lang } from "./languages" * potential support queries. */ +import { Lang } from "@scandic-hotels/common/constants/language" + const mainNumber = "+46 8 517 517 00" export const supportPhone: Record = { diff --git a/apps/scandic-web/constants/languages.ts b/apps/scandic-web/constants/languages.ts index 9d4ca065e..fe398fdf7 100644 --- a/apps/scandic-web/constants/languages.ts +++ b/apps/scandic-web/constants/languages.ts @@ -1,13 +1,6 @@ -import type { LowerCaseCountryCode } from "@/types/components/form/phone" +import { Lang } from "@scandic-hotels/common/constants/language" -export enum Lang { - da = "da", - de = "de", - en = "en", - fi = "fi", - no = "no", - sv = "sv", -} +import type { LowerCaseCountryCode } from "@/types/components/form/phone" export const languages: Record = { [Lang.da]: "Dansk", diff --git a/apps/scandic-web/constants/routes/hotelReservation.js b/apps/scandic-web/constants/routes/hotelReservation.js index 27371e304..f9d26f90b 100644 --- a/apps/scandic-web/constants/routes/hotelReservation.js +++ b/apps/scandic-web/constants/routes/hotelReservation.js @@ -1,5 +1,5 @@ /** - * @typedef {import('@/constants/languages').Lang} Lang + * @typedef {import('@scandic-hotels/common/constants/language').Lang} Lang */ /** diff --git a/apps/scandic-web/constants/webHrefs.ts b/apps/scandic-web/constants/webHrefs.ts index 59f0dc378..407a8b227 100644 --- a/apps/scandic-web/constants/webHrefs.ts +++ b/apps/scandic-web/constants/webHrefs.ts @@ -1,4 +1,4 @@ -import { Lang } from "./languages" +import { Lang } from "@scandic-hotels/common/constants/language" import type { LangRoute } from "@/types/routes" diff --git a/apps/scandic-web/env/client.ts b/apps/scandic-web/env/client.ts index 9df264b56..01974bea7 100644 --- a/apps/scandic-web/env/client.ts +++ b/apps/scandic-web/env/client.ts @@ -4,7 +4,7 @@ import { z } from "zod" import { getLiveStatus } from "./getLiveStatus" import { isLangLive } from "./isLangLive" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" const _env = createEnv({ client: { diff --git a/apps/scandic-web/env/getLiveStatus.ts b/apps/scandic-web/env/getLiveStatus.ts index 0552ebeb0..287b8680c 100644 --- a/apps/scandic-web/env/getLiveStatus.ts +++ b/apps/scandic-web/env/getLiveStatus.ts @@ -1,5 +1,4 @@ -// Cannot use from "@/constants/languages" due to jiti -import { Lang } from "../constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" export function getLiveStatus( internalEnv: diff --git a/apps/scandic-web/env/isLangLive.test.ts b/apps/scandic-web/env/isLangLive.test.ts index aded7a297..9e5956efd 100644 --- a/apps/scandic-web/env/isLangLive.test.ts +++ b/apps/scandic-web/env/isLangLive.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import { isLangLive } from "./isLangLive" diff --git a/apps/scandic-web/env/isLangLive.ts b/apps/scandic-web/env/isLangLive.ts index 350ab7617..2a985f3fa 100644 --- a/apps/scandic-web/env/isLangLive.ts +++ b/apps/scandic-web/env/isLangLive.ts @@ -1,4 +1,4 @@ -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" export function isLangLive(lang: Lang, liveLangs: string[]): boolean { return liveLangs.includes(lang) diff --git a/apps/scandic-web/env/server.ts b/apps/scandic-web/env/server.ts index 0b3ebb91c..5f162ea9e 100644 --- a/apps/scandic-web/env/server.ts +++ b/apps/scandic-web/env/server.ts @@ -4,7 +4,7 @@ import { z } from "zod" import { getLiveStatus } from "./getLiveStatus" import { isLangLive } from "./isLangLive" -import type { Lang } from "../constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" const TWENTYFOUR_HOURS = 24 * 60 * 60 diff --git a/apps/scandic-web/hooks/useLang.ts b/apps/scandic-web/hooks/useLang.ts index bd9028a9a..8b795c103 100644 --- a/apps/scandic-web/hooks/useLang.ts +++ b/apps/scandic-web/hooks/useLang.ts @@ -1,7 +1,7 @@ "use client" import { useParams } from "next/navigation" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import { languageSchema } from "@/utils/languages" diff --git a/apps/scandic-web/i18n/index.ts b/apps/scandic-web/i18n/index.ts index 150637622..d0e75c8a9 100644 --- a/apps/scandic-web/i18n/index.ts +++ b/apps/scandic-web/i18n/index.ts @@ -2,7 +2,7 @@ import "server-only" import { createIntl, createIntlCache } from "@formatjs/intl" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import { getLang } from "@/i18n/serverContext" diff --git a/apps/scandic-web/i18n/serverContext.ts b/apps/scandic-web/i18n/serverContext.ts index e3ae3fa33..d8ed5b06a 100644 --- a/apps/scandic-web/i18n/serverContext.ts +++ b/apps/scandic-web/i18n/serverContext.ts @@ -3,7 +3,7 @@ import "server-only" import { headers } from "next/headers" import { cache } from "react" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import { languageSchema } from "@/utils/languages" diff --git a/apps/scandic-web/lib/graphql/_request.ts b/apps/scandic-web/lib/graphql/_request.ts index 33857ea87..a31e79fc7 100644 --- a/apps/scandic-web/lib/graphql/_request.ts +++ b/apps/scandic-web/lib/graphql/_request.ts @@ -2,7 +2,8 @@ import "server-only" import { ClientError, type GraphQLClient } from "graphql-request" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { env } from "@/env/server" import type { DocumentNode } from "graphql" diff --git a/apps/scandic-web/lib/trpc/Provider.tsx b/apps/scandic-web/lib/trpc/Provider.tsx index 8d85b75fd..127c2f242 100644 --- a/apps/scandic-web/lib/trpc/Provider.tsx +++ b/apps/scandic-web/lib/trpc/Provider.tsx @@ -8,10 +8,11 @@ import { import { httpLink, loggerLink, TRPCClientError } from "@trpc/client" import { useState } from "react" +import { SessionExpiredError } from "@scandic-hotels/trpc/errors" +import { transformer } from "@scandic-hotels/trpc/transformer" + import { login } from "@/constants/routes/handleAuth" import { env } from "@/env/client" -import { SessionExpiredError } from "@/server/errors/trpc" -import { transformer } from "@/server/transformer" import useLang from "@/hooks/useLang" diff --git a/apps/scandic-web/lib/trpc/memoizedRequests/index.ts b/apps/scandic-web/lib/trpc/memoizedRequests/index.ts index 9f92dfd28..38d5d55d6 100644 --- a/apps/scandic-web/lib/trpc/memoizedRequests/index.ts +++ b/apps/scandic-web/lib/trpc/memoizedRequests/index.ts @@ -7,6 +7,8 @@ import { cache } from "@/utils/cache" import { serverClient } from "../server" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { Country } from "@/types/enums/country" import type { AncillaryPackagesInput, @@ -18,7 +20,6 @@ import type { CityCoordinatesInput, HotelInput, } from "@/types/trpc/routers/hotel/hotel" -import type { Lang } from "@/constants/languages" import type { GetHotelsByCSFilterInput } from "@/server/routers/hotels/input" import type { GetSavedPaymentCardsInput } from "@/server/routers/user/input" diff --git a/apps/scandic-web/lib/trpc/server.ts b/apps/scandic-web/lib/trpc/server.ts index 4ecd82813..af66713bd 100644 --- a/apps/scandic-web/lib/trpc/server.ts +++ b/apps/scandic-web/lib/trpc/server.ts @@ -1,18 +1,57 @@ import * as Sentry from "@sentry/nextjs" import { TRPCError } from "@trpc/server" +import { cookies, headers } from "next/headers" import { redirect } from "next/navigation" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" +import { createCallerFactory } from "@scandic-hotels/trpc" +import { createContext } from "@scandic-hotels/trpc/context" + import { login } from "@/constants/routes/handleAuth" import { webviews } from "@/constants/routes/webviews" import { appRouter } from "@/server" -import { createContext } from "@/server/context" -import { createCallerFactory } from "@/server/trpc" + +import { auth } from "@/auth" + +import type { Session } from "next-auth" const createCaller = createCallerFactory(appRouter) +export async function createAppContext() { + const headersList = await headers() + const cookie = await cookies() + const webviewTokenCookie = cookie.get("webviewToken") + const loginType = headersList.get("loginType") + + const ctx = createContext({ + lang: headersList.get("x-lang") as Lang, + pathname: headersList.get("x-pathname")!, + uid: headersList.get("x-uid"), + url: headersList.get("x-url")!, + webToken: webviewTokenCookie?.value, + contentType: headersList.get("x-contenttype")!, + auth: async () => { + const session = await auth() + const webToken = webviewTokenCookie?.value + if (!session?.token && !webToken) { + return null + } + + return ( + session || + ({ + token: { access_token: webToken, loginType }, + } as Session) + ) + }, + }) + + return ctx +} + export async function serverClient() { - const ctx = await createContext() + const ctx = await createAppContext() + return createCaller(ctx, { onError: ({ ctx, error, input, path, type }) => { console.error(`[serverClient] error for ${type}: ${path}`, error) diff --git a/apps/scandic-web/middleware.ts b/apps/scandic-web/middleware.ts index 878a91788..9c066784f 100644 --- a/apps/scandic-web/middleware.ts +++ b/apps/scandic-web/middleware.ts @@ -1,7 +1,7 @@ import * as Sentry from "@sentry/nextjs" import { type NextMiddleware, NextResponse } from "next/server" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import * as authRequired from "@/middlewares/authRequired" import * as bookingFlow from "@/middlewares/bookingFlow" diff --git a/apps/scandic-web/middlewares/redirect.ts b/apps/scandic-web/middlewares/redirect.ts index f3797323c..627be94ec 100644 --- a/apps/scandic-web/middlewares/redirect.ts +++ b/apps/scandic-web/middlewares/redirect.ts @@ -9,8 +9,9 @@ import { findLang } from "@/utils/languages" import { getDefaultRequestHeaders } from "./utils" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { MiddlewareMatcher } from "@/types/middleware" -import type { Lang } from "@/constants/languages" async function fetchAndCacheRedirect(lang: Lang, pathname: string) { const cacheKey = `${lang}:redirect:${pathname}` diff --git a/apps/scandic-web/middlewares/sasXScandic.ts b/apps/scandic-web/middlewares/sasXScandic.ts index 2f8eb14bd..28707df1c 100644 --- a/apps/scandic-web/middlewares/sasXScandic.ts +++ b/apps/scandic-web/middlewares/sasXScandic.ts @@ -1,6 +1,6 @@ import { type NextMiddleware, NextResponse } from "next/server" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import { getDefaultRequestHeaders } from "./utils" diff --git a/apps/scandic-web/middlewares/webView.ts b/apps/scandic-web/middlewares/webView.ts index f0efac22e..759b33498 100644 --- a/apps/scandic-web/middlewares/webView.ts +++ b/apps/scandic-web/middlewares/webView.ts @@ -16,8 +16,9 @@ import { findLang } from "@/utils/languages" import { getDefaultRequestHeaders } from "./utils" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { MiddlewareMatcher } from "@/types/middleware" -import type { Lang } from "@/constants/languages" export const middleware: NextMiddleware = async (request) => { const { nextUrl } = request diff --git a/apps/scandic-web/netlify/utils/hoteldata.ts b/apps/scandic-web/netlify/utils/hoteldata.ts index fe6aac35c..206e24ed3 100644 --- a/apps/scandic-web/netlify/utils/hoteldata.ts +++ b/apps/scandic-web/netlify/utils/hoteldata.ts @@ -1,4 +1,4 @@ -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" export async function warmupHotelDataOnLang(lang: Lang) { const PUBLIC_URL = Netlify.env.get("PUBLIC_URL") diff --git a/apps/scandic-web/next.config.ts b/apps/scandic-web/next.config.ts index 14235f7a8..29f428e3c 100644 --- a/apps/scandic-web/next.config.ts +++ b/apps/scandic-web/next.config.ts @@ -25,7 +25,7 @@ const nextConfig = { poweredByHeader: false, eslint: { ignoreDuringBuilds: true }, trailingSlash: false, - transpilePackages: ["@scandic-hotels/common"], + transpilePackages: ["@scandic-hotels/common", "@scandic-hotels/trpc"], experimental: { serverActions: { allowedOrigins: [ diff --git a/apps/scandic-web/package.json b/apps/scandic-web/package.json index 07f0dd948..280ad4ada 100644 --- a/apps/scandic-web/package.json +++ b/apps/scandic-web/package.json @@ -109,7 +109,6 @@ "slugify": "^1.6.6", "sonner": "^2.0.3", "supercluster": "^8.0.1", - "superjson": "^2.2.2", "usehooks-ts": "3.1.1", "uuid": "^11.1.0", "zod": "^3.24.4", diff --git a/apps/scandic-web/providers/MyStay.tsx b/apps/scandic-web/providers/MyStay.tsx index 5a256d680..edecb80dd 100644 --- a/apps/scandic-web/providers/MyStay.tsx +++ b/apps/scandic-web/providers/MyStay.tsx @@ -9,6 +9,8 @@ import { createMyStayStore } from "@/stores/my-stay" import { MyStaySkeleton } from "@/components/HotelReservation/MyStay/myStaySkeleton" import { MyStayContext } from "@/contexts/MyStay" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { Packages } from "@/types/components/myPages/myStay/ancillaries" import type { MyStayStore } from "@/types/contexts/my-stay" import type { RoomCategories } from "@/types/hotel" @@ -17,7 +19,6 @@ import type { BookingConfirmationSchema, } from "@/types/trpc/routers/booking/confirmation" import type { CreditCard } from "@/types/user" -import type { Lang } from "@/constants/languages" interface MyStayProviderProps { bookingConfirmation: BookingConfirmation diff --git a/apps/scandic-web/server/context.ts b/apps/scandic-web/server/context.ts deleted file mode 100644 index a81690365..000000000 --- a/apps/scandic-web/server/context.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { cookies, headers } from "next/headers" -import { type Session } from "next-auth" -import { cache } from "react" - -import { auth } from "@/auth" - -import type { Lang } from "@/constants/languages" - -typeof auth - -type CreateContextOptions = { - auth: () => Promise - lang: Lang - pathname: string - uid?: string | null - url: string - webToken?: string - contentType?: string -} - -/** Use this helper for: - * - testing, where we dont have to Mock Next.js' req/res - * - trpc's `createSSGHelpers` where we don't have req/res - **/ -export function createContextInner(opts: CreateContextOptions) { - return { - auth: opts.auth, - lang: opts.lang, - pathname: opts.pathname, - uid: opts.uid, - url: opts.url, - webToken: opts.webToken, - contentType: opts.contentType, - } -} - -/** - * This is the actual context you'll use in your router - * @link https://trpc.io/docs/context - **/ -export const createContext = cache(async function () { - const headersList = await headers() - - const cookie = await cookies() - const webviewTokenCookie = cookie.get("webviewToken") - const loginType = headersList.get("loginType") - - return createContextInner({ - auth: async () => { - const session = await auth() - const webToken = webviewTokenCookie?.value - if (!session?.token && !webToken) { - return null - } - - return ( - session || - ({ - token: { access_token: webToken, loginType }, - } as Session) - ) - }, - lang: headersList.get("x-lang") as Lang, - pathname: headersList.get("x-pathname")!, - uid: headersList.get("x-uid"), - url: headersList.get("x-url")!, - webToken: webviewTokenCookie?.value, - contentType: headersList.get("x-contenttype")!, - }) -}) - -export type Context = Awaited> diff --git a/apps/scandic-web/server/index.ts b/apps/scandic-web/server/index.ts index 0dd961cc2..09c2d2a69 100644 --- a/apps/scandic-web/server/index.ts +++ b/apps/scandic-web/server/index.ts @@ -1,4 +1,6 @@ /** Routers */ +import { router } from "@scandic-hotels/trpc" + import { autocompleteRouter } from "./routers/autocomplete" import { bookingRouter } from "./routers/booking" import { contentstackRouter } from "./routers/contentstack" @@ -6,7 +8,6 @@ import { hotelsRouter } from "./routers/hotels" import { navigationRouter } from "./routers/navigation" import { partnerRouter } from "./routers/partners" import { userRouter } from "./routers/user" -import { router } from "./trpc" export const appRouter = router({ booking: bookingRouter, diff --git a/apps/scandic-web/server/plugins/refIdToConfirmationNumber.ts b/apps/scandic-web/server/plugins/refIdToConfirmationNumber.ts index 4746b2a35..af1b90f97 100644 --- a/apps/scandic-web/server/plugins/refIdToConfirmationNumber.ts +++ b/apps/scandic-web/server/plugins/refIdToConfirmationNumber.ts @@ -3,8 +3,8 @@ import { z } from "zod" import { parseRefId } from "@/utils/refId" -import type { Meta } from "@/types/trpc/meta" -import type { Context } from "../context" +import type { Meta } from "@scandic-hotels/trpc" +import type { Context } from "@scandic-hotels/trpc/context" export function createRefIdPlugin() { const t = initTRPC.context().meta().create() diff --git a/apps/scandic-web/server/routers/autocomplete/destinations.ts b/apps/scandic-web/server/routers/autocomplete/destinations.ts index cf2f9d2b2..77e0cdf72 100644 --- a/apps/scandic-web/server/routers/autocomplete/destinations.ts +++ b/apps/scandic-web/server/routers/autocomplete/destinations.ts @@ -1,10 +1,10 @@ import { z } from "zod" +import { Lang } from "@scandic-hotels/common/constants/language" import { getCacheClient } from "@scandic-hotels/common/dataCache" import { safeTry } from "@scandic-hotels/common/utils/safeTry" +import { safeProtectedServiceProcedure } from "@scandic-hotels/trpc/procedures" -import { Lang } from "@/constants/languages" -import { safeProtectedServiceProcedure } from "@/server/trpc" import { isDefined } from "@/server/utils" import { getCityPageUrls } from "../contentstack/destinationCityPage/utils" diff --git a/apps/scandic-web/server/routers/autocomplete/index.ts b/apps/scandic-web/server/routers/autocomplete/index.ts index 75dbeedf5..ff940c4c1 100644 --- a/apps/scandic-web/server/routers/autocomplete/index.ts +++ b/apps/scandic-web/server/routers/autocomplete/index.ts @@ -1,4 +1,4 @@ -import { router } from "@/server/trpc" +import { router } from "@scandic-hotels/trpc" import { getDestinationsAutoCompleteRoute } from "./destinations" diff --git a/apps/scandic-web/server/routers/booking/index.ts b/apps/scandic-web/server/routers/booking/index.ts index f3c0b45ad..18fe6b208 100644 --- a/apps/scandic-web/server/routers/booking/index.ts +++ b/apps/scandic-web/server/routers/booking/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { bookingMutationRouter } from "./mutation" import { bookingQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/booking/input.ts b/apps/scandic-web/server/routers/booking/input.ts index 290a1622a..ace64abf6 100644 --- a/apps/scandic-web/server/routers/booking/input.ts +++ b/apps/scandic-web/server/routers/booking/input.ts @@ -1,7 +1,9 @@ import { z } from "zod" +import { Lang } from "@scandic-hotels/common/constants/language" + import { ChildBedTypeEnum } from "@/constants/booking" -import { Lang, langToApiLang } from "@/constants/languages" +import { langToApiLang } from "@/constants/languages" const roomsSchema = z .array( diff --git a/apps/scandic-web/server/routers/booking/mutation.ts b/apps/scandic-web/server/routers/booking/mutation.ts index 4fda04379..3bb78738e 100644 --- a/apps/scandic-web/server/routers/booking/mutation.ts +++ b/apps/scandic-web/server/routers/booking/mutation.ts @@ -1,8 +1,10 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { safeProtectedServiceProcedure } from "@scandic-hotels/trpc/procedures" + import * as api from "@/lib/api" import { createRefIdPlugin } from "@/server/plugins/refIdToConfirmationNumber" import { getMembershipNumber } from "@/server/routers/user/utils" -import { createCounter } from "@/server/telemetry" -import { router, safeProtectedServiceProcedure } from "@/server/trpc" import { encrypt } from "@/utils/encryption" import { isValidSession } from "@/utils/session" diff --git a/apps/scandic-web/server/routers/booking/query.ts b/apps/scandic-web/server/routers/booking/query.ts index a22133320..22a4af777 100644 --- a/apps/scandic-web/server/routers/booking/query.ts +++ b/apps/scandic-web/server/routers/booking/query.ts @@ -1,12 +1,16 @@ -import * as api from "@/lib/api" -import { badRequestError, serverErrorByStatus } from "@/server/errors/trpc" -import { createRefIdPlugin } from "@/server/plugins/refIdToConfirmationNumber" -import { createCounter } from "@/server/telemetry" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { + badRequestError, + serverErrorByStatus, +} from "@scandic-hotels/trpc/errors" import { - router, safeProtectedServiceProcedure, serviceProcedure, -} from "@/server/trpc" +} from "@scandic-hotels/trpc/procedures" + +import * as api from "@/lib/api" +import { createRefIdPlugin } from "@/server/plugins/refIdToConfirmationNumber" import { toApiLang } from "@/server/utils" import { getBookedHotelRoom } from "@/utils/booking" diff --git a/apps/scandic-web/server/routers/booking/utils.ts b/apps/scandic-web/server/routers/booking/utils.ts index 98a2dbac1..d0ad56284 100644 --- a/apps/scandic-web/server/routers/booking/utils.ts +++ b/apps/scandic-web/server/routers/booking/utils.ts @@ -1,11 +1,15 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { + badRequestError, + serverErrorByStatus, +} from "@scandic-hotels/trpc/errors" + import * as api from "@/lib/api" -import { badRequestError, serverErrorByStatus } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" import { toApiLang } from "@/server/utils" import { bookingConfirmationSchema, createBookingSchema } from "./output" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" export async function getBooking( confirmationNumber: string, diff --git a/apps/scandic-web/server/routers/contentstack/accountPage/index.ts b/apps/scandic-web/server/routers/contentstack/accountPage/index.ts index 53b998e7f..d2e6fe5f8 100644 --- a/apps/scandic-web/server/routers/contentstack/accountPage/index.ts +++ b/apps/scandic-web/server/routers/contentstack/accountPage/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { accountPageQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/accountPage/query.ts b/apps/scandic-web/server/routers/contentstack/accountPage/query.ts index 98e3d56ab..e581ae80d 100644 --- a/apps/scandic-web/server/routers/contentstack/accountPage/query.ts +++ b/apps/scandic-web/server/routers/contentstack/accountPage/query.ts @@ -1,11 +1,13 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentstackExtendedProcedureUID } from "@scandic-hotels/trpc/procedures" + import { GetAccountPage, GetAccountPageRefs, } from "@/lib/graphql/Query/AccountPage/AccountPage.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentstackExtendedProcedureUID, router } from "@/server/trpc" import { generateRefsResponseTag, diff --git a/apps/scandic-web/server/routers/contentstack/base/index.ts b/apps/scandic-web/server/routers/contentstack/base/index.ts index 8eac25c36..cd510d61e 100644 --- a/apps/scandic-web/server/routers/contentstack/base/index.ts +++ b/apps/scandic-web/server/routers/contentstack/base/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { baseQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/base/output.ts b/apps/scandic-web/server/routers/contentstack/base/output.ts index 9d339297c..d5cfe38db 100644 --- a/apps/scandic-web/server/routers/contentstack/base/output.ts +++ b/apps/scandic-web/server/routers/contentstack/base/output.ts @@ -1,6 +1,7 @@ import { z, ZodError, ZodIssueCode } from "zod" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { discriminatedUnion } from "@/lib/discriminatedUnion" import { cardBlockRefsSchema, diff --git a/apps/scandic-web/server/routers/contentstack/base/query.ts b/apps/scandic-web/server/routers/contentstack/base/query.ts index c40b5aa62..e9c594f88 100644 --- a/apps/scandic-web/server/routers/contentstack/base/query.ts +++ b/apps/scandic-web/server/routers/contentstack/base/query.ts @@ -1,5 +1,10 @@ import { cache } from "react" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentstackBaseProcedure } from "@scandic-hotels/trpc/procedures" + import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql" import { GetCurrentFooter, @@ -16,9 +21,6 @@ import { GetSiteConfigRef, } from "@/lib/graphql/Query/SiteConfig.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentstackBaseProcedure, router } from "@/server/trpc" import { langInput } from "@/server/utils" import { @@ -51,6 +53,8 @@ import { getSiteConfigConnections, } from "./utils" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { FooterDataRaw, FooterRefDataRaw, @@ -63,7 +67,6 @@ import type { GetSiteConfigData, GetSiteConfigRefData, } from "@/types/trpc/routers/contentstack/siteConfig" -import type { Lang } from "@/constants/languages" const getContactConfig = cache(async (lang: Lang) => { const getContactConfigCounter = createCounter( diff --git a/apps/scandic-web/server/routers/contentstack/breadcrumbs/index.ts b/apps/scandic-web/server/routers/contentstack/breadcrumbs/index.ts index fe82072dc..2057c29e2 100644 --- a/apps/scandic-web/server/routers/contentstack/breadcrumbs/index.ts +++ b/apps/scandic-web/server/routers/contentstack/breadcrumbs/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { breadcrumbsQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/breadcrumbs/query.ts b/apps/scandic-web/server/routers/contentstack/breadcrumbs/query.ts index d83c7621e..42a549f71 100644 --- a/apps/scandic-web/server/routers/contentstack/breadcrumbs/query.ts +++ b/apps/scandic-web/server/routers/contentstack/breadcrumbs/query.ts @@ -1,5 +1,10 @@ import { cache } from "react" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentstackExtendedProcedureUID } from "@scandic-hotels/trpc/procedures" + import { GetMyPagesBreadcrumbs, GetMyPagesBreadcrumbsRefs, @@ -37,21 +42,19 @@ import { GetLoyaltyPageBreadcrumbsRefs, } from "@/lib/graphql/Query/Breadcrumbs/LoyaltyPage.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentstackExtendedProcedureUID, router } from "@/server/trpc" import { generateRefsResponseTag } from "@/utils/generateTag" import { breadcrumbsRefsSchema, breadcrumbsSchema } from "./output" import { getTags } from "./utils" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { PageContentTypeEnum } from "@/types/requests/contentType" import type { BreadcrumbsRefsSchema, RawBreadcrumbsSchema, } from "@/types/trpc/routers/contentstack/breadcrumbs" -import type { Lang } from "@/constants/languages" interface BreadcrumbsPageData { dataKey: keyof T diff --git a/apps/scandic-web/server/routers/contentstack/breadcrumbs/utils.ts b/apps/scandic-web/server/routers/contentstack/breadcrumbs/utils.ts index 65845fc87..2eaff6bc1 100644 --- a/apps/scandic-web/server/routers/contentstack/breadcrumbs/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/breadcrumbs/utils.ts @@ -1,4 +1,4 @@ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import { generateTag, generateTags } from "@/utils/generateTag" diff --git a/apps/scandic-web/server/routers/contentstack/campaignPage/index.ts b/apps/scandic-web/server/routers/contentstack/campaignPage/index.ts index 3c0535d4c..1702e5f5a 100644 --- a/apps/scandic-web/server/routers/contentstack/campaignPage/index.ts +++ b/apps/scandic-web/server/routers/contentstack/campaignPage/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { campaignPageQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/campaignPage/query.ts b/apps/scandic-web/server/routers/contentstack/campaignPage/query.ts index 707964efe..26f6b8eb8 100644 --- a/apps/scandic-web/server/routers/contentstack/campaignPage/query.ts +++ b/apps/scandic-web/server/routers/contentstack/campaignPage/query.ts @@ -1,11 +1,13 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentStackUidWithServiceProcedure } from "@scandic-hotels/trpc/procedures" + import { GetCampaignPage, GetCampaignPageRefs, } from "@/lib/graphql/Query/CampaignPage/CampaignPage.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentStackUidWithServiceProcedure, router } from "@/server/trpc" import { generateRefsResponseTag } from "@/utils/generateTag" diff --git a/apps/scandic-web/server/routers/contentstack/campaignPage/utils.ts b/apps/scandic-web/server/routers/contentstack/campaignPage/utils.ts index efe4fb6ec..eeec30981 100644 --- a/apps/scandic-web/server/routers/contentstack/campaignPage/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/campaignPage/utils.ts @@ -1,9 +1,10 @@ import { generateTag, generateTagsFromSystem } from "@/utils/generateTag" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { CampaignPageEnum } from "@/types/enums/campaignPage" import type { System } from "@/types/requests/system" import type { CampaignPageRefs } from "@/types/trpc/routers/contentstack/campaignPage" -import type { Lang } from "@/constants/languages" export function generatePageTags( validatedData: CampaignPageRefs, diff --git a/apps/scandic-web/server/routers/contentstack/collectionPage/index.ts b/apps/scandic-web/server/routers/contentstack/collectionPage/index.ts index 04f372da8..29c04247b 100644 --- a/apps/scandic-web/server/routers/contentstack/collectionPage/index.ts +++ b/apps/scandic-web/server/routers/contentstack/collectionPage/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { collectionPageQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/collectionPage/query.ts b/apps/scandic-web/server/routers/contentstack/collectionPage/query.ts index 2dab99876..609236572 100644 --- a/apps/scandic-web/server/routers/contentstack/collectionPage/query.ts +++ b/apps/scandic-web/server/routers/contentstack/collectionPage/query.ts @@ -1,7 +1,9 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { contentstackExtendedProcedureUID } from "@scandic-hotels/trpc/procedures" + import { GetCollectionPage } from "@/lib/graphql/Query/CollectionPage/CollectionPage.graphql" import { request } from "@/lib/graphql/request" -import { createCounter } from "@/server/telemetry" -import { contentstackExtendedProcedureUID, router } from "@/server/trpc" import { collectionPageSchema } from "./output" import { diff --git a/apps/scandic-web/server/routers/contentstack/collectionPage/utils.ts b/apps/scandic-web/server/routers/contentstack/collectionPage/utils.ts index aeddbfad4..c6117b197 100644 --- a/apps/scandic-web/server/routers/contentstack/collectionPage/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/collectionPage/utils.ts @@ -1,7 +1,8 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { notFound } from "@scandic-hotels/trpc/errors" + import { GetCollectionPageRefs } from "@/lib/graphql/Query/CollectionPage/CollectionPage.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" import { generateRefsResponseTag, @@ -11,13 +12,14 @@ import { import { collectionPageRefsSchema } from "./output" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { CollectionPageEnum } from "@/types/enums/collectionPage" import type { System } from "@/types/requests/system" import type { CollectionPageRefs, GetCollectionPageRefsSchema, } from "@/types/trpc/routers/contentstack/collectionPage" -import type { Lang } from "@/constants/languages" export async function fetchCollectionPageRefs(lang: Lang, uid: string) { const getCollectionPageRefsCounter = createCounter( diff --git a/apps/scandic-web/server/routers/contentstack/contentPage/index.ts b/apps/scandic-web/server/routers/contentstack/contentPage/index.ts index 52130d7b4..4a933fa24 100644 --- a/apps/scandic-web/server/routers/contentstack/contentPage/index.ts +++ b/apps/scandic-web/server/routers/contentstack/contentPage/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { contentPageQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/contentPage/query.ts b/apps/scandic-web/server/routers/contentstack/contentPage/query.ts index 045cdfff1..a248843e6 100644 --- a/apps/scandic-web/server/routers/contentstack/contentPage/query.ts +++ b/apps/scandic-web/server/routers/contentstack/contentPage/query.ts @@ -1,11 +1,13 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { contentstackExtendedProcedureUID } from "@scandic-hotels/trpc/procedures" + import { batchRequest } from "@/lib/graphql/batchRequest" import { GetContentPage, GetContentPageBlocksBatch1, GetContentPageBlocksBatch2, } from "@/lib/graphql/Query/ContentPage/ContentPage.graphql" -import { createCounter } from "@/server/telemetry" -import { contentstackExtendedProcedureUID, router } from "@/server/trpc" import { contentPageSchema } from "./output" import { diff --git a/apps/scandic-web/server/routers/contentstack/contentPage/utils.ts b/apps/scandic-web/server/routers/contentstack/contentPage/utils.ts index 190c660fc..4e9e0cfdf 100644 --- a/apps/scandic-web/server/routers/contentstack/contentPage/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/contentPage/utils.ts @@ -1,10 +1,11 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { notFound } from "@scandic-hotels/trpc/errors" + import { batchRequest } from "@/lib/graphql/batchRequest" import { GetContentPageBlocksRefs, GetContentPageRefs, } from "@/lib/graphql/Query/ContentPage/ContentPage.graphql" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" import { generateRefsResponseTag, @@ -14,6 +15,8 @@ import { import { contentPageRefsSchema } from "./output" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { TrackingChannelEnum } from "@/types/components/tracking" import { ContentPageEnum } from "@/types/enums/contentPage" import type { System } from "@/types/requests/system" @@ -21,7 +24,6 @@ import { type ContentPageRefs, type GetContentPageRefsSchema, } from "@/types/trpc/routers/contentstack/contentPage" -import type { Lang } from "@/constants/languages" export async function fetchContentPageRefs(lang: Lang, uid: string) { const getContentPageRefsCounter = createCounter( diff --git a/apps/scandic-web/server/routers/contentstack/destinationCityPage/index.ts b/apps/scandic-web/server/routers/contentstack/destinationCityPage/index.ts index 81765282f..87dd50070 100644 --- a/apps/scandic-web/server/routers/contentstack/destinationCityPage/index.ts +++ b/apps/scandic-web/server/routers/contentstack/destinationCityPage/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { destinationCityPageQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/destinationCityPage/query.ts b/apps/scandic-web/server/routers/contentstack/destinationCityPage/query.ts index 39f173212..3a8534296 100644 --- a/apps/scandic-web/server/routers/contentstack/destinationCityPage/query.ts +++ b/apps/scandic-web/server/routers/contentstack/destinationCityPage/query.ts @@ -1,11 +1,13 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentStackUidWithServiceProcedure } from "@scandic-hotels/trpc/procedures" + import { GetDestinationCityPage, GetDestinationCityPageRefs, } from "@/lib/graphql/Query/DestinationCityPage/DestinationCityPage.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentStackUidWithServiceProcedure, router } from "@/server/trpc" import { generateRefsResponseTag } from "@/utils/generateTag" diff --git a/apps/scandic-web/server/routers/contentstack/destinationCityPage/utils.ts b/apps/scandic-web/server/routers/contentstack/destinationCityPage/utils.ts index d5a54adaa..6a8b8c9f3 100644 --- a/apps/scandic-web/server/routers/contentstack/destinationCityPage/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/destinationCityPage/utils.ts @@ -1,12 +1,15 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" + import { GetCityPageCount } from "@/lib/graphql/Query/DestinationCityPage/DestinationCityPageCount.graphql" import { GetCityPageUrls } from "@/lib/graphql/Query/DestinationCityPage/DestinationCityPageUrl.graphql" import { request } from "@/lib/graphql/request" -import { createCounter } from "@/server/telemetry" import { generateTag, generateTagsFromSystem } from "@/utils/generateTag" import { batchedCityPageUrlsSchema, cityPageCountSchema } from "./output" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { DestinationCityPageEnum } from "@/types/enums/destinationCityPage" import type { System } from "@/types/requests/system" import type { @@ -14,7 +17,6 @@ import type { GetCityPageCountData, GetCityPageUrlsData, } from "@/types/trpc/routers/contentstack/destinationCityPage" -import type { Lang } from "@/constants/languages" export function generatePageTags( validatedData: DestinationCityPageRefs, diff --git a/apps/scandic-web/server/routers/contentstack/destinationCountryPage/index.ts b/apps/scandic-web/server/routers/contentstack/destinationCountryPage/index.ts index 76da88a62..ff39f7b73 100644 --- a/apps/scandic-web/server/routers/contentstack/destinationCountryPage/index.ts +++ b/apps/scandic-web/server/routers/contentstack/destinationCountryPage/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { destinationCountryPageQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/destinationCountryPage/query.ts b/apps/scandic-web/server/routers/contentstack/destinationCountryPage/query.ts index b97c8ba74..804a12cb3 100644 --- a/apps/scandic-web/server/routers/contentstack/destinationCountryPage/query.ts +++ b/apps/scandic-web/server/routers/contentstack/destinationCountryPage/query.ts @@ -1,15 +1,16 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { + contentStackBaseWithServiceProcedure, + contentstackExtendedProcedureUID, +} from "@scandic-hotels/trpc/procedures" + import { GetDestinationCountryPage, GetDestinationCountryPageRefs, } from "@/lib/graphql/Query/DestinationCountryPage/DestinationCountryPage.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { - contentStackBaseWithServiceProcedure, - contentstackExtendedProcedureUID, - router, -} from "@/server/trpc" import { generateRefsResponseTag } from "@/utils/generateTag" diff --git a/apps/scandic-web/server/routers/contentstack/destinationCountryPage/utils.ts b/apps/scandic-web/server/routers/contentstack/destinationCountryPage/utils.ts index 26ff227a8..3a9e06847 100644 --- a/apps/scandic-web/server/routers/contentstack/destinationCountryPage/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/destinationCountryPage/utils.ts @@ -1,7 +1,8 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" + import { GetDestinationCityListData } from "@/lib/graphql/Query/DestinationCityPage/DestinationCityListData.graphql" import { GetCountryPageUrls } from "@/lib/graphql/Query/DestinationCountryPage/DestinationCountryPageUrl.graphql" import { request } from "@/lib/graphql/request" -import { createCounter } from "@/server/telemetry" import { generateTag, generateTagsFromSystem } from "@/utils/generateTag" @@ -9,6 +10,8 @@ import { getCitiesByCountry } from "../../hotels/utils" import { destinationCityListDataSchema } from "../destinationCityPage/output" import { countryPageUrlsSchema } from "./output" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { ApiCountry, type Country } from "@/types/enums/country" import { DestinationCountryPageEnum } from "@/types/enums/destinationCountryPage" import type { System } from "@/types/requests/system" @@ -17,7 +20,6 @@ import type { DestinationCountryPageRefs, GetCountryPageUrlsData, } from "@/types/trpc/routers/contentstack/destinationCountryPage" -import type { Lang } from "@/constants/languages" export function generatePageTags( validatedData: DestinationCountryPageRefs, diff --git a/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/index.ts b/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/index.ts index fc9146c0f..e86e251b4 100644 --- a/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/index.ts +++ b/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { destinationOverviewPageQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/query.ts b/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/query.ts index 91117d9c0..aa62c56e7 100644 --- a/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/query.ts +++ b/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/query.ts @@ -1,18 +1,18 @@ +import { Lang } from "@scandic-hotels/common/constants/language" +import { createCounter } from "@scandic-hotels/common/telemetry" import { safeTry } from "@scandic-hotels/common/utils/safeTry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { + contentstackExtendedProcedureUID, + serviceProcedure, +} from "@scandic-hotels/trpc/procedures" -import { Lang } from "@/constants/languages" import { GetDestinationOverviewPage, GetDestinationOverviewPageRefs, } from "@/lib/graphql/Query/DestinationOverviewPage/DestinationOverviewPage.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { - contentstackExtendedProcedureUID, - router, - serviceProcedure, -} from "@/server/trpc" import { generateRefsResponseTag, generateTag } from "@/utils/generateTag" diff --git a/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/utils.ts b/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/utils.ts index ce5b9cdf7..537ede5c1 100644 --- a/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/destinationOverviewPage/utils.ts @@ -1,4 +1,4 @@ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import type { DestinationsData } from "@/types/components/destinationOverviewPage/destinationsList/destinationsData" import { ApiCountry, Country } from "@/types/enums/country" diff --git a/apps/scandic-web/server/routers/contentstack/hotelPage/index.ts b/apps/scandic-web/server/routers/contentstack/hotelPage/index.ts index 5517dbb3e..b6b60e4e4 100644 --- a/apps/scandic-web/server/routers/contentstack/hotelPage/index.ts +++ b/apps/scandic-web/server/routers/contentstack/hotelPage/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { hotelPageQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/hotelPage/query.ts b/apps/scandic-web/server/routers/contentstack/hotelPage/query.ts index 988b2ee51..021190ce5 100644 --- a/apps/scandic-web/server/routers/contentstack/hotelPage/query.ts +++ b/apps/scandic-web/server/routers/contentstack/hotelPage/query.ts @@ -1,8 +1,10 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentstackExtendedProcedureUID } from "@scandic-hotels/trpc/procedures" + import { GetHotelPage } from "@/lib/graphql/Query/HotelPage/HotelPage.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentstackExtendedProcedureUID, router } from "@/server/trpc" import { generateTag } from "@/utils/generateTag" diff --git a/apps/scandic-web/server/routers/contentstack/hotelPage/utils.ts b/apps/scandic-web/server/routers/contentstack/hotelPage/utils.ts index 4c4d91ec9..3262ae2ff 100644 --- a/apps/scandic-web/server/routers/contentstack/hotelPage/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/hotelPage/utils.ts @@ -1,15 +1,17 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" + import { GetHotelPageCount } from "@/lib/graphql/Query/HotelPage/HotelPageCount.graphql" import { GetHotelPageUrls } from "@/lib/graphql/Query/HotelPage/HotelPageUrl.graphql" import { request } from "@/lib/graphql/request" -import { createCounter } from "@/server/telemetry" import { batchedHotelPageUrlsSchema, hotelPageCountSchema } from "./output" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { GetHotelPageCountData, GetHotelPageUrlsData, } from "@/types/trpc/routers/contentstack/hotelPage" -import type { Lang } from "@/constants/languages" export async function getHotelPageCount(lang: Lang) { const getHotelPageCountCounter = createCounter( diff --git a/apps/scandic-web/server/routers/contentstack/index.ts b/apps/scandic-web/server/routers/contentstack/index.ts index 543edc3f6..e5922bad5 100644 --- a/apps/scandic-web/server/routers/contentstack/index.ts +++ b/apps/scandic-web/server/routers/contentstack/index.ts @@ -1,4 +1,4 @@ -import { router } from "@/server/trpc" +import { router } from "@scandic-hotels/trpc" import { accountPageRouter } from "./accountPage" import { baseRouter } from "./base" diff --git a/apps/scandic-web/server/routers/contentstack/languageSwitcher/index.ts b/apps/scandic-web/server/routers/contentstack/languageSwitcher/index.ts index c4dc0ab05..0877c7db2 100644 --- a/apps/scandic-web/server/routers/contentstack/languageSwitcher/index.ts +++ b/apps/scandic-web/server/routers/contentstack/languageSwitcher/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { languageSwitcherQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/languageSwitcher/input.ts b/apps/scandic-web/server/routers/contentstack/languageSwitcher/input.ts index 39f056b95..7c92f1962 100644 --- a/apps/scandic-web/server/routers/contentstack/languageSwitcher/input.ts +++ b/apps/scandic-web/server/routers/contentstack/languageSwitcher/input.ts @@ -1,6 +1,6 @@ import { z } from "zod" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" export const getLanguageSwitcherInput = z.object({ lang: z.nativeEnum(Lang), diff --git a/apps/scandic-web/server/routers/contentstack/languageSwitcher/query.ts b/apps/scandic-web/server/routers/contentstack/languageSwitcher/query.ts index fbd0010b8..7ed3698f1 100644 --- a/apps/scandic-web/server/routers/contentstack/languageSwitcher/query.ts +++ b/apps/scandic-web/server/routers/contentstack/languageSwitcher/query.ts @@ -1,4 +1,5 @@ -import { publicProcedure, router } from "@/server/trpc" +import { router } from "@scandic-hotels/trpc" +import { publicProcedure } from "@scandic-hotels/trpc/procedures" import { getUidAndContentTypeByPath } from "@/services/cms/getUidAndContentTypeByPath" diff --git a/apps/scandic-web/server/routers/contentstack/languageSwitcher/utils.ts b/apps/scandic-web/server/routers/contentstack/languageSwitcher/utils.ts index 6741d985c..0fbe784db 100644 --- a/apps/scandic-web/server/routers/contentstack/languageSwitcher/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/languageSwitcher/utils.ts @@ -1,4 +1,7 @@ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { internalServerError } from "@scandic-hotels/trpc/errors" + import { batchRequest } from "@/lib/graphql/batchRequest" import { GetDaDeEnUrlsAccountPage, @@ -44,8 +47,6 @@ import { GetDaDeEnUrlsStartPage, GetFiNoSvUrlsStartPage, } from "@/lib/graphql/Query/StartPage/StartPage.graphql" -import { internalServerError } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" import { generateTag } from "@/utils/generateTag" import { removeTrailingSlash } from "@/utils/url" diff --git a/apps/scandic-web/server/routers/contentstack/loyaltyLevel/index.ts b/apps/scandic-web/server/routers/contentstack/loyaltyLevel/index.ts index 4b5f9d720..cb174ec51 100644 --- a/apps/scandic-web/server/routers/contentstack/loyaltyLevel/index.ts +++ b/apps/scandic-web/server/routers/contentstack/loyaltyLevel/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { loyaltyLevelQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/loyaltyLevel/input.ts b/apps/scandic-web/server/routers/contentstack/loyaltyLevel/input.ts index 19ca42353..05e3d450c 100644 --- a/apps/scandic-web/server/routers/contentstack/loyaltyLevel/input.ts +++ b/apps/scandic-web/server/routers/contentstack/loyaltyLevel/input.ts @@ -1,6 +1,7 @@ import { z } from "zod" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { MembershipLevelEnum } from "@/constants/membershipLevels" export const loyaltyLevelInput = z.object({ diff --git a/apps/scandic-web/server/routers/contentstack/loyaltyLevel/query.ts b/apps/scandic-web/server/routers/contentstack/loyaltyLevel/query.ts index a73d6f7b3..9b9d66079 100644 --- a/apps/scandic-web/server/routers/contentstack/loyaltyLevel/query.ts +++ b/apps/scandic-web/server/routers/contentstack/loyaltyLevel/query.ts @@ -1,5 +1,10 @@ import { cache } from "react" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentstackBaseProcedure } from "@scandic-hotels/trpc/procedures" + import { type MembershipLevel, MembershipLevelEnum, @@ -9,9 +14,6 @@ import { GetLoyaltyLevel, } from "@/lib/graphql/Query/LoyaltyLevels.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentstackBaseProcedure, router } from "@/server/trpc" import { generateLoyaltyConfigTag } from "@/utils/generateTag" @@ -22,9 +24,9 @@ import { validateLoyaltyLevelsSchema, } from "./output" -import type { Context } from "@/server/context" +import type { Lang } from "@scandic-hotels/common/constants/language" -export const getAllLoyaltyLevels = cache(async (ctx: Context) => { +export const getAllLoyaltyLevels = cache(async (lang: Lang) => { const getLoyaltyLevelAllCounter = createCounter( "trpc.contentstack", "loyaltyLevel.all" @@ -39,12 +41,12 @@ export const getAllLoyaltyLevels = cache(async (ctx: Context) => { const allLevelIds = Object.values(MembershipLevelEnum) const tags = allLevelIds.map((levelId) => - generateLoyaltyConfigTag(ctx.lang, "loyalty_level", levelId) + generateLoyaltyConfigTag(lang, "loyalty_level", levelId) ) const loyaltyLevelsConfigResponse = await request( GetAllLoyaltyLevels, - { lang: ctx.lang, level_ids: allLevelIds }, + { lang, level_ids: allLevelIds }, { key: tags, ttl: "max" } ) @@ -68,13 +70,13 @@ export const getAllLoyaltyLevels = cache(async (ctx: Context) => { }) export const getLoyaltyLevel = cache( - async (ctx: Context, level_id: MembershipLevel) => { + async (lang: Lang, level_id: MembershipLevel) => { const getLoyaltyLevelCounter = createCounter( "trpc.contentstack", "loyaltyLevel.get" ) const metricsGetLoyaltyLevel = getLoyaltyLevelCounter.init({ - lang: ctx.lang, + lang, level_id, }) @@ -82,9 +84,9 @@ export const getLoyaltyLevel = cache( const loyaltyLevelsConfigResponse = await request( GetLoyaltyLevel, - { lang: ctx.lang, level_id }, + { lang, level_id }, { - key: generateLoyaltyConfigTag(ctx.lang, "loyalty_level", level_id), + key: generateLoyaltyConfigTag(lang, "loyalty_level", level_id), ttl: "max", } ) @@ -116,9 +118,9 @@ export const loyaltyLevelQueryRouter = router({ byLevel: contentstackBaseProcedure .input(loyaltyLevelInput) .query(async function ({ ctx, input }) { - return getLoyaltyLevel(ctx, input.level) + return getLoyaltyLevel(ctx.lang, input.level) }), all: contentstackBaseProcedure.query(async function ({ ctx }) { - return getAllLoyaltyLevels(ctx) + return getAllLoyaltyLevels(ctx.lang) }), }) diff --git a/apps/scandic-web/server/routers/contentstack/loyaltyPage/index.ts b/apps/scandic-web/server/routers/contentstack/loyaltyPage/index.ts index 5e47223a1..aa1d6a6fa 100644 --- a/apps/scandic-web/server/routers/contentstack/loyaltyPage/index.ts +++ b/apps/scandic-web/server/routers/contentstack/loyaltyPage/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { loyaltyPageQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/loyaltyPage/query.ts b/apps/scandic-web/server/routers/contentstack/loyaltyPage/query.ts index f66424d99..622aa48ec 100644 --- a/apps/scandic-web/server/routers/contentstack/loyaltyPage/query.ts +++ b/apps/scandic-web/server/routers/contentstack/loyaltyPage/query.ts @@ -1,11 +1,13 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentstackExtendedProcedureUID } from "@scandic-hotels/trpc/procedures" + import { GetLoyaltyPage, GetLoyaltyPageRefs, } from "@/lib/graphql/Query/LoyaltyPage/LoyaltyPage.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentstackExtendedProcedureUID, router } from "@/server/trpc" import { generateRefsResponseTag, diff --git a/apps/scandic-web/server/routers/contentstack/metadata/index.ts b/apps/scandic-web/server/routers/contentstack/metadata/index.ts index 4da22bdee..f2282a2c4 100644 --- a/apps/scandic-web/server/routers/contentstack/metadata/index.ts +++ b/apps/scandic-web/server/routers/contentstack/metadata/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { metadataQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/metadata/output.ts b/apps/scandic-web/server/routers/contentstack/metadata/output.ts index 9d1266110..201dc26fd 100644 --- a/apps/scandic-web/server/routers/contentstack/metadata/output.ts +++ b/apps/scandic-web/server/routers/contentstack/metadata/output.ts @@ -15,13 +15,13 @@ import { getDescription } from "./utils/description" import { getImage } from "./utils/image" import { getTitle } from "./utils/title" +import type { Lang } from "@scandic-hotels/common/constants/language" import type { Metadata } from "next" import type { ImageVaultAsset } from "@/types/components/imageVault" import { Country } from "@/types/enums/country" import type { LanguageSwitcherData } from "@/types/requests/languageSwitcher" import { RTETypeEnum } from "@/types/rte/enums" -import type { Lang } from "@/constants/languages" const metaDataJsonSchema = z.object({ children: z.array( diff --git a/apps/scandic-web/server/routers/contentstack/metadata/query.ts b/apps/scandic-web/server/routers/contentstack/metadata/query.ts index 79eb13e31..7c06f4e77 100644 --- a/apps/scandic-web/server/routers/contentstack/metadata/query.ts +++ b/apps/scandic-web/server/routers/contentstack/metadata/query.ts @@ -1,5 +1,10 @@ import { cache } from "react" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentStackUidWithServiceProcedure } from "@scandic-hotels/trpc/procedures" + import { env } from "@/env/server" import { GetAccountPageMetadata } from "@/lib/graphql/Query/AccountPage/Metadata.graphql" import { GetCampaignPageMetadata } from "@/lib/graphql/Query/CampaignPage/Metadata.graphql" @@ -12,9 +17,6 @@ import { GetHotelPageMetadata } from "@/lib/graphql/Query/HotelPage/Metadata.gra import { GetLoyaltyPageMetadata } from "@/lib/graphql/Query/LoyaltyPage/Metadata.graphql" import { GetStartPageMetadata } from "@/lib/graphql/Query/StartPage/Metadata.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentStackUidWithServiceProcedure, router } from "@/server/trpc" import { generateTag } from "@/utils/generateTag" @@ -24,12 +26,12 @@ import { getMetadataInput } from "./input" import { getNonContentstackUrls, metadataSchema } from "./output" import { affix, getCityData, getCountryData } from "./utils" +import type { Lang } from "@scandic-hotels/common/constants/language" import type { Metadata } from "next" import { PageContentTypeEnum } from "@/types/requests/contentType" import type { LanguageSwitcherData } from "@/types/requests/languageSwitcher" import type { RawMetadataSchema } from "@/types/trpc/routers/contentstack/metadata" -import type { Lang } from "@/constants/languages" const fetchMetadata = cache(async function fetchMemoizedMetadata( query: string, diff --git a/apps/scandic-web/server/routers/contentstack/metadata/utils/index.ts b/apps/scandic-web/server/routers/contentstack/metadata/utils/index.ts index 8003b56f5..002b95991 100644 --- a/apps/scandic-web/server/routers/contentstack/metadata/utils/index.ts +++ b/apps/scandic-web/server/routers/contentstack/metadata/utils/index.ts @@ -1,4 +1,3 @@ -import { type Lang } from "@/constants/languages" import { getFiltersFromHotels, getSortedCities, @@ -12,6 +11,8 @@ import { } from "../../../hotels/utils" import { getCityPages } from "../../destinationCountryPage/utils" +import type { Lang } from "@scandic-hotels/common/constants/language" + import { ApiCountry } from "@/types/enums/country" import { SortOption } from "@/types/enums/destinationFilterAndSort" import type { diff --git a/apps/scandic-web/server/routers/contentstack/pageSettings/index.ts b/apps/scandic-web/server/routers/contentstack/pageSettings/index.ts index a6d9ecdd2..e16c05982 100644 --- a/apps/scandic-web/server/routers/contentstack/pageSettings/index.ts +++ b/apps/scandic-web/server/routers/contentstack/pageSettings/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { pageSettingsQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/pageSettings/query.ts b/apps/scandic-web/server/routers/contentstack/pageSettings/query.ts index 97b98a5d2..c4cd27e52 100644 --- a/apps/scandic-web/server/routers/contentstack/pageSettings/query.ts +++ b/apps/scandic-web/server/routers/contentstack/pageSettings/query.ts @@ -1,5 +1,8 @@ import * as Sentry from "@sentry/nextjs" +import { router } from "@scandic-hotels/trpc" +import { contentstackBaseProcedure } from "@scandic-hotels/trpc/procedures" + import { GetAccountPageSettings, GetCampaignPageSettings, @@ -14,7 +17,6 @@ import { GetStartPageSettings, } from "@/lib/graphql/Query/PageSettings.graphql" import { request } from "@/lib/graphql/request" -import { contentstackBaseProcedure, router } from "@/server/trpc" import { langInput } from "@/server/utils" import { generateTag } from "@/utils/generateTag" diff --git a/apps/scandic-web/server/routers/contentstack/partner/index.ts b/apps/scandic-web/server/routers/contentstack/partner/index.ts index 2a87cfc8c..9aad4af51 100644 --- a/apps/scandic-web/server/routers/contentstack/partner/index.ts +++ b/apps/scandic-web/server/routers/contentstack/partner/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { partnerQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/partner/query.ts b/apps/scandic-web/server/routers/contentstack/partner/query.ts index c07b55504..161305492 100644 --- a/apps/scandic-web/server/routers/contentstack/partner/query.ts +++ b/apps/scandic-web/server/routers/contentstack/partner/query.ts @@ -1,32 +1,35 @@ import { cache } from "react" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentstackBaseProcedure } from "@scandic-hotels/trpc/procedures" + import { GetAllSasTierComparison } from "@/lib/graphql/Query/SASTierComparison.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentstackBaseProcedure, router } from "@/server/trpc" import { validateSasTierComparisonSchema } from "./output" -import type { SasTierComparisonResponse } from "@/types/trpc/routers/contentstack/partner" -import type { Context } from "@/server/context" +import type { Lang } from "@scandic-hotels/common/constants/language" -export const getSasTierComparison = cache(async (ctx: Context) => { +import type { SasTierComparisonResponse } from "@/types/trpc/routers/contentstack/partner" + +export const getSasTierComparison = cache(async (lang: Lang) => { const getSasTierComparisonCounter = createCounter( "trpc.contentstack", "partner.getSasTierComparison" ) const metricsGetSasTierComparison = getSasTierComparisonCounter.init({ - lang: ctx.lang, + lang, }) metricsGetSasTierComparison.start() - const tag = `${ctx.lang}:sas_tier_comparison` + const tag = `${lang}:sas_tier_comparison` const sasTierComparisonConfigResponse = await request( GetAllSasTierComparison, - { lang: ctx.lang }, + { lang }, { key: tag, ttl: "max", @@ -59,6 +62,6 @@ export const partnerQueryRouter = router({ getSasTierComparison: contentstackBaseProcedure.query(async function ({ ctx, }) { - return getSasTierComparison(ctx) + return getSasTierComparison(ctx.lang) }), }) diff --git a/apps/scandic-web/server/routers/contentstack/reward/index.ts b/apps/scandic-web/server/routers/contentstack/reward/index.ts index 9b2203350..87084949d 100644 --- a/apps/scandic-web/server/routers/contentstack/reward/index.ts +++ b/apps/scandic-web/server/routers/contentstack/reward/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { rewardQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/reward/query.ts b/apps/scandic-web/server/routers/contentstack/reward/query.ts index 4f42ba4d5..99181cf82 100644 --- a/apps/scandic-web/server/routers/contentstack/reward/query.ts +++ b/apps/scandic-web/server/routers/contentstack/reward/query.ts @@ -1,12 +1,13 @@ -import * as api from "@/lib/api" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" import { contentStackBaseWithProtectedProcedure, contentStackBaseWithServiceProcedure, protectedProcedure, - router, -} from "@/server/trpc" +} from "@scandic-hotels/trpc/procedures" + +import * as api from "@/lib/api" import { langInput } from "@/server/utils" import { @@ -64,7 +65,7 @@ export const rewardQueryRouter = router({ return [] } - const loyaltyLevelsConfig = await getAllLoyaltyLevels(ctx) + const loyaltyLevelsConfig = await getAllLoyaltyLevels(ctx.lang) const levelsWithRewards = Object.entries(allApiRewards).map( ([level, rewards]) => { const combinedRewards = rewards @@ -150,7 +151,7 @@ export const rewardQueryRouter = router({ const [contentStackRewards, loyaltyLevelsConfig] = await Promise.all([ getCmsRewards(ctx.lang, rewardIds), - getLoyaltyLevel(ctx, input.level_id), + getLoyaltyLevel(ctx.lang, input.level_id), ]) if (!contentStackRewards) { diff --git a/apps/scandic-web/server/routers/contentstack/reward/utils.ts b/apps/scandic-web/server/routers/contentstack/reward/utils.ts index d441708e7..abf13298a 100644 --- a/apps/scandic-web/server/routers/contentstack/reward/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/reward/utils.ts @@ -1,4 +1,6 @@ import { getCacheClient } from "@scandic-hotels/common/dataCache" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { notFound } from "@scandic-hotels/trpc/errors" import * as api from "@/lib/api" import { @@ -6,8 +8,6 @@ import { GetRewardsRef as GetRewardsRef, } from "@/lib/graphql/Query/RewardsWithRedeem.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" import { generateLoyaltyConfigTag, @@ -20,11 +20,12 @@ import { validateCmsRewardsSchema, } from "./output" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { CMSRewardsResponse, GetRewardRefsSchema, } from "@/types/trpc/routers/contentstack/reward" -import type { Lang } from "@/constants/languages" export function getUniqueRewardIds(rewardIds: string[]) { const uniqueRewardIds = new Set(rewardIds) diff --git a/apps/scandic-web/server/routers/contentstack/schemas/system.ts b/apps/scandic-web/server/routers/contentstack/schemas/system.ts index bf6c19129..e86afd1e4 100644 --- a/apps/scandic-web/server/routers/contentstack/schemas/system.ts +++ b/apps/scandic-web/server/routers/contentstack/schemas/system.ts @@ -1,6 +1,6 @@ import { z } from "zod" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" export const systemSchema = z.object({ content_type_uid: z.string(), diff --git a/apps/scandic-web/server/routers/contentstack/startPage/index.ts b/apps/scandic-web/server/routers/contentstack/startPage/index.ts index c8236f2a6..3838da32f 100644 --- a/apps/scandic-web/server/routers/contentstack/startPage/index.ts +++ b/apps/scandic-web/server/routers/contentstack/startPage/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { startPageQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/contentstack/startPage/query.ts b/apps/scandic-web/server/routers/contentstack/startPage/query.ts index dd9dbb3c6..bc56125ad 100644 --- a/apps/scandic-web/server/routers/contentstack/startPage/query.ts +++ b/apps/scandic-web/server/routers/contentstack/startPage/query.ts @@ -1,11 +1,13 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { notFound } from "@scandic-hotels/trpc/errors" +import { contentstackExtendedProcedureUID } from "@scandic-hotels/trpc/procedures" + import { GetStartPage, GetStartPageRefs, } from "@/lib/graphql/Query/StartPage/StartPage.graphql" import { request } from "@/lib/graphql/request" -import { notFound } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" -import { contentstackExtendedProcedureUID, router } from "@/server/trpc" import { generateRefsResponseTag, diff --git a/apps/scandic-web/server/routers/hotels/index.ts b/apps/scandic-web/server/routers/hotels/index.ts index 5ea00a5de..eb748fabd 100644 --- a/apps/scandic-web/server/routers/hotels/index.ts +++ b/apps/scandic-web/server/routers/hotels/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { hotelQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/hotels/input.ts b/apps/scandic-web/server/routers/hotels/input.ts index 3ca849ff8..ce14ffbd8 100644 --- a/apps/scandic-web/server/routers/hotels/input.ts +++ b/apps/scandic-web/server/routers/hotels/input.ts @@ -1,7 +1,7 @@ import dayjs from "dayjs" import { z } from "zod" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums" import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter" diff --git a/apps/scandic-web/server/routers/hotels/query.ts b/apps/scandic-web/server/routers/hotels/query.ts index bdd6f8507..183515d31 100644 --- a/apps/scandic-web/server/routers/hotels/query.ts +++ b/apps/scandic-web/server/routers/hotels/query.ts @@ -1,21 +1,21 @@ +import { Lang } from "@scandic-hotels/common/constants/language" import { getCacheClient } from "@scandic-hotels/common/dataCache" - -import { REDEMPTION } from "@/constants/booking" -import { Lang } from "@/constants/languages" -import { env } from "@/env/server" -import * as api from "@/lib/api" -import { dt } from "@/lib/dt" -import { badRequestError, unauthorizedError } from "@/server/errors/trpc" -import { getCityPageUrls } from "@/server/routers/contentstack/destinationCityPage/utils" -import { getVerifiedUser } from "@/server/routers/user/utils" -import { createCounter } from "@/server/telemetry" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { badRequestError, unauthorizedError } from "@scandic-hotels/trpc/errors" import { contentStackBaseWithServiceProcedure, publicProcedure, - router, safeProtectedServiceProcedure, serviceProcedure, -} from "@/server/trpc" +} from "@scandic-hotels/trpc/procedures" + +import { REDEMPTION } from "@/constants/booking" +import { env } from "@/env/server" +import * as api from "@/lib/api" +import { dt } from "@/lib/dt" +import { getCityPageUrls } from "@/server/routers/contentstack/destinationCityPage/utils" +import { getVerifiedUser } from "@/server/routers/user/utils" import { toApiLang } from "@/server/utils" import { getHotelPageUrls } from "../contentstack/hotelPage/utils" diff --git a/apps/scandic-web/server/routers/hotels/utils.ts b/apps/scandic-web/server/routers/hotels/utils.ts index 08056cf85..fe09cb6f2 100644 --- a/apps/scandic-web/server/routers/hotels/utils.ts +++ b/apps/scandic-web/server/routers/hotels/utils.ts @@ -1,15 +1,15 @@ import deepmerge from "deepmerge" import stringify from "json-stable-stringify-without-jsonify" +import { Lang } from "@scandic-hotels/common/constants/language" import { getCacheClient } from "@scandic-hotels/common/dataCache" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { badRequestError } from "@scandic-hotels/trpc/errors" import { BookingErrorCodeEnum, REDEMPTION } from "@/constants/booking" -import { Lang } from "@/constants/languages" import { selectRate } from "@/constants/routes/hotelReservation" import { env } from "@/env/server" import * as api from "@/lib/api" -import { badRequestError } from "@/server/errors/trpc" -import { createCounter } from "@/server/telemetry" import { toApiLang } from "@/server/utils" import { generateChildrenString } from "@/components/HotelReservation/utils" diff --git a/apps/scandic-web/server/routers/navigation/index.ts b/apps/scandic-web/server/routers/navigation/index.ts index a007086a4..f2da2d4e5 100644 --- a/apps/scandic-web/server/routers/navigation/index.ts +++ b/apps/scandic-web/server/routers/navigation/index.ts @@ -1,4 +1,4 @@ -import { router } from "@/server/trpc" +import { router } from "@scandic-hotels/trpc" import { myPagesNavigation } from "./mypages/index" diff --git a/apps/scandic-web/server/routers/navigation/mypages/getPrimaryLinks.ts b/apps/scandic-web/server/routers/navigation/mypages/getPrimaryLinks.ts index addd86e5b..dbb8addb0 100644 --- a/apps/scandic-web/server/routers/navigation/mypages/getPrimaryLinks.ts +++ b/apps/scandic-web/server/routers/navigation/mypages/getPrimaryLinks.ts @@ -8,8 +8,9 @@ import { env } from "@/env/server" import { getIntl } from "@/i18n" import { getEurobonusMembership } from "@/utils/user" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { UserLoyalty } from "@/types/user" -import type { Lang } from "@/constants/languages" import type { MyPagesLink } from "./MyPagesLink" export const getPrimaryLinks = cache( diff --git a/apps/scandic-web/server/routers/navigation/mypages/getSecondaryLinks.ts b/apps/scandic-web/server/routers/navigation/mypages/getSecondaryLinks.ts index d57fce926..5257baf9b 100644 --- a/apps/scandic-web/server/routers/navigation/mypages/getSecondaryLinks.ts +++ b/apps/scandic-web/server/routers/navigation/mypages/getSecondaryLinks.ts @@ -2,7 +2,8 @@ import * as routes from "@/constants/routes/myPages" import { getIntl } from "@/i18n" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { MyPagesLink } from "./MyPagesLink" export async function getSecondaryLinks({ diff --git a/apps/scandic-web/server/routers/navigation/mypages/index.ts b/apps/scandic-web/server/routers/navigation/mypages/index.ts index 1490ee7fc..6b7fea898 100644 --- a/apps/scandic-web/server/routers/navigation/mypages/index.ts +++ b/apps/scandic-web/server/routers/navigation/mypages/index.ts @@ -1,9 +1,10 @@ import { TRPCError } from "@trpc/server" import { z } from "zod" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" +import { safeProtectedProcedure } from "@scandic-hotels/trpc/procedures" + import { getVerifiedUser } from "@/server/routers/user/utils" -import { safeProtectedProcedure } from "@/server/trpc" import { isValidSession } from "@/utils/session" diff --git a/apps/scandic-web/server/routers/partners/index.ts b/apps/scandic-web/server/routers/partners/index.ts index f1679a468..a83f29da9 100644 --- a/apps/scandic-web/server/routers/partners/index.ts +++ b/apps/scandic-web/server/routers/partners/index.ts @@ -1,4 +1,4 @@ -import { router } from "@/server/trpc" +import { router } from "@scandic-hotels/trpc" import { jobylonQueryRouter } from "./jobylon/query" import { sasRouter } from "./sas" diff --git a/apps/scandic-web/server/routers/partners/jobylon/query.ts b/apps/scandic-web/server/routers/partners/jobylon/query.ts index bc714d72a..f6ea7bd5b 100644 --- a/apps/scandic-web/server/routers/partners/jobylon/query.ts +++ b/apps/scandic-web/server/routers/partners/jobylon/query.ts @@ -1,7 +1,7 @@ import { getCacheClient } from "@scandic-hotels/common/dataCache" - -import { createCounter } from "@/server/telemetry" -import { publicProcedure, router } from "@/server/trpc" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { publicProcedure } from "@scandic-hotels/trpc/procedures" import { jobylonFeedSchema } from "./output" diff --git a/apps/scandic-web/server/routers/partners/sas/index.ts b/apps/scandic-web/server/routers/partners/sas/index.ts index 579dc87cf..645766c98 100644 --- a/apps/scandic-web/server/routers/partners/sas/index.ts +++ b/apps/scandic-web/server/routers/partners/sas/index.ts @@ -1,4 +1,4 @@ -import { router } from "@/server/trpc" +import { router } from "@scandic-hotels/trpc" import { requestOtp } from "./otp/request/requestOtp" import { verifyOtp } from "./otp/verify/verifyOtp" diff --git a/apps/scandic-web/server/routers/partners/sas/linkAccount.ts b/apps/scandic-web/server/routers/partners/sas/linkAccount.ts index 0eb732106..77ff9a029 100644 --- a/apps/scandic-web/server/routers/partners/sas/linkAccount.ts +++ b/apps/scandic-web/server/routers/partners/sas/linkAccount.ts @@ -1,8 +1,9 @@ import * as Sentry from "@sentry/nextjs" import { z } from "zod" +import { protectedProcedure } from "@scandic-hotels/trpc/procedures" + import * as api from "@/lib/api" -import { protectedProcedure } from "@/server/trpc" import { getOTPState } from "./otp/getOTPState" import { getSasToken } from "./getSasToken" diff --git a/apps/scandic-web/server/routers/partners/sas/otp/request/requestOtp.ts b/apps/scandic-web/server/routers/partners/sas/otp/request/requestOtp.ts index 673c0bc5a..874b57bf6 100644 --- a/apps/scandic-web/server/routers/partners/sas/otp/request/requestOtp.ts +++ b/apps/scandic-web/server/routers/partners/sas/otp/request/requestOtp.ts @@ -4,8 +4,9 @@ import { cookies } from "next/headers" import { v4 as uuidv4 } from "uuid" import { z } from "zod" +import { protectedProcedure } from "@scandic-hotels/trpc/procedures" + import { env } from "@/env/server" -import { protectedProcedure } from "@/server/trpc" import { getSasToken } from "../../getSasToken" import { SAS_REQUEST_OTP_STATE_STORAGE_COOKIE_NAME } from "../constants" diff --git a/apps/scandic-web/server/routers/partners/sas/otp/verify/verifyOtp.ts b/apps/scandic-web/server/routers/partners/sas/otp/verify/verifyOtp.ts index 2d33073b8..a69e84ea6 100644 --- a/apps/scandic-web/server/routers/partners/sas/otp/verify/verifyOtp.ts +++ b/apps/scandic-web/server/routers/partners/sas/otp/verify/verifyOtp.ts @@ -1,8 +1,9 @@ import { TRPCError } from "@trpc/server" import { z } from "zod" +import { protectedProcedure } from "@scandic-hotels/trpc/procedures" + import { env } from "@/env/server" -import { protectedProcedure } from "@/server/trpc" import { getSasToken } from "../../getSasToken" import { getOTPState } from "../getOTPState" diff --git a/apps/scandic-web/server/routers/partners/sas/performLevelUpgrade.ts b/apps/scandic-web/server/routers/partners/sas/performLevelUpgrade.ts index 41c40db07..b1c40ba2a 100644 --- a/apps/scandic-web/server/routers/partners/sas/performLevelUpgrade.ts +++ b/apps/scandic-web/server/routers/partners/sas/performLevelUpgrade.ts @@ -2,9 +2,10 @@ import * as Sentry from "@sentry/nextjs" import { cookies } from "next/headers" import { z } from "zod" +import { protectedProcedure } from "@scandic-hotels/trpc/procedures" + import { FriendsMembershipLevels } from "@/constants/membershipLevels" import * as api from "@/lib/api" -import { protectedProcedure } from "@/server/trpc" import { getUserSchema } from "../../user/output" import { getVerifiedUser } from "../../user/utils" diff --git a/apps/scandic-web/server/routers/partners/sas/transferPoints.ts b/apps/scandic-web/server/routers/partners/sas/transferPoints.ts index e8b9a5be3..f83cfdc0b 100644 --- a/apps/scandic-web/server/routers/partners/sas/transferPoints.ts +++ b/apps/scandic-web/server/routers/partners/sas/transferPoints.ts @@ -1,10 +1,12 @@ import * as Sentry from "@sentry/nextjs" import { z } from "zod" +import { protectedProcedure } from "@scandic-hotels/trpc/procedures" + import * as api from "@/lib/api" -import { protectedProcedure } from "@/server/trpc" import { getOTPState } from "./otp/getOTPState" +// import * as api from "@/lib/api" import { getSasToken } from "./getSasToken" const outputSchema = z.object({ diff --git a/apps/scandic-web/server/routers/partners/sas/unlinkAccount.ts b/apps/scandic-web/server/routers/partners/sas/unlinkAccount.ts index 7a5b6ddb0..78ee9a03d 100644 --- a/apps/scandic-web/server/routers/partners/sas/unlinkAccount.ts +++ b/apps/scandic-web/server/routers/partners/sas/unlinkAccount.ts @@ -1,7 +1,8 @@ import { z } from "zod" +import { protectedProcedure } from "@scandic-hotels/trpc/procedures" + import * as api from "@/lib/api" -import { protectedProcedure } from "@/server/trpc" import { getOTPState } from "./otp/getOTPState" import { getSasToken } from "./getSasToken" diff --git a/apps/scandic-web/server/routers/user/index.ts b/apps/scandic-web/server/routers/user/index.ts index 21941006d..759c466ae 100644 --- a/apps/scandic-web/server/routers/user/index.ts +++ b/apps/scandic-web/server/routers/user/index.ts @@ -1,4 +1,4 @@ -import { mergeRouters } from "@/server/trpc" +import { mergeRouters } from "@scandic-hotels/trpc" import { userMutationRouter } from "./mutation" import { userQueryRouter } from "./query" diff --git a/apps/scandic-web/server/routers/user/input.ts b/apps/scandic-web/server/routers/user/input.ts index b1d70b524..50499eefc 100644 --- a/apps/scandic-web/server/routers/user/input.ts +++ b/apps/scandic-web/server/routers/user/input.ts @@ -1,6 +1,6 @@ import { z } from "zod" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import { signUpSchema } from "@/components/Forms/Signup/schema" diff --git a/apps/scandic-web/server/routers/user/mutation.ts b/apps/scandic-web/server/routers/user/mutation.ts index 44d942ba0..00137de29 100644 --- a/apps/scandic-web/server/routers/user/mutation.ts +++ b/apps/scandic-web/server/routers/user/mutation.ts @@ -1,13 +1,18 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" +import { serverErrorByStatus } from "@scandic-hotels/trpc/errors" +import { + protectedProcedure, + serviceProcedure, +} from "@scandic-hotels/trpc/procedures" + import { signupVerify } from "@/constants/routes/signup" import { env } from "@/env/server" import * as api from "@/lib/api" -import { serverErrorByStatus } from "@/server/errors/trpc" import { initiateSaveCardSchema, subscriberIdSchema, } from "@/server/routers/user/output" -import { createCounter } from "@/server/telemetry" -import { protectedProcedure, router, serviceProcedure } from "@/server/trpc" import { addCreditCardInput, diff --git a/apps/scandic-web/server/routers/user/query.ts b/apps/scandic-web/server/routers/user/query.ts index 2f1bbe981..07e835c99 100644 --- a/apps/scandic-web/server/routers/user/query.ts +++ b/apps/scandic-web/server/routers/user/query.ts @@ -1,11 +1,12 @@ -import * as api from "@/lib/api" -import { createCounter } from "@/server/telemetry" +import { createCounter } from "@scandic-hotels/common/telemetry" +import { router } from "@scandic-hotels/trpc" import { languageProtectedProcedure, protectedProcedure, - router, safeProtectedProcedure, -} from "@/server/trpc" +} from "@scandic-hotels/trpc/procedures" + +import * as api from "@/lib/api" import { toApiLang } from "@/server/utils" import { isValidSession } from "@/utils/session" diff --git a/apps/scandic-web/server/routers/user/utils.ts b/apps/scandic-web/server/routers/user/utils.ts index 361e7aef7..0e3b469c7 100644 --- a/apps/scandic-web/server/routers/user/utils.ts +++ b/apps/scandic-web/server/routers/user/utils.ts @@ -1,10 +1,11 @@ +import { createCounter } from "@scandic-hotels/common/telemetry" + import { countries } from "@/constants/countries" import { myBookingPath } from "@/constants/myBooking" import { myStay } from "@/constants/routes/myStay" import { env } from "@/env/server" import * as api from "@/lib/api" import { dt } from "@/lib/dt" -import { createCounter } from "@/server/telemetry" import { toApiLang } from "@/server/utils" import { cache } from "@/utils/cache" @@ -22,10 +23,10 @@ import { type Stay, } from "./output" +import type { Lang } from "@scandic-hotels/common/constants/language" import type { Session } from "next-auth" import type { User } from "@/types/user" -import type { Lang } from "@/constants/languages" export const getVerifiedUser = cache( async ({ diff --git a/apps/scandic-web/server/trpc.ts b/apps/scandic-web/server/trpc.ts index f33e06f1f..57756949f 100644 --- a/apps/scandic-web/server/trpc.ts +++ b/apps/scandic-web/server/trpc.ts @@ -1,211 +1,19 @@ -import * as Sentry from "@sentry/nextjs" -import { initTRPC } from "@trpc/server" import { experimental_nextAppDirCaller } from "@trpc/server/adapters/next-app-dir" -import { ZodError } from "zod" - -import { env } from "@/env/server" import { - badRequestError, - internalServerError, - sessionExpiredError, - unauthorizedError, -} from "./errors/trpc" -import { type Context, createContext } from "./context" -import { getServiceToken } from "./tokenManager" -import { transformer } from "./transformer" -import { langInput } from "./utils" + baseProcedure, + getProtectedServerActionProcedure, +} from "@scandic-hotels/trpc/procedures" -import type { Session } from "next-auth" +import { createAppContext } from "@/lib/trpc/server" -import type { Meta } from "@/types/trpc/meta" - -const t = initTRPC - .context() - .meta() - .create({ - transformer, - errorFormatter({ shape, error }) { - return { - ...shape, - data: { - ...shape.data, - cause: - error.cause instanceof ZodError - ? undefined - : JSON.parse(JSON.stringify(error.cause)), - zodError: - error.cause instanceof ZodError ? error.cause.flatten() : null, - }, - } - }, - }) - -const sentryMiddleware = t.middleware( - Sentry.trpcMiddleware({ - attachRpcInput: true, - }) -) - -export const { createCallerFactory, mergeRouters, router } = t -const baseProcedure = t.procedure.use(sentryMiddleware) - -export const publicProcedure = baseProcedure - -export const languageProcedure = 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: opts.ctx.lang, - }, - }) -}) - -export const contentstackBaseProcedure = languageProcedure - -export const contentstackExtendedProcedureUID = contentstackBaseProcedure.use( - async function (opts) { - if (!opts.ctx.uid) { - throw badRequestError("Missing UID in tRPC context") - } - - return opts.next({ - ctx: { - uid: opts.ctx.uid, - }, - }) - } -) -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") { - console.info( - `❌❌❌❌ You are opting out of authorization, if its done on purpose maybe you should use the publicProcedure instead. ❌❌❌❌` - ) - console.info(`path: ${opts.path} | type: ${opts.type}`) - } - - if (!session) { - throw unauthorizedError() - } - - if (session?.error === "RefreshAccessTokenError") { - throw sessionExpiredError() - } - - return opts.next({ - ctx: { - session, - }, - }) -}) - -export const safeProtectedProcedure = baseProcedure.use(async function (opts) { - const authRequired = opts.meta?.authRequired ?? true - let session: Session | null = await opts.ctx.auth() - if (!authRequired && env.NODE_ENV === "development") { - console.info( - `❌❌❌❌ You are opting out of authorization, if its done on purpose maybe you should use the publicProcedure instead. ❌❌❌❌` - ) - console.info(`path: ${opts.path} | type: ${opts.type}`) - } - - if (!session || session.error === "RefreshAccessTokenError") { - session = null - } - - return opts.next({ - ctx: { - session, - }, - }) -}) - -export const serviceProcedure = baseProcedure.use(async (opts) => { - const token = await getServiceToken() - const { access_token } = token - if (!access_token) { - throw internalServerError(`[serviceProcedure] No service token`) - } - return opts.next({ - ctx: { - serviceToken: access_token, - }, - }) -}) - -export const serverActionProcedure = baseProcedure.experimental_caller( +const serverActionProcedure = baseProcedure.experimental_caller( experimental_nextAppDirCaller({ - createContext, + createContext: createAppContext, normalizeFormData: true, }) ) -export const serviceServerActionProcedure = serverActionProcedure.use( - async (opts) => { - const { access_token } = await getServiceToken() - if (!access_token) { - throw internalServerError( - "[serviceServerActionProcedure]: No service token" - ) - } - return opts.next({ - ctx: { - serviceToken: access_token, - }, - }) - } +export const protectedServerActionProcedure = getProtectedServerActionProcedure( + serverActionProcedure ) - -export const protectedServerActionProcedure = serverActionProcedure.use( - async (opts) => { - const session = await opts.ctx.auth() - if (!session) { - throw unauthorizedError() - } - - if (session && session.error === "RefreshAccessTokenError") { - throw sessionExpiredError() - } - - return opts.next({ - ctx: { - ...opts.ctx, - session, - }, - }) - } -) - -export const contentStackUidWithServiceProcedure = - contentstackExtendedProcedureUID.concat(serviceProcedure) - -export const contentStackBaseWithServiceProcedure = - contentstackBaseProcedure.concat(serviceProcedure) - -export const contentStackBaseWithProtectedProcedure = - contentstackBaseProcedure.concat(protectedProcedure) - -export const safeProtectedServiceProcedure = - safeProtectedProcedure.concat(serviceProcedure) - -export const languageProtectedProcedure = - protectedProcedure.concat(languageProcedure) diff --git a/apps/scandic-web/server/utils.ts b/apps/scandic-web/server/utils.ts index 65c37fddf..a6b4bea82 100644 --- a/apps/scandic-web/server/utils.ts +++ b/apps/scandic-web/server/utils.ts @@ -1,7 +1,8 @@ import { NextRequest } from "next/server" import { z } from "zod" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { env } from "@/env/server" export function isDefined(argument: T | undefined | null): argument is T { diff --git a/apps/scandic-web/services/cms/getUidAndContentTypeByPath.ts b/apps/scandic-web/services/cms/getUidAndContentTypeByPath.ts index add3e8e84..7b2539283 100644 --- a/apps/scandic-web/services/cms/getUidAndContentTypeByPath.ts +++ b/apps/scandic-web/services/cms/getUidAndContentTypeByPath.ts @@ -1,4 +1,4 @@ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import { resolve as resolveEntry } from "@/utils/entry" import { findLang } from "@/utils/languages" diff --git a/apps/scandic-web/services/warmup/index.ts b/apps/scandic-web/services/warmup/index.ts index a6c74e3f4..0ccc1dccd 100644 --- a/apps/scandic-web/services/warmup/index.ts +++ b/apps/scandic-web/services/warmup/index.ts @@ -1,4 +1,4 @@ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" import { warmupAutoComplete } from "./wamupAutoCompleteLocations" import { warmupCountry } from "./warmupCountries" diff --git a/apps/scandic-web/services/warmup/wamupAutoCompleteLocations.ts b/apps/scandic-web/services/warmup/wamupAutoCompleteLocations.ts index f16332e77..485a726d2 100644 --- a/apps/scandic-web/services/warmup/wamupAutoCompleteLocations.ts +++ b/apps/scandic-web/services/warmup/wamupAutoCompleteLocations.ts @@ -1,7 +1,9 @@ -import { getAutoCompleteDestinationsData } from "@/server/routers/autocomplete/destinations" -import { getServiceToken } from "@/server/tokenManager" +import { getServiceToken } from "@scandic-hotels/common/tokenManager" + +import { getAutoCompleteDestinationsData } from "@/server/routers/autocomplete/destinations" + +import type { Lang } from "@scandic-hotels/common/constants/language" -import type { Lang } from "@/constants/languages" import type { WarmupFunction, WarmupResult } from "." export const warmupAutoComplete = diff --git a/apps/scandic-web/services/warmup/warmupCountries.ts b/apps/scandic-web/services/warmup/warmupCountries.ts index 45927d06f..a6371a31b 100644 --- a/apps/scandic-web/services/warmup/warmupCountries.ts +++ b/apps/scandic-web/services/warmup/warmupCountries.ts @@ -1,7 +1,9 @@ -import { getCountries } from "@/server/routers/hotels/utils" -import { getServiceToken } from "@/server/tokenManager" +import { getServiceToken } from "@scandic-hotels/common/tokenManager" + +import { getCountries } from "@/server/routers/hotels/utils" + +import type { Lang } from "@scandic-hotels/common/constants/language" -import type { Lang } from "@/constants/languages" import type { WarmupFunction, WarmupResult } from "." export const warmupCountry = diff --git a/apps/scandic-web/services/warmup/warmupHotelData.ts b/apps/scandic-web/services/warmup/warmupHotelData.ts index 2853f2fcf..1972d54f8 100644 --- a/apps/scandic-web/services/warmup/warmupHotelData.ts +++ b/apps/scandic-web/services/warmup/warmupHotelData.ts @@ -1,7 +1,8 @@ import { env } from "@/env/server" import { serverClient } from "@/lib/trpc/server" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { WarmupFunction, WarmupResult } from "." export const warmupHotelData = diff --git a/apps/scandic-web/services/warmup/warmupHotelIdsByCountry.ts b/apps/scandic-web/services/warmup/warmupHotelIdsByCountry.ts index 4fd5b8a19..58a4526df 100644 --- a/apps/scandic-web/services/warmup/warmupHotelIdsByCountry.ts +++ b/apps/scandic-web/services/warmup/warmupHotelIdsByCountry.ts @@ -1,11 +1,11 @@ +import { Lang } from "@scandic-hotels/common/constants/language" +import { getServiceToken } from "@scandic-hotels/common/tokenManager" import { safeTry } from "@scandic-hotels/common/utils/safeTry" -import { Lang } from "@/constants/languages" import { getCountries, getHotelIdsByCountry, } from "@/server/routers/hotels/utils" -import { getServiceToken } from "@/server/tokenManager" import type { WarmupFunction, WarmupResult } from "." diff --git a/apps/scandic-web/services/warmup/warmupKeys.ts b/apps/scandic-web/services/warmup/warmupKeys.ts index 77dbab106..58e5d5973 100644 --- a/apps/scandic-web/services/warmup/warmupKeys.ts +++ b/apps/scandic-web/services/warmup/warmupKeys.ts @@ -1,4 +1,4 @@ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" const langs = Object.keys(Lang) as Lang[] diff --git a/apps/scandic-web/types/components/hotelReservation/myStay/changeDates.ts b/apps/scandic-web/types/components/hotelReservation/myStay/changeDates.ts index ad4c3df84..1afa37add 100644 --- a/apps/scandic-web/types/components/hotelReservation/myStay/changeDates.ts +++ b/apps/scandic-web/types/components/hotelReservation/myStay/changeDates.ts @@ -1,6 +1,6 @@ import { z } from "zod" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" export const changeDatesSchema = z.object({ checkInDate: z.string(), diff --git a/apps/scandic-web/types/components/myPages/myPage/earnAndBurn.ts b/apps/scandic-web/types/components/myPages/myPage/earnAndBurn.ts index b3369b968..ccd53fb62 100644 --- a/apps/scandic-web/types/components/myPages/myPage/earnAndBurn.ts +++ b/apps/scandic-web/types/components/myPages/myPage/earnAndBurn.ts @@ -1,7 +1,7 @@ +import type { Lang } from "@scandic-hotels/common/constants/language" import type { VariantProps } from "class-variance-authority" import type { awardPointsVariants } from "@/components/Blocks/DynamicContent/Points/EarnAndBurn/AwardPoints/awardPointsVariants" -import type { Lang } from "@/constants/languages" import type { UserQueryRouter } from "../user" export type TransactionResponse = Awaited< diff --git a/apps/scandic-web/types/components/myPages/stays/upcoming.ts b/apps/scandic-web/types/components/myPages/stays/upcoming.ts index 769ff8307..829c201b1 100644 --- a/apps/scandic-web/types/components/myPages/stays/upcoming.ts +++ b/apps/scandic-web/types/components/myPages/stays/upcoming.ts @@ -1,4 +1,3 @@ -import type { Lang } from "@/constants/languages" import type { UserQueryRouter } from "../user" export type UpcomingStaysResponse = Awaited< diff --git a/apps/scandic-web/types/components/tracking.ts b/apps/scandic-web/types/components/tracking.ts index 439a09e12..ee738dd32 100644 --- a/apps/scandic-web/types/components/tracking.ts +++ b/apps/scandic-web/types/components/tracking.ts @@ -1,4 +1,5 @@ -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { MembershipLevel } from "@/constants/membershipLevels" import type { RateEnum } from "../enums/rate" diff --git a/apps/scandic-web/types/enums/country.ts b/apps/scandic-web/types/enums/country.ts index d06844ca2..27cfbe103 100644 --- a/apps/scandic-web/types/enums/country.ts +++ b/apps/scandic-web/types/enums/country.ts @@ -1,4 +1,4 @@ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" export enum Country { Denmark = "Denmark", diff --git a/apps/scandic-web/types/params.ts b/apps/scandic-web/types/params.ts index 90e17a61d..8485444d4 100644 --- a/apps/scandic-web/types/params.ts +++ b/apps/scandic-web/types/params.ts @@ -1,4 +1,5 @@ -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { PageContentTypeEnum } from "./requests/contentType" export type NextSearchParams = { [key: string]: string | string[] | undefined } diff --git a/apps/scandic-web/types/requests/asides/contact.ts b/apps/scandic-web/types/requests/asides/contact.ts index dafc5564c..b45fb0773 100644 --- a/apps/scandic-web/types/requests/asides/contact.ts +++ b/apps/scandic-web/types/requests/asides/contact.ts @@ -1,4 +1,5 @@ -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { EdgesWithTotalCount } from "../utils/edges" import type { Typename } from "../utils/typename" diff --git a/apps/scandic-web/types/routes.ts b/apps/scandic-web/types/routes.ts index 17acc1eaa..91eb813ae 100644 --- a/apps/scandic-web/types/routes.ts +++ b/apps/scandic-web/types/routes.ts @@ -1,3 +1,3 @@ -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" export type LangRoute = Record diff --git a/apps/scandic-web/types/rte/attrs.ts b/apps/scandic-web/types/rte/attrs.ts index 0f635d0cc..112edf802 100644 --- a/apps/scandic-web/types/rte/attrs.ts +++ b/apps/scandic-web/types/rte/attrs.ts @@ -1,11 +1,10 @@ -import { +import type { Lang } from "@scandic-hotels/common/constants/language" + +import type { ImageVaultAsset, ImageVaultAssetResponse, } from "../components/imageVault" -import { RTEItemTypeEnum } from "./enums" - -import type { Lang } from "@/constants/languages" -import type { EmbedTypesEnum, RTEItemType } from "./enums" +import type { EmbedTypesEnum, RTEItemType, RTEItemTypeEnum } from "./enums" export interface Attributes { [key: string]: any diff --git a/apps/scandic-web/types/sitemap.ts b/apps/scandic-web/types/sitemap.ts index e3053456f..d032ac598 100644 --- a/apps/scandic-web/types/sitemap.ts +++ b/apps/scandic-web/types/sitemap.ts @@ -1,7 +1,6 @@ +import type { Lang } from "@scandic-hotels/common/constants/language" import type { SyncResult } from "contentstack" -import type { Lang } from "@/constants/languages" - export type ChangeFrequency = | "always" | "hourly" diff --git a/apps/scandic-web/types/tokens.ts b/apps/scandic-web/types/tokens.ts deleted file mode 100644 index 355ab5ad5..000000000 --- a/apps/scandic-web/types/tokens.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface ServiceTokenResponse { - access_token: string - scope?: string - token_type: string - expires_in: number -} diff --git a/apps/scandic-web/types/transitionTypes/rte/attrs.ts b/apps/scandic-web/types/transitionTypes/rte/attrs.ts index 602dc28ce..8c298912c 100644 --- a/apps/scandic-web/types/transitionTypes/rte/attrs.ts +++ b/apps/scandic-web/types/transitionTypes/rte/attrs.ts @@ -1,8 +1,7 @@ -import { ImageVaultAsset } from "../../components/imageVault" -import { RTEItemTypeEnum } from "./enums" +import type { Lang } from "@scandic-hotels/common/constants/language" -import type { Lang } from "@/constants/languages" -import type { EmbedTypesEnum, RTEItemType } from "./enums" +import type { ImageVaultAsset } from "../../components/imageVault" +import type { EmbedTypesEnum, RTEItemType, RTEItemTypeEnum } from "./enums" export interface Attributes { [key: string]: any diff --git a/apps/scandic-web/types/trpc/meta.ts b/apps/scandic-web/types/trpc/meta.ts deleted file mode 100644 index e52d2bbaf..000000000 --- a/apps/scandic-web/types/trpc/meta.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type Meta = { - authRequired?: boolean -} diff --git a/apps/scandic-web/utils/dateFormatting.ts b/apps/scandic-web/utils/dateFormatting.ts index d1b8c3a9e..4bc260f68 100644 --- a/apps/scandic-web/utils/dateFormatting.ts +++ b/apps/scandic-web/utils/dateFormatting.ts @@ -1,6 +1,6 @@ import { dt } from "@/lib/dt" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" /** * Get the localized month name for a given month index and language diff --git a/apps/scandic-web/utils/entry.ts b/apps/scandic-web/utils/entry.ts index a1b8b1bf0..19991bdab 100644 --- a/apps/scandic-web/utils/entry.ts +++ b/apps/scandic-web/utils/entry.ts @@ -1,4 +1,5 @@ -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" + import { batchRequest } from "@/lib/graphql/batchRequest" import { EntryByUrlBatch1, diff --git a/apps/scandic-web/utils/generateMetadata.ts b/apps/scandic-web/utils/generateMetadata.ts index 48833795b..960f11339 100644 --- a/apps/scandic-web/utils/generateMetadata.ts +++ b/apps/scandic-web/utils/generateMetadata.ts @@ -1,6 +1,7 @@ import { env } from "@/env/server" import { serverClient } from "@/lib/trpc/server" +import type { Lang } from "@scandic-hotels/common/constants/language" import type { AlternateURLs } from "next/dist/lib/metadata/types/alternative-urls-types" import type { @@ -9,7 +10,6 @@ import type { PageArgs, UIDParams, } from "@/types/params" -import type { Lang } from "@/constants/languages" export async function generateMetadata({ searchParams, diff --git a/apps/scandic-web/utils/generateTag.ts b/apps/scandic-web/utils/generateTag.ts index f85fe72fc..e1e3d4695 100644 --- a/apps/scandic-web/utils/generateTag.ts +++ b/apps/scandic-web/utils/generateTag.ts @@ -1,7 +1,8 @@ +import type { Lang } from "@scandic-hotels/common/constants/language" + import type { System } from "@/types/requests/system" import type { Edges } from "@/types/requests/utils/edges" import type { NodeRefs } from "@/types/requests/utils/refs" -import type { Lang } from "@/constants/languages" /** * Function to generate tag for initial refs request diff --git a/apps/scandic-web/utils/languages.ts b/apps/scandic-web/utils/languages.ts index 311fd9a24..ad1e30aca 100644 --- a/apps/scandic-web/utils/languages.ts +++ b/apps/scandic-web/utils/languages.ts @@ -1,6 +1,6 @@ import { z } from "zod" -import { Lang } from "@/constants/languages" +import { Lang } from "@scandic-hotels/common/constants/language" export const languageSchema = z.preprocess( (arg) => (typeof arg === "string" ? arg.toLowerCase() : arg), diff --git a/apps/scandic-web/utils/url.ts b/apps/scandic-web/utils/url.ts index 12f716af5..a5167477c 100644 --- a/apps/scandic-web/utils/url.ts +++ b/apps/scandic-web/utils/url.ts @@ -1,7 +1,8 @@ import { z } from "zod" +import { Lang } from "@scandic-hotels/common/constants/language" + import { bookingSearchTypes } from "@/constants/booking" -import { Lang } from "@/constants/languages" import { parseSearchParams, serializeSearchParams } from "./searchParams" diff --git a/apps/scandic-web/utils/webviews.ts b/apps/scandic-web/utils/webviews.ts index 561e94162..3a8b1bf74 100644 --- a/apps/scandic-web/utils/webviews.ts +++ b/apps/scandic-web/utils/webviews.ts @@ -4,7 +4,7 @@ import { headers } from "next/headers" import { webviews } from "@/constants/routes/webviews" -import type { Lang } from "@/constants/languages" +import type { Lang } from "@scandic-hotels/common/constants/language" export async function webviewSearchParams() { const searchParams = new URLSearchParams() diff --git a/packages/common/constants/language.ts b/packages/common/constants/language.ts new file mode 100644 index 000000000..97732c943 --- /dev/null +++ b/packages/common/constants/language.ts @@ -0,0 +1,8 @@ +export enum Lang { + da = "da", + de = "de", + en = "en", + fi = "fi", + no = "no", + sv = "sv", +} diff --git a/packages/common/env/server.ts b/packages/common/env/server.ts index 3634eeb51..3e1b18468 100644 --- a/packages/common/env/server.ts +++ b/packages/common/env/server.ts @@ -17,6 +17,9 @@ export const env = createEnv({ ? z.string() : z.string().optional().default("dev"), GIT_SHA: z.string().optional(), + CURITY_ISSUER_USER: z.string(), + CURITY_CLIENT_ID_SERVICE: z.string().default("scandichotels-web-backend"), + CURITY_CLIENT_SECRET_SERVICE: z.string(), }, emptyStringAsUndefined: true, runtimeEnv: { @@ -25,5 +28,8 @@ export const env = createEnv({ REDIS_API_KEY: process.env.REDIS_API_KEY, BRANCH: process.env.BRANCH, GIT_SHA: process.env.GIT_SHA, + CURITY_CLIENT_SECRET_SERVICE: process.env.CURITY_CLIENT_SECRET_SERVICE, + CURITY_ISSUER_USER: process.env.CURITY_ISSUER_USER, + CURITY_CLIENT_ID_SERVICE: process.env.CURITY_CLIENT_ID_SERVICE, }, }) diff --git a/packages/common/package.json b/packages/common/package.json index 811675ec7..2f4d75092 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -10,10 +10,22 @@ "check-types": "tsc --noEmit", "lint": "eslint . --max-warnings 0 && tsc --noEmit" }, + "exports": { + "./global.d.ts": "./global.d.ts", + "./dataCache": "./dataCache/index.ts", + "./telemetry": "./telemetry/index.ts", + "./tokenManager": "./tokenManager/index.ts", + "./utils/isEdge": "./utils/isEdge.ts", + "./utils/safeTry": "./utils/safeTry.ts", + "./constants/language": "./constants/language.ts" + }, "dependencies": { "@opentelemetry/api": "^1.9.0", "@sentry/nextjs": "^8.41.0", "@t3-oss/env-nextjs": "^0.13.4", + "deepmerge": "^4.3.1", + "flat": "^6.0.1", + "lodash-es": "^4.17.21", "zod": "^3.24.4" }, "devDependencies": { @@ -21,6 +33,7 @@ "@eslint/eslintrc": "^3.3.1", "@eslint/js": "^9.26.0", "@scandic-hotels/typescript-config": "workspace:*", + "@types/lodash-es": "^4", "@typescript-eslint/eslint-plugin": "^8.32.0", "@typescript-eslint/parser": "^8.32.0", "dotenv": "^16.5.0", diff --git a/apps/scandic-web/server/telemetry/index.test.ts b/packages/common/telemetry/index.test.ts similarity index 97% rename from apps/scandic-web/server/telemetry/index.test.ts rename to packages/common/telemetry/index.test.ts index 1d1065f86..1349e75b3 100644 --- a/apps/scandic-web/server/telemetry/index.test.ts +++ b/packages/common/telemetry/index.test.ts @@ -1,6 +1,6 @@ -import { describe, expect, test } from "@jest/globals" +import { describe, expect, test } from "vitest" -import { sanitize } from "./" +import { sanitize } from "." describe("sanitize", () => { test("should handle valid primitive attributes", () => { diff --git a/apps/scandic-web/server/telemetry/index.ts b/packages/common/telemetry/index.ts similarity index 100% rename from apps/scandic-web/server/telemetry/index.ts rename to packages/common/telemetry/index.ts diff --git a/packages/common/tokenManager/index.ts b/packages/common/tokenManager/index.ts new file mode 100644 index 000000000..d8d677718 --- /dev/null +++ b/packages/common/tokenManager/index.ts @@ -0,0 +1,2 @@ +import { getServiceToken } from "./tokenManager" +export { getServiceToken } diff --git a/apps/scandic-web/server/tokenManager.ts b/packages/common/tokenManager/tokenManager.ts similarity index 92% rename from apps/scandic-web/server/tokenManager.ts rename to packages/common/tokenManager/tokenManager.ts index 33b3e72c6..14d1683d2 100644 --- a/apps/scandic-web/server/tokenManager.ts +++ b/packages/common/tokenManager/tokenManager.ts @@ -1,11 +1,15 @@ import { trace, type Tracer } from "@opentelemetry/api" -import { getCacheClient } from "@scandic-hotels/common/dataCache" +import { getCacheClient } from "../dataCache" +import { env } from "../env/server" +import { createCounter } from "../telemetry" -import { env } from "@/env/server" -import { createCounter } from "@/server/telemetry" - -import type { ServiceTokenResponse } from "@/types/tokens" +interface ServiceTokenResponse { + access_token: string + scope?: string + token_type: string + expires_in: number +} export async function getServiceToken() { const tracer = trace.getTracer("getServiceToken") diff --git a/packages/trpc/env/server.ts b/packages/trpc/env/server.ts new file mode 100644 index 000000000..79a961338 --- /dev/null +++ b/packages/trpc/env/server.ts @@ -0,0 +1,18 @@ +import { createEnv } from "@t3-oss/env-nextjs" +import { z } from "zod" + +export const env = createEnv({ + /** + * Due to t3-env only checking typeof window === "undefined" + * and Netlify running Deno, window is never "undefined" + * https://github.com/t3-oss/t3-env/issues/154 + */ + isServer: typeof window === "undefined" || "Deno" in window, + server: { + NODE_ENV: z.enum(["development", "test", "production"]), + }, + emptyStringAsUndefined: true, + runtimeEnv: { + NODE_ENV: process.env.NODE_ENV, + }, +}) diff --git a/packages/trpc/eslint.config.mjs b/packages/trpc/eslint.config.mjs new file mode 100644 index 000000000..6aa5464e2 --- /dev/null +++ b/packages/trpc/eslint.config.mjs @@ -0,0 +1,89 @@ +import { FlatCompat } from "@eslint/eslintrc" +import js from "@eslint/js" +import typescriptEslint from "@typescript-eslint/eslint-plugin" +import tsParser from "@typescript-eslint/parser" +import { defineConfig } from "eslint/config" +import simpleImportSort from "eslint-plugin-simple-import-sort" +import importPlugin from "eslint-plugin-import" + +const compat = new FlatCompat({ + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all, +}) + +export default defineConfig([ + { + files: ["**/*.ts", "**/*.tsx"], + extends: compat.extends("plugin:import/typescript"), + plugins: { + "simple-import-sort": simpleImportSort, + "@typescript-eslint": typescriptEslint, + import: importPlugin, + }, + + linterOptions: { + reportUnusedDisableDirectives: true, + }, + + languageOptions: { + parser: tsParser, + }, + + rules: { + "no-unused-vars": "off", + "import/no-relative-packages": "error", + "simple-import-sort/imports": [ + "error", + { + groups: [ + ["^\\u0000"], + ["^node:"], + ["^@?\\w"], + ["^@scandic-hotels/(?!.*\u0000$).*$"], + [ + "^@/constants/?(?!.*\u0000$).*$", + "^@/env/?(?!.*\u0000$).*$", + "^@/lib/?(?!.*\u0000$).*$", + "^@/server/?(?!.*\u0000$).*$", + "^@/stores/?(?!.*\u0000$).*$", + ], + ["^@/(?!(types|.*\u0000$)).*$"], + [ + "^\\.\\.(?!/?$)", + "^\\.\\./?$", + "^\\./(?=.*/)(?!/?$)", + "^\\.(?!/?$)", + "^\\./?$", + ], + ["^(?!\\u0000).+\\.s?css$"], + ["^node:.*\\u0000$", "^@?\\w.*\\u0000$"], + [ + "^@scandichotels/.*\\u0000$", + "^@/types/.*", + "^@/.*\\u0000$", + "^[^.].*\\u0000$", + "^\\..*\\u0000$", + ], + ], + }, + ], + + "simple-import-sort/exports": "error", + + "@typescript-eslint/consistent-type-imports": "error", + + "@typescript-eslint/no-unused-vars": [ + "error", + { + args: "all", + argsIgnorePattern: "^_", + caughtErrors: "all", + caughtErrorsIgnorePattern: "^_", + destructuredArrayIgnorePattern: "^_", + varsIgnorePattern: "^_", + ignoreRestSiblings: true, + }, + ], + }, + }, +]) diff --git a/packages/trpc/global.d.ts b/packages/trpc/global.d.ts new file mode 100644 index 000000000..c218bf691 --- /dev/null +++ b/packages/trpc/global.d.ts @@ -0,0 +1,5 @@ +import type { DataCache } from "./dataCache/Cache" + +declare global { + var cacheClient: Promise | undefined +} diff --git a/packages/trpc/lib/context.ts b/packages/trpc/lib/context.ts new file mode 100644 index 000000000..05f4b31bf --- /dev/null +++ b/packages/trpc/lib/context.ts @@ -0,0 +1,34 @@ +import type { Lang } from "@scandic-hotels/common/constants/language" +import type { User } from "next-auth" +import type { JWT } from "next-auth/jwt" + +type Session = { + token: JWT + expires: string + user?: User + error?: "RefreshAccessTokenError" +} + +type CreateContextOptions = { + auth: () => Promise + lang: Lang + pathname: string + uid?: string | null + url: string + webToken?: string + contentType?: string +} + +export function createContext(opts: CreateContextOptions) { + return { + auth: opts.auth, + lang: opts.lang, + pathname: opts.pathname, + uid: opts.uid, + url: opts.url, + webToken: opts.webToken, + contentType: opts.contentType, + } +} + +export type Context = Awaited> diff --git a/apps/scandic-web/server/errors/trpc.ts b/packages/trpc/lib/errors.ts similarity index 100% rename from apps/scandic-web/server/errors/trpc.ts rename to packages/trpc/lib/errors.ts diff --git a/packages/trpc/lib/index.ts b/packages/trpc/lib/index.ts new file mode 100644 index 000000000..9074357e5 --- /dev/null +++ b/packages/trpc/lib/index.ts @@ -0,0 +1,39 @@ +import { initTRPC } from "@trpc/server" +import { ZodError } from "zod" + +import { transformer } from "./transformer" + +import type { Context } from "./context" + +export type Meta = { + authRequired?: boolean +} + +const t = initTRPC + .context() + .meta() + .create({ + transformer, + errorFormatter({ shape, error }) { + return { + ...shape, + data: { + ...shape.data, + cause: + error.cause instanceof ZodError + ? undefined + : JSON.parse(JSON.stringify(error.cause)), + zodError: + error.cause instanceof ZodError ? error.cause.flatten() : null, + }, + } + }, + }) + +export const { + createCallerFactory, + mergeRouters, + router, + procedure, + middleware, +} = t diff --git a/packages/trpc/lib/procedures.ts b/packages/trpc/lib/procedures.ts new file mode 100644 index 000000000..b7b5deef2 --- /dev/null +++ b/packages/trpc/lib/procedures.ts @@ -0,0 +1,164 @@ +import * as Sentry from "@sentry/nextjs" + +import { getServiceToken } from "@scandic-hotels/common/tokenManager" + +import { env } from "../env/server" +import { + badRequestError, + internalServerError, + sessionExpiredError, + unauthorizedError, +} from "./errors" +import { langInput } from "./utils" +import { middleware, procedure } from "." + +const sentryMiddleware = middleware( + Sentry.trpcMiddleware({ + attachRpcInput: true, + }) +) + +export const baseProcedure = procedure.use(sentryMiddleware) + +export const publicProcedure = baseProcedure + +export const languageProcedure = 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: opts.ctx.lang, + }, + }) +}) + +export const contentstackBaseProcedure = languageProcedure + +export const contentstackExtendedProcedureUID = contentstackBaseProcedure.use( + async function (opts) { + if (!opts.ctx.uid) { + throw badRequestError("Missing UID in tRPC context") + } + + return opts.next({ + ctx: { + uid: opts.ctx.uid, + }, + }) + } +) + +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") { + console.info( + `❌❌❌❌ You are opting out of authorization, if its done on purpose maybe you should use the publicProcedure instead. ❌❌❌❌` + ) + console.info(`path: ${opts.path} | type: ${opts.type}`) + } + + if (!session) { + throw unauthorizedError() + } + + if (session?.error === "RefreshAccessTokenError") { + throw sessionExpiredError() + } + + return opts.next({ + ctx: { + session, + }, + }) +}) + +export const safeProtectedProcedure = baseProcedure.use(async function (opts) { + const authRequired = opts.meta?.authRequired ?? true + let session = await opts.ctx.auth() + if (!authRequired && env.NODE_ENV === "development") { + console.info( + `❌❌❌❌ You are opting out of authorization, if its done on purpose maybe you should use the publicProcedure instead. ❌❌❌❌` + ) + console.info(`path: ${opts.path} | type: ${opts.type}`) + } + + if (!session || session.error === "RefreshAccessTokenError") { + session = null + } + + return opts.next({ + ctx: { + session, + }, + }) +}) + +export const serviceProcedure = baseProcedure.use(async (opts) => { + const token = await getServiceToken() + const { access_token } = token + if (!access_token) { + throw internalServerError(`[serviceProcedure] No service token`) + } + return opts.next({ + ctx: { + serviceToken: access_token, + }, + }) +}) + +export const contentStackUidWithServiceProcedure = + contentstackExtendedProcedureUID.concat(serviceProcedure) + +export const contentStackBaseWithServiceProcedure = + contentstackBaseProcedure.concat(serviceProcedure) + +export const contentStackBaseWithProtectedProcedure = + contentstackBaseProcedure.concat(protectedProcedure) + +export const safeProtectedServiceProcedure = + safeProtectedProcedure.concat(serviceProcedure) + +export const languageProtectedProcedure = + protectedProcedure.concat(languageProcedure) + +type ExperimentalProcedureCaller = ReturnType< + typeof baseProcedure.experimental_caller +> +export function getProtectedServerActionProcedure( + serverActionProcedure: ExperimentalProcedureCaller +) { + return serverActionProcedure.use(async (opts) => { + const session = await opts.ctx.auth() + if (!session) { + throw unauthorizedError() + } + + if (session && session.error === "RefreshAccessTokenError") { + throw sessionExpiredError() + } + + return opts.next({ + ctx: { + ...opts.ctx, + session, + }, + }) + }) +} diff --git a/apps/scandic-web/server/transformer.ts b/packages/trpc/lib/transformer.ts similarity index 100% rename from apps/scandic-web/server/transformer.ts rename to packages/trpc/lib/transformer.ts diff --git a/packages/trpc/lib/utils.ts b/packages/trpc/lib/utils.ts new file mode 100644 index 000000000..e042f059b --- /dev/null +++ b/packages/trpc/lib/utils.ts @@ -0,0 +1,7 @@ +import { z } from "zod" + +import { Lang } from "@scandic-hotels/common/constants/language" + +export const langInput = z.object({ + lang: z.nativeEnum(Lang), +}) diff --git a/packages/trpc/lint-staged.config.mjs b/packages/trpc/lint-staged.config.mjs new file mode 100644 index 000000000..e6ae14b2a --- /dev/null +++ b/packages/trpc/lint-staged.config.mjs @@ -0,0 +1,6 @@ +const config = { + "*.{ts,tsx}": [() => "tsc -p tsconfig.json --noEmit", "prettier --write"], + "*.{js,cjs,mjs}": "prettier --write", +} + +export default config diff --git a/packages/trpc/package.json b/packages/trpc/package.json new file mode 100644 index 000000000..1f9e788c6 --- /dev/null +++ b/packages/trpc/package.json @@ -0,0 +1,38 @@ +{ + "name": "@scandic-hotels/trpc", + "version": "1.0.0", + "main": "index.ts", + "type": "module", + "scripts": { + "check-types": "tsc --noEmit", + "lint": "eslint . --max-warnings 0 && tsc --noEmit" + }, + "exports": { + ".": "./lib/index.ts", + "./context": "./lib/context.ts", + "./errors": "./lib/errors.ts", + "./procedures": "./lib/procedures.ts", + "./transformer": "./lib/transformer.ts" + }, + "dependencies": { + "@scandic-hotels/common": "workspace:*", + "@sentry/nextjs": "^8.41.0", + "@t3-oss/env-nextjs": "^0.13.4", + "@trpc/server": "^11.1.2", + "next-auth": "5.0.0-beta.27", + "superjson": "^2.2.2", + "zod": "^3.24.4" + }, + "devDependencies": { + "@eslint/compat": "^1.2.9", + "@eslint/eslintrc": "^3.3.1", + "@eslint/js": "^9.26.0", + "@types/lodash-es": "^4", + "@typescript-eslint/eslint-plugin": "^8.32.0", + "@typescript-eslint/parser": "^8.32.0", + "eslint": "^9", + "eslint-plugin-import": "^2.31.0", + "eslint-plugin-simple-import-sort": "^12.1.1", + "typescript": "5.8.3" + } +} diff --git a/packages/trpc/prettier.config.cjs b/packages/trpc/prettier.config.cjs new file mode 100644 index 000000000..b78e09189 --- /dev/null +++ b/packages/trpc/prettier.config.cjs @@ -0,0 +1,8 @@ +module.exports = { + semi: false, + trailingComma: "es5", + singleQuote: false, + printWidth: 80, + tabWidth: 2, + endOfLine: "lf", +}; diff --git a/packages/trpc/tsconfig.json b/packages/trpc/tsconfig.json new file mode 100644 index 000000000..1b8d2c58c --- /dev/null +++ b/packages/trpc/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "@scandic-hotels/typescript-config/base.json", + "compilerOptions": { + "paths": { + "@/*": ["./*"] + } + }, + "include": ["**/*.ts"], + "exclude": ["**/node_modules/**"] +} diff --git a/yarn.lock b/yarn.lock index 85b8ef148..90fdb98de 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6957,12 +6957,16 @@ __metadata: "@scandic-hotels/typescript-config": "workspace:*" "@sentry/nextjs": "npm:^8.41.0" "@t3-oss/env-nextjs": "npm:^0.13.4" + "@types/lodash-es": "npm:^4" "@typescript-eslint/eslint-plugin": "npm:^8.32.0" "@typescript-eslint/parser": "npm:^8.32.0" + deepmerge: "npm:^4.3.1" dotenv: "npm:^16.5.0" eslint: "npm:^9" eslint-plugin-import: "npm:^2.31.0" eslint-plugin-simple-import-sort: "npm:^12.1.1" + flat: "npm:^6.0.1" + lodash-es: "npm:^4.17.21" typescript: "npm:5.8.3" vitest: "npm:^3.2.3" zod: "npm:^3.24.4" @@ -7177,7 +7181,6 @@ __metadata: sonner: "npm:^2.0.3" start-server-and-test: "npm:^2.0.11" supercluster: "npm:^8.0.1" - superjson: "npm:^2.2.2" ts-jest: "npm:^29.3.2" ts-morph: "npm:^25.0.1" ts-node: "npm:^10.9.2" @@ -7190,6 +7193,30 @@ __metadata: languageName: unknown linkType: soft +"@scandic-hotels/trpc@workspace:packages/trpc": + version: 0.0.0-use.local + resolution: "@scandic-hotels/trpc@workspace:packages/trpc" + dependencies: + "@eslint/compat": "npm:^1.2.9" + "@eslint/eslintrc": "npm:^3.3.1" + "@eslint/js": "npm:^9.26.0" + "@scandic-hotels/common": "workspace:*" + "@sentry/nextjs": "npm:^8.41.0" + "@t3-oss/env-nextjs": "npm:^0.13.4" + "@trpc/server": "npm:^11.1.2" + "@types/lodash-es": "npm:^4" + "@typescript-eslint/eslint-plugin": "npm:^8.32.0" + "@typescript-eslint/parser": "npm:^8.32.0" + eslint: "npm:^9" + eslint-plugin-import: "npm:^2.31.0" + eslint-plugin-simple-import-sort: "npm:^12.1.1" + next-auth: "npm:5.0.0-beta.27" + superjson: "npm:^2.2.2" + typescript: "npm:5.8.3" + zod: "npm:^3.24.4" + languageName: unknown + linkType: soft + "@scandic-hotels/typescript-config@workspace:*, @scandic-hotels/typescript-config@workspace:packages/typescript-config": version: 0.0.0-use.local resolution: "@scandic-hotels/typescript-config@workspace:packages/typescript-config"