diff --git a/server/routers/contentstack/contentPage/output.ts b/server/routers/contentstack/contentPage/output.ts index bc5ec0c2e..b6b920a78 100644 --- a/server/routers/contentstack/contentPage/output.ts +++ b/server/routers/contentstack/contentPage/output.ts @@ -19,8 +19,8 @@ import { RTEEmbedsEnum } from "@/types/requests/rte" import { EdgesWithTotalCount } from "@/types/requests/utils/edges" import { RTEDocument } from "@/types/rte/node" -// Block Schema and types -const contentPageBlockTextContent = z.object({ +// Block schemas +export const contentPageBlockTextContent = z.object({ __typename: z.literal(ContentBlocksTypenameEnum.ContentPageBlocksContent), content: z.object({ content: z.object({ @@ -33,7 +33,7 @@ const contentPageBlockTextContent = z.object({ }), }) -const contentPageShortcuts = z.object({ +export const contentPageShortcuts = z.object({ __typename: z.literal(ContentBlocksTypenameEnum.ContentPageBlocksShortcuts), shortcuts: z.object({ title: z.string().nullable(), @@ -49,7 +49,7 @@ const contentPageShortcuts = z.object({ }), }) -const contentPageDynamicContent = z.object({ +export const contentPageDynamicContent = z.object({ __typename: z.literal( ContentBlocksTypenameEnum.ContentPageBlocksDynamicContent ), @@ -66,7 +66,7 @@ const contentPageDynamicContent = z.object({ }), }) -const cardBlock = z.object({ +export const cardBlock = z.object({ __typename: z.literal(CardsGridEnum.Card), heading: z.string().nullable(), body_text: z.string().nullable(), @@ -94,7 +94,7 @@ const cardBlock = z.object({ }), }) -const loyaltyCardBlock = z.object({ +export const loyaltyCardBlock = z.object({ __typename: z.literal(CardsGridEnum.LoyaltyCard), heading: z.string().nullable(), body_text: z.string().nullable(), @@ -118,7 +118,7 @@ const contentPageCardsItems = z.discriminatedUnion("__typename", [ cardBlock, ]) -const contentPageCards = z.object({ +export const contentPageCards = z.object({ __typename: z.literal(ContentBlocksTypenameEnum.ContentPageBlocksCardsGrid), cards_grid: z.object({ title: z.string().nullable(), @@ -136,7 +136,7 @@ const contentPageBlockItem = z.discriminatedUnion("__typename", [ contentPageShortcuts, ]) -const contentPageSidebarTextContent = z.object({ +export const contentPageSidebarTextContent = z.object({ __typename: z.literal(SidebarTypenameEnum.ContentPageSidebarContent), content: z.object({ content: z.object({ @@ -149,7 +149,7 @@ const contentPageSidebarTextContent = z.object({ }), }) -const contentPageJoinLoyaltyContact = z.object({ +export const contentPageJoinLoyaltyContact = z.object({ __typename: z.literal( SidebarTypenameEnum.ContentPageSidebarJoinLoyaltyContact ), @@ -179,7 +179,7 @@ const contentPageJoinLoyaltyContact = z.object({ }), }) -const contentPageSidebarDynamicContent = z.object({ +export const contentPageSidebarDynamicContent = z.object({ __typename: z.literal(SidebarTypenameEnum.ContentPageSidebarDynamicContent), dynamic_content: z.object({ component: z.nativeEnum(SidebarDynamicComponentEnum), @@ -192,55 +192,6 @@ const contentPageSidebarItem = z.discriminatedUnion("__typename", [ contentPageJoinLoyaltyContact, ]) -export type DynamicContent = z.infer - -type BlockContentRaw = z.infer -export interface RteBlockContent extends BlockContentRaw { - content: { - content: { - json: RTEDocument - embedded_itemsConnection: EdgesWithTotalCount - } - } -} - -export type Shortcuts = z.infer - -type LoyaltyCardRaw = z.infer -type LoyaltyCard = Omit & { - image?: ImageVaultAsset -} -type CardRaw = z.infer -type Card = Omit & { - backgroundImage?: ImageVaultAsset -} -type CardsGridRaw = z.infer -export type CardsGrid = Omit & { - cards: (LoyaltyCard | Card)[] -} -export type CardsRaw = CardsGrid["cards_grid"]["cards"][number] - -export type Block = RteBlockContent | Shortcuts | CardsGrid | DynamicContent - -type SidebarContentRaw = z.infer - -export type RteSidebarContent = Omit & { - content: { - content: { - json: RTEDocument - embedded_itemsConnection: EdgesWithTotalCount - } - } -} - -type SideBarDynamicContent = z.infer - -export type JoinLoyaltyContact = z.infer -export type Sidebar = - | JoinLoyaltyContact - | RteSidebarContent - | SideBarDynamicContent - // Content Page Schema and types export const validateContentPageSchema = z.object({ content_page: z.object({ @@ -261,18 +212,6 @@ export const validateContentPageSchema = z.object({ }), }) -export type ContentPageDataRaw = z.infer -type ContentPageRaw = ContentPageDataRaw["content_page"] - -export type ContentPage = Omit< - ContentPageRaw, - "blocks" | "hero_image" | "sidebar" -> & { - heroImage?: ImageVaultAsset - blocks: Block[] - sidebar: Sidebar[] -} - const pageConnectionRefs = z.object({ edges: z.array( z.object({ @@ -425,7 +364,3 @@ export const validateContentPageRefsSchema = z.object({ }), }), }) - -export type ContentPageRefsDataRaw = z.infer< - typeof validateContentPageRefsSchema -> diff --git a/server/routers/contentstack/contentPage/query.ts b/server/routers/contentstack/contentPage/query.ts index 12de1a965..c37adbd68 100644 --- a/server/routers/contentstack/contentPage/query.ts +++ b/server/routers/contentstack/contentPage/query.ts @@ -8,13 +8,7 @@ import { makeImageVaultImage } from "@/utils/imageVault" import { removeMultipleSlashes } from "@/utils/url" import { removeEmptyObjects } from "../../utils" -import { - Block, - ContentPage, - ContentPageDataRaw, - Sidebar, - validateContentPageSchema, -} from "./output" +import { validateContentPageSchema } from "./output" import { fetchContentPageRefs, generatePageTags, @@ -32,6 +26,12 @@ import { TrackingChannelEnum, TrackingSDKPageData, } from "@/types/components/tracking" +import { + Block, + ContentPage, + ContentPageDataRaw, + Sidebar, +} from "@/types/trpc/routers/contentstack/contentPage" export const contentPageQueryRouter = router({ get: contentstackExtendedProcedureUID.query(async ({ ctx }) => { diff --git a/server/routers/contentstack/contentPage/utils.ts b/server/routers/contentstack/contentPage/utils.ts index 3f2689fc0..f5068735b 100644 --- a/server/routers/contentstack/contentPage/utils.ts +++ b/server/routers/contentstack/contentPage/utils.ts @@ -9,11 +9,12 @@ import { generateTag, generateTags } from "@/utils/generateTag" import { removeMultipleSlashes } from "@/utils/url" import { removeEmptyObjects } from "../../utils" -import { ContentPageRefsDataRaw, validateContentPageRefsSchema } from "./output" +import { validateContentPageRefsSchema } from "./output" import { ContentBlocksTypenameEnum } from "@/types/components/content/enums" import { Edges } from "@/types/requests/utils/edges" import { NodeRefs } from "@/types/requests/utils/refs" +import { ContentPageRefsDataRaw } from "@/types/trpc/routers/contentstack/contentPage" const meter = metrics.getMeter("trpc.contentPage") // OpenTelemetry metrics: ContentPage diff --git a/types/components/content/blocks.ts b/types/components/content/blocks.ts index 720490a2a..a97ac9780 100644 --- a/types/components/content/blocks.ts +++ b/types/components/content/blocks.ts @@ -1,12 +1,13 @@ import { Lang } from "@/constants/languages" import { membershipLevels } from "@/constants/membershipLevels" + +import type { IntlFormatters } from "@formatjs/intl" + import { Block, CardsGrid, DynamicContent, -} from "@/server/routers/contentstack/contentPage/output" - -import type { IntlFormatters } from "@formatjs/intl" +} from "@/types/trpc/routers/contentstack/contentPage" export type BlocksProps = { blocks: Block[] diff --git a/types/components/content/enums.ts b/types/components/content/enums.ts index b69a067d5..3bc20ac48 100644 --- a/types/components/content/enums.ts +++ b/types/components/content/enums.ts @@ -1,6 +1,5 @@ -import { JoinLoyaltyContact } from "@/server/routers/contentstack/contentPage/output" - import { Typename } from "@/types/requests/utils/typename" +import { JoinLoyaltyContact } from "@/types/trpc/routers/contentstack/contentPage" export enum ContentBlocksTypenameEnum { ContentPageBlocksContent = "ContentPageBlocksContent", diff --git a/types/components/content/sidebar.ts b/types/components/content/sidebar.ts index 843a16132..6b740a386 100644 --- a/types/components/content/sidebar.ts +++ b/types/components/content/sidebar.ts @@ -1,8 +1,9 @@ import { ContactFields } from "@/server/routers/contentstack/base/output" + import { JoinLoyaltyContact, Sidebar, -} from "@/server/routers/contentstack/contentPage/output" +} from "@/types/trpc/routers/contentstack/contentPage" export type SidebarProps = { blocks: Sidebar[] diff --git a/types/trpc/routers/contentstack/contentPage.ts b/types/trpc/routers/contentstack/contentPage.ts index 49d55e3fa..4c3f27ce6 100644 --- a/types/trpc/routers/contentstack/contentPage.ts +++ b/types/trpc/routers/contentstack/contentPage.ts @@ -1,17 +1,84 @@ import { z } from "zod" import { - Block, + cardBlock, + contentPageBlockTextContent, + contentPageCards, + contentPageDynamicContent, + contentPageJoinLoyaltyContact, + contentPageShortcuts, + contentPageSidebarDynamicContent, + contentPageSidebarTextContent, + loyaltyCardBlock, + validateContentPageRefsSchema, validateContentPageSchema, } from "@/server/routers/contentstack/contentPage/output" import { ImageVaultAsset } from "@/types/components/imageVault" +import { Embeds } from "@/types/requests/embeds" +import { EdgesWithTotalCount } from "@/types/requests/utils/edges" +import { RTEDocument } from "@/types/rte/node" export type ContentPageDataRaw = z.infer type ContentPageRaw = ContentPageDataRaw["content_page"] -export type ContentPage = Omit & { +export type ContentPage = Omit< + ContentPageRaw, + "blocks" | "hero_image" | "sidebar" +> & { heroImage?: ImageVaultAsset - blocks?: Block[] + blocks: Block[] + sidebar: Sidebar[] } + +export type ContentPageRefsDataRaw = z.infer< + typeof validateContentPageRefsSchema +> + +type SidebarContentRaw = z.infer +type SideBarDynamicContent = z.infer +export type JoinLoyaltyContact = z.infer +export type RteSidebarContent = Omit & { + content: { + content: { + json: RTEDocument + embedded_itemsConnection: EdgesWithTotalCount + } + } +} + +export type Sidebar = + | JoinLoyaltyContact + | RteSidebarContent + | SideBarDynamicContent + +export type DynamicContent = z.infer + +type BlockContentRaw = z.infer +export interface RteBlockContent extends BlockContentRaw { + content: { + content: { + json: RTEDocument + embedded_itemsConnection: EdgesWithTotalCount + } + } +} + +export type Shortcuts = z.infer + +type LoyaltyCardRaw = z.infer +type LoyaltyCard = Omit & { + image?: ImageVaultAsset +} +type CardRaw = z.infer +type Card = Omit & { + backgroundImage?: ImageVaultAsset +} +type CardsGridRaw = z.infer +export type CardsGrid = Omit & { + cards: (LoyaltyCard | Card)[] +} +export type CardsRaw = CardsGrid["cards_grid"]["cards"][number] + +export type Block = RteBlockContent | Shortcuts | CardsGrid | DynamicContent