@mikulgohil/ai-kit 1.2.1 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikulgohil/ai-kit",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "AI-assisted development setup kit. Auto-detects your tech stack and generates tailored CLAUDE.md, .cursorrules, hooks, agents, context modes, slash commands, and developer guides.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,8 +22,42 @@ app/
22
22
  api/ ← Route Handlers
23
23
  ```
24
24
 
25
+ ## Server Actions
26
+ - Use `'use server'` directive at the top of the file or inline in a function
27
+ - For form handling: pass Server Action directly to `<form action={myAction}>`
28
+ - Use `useActionState` (React 19) for form state management with pending/error states
29
+ - Always validate input with Zod before processing
30
+ - Call `revalidatePath()` or `revalidateTag()` after mutations to update cached data
31
+ - Return structured results `{ success, error, data }` — do not throw from Server Actions
32
+
33
+ ## Streaming & Suspense
34
+ - Use `loading.tsx` for route-level loading states (automatic Suspense boundary)
35
+ - Wrap slow data-fetching components in `<Suspense fallback={...}>` for granular streaming
36
+ - Nested Suspense boundaries enable progressive page rendering
37
+ - `loading.tsx` applies to the entire route segment; `<Suspense>` is per-component
38
+
39
+ ## Route Groups & Layouts
40
+ - Use `(groupName)/` directories to organize routes without affecting URL structure
41
+ - Route groups can have their own `layout.tsx` for section-specific layouts
42
+ - Example: `(marketing)/about/page.tsx` → URL is `/about`, not `/(marketing)/about`
43
+ - Use parallel routes (`@slot/`) for independent loading states within a layout
44
+
45
+ ## Middleware
46
+ - Place `middleware.ts` in the project root (next to `app/`)
47
+ - Use `matcher` config to scope middleware to specific routes
48
+ - Common uses: authentication guards, redirects, i18n locale detection, Sitecore preview mode
49
+ - Middleware runs on the Edge — use only Edge-compatible APIs (no Node.js fs, path, etc.)
50
+
51
+ ## ISR (Incremental Static Regeneration)
52
+ - Set `revalidate` in `fetch()` options: `fetch(url, { next: { revalidate: 60 } })`
53
+ - Use `export const revalidate = 60` at the page/layout level for time-based ISR
54
+ - Use `revalidateTag(tag)` or `revalidatePath(path)` in Server Actions for on-demand ISR
55
+ - Tag fetches with `fetch(url, { next: { tags: ['posts'] } })` for targeted revalidation
56
+
25
57
  ## Common Mistakes to Avoid
26
58
  - Don't use `useEffect` for data fetching in Server Components
27
59
  - Don't import server-only code in Client Components
28
60
  - Don't use `router.push` for simple navigation — use `<Link>`
29
- - Don't forget to add `loading.tsx` for route transitions
61
+ - Don't forget to add `loading.tsx` for route transitions
62
+ - Don't throw errors from Server Actions — return error objects instead
63
+ - Don't use Node.js APIs in Middleware — it runs on the Edge runtime
@@ -6,8 +6,9 @@
6
6
  - Use `@sitecore-jss/sitecore-jss-nextjs` or `@sitecore-content-sdk/nextjs` for component bindings
7
7
 
8
8
  ## Component Patterns
9
+
10
+ ### JSS-based (v21.x)
9
11
  ```typescript
10
- // Standard Sitecore component pattern
11
12
  import { Text, RichText, Image, Link } from '@sitecore-jss/sitecore-jss-nextjs';
12
13
  import type { ComponentRendering, ComponentFields } from '@sitecore-jss/sitecore-jss-nextjs';
13
14
 
@@ -31,6 +32,100 @@ const MyComponent = ({ fields }: MyComponentProps): JSX.Element => (
31
32
  export default MyComponent;
32
33
  ```
33
34
 
35
+ ### Content SDK v2.x
36
+ ```typescript
37
+ import { Text, RichText, Image, Link } from '@sitecore-content-sdk/nextjs';
38
+ import type { ComponentRendering, ComponentFields, Field } from '@sitecore-content-sdk/nextjs';
39
+
40
+ interface MyComponentFields extends ComponentFields {
41
+ heading: Field<string>;
42
+ body: Field<string>;
43
+ }
44
+
45
+ type MyComponentProps = {
46
+ rendering: ComponentRendering;
47
+ fields: MyComponentFields;
48
+ };
49
+
50
+ const MyComponent = ({ fields }: MyComponentProps): JSX.Element => (
51
+ <div>
52
+ <Text field={fields.heading} tag="h2" />
53
+ <RichText field={fields.body} />
54
+ </div>
55
+ );
56
+
57
+ export default MyComponent;
58
+ ```
59
+
60
+ ## Experience Edge GraphQL
61
+ - Use Experience Edge for cross-page queries: navigation, search indexes, content listings
62
+ - Endpoint: `https://edge.sitecorecloud.io/api/graphql/v1`
63
+ - Authenticate with `sc_apikey` header
64
+ - Paginate with `first` and `after` parameters
65
+ - Cache responses with appropriate TTL — Edge content is published/read-only
66
+
67
+ ```graphql
68
+ query NavigationQuery($rootPath: String!, $language: String!) {
69
+ search(
70
+ where: {
71
+ AND: [
72
+ { name: "_path", value: $rootPath, operator: CONTAINS }
73
+ { name: "_language", value: $language }
74
+ { name: "_templatename", value: "Navigation Item" }
75
+ ]
76
+ }
77
+ first: 50
78
+ ) {
79
+ results {
80
+ name
81
+ url { path }
82
+ ... on NavigationItem {
83
+ title { value }
84
+ link { jsonValue }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ ## Sitecore Image Optimization
92
+ - Use `next/image` with Sitecore image fields for responsive images
93
+ - Extract `src`, `alt`, `width`, `height` from the Sitecore `ImageField` value
94
+ - Configure Sitecore CDN domain in `next.config.js` `images.remotePatterns`
95
+
96
+ ```typescript
97
+ import NextImage from 'next/image';
98
+ import type { ImageField } from '@sitecore-jss/sitecore-jss-nextjs';
99
+
100
+ function OptimizedImage({ field }: { field: ImageField }) {
101
+ if (!field?.value?.src) return null;
102
+ const { src, alt, width, height } = field.value;
103
+ return (
104
+ <NextImage
105
+ src={src}
106
+ alt={alt || ''}
107
+ width={Number(width) || 800}
108
+ height={Number(height) || 600}
109
+ />
110
+ );
111
+ }
112
+ ```
113
+
114
+ ## Personalization & Variants
115
+ - Sitecore delivers personalized component variants via Layout Service
116
+ - Personalized pages require SSR — they cannot be statically generated
117
+ - Component variants are transparent to the React component — same props, different data
118
+ - Test both default and personalized rendering in development
119
+
120
+ ## Environment Setup
121
+ Required `.env.local` variables for XM Cloud:
122
+ ```
123
+ SITECORE_API_KEY=your-api-key
124
+ SITECORE_API_HOST=https://your-instance.sitecorecloud.io
125
+ GRAPH_QL_ENDPOINT=https://edge.sitecorecloud.io/api/graphql/v1
126
+ SITECORE_SITE_NAME=your-site-name
127
+ ```
128
+
34
129
  ## Rules
35
130
  - Always use Sitecore field helpers (`<Text>`, `<RichText>`, `<Image>`, `<Link>`) — never render field values directly
36
131
  - This enables Experience Editor / Pages inline editing
@@ -43,4 +138,6 @@ export default MyComponent;
43
138
  - Don't render `fields.heading.value` directly — use `<Text field={fields.heading} />`
44
139
  - Don't hardcode content that should come from Sitecore fields
45
140
  - Don't forget to register new components in the component factory
46
- - Don't use `getStaticProps` directly — use Sitecore's built-in SSG/SSR integration
141
+ - Don't use `getStaticProps` directly — use Sitecore's built-in SSG/SSR integration
142
+ - Don't statically generate personalized pages — they need SSR
143
+ - Don't forget to configure Sitecore CDN domain in `next.config.js` for image optimization
@@ -11,9 +11,87 @@
11
11
  - Use `satisfies` for type-safe object literals when the type is known
12
12
  - Use discriminated unions for state management (loading/success/error)
13
13
  - Prefer `as const` for literal type inference
14
+ - Use branded types for domain identifiers: `type UserId = string & { readonly __brand: 'UserId' }`
15
+
16
+ ## Sitecore Field Typing
17
+ ```typescript
18
+ // Typed component props with Sitecore fields
19
+ import type { Field, ImageField, LinkField, ComponentRendering } from '@sitecore-jss/sitecore-jss-nextjs';
20
+
21
+ interface HeroBannerFields {
22
+ heading: Field<string>;
23
+ body: Field<string>;
24
+ image: ImageField;
25
+ cta: LinkField;
26
+ }
27
+
28
+ type HeroBannerProps = {
29
+ rendering: ComponentRendering;
30
+ fields: HeroBannerFields;
31
+ };
32
+
33
+ // Type guard for checking if a field has a value
34
+ function hasFieldValue<T>(field: Field<T> | undefined): field is Field<T> & { value: T } {
35
+ return field !== undefined && field.value !== undefined && field.value !== null;
36
+ }
37
+ ```
38
+
39
+ ## Next.js Typing
40
+ ```typescript
41
+ // Page props (App Router)
42
+ type PageProps = {
43
+ params: Promise<{ slug: string }>;
44
+ searchParams: Promise<Record<string, string | string[] | undefined>>;
45
+ };
46
+
47
+ // Layout props
48
+ type LayoutProps = {
49
+ children: React.ReactNode;
50
+ params: Promise<{ locale: string }>;
51
+ };
52
+
53
+ // Server Action return type
54
+ type ActionResult<T = void> =
55
+ | { success: true; data: T }
56
+ | { success: false; error: string };
57
+
58
+ // Metadata generation
59
+ import type { Metadata } from 'next';
60
+ export async function generateMetadata({ params }: PageProps): Promise<Metadata> { ... }
61
+ ```
62
+
63
+ ## Tailwind Type Safety
64
+ ```typescript
65
+ // Typed Tailwind config extensions
66
+ import type { Config } from 'tailwindcss';
67
+
68
+ const config: Config = {
69
+ content: ['./src/**/*.{ts,tsx}'],
70
+ theme: {
71
+ extend: {
72
+ colors: { brand: { primary: '#...', secondary: '#...' } },
73
+ },
74
+ },
75
+ };
76
+ ```
77
+
78
+ ## Validation with Zod
79
+ ```typescript
80
+ import { z } from 'zod';
81
+
82
+ // Define schema once — derive TypeScript type from it
83
+ const ContactFormSchema = z.object({
84
+ name: z.string().min(1, 'Name is required'),
85
+ email: z.string().email('Invalid email'),
86
+ message: z.string().min(10, 'Message too short'),
87
+ });
88
+
89
+ type ContactForm = z.infer<typeof ContactFormSchema>;
90
+ ```
14
91
 
15
92
  ## Common Mistakes to Avoid
16
93
  - Don't use `any` to bypass type errors — fix the underlying type issue
17
94
  - Don't create unnecessary generic types — use them only when the type genuinely varies
18
95
  - Don't duplicate types — import from a shared types file
19
- - Don't use optional chaining as a substitute for proper null checking
96
+ - Don't use optional chaining as a substitute for proper null checking
97
+ - Don't use `as` type assertions when a type guard or `satisfies` would be safer
@@ -5,4 +5,9 @@
5
5
  - Colocate `loading.tsx`, `error.tsx`, `not-found.tsx` with pages
6
6
  - Data fetching: use `fetch()` in Server Components, Server Actions for mutations
7
7
  - Use `<Link>` for navigation, `next/image` for images
8
- - No `useEffect` for data fetching in Server Components
8
+ - No `useEffect` for data fetching in Server Components
9
+ - Server Actions: validate with Zod, return `{ success, error }`, call `revalidatePath`/`revalidateTag` after mutations
10
+ - Streaming: wrap slow components in `<Suspense fallback={...}>` for progressive rendering
11
+ - ISR: use `fetch(url, { next: { revalidate: N } })` or `export const revalidate = N`
12
+ - Middleware: place `middleware.ts` at project root, use `matcher` config, Edge-compatible APIs only
13
+ - Route Groups: use `(groupName)/` for organization without affecting URL paths
@@ -6,4 +6,8 @@
6
6
  - Register new components in the component factory
7
7
  - GraphQL queries go in `.graphql` files alongside components
8
8
  - Don't use `getStaticProps` directly — use Sitecore's SSG/SSR integration
9
- - Don't hardcode content that should come from Sitecore fields
9
+ - Don't hardcode content that should come from Sitecore fields
10
+ - Content SDK v2.x: import from `@sitecore-content-sdk/nextjs` instead of `@sitecore-jss/sitecore-jss-nextjs`
11
+ - Experience Edge: use `first`/`after` for pagination, cache responses appropriately
12
+ - Personalized pages require SSR — do not statically generate them
13
+ - Use `next/image` with Sitecore image fields — configure CDN domain in `next.config.js`
@@ -5,4 +5,9 @@
5
5
  - Use `unknown` over `any` — narrow with type guards
6
6
  - No `@ts-ignore` without explanation comments
7
7
  - Use `satisfies` for type-safe literals, `as const` for inference
8
- - Import types from shared files — don't duplicate
8
+ - Import types from shared files — don't duplicate
9
+ - Sitecore: type component fields with `Field<string>`, `ImageField`, `LinkField`
10
+ - Next.js: use `Promise<{ slug: string }>` for `params` in App Router page props
11
+ - Server Actions: return `{ success: true; data: T } | { success: false; error: string }`
12
+ - Validation: define Zod schemas, derive TS types with `z.infer<typeof Schema>`
13
+ - Prefer type guards and `satisfies` over `as` type assertions