Merged in monorepo-step-1 (pull request #1080)

Migrate to a monorepo setup - step 1

* Move web to subfolder /apps/scandic-web

* Yarn + transitive deps

- Move to yarn
- design-system package removed for now since yarn doesn't
support the parameter for token (ie project currently broken)
- Add missing transitive dependencies as Yarn otherwise
prevents these imports
- VS Code doesn't pick up TS path aliases unless you open
/apps/scandic-web instead of root (will be fixed with monorepo)

* Pin framer-motion to temporarily fix typing issue

https://github.com/adobe/react-spectrum/issues/7494

* Pin zod to avoid typ error

There seems to have been a breaking change in the types
returned by zod where error is now returned as undefined
instead of missing in the type. We should just handle this
but to avoid merge conflicts just pin the dependency for
now.

* Pin react-intl version

Pin version of react-intl to avoid tiny type issue where formatMessage
does not accept a generic any more. This will be fixed in a future
commit, but to avoid merge conflicts just pin for now.

* Pin typescript version

Temporarily pin version as newer versions as stricter and results in
a type error. Will be fixed in future commit after merge.

* Setup workspaces

* Add design-system as a monorepo package

* Remove unused env var DESIGN_SYSTEM_ACCESS_TOKEN

* Fix husky for monorepo setup

* Update netlify.toml

* Add lint script to root package.json

* Add stub readme

* Fix react-intl formatMessage types

* Test netlify.toml in root

* Remove root toml

* Update netlify.toml publish path

* Remove package-lock.json

* Update build for branch/preview builds


Approved-by: Linus Flood
This commit is contained in:
Anton Gunnarsson
2025-02-26 10:36:17 +00:00
committed by Linus Flood
parent 667cab6fb6
commit 80100e7631
2731 changed files with 30986 additions and 23708 deletions

View File

@@ -0,0 +1,5 @@
import { mergeRouters } from "@/server/trpc"
import { startPageQueryRouter } from "./query"
export const startPageRouter = mergeRouters(startPageQueryRouter)

View File

@@ -0,0 +1,116 @@
import { z } from "zod"
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
import {
cardGridRefsSchema,
cardsGridSchema,
} from "../schemas/blocks/cardsGrid"
import {
carouselCardsRefsSchema,
carouselCardsSchema,
} from "../schemas/blocks/carouselCards"
import {
fullWidthCampaignBlockRefsSchema,
fullWidthCampaignBlockSchema,
} from "../schemas/blocks/fullWidthCampaign"
import {
joinScandicFriendsBlockRefsSchema,
joinScandicFriendsBlockSchema,
} from "../schemas/blocks/joinScandicFriends"
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
import { systemSchema } from "../schemas/system"
import { StartPageEnum } from "@/types/enums/startPage"
const startPageCards = z
.object({
__typename: z.literal(StartPageEnum.ContentStack.blocks.CardsGrid),
})
.merge(cardsGridSchema)
const startPageCarouselCards = z
.object({
__typename: z.literal(StartPageEnum.ContentStack.blocks.CarouselCards),
})
.merge(carouselCardsSchema)
const startPageFullWidthCampaign = z
.object({
__typename: z.literal(StartPageEnum.ContentStack.blocks.FullWidthCampaign),
})
.merge(fullWidthCampaignBlockSchema)
const startPageJoinScandicFriends = z
.object({
__typename: z.literal(StartPageEnum.ContentStack.blocks.JoinScandicFriends),
})
.merge(joinScandicFriendsBlockSchema)
export const blocksSchema = z.discriminatedUnion("__typename", [
startPageCards,
startPageFullWidthCampaign,
startPageCarouselCards,
startPageJoinScandicFriends,
])
export const startPageSchema = z.object({
start_page: z.object({
title: z.string(),
header: z.object({
heading: z.string(),
hero_image: tempImageVaultAssetSchema,
}),
blocks: discriminatedUnionArray(blocksSchema.options)
.nullable()
.transform((val) => val || []),
system: systemSchema.merge(
z.object({
created_at: z.string(),
updated_at: z.string(),
})
),
}),
trackingProps: z.object({
url: z.string(),
}),
})
/** REFS */
const startPageCardsRefs = z
.object({
__typename: z.literal(StartPageEnum.ContentStack.blocks.CardsGrid),
})
.merge(cardGridRefsSchema)
const startPageFullWidthCampaignRef = z
.object({
__typename: z.literal(StartPageEnum.ContentStack.blocks.FullWidthCampaign),
})
.merge(fullWidthCampaignBlockRefsSchema)
const startPageCarouselCardsRef = z
.object({
__typename: z.literal(StartPageEnum.ContentStack.blocks.CarouselCards),
})
.merge(carouselCardsRefsSchema)
const startPageJoinScandicFriendsRef = z
.object({
__typename: z.literal(StartPageEnum.ContentStack.blocks.JoinScandicFriends),
})
.merge(joinScandicFriendsBlockRefsSchema)
const startPageBlockRefsItem = z.discriminatedUnion("__typename", [
startPageCardsRefs,
startPageFullWidthCampaignRef,
startPageCarouselCardsRef,
startPageJoinScandicFriendsRef,
])
export const startPageRefsSchema = z.object({
start_page: z.object({
blocks: discriminatedUnionArray(startPageBlockRefsItem.options).nullable(),
system: systemSchema,
}),
})

View File

@@ -0,0 +1,191 @@
import {
GetStartPage,
GetStartPageRefs,
} from "@/lib/graphql/Query/StartPage/StartPage.graphql"
import { request } from "@/lib/graphql/request"
import { notFound } from "@/server/errors/trpc"
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
import { generateTag, generateTagsFromSystem } from "@/utils/generateTag"
import { startPageRefsSchema, startPageSchema } from "./output"
import {
getStartPageCounter,
getStartPageFailCounter,
getStartPageRefsCounter,
getStartPageRefsFailCounter,
getStartPageRefsSuccessCounter,
getStartPageSuccessCounter,
} from "./telemetry"
import { getConnections } from "./utils"
import {
TrackingChannelEnum,
type TrackingSDKPageData,
} from "@/types/components/tracking"
import type {
GetStartPageData,
GetStartPageRefsSchema,
} from "@/types/trpc/routers/contentstack/startPage"
export const startPageQueryRouter = router({
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
const { lang, uid } = ctx
getStartPageRefsCounter.add(1, { lang, uid: `${uid}` })
console.info(
"contentstack.startPage.refs start",
JSON.stringify({
query: { lang, uid },
})
)
const refsResponse = await request<GetStartPageRefsSchema>(
GetStartPageRefs,
{
locale: lang,
uid,
},
{
cache: "force-cache",
next: {
tags: [generateTag(lang, uid)],
},
}
)
if (!refsResponse.data) {
const notFoundError = notFound(refsResponse)
getStartPageRefsFailCounter.add(1, {
lang,
uid,
error_type: "not_found",
error: JSON.stringify({ code: notFoundError.code }),
})
console.error(
"contentstack.startPage.refs not found error",
JSON.stringify({
query: { lang, uid },
error: { code: notFoundError.code },
})
)
throw notFoundError
}
const validatedRefsData = startPageRefsSchema.safeParse(refsResponse.data)
if (!validatedRefsData.success) {
getStartPageRefsFailCounter.add(1, {
lang,
uid,
error_type: "validation_error",
error: JSON.stringify(validatedRefsData.error),
})
console.error(
"contentstack.startPage.refs validation error",
JSON.stringify({
query: { lang, uid },
error: validatedRefsData.error,
})
)
return null
}
getStartPageRefsSuccessCounter.add(1, { lang, uid: `${uid}` })
console.info(
"contentstack.startPage.refs success",
JSON.stringify({
query: { lang, uid },
})
)
getStartPageCounter.add(1, { lang, uid: `${uid}` })
console.info(
"contentstack.startPage start",
JSON.stringify({
query: { lang, uid },
})
)
const connections = getConnections(validatedRefsData.data)
const tags = [
generateTagsFromSystem(lang, connections),
generateTag(lang, validatedRefsData.data.start_page.system.uid),
].flat()
const response = await request<GetStartPageData>(
GetStartPage,
{
locale: lang,
uid,
},
{
cache: "force-cache",
next: {
tags,
},
}
)
if (!response.data) {
const notFoundError = notFound(response)
getStartPageFailCounter.add(1, {
lang,
uid: `${uid}`,
error_type: "not_found",
error: JSON.stringify({ code: notFoundError.code }),
})
console.error(
"contentstack.startPage not found error",
JSON.stringify({
query: { lang, uid },
error: { code: notFoundError.code },
})
)
throw notFoundError
}
const startPage = startPageSchema.safeParse(response.data)
if (!startPage.success) {
getStartPageFailCounter.add(1, {
lang,
uid: `${uid}`,
error_type: "validation_error",
error: JSON.stringify(startPage.error),
})
console.error(
"contentstack.startPage validation error",
JSON.stringify({
query: { lang, uid },
error: startPage.error,
})
)
return null
}
getStartPageSuccessCounter.add(1, { lang, uid: `${uid}` })
console.info(
"contentstack.startPage success",
JSON.stringify({
query: { lang, uid },
})
)
const system = startPage.data.start_page.system
const tracking: TrackingSDKPageData = {
pageId: system.uid,
domainLanguage: lang,
publishDate: system.updated_at,
createDate: system.created_at,
channel: TrackingChannelEnum["start-page"],
pageType: "start-page",
pageName: startPage.data.trackingProps.url,
siteSections: startPage.data.trackingProps.url,
siteVersion: "new-web",
}
return {
startPage: startPage.data.start_page,
tracking,
}
}),
})

View File

@@ -0,0 +1,23 @@
import { metrics } from "@opentelemetry/api"
const meter = metrics.getMeter("trpc.contentstack.startPage")
export const getStartPageRefsCounter = meter.createCounter(
"trpc.contentstack.startPage.get"
)
export const getStartPageRefsFailCounter = meter.createCounter(
"trpc.contentstack.startPage.get-fail"
)
export const getStartPageRefsSuccessCounter = meter.createCounter(
"trpc.contentstack.startPage.get-success"
)
export const getStartPageCounter = meter.createCounter(
"trpc.contentstack.startPage.get"
)
export const getStartPageSuccessCounter = meter.createCounter(
"trpc.contentstack.startPage.get-success"
)
export const getStartPageFailCounter = meter.createCounter(
"trpc.contentstack.startPage.get-fail"
)

View File

@@ -0,0 +1,24 @@
import { StartPageEnum } from "@/types/enums/startPage"
import type { System } from "@/types/requests/system"
import type { StartPageRefs } from "@/types/trpc/routers/contentstack/startPage"
export function getConnections({ start_page }: StartPageRefs) {
const connections: System["system"][] = [start_page.system]
if (start_page.blocks) {
start_page.blocks.forEach((block) => {
switch (block.__typename) {
case StartPageEnum.ContentStack.blocks.FullWidthCampaign: {
block.full_width_campaign.full_width_campaignConnection.edges.forEach(
({ node }) => {
connections.push(node.system)
}
)
break
}
}
})
}
return connections
}