create-content-sdk-app 2.0.0 → 2.0.1

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.
Files changed (84) hide show
  1. package/dist/templates/nextjs/.agents/skills/content-sdk-component-data-strategy/SKILL.md +37 -0
  2. package/dist/templates/nextjs/.agents/skills/content-sdk-component-registration/SKILL.md +36 -0
  3. package/dist/templates/nextjs/.agents/skills/content-sdk-component-scaffold/SKILL.md +34 -0
  4. package/dist/templates/nextjs/.agents/skills/content-sdk-component-variants/SKILL.md +36 -0
  5. package/dist/templates/nextjs/.agents/skills/content-sdk-dictionary-and-i18n/SKILL.md +35 -0
  6. package/dist/templates/nextjs/.agents/skills/content-sdk-editing-safe-rendering/SKILL.md +37 -0
  7. package/dist/templates/nextjs/.agents/skills/content-sdk-field-usage-image-link-text/SKILL.md +36 -0
  8. package/dist/templates/nextjs/.agents/skills/content-sdk-graphql-data-fetching/SKILL.md +38 -0
  9. package/dist/templates/nextjs/.agents/skills/content-sdk-multisite-management/SKILL.md +37 -0
  10. package/dist/templates/nextjs/.agents/skills/content-sdk-route-configuration/SKILL.md +38 -0
  11. package/dist/templates/nextjs/.agents/skills/content-sdk-site-setup-and-env/SKILL.md +36 -0
  12. package/dist/templates/nextjs/.agents/skills/content-sdk-sitemap-robots/SKILL.md +37 -0
  13. package/dist/templates/nextjs/.agents/skills/content-sdk-troubleshoot-editing/SKILL.md +39 -0
  14. package/dist/templates/nextjs/.agents/skills/content-sdk-upgrade-assistant/SKILL.md +36 -0
  15. package/dist/templates/nextjs/AGENTS.md +1 -0
  16. package/dist/templates/nextjs/CLAUDE.md +6 -170
  17. package/dist/templates/nextjs/Skills.md +79 -0
  18. package/dist/templates/nextjs/package.json +2 -2
  19. package/dist/templates/nextjs/src/Bootstrap.tsx +20 -13
  20. package/dist/templates/nextjs/src/byoc/index.tsx +1 -1
  21. package/dist/templates/nextjs/src/components/content-sdk/CdpPageView.tsx +1 -1
  22. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-component-data-strategy/SKILL.md +37 -0
  23. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-component-registration/SKILL.md +38 -0
  24. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-component-scaffold/SKILL.md +38 -0
  25. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-component-variants/SKILL.md +36 -0
  26. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-dictionary-and-i18n/SKILL.md +37 -0
  27. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-editing-safe-rendering/SKILL.md +37 -0
  28. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-field-usage-image-link-text/SKILL.md +36 -0
  29. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-graphql-data-fetching/SKILL.md +37 -0
  30. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-multisite-management/SKILL.md +37 -0
  31. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-route-configuration/SKILL.md +38 -0
  32. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-site-setup-and-env/SKILL.md +36 -0
  33. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-sitemap-robots/SKILL.md +37 -0
  34. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-troubleshoot-editing/SKILL.md +39 -0
  35. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-upgrade-assistant/SKILL.md +36 -0
  36. package/dist/templates/nextjs-app-router/.sitecore/import-map.server.ts +2 -2
  37. package/dist/templates/nextjs-app-router/AGENTS.md +6 -6
  38. package/dist/templates/nextjs-app-router/CLAUDE.md +6 -271
  39. package/dist/templates/nextjs-app-router/README.md +0 -36
  40. package/dist/templates/nextjs-app-router/Skills.md +79 -0
  41. package/dist/templates/nextjs-app-router/package.json +3 -2
  42. package/dist/templates/nextjs-app-router/src/Bootstrap.tsx +20 -12
  43. package/dist/templates/nextjs-app-router/src/app/[site]/[locale]/[[...path]]/layout.tsx +19 -0
  44. package/dist/templates/nextjs-app-router/src/app/[site]/[locale]/[[...path]]/not-found.tsx +3 -28
  45. package/dist/templates/nextjs-app-router/src/app/[site]/[locale]/[[...path]]/page.tsx +6 -21
  46. package/dist/templates/nextjs-app-router/src/app/[site]/layout.tsx +5 -21
  47. package/dist/templates/nextjs-app-router/src/app/not-found.tsx +1 -23
  48. package/dist/templates/nextjs-app-router/src/byoc/index.tsx +1 -1
  49. package/dist/templates/nextjs-app-router/src/components/content-sdk/CdpPageView.tsx +1 -1
  50. package/package.json +2 -2
  51. package/dist/initializers/angular/args.js +0 -2
  52. package/dist/initializers/angular/index.js +0 -30
  53. package/dist/initializers/angular/prompts.js +0 -20
  54. package/dist/templates/angular/.postcssrc.json +0 -5
  55. package/dist/templates/angular/.vscode/extensions.json +0 -4
  56. package/dist/templates/angular/README.md +0 -3
  57. package/dist/templates/angular/angular.json +0 -79
  58. package/dist/templates/angular/package.json +0 -58
  59. package/dist/templates/angular/public/favicon.ico +0 -0
  60. package/dist/templates/angular/src/app/app.config.server.ts +0 -12
  61. package/dist/templates/angular/src/app/app.config.ts +0 -31
  62. package/dist/templates/angular/src/app/app.css +0 -0
  63. package/dist/templates/angular/src/app/app.html +0 -1
  64. package/dist/templates/angular/src/app/app.routes.server.ts +0 -15
  65. package/dist/templates/angular/src/app/app.routes.ts +0 -28
  66. package/dist/templates/angular/src/app/app.ts +0 -12
  67. package/dist/templates/angular/src/app/loaders/error.loader.ts +0 -12
  68. package/dist/templates/angular/src/app/loaders/index.ts +0 -14
  69. package/dist/templates/angular/src/app/loaders/not-found.loader.ts +0 -12
  70. package/dist/templates/angular/src/app/loaders/page.loader.ts +0 -15
  71. package/dist/templates/angular/src/app/loaders/stub-utils.ts +0 -83
  72. package/dist/templates/angular/src/app/pages/error.component.ts +0 -124
  73. package/dist/templates/angular/src/app/pages/not-found.component.ts +0 -85
  74. package/dist/templates/angular/src/app/pages/page.component.ts +0 -58
  75. package/dist/templates/angular/src/app/shared/layout.component.ts +0 -106
  76. package/dist/templates/angular/src/index.html +0 -13
  77. package/dist/templates/angular/src/main.server.ts +0 -8
  78. package/dist/templates/angular/src/main.ts +0 -6
  79. package/dist/templates/angular/src/server.ts +0 -65
  80. package/dist/templates/angular/src/styles.css +0 -3
  81. package/dist/templates/angular/tsconfig.json +0 -38
  82. package/dist/templates/angular/tsconfig.spec.json +0 -10
  83. package/dist/templates/nextjs/LLMs.txt +0 -179
  84. package/dist/templates/nextjs-app-router/LLMs.txt +0 -236
@@ -1,173 +1,9 @@
1
- # Claude Code Agent Guide for Sitecore Content SDK Next.js Project
1
+ # Claude Code Sitecore Content SDK Next.js (Pages Router) App
2
2
 
3
- ## Project Purpose and Tech Stack
3
+ At the start of every session, read these files for full project guidance:
4
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.
5
+ 1. **`AGENTS.md`** Canonical source of truth for this app: overview, commands, application structure, middleware, SitecoreClient, catch-all route, i18n, DO/DON'T, guardrails, boundaries
6
+ 2. **`.cursor/rules/`** — Coding rules for this template: general, javascript, sitecore, project-setup
7
+ 3. **`Skills.md`** and **`.agents/skills/`** — Capability-specific guidance (component registration, data fetching, editing, i18n, etc.) for tools that support the [Agent Skills](https://agentskills.io) standard.
6
8
 
7
- ### Key Technologies
8
- - **Next.js** - React framework with SSR/SSG capabilities
9
- - **Sitecore Content SDK** - Official SDK for Sitecore XM Cloud integration
10
- - **TypeScript** - Type-safe JavaScript development
11
- - **Sitecore XM Cloud** - Headless CMS platform
12
- - **React** - Component-based UI library
13
-
14
- ## Coding Standards
15
-
16
- ### TypeScript Standards
17
- - Use **strict mode** in tsconfig.json
18
- - Prefer type assertions over `any`: `value as ContentItem`
19
- - Use discriminated unions for complex state management
20
- - Enable strict null checks and strict function types
21
-
22
- ### Naming Conventions
23
- - **Variables/Functions**: camelCase (`getUserData()`, `isLoading`, `currentUser`)
24
- - **Components**: PascalCase (`SitecoreComponent`, `PageLayout`, `ContentBlock`)
25
- - **Constants**: UPPER_SNAKE_CASE (`API_ENDPOINT`, `DEFAULT_TIMEOUT`)
26
- - **Directories**: kebab-case (`src/components`, `src/api-clients`)
27
- - **Types/Interfaces**: PascalCase (`ContentItem`, `LayoutProps`, `SitecoreConfig`)
28
-
29
- ### Modular Layout
30
- ```
31
- src/
32
- components/ # UI components (React)
33
- lib/ # Configuration and utilities
34
- pages/ # Next.js pages
35
- assets/ # Static assets and styles
36
- types/ # TypeScript type definitions
37
- hooks/ # Custom React hooks
38
- ```
39
-
40
- ## Library Usage
41
-
42
- ### @sitecore-content-sdk
43
- - Use `SitecoreClient` for content fetching
44
- - Implement proper error handling with try/catch blocks
45
- - Cache API responses using React Query or SWR
46
- - Handle content preview vs. published content scenarios
47
-
48
- ```typescript
49
- import { SitecoreClient } from '@sitecore-content-sdk/nextjs/client';
50
- import scConfig from 'sitecore.config';
51
-
52
- const client = new SitecoreClient({
53
- ...scConfig,
54
- });
55
- ```
56
-
57
- ### React Patterns
58
- - Use **Server Components** for data fetching and static content
59
- - Use **Client Components** for interactivity (use 'use client')
60
- - Implement proper error boundaries
61
- - Use React.memo for expensive components
62
- - Leverage useCallback and useMemo for performance optimization
63
-
64
- ### Sitecore Field Components
65
- - Always use Sitecore field components: `<Text>`, `<RichText>`, `<Image>`
66
- - Validate field existence before rendering
67
- - Handle empty/null fields gracefully
68
- - Prefer Sitecore field components over manual rendering
69
-
70
- ```typescript
71
- // Good: Using Sitecore field components
72
- <Text field={fields?.title} tag="h1" />
73
- <RichText field={fields?.content} />
74
- <Image field={fields?.backgroundImage} />
75
-
76
- // Avoid: Manual field value extraction unless necessary
77
- ```
78
-
79
- ## Example Patterns and Prompts
80
-
81
- ### Component Development
82
- ```typescript
83
- // Component props interface
84
- interface HeroProps {
85
- fields: {
86
- title: Field;
87
- subtitle: Field;
88
- backgroundImage: Field;
89
- };
90
- }
91
-
92
- export default function Hero({ fields }: HeroProps) {
93
- return (
94
- <div>
95
- <Text field={fields?.title} tag="h1" />
96
- <Text field={fields?.subtitle} tag="p" />
97
- <Image field={fields?.backgroundImage} />
98
- </div>
99
- );
100
- }
101
- ```
102
-
103
- ### Error Handling
104
- ```typescript
105
- async function fetchPageData(path: string): Promise<Page | null> {
106
- if (!path) {
107
- throw new Error('Page path is required');
108
- }
109
-
110
- try {
111
- const pageData = await client.getPage(path);
112
- return pageData;
113
- } catch (error) {
114
- throw new SitecoreFetchError(`Failed to fetch page data for ${path}`, error);
115
- }
116
- }
117
- ```
118
-
119
- ### Configuration
120
- ```typescript
121
- // sitecore.config.ts
122
- import { defineConfig } from '@sitecore-content-sdk/nextjs/config';
123
-
124
- export default defineConfig({
125
- api: {
126
- edge: {
127
- contextId: process.env.SITECORE_EDGE_CONTEXT_ID || '',
128
- clientContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID,
129
- edgeUrl:
130
- process.env.NEXT_PUBLIC_SITECORE_EDGE_PLATFORM_HOSTNAME ||
131
- process.env.SITECORE_EDGE_PLATFORM_HOSTNAME ||
132
- 'https://edge-platform.sitecorecloud.io',
133
- },
134
- local: {
135
- apiKey: process.env.SITECORE_API_KEY || '',
136
- apiHost: process.env.SITECORE_API_HOST || '',
137
- },
138
- },
139
- defaultSite: process.env.NEXT_PUBLIC_DEFAULT_SITE_NAME || 'default',
140
- defaultLanguage: process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE || 'en',
141
- editingSecret: process.env.SITECORE_EDITING_SECRET,
142
- });
143
- ```
144
-
145
- ## Development Workflow
146
-
147
- 1. **Install dependencies**: `npm install`
148
- 2. **Configure environment**: Copy `.env.example` to `.env.local`
149
- 3. **Start development**: `npm run dev`
150
- 4. **Build for production**: `npm run build`
151
-
152
- ## Best Practices
153
-
154
- ### Performance
155
- - Optimize images using Next.js Image component
156
- - Implement proper loading states
157
- - Cache expensive operations appropriately
158
- - Consider server-side rendering implications
159
- - Lazy-load non-critical modules
160
-
161
- ### Security
162
- - Sanitize user inputs before processing
163
- - Validate data at application boundaries
164
- - Use HTTPS for all Sitecore connections
165
- - Never expose sensitive configuration in client-side code
166
- - Escape content when rendering to prevent XSS
167
-
168
- ### Code Quality
169
- - Follow DRY principle - extract common functionality
170
- - Use SOLID principles for maintainable code
171
- - Write self-documenting code with clear intent
172
- - Implement proper error boundaries
173
- - Test behavior, not implementation details
9
+ This file applies to **this scaffolded head application only**. For the Content SDK monorepo (packages, CLI, templates source), use that repo's root `AGENTS.md` and `.cursor/rules/`.
@@ -0,0 +1,79 @@
1
+ # Skills.md — Capability groupings for this app (Next.js Pages Router)
2
+
3
+ This file describes **this application** in terms of **capability-style groupings**: high-level areas that help AI tools and developers map tasks to the right part of the app. This is a Pages Router app with `pages/[[...path]].tsx`, Next.js i18n, and a single component map. For concrete steps and patterns, see [AGENTS.md](AGENTS.md) and the [official Content SDK documentation](https://doc.sitecore.com/xmc/en/developers/content-sdk/sitecore-content-sdk-for-xm-cloud.html).
4
+
5
+ **Agent Skills:** Each grouping is also available as a skill in [.agents/skills/](.agents/skills/) in the standard [Agent Skills](https://agentskills.io) format (`SKILL.md` per capability). Tools that support this standard load skills from `.agents/skills/`; Cursor's built-in skills use `.cursor/skills/` unless it also supports the Agent Skills standard. The skills here are tailored for **Pages Router** (e.g. extractPath, context.locale, getComponentData, single component-map.ts).
6
+
7
+ ---
8
+
9
+ ## Why capability grouping
10
+
11
+ Grouping related capabilities makes it easier to know which area of the app applies to a given task and to point to the right docs and patterns. Map the task to one or more of the groupings below; use AGENTS.md and the official docs for concrete steps.
12
+
13
+ ---
14
+
15
+ ## Capability groupings
16
+
17
+ ### content-sdk-component-scaffold
18
+
19
+ Creating new Sitecore components: file structure, props interface, and placement under `src/components/`. Use when adding a new component from scratch. Register in `.sitecore/component-map.ts`.
20
+
21
+ ### content-sdk-component-registration
22
+
23
+ Registering components in `.sitecore/component-map.ts` only. Required so layout and editing can resolve and render components. Used by getComponentData and editing API routes. Pages Router has a single map.
24
+
25
+ ### content-sdk-editing-safe-rendering
26
+
27
+ Safe rendering in XM Cloud editing and preview: `context.preview` and `context.previewData`, editing chromes, and design library. Use when ensuring components work in the Sitecore editor and preview. Use `client.getPreview(context.previewData)` or `client.getDesignLibraryData(context.previewData)` when in preview.
28
+
29
+ ### content-sdk-field-usage-image-link-text
30
+
31
+ Using SDK field components: `<Text>`, `<RichText>`, `<Image>`, `<Link>`, with proper validation and fallbacks. Use when rendering Sitecore fields.
32
+
33
+ ### content-sdk-graphql-data-fetching
34
+
35
+ Page, dictionary, and component data via the single Sitecore client in `src/lib/sitecore-client.ts`. Use `getPage(path, { locale: context.locale })`, then `getDictionary({ site: page.siteName, locale: page.locale })` and `getComponentData(page.layout, context, components)`. For SSG use `getPagePaths(sites, context?.locales)`.
36
+
37
+ ### content-sdk-route-configuration
38
+
39
+ Routing: single catch-all at `src/pages/[[...path]].tsx`. Path from `extractPath(context)`; locale from `context.locale`. Layout and page data flow via getStaticProps/getServerSideProps to _app and Layout.tsx. No [site]/[locale] in path; site resolved by middleware.
40
+
41
+ ### content-sdk-site-setup-and-env
42
+
43
+ Site and environment: `sitecore.config.ts`, environment variables, default site and language. Document vars in `.env.example` only; never commit `.env` or `.env.local`.
44
+
45
+ ### content-sdk-multisite-management
46
+
47
+ Multisite: `.sitecore/sites.json`, proxy in `src/proxy.ts`. Chain order is **fixed:** MultisiteProxy → RedirectsProxy → PersonalizeProxy. Do not change proxy order.
48
+
49
+ ### content-sdk-dictionary-and-i18n
50
+
51
+ Dictionary and i18n: Next.js i18n in `next.config.js` (i18n.locales, defaultLocale). Per-request locale is `context.locale` in getStaticProps/getServerSideProps. Fetch dictionary with `client.getDictionary({ site: page.siteName, locale: page.locale })` after getPage.
52
+
53
+ ### content-sdk-sitemap-robots
54
+
55
+ Sitemap and robots: `src/pages/api/sitemap.ts` and `src/pages/api/robots.ts` with `SitemapMiddleware(scClient, sites).getHandler()` and `RobotsMiddleware(scClient, sites).getHandler()`. Rewrites in next.config.js for /sitemap*.xml and /robots.txt.
56
+
57
+ ### content-sdk-component-variants
58
+
59
+ Component variants: different renderings or data-driven variants of the same component type. Use when one component has multiple presentations. Register in `.sitecore/component-map.ts`; getComponentData resolves props.
60
+
61
+ ### content-sdk-troubleshoot-editing
62
+
63
+ Troubleshooting XM Cloud editing, preview, and design library. Use when editing or preview does not behave as expected. Check context.preview, context.previewData, and editing API routes (config, render, feaas/render).
64
+
65
+ ### content-sdk-upgrade-assistant
66
+
67
+ Upgrading @sitecore-content-sdk/* packages: version bumps, breaking changes, migration steps. Use when moving to a newer SDK version. Check the Content SDK repo CHANGELOG and upgrade guides.
68
+
69
+ ### content-sdk-component-data-strategy
70
+
71
+ Component data: after getPage, use `client.getComponentData(page.layout, context, components)` to resolve component props; pass result to layout renderer. All Sitecore-driven component data goes through this flow. BYOC must be registered in `.sitecore/component-map.ts`.
72
+
73
+ ---
74
+
75
+ ## How to use this
76
+
77
+ Map the task to one or more groupings above. Use [AGENTS.md](AGENTS.md) for app-level instructions and the [official documentation](https://doc.sitecore.com/xmc/en/developers/content-sdk/sitecore-content-sdk-for-xm-cloud.html) for APIs.
78
+
79
+ **If your tool supports Agent Skills:** Load skills from [.agents/skills/](.agents/skills/) (one folder per capability). They provide when-to-use, hard rules, and stop conditions tailored for this Pages Router app.
@@ -22,9 +22,9 @@
22
22
  },
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@sitecore-cloudsdk/core": "^0.5.1",
26
- "@sitecore-cloudsdk/events": "^0.5.1",
27
25
  "@sitecore-content-sdk/nextjs": "<%- version %>",
26
+ "@sitecore-content-sdk/analytics-core": "<%- version %>",
27
+ "@sitecore-content-sdk/events": "<%- version %>",
28
28
  "@sitecore-feaas/clientside": "^0.6.0",
29
29
  "@sitecore/components": "~2.1.0",
30
30
  "next": "^16.1.1",
@@ -1,8 +1,8 @@
1
1
  import { useEffect, JSX } from 'react';
2
- import { CloudSDK } from '@sitecore-cloudsdk/core/browser';
3
- import { SitecorePageProps } from '@sitecore-content-sdk/nextjs';
4
- import '@sitecore-cloudsdk/events/browser';
2
+ import { SitecorePageProps, initContentSdk } from '@sitecore-content-sdk/nextjs';
5
3
  import config from 'sitecore.config';
4
+ import { eventsPlugin } from '@sitecore-content-sdk/events';
5
+ import { analyticsBrowserAdapter, analyticsPlugin } from '@sitecore-content-sdk/analytics-core';
6
6
 
7
7
  /**
8
8
  * The Bootstrap component is the entry point for performing any initialization logic
@@ -26,16 +26,23 @@ const Bootstrap = (props: SitecorePageProps): JSX.Element | null => {
26
26
  console.debug('Browser Events SDK is not initialized in edit and preview modes');
27
27
  } else {
28
28
  if (config.api.edge?.clientContextId) {
29
- CloudSDK({
30
- sitecoreEdgeUrl: config.api.edge.edgeUrl,
31
- sitecoreEdgeContextId: config.api.edge.clientContextId,
32
- siteName: page.siteName || config.defaultSite,
33
- enableBrowserCookie: true,
34
- // Replace with the top level cookie domain of the website that is being integrated e.g ".example.com" and not "www.example.com"
35
- cookieDomain: window.location.hostname.replace(/^www\./, ''),
36
- })
37
- .addEvents()
38
- .initialize();
29
+ initContentSdk({
30
+ config: {
31
+ contextId: config.api.edge.clientContextId,
32
+ edgeUrl: config.api.edge.edgeUrl,
33
+ siteName: page.siteName || config.defaultSite,
34
+ },
35
+ plugins: [
36
+ analyticsPlugin({
37
+ options: {
38
+ enableCookie: true,
39
+ cookieDomain: window.location.hostname.replace(/^www\./, ''),
40
+ },
41
+ adapter: analyticsBrowserAdapter(),
42
+ }),
43
+ eventsPlugin(),
44
+ ],
45
+ });
39
46
  } else {
40
47
  console.error('Client Edge API settings missing from configuration');
41
48
  }
@@ -1,6 +1,6 @@
1
1
  import React, { JSX } from 'react';
2
2
  import * as FEAAS from '@sitecore-feaas/clientside/react';
3
- import * as Events from '@sitecore-cloudsdk/events/browser';
3
+ import * as Events from '@sitecore-content-sdk/events';
4
4
  import { LayoutServicePageState, SitecoreProviderReactContext } from '@sitecore-content-sdk/nextjs';
5
5
  import '@sitecore/components/context';
6
6
  import dynamic from 'next/dynamic';
@@ -1,6 +1,6 @@
1
1
  import { CdpHelper, useSitecore } from '@sitecore-content-sdk/nextjs';
2
2
  import { useEffect, JSX } from 'react';
3
- import { pageView } from '@sitecore-cloudsdk/events/browser';
3
+ import { pageView } from '@sitecore-content-sdk/events';
4
4
  import config from 'sitecore.config';
5
5
 
6
6
  /**
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: content-sdk-component-data-strategy
3
+ description: Component data for App Router: layout data from getPage (or getPreview/getDesignLibraryData in editing). No getComponentData; pass site and locale from route params. Server Components use the client in server context; Client Components receive serializable props. Use when wiring component data or BYOC.
4
+ ---
5
+
6
+ # Content SDK Component Data Strategy (App Router)
7
+
8
+ This app does **not** use getComponentData. Page and layout data come from **getPage** (or getPreview/getDesignLibraryData in editing). Component props are derived from the layout/placeholders; pass site and locale from route params.
9
+
10
+ ## When to Use
11
+
12
+ - User asks how to pass data to components, wire component props, or integrate custom/BYOC components.
13
+ - Task involves component props, server vs client components, or BYOC.
14
+ - User mentions "component data," "props," "BYOC," "server component," or "client component."
15
+
16
+ ## How to perform
17
+
18
+ - Fetch at page/layout with getPage (or getPreview/getDesignLibraryData in draft). Pass site and locale from route params. Server Components use the client in server context; Client Components receive serializable props only. Register BYOC in the correct component map and pass props from layout.
19
+
20
+ ## Hard Rules
21
+
22
+ - **Data source:** Page and layout from `client.getPage(path ?? [], { site, locale })` in the catch-all page (or getPreview/getDesignLibraryData when draftMode() is enabled). All Sitecore-driven data flows from this single fetch at the route level.
23
+ - **Server Components:** Use the same SitecoreClient in server context (e.g. in the page or layout). Pass data as props to children.
24
+ - **Client Components:** Receive **serializable** props from parent (no functions or non-serializable values). Do not create a new client inside components. Pass data from page/layout level into components.
25
+ - **BYOC or custom components:** Must be registered in the appropriate component map (.sitecore/component-map.ts or component-map.client.ts) and receive props in the shape the layout expects (e.g. fields, params).
26
+ - Do not fetch layout or page data inside a child component (e.g. another getPage call); fetch at page/layout level and pass props.
27
+
28
+ ## Stop Conditions
29
+
30
+ - Stop if the user wants to fetch page/layout data inside a child component; recommend fetching at page/layout level and passing props.
31
+ - Stop if server/client boundary is ambiguous and the change could cause "use client" or serialization issues; clarify and follow Next.js and app conventions.
32
+ - Do not introduce getComponentData or duplicate getPage logic; this app uses getPage-only data flow.
33
+
34
+ ## References
35
+
36
+ - content-sdk-graphql-data-fetching and [AGENTS.md](../../../AGENTS.md) for getPage and data flow.
37
+ - [Official Content SDK docs](https://doc.sitecore.com/xmc/en/developers/content-sdk/sitecore-content-sdk-for-xm-cloud.html).
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: content-sdk-component-registration
3
+ description: Registers Sitecore components in the component map so layout and editing can resolve them. App Router uses .sitecore/component-map.ts (Server) and .sitecore/component-map.client.ts (Client). Use when registering a new component or when layout/editor cannot find a component.
4
+ ---
5
+
6
+ # Content SDK Component Registration (App Router)
7
+
8
+ Register components in the Sitecore component maps so the layout and editing pipeline can resolve and render them. This app has **two** maps: server and client.
9
+
10
+ ## When to Use
11
+
12
+ - After scaffolding or adding a new Sitecore component (must be registered).
13
+ - User reports a component not rendering, "component not found," or layout/placeholder showing raw component name.
14
+ - Task involves `.sitecore/component-map.ts` or `.sitecore/component-map.client.ts`.
15
+ - User asks how to register a component or fix component resolution.
16
+
17
+ ## How to perform
18
+
19
+ - Open `.sitecore/component-map.ts` (Server) or `.sitecore/component-map.client.ts` (Client). Add an entry mapping the layout component name to the React component import. Keep keys consistent with layout and existing map entries.
20
+
21
+ ## Hard Rules
22
+
23
+ - Every component rendered from Sitecore layout must be registered. Keep the maps in sync with `src/components/`.
24
+ - **Server components** (no `'use client'`): Register in `.sitecore/component-map.ts` only.
25
+ - **Client components** (`'use client'`): Register in `.sitecore/component-map.client.ts` only. Editing API routes use both maps (e.g. `clientComponents` from the client map).
26
+ - Use consistent component names (same key in map as used in layout). Follow existing naming in the maps.
27
+ - Do not remove or rename registrations without updating all references (layout, editing routes).
28
+
29
+ ## Stop Conditions
30
+
31
+ - Stop if it is unclear whether the new component is Server or Client; ask or follow app convention.
32
+ - Stop if modifying the maps would break existing layout or editing; suggest a safe change or ask for confirmation.
33
+ - Do not edit `.sitecore/metadata.json` or import-map unless the task explicitly requires it.
34
+
35
+ ## References
36
+
37
+ - [AGENTS.md](../../../AGENTS.md) for component maps and editing routes.
38
+ - [Official Content SDK docs](https://doc.sitecore.com/xmc/en/developers/content-sdk/sitecore-content-sdk-for-xm-cloud.html).
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: content-sdk-component-scaffold
3
+ description: Creates new Sitecore components with correct file structure, props interface, and placement under src/components/. Use when adding a new component from scratch or scaffolding a component. App Router: decide Server vs Client and register in the appropriate map.
4
+ ---
5
+
6
+ # Content SDK Component Scaffold (App Router)
7
+
8
+ Scaffold new Sitecore components so they integrate with the layout and editing pipeline. This app uses App Router with separate server and client component maps.
9
+
10
+ ## When to Use
11
+
12
+ - User asks to add a new Sitecore component, create a component from scratch, or scaffold a component.
13
+ - Task involves creating a new React component that will be rendered from Sitecore layout/placeholders.
14
+ - User mentions "new component," "add component," or "component file structure."
15
+
16
+ ## How to perform
17
+
18
+ - Create a new file under `src/components/` (or existing feature folder). Define props (fields, params), export a single default component.
19
+ - Decide Server vs Client: default Server; add `'use client'` only if the component needs hooks or event handlers.
20
+ - Register the component in the correct map (content-sdk-component-registration). Run `npm run build` to verify.
21
+
22
+ ## Hard Rules
23
+
24
+ - Place components under `src/components/`. Use existing folder conventions.
25
+ - Define a props interface with the component's fields (e.g. `fields: { title: Field; ... }`) and any params. Use types from `@sitecore-content-sdk/react` or the app's types.
26
+ - Export a single default component; one component per file unless the app pattern differs.
27
+ - **Server vs Client:** Use Server Components by default. Add `'use client'` only for interactivity (hooks, event handlers). Register Server components in `.sitecore/component-map.ts`; Client components in `.sitecore/component-map.client.ts`.
28
+ - After creating the component file, register it in the correct component map (see content-sdk-component-registration). Do not leave the component unregistered.
29
+
30
+ ## Stop Conditions
31
+
32
+ - Stop and ask if the component should be a Server or Client Component when the app does not have a clear convention.
33
+ - Do not create components in `.next/`, `node_modules/`, or build output.
34
+
35
+ ## References
36
+
37
+ - [AGENTS.md](../../../AGENTS.md) for app structure and component maps.
38
+ - [Skills.md](../../../Skills.md) for capability map. [Official Content SDK docs](https://doc.sitecore.com/xmc/en/developers/content-sdk/sitecore-content-sdk-for-xm-cloud.html).
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: content-sdk-component-variants
3
+ description: Implements component variants: different renderings or data-driven variants of the same component type. App Router: register in component-map.ts or component-map.client.ts as appropriate. Use when one component has multiple presentations.
4
+ ---
5
+
6
+ # Content SDK Component Variants (App Router)
7
+
8
+ One component definition can have multiple presentations or data-driven variants. Keep registration and layout aligned. This app does not use getComponentData; layout/placeholder data comes from getPage.
9
+
10
+ ## When to Use
11
+
12
+ - User asks for different "variants," "versions," or "presentations" of a component.
13
+ - Task involves rendering the same component type with different layouts or props based on data (e.g. variant field or style).
14
+ - User mentions "component variants," "variations," or "multiple renderings."
15
+
16
+ ## How to perform
17
+
18
+ - Prefer one component that accepts variant/style via props and branches internally; or multiple map entries if the app pattern uses one key per variant. Use layout/fields/params for variant; register in the correct component map (Server or Client). Align with existing app convention.
19
+
20
+ ## Hard Rules
21
+
22
+ - Prefer a single component registration that accepts variant/style data (e.g. params or fields) and branches internally, over multiple map entries for the same logical component unless the app pattern uses separate registrations per variant.
23
+ - Use props (fields, params) from layout to decide variant; do not rely on global state or URL for variant selection when data comes from Sitecore.
24
+ - Register in `.sitecore/component-map.ts` (Server) or `.sitecore/component-map.client.ts` (Client) as appropriate. If the app uses one key per variant, register each; if one key with variant param, single registration. Follow existing app convention.
25
+ - Keep component maps in sync with src/components/.
26
+
27
+ ## Stop Conditions
28
+
29
+ - Stop if the variant model (one registration vs many) is unclear; ask or follow the app's existing pattern.
30
+ - Do not add new component map entries without ensuring layout and editing can provide the corresponding data.
31
+ - Do not assume variant field names (e.g. "variant," "style") without checking the layout definition.
32
+
33
+ ## References
34
+
35
+ - [AGENTS.md](../../../AGENTS.md) and content-sdk-component-registration for maps.
36
+ - [Official Content SDK docs](https://doc.sitecore.com/xmc/en/developers/content-sdk/sitecore-content-sdk-for-xm-cloud.html).
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: content-sdk-dictionary-and-i18n
3
+ description: Dictionary and i18n for App Router: next-intl with src/i18n/routing.ts and request.ts. Request locale is site_locale; call setRequestLocale in the page; in request.ts parse and load dictionary with client.getDictionary. Use when adding or changing translated content or locale behavior.
4
+ ---
5
+
6
+ # Content SDK Dictionary and i18n (App Router)
7
+
8
+ This app uses **next-intl**. Locale is in the URL as [locale]. Request locale is encoded as `${site}_${locale}` for next-intl.
9
+
10
+ ## When to Use
11
+
12
+ - User asks to add or change translated content, locale, or dictionary.
13
+ - Task involves getDictionary, next-intl, or locale in URL/request.
14
+ - User mentions "dictionary," "i18n," "locale," "translation," or "next-intl."
15
+
16
+ ## How to perform
17
+
18
+ - Locales and routing: `src/i18n/routing.ts`. Request config: `src/i18n/request.ts` — parse `requestLocale` (e.g. `${site}_${locale}`), call `client.getDictionary({ locale, site })`, return `{ locale, messages }`. In the page, call `setRequestLocale(\`${site}_${locale}\`)` at the top. Use a single getDictionary per request.
19
+
20
+ ## Hard Rules
21
+
22
+ - **Config:** `src/i18n/routing.ts` — `defineRouting({ locales, defaultLocale, localePrefix })`. Align `locales` with Sitecore languages (e.g. from sitecore.config.ts defaultLanguage).
23
+ - **Request config:** `src/i18n/request.ts` — `getRequestConfig` receives `requestLocale`. This app uses `${site}_${locale}` (set by `setRequestLocale(\`${site}_${locale}\`)` in the page). Parse requestLocale (e.g. `split('_')`) to get site and locale; load dictionary with `client.getDictionary({ locale, site })` and return `{ locale, messages }`.
24
+ - **In the page:** Call `setRequestLocale(\`${site}_${locale}\`)` at the **top** of the page so next-intl and request config see the correct locale. Do not omit when adding new page branches.
25
+ - **Do not** change the `${site}_${locale}` convention without updating request.ts and all pages that call setRequestLocale.
26
+ - Use a single client.getDictionary per request for the active site/locale. Never assume locale from headers or global state; use route params (site, locale).
27
+
28
+ ## Stop Conditions
29
+
30
+ - Stop if the user wants to change to a different encoding for requestLocale; this affects request.ts and all setRequestLocale call sites.
31
+ - Stop if adding a new locale without confirming it exists in Sitecore and in routing.ts.
32
+ - Do not duplicate dictionary fetching (e.g. in layout and page) without a clear need.
33
+
34
+ ## References
35
+
36
+ - [AGENTS.md](../../../AGENTS.md) for next-intl, setRequestLocale, and getDictionary usage.
37
+ - [Official Content SDK docs](https://doc.sitecore.com/xmc/en/developers/content-sdk/sitecore-content-sdk-for-xm-cloud.html).
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: content-sdk-editing-safe-rendering
3
+ description: Ensures components render safely in XM Cloud editing and preview. App Router uses draftMode() and getPreview/getDesignLibraryData from searchParams. Use when making components work in the Sitecore editor or fixing preview/editing behavior.
4
+ ---
5
+
6
+ # Content SDK Editing-Safe Rendering (App Router)
7
+
8
+ Ensure components behave correctly in XM Cloud editing, preview, and design library. This app uses **draftMode()** and **searchParams** for editing data.
9
+
10
+ ## When to Use
11
+
12
+ - User asks about editing, preview, design library, or "component not working in editor."
13
+ - Task involves draft mode, editing chromes, or design library integration.
14
+ - Fixing issues where components render differently or break in editor vs published.
15
+ - User mentions getPreview, getDesignLibraryData, or editing API routes.
16
+
17
+ ## How to perform
18
+
19
+ - In the page or layout: call `draftMode()`; when enabled, read editing params from searchParams, use `isDesignLibraryPreviewData(editingParams)` to choose getDesignLibraryData vs getPreview; otherwise use getPage. Editing routes: config route uses `createEditingConfigRouteHandler`, render route uses `createEditingRenderRouteHandlers`; set `dynamic = 'force-dynamic'` on both.
20
+
21
+ ## Hard Rules
22
+
23
+ - Use `draftMode()` in Server Components (e.g. in the page or [site] layout). When `draft.isEnabled`, get editing params from **searchParams** and use `isDesignLibraryPreviewData(editingParams)` to distinguish: if true, use `client.getDesignLibraryData(editingParams)`; otherwise use `client.getPreview(editingParams)`. When not in draft mode, use `getPage(path ?? [], { site, locale })`.
24
+ - Do not assume editing/preview context in components that might run in static or non-editing contexts; guard on `draftMode()`.
25
+ - Editing API routes: `src/app/api/editing/config/route.ts` uses `createEditingConfigRouteHandler({ components, clientComponents, metadata })` (import from `.sitecore/component-map`, `.sitecore/component-map.client`, `.sitecore/metadata.json`). `src/app/api/editing/render/route.ts` uses `createEditingRenderRouteHandlers({})`. Set `export const dynamic = 'force-dynamic'` on both. Do not duplicate client creation; config and render routes use the same component maps as the app.
26
+ - Never commit editing secrets; use environment variables and document in .env.example only.
27
+
28
+ ## Stop Conditions
29
+
30
+ - Stop and clarify if the issue is preview vs design library vs published; behavior differs.
31
+ - Do not change proxy or middleware order to "fix" editing; editing is driven by API routes and draft/preview data.
32
+ - Do not recommend disabling secret validation without explicit user request and warning.
33
+
34
+ ## References
35
+
36
+ - [AGENTS.md](../../../AGENTS.md) for data fetching, preview flow, and editing routes.
37
+ - [Official Content SDK docs](https://doc.sitecore.com/xmc/en/developers/content-sdk/sitecore-content-sdk-for-xm-cloud.html).
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: content-sdk-field-usage-image-link-text
3
+ description: Renders Sitecore fields using SDK field components (Text, RichText, Image, Link) with proper validation and fallbacks. Use when rendering content fields or when the user mentions Text, RichText, Image, Link, or field components.
4
+ ---
5
+
6
+ # Content SDK Field Usage (App Router)
7
+
8
+ Use SDK field components to render Sitecore fields with proper validation and fallbacks.
9
+
10
+ ## When to Use
11
+
12
+ - User asks how to render a title, body, image, or link from Sitecore.
13
+ - Task involves displaying content fields, fixing empty/broken images or links, or using RichText/Text/Image/Link components.
14
+ - User mentions "field," "Image," "Link," "Text," "RichText," or "field value."
15
+
16
+ ## How to perform
17
+
18
+ - Use SDK field components: `<Text field={fields?.title} />`, `<RichText field={fields?.content} />`, `<Image field={fields?.image} />`, `<Link field={fields?.link} />`. Guard with `fields?.` when optional; use tag prop on Text when needed. Do not hardcode media or link URLs from Sitecore.
19
+
20
+ ## Hard Rules
21
+
22
+ - Prefer SDK field components over manual field value extraction: `<Text field={fields?.title} />`, `<RichText field={fields?.content} />`, `<Image field={fields?.image} />`, `<Link field={fields?.link} />`. Use tag prop for Text when needed (e.g. tag="h1").
23
+ - Validate or guard field existence before rendering when fields can be optional (e.g. `fields?.title`). Handle null/undefined and empty fields gracefully.
24
+ - Do not hardcode image or link URLs when the data comes from Sitecore; use the field components or helpers that resolve media/URLs.
25
+ - Follow the app's import pattern (e.g. from lib or components).
26
+
27
+ ## Stop Conditions
28
+
29
+ - Stop if the field structure (name or type) is unknown; suggest checking the layout/data shape or asking the user.
30
+ - Do not assume field names (e.g. "title") without confirmation when the template might use different names.
31
+ - Do not commit or log raw field values that might contain PII or secrets.
32
+
33
+ ## References
34
+
35
+ - [AGENTS.md](../../../AGENTS.md) for component and Sitecore patterns.
36
+ - [Official Content SDK docs](https://doc.sitecore.com/xmc/en/developers/content-sdk/sitecore-content-sdk-for-xm-cloud.html).
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: content-sdk-graphql-data-fetching
3
+ description: Fetches page data and dictionary via the single Sitecore client. App Router: getPage(path ?? [], { site, locale }), getDictionary, getAppRouterStaticParams; for preview use draftMode() and getPreview/getDesignLibraryData from searchParams. Use when fetching page or dictionary content.
4
+ ---
5
+
6
+ # Content SDK GraphQL Data Fetching (App Router)
7
+
8
+ All Sitecore data fetching goes through the single client in `src/lib/sitecore-client.ts`. Use getPage, getDictionary, and related methods correctly. This app does **not** use getComponentData; layout data comes from getPage.
9
+
10
+ ## When to Use
11
+
12
+ - User asks how to fetch page data, layout, or dictionary phrases.
13
+ - Task involves getPage, getDictionary, getErrorPage, getPreview, getDesignLibraryData, or getAppRouterStaticParams.
14
+ - User mentions "sitecore client," "Layout Service," "page data," or "dictionary."
15
+
16
+ ## How to perform
17
+
18
+ - Use the client from `src/lib/sitecore-client.ts` only. In the catch-all page: `await params`, then `client.getPage(path ?? [], { site, locale })`. For SSG use `generateStaticParams` and `client.getAppRouterStaticParams(siteNames, locales)`. For preview use `draftMode()` and `getPreview`/`getDesignLibraryData` from searchParams.
19
+
20
+ ## Hard Rules
21
+
22
+ - Use the single SitecoreClient instance in `src/lib/sitecore-client.ts`. Do not create a second client or instantiate SitecoreClient elsewhere.
23
+ - Pass **site** and **locale** from route params (e.g. `await params` in the page). Do not rely on global state for site/locale in server code.
24
+ - **Catch-all page:** `client.getPage(path ?? [], { site, locale })`. Params are a Promise (Next.js 15+); use `await params` to get `{ site, locale, path? }`.
25
+ - **Preview:** Use `draftMode()`; if `draft.isEnabled`, use `client.getPreview(editingParams)` or `client.getDesignLibraryData(editingParams)` from **searchParams**. Otherwise use getPage with site and locale.
26
+ - **SSG:** `generateStaticParams` — use `client.getAppRouterStaticParams(siteNames, locales)` where site names come from `.sitecore/sites.json` (e.g. `sites.map((s) => s.name)`), locales from `src/i18n/routing.ts` (e.g. `routing.locales.slice()`). Return at least one default param when not generating full paths (e.g. `{ site, locale, path: [] }`).
27
+ - Config for the client comes from `sitecore.config.ts`; use environment variables, never hardcode secrets.
28
+
29
+ ## Stop Conditions
30
+
31
+ - Stop if the task requires moving the client to another folder without clear requirement; suggest keeping a single instance in lib.
32
+ - Do not add direct GraphQL or fetch to Layout Service bypassing the client unless the task explicitly requires it.
33
+
34
+ ## References
35
+
36
+ - [AGENTS.md](../../../AGENTS.md) for SitecoreClient, getPage, getDictionary, and SSG.
37
+ - [Official Content SDK docs](https://doc.sitecore.com/xmc/en/developers/content-sdk/sitecore-content-sdk-for-xm-cloud.html).