create-content-sdk-app 1.2.0-canary.8 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.MD +202 -202
- package/README.md +5 -5
- package/dist/templates/nextjs/.cursor/rules/general.mdc +81 -0
- package/dist/templates/nextjs/.cursor/rules/javascript.mdc +112 -0
- package/dist/templates/nextjs/.cursor/rules/project-setup.mdc +100 -0
- package/dist/templates/nextjs/.cursor/rules/sitecore.mdc +147 -0
- package/dist/templates/nextjs/.env.container.example +27 -27
- package/dist/templates/nextjs/.env.remote.example +44 -44
- package/dist/templates/nextjs/.gitattributes +11 -11
- package/dist/templates/nextjs/.prettierrc +8 -8
- package/dist/templates/nextjs/.vscode/extensions.json +8 -8
- package/dist/templates/nextjs/.vscode/launch.json +15 -15
- package/dist/templates/nextjs/.windsurfrules +183 -0
- package/dist/templates/nextjs/CLAUDE.md +170 -0
- package/dist/templates/nextjs/LICENSE.txt +202 -202
- package/dist/templates/nextjs/LLMs.txt +179 -0
- package/dist/templates/nextjs/README.md +7 -7
- package/dist/templates/nextjs/copilot-instructions.md +170 -0
- package/dist/templates/nextjs/eslint.config.mjs +81 -81
- package/dist/templates/nextjs/gitignore +28 -28
- package/dist/templates/nextjs/next.config.js +1 -13
- package/dist/templates/nextjs/package.json +68 -73
- package/dist/templates/nextjs/sitecore.cli.config.ts +3 -7
- package/dist/templates/nextjs/sitecore.config.ts.example +38 -38
- package/dist/templates/nextjs/src/Providers.tsx +28 -0
- package/dist/templates/nextjs/src/pages/404.tsx +16 -11
- package/dist/templates/nextjs/src/pages/500.tsx +16 -11
- package/dist/templates/nextjs/src/pages/[[...path]].tsx +6 -9
- package/dist/templates/nextjs/src/pages/_app.tsx +0 -1
- package/dist/templates/nextjs/tsconfig.json +40 -40
- package/dist/templates/nextjs-app-router (beta)/.cursor/rules/app-router-setup.mdc +116 -0
- package/dist/templates/nextjs-app-router (beta)/.cursor/rules/general.mdc +80 -0
- package/dist/templates/nextjs-app-router (beta)/.cursor/rules/javascript.mdc +112 -0
- package/dist/templates/nextjs-app-router (beta)/.cursor/rules/sitecore.mdc +171 -0
- package/dist/templates/nextjs-app-router (beta)/.env.container.example +27 -27
- package/dist/templates/nextjs-app-router (beta)/.env.remote.example +44 -44
- package/dist/templates/nextjs-app-router (beta)/.gitattributes +11 -11
- package/dist/templates/nextjs-app-router (beta)/.sitecore/component-map.client.ts +15 -0
- package/dist/templates/nextjs-app-router (beta)/.windsurfrules +287 -0
- package/dist/templates/nextjs-app-router (beta)/CLAUDE.md +271 -0
- package/dist/templates/nextjs-app-router (beta)/LLMs.txt +236 -0
- package/dist/templates/nextjs-app-router (beta)/README.md +7 -7
- package/dist/templates/nextjs-app-router (beta)/copilot-instructions.md +271 -0
- package/dist/templates/nextjs-app-router (beta)/eslint.config.mjs +29 -29
- package/dist/templates/nextjs-app-router (beta)/gitignore +29 -28
- package/dist/templates/nextjs-app-router (beta)/next.config.ts +5 -2
- package/dist/templates/nextjs-app-router (beta)/package.json +55 -52
- package/dist/templates/nextjs-app-router (beta)/postcss.config.mjs +5 -5
- package/dist/templates/nextjs-app-router (beta)/sitecore.cli.config.ts +3 -7
- package/dist/templates/nextjs-app-router (beta)/sitecore.config.ts.example +38 -38
- package/dist/templates/nextjs-app-router (beta)/src/Bootstrap.tsx +26 -32
- package/dist/templates/nextjs-app-router (beta)/src/DesignLibraryLayout.tsx +7 -0
- package/dist/templates/nextjs-app-router (beta)/src/Layout.tsx +28 -8
- package/dist/templates/nextjs-app-router (beta)/src/Providers.tsx +1 -1
- package/dist/templates/nextjs-app-router (beta)/src/Scripts.tsx +3 -1
- package/dist/templates/nextjs-app-router (beta)/src/app/[site]/[locale]/[[...path]]/not-found.tsx +37 -0
- package/dist/templates/nextjs-app-router (beta)/src/app/[site]/[locale]/[[...path]]/page.tsx +81 -0
- package/dist/templates/nextjs-app-router (beta)/src/app/[site]/layout.tsx +20 -0
- package/dist/templates/nextjs-app-router (beta)/src/app/api/editing/config/route.ts +13 -0
- package/dist/templates/nextjs-app-router (beta)/src/app/api/editing/render/route.ts +15 -0
- package/dist/templates/nextjs-app-router (beta)/src/app/api/robots/route.ts +2 -0
- package/dist/templates/nextjs-app-router (beta)/src/app/api/sitemap/route.ts +2 -0
- package/dist/templates/nextjs-app-router (beta)/src/app/globals.css +1 -1
- package/dist/templates/nextjs-app-router (beta)/src/app/not-found.tsx +13 -11
- package/dist/templates/nextjs-app-router (beta)/src/byoc/index.client.tsx +20 -0
- package/dist/templates/nextjs-app-router (beta)/src/byoc/index.hybrid.ts +10 -0
- package/dist/templates/nextjs-app-router (beta)/src/byoc/index.tsx +39 -0
- package/dist/templates/nextjs-app-router (beta)/src/i18n/request.ts +27 -0
- package/dist/templates/nextjs-app-router (beta)/src/i18n/routing.ts +15 -0
- package/dist/templates/nextjs-app-router (beta)/src/middleware.ts +40 -24
- package/dist/templates/nextjs-app-router (beta)/tsconfig.json +48 -45
- package/package.json +2 -2
- package/dist/templates/nextjs/src/assets/main.scss +0 -3
- package/dist/templates/nextjs-app-router (beta)/src/app/[[...path]]/page.tsx +0 -75
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Getting started with your Sitecore Content SDK Next.js project
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
globs: []
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Sitecore Content SDK Next.js Project
|
|
8
|
+
|
|
9
|
+
## Project Overview
|
|
10
|
+
|
|
11
|
+
This is a Sitecore Content SDK application built with Next.js. The project structure follows Sitecore best practices for XM Cloud development.
|
|
12
|
+
|
|
13
|
+
Key Technologies:
|
|
14
|
+
|
|
15
|
+
- Next.js (React framework)
|
|
16
|
+
- Sitecore Content SDK
|
|
17
|
+
- TypeScript
|
|
18
|
+
- Sitecore XM Cloud
|
|
19
|
+
|
|
20
|
+
## Getting Started
|
|
21
|
+
|
|
22
|
+
Development Workflow:
|
|
23
|
+
|
|
24
|
+
1. Install dependencies: `npm install`
|
|
25
|
+
2. Configure environment variables (copy `.env.example` to `.env.local`)
|
|
26
|
+
3. Start development server: `npm run dev`
|
|
27
|
+
4. Build for production: `npm run build`
|
|
28
|
+
|
|
29
|
+
Environment Configuration:
|
|
30
|
+
|
|
31
|
+
- Copy `.env.example` to `.env.local`
|
|
32
|
+
- Add your Sitecore API endpoint and key
|
|
33
|
+
- Configure site name and other settings
|
|
34
|
+
|
|
35
|
+
## Sitecore Integration
|
|
36
|
+
|
|
37
|
+
Configuration:
|
|
38
|
+
|
|
39
|
+
- Configure Sitecore connection in `sitecore.config.ts`
|
|
40
|
+
- Register components in the component map
|
|
41
|
+
- Use Sitecore field components for content rendering
|
|
42
|
+
- Follow Sitecore's layout service patterns
|
|
43
|
+
|
|
44
|
+
Component Development:
|
|
45
|
+
|
|
46
|
+
- Create components in `src/components/`
|
|
47
|
+
- Export from component files for registration
|
|
48
|
+
- Use TypeScript interfaces for component props
|
|
49
|
+
- Follow Sitecore field handling patterns
|
|
50
|
+
|
|
51
|
+
## Project Structure
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
src/
|
|
55
|
+
components/ # React-specific SDK
|
|
56
|
+
lib/ # Configuration and utilities
|
|
57
|
+
pages/ # Next.js pages
|
|
58
|
+
assets/ # Static assets and styles
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Best Practices
|
|
62
|
+
|
|
63
|
+
Sitecore Components:
|
|
64
|
+
|
|
65
|
+
- Use descriptive component names
|
|
66
|
+
- Handle field validation gracefully
|
|
67
|
+
- Implement proper error boundaries
|
|
68
|
+
- Cache content when appropriate
|
|
69
|
+
|
|
70
|
+
Performance:
|
|
71
|
+
|
|
72
|
+
- Optimize images using Next.js Image component
|
|
73
|
+
- Implement proper loading states
|
|
74
|
+
- Use React.memo for expensive components
|
|
75
|
+
- Consider server-side rendering implications
|
|
76
|
+
|
|
77
|
+
## Development Commands
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm run dev # Start development server
|
|
81
|
+
npm run build # Build for production
|
|
82
|
+
npm run start # Start production server
|
|
83
|
+
npm run lint # Run ESLint
|
|
84
|
+
npm run type-check # Run TypeScript compiler
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Next Steps
|
|
88
|
+
|
|
89
|
+
1. Configure your Sitecore connection
|
|
90
|
+
2. Create your first component
|
|
91
|
+
3. Add content types and templates
|
|
92
|
+
4. Set up your development workflow
|
|
93
|
+
5. Deploy to your hosting platform
|
|
94
|
+
|
|
95
|
+
Referenced:
|
|
96
|
+
@src/components/
|
|
97
|
+
@sitecore.config.ts
|
|
98
|
+
@package.json
|
|
99
|
+
@.env.example
|
|
100
|
+
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Sitecore development patterns for your project
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
globs:
|
|
5
|
+
- 'src/components/**'
|
|
6
|
+
- 'src/lib/**'
|
|
7
|
+
- 'sitecore.config.ts'
|
|
8
|
+
- '**/*sitecore*'
|
|
9
|
+
- '**/*content*'
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Sitecore Development Patterns
|
|
13
|
+
|
|
14
|
+
## Component Development
|
|
15
|
+
|
|
16
|
+
Sitecore Component Naming:
|
|
17
|
+
|
|
18
|
+
- Use descriptive, feature-based names: `HeroWithContent`, `ProductListing`, `ContentBlockGrid`
|
|
19
|
+
- Follow PascalCase convention
|
|
20
|
+
- Include component type in name when helpful: `LayoutContainer`, `ContentRenderer`
|
|
21
|
+
|
|
22
|
+
Component Registration:
|
|
23
|
+
|
|
24
|
+
- Export component from component file
|
|
25
|
+
- Use descriptive, PascalCase names
|
|
26
|
+
- Include TypeScript interfaces for props
|
|
27
|
+
- Handle missing fields gracefully
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
// Component props interface
|
|
31
|
+
interface HeroProps {
|
|
32
|
+
fields: {
|
|
33
|
+
title: Field;
|
|
34
|
+
subtitle: Field;
|
|
35
|
+
backgroundImage: Field;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default function Hero({ fields }: HeroProps) {
|
|
40
|
+
return (
|
|
41
|
+
<div>
|
|
42
|
+
<Text field={fields?.title} tag="h1" />
|
|
43
|
+
<Text field={fields?.subtitle} tag="p" />
|
|
44
|
+
<Image field={fields?.backgroundImage} />
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Content Management
|
|
51
|
+
|
|
52
|
+
Field Handling:
|
|
53
|
+
|
|
54
|
+
- Always validate field existence before rendering
|
|
55
|
+
- Use helper functions for common field operations
|
|
56
|
+
- Handle empty/null fields gracefully
|
|
57
|
+
- Prefer Sitecore field components over manual rendering
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
// Good: Using Sitecore field components
|
|
61
|
+
<Text field={fields?.title} tag="h1" />
|
|
62
|
+
<RichText field={fields?.content} />
|
|
63
|
+
|
|
64
|
+
// Avoid: Manual field value extraction unless necessary
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Layout Service:
|
|
68
|
+
|
|
69
|
+
- Use the Layout Service for page data fetching
|
|
70
|
+
- Implement proper error boundaries for layout rendering
|
|
71
|
+
- Handle missing placeholder content gracefully
|
|
72
|
+
- Cache layout data when appropriate
|
|
73
|
+
|
|
74
|
+
## Configuration
|
|
75
|
+
|
|
76
|
+
Environment Setup:
|
|
77
|
+
|
|
78
|
+
- Use `.env.local` for local development
|
|
79
|
+
- Never commit API keys to version control
|
|
80
|
+
- Use `.env.example` to document required variables
|
|
81
|
+
- Configure Sitecore endpoints in `sitecore.config.ts`
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// sitecore.config.ts
|
|
85
|
+
import { defineConfig } from '@sitecore-content-sdk/nextjs/config';
|
|
86
|
+
|
|
87
|
+
export default defineConfig({
|
|
88
|
+
api: {
|
|
89
|
+
edge: {
|
|
90
|
+
contextId: process.env.SITECORE_EDGE_CONTEXT_ID || '',
|
|
91
|
+
clientContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID,
|
|
92
|
+
edgeUrl: process.env.SITECORE_EDGE_URL || 'https://edge-platform.sitecorecloud.io',
|
|
93
|
+
},
|
|
94
|
+
local: {
|
|
95
|
+
apiKey: process.env.SITECORE_API_KEY || '',
|
|
96
|
+
apiHost: process.env.SITECORE_API_HOST || '',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
defaultSite: process.env.NEXT_PUBLIC_DEFAULT_SITE_NAME || 'default',
|
|
100
|
+
defaultLanguage: process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE || 'en',
|
|
101
|
+
editingSecret: process.env.SITECORE_EDITING_SECRET,
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Security and Performance
|
|
106
|
+
|
|
107
|
+
Security Best Practices:
|
|
108
|
+
|
|
109
|
+
- Sanitize user inputs before processing
|
|
110
|
+
- Validate content from Sitecore before rendering
|
|
111
|
+
- Use HTTPS for all Sitecore connections
|
|
112
|
+
- Never expose sensitive configuration in client-side code
|
|
113
|
+
|
|
114
|
+
Content Fetching:
|
|
115
|
+
|
|
116
|
+
- Implement caching strategy for content (React Query recommended)
|
|
117
|
+
- Use GraphQL queries efficiently (avoid over-fetching)
|
|
118
|
+
- Implement proper loading states and error handling
|
|
119
|
+
- Consider content preview vs. published content scenarios
|
|
120
|
+
|
|
121
|
+
## Development Patterns
|
|
122
|
+
|
|
123
|
+
Error Handling:
|
|
124
|
+
|
|
125
|
+
- Create custom error classes: `SitecoreFetchError`, `ComponentRenderError`
|
|
126
|
+
- Log errors appropriately for debugging
|
|
127
|
+
- Provide fallback content when components fail to render
|
|
128
|
+
- Use error boundaries in React applications
|
|
129
|
+
|
|
130
|
+
Placeholder Management:
|
|
131
|
+
|
|
132
|
+
- Use strongly-typed placeholder names
|
|
133
|
+
- Handle dynamic placeholders appropriately
|
|
134
|
+
- Implement fallback rendering for missing placeholders
|
|
135
|
+
- Follow Sitecore's placeholder naming conventions
|
|
136
|
+
|
|
137
|
+
Testing:
|
|
138
|
+
|
|
139
|
+
- Mock Sitecore services in unit tests
|
|
140
|
+
- Test component rendering with various field configurations
|
|
141
|
+
- Include tests for error scenarios (missing fields, API failures)
|
|
142
|
+
- Use Sitecore's test data helpers when available
|
|
143
|
+
|
|
144
|
+
Referenced:
|
|
145
|
+
@src/components/
|
|
146
|
+
@sitecore.config.ts
|
|
147
|
+
@.env.example
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
# This file should be copied to .env.local and modified with your environment variables to connect to your Sitecore container instance.
|
|
2
|
-
|
|
3
|
-
# To secure the Sitecore editor endpoint exposed by your Next.js app
|
|
4
|
-
# (`/api/editing/render` by default), a secret token is used. This (client-side)
|
|
5
|
-
SITECORE_EDITING_SECRET=
|
|
6
|
-
|
|
7
|
-
# Your Sitecore site name.
|
|
8
|
-
# The value of the variable represents the default/configured site.
|
|
9
|
-
NEXT_PUBLIC_DEFAULT_SITE_NAME=
|
|
10
|
-
|
|
11
|
-
# Your default app language.
|
|
12
|
-
NEXT_PUBLIC_DEFAULT_LANGUAGE=
|
|
13
|
-
|
|
14
|
-
# Your Sitecore API key is needed to build the app.
|
|
15
|
-
NEXT_PUBLIC_SITECORE_API_KEY=
|
|
16
|
-
|
|
17
|
-
# Your Sitecore API hostname is needed to build the app.
|
|
18
|
-
NEXT_PUBLIC_SITECORE_API_HOST=
|
|
19
|
-
|
|
20
|
-
# Sitecore Content SDK npm packages utilize the debug module for debug logging.
|
|
21
|
-
# https://www.npmjs.com/package/debug
|
|
22
|
-
# Set the DEBUG environment variable to 'content-sdk:*' to see all logs:
|
|
23
|
-
#DEBUG=content-sdk:*
|
|
24
|
-
# Or be selective and show for example only layout service logs:
|
|
25
|
-
#DEBUG=content-sdk:layout
|
|
26
|
-
# Or everything BUT layout service logs:
|
|
27
|
-
#DEBUG=content-sdk:*,-content-sdk:layout
|
|
1
|
+
# This file should be copied to .env.local and modified with your environment variables to connect to your Sitecore container instance.
|
|
2
|
+
|
|
3
|
+
# To secure the Sitecore editor endpoint exposed by your Next.js app
|
|
4
|
+
# (`/api/editing/render` by default), a secret token is used. This (client-side)
|
|
5
|
+
SITECORE_EDITING_SECRET=
|
|
6
|
+
|
|
7
|
+
# Your Sitecore site name.
|
|
8
|
+
# The value of the variable represents the default/configured site.
|
|
9
|
+
NEXT_PUBLIC_DEFAULT_SITE_NAME=
|
|
10
|
+
|
|
11
|
+
# Your default app language.
|
|
12
|
+
NEXT_PUBLIC_DEFAULT_LANGUAGE=
|
|
13
|
+
|
|
14
|
+
# Your Sitecore API key is needed to build the app.
|
|
15
|
+
NEXT_PUBLIC_SITECORE_API_KEY=
|
|
16
|
+
|
|
17
|
+
# Your Sitecore API hostname is needed to build the app.
|
|
18
|
+
NEXT_PUBLIC_SITECORE_API_HOST=
|
|
19
|
+
|
|
20
|
+
# Sitecore Content SDK npm packages utilize the debug module for debug logging.
|
|
21
|
+
# https://www.npmjs.com/package/debug
|
|
22
|
+
# Set the DEBUG environment variable to 'content-sdk:*' to see all logs:
|
|
23
|
+
#DEBUG=content-sdk:*
|
|
24
|
+
# Or be selective and show for example only layout service logs:
|
|
25
|
+
#DEBUG=content-sdk:layout
|
|
26
|
+
# Or everything BUT layout service logs:
|
|
27
|
+
#DEBUG=content-sdk:*,-content-sdk:layout
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
# This file should be copied to .env.local and modified with your environment variables to connect to your remote Sitecore instance.
|
|
2
|
-
|
|
3
|
-
# To secure the Sitecore editor endpoint exposed by your Next.js app
|
|
4
|
-
# (`/api/editing/render` by default), a secret token is used. This (client-side)
|
|
5
|
-
SITECORE_EDITING_SECRET=
|
|
6
|
-
|
|
7
|
-
# Your Sitecore site name.
|
|
8
|
-
# The value of the variable represents the default/configured site.
|
|
9
|
-
NEXT_PUBLIC_DEFAULT_SITE_NAME=
|
|
10
|
-
|
|
11
|
-
# Your default app language.
|
|
12
|
-
NEXT_PUBLIC_DEFAULT_LANGUAGE=
|
|
13
|
-
|
|
14
|
-
# Your unified Sitecore Edge Context Id for server-side use.
|
|
15
|
-
# This will be used over any Sitecore Preview / Delivery Edge variables (above).
|
|
16
|
-
SITECORE_EDGE_CONTEXT_ID=
|
|
17
|
-
|
|
18
|
-
# Your Sitecore Edge Context Id for client-side use.
|
|
19
|
-
# Will be used as a fallback if separate SITECORE_EDGE_CONTEXT_ID value is not provided
|
|
20
|
-
NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID=
|
|
21
|
-
|
|
22
|
-
# An optional Sitecore Personalize scope identifier.
|
|
23
|
-
# This can be used to isolate personalization data when multiple XM Cloud Environments share a Personalize tenant.
|
|
24
|
-
# This should match the PAGES_PERSONALIZE_SCOPE environment variable for your connected XM Cloud Environment.
|
|
25
|
-
NEXT_PUBLIC_PERSONALIZE_SCOPE=
|
|
26
|
-
|
|
27
|
-
# Timeout (ms) for Sitecore CDP requests to respond within. Default is 400.
|
|
28
|
-
PERSONALIZE_MIDDLEWARE_CDP_TIMEOUT=
|
|
29
|
-
|
|
30
|
-
# Timeout (ms) for Sitecore Experience Edge requests to respond within. Default is 400.
|
|
31
|
-
PERSONALIZE_MIDDLEWARE_EDGE_TIMEOUT=
|
|
32
|
-
|
|
33
|
-
# Sitecore Content SDK npm packages utilize the debug module for debug logging.
|
|
34
|
-
# https://www.npmjs.com/package/debug
|
|
35
|
-
# Set the DEBUG environment variable to 'content-sdk:*' to see all logs:
|
|
36
|
-
#DEBUG=content-sdk:*
|
|
37
|
-
# Or be selective and show for example only layout service logs:
|
|
38
|
-
#DEBUG=content-sdk:layout
|
|
39
|
-
# Or everything BUT layout service logs:
|
|
40
|
-
#DEBUG=content-sdk:*,-content-sdk:layout
|
|
41
|
-
|
|
42
|
-
# Client ID and Secret used for Design Library functionality
|
|
43
|
-
SITECORE_AUTH_CLIENT_ID=
|
|
44
|
-
SITECORE_AUTH_CLIENT_SECRET=
|
|
1
|
+
# This file should be copied to .env.local and modified with your environment variables to connect to your remote Sitecore instance.
|
|
2
|
+
|
|
3
|
+
# To secure the Sitecore editor endpoint exposed by your Next.js app
|
|
4
|
+
# (`/api/editing/render` by default), a secret token is used. This (client-side)
|
|
5
|
+
SITECORE_EDITING_SECRET=
|
|
6
|
+
|
|
7
|
+
# Your Sitecore site name.
|
|
8
|
+
# The value of the variable represents the default/configured site.
|
|
9
|
+
NEXT_PUBLIC_DEFAULT_SITE_NAME=
|
|
10
|
+
|
|
11
|
+
# Your default app language.
|
|
12
|
+
NEXT_PUBLIC_DEFAULT_LANGUAGE=
|
|
13
|
+
|
|
14
|
+
# Your unified Sitecore Edge Context Id for server-side use.
|
|
15
|
+
# This will be used over any Sitecore Preview / Delivery Edge variables (above).
|
|
16
|
+
SITECORE_EDGE_CONTEXT_ID=
|
|
17
|
+
|
|
18
|
+
# Your Sitecore Edge Context Id for client-side use.
|
|
19
|
+
# Will be used as a fallback if separate SITECORE_EDGE_CONTEXT_ID value is not provided
|
|
20
|
+
NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID=
|
|
21
|
+
|
|
22
|
+
# An optional Sitecore Personalize scope identifier.
|
|
23
|
+
# This can be used to isolate personalization data when multiple XM Cloud Environments share a Personalize tenant.
|
|
24
|
+
# This should match the PAGES_PERSONALIZE_SCOPE environment variable for your connected XM Cloud Environment.
|
|
25
|
+
NEXT_PUBLIC_PERSONALIZE_SCOPE=
|
|
26
|
+
|
|
27
|
+
# Timeout (ms) for Sitecore CDP requests to respond within. Default is 400.
|
|
28
|
+
PERSONALIZE_MIDDLEWARE_CDP_TIMEOUT=
|
|
29
|
+
|
|
30
|
+
# Timeout (ms) for Sitecore Experience Edge requests to respond within. Default is 400.
|
|
31
|
+
PERSONALIZE_MIDDLEWARE_EDGE_TIMEOUT=
|
|
32
|
+
|
|
33
|
+
# Sitecore Content SDK npm packages utilize the debug module for debug logging.
|
|
34
|
+
# https://www.npmjs.com/package/debug
|
|
35
|
+
# Set the DEBUG environment variable to 'content-sdk:*' to see all logs:
|
|
36
|
+
#DEBUG=content-sdk:*
|
|
37
|
+
# Or be selective and show for example only layout service logs:
|
|
38
|
+
#DEBUG=content-sdk:layout
|
|
39
|
+
# Or everything BUT layout service logs:
|
|
40
|
+
#DEBUG=content-sdk:*,-content-sdk:layout
|
|
41
|
+
|
|
42
|
+
# Client ID and Secret used for Design Library functionality
|
|
43
|
+
SITECORE_AUTH_CLIENT_ID=
|
|
44
|
+
SITECORE_AUTH_CLIENT_SECRET=
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# Line endings for this repository
|
|
2
|
-
# See: https://help.github.com/en/articles/configuring-git-to-handle-line-endings
|
|
3
|
-
# This should line up with the expectations from .eslintrc
|
|
4
|
-
|
|
5
|
-
# Set the default behavior, in case people don't have core.autocrlf set.
|
|
6
|
-
* text=crlf
|
|
7
|
-
|
|
8
|
-
# Declare files that will always have CRLF line endings on checkout.
|
|
9
|
-
*.ts text eol=crlf
|
|
10
|
-
*.tsx text eol=crlf
|
|
11
|
-
*.js text eol=crlf
|
|
1
|
+
# Line endings for this repository
|
|
2
|
+
# See: https://help.github.com/en/articles/configuring-git-to-handle-line-endings
|
|
3
|
+
# This should line up with the expectations from .eslintrc
|
|
4
|
+
|
|
5
|
+
# Set the default behavior, in case people don't have core.autocrlf set.
|
|
6
|
+
* text=crlf
|
|
7
|
+
|
|
8
|
+
# Declare files that will always have CRLF line endings on checkout.
|
|
9
|
+
*.ts text eol=crlf
|
|
10
|
+
*.tsx text eol=crlf
|
|
11
|
+
*.js text eol=crlf
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
{
|
|
2
|
-
"endOfLine": "crlf",
|
|
3
|
-
"semi": true,
|
|
4
|
-
"singleQuote": true,
|
|
5
|
-
"tabWidth": 2,
|
|
6
|
-
"trailingComma": "es5",
|
|
7
|
-
"printWidth": 100
|
|
8
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"endOfLine": "crlf",
|
|
3
|
+
"semi": true,
|
|
4
|
+
"singleQuote": true,
|
|
5
|
+
"tabWidth": 2,
|
|
6
|
+
"trailingComma": "es5",
|
|
7
|
+
"printWidth": 100
|
|
8
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
{
|
|
2
|
-
"recommendations": [
|
|
3
|
-
"GraphQL.vscode-graphql",
|
|
4
|
-
"dbaeumer.vscode-eslint",
|
|
5
|
-
"esbenp.prettier-vscode",
|
|
6
|
-
"mikestead.dotenv",
|
|
7
|
-
]
|
|
8
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"recommendations": [
|
|
3
|
+
"GraphQL.vscode-graphql",
|
|
4
|
+
"dbaeumer.vscode-eslint",
|
|
5
|
+
"esbenp.prettier-vscode",
|
|
6
|
+
"mikestead.dotenv",
|
|
7
|
+
]
|
|
8
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"name": "Attach to Process",
|
|
9
|
-
"type": "node",
|
|
10
|
-
"request": "attach",
|
|
11
|
-
"skipFiles": ["<node_internals>/**"],
|
|
12
|
-
"port": 9229
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
}
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Attach to Process",
|
|
9
|
+
"type": "node",
|
|
10
|
+
"request": "attach",
|
|
11
|
+
"skipFiles": ["<node_internals>/**"],
|
|
12
|
+
"port": 9229
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Sitecore Content SDK Next.js Project - Windsurf AI Rules
|
|
2
|
+
|
|
3
|
+
## Project Purpose and Tech Stack
|
|
4
|
+
|
|
5
|
+
This is a **Sitecore Content SDK** application built with **Next.js** and **TypeScript**. The project follows Sitecore best practices for XM Cloud development and provides a modern, performant web application framework.
|
|
6
|
+
|
|
7
|
+
### Key Technologies
|
|
8
|
+
|
|
9
|
+
- **Next.js** - React framework with SSR/SSG capabilities
|
|
10
|
+
- **Sitecore Content SDK** - Official SDK for Sitecore XM Cloud integration
|
|
11
|
+
- **TypeScript** - Type-safe JavaScript development
|
|
12
|
+
- **Sitecore XM Cloud** - Headless CMS platform
|
|
13
|
+
- **React** - Component-based UI library
|
|
14
|
+
|
|
15
|
+
## Coding Standards
|
|
16
|
+
|
|
17
|
+
### TypeScript Standards
|
|
18
|
+
|
|
19
|
+
- Use **strict mode** in tsconfig.json
|
|
20
|
+
- Prefer type assertions over `any`: `value as ContentItem`
|
|
21
|
+
- Use discriminated unions for complex state management
|
|
22
|
+
- Enable strict null checks and strict function types
|
|
23
|
+
|
|
24
|
+
### Naming Conventions
|
|
25
|
+
|
|
26
|
+
- **Variables/Functions**: camelCase (`getUserData()`, `isLoading`, `currentUser`)
|
|
27
|
+
- **Components**: PascalCase (`SitecoreComponent`, `PageLayout`, `ContentBlock`)
|
|
28
|
+
- **Constants**: UPPER_SNAKE_CASE (`API_ENDPOINT`, `DEFAULT_TIMEOUT`)
|
|
29
|
+
- **Directories**: kebab-case (`src/components`, `src/api-clients`)
|
|
30
|
+
- **Types/Interfaces**: PascalCase (`ContentItem`, `LayoutProps`, `SitecoreConfig`)
|
|
31
|
+
|
|
32
|
+
### Modular Layout
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
src/
|
|
36
|
+
components/ # UI components (React)
|
|
37
|
+
lib/ # Configuration and utilities
|
|
38
|
+
pages/ # Next.js pages
|
|
39
|
+
assets/ # Static assets and styles
|
|
40
|
+
types/ # TypeScript type definitions
|
|
41
|
+
hooks/ # Custom React hooks
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Library Usage
|
|
45
|
+
|
|
46
|
+
### @sitecore-content-sdk
|
|
47
|
+
|
|
48
|
+
- Use `SitecoreClient` for content fetching
|
|
49
|
+
- Implement proper error handling with try/catch blocks
|
|
50
|
+
- Cache API responses using React Query or SWR
|
|
51
|
+
- Handle content preview vs. published content scenarios
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { SitecoreClient } from '@sitecore-content-sdk/nextjs/client';
|
|
55
|
+
import scConfig from 'sitecore.config';
|
|
56
|
+
|
|
57
|
+
const client = new SitecoreClient({
|
|
58
|
+
...scConfig,
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### React Patterns
|
|
63
|
+
|
|
64
|
+
- Use **Server Components** for data fetching and static content
|
|
65
|
+
- Use **Client Components** for interactivity (use 'use client')
|
|
66
|
+
- Implement proper error boundaries
|
|
67
|
+
- Use React.memo for expensive components
|
|
68
|
+
- Leverage useCallback and useMemo for performance optimization
|
|
69
|
+
|
|
70
|
+
### Sitecore Field Components
|
|
71
|
+
|
|
72
|
+
- Always use Sitecore field components: `<Text>`, `<RichText>`, `<Image>`
|
|
73
|
+
- Validate field existence before rendering
|
|
74
|
+
- Handle empty/null fields gracefully
|
|
75
|
+
- Prefer Sitecore field components over manual rendering
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
// Good: Using Sitecore field components
|
|
79
|
+
<Text field={fields?.title} tag="h1" />
|
|
80
|
+
<RichText field={fields?.content} />
|
|
81
|
+
<Image field={fields?.backgroundImage} />
|
|
82
|
+
|
|
83
|
+
// Avoid: Manual field value extraction unless necessary
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Example Patterns and Prompts
|
|
87
|
+
|
|
88
|
+
### Component Development
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// Component props interface
|
|
92
|
+
interface HeroProps {
|
|
93
|
+
fields: {
|
|
94
|
+
title: Field;
|
|
95
|
+
subtitle: Field;
|
|
96
|
+
backgroundImage: Field;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default function Hero({ fields }: HeroProps) {
|
|
101
|
+
return (
|
|
102
|
+
<div>
|
|
103
|
+
<Text field={fields?.title} tag="h1" />
|
|
104
|
+
<Text field={fields?.subtitle} tag="p" />
|
|
105
|
+
<Image field={fields?.backgroundImage} />
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Error Handling
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
async function fetchPageData(path: string): Promise<Page | null> {
|
|
115
|
+
if (!path) {
|
|
116
|
+
throw new Error('Page path is required');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
const pageData = await client.getPage(path);
|
|
121
|
+
return pageData;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
throw new SitecoreFetchError(`Failed to fetch page data for ${path}`, error);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Configuration
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// sitecore.config.ts
|
|
132
|
+
import { defineConfig } from '@sitecore-content-sdk/nextjs/config';
|
|
133
|
+
|
|
134
|
+
export default defineConfig({
|
|
135
|
+
api: {
|
|
136
|
+
edge: {
|
|
137
|
+
contextId: process.env.SITECORE_EDGE_CONTEXT_ID || '',
|
|
138
|
+
clientContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID,
|
|
139
|
+
edgeUrl: process.env.SITECORE_EDGE_URL || 'https://edge-platform.sitecorecloud.io',
|
|
140
|
+
},
|
|
141
|
+
local: {
|
|
142
|
+
apiKey: process.env.SITECORE_API_KEY || '',
|
|
143
|
+
apiHost: process.env.SITECORE_API_HOST || '',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
defaultSite: process.env.NEXT_PUBLIC_DEFAULT_SITE_NAME || 'default',
|
|
147
|
+
defaultLanguage: process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE || 'en',
|
|
148
|
+
editingSecret: process.env.SITECORE_EDITING_SECRET,
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Development Workflow
|
|
153
|
+
|
|
154
|
+
1. **Install dependencies**: `npm install`
|
|
155
|
+
2. **Configure environment**: Copy `.env.example` to `.env.local`
|
|
156
|
+
3. **Start development**: `npm run dev`
|
|
157
|
+
4. **Build for production**: `npm run build`
|
|
158
|
+
|
|
159
|
+
## Best Practices
|
|
160
|
+
|
|
161
|
+
### Performance
|
|
162
|
+
|
|
163
|
+
- Optimize images using Next.js Image component
|
|
164
|
+
- Implement proper loading states
|
|
165
|
+
- Cache expensive operations appropriately
|
|
166
|
+
- Consider server-side rendering implications
|
|
167
|
+
- Lazy-load non-critical modules
|
|
168
|
+
|
|
169
|
+
### Security
|
|
170
|
+
|
|
171
|
+
- Sanitize user inputs before processing
|
|
172
|
+
- Validate data at application boundaries
|
|
173
|
+
- Use HTTPS for all Sitecore connections
|
|
174
|
+
- Never expose sensitive configuration in client-side code
|
|
175
|
+
- Escape content when rendering to prevent XSS
|
|
176
|
+
|
|
177
|
+
### Code Quality
|
|
178
|
+
|
|
179
|
+
- Follow DRY principle - extract common functionality
|
|
180
|
+
- Use SOLID principles for maintainable code
|
|
181
|
+
- Write self-documenting code with clear intent
|
|
182
|
+
- Implement proper error boundaries
|
|
183
|
+
- Test behavior, not implementation details
|