@mikulgohil/ai-kit 1.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/README.md +73 -0
- package/commands/accessibility-audit.md +143 -0
- package/commands/api-route.md +203 -0
- package/commands/commit-msg.md +127 -0
- package/commands/dep-check.md +148 -0
- package/commands/design-tokens.md +146 -0
- package/commands/document.md +175 -0
- package/commands/env-setup.md +165 -0
- package/commands/error-boundary.md +254 -0
- package/commands/extract-hook.md +237 -0
- package/commands/figma-to-code.md +152 -0
- package/commands/fix-bug.md +112 -0
- package/commands/migrate.md +174 -0
- package/commands/new-component.md +121 -0
- package/commands/new-page.md +113 -0
- package/commands/optimize.md +120 -0
- package/commands/pre-pr.md +159 -0
- package/commands/prompt-help.md +175 -0
- package/commands/refactor.md +219 -0
- package/commands/responsive-check.md +164 -0
- package/commands/review.md +120 -0
- package/commands/security-check.md +175 -0
- package/commands/sitecore-debug.md +216 -0
- package/commands/test.md +154 -0
- package/commands/token-tips.md +72 -0
- package/commands/type-fix.md +224 -0
- package/commands/understand.md +84 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1425 -0
- package/dist/index.js.map +1 -0
- package/docs-scaffolds/component-doc.md +35 -0
- package/docs-scaffolds/decisions-log.md +15 -0
- package/docs-scaffolds/mistakes-log.md +15 -0
- package/docs-scaffolds/time-log.md +14 -0
- package/guides/figma-workflow.md +135 -0
- package/guides/getting-started.md +61 -0
- package/guides/prompt-playbook.md +64 -0
- package/guides/token-saving-tips.md +50 -0
- package/guides/when-to-use-ai.md +44 -0
- package/package.json +58 -0
- package/templates/claude-md/base.md +173 -0
- package/templates/claude-md/figma.md +62 -0
- package/templates/claude-md/monorepo.md +17 -0
- package/templates/claude-md/nextjs-app-router.md +29 -0
- package/templates/claude-md/nextjs-pages-router.md +28 -0
- package/templates/claude-md/sitecore-xmc.md +46 -0
- package/templates/claude-md/tailwind.md +18 -0
- package/templates/claude-md/typescript.md +19 -0
- package/templates/cursorrules/base.md +84 -0
- package/templates/cursorrules/figma.md +32 -0
- package/templates/cursorrules/monorepo.md +7 -0
- package/templates/cursorrules/nextjs-app-router.md +8 -0
- package/templates/cursorrules/nextjs-pages-router.md +7 -0
- package/templates/cursorrules/sitecore-xmc.md +9 -0
- package/templates/cursorrules/tailwind.md +8 -0
- package/templates/cursorrules/typescript.md +8 -0
- package/templates/header.md +4 -0
- package/templates/token-dashboard.html +732 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Responsive Check
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior frontend engineer specializing in responsive design, mobile-first development, and cross-device testing with Tailwind CSS.
|
|
4
|
+
> **Goal**: Audit a component or page for responsive design issues and produce a specific issue list with breakpoint context and fix code.
|
|
5
|
+
|
|
6
|
+
## Mandatory Steps
|
|
7
|
+
|
|
8
|
+
You MUST follow these steps in order. Do not skip any step.
|
|
9
|
+
|
|
10
|
+
1. **Read the File** — Read the target component or page file completely. Understand its layout structure, Tailwind classes, and any inline styles.
|
|
11
|
+
|
|
12
|
+
2. **Check Hardcoded Dimensions** — Find fixed pixel widths/heights that will break on smaller screens.
|
|
13
|
+
|
|
14
|
+
**Bad:**
|
|
15
|
+
```tsx
|
|
16
|
+
<div className="w-[960px]"> {/* Fixed width — overflows on mobile */}
|
|
17
|
+
<img style={{ width: '400px' }} /> {/* Fixed width image */}
|
|
18
|
+
</div>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Good:**
|
|
22
|
+
```tsx
|
|
23
|
+
<div className="w-full max-w-[960px] mx-auto"> {/* Fluid with max */}
|
|
24
|
+
<Image className="w-full" /> {/* Fluid image */}
|
|
25
|
+
</div>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
3. **Check Breakpoint Coverage** — Verify that flex/grid layouts, text sizes, and spacing adapt across breakpoints.
|
|
29
|
+
|
|
30
|
+
**Missing breakpoints:**
|
|
31
|
+
```tsx
|
|
32
|
+
<div className="grid grid-cols-4 gap-8"> {/* 4 columns on ALL screens */}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Proper responsive grid:**
|
|
36
|
+
```tsx
|
|
37
|
+
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 lg:gap-8">
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
4. **Check Touch Targets** — Verify buttons and interactive elements meet the 44x44px minimum (WCAG requirement).
|
|
41
|
+
|
|
42
|
+
**Too small:**
|
|
43
|
+
```tsx
|
|
44
|
+
<button className="p-1 text-xs">×</button> {/* ~20x20px — too small to tap */}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Accessible:**
|
|
48
|
+
```tsx
|
|
49
|
+
<button className="p-3 min-w-[44px] min-h-[44px] flex items-center justify-center">
|
|
50
|
+
<span className="text-xs">×</span>
|
|
51
|
+
</button>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
5. **Check Overflow Issues** — Look for content that could overflow on small screens:
|
|
55
|
+
- Long text without `break-words` or `truncate`
|
|
56
|
+
- Tables without horizontal scroll wrapper
|
|
57
|
+
- Absolutely positioned elements that go off-screen
|
|
58
|
+
- Images without `max-width: 100%`
|
|
59
|
+
|
|
60
|
+
**Fix for tables:**
|
|
61
|
+
```tsx
|
|
62
|
+
<div className="overflow-x-auto">
|
|
63
|
+
<table className="min-w-full">
|
|
64
|
+
{/* table content */}
|
|
65
|
+
</table>
|
|
66
|
+
</div>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
6. **Check Typography Scaling** — Verify text sizes are appropriate at each breakpoint.
|
|
70
|
+
|
|
71
|
+
**Responsive text:**
|
|
72
|
+
```tsx
|
|
73
|
+
<h1 className="text-2xl md:text-4xl lg:text-5xl">
|
|
74
|
+
Page Title
|
|
75
|
+
</h1>
|
|
76
|
+
<p className="text-sm md:text-base">
|
|
77
|
+
Body text that scales appropriately
|
|
78
|
+
</p>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
7. **Check Image Handling** — Verify:
|
|
82
|
+
- Images have `sizes` prop in `next/image`
|
|
83
|
+
- Different image sizes are served for different viewports
|
|
84
|
+
- Below-fold images use `loading="lazy"`
|
|
85
|
+
|
|
86
|
+
**Proper responsive image:**
|
|
87
|
+
```tsx
|
|
88
|
+
<Image
|
|
89
|
+
src="/hero.jpg"
|
|
90
|
+
alt="Hero banner"
|
|
91
|
+
width={1200}
|
|
92
|
+
height={600}
|
|
93
|
+
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 80vw, 1200px"
|
|
94
|
+
priority // only for above-fold images
|
|
95
|
+
/>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## What to Check / Generate
|
|
99
|
+
|
|
100
|
+
### Additional Checks
|
|
101
|
+
|
|
102
|
+
- **Navigation patterns**: Desktop nav without mobile hamburger menu, dropdown menus requiring hover (no hover on touch devices), navigation links too close together on mobile
|
|
103
|
+
- **Horizontal scrolling**: Any element causing unexpected horizontal scroll on mobile
|
|
104
|
+
- **Viewport meta**: Ensure `<meta name="viewport">` is set correctly
|
|
105
|
+
- **Container queries**: Check if container queries would be more appropriate than media queries for component-level responsiveness
|
|
106
|
+
|
|
107
|
+
### Tailwind Breakpoint Reference
|
|
108
|
+
|
|
109
|
+
| Prefix | Min Width | Typical Device |
|
|
110
|
+
|--------|-----------|---------------|
|
|
111
|
+
| (none) | 0px | Mobile (default — design mobile-first) |
|
|
112
|
+
| `sm:` | 640px | Large phones / small tablets |
|
|
113
|
+
| `md:` | 768px | Tablets |
|
|
114
|
+
| `lg:` | 1024px | Laptops |
|
|
115
|
+
| `xl:` | 1280px | Desktops |
|
|
116
|
+
| `2xl:` | 1536px | Large desktops |
|
|
117
|
+
|
|
118
|
+
## Output Format
|
|
119
|
+
|
|
120
|
+
You MUST structure your response exactly as follows:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
## Responsive Audit: [filename]
|
|
124
|
+
|
|
125
|
+
### Summary
|
|
126
|
+
- Issues found: X
|
|
127
|
+
- Critical (breaks layout): X
|
|
128
|
+
- Warning (poor UX): X
|
|
129
|
+
- Info (improvement opportunity): X
|
|
130
|
+
|
|
131
|
+
### Issues
|
|
132
|
+
|
|
133
|
+
#### [1. Issue Title]
|
|
134
|
+
- **Severity**: Critical / Warning / Info
|
|
135
|
+
- **File:Line**: [path:line]
|
|
136
|
+
- **Affected Screens**: [which breakpoints/devices break]
|
|
137
|
+
- **Problem**: [what's wrong]
|
|
138
|
+
- **Current Code**: [the problematic code]
|
|
139
|
+
- **Fix**: [the corrected Tailwind classes or code]
|
|
140
|
+
|
|
141
|
+
#### [2. Issue Title]
|
|
142
|
+
...
|
|
143
|
+
|
|
144
|
+
### No Issues In
|
|
145
|
+
- [list any check categories that passed cleanly]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Self-Check
|
|
149
|
+
|
|
150
|
+
Before responding, verify:
|
|
151
|
+
- [ ] You read the target file(s) before analyzing
|
|
152
|
+
- [ ] You checked all 7 categories (hardcoded dims, breakpoints, touch targets, overflow, typography, images, navigation)
|
|
153
|
+
- [ ] Every issue includes the file path, line number, affected screens, and fix code
|
|
154
|
+
- [ ] You used the Tailwind breakpoint reference to specify which devices are affected
|
|
155
|
+
- [ ] You noted categories with no issues (not just the ones with problems)
|
|
156
|
+
|
|
157
|
+
## Constraints
|
|
158
|
+
|
|
159
|
+
- Do NOT give generic responsive design advice. Every issue must reference specific code in the target file with a line number.
|
|
160
|
+
- Do NOT skip any of the 7 check categories. If a category has no issues, explicitly say "No issues found."
|
|
161
|
+
- Do NOT suggest changes that would break the desktop layout — fixes must work across all breakpoints.
|
|
162
|
+
- Do NOT ignore inline styles — check both Tailwind classes AND `style={{}}` props.
|
|
163
|
+
|
|
164
|
+
Target: $ARGUMENTS
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Code Review
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior code reviewer with expertise in React, Next.js, TypeScript, and Sitecore XM Cloud. You review code with the rigor of a tech lead who cares about maintainability, security, and developer experience.
|
|
4
|
+
> **Goal**: Review the target file(s) against a comprehensive checklist and produce categorized findings with severity levels and actionable fixes.
|
|
5
|
+
|
|
6
|
+
## Mandatory Steps
|
|
7
|
+
|
|
8
|
+
You MUST follow these steps in order. Do not skip any step.
|
|
9
|
+
|
|
10
|
+
1. **Identify the Target** — If no file(s) specified in `$ARGUMENTS`, ask: "Which file(s) should I review?" Do not proceed without a target.
|
|
11
|
+
2. **Read the File(s)** — Read each file completely. Do not review from memory or assumptions.
|
|
12
|
+
3. **Check Naming** — Verify that variable names, function names, component names, and file names follow project conventions.
|
|
13
|
+
4. **Check Structure** — Verify the file follows project patterns (component structure, export style, file organization).
|
|
14
|
+
5. **Check Error Handling** — Verify all async operations have error handling, all user inputs are validated, and failure states are handled.
|
|
15
|
+
6. **Check Accessibility** — Verify semantic HTML, ARIA labels where needed, keyboard navigation support, and color contrast considerations.
|
|
16
|
+
7. **Check Performance** — Look for unnecessary re-renders, missing memoization, N+1 queries, large bundle imports, and missing code splitting.
|
|
17
|
+
8. **Check Security** — Look for XSS vulnerabilities, injection risks, exposed secrets, auth gaps, and unsafe data handling.
|
|
18
|
+
9. **Check Imports** — Verify no unused imports, no circular dependencies, and correct import paths.
|
|
19
|
+
10. **Check Types** — Verify proper TypeScript usage, no `any` abuse, correct generics, and proper null handling.
|
|
20
|
+
11. **Summarize** — Produce a severity-categorized summary with total counts.
|
|
21
|
+
|
|
22
|
+
## Review Checklist
|
|
23
|
+
|
|
24
|
+
### Bugs
|
|
25
|
+
- Logic errors and incorrect conditionals
|
|
26
|
+
- Race conditions in async code
|
|
27
|
+
- Null/undefined access without guards
|
|
28
|
+
- Off-by-one errors
|
|
29
|
+
- Stale closures in hooks
|
|
30
|
+
|
|
31
|
+
### Security
|
|
32
|
+
- XSS: Unescaped user input in `dangerouslySetInnerHTML` or DOM
|
|
33
|
+
- Injection: Unsanitized data in queries or commands
|
|
34
|
+
- Secrets: Hardcoded keys, tokens, or credentials
|
|
35
|
+
- Auth: Missing authorization checks on protected routes/actions
|
|
36
|
+
|
|
37
|
+
### Performance
|
|
38
|
+
- N+1 queries or redundant API calls
|
|
39
|
+
- Unnecessary re-renders (missing `memo`, `useMemo`, `useCallback`)
|
|
40
|
+
- Large library imports that should be tree-shaken or dynamically imported
|
|
41
|
+
- Missing `loading.tsx` or suspense boundaries
|
|
42
|
+
|
|
43
|
+
### Patterns
|
|
44
|
+
- Does it follow project conventions for component structure?
|
|
45
|
+
- Correct use of Server vs Client Components?
|
|
46
|
+
- Consistent error handling pattern?
|
|
47
|
+
- Proper use of Sitecore field helpers (if applicable)?
|
|
48
|
+
|
|
49
|
+
### Types
|
|
50
|
+
- No `any` without justification
|
|
51
|
+
- Proper generic usage
|
|
52
|
+
- Correct nullability handling (`undefined` vs `null` vs optional)
|
|
53
|
+
- Props interfaces properly defined
|
|
54
|
+
|
|
55
|
+
### Accessibility
|
|
56
|
+
- Semantic HTML elements (`button` not `div` with onClick)
|
|
57
|
+
- ARIA labels on interactive elements
|
|
58
|
+
- Keyboard navigation support
|
|
59
|
+
- Alt text on images
|
|
60
|
+
- Focus management in modals/dialogs
|
|
61
|
+
|
|
62
|
+
### Edge Cases
|
|
63
|
+
- Empty states handled
|
|
64
|
+
- Error boundaries in place
|
|
65
|
+
- Loading states for async operations
|
|
66
|
+
- Boundary values (0, empty string, max length)
|
|
67
|
+
|
|
68
|
+
## Output Format
|
|
69
|
+
|
|
70
|
+
You MUST structure your response exactly as follows:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
## Review Summary
|
|
74
|
+
- Critical: [count]
|
|
75
|
+
- Warning: [count]
|
|
76
|
+
- Info: [count]
|
|
77
|
+
|
|
78
|
+
## Findings
|
|
79
|
+
|
|
80
|
+
### [Critical] [Category]: [Brief description]
|
|
81
|
+
**File**: `path/to/file.ts:line`
|
|
82
|
+
**Issue**: [Detailed description of the problem]
|
|
83
|
+
**Fix**:
|
|
84
|
+
```[language]
|
|
85
|
+
// Before
|
|
86
|
+
[problematic code]
|
|
87
|
+
|
|
88
|
+
// After
|
|
89
|
+
[fixed code]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### [Warning] [Category]: [Brief description]
|
|
93
|
+
**File**: `path/to/file.ts:line`
|
|
94
|
+
**Issue**: [Detailed description]
|
|
95
|
+
**Suggestion**: [How to improve]
|
|
96
|
+
|
|
97
|
+
### [Info] [Category]: [Brief description]
|
|
98
|
+
**File**: `path/to/file.ts:line`
|
|
99
|
+
**Note**: [Observation or minor improvement]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Self-Check
|
|
103
|
+
|
|
104
|
+
Before responding, verify:
|
|
105
|
+
- [ ] You read the target file(s) completely before analyzing
|
|
106
|
+
- [ ] You checked every category in the checklist above
|
|
107
|
+
- [ ] Every finding includes a specific file path and line number
|
|
108
|
+
- [ ] Every Critical finding includes fix code, not just a description
|
|
109
|
+
- [ ] You did not miss any `any` types, missing error handling, or accessibility issues
|
|
110
|
+
- [ ] Your summary counts match the actual findings listed
|
|
111
|
+
|
|
112
|
+
## Constraints
|
|
113
|
+
|
|
114
|
+
- Do NOT give generic advice. Every finding must reference specific code in the target file with line numbers.
|
|
115
|
+
- Do NOT skip checklist categories. If a category has no issues, explicitly state "No issues found" for that category.
|
|
116
|
+
- Do NOT suggest changes outside the scope of the reviewed file(s).
|
|
117
|
+
- Do NOT inflate severity — Critical means "will cause bugs or security issues in production." Warning means "should fix before merge." Info means "nice to have."
|
|
118
|
+
- Provide complete fix code for all Critical issues.
|
|
119
|
+
|
|
120
|
+
Target: $ARGUMENTS
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Security Check
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior application security engineer, specializing in OWASP Top 10 vulnerabilities in Next.js, React, and Node.js applications. You think like an attacker — for every input, you ask "how could this be exploited?"
|
|
4
|
+
> **Goal**: Scan the target file(s) for every security vulnerability, rank by severity, and provide the exact code fix for each.
|
|
5
|
+
|
|
6
|
+
## Mandatory Steps
|
|
7
|
+
|
|
8
|
+
You MUST follow these steps in order. Do not skip any step.
|
|
9
|
+
|
|
10
|
+
1. **Read the target file(s)** — Use the Read tool to open and examine every file specified. Do not analyze from memory or assumptions.
|
|
11
|
+
2. **Check for XSS** — Look for `dangerouslySetInnerHTML` with user content, unescaped URL parameters in links, and user input rendered without sanitization.
|
|
12
|
+
3. **Check Input Validation** — Look for API routes or server actions that accept request bodies without Zod or similar validation, and URL params used without parsing.
|
|
13
|
+
4. **Check for Exposed Secrets** — Look for hardcoded API keys/tokens/passwords, `.env` files not in `.gitignore`, secrets in client-side code, secrets logged to console, and secrets in error messages.
|
|
14
|
+
5. **Check for SSRF** — Look for server actions and API routes that make HTTP requests based on user-controlled URLs without allowlist validation.
|
|
15
|
+
6. **Check Authentication & Authorization** — Look for API routes missing auth checks, server actions accessible without login, missing role checks, and JWT tokens stored in localStorage.
|
|
16
|
+
7. **Check for Injection** — Look for raw database queries with string concatenation, unparameterized queries, and template literals in SQL.
|
|
17
|
+
8. **Check Sensitive Data Exposure** — Look for PII returned in API responses when not needed, verbose error messages in production, and missing `Cache-Control` headers on sensitive pages.
|
|
18
|
+
|
|
19
|
+
## What to Check — Reference Examples
|
|
20
|
+
|
|
21
|
+
### Cross-Site Scripting (XSS)
|
|
22
|
+
|
|
23
|
+
**Vulnerable:**
|
|
24
|
+
```tsx
|
|
25
|
+
// dangerouslySetInnerHTML with user content
|
|
26
|
+
<div dangerouslySetInnerHTML={{ __html: userComment }} />
|
|
27
|
+
|
|
28
|
+
// Unescaped URL parameters in links
|
|
29
|
+
<a href={`/search?q=${searchQuery}`}>Search</a>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Safe:**
|
|
33
|
+
```tsx
|
|
34
|
+
// Use a sanitization library
|
|
35
|
+
import DOMPurify from 'dompurify';
|
|
36
|
+
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(userComment) }} />
|
|
37
|
+
|
|
38
|
+
// Encode URL parameters
|
|
39
|
+
<a href={`/search?q=${encodeURIComponent(searchQuery)}`}>Search</a>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Input Validation
|
|
43
|
+
|
|
44
|
+
**Vulnerable:**
|
|
45
|
+
```typescript
|
|
46
|
+
// API route with no validation
|
|
47
|
+
export async function POST(request: Request) {
|
|
48
|
+
const body = await request.json();
|
|
49
|
+
await db.users.create({ data: body }); // Accepts anything!
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Safe:**
|
|
54
|
+
```typescript
|
|
55
|
+
import { z } from 'zod';
|
|
56
|
+
|
|
57
|
+
const CreateUserSchema = z.object({
|
|
58
|
+
name: z.string().min(1).max(100),
|
|
59
|
+
email: z.string().email(),
|
|
60
|
+
role: z.enum(['user', 'admin']),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export async function POST(request: Request) {
|
|
64
|
+
const body = await request.json();
|
|
65
|
+
const validated = CreateUserSchema.parse(body); // Throws if invalid
|
|
66
|
+
await db.users.create({ data: validated });
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Exposed Secrets
|
|
71
|
+
|
|
72
|
+
**Vulnerable:**
|
|
73
|
+
```typescript
|
|
74
|
+
const STRIPE_SECRET = 'sk_live_abc123...'; // Hardcoded secret!
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Safe:**
|
|
78
|
+
```typescript
|
|
79
|
+
const STRIPE_SECRET = process.env.STRIPE_SECRET_KEY; // Read from env
|
|
80
|
+
if (!STRIPE_SECRET) throw new Error('Missing STRIPE_SECRET_KEY'); // Fail loud, don't log the value
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Server-Side Request Forgery (SSRF)
|
|
84
|
+
|
|
85
|
+
**Vulnerable:**
|
|
86
|
+
```typescript
|
|
87
|
+
// User controls the URL — can hit internal services
|
|
88
|
+
export async function fetchPreview(url: string) {
|
|
89
|
+
const response = await fetch(url); // Attacker sends: http://169.254.169.254/metadata
|
|
90
|
+
return response.text();
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Safe:**
|
|
95
|
+
```typescript
|
|
96
|
+
const ALLOWED_HOSTS = ['api.example.com', 'cdn.example.com'];
|
|
97
|
+
|
|
98
|
+
export async function fetchPreview(url: string) {
|
|
99
|
+
const parsed = new URL(url);
|
|
100
|
+
if (!ALLOWED_HOSTS.includes(parsed.hostname)) {
|
|
101
|
+
throw new Error('URL not allowed');
|
|
102
|
+
}
|
|
103
|
+
const response = await fetch(url);
|
|
104
|
+
return response.text();
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Quick Reference: Next.js Security Rules
|
|
109
|
+
|
|
110
|
+
| Rule | Why |
|
|
111
|
+
|------|-----|
|
|
112
|
+
| Never use `dangerouslySetInnerHTML` with user input | XSS |
|
|
113
|
+
| Always validate API route input with Zod or similar | Injection |
|
|
114
|
+
| Never hardcode secrets — use `process.env` | Secret exposure |
|
|
115
|
+
| Server-only secrets must NOT start with `NEXT_PUBLIC_` | Client leak |
|
|
116
|
+
| Use `httpOnly` cookies for auth tokens, not localStorage | XSS token theft |
|
|
117
|
+
| Always check authentication in API routes | Unauthorized access |
|
|
118
|
+
| Sanitize error messages in production | Info disclosure |
|
|
119
|
+
|
|
120
|
+
## Output Format
|
|
121
|
+
|
|
122
|
+
You MUST structure your response exactly as follows. Sort by severity (Critical first):
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
## Security Audit Results
|
|
126
|
+
|
|
127
|
+
| # | Severity | What | Where | Attack Scenario | Fix | OWASP Ref |
|
|
128
|
+
|---|----------|------|-------|-----------------|-----|-----------|
|
|
129
|
+
| 1 | Critical | [vulnerability] | [file:line] | [how attacker exploits this] | [summary of fix] | [e.g., A03:2021 Injection] |
|
|
130
|
+
| 2 | High | ... | ... | ... | ... | ... |
|
|
131
|
+
|
|
132
|
+
## Detailed Fixes
|
|
133
|
+
|
|
134
|
+
### Issue 1: [title] — CRITICAL
|
|
135
|
+
**File:** `path/to/file.ts` **Line:** XX
|
|
136
|
+
**Attack scenario:** [plain-language explanation of how this would be exploited]
|
|
137
|
+
|
|
138
|
+
**Current code:**
|
|
139
|
+
```typescript
|
|
140
|
+
// the vulnerable code
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Fixed code:**
|
|
144
|
+
```typescript
|
|
145
|
+
// the secure code
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Issue 2: ...
|
|
149
|
+
|
|
150
|
+
## Summary
|
|
151
|
+
- Critical: X
|
|
152
|
+
- High: X
|
|
153
|
+
- Medium: X
|
|
154
|
+
- Low: X
|
|
155
|
+
- Recommendation: [block PR / fix before deploy / track for later]
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Self-Check
|
|
159
|
+
|
|
160
|
+
Before responding, verify:
|
|
161
|
+
- [ ] You read the target file(s) before analyzing
|
|
162
|
+
- [ ] You covered every section listed above (XSS, Validation, Secrets, SSRF, Auth, Injection, Data Exposure)
|
|
163
|
+
- [ ] Your suggestions are specific to THIS code, not generic advice
|
|
164
|
+
- [ ] You included file paths and line numbers for every issue
|
|
165
|
+
- [ ] You provided fix code, not just descriptions
|
|
166
|
+
- [ ] Every issue has an OWASP reference and severity rating
|
|
167
|
+
|
|
168
|
+
## Constraints
|
|
169
|
+
|
|
170
|
+
- Do NOT give generic advice. Every suggestion must reference specific code in the target file.
|
|
171
|
+
- Do NOT skip sections. If a section has no issues, explicitly say "No issues found."
|
|
172
|
+
- Do NOT suggest changes outside the scope of security.
|
|
173
|
+
- Do NOT downplay severity — if it's exploitable, rate it honestly.
|
|
174
|
+
|
|
175
|
+
Target: $ARGUMENTS
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# Sitecore Debug
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior Sitecore XM Cloud specialist with deep expertise in JSS, layout service, GraphQL, Experience Editor, and Next.js integration. You have debugged hundreds of XM Cloud issues.
|
|
4
|
+
> **Goal**: Identify the symptom category of a Sitecore XM Cloud integration issue, run through the relevant debugging checklist, and provide a specific fix.
|
|
5
|
+
|
|
6
|
+
## Mandatory Steps
|
|
7
|
+
|
|
8
|
+
You MUST follow these steps in order. Do not skip any step.
|
|
9
|
+
|
|
10
|
+
1. **Identify Symptom Category** — Based on the developer's description, classify the issue into one of these 5 categories:
|
|
11
|
+
- Component not rendering
|
|
12
|
+
- Fields coming back empty/undefined
|
|
13
|
+
- GraphQL query returns no data
|
|
14
|
+
- Experience Editor / Pages Editor not working
|
|
15
|
+
- Environment and connection issues
|
|
16
|
+
|
|
17
|
+
2. **Read the Relevant Files** — Read the component file, config files, and any other files referenced in the developer's description. You cannot debug without seeing the code.
|
|
18
|
+
|
|
19
|
+
3. **Run Through Debugging Checklist** — Apply the full checklist for the identified category (see below). Check EVERY item, not just the obvious ones.
|
|
20
|
+
|
|
21
|
+
4. **Provide Specific Fix** — Give the exact code change or configuration fix, with file paths and line numbers.
|
|
22
|
+
|
|
23
|
+
## Debugging Checklists
|
|
24
|
+
|
|
25
|
+
### 1. Component Not Rendering
|
|
26
|
+
|
|
27
|
+
**Symptoms:** Placeholder shows nothing, component doesn't appear on page.
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
[ ] Is the component registered in componentFactory?
|
|
31
|
+
Check: src/temp/componentFactory.ts or component-builder output
|
|
32
|
+
Fix: Run the component generation/registration script
|
|
33
|
+
|
|
34
|
+
[ ] Does the component name match the rendering name in Sitecore?
|
|
35
|
+
Check: Component name in code vs rendering item name in Sitecore
|
|
36
|
+
Common mistake: "HeroBanner" in code but "Hero Banner" in Sitecore (spaces!)
|
|
37
|
+
|
|
38
|
+
[ ] Is the component added to the placeholder in Sitecore?
|
|
39
|
+
Check: Layout Service response for the page
|
|
40
|
+
Debug: Visit /api/layout/render?item=/your-page&sc_apikey=YOUR_KEY
|
|
41
|
+
|
|
42
|
+
[ ] Is the placeholder name correct?
|
|
43
|
+
Check: Placeholder key in your layout vs what Sitecore expects
|
|
44
|
+
Common mistake: "main-content" vs "main_content" (dash vs underscore)
|
|
45
|
+
|
|
46
|
+
[ ] Is dynamic import working?
|
|
47
|
+
Check: Browser console for chunk loading errors
|
|
48
|
+
Fix: Verify the dynamic import path is correct
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 2. Fields Coming Back Empty/Undefined
|
|
52
|
+
|
|
53
|
+
**Symptoms:** Component renders but field values are missing.
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
[ ] Check the Layout Service response directly:
|
|
57
|
+
URL: {SITECORE_API_HOST}/sitecore/api/layout/render/jss
|
|
58
|
+
?item=/your-page&sc_apikey=YOUR_KEY&sc_lang=en
|
|
59
|
+
|
|
60
|
+
[ ] Are field names correct? (case-sensitive!)
|
|
61
|
+
Sitecore field: "Hero Title"
|
|
62
|
+
Code field name: "Hero Title" (must match exactly, including spaces)
|
|
63
|
+
|
|
64
|
+
[ ] Are you using the right field helper?
|
|
65
|
+
Single-line text → <Text field={fields['Hero Title']} />
|
|
66
|
+
Rich text → <RichText field={fields['Hero Title']} />
|
|
67
|
+
Image → <Image field={fields['Hero Image']} />
|
|
68
|
+
Link → <Link field={fields['Hero Link']} />
|
|
69
|
+
Date → fields['Event Date']?.value
|
|
70
|
+
|
|
71
|
+
[ ] Is the rendering item configured with the right datasource template?
|
|
72
|
+
Check: Sitecore > Rendering Item > Datasource Template field
|
|
73
|
+
|
|
74
|
+
[ ] Are you in connected mode?
|
|
75
|
+
Check: .env has correct SITECORE_API_HOST and SITECORE_API_KEY
|
|
76
|
+
Test: curl your layout service URL — does it return data?
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Common field access pattern:**
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { Text, RichText, Image, Link } from '@sitecore-jss/sitecore-jss-nextjs';
|
|
83
|
+
|
|
84
|
+
function HeroBanner({ fields }: HeroBannerProps) {
|
|
85
|
+
return (
|
|
86
|
+
<section>
|
|
87
|
+
{/* Always use field helpers — they handle editing mode */}
|
|
88
|
+
<Text tag="h1" field={fields['Hero Title']} />
|
|
89
|
+
<RichText field={fields['Hero Description']} />
|
|
90
|
+
<Image field={fields['Hero Image']} />
|
|
91
|
+
<Link field={fields['CTA Link']}>
|
|
92
|
+
<Text field={fields['CTA Text']} />
|
|
93
|
+
</Link>
|
|
94
|
+
</section>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 3. GraphQL Query Returns No Data
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
[ ] Test your query in GraphQL Playground first:
|
|
103
|
+
URL: {SITECORE_API_HOST}/sitecore/api/graph/edge
|
|
104
|
+
Headers: sc_apikey: YOUR_KEY
|
|
105
|
+
|
|
106
|
+
[ ] Check the query path — is the item path correct?
|
|
107
|
+
path: "/sitecore/content/your-site/home" (full Sitecore path)
|
|
108
|
+
|
|
109
|
+
[ ] Check language — is sc_lang set correctly?
|
|
110
|
+
Default is "en" — if your content is in another language, specify it
|
|
111
|
+
|
|
112
|
+
[ ] Are you querying the right database?
|
|
113
|
+
Connected mode uses "web" (published)
|
|
114
|
+
Disconnected uses mock data
|
|
115
|
+
|
|
116
|
+
[ ] Is the content published?
|
|
117
|
+
Sitecore content must be published to "web" database to appear in API
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 4. Experience Editor / Pages Editor Not Working
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
[ ] Component renders in preview but not in editor:
|
|
124
|
+
- Check if component uses 'use client' — editor needs server rendering
|
|
125
|
+
- Verify field helpers are used (not raw field.value access)
|
|
126
|
+
|
|
127
|
+
[ ] Field editing doesn't work (can't click to edit):
|
|
128
|
+
- Field helpers must render the field directly, not extract .value
|
|
129
|
+
Bad: <h1>{fields['Title'].value}</h1>
|
|
130
|
+
Good: <Text tag="h1" field={fields['Title']} />
|
|
131
|
+
|
|
132
|
+
[ ] Component disappears in editor:
|
|
133
|
+
- Check for hydration mismatches (SSR vs client render differences)
|
|
134
|
+
- Check browser console for React hydration errors
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 5. Environment & Connection Issues
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
[ ] "Unauthorized" errors:
|
|
141
|
+
- Check SITECORE_API_KEY is correct
|
|
142
|
+
- Check the API key is published in Sitecore
|
|
143
|
+
- Verify the API key has the correct CORS origins
|
|
144
|
+
|
|
145
|
+
[ ] CORS errors:
|
|
146
|
+
- Add your dev URL (http://localhost:3000) to the API key's allowed origins
|
|
147
|
+
- In Sitecore: /sitecore/system/Settings/Services/API Keys
|
|
148
|
+
|
|
149
|
+
[ ] "Network error" in development:
|
|
150
|
+
- Is the Sitecore instance running?
|
|
151
|
+
- Can you reach SITECORE_API_HOST from your machine?
|
|
152
|
+
- Check VPN if the instance is behind a corporate network
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## What to Check / Generate
|
|
156
|
+
|
|
157
|
+
### Quick Debug Technique
|
|
158
|
+
|
|
159
|
+
When all else fails, dump the layout service response to see exactly what Sitecore is returning:
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
// Temporary debug — add to your page component
|
|
163
|
+
console.log('Layout data:', JSON.stringify(layoutData, null, 2));
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Check for: field names, placeholder names, component names, data structure.
|
|
167
|
+
|
|
168
|
+
### Cross-Category Checks
|
|
169
|
+
|
|
170
|
+
These apply to ALL symptom categories:
|
|
171
|
+
- Is the `.env` file configured with correct `SITECORE_API_HOST` and `SITECORE_API_KEY`?
|
|
172
|
+
- Is the Sitecore instance accessible from the development machine?
|
|
173
|
+
- Has the content been published to the `web` database?
|
|
174
|
+
- Are you running in connected mode or disconnected mode?
|
|
175
|
+
|
|
176
|
+
## Output Format
|
|
177
|
+
|
|
178
|
+
You MUST structure your response exactly as follows:
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
## Sitecore Debug Report
|
|
182
|
+
|
|
183
|
+
### Symptom Category
|
|
184
|
+
[which of the 5 categories]
|
|
185
|
+
|
|
186
|
+
### Root Cause
|
|
187
|
+
[specific explanation of what's wrong]
|
|
188
|
+
|
|
189
|
+
### Checklist Results
|
|
190
|
+
[each checklist item with PASS/FAIL/UNABLE TO CHECK]
|
|
191
|
+
|
|
192
|
+
### Fix
|
|
193
|
+
[exact code change or configuration fix with file path and line number]
|
|
194
|
+
|
|
195
|
+
### Verification
|
|
196
|
+
[how to verify the fix worked]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Self-Check
|
|
200
|
+
|
|
201
|
+
Before responding, verify:
|
|
202
|
+
- [ ] You read the target component/config file(s) before diagnosing
|
|
203
|
+
- [ ] You identified the correct symptom category
|
|
204
|
+
- [ ] You checked EVERY item in the relevant checklist
|
|
205
|
+
- [ ] Your fix includes specific file paths and line numbers
|
|
206
|
+
- [ ] You provided a verification step to confirm the fix works
|
|
207
|
+
- [ ] You checked cross-category issues (env config, connectivity, publishing)
|
|
208
|
+
|
|
209
|
+
## Constraints
|
|
210
|
+
|
|
211
|
+
- Do NOT guess the issue without reading the actual code and config files.
|
|
212
|
+
- Do NOT skip checklist items. If you cannot verify an item, mark it "UNABLE TO CHECK" and explain why.
|
|
213
|
+
- Do NOT provide generic Sitecore advice. Every suggestion must reference the specific code or configuration in the target files.
|
|
214
|
+
- Do NOT overlook the simple things — field name casing, placeholder naming, and missing component registration cause the majority of issues.
|
|
215
|
+
|
|
216
|
+
Target: $ARGUMENTS
|