Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 13 additions & 9 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ jobs:
CHANGED_STARTERS="$CHANGED_STARTERS kit-nextjs-product-listing"
fi

if echo "$CHANGED_FILES" | grep -q "^examples/kit-nextjs-b2b-manu/"; then
CHANGED_STARTERS="$CHANGED_STARTERS kit-nextjs-b2b-manu"
fi

# If no specific starter changes detected, check for global changes
if [ -z "$CHANGED_STARTERS" ]; then
if echo "$CHANGED_FILES" | grep -q "^xmcloud.build.json\|^\.github/\|^README.md\|^CONTRIBUTING.md"; then
echo "Global changes detected, validating all starters"
CHANGED_STARTERS="kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing"
CHANGED_STARTERS="kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing kit-nextjs-b2b-manu"
fi
fi

Expand All @@ -116,7 +120,7 @@ jobs:
echo "Installing dependencies for all starters..."

# Install dependencies for all enabled starters
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing; do
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing kit-nextjs-b2b-manu; do
if [ -d "examples/$starter" ]; then
echo "Installing dependencies for $starter..."
cd "examples/$starter"
Expand All @@ -130,7 +134,7 @@ jobs:
echo "Generating Sitecore configuration files..."

# Generate files for all enabled starters
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing; do
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing kit-nextjs-b2b-manu; do
if [ -d "examples/$starter" ]; then
echo "Generating files for $starter..."
cd "examples/$starter"
Expand Down Expand Up @@ -186,7 +190,7 @@ jobs:
run: |
echo "Running linting and formatting checks for all starters..."

for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing; do
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing kit-nextjs-b2b-manu; do
if [ -d "examples/$starter" ]; then
echo "=================================="
echo "Checking examples/$starter"
Expand Down Expand Up @@ -228,7 +232,7 @@ jobs:
echo "Running TypeScript type checking for all starters..."

# WARNING ONLY - does not fail the workflow
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing; do
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing kit-nextjs-b2b-manu; do
if [ -d "examples/$starter" ]; then
echo "Type checking $starter..."
cd "examples/$starter"
Expand Down Expand Up @@ -291,7 +295,7 @@ jobs:
echo " NEXT_PUBLIC_DEFAULT_SITE_NAME: ${NEXT_PUBLIC_DEFAULT_SITE_NAME}"
echo " SITECORE_EDITING_SECRET: ${SITECORE_EDITING_SECRET:+[SET]}"

for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing; do
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing kit-nextjs-b2b-manu; do
if [ -d "examples/$starter" ]; then
echo "=================================="
echo "Building $starter"
Expand Down Expand Up @@ -324,7 +328,7 @@ jobs:
echo "Running TypeScript compilation to validate code correctness..."
echo ""

for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing; do
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing kit-nextjs-b2b-manu; do
if [ -d "examples/$starter" ]; then
echo "=================================="
echo "TypeScript compile check: $starter"
Expand Down Expand Up @@ -367,7 +371,7 @@ jobs:
echo "Running tests with coverage for all starters..."

# Test all enabled starters
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing; do
for starter in kit-nextjs-skate-park kit-nextjs-article-starter kit-nextjs-location-finder kit-nextjs-product-listing kit-nextjs-b2b-manu; do
if [ -d "examples/$starter" ]; then
echo "=================================="
echo "Testing $starter"
Expand Down Expand Up @@ -424,7 +428,7 @@ jobs:

**Build Type:** ${buildType}

**Validated Starters:** kit-nextjs-skate-park, kit-nextjs-article-starter, kit-nextjs-location-finder, kit-nextjs-product-listing
**Validated Starters:** kit-nextjs-skate-park, kit-nextjs-article-starter, kit-nextjs-location-finder, kit-nextjs-product-listing, kit-nextjs-b2b-manu

**Checks Performed:**
- ✅ Linting and formatting
Expand Down
116 changes: 116 additions & 0 deletions examples/kit-nextjs-b2b-manu/.cursor/rules/app-router-setup.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
description: Getting started with your Sitecore Content SDK Next.js App Router project
alwaysApply: true
globs: []
---

# Sitecore Content SDK Next.js App Router Project

## Project Overview

This is a Sitecore Content SDK application built with Next.js App Router. This project uses the latest Next.js features for improved performance and developer experience.

Key Technologies:

- Next.js App Router (React Server Components)
- Sitecore Content SDK
- TypeScript
- Sitecore XM Cloud
- next-intl for internationalization

## Getting Started

Development Workflow:

1. Install dependencies: `npm install`
2. Configure environment variables (copy `.env.example` to `.env.local`)
3. Start development server: `npm run dev`
4. Build for production: `npm run build`

App Router Specifics:

- Server Components by default
- Client Components when interactivity needed
- File-based routing in `src/app/` directory
- Layout files for shared UI elements

## Project Structure

```
src/
app/ # App Router pages and layouts
components/ # React-specific SDK
lib/ # Configuration and utilities
i18n/ # Internationalization setup
```

Component Development:

- Server Components for data fetching and static content
- Client Components for interactivity (use 'use client')
- Shared components in `src/components/`
- Follow Sitecore field handling patterns

## App Router Best Practices

Server vs Client Components:

- Use Server Components for Sitecore content rendering
- Use Client Components for user interactions
- Minimize client-side JavaScript
- Leverage server-side data fetching

Routing and Layouts:

- Use layout.tsx for shared page structure
- Implement loading.tsx for loading states
- Create error.tsx for error boundaries
- Use page.tsx for route content

## Sitecore Integration

Content Rendering:

- Fetch Sitecore data in Server Components
- Use layout service for page structure
- Handle content preview scenarios
- Implement proper error handling

Performance:

- Leverage Server Components for better performance
- Use streaming for improved loading experience
- Implement proper caching strategies
- Optimize images with Next.js Image component

## Development Commands

```bash
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
npm run type-check # Run TypeScript compiler
```

## Environment Configuration

- Copy `.env.example` to `.env.local`
- Add your Sitecore API endpoint and key
- Configure site name and locale settings
- Set up internationalization if needed

## Next Steps

1. Configure your Sitecore connection
2. Set up internationalization (if needed)
3. Create your first Server Component
4. Add content types and templates
5. Implement your layout structure
6. Deploy to your hosting platform

Referenced:
@src/app/
@src/components/
@sitecore.config.ts
@src/i18n/
80 changes: 80 additions & 0 deletions examples/kit-nextjs-b2b-manu/.cursor/rules/general.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
description: Core coding principles for your Sitecore project
alwaysApply: true
globs: []
---

# General Coding Principles

## Universal Standards

DRY Principle:

- Don't Repeat Yourself - extract common functionality
- Create reusable utilities and helper functions
- Use composition over inheritance
- Share types and interfaces across modules

SOLID Principles:

- Single Responsibility: each function/class has one purpose
- Open/Closed: extend functionality through composition
- Dependency Inversion: depend on abstractions, not implementations

Code Clarity:

- Write self-documenting code with clear intent
- Use meaningful names that express business concepts
- Prefer explicit over implicit behavior
- Make dependencies and requirements obvious

## Architecture Patterns

Modular Design:

- Organize code into focused, cohesive modules
- Minimize coupling between modules
- Use clear interfaces between layers
- Follow established patterns consistently

Data Flow:

- Prefer unidirectional data flow
- Validate inputs at system boundaries
- Transform data at appropriate layers
- Handle errors close to their source

Testing:

- Write testable code with minimal dependencies
- Use dependency injection for better testability
- Mock external services and side effects
- Test behavior, not implementation details

## Development Standards

Version Control:

- Write descriptive commit messages
- Keep commits focused and atomic
- Use branching strategies appropriate to team size
- Review code before merging

Documentation:

- Document public APIs and interfaces
- Include usage examples for complex functionality
- Keep documentation close to code
- Update documentation with code changes

Performance:

- Optimize for readability first, performance second
- Profile before optimizing
- Cache expensive operations appropriately
- Consider memory usage and cleanup

Referenced:
@src/app/
@src/components/
@src/lib/
112 changes: 112 additions & 0 deletions examples/kit-nextjs-b2b-manu/.cursor/rules/javascript.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
description: JavaScript/TypeScript rules for your Sitecore App Router project
alwaysApply: false
globs:
- '**/*.js'
- '**/*.ts'
- '**/*.tsx'
- '**/*.mjs'
---

# JavaScript/TypeScript Rules

## Naming Conventions

Variables and Functions:

- Use camelCase: `getUserData()`, `isLoading`, `currentUser`
- Boolean variables: prefix with `is`, `has`, `can`, `should`
- Event handlers: prefix with `handle` or `on`: `handleClick`, `onSubmit`

Components (React):

- Use PascalCase: `SitecoreComponent`, `PageLayout`, `ContentBlock`
- File names match component names: `SitecoreComponent.tsx`

Constants:

- Use UPPER_SNAKE_CASE: `API_ENDPOINT`, `DEFAULT_TIMEOUT`, `MAX_RETRIES`
- Export at module level when shared

Directories:

- Use kebab-case: `src/components`, `src/api-clients`, `src/sitecore-utils`
- Organize by feature when appropriate: `src/content-management/`

Types and Interfaces:

- Use PascalCase with descriptive names: `ContentItem`, `LayoutProps`, `SitecoreConfig`
- Prefix interfaces with `I` only when needed for disambiguation

## Code Layout and Organization

Directory Structure:

```
src/
app/ # App Router pages and layouts
components/ # UI components (React)
lib/ # Configuration and utilities
i18n/ # Internationalization setup
types/ # TypeScript type definitions
```

File Organization:

- Server Components for data fetching and static content
- Client Components for interactivity (use 'use client')
- Group related functionality in feature directories
- Keep components co-located with their styles and tests

## Error Handling

API Calls:

- Always wrap in try/catch blocks
- Throw custom errors with context: `SitecoreFetchError`, `ConfigurationError`
- Handle edge cases with guard clauses

```typescript
async function fetchContent(id: string): Promise<ContentItem> {
if (!id) {
throw new Error('Content ID is required');
}

try {
const response = await sitecoreClient.getItem(id);
return response.data;
} catch (error) {
throw new SitecoreFetchError(`Failed to fetch content ${id}`, error);
}
}
```

## Security

Input Validation:

- Sanitize user inputs before processing
- Validate data at application boundaries
- Use type guards for runtime type checking
- Escape content when rendering to prevent XSS

## Performance

Optimization Patterns:

- Cache API responses using React Query or SWR
- Use Server Components for better performance
- Lazy-load non-critical modules: `const Component = lazy(() => import('./Component'))`
- Use useCallback and useMemo for expensive operations in Client Components

TypeScript:

- Enable strict mode in tsconfig.json
- Prefer type assertions over any: `value as ContentItem`
- Use discriminated unions for complex state management

Referenced:
@src/app/
@src/components/
@src/lib/

Loading