create-content-sdk-app 2.0.0-canary.8 → 2.0.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/dist/initializers/angular/args.js +2 -0
- package/dist/initializers/angular/index.js +30 -0
- package/dist/initializers/angular/prompts.js +20 -0
- package/dist/templates/angular/.postcssrc.json +5 -0
- package/dist/templates/angular/.vscode/extensions.json +4 -0
- package/dist/templates/angular/README.md +3 -0
- package/dist/templates/angular/angular.json +79 -0
- package/dist/templates/angular/package.json +58 -0
- package/dist/templates/angular/public/favicon.ico +0 -0
- package/dist/templates/angular/src/app/app.config.server.ts +12 -0
- package/dist/templates/angular/src/app/app.config.ts +31 -0
- package/dist/templates/angular/src/app/app.css +0 -0
- package/dist/templates/angular/src/app/app.html +1 -0
- package/dist/templates/angular/src/app/app.routes.server.ts +15 -0
- package/dist/templates/angular/src/app/app.routes.ts +28 -0
- package/dist/templates/angular/src/app/app.ts +12 -0
- package/dist/templates/angular/src/app/loaders/error.loader.ts +12 -0
- package/dist/templates/angular/src/app/loaders/index.ts +14 -0
- package/dist/templates/angular/src/app/loaders/not-found.loader.ts +12 -0
- package/dist/templates/angular/src/app/loaders/page.loader.ts +15 -0
- package/dist/templates/angular/src/app/loaders/stub-utils.ts +83 -0
- package/dist/templates/angular/src/app/pages/error.component.ts +124 -0
- package/dist/templates/angular/src/app/pages/not-found.component.ts +85 -0
- package/dist/templates/angular/src/app/pages/page.component.ts +58 -0
- package/dist/templates/angular/src/app/shared/layout.component.ts +106 -0
- package/dist/templates/angular/src/index.html +13 -0
- package/dist/templates/angular/src/main.server.ts +8 -0
- package/dist/templates/angular/src/main.ts +6 -0
- package/dist/templates/angular/src/server.ts +65 -0
- package/dist/templates/angular/src/styles.css +3 -0
- package/dist/templates/angular/tsconfig.json +38 -0
- package/dist/templates/angular/tsconfig.spec.json +10 -0
- package/dist/templates/nextjs/.cursor/rules/general.mdc +81 -81
- package/dist/templates/nextjs/.cursor/rules/javascript.mdc +112 -112
- package/dist/templates/nextjs/.cursor/rules/project-setup.mdc +100 -100
- package/dist/templates/nextjs/.cursor/rules/sitecore.mdc +150 -150
- package/dist/templates/nextjs/.env.container.example +27 -27
- package/dist/templates/nextjs/.env.remote.example +51 -51
- 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 +186 -186
- package/dist/templates/nextjs/LICENSE.txt +202 -202
- package/dist/templates/nextjs/LLMs.txt +179 -179
- package/dist/templates/nextjs/eslint.config.mjs +81 -81
- package/dist/templates/nextjs/gitignore +28 -28
- package/dist/templates/nextjs/package.json +68 -68
- package/dist/templates/nextjs/sitecore.config.ts.example +40 -40
- package/dist/templates/nextjs/tsconfig.json +40 -40
- package/dist/templates/nextjs-app-router/.cursor/rules/app-router-setup.mdc +116 -116
- package/dist/templates/nextjs-app-router/.cursor/rules/general.mdc +80 -80
- package/dist/templates/nextjs-app-router/.cursor/rules/javascript.mdc +112 -112
- package/dist/templates/nextjs-app-router/.cursor/rules/sitecore.mdc +174 -174
- package/dist/templates/nextjs-app-router/.env.container.example +27 -27
- package/dist/templates/nextjs-app-router/.env.remote.example +51 -51
- package/dist/templates/nextjs-app-router/.gitattributes +11 -11
- package/dist/templates/nextjs-app-router/.windsurfrules +290 -290
- package/dist/templates/nextjs-app-router/LLMs.txt +236 -236
- package/dist/templates/nextjs-app-router/eslint.config.mjs +29 -29
- package/dist/templates/nextjs-app-router/gitignore +31 -31
- package/dist/templates/nextjs-app-router/package.json +54 -54
- package/dist/templates/nextjs-app-router/postcss.config.mjs +5 -5
- package/dist/templates/nextjs-app-router/sitecore.config.ts.example +40 -40
- package/dist/templates/nextjs-app-router/src/app/globals.css +1 -1
- package/dist/templates/nextjs-app-router/tsconfig.json +48 -48
- package/package.json +2 -2
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AngularNodeAppEngine,
|
|
3
|
+
createNodeRequestHandler,
|
|
4
|
+
isMainModule,
|
|
5
|
+
writeResponseToNodeResponse,
|
|
6
|
+
} from '@angular/ssr/node';
|
|
7
|
+
import express from 'express';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { createLoaderDataServiceMiddleware } from '@sitecore-content-sdk/angular';
|
|
10
|
+
import { LOADERS } from './app/loaders';
|
|
11
|
+
|
|
12
|
+
const browserDistFolder = join(import.meta.dirname, '../browser');
|
|
13
|
+
|
|
14
|
+
const app = express();
|
|
15
|
+
const angularApp = new AngularNodeAppEngine();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Loader data endpoint (/_data). Must use the same loaders as the client registry
|
|
19
|
+
* so client-side navigation can fetch route data via POST /_data.
|
|
20
|
+
*/
|
|
21
|
+
app.use(express.json());
|
|
22
|
+
app.use(createLoaderDataServiceMiddleware({ loaders: LOADERS }));
|
|
23
|
+
/**
|
|
24
|
+
* Serve static files from /browser
|
|
25
|
+
*/
|
|
26
|
+
app.use(
|
|
27
|
+
express.static(browserDistFolder, {
|
|
28
|
+
maxAge: '1y',
|
|
29
|
+
index: false,
|
|
30
|
+
redirect: false,
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Handle all other requests by rendering the Angular application.
|
|
36
|
+
* Catches ExternalRedirectError from loaders so server-side external redirects send HTTP 302.
|
|
37
|
+
*/
|
|
38
|
+
app.use((req, res, next) => {
|
|
39
|
+
angularApp
|
|
40
|
+
.handle(req)
|
|
41
|
+
.then((response) => (response ? writeResponseToNodeResponse(response, res) : next()))
|
|
42
|
+
.catch((err) => {
|
|
43
|
+
next(err);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Start the server if this module is the main entry point
|
|
49
|
+
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
|
|
50
|
+
*/
|
|
51
|
+
if (isMainModule(import.meta.url)) {
|
|
52
|
+
const port = process.env.PORT || 4000;
|
|
53
|
+
app.listen(port, (error) => {
|
|
54
|
+
if (error) {
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log(`Node Express server listening on http://localhost:${port}`);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Request handler used by the Angular CLI (for dev-server and during build) or Firebase Cloud Functions.
|
|
64
|
+
*/
|
|
65
|
+
export const reqHandler = createNodeRequestHandler(app);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": false,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"importHelpers": true,
|
|
5
|
+
"outDir": "./dist/out-tsc",
|
|
6
|
+
"sourceMap": true,
|
|
7
|
+
"declaration": false,
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"emitDecoratorMetadata": true,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"allowJs": true,
|
|
15
|
+
"target": "es2022",
|
|
16
|
+
"module": "es2022",
|
|
17
|
+
"noImplicitAny": true,
|
|
18
|
+
"noImplicitReturns": true,
|
|
19
|
+
"noImplicitThis": true,
|
|
20
|
+
"noUnusedLocals": true,
|
|
21
|
+
"noUnusedParameters": true,
|
|
22
|
+
"newLine": "LF",
|
|
23
|
+
"types": ["node"],
|
|
24
|
+
// add additional type root in case of monorepo where dependencies are hoisted to root node_modules
|
|
25
|
+
"typeRoots": ["node_modules/@types", "../node_modules/@types"],
|
|
26
|
+
"lib": ["es2019", "dom", "esnext.asynciterable"],
|
|
27
|
+
"paths": {
|
|
28
|
+
"@angular/*": ["./node_modules/@angular/*"],
|
|
29
|
+
"rxjs": ["node_modules/rxjs", "./node_modules/rxjs"],
|
|
30
|
+
"lib/*": ["src/app/lib/*"],
|
|
31
|
+
".sitecore": ["./.sitecore"]
|
|
32
|
+
},
|
|
33
|
+
"baseUrl": "./",
|
|
34
|
+
"esModuleInterop": true
|
|
35
|
+
},
|
|
36
|
+
"include": ["src/**/*.ts"],
|
|
37
|
+
"exclude": ["src/**/*.spec.ts"]
|
|
38
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
+
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
+
{
|
|
4
|
+
"extends": "./tsconfig.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"outDir": "./out-tsc/spec",
|
|
7
|
+
"types": ["vitest/globals"]
|
|
8
|
+
},
|
|
9
|
+
"include": ["src/**/*.d.ts", "src/**/*.spec.ts"]
|
|
10
|
+
}
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Core coding principles for your Sitecore project
|
|
3
|
-
alwaysApply: true
|
|
4
|
-
globs: []
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# General Coding Principles
|
|
8
|
-
|
|
9
|
-
## Universal Standards
|
|
10
|
-
|
|
11
|
-
DRY Principle:
|
|
12
|
-
|
|
13
|
-
- Don't Repeat Yourself - extract common functionality
|
|
14
|
-
- Create reusable utilities and helper functions
|
|
15
|
-
- Use composition over inheritance
|
|
16
|
-
- Share types and interfaces across modules
|
|
17
|
-
|
|
18
|
-
SOLID Principles:
|
|
19
|
-
|
|
20
|
-
- Single Responsibility: each function/class has one purpose
|
|
21
|
-
- Open/Closed: extend functionality through composition
|
|
22
|
-
- Dependency Inversion: depend on abstractions, not implementations
|
|
23
|
-
|
|
24
|
-
Code Clarity:
|
|
25
|
-
|
|
26
|
-
- Write self-documenting code with clear intent
|
|
27
|
-
- Use meaningful names that express business concepts
|
|
28
|
-
- Prefer explicit over implicit behavior
|
|
29
|
-
- Make dependencies and requirements obvious
|
|
30
|
-
|
|
31
|
-
## Architecture Patterns
|
|
32
|
-
|
|
33
|
-
Modular Design:
|
|
34
|
-
|
|
35
|
-
- Organize code into focused, cohesive modules
|
|
36
|
-
- Minimize coupling between modules
|
|
37
|
-
- Use clear interfaces between layers
|
|
38
|
-
- Follow established patterns consistently
|
|
39
|
-
|
|
40
|
-
Data Flow:
|
|
41
|
-
|
|
42
|
-
- Prefer unidirectional data flow
|
|
43
|
-
- Validate inputs at system boundaries
|
|
44
|
-
- Transform data at appropriate layers
|
|
45
|
-
- Handle errors close to their source
|
|
46
|
-
|
|
47
|
-
Testing:
|
|
48
|
-
|
|
49
|
-
- Write testable code with minimal dependencies
|
|
50
|
-
- Use dependency injection for better testability
|
|
51
|
-
- Mock external services and side effects
|
|
52
|
-
- Test behavior, not implementation details
|
|
53
|
-
|
|
54
|
-
## Development Standards
|
|
55
|
-
|
|
56
|
-
Version Control:
|
|
57
|
-
|
|
58
|
-
- Write descriptive commit messages
|
|
59
|
-
- Keep commits focused and atomic
|
|
60
|
-
- Use branching strategies appropriate to team size
|
|
61
|
-
- Review code before merging
|
|
62
|
-
|
|
63
|
-
Documentation:
|
|
64
|
-
|
|
65
|
-
- Document public APIs and interfaces
|
|
66
|
-
- Include usage examples for complex functionality
|
|
67
|
-
- Keep documentation close to code
|
|
68
|
-
- Update documentation with code changes
|
|
69
|
-
|
|
70
|
-
Performance:
|
|
71
|
-
|
|
72
|
-
- Optimize for readability first, performance second
|
|
73
|
-
- Profile before optimizing
|
|
74
|
-
- Cache expensive operations appropriately
|
|
75
|
-
- Consider memory usage and cleanup
|
|
76
|
-
|
|
77
|
-
Referenced:
|
|
78
|
-
@src/components/
|
|
79
|
-
@src/lib/
|
|
80
|
-
@package.json
|
|
81
|
-
|
|
1
|
+
---
|
|
2
|
+
description: Core coding principles for your Sitecore project
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
globs: []
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# General Coding Principles
|
|
8
|
+
|
|
9
|
+
## Universal Standards
|
|
10
|
+
|
|
11
|
+
DRY Principle:
|
|
12
|
+
|
|
13
|
+
- Don't Repeat Yourself - extract common functionality
|
|
14
|
+
- Create reusable utilities and helper functions
|
|
15
|
+
- Use composition over inheritance
|
|
16
|
+
- Share types and interfaces across modules
|
|
17
|
+
|
|
18
|
+
SOLID Principles:
|
|
19
|
+
|
|
20
|
+
- Single Responsibility: each function/class has one purpose
|
|
21
|
+
- Open/Closed: extend functionality through composition
|
|
22
|
+
- Dependency Inversion: depend on abstractions, not implementations
|
|
23
|
+
|
|
24
|
+
Code Clarity:
|
|
25
|
+
|
|
26
|
+
- Write self-documenting code with clear intent
|
|
27
|
+
- Use meaningful names that express business concepts
|
|
28
|
+
- Prefer explicit over implicit behavior
|
|
29
|
+
- Make dependencies and requirements obvious
|
|
30
|
+
|
|
31
|
+
## Architecture Patterns
|
|
32
|
+
|
|
33
|
+
Modular Design:
|
|
34
|
+
|
|
35
|
+
- Organize code into focused, cohesive modules
|
|
36
|
+
- Minimize coupling between modules
|
|
37
|
+
- Use clear interfaces between layers
|
|
38
|
+
- Follow established patterns consistently
|
|
39
|
+
|
|
40
|
+
Data Flow:
|
|
41
|
+
|
|
42
|
+
- Prefer unidirectional data flow
|
|
43
|
+
- Validate inputs at system boundaries
|
|
44
|
+
- Transform data at appropriate layers
|
|
45
|
+
- Handle errors close to their source
|
|
46
|
+
|
|
47
|
+
Testing:
|
|
48
|
+
|
|
49
|
+
- Write testable code with minimal dependencies
|
|
50
|
+
- Use dependency injection for better testability
|
|
51
|
+
- Mock external services and side effects
|
|
52
|
+
- Test behavior, not implementation details
|
|
53
|
+
|
|
54
|
+
## Development Standards
|
|
55
|
+
|
|
56
|
+
Version Control:
|
|
57
|
+
|
|
58
|
+
- Write descriptive commit messages
|
|
59
|
+
- Keep commits focused and atomic
|
|
60
|
+
- Use branching strategies appropriate to team size
|
|
61
|
+
- Review code before merging
|
|
62
|
+
|
|
63
|
+
Documentation:
|
|
64
|
+
|
|
65
|
+
- Document public APIs and interfaces
|
|
66
|
+
- Include usage examples for complex functionality
|
|
67
|
+
- Keep documentation close to code
|
|
68
|
+
- Update documentation with code changes
|
|
69
|
+
|
|
70
|
+
Performance:
|
|
71
|
+
|
|
72
|
+
- Optimize for readability first, performance second
|
|
73
|
+
- Profile before optimizing
|
|
74
|
+
- Cache expensive operations appropriately
|
|
75
|
+
- Consider memory usage and cleanup
|
|
76
|
+
|
|
77
|
+
Referenced:
|
|
78
|
+
@src/components/
|
|
79
|
+
@src/lib/
|
|
80
|
+
@package.json
|
|
81
|
+
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: JavaScript/TypeScript rules for your Sitecore project
|
|
3
|
-
alwaysApply: false
|
|
4
|
-
globs:
|
|
5
|
-
- '**/*.js'
|
|
6
|
-
- '**/*.ts'
|
|
7
|
-
- '**/*.tsx'
|
|
8
|
-
- '**/*.mjs'
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# JavaScript/TypeScript Rules
|
|
12
|
-
|
|
13
|
-
## Naming Conventions
|
|
14
|
-
|
|
15
|
-
Variables and Functions:
|
|
16
|
-
|
|
17
|
-
- Use camelCase: `getUserData()`, `isLoading`, `currentUser`
|
|
18
|
-
- Boolean variables: prefix with `is`, `has`, `can`, `should`
|
|
19
|
-
- Event handlers: prefix with `handle` or `on`: `handleClick`, `onSubmit`
|
|
20
|
-
|
|
21
|
-
Components (React):
|
|
22
|
-
|
|
23
|
-
- Use PascalCase: `SitecoreComponent`, `PageLayout`, `ContentBlock`
|
|
24
|
-
- File names match component names: `SitecoreComponent.tsx`
|
|
25
|
-
|
|
26
|
-
Constants:
|
|
27
|
-
|
|
28
|
-
- Use UPPER_SNAKE_CASE: `API_ENDPOINT`, `DEFAULT_TIMEOUT`, `MAX_RETRIES`
|
|
29
|
-
- Export at module level when shared
|
|
30
|
-
|
|
31
|
-
Directories:
|
|
32
|
-
|
|
33
|
-
- Use kebab-case: `src/components`, `src/api-clients`, `src/sitecore-utils`
|
|
34
|
-
- Organize by feature when appropriate: `src/content-management/`
|
|
35
|
-
|
|
36
|
-
Types and Interfaces:
|
|
37
|
-
|
|
38
|
-
- Use PascalCase with descriptive names: `ContentItem`, `LayoutProps`, `SitecoreConfig`
|
|
39
|
-
- Prefix interfaces with `I` only when needed for disambiguation
|
|
40
|
-
|
|
41
|
-
## Code Layout and Organization
|
|
42
|
-
|
|
43
|
-
Directory Structure:
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
src/
|
|
47
|
-
components/ # UI components (React)
|
|
48
|
-
lib/ # Configuration and utilities
|
|
49
|
-
pages/ # Next.js pages (or app/ for App Router)
|
|
50
|
-
assets/ # Static assets and styles
|
|
51
|
-
types/ # TypeScript type definitions
|
|
52
|
-
hooks/ # Custom React hooks
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
File Organization:
|
|
56
|
-
|
|
57
|
-
- Group related functionality in feature directories
|
|
58
|
-
- Keep components co-located with their styles and tests
|
|
59
|
-
- Export public APIs through index.ts files
|
|
60
|
-
|
|
61
|
-
## Error Handling
|
|
62
|
-
|
|
63
|
-
API Calls:
|
|
64
|
-
|
|
65
|
-
- Always wrap in try/catch blocks
|
|
66
|
-
- Throw custom errors with context: `SitecoreFetchError`, `ConfigurationError`
|
|
67
|
-
- Handle edge cases with guard clauses
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
async function fetchContent(id: string): Promise<ContentItem> {
|
|
71
|
-
if (!id) {
|
|
72
|
-
throw new Error('Content ID is required');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const response = await sitecoreClient.getItem(id);
|
|
77
|
-
return response.data;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
throw new SitecoreFetchError(`Failed to fetch content ${id}`, error);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## Security
|
|
85
|
-
|
|
86
|
-
Input Validation:
|
|
87
|
-
|
|
88
|
-
- Sanitize user inputs before processing
|
|
89
|
-
- Validate data at application boundaries
|
|
90
|
-
- Use type guards for runtime type checking
|
|
91
|
-
- Escape content when rendering to prevent XSS
|
|
92
|
-
|
|
93
|
-
## Performance
|
|
94
|
-
|
|
95
|
-
Optimization Patterns:
|
|
96
|
-
|
|
97
|
-
- Cache API responses using React Query or SWR
|
|
98
|
-
- Memoize components with React.memo when appropriate
|
|
99
|
-
- Lazy-load non-critical modules: `const Component = lazy(() => import('./Component'))`
|
|
100
|
-
- Use useCallback and useMemo for expensive operations
|
|
101
|
-
|
|
102
|
-
TypeScript:
|
|
103
|
-
|
|
104
|
-
- Enable strict mode in tsconfig.json
|
|
105
|
-
- Prefer type assertions over any: `value as ContentItem`
|
|
106
|
-
- Use discriminated unions for complex state management
|
|
107
|
-
|
|
108
|
-
Referenced:
|
|
109
|
-
@src/components/
|
|
110
|
-
@src/lib/
|
|
111
|
-
@src/types/
|
|
112
|
-
|
|
1
|
+
---
|
|
2
|
+
description: JavaScript/TypeScript rules for your Sitecore project
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
globs:
|
|
5
|
+
- '**/*.js'
|
|
6
|
+
- '**/*.ts'
|
|
7
|
+
- '**/*.tsx'
|
|
8
|
+
- '**/*.mjs'
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# JavaScript/TypeScript Rules
|
|
12
|
+
|
|
13
|
+
## Naming Conventions
|
|
14
|
+
|
|
15
|
+
Variables and Functions:
|
|
16
|
+
|
|
17
|
+
- Use camelCase: `getUserData()`, `isLoading`, `currentUser`
|
|
18
|
+
- Boolean variables: prefix with `is`, `has`, `can`, `should`
|
|
19
|
+
- Event handlers: prefix with `handle` or `on`: `handleClick`, `onSubmit`
|
|
20
|
+
|
|
21
|
+
Components (React):
|
|
22
|
+
|
|
23
|
+
- Use PascalCase: `SitecoreComponent`, `PageLayout`, `ContentBlock`
|
|
24
|
+
- File names match component names: `SitecoreComponent.tsx`
|
|
25
|
+
|
|
26
|
+
Constants:
|
|
27
|
+
|
|
28
|
+
- Use UPPER_SNAKE_CASE: `API_ENDPOINT`, `DEFAULT_TIMEOUT`, `MAX_RETRIES`
|
|
29
|
+
- Export at module level when shared
|
|
30
|
+
|
|
31
|
+
Directories:
|
|
32
|
+
|
|
33
|
+
- Use kebab-case: `src/components`, `src/api-clients`, `src/sitecore-utils`
|
|
34
|
+
- Organize by feature when appropriate: `src/content-management/`
|
|
35
|
+
|
|
36
|
+
Types and Interfaces:
|
|
37
|
+
|
|
38
|
+
- Use PascalCase with descriptive names: `ContentItem`, `LayoutProps`, `SitecoreConfig`
|
|
39
|
+
- Prefix interfaces with `I` only when needed for disambiguation
|
|
40
|
+
|
|
41
|
+
## Code Layout and Organization
|
|
42
|
+
|
|
43
|
+
Directory Structure:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
src/
|
|
47
|
+
components/ # UI components (React)
|
|
48
|
+
lib/ # Configuration and utilities
|
|
49
|
+
pages/ # Next.js pages (or app/ for App Router)
|
|
50
|
+
assets/ # Static assets and styles
|
|
51
|
+
types/ # TypeScript type definitions
|
|
52
|
+
hooks/ # Custom React hooks
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
File Organization:
|
|
56
|
+
|
|
57
|
+
- Group related functionality in feature directories
|
|
58
|
+
- Keep components co-located with their styles and tests
|
|
59
|
+
- Export public APIs through index.ts files
|
|
60
|
+
|
|
61
|
+
## Error Handling
|
|
62
|
+
|
|
63
|
+
API Calls:
|
|
64
|
+
|
|
65
|
+
- Always wrap in try/catch blocks
|
|
66
|
+
- Throw custom errors with context: `SitecoreFetchError`, `ConfigurationError`
|
|
67
|
+
- Handle edge cases with guard clauses
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
async function fetchContent(id: string): Promise<ContentItem> {
|
|
71
|
+
if (!id) {
|
|
72
|
+
throw new Error('Content ID is required');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const response = await sitecoreClient.getItem(id);
|
|
77
|
+
return response.data;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new SitecoreFetchError(`Failed to fetch content ${id}`, error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Security
|
|
85
|
+
|
|
86
|
+
Input Validation:
|
|
87
|
+
|
|
88
|
+
- Sanitize user inputs before processing
|
|
89
|
+
- Validate data at application boundaries
|
|
90
|
+
- Use type guards for runtime type checking
|
|
91
|
+
- Escape content when rendering to prevent XSS
|
|
92
|
+
|
|
93
|
+
## Performance
|
|
94
|
+
|
|
95
|
+
Optimization Patterns:
|
|
96
|
+
|
|
97
|
+
- Cache API responses using React Query or SWR
|
|
98
|
+
- Memoize components with React.memo when appropriate
|
|
99
|
+
- Lazy-load non-critical modules: `const Component = lazy(() => import('./Component'))`
|
|
100
|
+
- Use useCallback and useMemo for expensive operations
|
|
101
|
+
|
|
102
|
+
TypeScript:
|
|
103
|
+
|
|
104
|
+
- Enable strict mode in tsconfig.json
|
|
105
|
+
- Prefer type assertions over any: `value as ContentItem`
|
|
106
|
+
- Use discriminated unions for complex state management
|
|
107
|
+
|
|
108
|
+
Referenced:
|
|
109
|
+
@src/components/
|
|
110
|
+
@src/lib/
|
|
111
|
+
@src/types/
|
|
112
|
+
|