Merged in feat/sw-2872-dependency-inject-app-context-in-trpc-package (pull request #2478)

feat(SW-2872) Dependency inject app context in trpc package

* Move appRouter to trpc package

* WIP Move serverClient to trpc package

Doesn't handle errors yet

* Don't use global

* Use trpc everywhere


Approved-by: Linus Flood
This commit is contained in:
Anton Gunnarsson
2025-07-01 08:49:33 +00:00
parent a3702d0ecc
commit 6eeaa1cd40
19 changed files with 194 additions and 100 deletions

View File

@@ -1,15 +1,26 @@
import { Temp } from "@scandic-hotels/booking-flow/test-entry"
import { Lang } from "@scandic-hotels/common/constants/language"
import { Typography } from "@scandic-hotels/design-system/Typography"
import { serverClient } from "@/lib/trpc"
import styles from "./page.module.css"
export default function Home() {
export default async function Home() {
const caller = await serverClient()
const destinations = await caller.autocomplete.destinations({
lang: Lang.en,
includeTypes: ["hotels"],
query: "Göteborg",
})
const hotel = destinations.hits.hotels[0].name
return (
<div className={styles.page}>
<main>
<Typography variant="Title/Decorative/lg">
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
<p>hello world</p>
<p>hello world with data: {hotel}</p>
</Typography>
<Typography>
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}

4
apps/partner-sas/global.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
import "@scandic-hotels/common/global.d.ts"
import "@scandic-hotels/trpc/types.d.ts"
import "@scandic-hotels/trpc/auth.d.ts"
import "@scandic-hotels/trpc/jwt.d.ts"

View File

@@ -0,0 +1,34 @@
import { headers } from "next/headers"
import { createContext } from "@scandic-hotels/trpc/context"
import {
appServerClient,
configureServerClient,
} from "@scandic-hotels/trpc/serverClient"
import type { Lang } from "@scandic-hotels/common/constants/language"
export async function createAppContext() {
const headersList = await headers()
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")!,
contentType: headersList.get("x-contenttype")!,
auth: async () => {
return null
},
})
return ctx
}
configureServerClient(createAppContext)
export async function serverClient() {
const ctx = await createAppContext()
return appServerClient(ctx)
}

View File

@@ -1,3 +1,5 @@
import * as Sentry from "@sentry/nextjs"
import type { NextConfig } from "next"
const nextConfig: NextConfig = {
@@ -27,4 +29,23 @@ const nextConfig: NextConfig = {
},
}
export default nextConfig
export default Sentry.withSentryConfig(nextConfig, {
org: "scandic-hotels",
project: "partner-sas",
authToken: process.env.SENTRY_AUTH_TOKEN,
// Only print logs for uploading source maps in CI
silent: !process.env.CI,
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Automatically annotate React components to show their full name in breadcrumbs and session replay
reactComponentAnnotation: {
enabled: true,
},
hideSourceMaps: true,
disableLogger: true,
})

View File

@@ -18,6 +18,7 @@
"@netlify/plugin-nextjs": "^5.11.2",
"@scandic-hotels/booking-flow": "workspace:*",
"@scandic-hotels/design-system": "workspace:*",
"@sentry/nextjs": "^8.41.0",
"next": "15.3.4",
"react": "^19.0.0",
"react-dom": "^19.0.0"