@ai-growth/nextjs
Version:
Seamlessly integrate Sanity CMS with Next.js applications for automated blog routing and rendering
421 lines • 12.2 kB
TypeScript
import { ReactNode, ComponentType } from 'react';
import * as React from 'react';
export interface CMSConfig {
projectId: string;
dataset: string;
apiToken?: string;
apiVersion?: string;
routePath?: string;
}
export interface CMSPageContent {
_id: string;
title: string;
slug: string;
content: any;
publishedAt?: string;
author?: {
name: string;
image?: string;
};
mainImage?: {
asset: {
_ref: string;
};
alt?: string;
};
}
export interface CMSRouterProps {
config: CMSConfig;
children?: ReactNode;
customTemplate?: ComponentType<{
content: CMSPageContent;
}>;
}
export interface RoutePattern {
/** Regular expression pattern for matching routes */
pattern: string;
/** Content type to fetch for this pattern */
contentType: string;
/** Optional template override for this pattern */
template?: string;
/** Priority order for pattern matching (higher = higher priority) */
priority?: number;
/** Whether this pattern is enabled */
enabled?: boolean;
/** Parameter extraction configuration for dynamic segments */
parameterConfig?: RouteParameterConfig;
/** Query parameter filtering configuration */
queryConfig?: QueryParameterConfig;
/** Whether this pattern supports nested content structures */
supportsNesting?: boolean;
/** Custom content projection for this pattern */
projection?: string;
}
/**
* Configuration for extracting parameters from route patterns
*/
export interface RouteParameterConfig {
/** Parameter names in order they appear in the pattern */
paramNames?: string[];
/** Parameter validation rules */
validation?: Record<string, RouteParameterValidation>;
/** Parameter transformation rules */
transform?: Record<string, RouteParameterTransform>;
/** Nested parameter structure for hierarchical content */
nested?: NestedParameterConfig;
}
/**
* Validation rules for route parameters
*/
export interface RouteParameterValidation {
/** Parameter type validation */
type?: 'string' | 'number' | 'slug' | 'category';
/** Minimum length for string parameters */
minLength?: number;
/** Maximum length for string parameters */
maxLength?: number;
/** Regular expression pattern for validation */
pattern?: string;
/** Whether the parameter is required */
required?: boolean;
/** Allowed values for enumeration parameters */
allowedValues?: string[];
}
/**
* Transformation rules for route parameters
*/
export interface RouteParameterTransform {
/** Transform to lowercase */
toLowerCase?: boolean;
/** Transform to uppercase */
toUpperCase?: boolean;
/** Replace characters using regex */
replace?: {
pattern: string;
replacement: string;
};
/** Custom transformation function name */
customTransform?: string;
}
/**
* Configuration for nested parameter structures
*/
export interface NestedParameterConfig {
/** Separator for nested segments (default: '/') */
separator?: string;
/** Maximum nesting depth */
maxDepth?: number;
/** Parameter names for each nesting level */
levelNames?: string[];
/** Content type mapping for different nesting levels */
typeMapping?: Record<number, string>;
}
/**
* Configuration for query parameter handling
*/
export interface QueryParameterConfig {
/** Allowed query parameters */
allowedParams?: string[];
/** Query parameter filtering rules */
filters?: Record<string, QueryParameterFilter>;
/** Query parameter transformation to GROQ */
groqMapping?: Record<string, string>;
/** Whether to preserve unknown query parameters */
preserveUnknown?: boolean;
}
/**
* Query parameter filter configuration
*/
export interface QueryParameterFilter {
/** Parameter type */
type: 'string' | 'number' | 'boolean' | 'array';
/** Whether parameter is required */
required?: boolean;
/** Default value if not provided */
default?: any;
/** Validation pattern for string types */
pattern?: string;
/** Allowed values for enumeration */
allowedValues?: string[];
/** For array types, the item type */
itemType?: 'string' | 'number';
/** Array separator (default: ',') */
separator?: string;
}
export interface CmsRouteConfig {
/** Whether CMS routing is enabled */
enabled: boolean;
/** Base path for CMS routes (e.g., '/blog', '/cms') */
basePath: string;
/** Array of route patterns to match against */
patterns: RoutePattern[];
/** Paths to exclude from CMS routing */
excludePaths: string[];
/** Default content type when type cannot be determined */
defaultContentType: string;
/** Whether to use strict matching (exact patterns only) */
strictMatching: boolean;
}
export interface RouteMatch {
/** Whether the route was matched */
matched: boolean;
/** Extracted slug from the route */
slug?: string;
/** Determined content type */
contentType?: string;
/** Matched pattern */
pattern?: RoutePattern;
/** Extracted route parameters */
params?: Record<string, string>;
/** Parsed query parameters */
queryParams?: Record<string, any>;
/** Nested parameter structure for hierarchical content */
nestedParams?: NestedRouteParams;
/** Validation results for all parameters */
validation?: RouteValidationResults;
}
/**
* Structured nested parameters for hierarchical content
*/
export interface NestedRouteParams {
/** Hierarchy levels from root to leaf */
levels: NestedLevel[];
/** Full path segments */
segments: string[];
/** Depth of nesting */
depth: number;
/** Leaf node information */
leaf?: NestedLevel;
}
/**
* Individual level in nested route structure
*/
export interface NestedLevel {
/** Parameter name for this level */
name: string;
/** Parameter value */
value: string;
/** Content type for this level */
contentType?: string;
/** Level index (0-based) */
index: number;
}
/**
* Validation results for route parameters
*/
export interface RouteValidationResults {
/** Overall validation status */
valid: boolean;
/** Parameter-specific validation results */
parameters: Record<string, ParameterValidationResult>;
/** Query parameter validation results */
queryParameters: Record<string, ParameterValidationResult>;
/** General validation errors */
errors: string[];
/** Validation warnings */
warnings: string[];
}
/**
* Individual parameter validation result
*/
export interface ParameterValidationResult {
/** Whether parameter is valid */
valid: boolean;
/** Original value */
originalValue: string;
/** Transformed value */
transformedValue: any;
/** Validation errors */
errors: string[];
/** Parameter type */
type: string;
}
/**
* Standard content interface for router integration
*/
export interface CmsContent {
/** Sanity document ID */
_id: string;
/** Sanity document type */
_type: string;
/** Content slug for URL routing */
slug: string;
/** Content title */
title: string;
/** Main content body (can be any structure) */
content: any;
/** SEO metadata */
metadata?: any;
/** Publication date */
publishedAt?: string;
/** Content author */
author?: any;
/** Additional document fields */
[key: string]: any;
}
/**
* Result of validating a route against CMS content
*/
export interface RouteValidationResult {
/** Whether the route is valid and has content */
isValid: boolean;
/** Determined content type */
contentType?: string;
/** Extracted slug from the route */
slug?: string;
/** Fetched content if available */
content?: CmsContent;
/** Error details if validation failed */
error?: string;
/** Route match information */
routeInfo?: RouteMatch;
}
/**
* Information about available routes in the CMS
*/
export interface RouteInfo {
/** Full route path */
path: string;
/** Content type */
contentType: string;
/** Content slug */
slug: string;
/** Content title */
title: string;
/** Content ID */
contentId: string;
/** Publication status */
isPublished: boolean;
/** Last modified date */
lastModified?: string;
}
/**
* Options for fetching content through router integration
*/
export interface CmsContentOptions {
/** Whether to include draft content */
includeDrafts?: boolean;
/** GROQ projection for specific fields */
projection?: string;
/** Whether to include SEO metadata */
includeSEO?: boolean;
/** Whether to include author information */
includeAuthor?: boolean;
/** Custom route configuration */
routeConfig?: Partial<CmsRouteConfig>;
}
/**
* Options for preloading multiple routes
*/
export interface PreloadOptions extends CmsContentOptions {
/** Maximum number of routes to preload */
maxRoutes?: number;
/** Content types to include */
contentTypes?: string[];
/** Whether to preload in parallel */
parallel?: boolean;
}
/**
* Batch operation result for preloading
*/
export interface PreloadResult {
/** Successfully loaded content by path */
loaded: Map<string, CmsContent>;
/** Failed routes with error information */
failed: Map<string, string>;
/** Total processing time */
duration: number;
/** Number of routes processed */
totalRoutes: number;
}
/**
* Props for the default content template component
*/
export interface DefaultTemplateProps {
/** Content data to render */
content: CmsContent | null;
/** Additional CSS class names */
className?: string;
/** Whether to show metadata section */
showMetadata?: boolean;
/** Whether to show author information */
showAuthor?: boolean;
/** Custom renderers for specific content sections */
customRenderers?: ContentRenderers;
/** Loading state */
isLoading?: boolean;
/** Error state */
error?: string;
/** Optional retry callback for error states */
onRetry?: () => void;
}
/**
* Custom renderers for content sections
*/
export interface ContentRenderers {
/** Custom header renderer */
header?: (content: CmsContent) => React.ReactNode;
/** Custom content body renderer */
body?: (content: any) => React.ReactNode;
/** Custom author renderer */
author?: (author: any) => React.ReactNode;
/** Custom metadata renderer */
metadata?: (metadata: any) => React.ReactNode;
}
/**
* Props for content header component
*/
export interface ContentHeaderProps {
/** Content title */
title: string;
/** Content type */
contentType: string;
/** Publication date */
publishedAt?: string;
/** SEO metadata */
metadata?: any;
/** Whether to show metadata */
showMetadata?: boolean;
/** Additional CSS class names */
className?: string;
}
/**
* Props for content body component
*/
export interface ContentBodyProps {
/** Content body data */
content: any;
/** Content type for rendering strategy */
contentType: string;
/** Custom renderer function */
customRenderer?: (content: any) => React.ReactNode;
/** Additional CSS class names */
className?: string;
}
/**
* Props for author info component
*/
export interface AuthorInfoProps {
/** Author data */
author: any;
/** Whether to show author bio */
showBio?: boolean;
/** Whether to show author image */
showImage?: boolean;
/** Additional CSS class names */
className?: string;
}
/**
* Loading skeleton props
*/
export interface LoadingSkeletonProps {
/** Whether to show author skeleton */
showAuthor?: boolean;
/** Whether to show metadata skeleton */
showMetadata?: boolean;
/** Additional CSS class names */
className?: string;
}
export * from './sanity';
export * from './seo';
//# sourceMappingURL=index.d.ts.map