@se-studio/core-data-types
v2.0.1
Published
Core TypeScript type definitions for SE Studio content models
Maintainers
Readme
@se-studio/core-data-types
Core TypeScript type definitions for SE Studio content models and shared types across the monorepo.
Installation
# pnpm
pnpm add @se-studio/core-data-types
# npm
npm install @se-studio/core-data-types
# yarn
yarn add @se-studio/core-data-typesUsage
import type { IPage, ISeoMetadata, IAsset, DeepPartial } from '@se-studio/core-data-types';
// Use the page interface
const page: IPage = {
id: 'page-123',
slug: 'about-us',
title: 'About Us',
seo: {
title: 'About Us - SE Studio',
description: 'Learn more about SE Studio',
},
};
// Use utility types
type PartialPage = DeepPartial<IPage>;API Reference
Content Model Types
Pages
IBasePage- Base interface for page content models- Extends
IBaseModelwith page-specific properties type: 'Page'- Content type discriminatorisHomePage: boolean- Whether this is the home pagecontents?: ReadonlyArray<ITyped>- Page content sectionstags?: ReadonlyArray<IInternalLink>- Tags associated with the pagestructuredData?: ReadonlyArray<unknown>- Optional structured data
- Extends
PageLink- Page link type (metadata without full content)
Articles
IBaseArticle- Base interface for article content modelstype: 'Article'- Content type discriminatorarticleType?: IInternalLink- Link to the article typecontents?: ReadonlyArray<ITyped>- Article content sectionstags?: ReadonlyArray<IInternalLink>- Tags associated with the articledownload?: IDownloadAsset- Optional downloadable asset (e.g. PDF)
IBaseArticleType- Base interface for article type content modelstype: 'Article type'- Content type discriminatorindexPageContent?: ReadonlyArray<ITyped>- Content for index pagesearchPageContent?: ReadonlyArray<ITyped>- Content for search page
Components & Collections
IBaseComponent- Base interface for component content models (project addscomponentType)IBaseCollection- Base interface for collection content models (project addscollectionType)IBaseExternalComponent- Base interface for external component models (project addsexternalComponentType)- Contentful field name is
externalComponentType, notexternalType— the latter is never set at runtime
- Contentful field name is
IBaseHtmlComponent- Raw HTML/CSS/JS component entries (type: 'HtmlComponent')
Utilities
orderContentWithHtmlHeroFirst(contents)- Stable sort soHtmlComponentitems withisHero: truerender (and export to markdown) before siblings in the same array.
Article authors
Articles support an ordered authors array (first = primary). During CMS migration, legacy single author is still populated as authors[0].
getArticleAuthors(article)- All authors in display order (deduped by id)getPrimaryArticleAuthor(article)- First author, if anyformatArticleAuthorNames(article)- Comma-separated byline for search and markdownnormalizeResolvedArticleAuthors(authorsFromCms, legacyAuthorFromCms)- Used by Contentful converters: non-emptyauthorswins, else legacyauthor
Prefer these helpers over reading article.author directly in app or package code.
Visual/Asset Types
IVisual- Union type for visual content (Image | Video | Animation)IImage- Image types (Picture | SvgImage | SvgData)IPicture- Raster image (type: 'Picture'); optionalblurDataURLfor Next.js blur placeholders (set at conversion time)IVideo- Video content typeIAnimation- Animation/Lottie content typeIResponsiveVisual- Responsive visual with breakpoint configuration
Link Types
ILinkProps- Base link properties (includes optionalaccessibilityLabelfor screen readers)IInternalLink- Internal link to CMS contentIArticleLink- Article link (extendsIInternalLink)internalType: 'Article'articleType?: IArticleTypeLink- The article's type (e.g. blog, case study)primaryTag?: ITagLink- First tag on the article- Tag / tag type
show?: boolean- Visual display on cards and detail pages only (falsehides; unset = visible). Distinct fromhiddenandindexedonIInternalLink date?: string- Publication dateauthors?: ReadonlyArray<IPersonLink>- Ordered authors (first = primary)author?: IPersonLink- Primary author (authors[0]); legacy CMS field during transitionexternalLink?: string | null- Supplementary external URL (e.g. DOI or publisher link). OnIArticleLink,hrefis the internal detail URL when the article has article-level body content (topContent,content, orbottomContenton the article entry; article-typearticlePageTopContentdoes not count); external-only articles useexternalLinkashref.download?: IDownloadAsset- Optional downloadable assetsubtitle?: string- Article subtitle (e.g. customer name for case studies)visuals?: ReadonlyArray<IVisual>- Additional visuals beyond the featured image; used for article browser / gallery views
IListCard- Slim list-row DTO (id,href,title, optionalsubtitle,date,primaryTag,colours, featuredvisual,icon). Not a replacement forIArticleLink(detail / sitemap / markdown). Map witharticleLinkToListCardfrom@se-studio/core-ui/server.visual/iconare for RSC cards, not client island props; do not passIArticleLink[]into client islands.IExternalLink- External linkIDownloadLink- Download linkIBlankLink- Blank link (no href)
Context Types
IPageContext- Page context with links to related contentIContentContext- Content context for component renderingIAnalyticsContext- Analytics context for tracking. Optionaldnt?: boolean: when true, YouTube/Vimeo embeds use privacy options (nocookie domain, dnt=1).
Type Guard Functions
isPage(content)- Check if content is a pageisArticle(content)- Check if content is an articleisArticleType(content)- Check if content is an article typeisComponent(content)- Check if content is a componentisCollection(content)- Check if content is a collectionisHtmlComponent(content)- Check if content is an HTML component entryisInternalLink(link)- Check if link is internalisExternalLink(link)- Check if link is externalisDownloadLink(link)- Check if link is a download linkisImage(visual)- Check if visual is an imageisVideo(visual)- Check if visual is a videoisAnimation(visual)- Check if visual is an animation
Utility Types
DeepPartial<T>- Makes all nested properties optional (recursive)Prettify<T>- Improves type readability in IDE tooltips
For detailed JSDoc documentation on all types and functions, see the TypeScript declaration files (.d.ts) in the package.
Development
This package is part of the SE Studio monorepo. To work on this package:
# Install dependencies
pnpm install
# Build the package
pnpm build
# Run tests
pnpm test
# Type check
pnpm type-check
# Run linting
pnpm lintExtending Types
These types serve as a foundation and should be extended based on your actual Contentful content model:
import type { IPage } from '@se-studio/core-data-types';
// Extend the base page type with your custom fields
interface ICustomPage extends IPage {
hero: {
title: string;
image: IAsset;
};
content: RichTextContent;
}Future Additions
This package currently contains placeholder types. As the content model evolves, additional types will be added for:
- Component types (Hero, CTA, etc.)
- Rich text content structures
- Navigation structures
- Blog/Article types
- And more...
License
MIT
