@gradial/aci 0.1.27 → 0.1.29
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 +47 -0
- package/bin/aci-darwin-arm64 +0 -0
- package/dist/assets/index.d.ts +1 -1
- package/dist/astro/index.d.ts +1 -0
- package/dist/astro/index.js +7 -0
- package/dist/collect/api.d.ts +24 -0
- package/dist/collect/api.js +63 -0
- package/dist/collect/batcher.d.ts +65 -0
- package/dist/collect/batcher.js +127 -0
- package/dist/collect/config.d.ts +30 -0
- package/dist/collect/config.js +53 -0
- package/dist/collect/consent/adapters/c15t.d.ts +2 -0
- package/dist/collect/consent/adapters/c15t.js +43 -0
- package/dist/collect/consent/adapters/cookiebot.d.ts +2 -0
- package/dist/collect/consent/adapters/cookiebot.js +48 -0
- package/dist/collect/consent/adapters/onetrust.d.ts +2 -0
- package/dist/collect/consent/adapters/onetrust.js +54 -0
- package/dist/collect/consent/adapters/trustarc.d.ts +2 -0
- package/dist/collect/consent/adapters/trustarc.js +65 -0
- package/dist/collect/consent/envelope.d.ts +49 -0
- package/dist/collect/consent/envelope.js +100 -0
- package/dist/collect/consent/mapping.d.ts +62 -0
- package/dist/collect/consent/mapping.js +129 -0
- package/dist/collect/declarative.d.ts +35 -0
- package/dist/collect/declarative.js +100 -0
- package/dist/collect/gapbuffer.d.ts +55 -0
- package/dist/collect/gapbuffer.js +134 -0
- package/dist/collect/index.d.ts +6 -0
- package/dist/collect/index.js +154 -0
- package/dist/collect/linkclicks.d.ts +12 -0
- package/dist/collect/linkclicks.js +35 -0
- package/dist/collect/pageviews.d.ts +22 -0
- package/dist/collect/pageviews.js +42 -0
- package/dist/collect/transport.d.ts +22 -0
- package/dist/collect/transport.js +52 -0
- package/dist/collect/ulid.d.ts +6 -0
- package/dist/collect/ulid.js +36 -0
- package/dist/collect/variationviews.d.ts +31 -0
- package/dist/collect/variationviews.js +80 -0
- package/dist/collect/webvitals.d.ts +38 -0
- package/dist/collect/webvitals.js +99 -0
- package/dist/content/index.d.ts +1 -0
- package/dist/content/index.js +1 -0
- package/dist/content/personalization.d.ts +57 -0
- package/dist/content/personalization.js +54 -0
- package/dist/content/types.d.ts +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/next/asset-route.js +16 -3
- package/dist/next/collect-script.d.ts +12 -0
- package/dist/next/collect-script.js +15 -0
- package/dist/next/config.js +1 -0
- package/dist/next/index.d.ts +3 -0
- package/dist/next/index.js +3 -0
- package/dist/next/page.d.ts +2 -0
- package/dist/next/page.js +5 -2
- package/dist/react/VideoPlayer.d.ts +3 -3
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +2 -1
- package/dist/types/data.d.ts +2 -0
- package/dist/types/image.d.ts +37 -11
- package/dist/types/image.js +20 -17
- package/dist/types/media.d.ts +14 -2
- package/dist/types/page.d.ts +2 -0
- package/dist/types/video.d.ts +7 -1
- package/package.json +6 -1
- package/src/types/data.ts +3 -0
- package/src/types/image.ts +44 -29
- package/src/types/page.ts +2 -0
- package/templates/astro/template/package.json.tmpl +1 -1
- package/templates/astro/template/src/fixtures/sections.ts +2 -1
- package/templates/astro/template/src/layouts/SiteLayout.astro +77 -1
- package/templates/astro/template/src/pages/[...slug].astro +3 -2
- package/templates/common/.agents/AGENTS.md +5 -0
- package/templates/common/.agents/skills/authoring/SKILL.md +31 -0
- package/templates/common/.agents/skills/authoring/references/asset-rendering.md +110 -0
- package/templates/common/.agents/skills/authoring/references/block-slots.md +140 -0
- package/templates/common/.agents/skills/authoring/references/rich-text.md +75 -0
- package/templates/common/.agents/skills/authoring/references/sdk-server-functions.md +192 -0
- package/templates/common/.agents/skills/authoring/references/type-safety.md +141 -0
- package/templates/common/.content/config/site.json +5 -0
- package/templates/common/.content/schemas/site.schema.json +15 -0
- package/templates/common/README.md.tmpl +15 -0
- package/templates/nextjs/template/package.json.tmpl +3 -1
- package/templates/nextjs/template/src/app/_components/ConsentManager.tsx +132 -0
- package/templates/nextjs/template/src/app/layout.tsx +3 -1
- package/templates/nextjs/template/src/components/sections/HomeHero.tsx +1 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Block Slots Reference
|
|
2
|
+
|
|
3
|
+
## What Block Slots Are
|
|
4
|
+
|
|
5
|
+
Container components (like `container` and `grid_column`) can render
|
|
6
|
+
child blocks. The SDK detects block slots from contracts and injects a
|
|
7
|
+
`renderChildren` callback into the component props at render time.
|
|
8
|
+
|
|
9
|
+
This lets editors nest blocks inside other blocks in content JSON, and
|
|
10
|
+
the SDK resolves the child components through the registry — no
|
|
11
|
+
hardcoded component name matching needed.
|
|
12
|
+
|
|
13
|
+
## Defining Block Slots in Contracts
|
|
14
|
+
|
|
15
|
+
Use `blockRefArray()` from `@gradial/aci` in the contract's Zod schema
|
|
16
|
+
to declare a block slot field. The compiler scans the schema for
|
|
17
|
+
`blockRefArray` and `blockRef` fields and auto-discovers block slots —
|
|
18
|
+
no separate `slots` or `blockSlots` declaration needed.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { blockRefArray, defineComponentContract } from '@gradial/aci';
|
|
22
|
+
import { z } from 'zod';
|
|
23
|
+
import { calloutContract } from './callout.contract';
|
|
24
|
+
import { headingContract } from './heading.contract';
|
|
25
|
+
|
|
26
|
+
export const schema = z.object({
|
|
27
|
+
theme: z.enum(['auto', 'light', 'dark']).optional(),
|
|
28
|
+
className: z.string().optional(),
|
|
29
|
+
blocks: blockRefArray([calloutContract, headingContract]).optional(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export type ContentProps = z.infer<typeof schema>;
|
|
33
|
+
|
|
34
|
+
export const containerContract = defineComponentContract({
|
|
35
|
+
id: 'container',
|
|
36
|
+
props: schema,
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`blockRefArray()` takes an array of allowed contracts — only those block
|
|
41
|
+
types can be placed in the slot. This flows into the generated JSON
|
|
42
|
+
schema, so the content validator enforces the allowlist at build time.
|
|
43
|
+
|
|
44
|
+
For a single (non-array) block slot, use `blockRef(contracts)` instead:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { blockRef, defineComponentContract } from '@gradial/aci';
|
|
48
|
+
import { headingContract } from './heading.contract';
|
|
49
|
+
|
|
50
|
+
export const schema = z.object({
|
|
51
|
+
heading: blockRef([headingContract]).optional(),
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Using renderChildren in Components
|
|
56
|
+
|
|
57
|
+
The SDK's render system checks `entry.contract.blockSlots` and, if
|
|
58
|
+
present, injects a `renderChildren` callback into the component props.
|
|
59
|
+
This callback resolves child blocks through the registry.
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import type { BlockRef, ReactElement } from '@gradial/aci';
|
|
63
|
+
import type { RenderChildren } from '@gradial/aci/react';
|
|
64
|
+
import type { ContentProps } from '@/cms/contracts/components/container.contract';
|
|
65
|
+
|
|
66
|
+
export async function ContainerSection({
|
|
67
|
+
theme = 'auto',
|
|
68
|
+
className = '',
|
|
69
|
+
blocks = [],
|
|
70
|
+
renderChildren,
|
|
71
|
+
}: ContentProps & { renderChildren?: RenderChildren<readonly BlockRef[]> }) {
|
|
72
|
+
const rendered = blocks.length && renderChildren
|
|
73
|
+
? await renderChildren(blocks)
|
|
74
|
+
: null;
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<section className={`theme-${theme} py-[var(--spacing-section-y)] ${className}`}>
|
|
78
|
+
<div className="flex flex-col gap-6">
|
|
79
|
+
{rendered}
|
|
80
|
+
</div>
|
|
81
|
+
</section>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The `RenderChildren` type is exported from `@gradial/aci/react`:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
type RenderChildren<T extends readonly BlockRef[]> = (blocks: T) => Promise<ReactElement[]>;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Rules
|
|
93
|
+
|
|
94
|
+
- **Never hardcode component name matching.** No switch statements on
|
|
95
|
+
`block.component`. Always use `renderChildren` from the SDK — it uses
|
|
96
|
+
the registry to resolve components.
|
|
97
|
+
- **Always use `blockRefArray()` in contracts** to declare block slot
|
|
98
|
+
fields. The compiler auto-discovers them from the Zod schema.
|
|
99
|
+
- **Atomic block contracts must be registered** in the registry with
|
|
100
|
+
their components. `renderChildren` resolves child blocks through the
|
|
101
|
+
same registry used for top-level blocks.
|
|
102
|
+
- **`blockRefArray()` takes an array of allowed contracts** — only
|
|
103
|
+
those block types can be placed in the slot. This is enforced at
|
|
104
|
+
content validation time.
|
|
105
|
+
- **`renderChildren` is optional** — always guard with a conditional
|
|
106
|
+
(`blocks.length && renderChildren ? await renderChildren(blocks) : null`)
|
|
107
|
+
so the component works in isolation (e.g., Storybook).
|
|
108
|
+
- **Nested blocks live inside `props`**, not in a sibling `slots` field.
|
|
109
|
+
The content JSON places child blocks directly in the prop value
|
|
110
|
+
matching the `blockRefArray` field name.
|
|
111
|
+
|
|
112
|
+
## Content JSON Example
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"id": "cta-section",
|
|
117
|
+
"component": "container",
|
|
118
|
+
"props": {
|
|
119
|
+
"theme": "dark",
|
|
120
|
+
"blocks": [
|
|
121
|
+
{
|
|
122
|
+
"id": "primary-cta",
|
|
123
|
+
"component": "callout",
|
|
124
|
+
"props": {
|
|
125
|
+
"headline": "Get started today",
|
|
126
|
+
"body": "Ship content updates in minutes."
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"id": "heading",
|
|
131
|
+
"component": "heading",
|
|
132
|
+
"props": {
|
|
133
|
+
"text": "Why teams choose us",
|
|
134
|
+
"level": 2
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Rich Text Reference
|
|
2
|
+
|
|
3
|
+
## Rules
|
|
4
|
+
|
|
5
|
+
- **NEVER** use `marked`, `markdown-it`, or `dangerouslySetInnerHTML`
|
|
6
|
+
directly in component code.
|
|
7
|
+
- **ALWAYS** use the SDK's `RichText` component from `@gradial/aci/react`.
|
|
8
|
+
|
|
9
|
+
The SDK `RichText` component uses `sanitize-html` with an explicit
|
|
10
|
+
allowlist. It renders markdown via `markdown-it` (with `html: false` to
|
|
11
|
+
prevent raw HTML in markdown) and then sanitizes the output. Links get
|
|
12
|
+
`rel="noopener noreferrer"` automatically.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { RichText } from '@gradial/aci/react';
|
|
18
|
+
|
|
19
|
+
export function ArticleBody({ body }: { body: string }) {
|
|
20
|
+
return <RichText value={body} />;
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The `value` prop accepts:
|
|
25
|
+
|
|
26
|
+
- **`string`** — treated as markdown and rendered to HTML
|
|
27
|
+
- **`RichTextValue`** object — `{ format: 'markdown', markdown: '...' }`
|
|
28
|
+
or `{ format: 'html', html: '...' }`
|
|
29
|
+
|
|
30
|
+
When a string is passed, the component wraps it as
|
|
31
|
+
`{ format: 'markdown', markdown: value }` internally.
|
|
32
|
+
|
|
33
|
+
## In Contracts
|
|
34
|
+
|
|
35
|
+
Use `RichTextValueSchema` for typed rich text fields:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { RichTextValueSchema } from '@gradial/aci';
|
|
39
|
+
import { z } from 'zod';
|
|
40
|
+
|
|
41
|
+
export const schema = z.object({
|
|
42
|
+
body: RichTextValueSchema.optional(),
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or accept a plain string:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
export const schema = z.object({
|
|
50
|
+
body: z.string().optional(),
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Both forms work with the `RichText` component — it accepts
|
|
55
|
+
`RichTextValue | string`.
|
|
56
|
+
|
|
57
|
+
## Sanitization Policy
|
|
58
|
+
|
|
59
|
+
The SDK allowlist includes:
|
|
60
|
+
|
|
61
|
+
- Standard formatting tags: `p`, `br`, `strong`, `em`, `ul`, `ol`, `li`,
|
|
62
|
+
`code`, `pre`, `blockquote`, `h1`–`h6`, `img`
|
|
63
|
+
- Links (`a`) with `href`, `name`, `target`, `rel` attributes
|
|
64
|
+
- Images (`img`) with `src`, `alt`, `width`, `height`, `loading`
|
|
65
|
+
attributes
|
|
66
|
+
|
|
67
|
+
Raw HTML in markdown input is rejected by `markdown-it`'s `html: false`
|
|
68
|
+
setting. HTML format values are sanitized by `sanitize-html`.
|
|
69
|
+
|
|
70
|
+
## Anti-Patterns
|
|
71
|
+
|
|
72
|
+
- Importing `marked` or `markdown-it` directly — the SDK already
|
|
73
|
+
handles this with proper sanitization
|
|
74
|
+
- Using `dangerouslySetInnerHTML` with unsanitized content
|
|
75
|
+
- Writing a custom markdown-to-HTML pipeline in component code
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# SDK Server Functions Reference
|
|
2
|
+
|
|
3
|
+
## `@gradial/aci/next` Exports
|
|
4
|
+
|
|
5
|
+
The SDK provides server-side functions that handle content resolution
|
|
6
|
+
across preview, local file, and deployed S3 modes. **Always use these
|
|
7
|
+
functions instead of directly importing `FileContentProvider` or
|
|
8
|
+
`S3ContentProvider`.** The SDK handles the resolution chain automatically.
|
|
9
|
+
|
|
10
|
+
### `createPage(registry)`
|
|
11
|
+
|
|
12
|
+
The catch-all route handler for Next.js App Router. Owns param
|
|
13
|
+
normalization, content loading via render input, metadata generation,
|
|
14
|
+
`notFound` handling, layout resolution, and block rendering via the
|
|
15
|
+
registry.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
// src/app/[[...slug]]/page.tsx
|
|
19
|
+
import { createPage } from '@gradial/aci/next';
|
|
20
|
+
import { registry } from '@/cms/registry';
|
|
21
|
+
|
|
22
|
+
const page = createPage(registry);
|
|
23
|
+
export const dynamic = 'force-dynamic';
|
|
24
|
+
export const generateMetadata = page.generateMetadata;
|
|
25
|
+
export default page.default;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`createPage` loads the page's layout, resolves all slots (filling from
|
|
29
|
+
page regions or layout fragment defaults), and renders blocks via the
|
|
30
|
+
registry. The `main` slot is wrapped in `<main>`; other slots render as
|
|
31
|
+
fragments.
|
|
32
|
+
|
|
33
|
+
### `withAci(nextConfig, options?)`
|
|
34
|
+
|
|
35
|
+
Next.js config wrapper. Sets up asset rewrites (`.gradial-dam` prefix)
|
|
36
|
+
and dev-mode content watch via webpack plugin.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// next.config.ts
|
|
40
|
+
import { withAci } from '@gradial/aci/next';
|
|
41
|
+
import type { NextConfig } from 'next';
|
|
42
|
+
|
|
43
|
+
const nextConfig: NextConfig = { reactStrictMode: true };
|
|
44
|
+
export default withAci(nextConfig);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `getSiteConfig<T>()`
|
|
48
|
+
|
|
49
|
+
Loads the site configuration. Checks the render input header first
|
|
50
|
+
(preview mode), then falls back to file or S3 provider. **MUST be used
|
|
51
|
+
in `layout.tsx` instead of `new FileContentProvider()`.**
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { getSiteConfig } from '@gradial/aci/next';
|
|
55
|
+
|
|
56
|
+
const siteConfig = await getSiteConfig<MySiteConfig>();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Generic: pass your site config interface for typed access:
|
|
60
|
+
`getSiteConfig<SiteConfig>()`.
|
|
61
|
+
|
|
62
|
+
### `getFragment(name)`
|
|
63
|
+
|
|
64
|
+
Loads a fragment by name. Checks render input first (preview mode), then
|
|
65
|
+
provider fallback.
|
|
66
|
+
|
|
67
|
+
### `getLayout(name)`
|
|
68
|
+
|
|
69
|
+
Loads a layout by name. Checks render input first (preview mode), then
|
|
70
|
+
provider fallback.
|
|
71
|
+
|
|
72
|
+
### `getPage(route)`
|
|
73
|
+
|
|
74
|
+
Loads page content for a specific route. Checks render input first
|
|
75
|
+
(preview mode), then provider fallback.
|
|
76
|
+
|
|
77
|
+
### `getRenderInput(route)`
|
|
78
|
+
|
|
79
|
+
Loads the full render input (page + siteConfig + domain + locale). Used
|
|
80
|
+
internally by `createPage`. Available for custom server composition when
|
|
81
|
+
you need the full render context.
|
|
82
|
+
|
|
83
|
+
### `routeFromNextParams(params)`
|
|
84
|
+
|
|
85
|
+
Normalizes Next.js catch-all params (`{ slug?: string[] }`) into a route
|
|
86
|
+
string. Handles `Promise`-wrapped params from Next.js 15+.
|
|
87
|
+
|
|
88
|
+
### `isPreviewMode()`
|
|
89
|
+
|
|
90
|
+
Async function returning the preview release ID string when in preview
|
|
91
|
+
mode, or an empty string when not. Use as a truthy check:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
const previewRelease = await isPreviewMode();
|
|
95
|
+
if (previewRelease) { /* preview-specific logic */ }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### `DevRefresh`
|
|
99
|
+
|
|
100
|
+
React component for dev-mode content refresh. Connects to the SDK's
|
|
101
|
+
content watch WebSocket and triggers a page reload when compiled content
|
|
102
|
+
changes. Add to the root layout:
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
import { DevRefresh } from '@gradial/aci/next';
|
|
106
|
+
|
|
107
|
+
// In layout body:
|
|
108
|
+
<DevRefresh />
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Only active in development (`NODE_ENV !== 'production'`). Renders `null`
|
|
112
|
+
in production.
|
|
113
|
+
|
|
114
|
+
### Error Classes
|
|
115
|
+
|
|
116
|
+
| Class | Thrown When |
|
|
117
|
+
|-------|-------------|
|
|
118
|
+
| `PageNotFoundError` | Page not found for a route |
|
|
119
|
+
| `FragmentNotFoundError` | Fragment not found by name |
|
|
120
|
+
| `LayoutNotFoundError` | Layout not found by name |
|
|
121
|
+
|
|
122
|
+
`createPage` catches `PageNotFoundError` and calls `notFound()`
|
|
123
|
+
automatically.
|
|
124
|
+
|
|
125
|
+
## Three-Tier Content Resolution
|
|
126
|
+
|
|
127
|
+
Every SDK server function follows the same resolution chain:
|
|
128
|
+
|
|
129
|
+
### Tier 1: Render Input (Preview Mode)
|
|
130
|
+
|
|
131
|
+
When the Go harness sends a render request, it sets the
|
|
132
|
+
`x-gradial-render-input-id` header. The SDK checks the
|
|
133
|
+
`pendingRenderInputs` in-process map for a matching render input and
|
|
134
|
+
returns page data directly from the Go harness's render payload. This
|
|
135
|
+
is how preview works — the harness pushes content into the Next.js
|
|
136
|
+
process without touching S3 or disk.
|
|
137
|
+
|
|
138
|
+
### Tier 2: File Provider (`ACI_CONTENT_PROVIDER=file`)
|
|
139
|
+
|
|
140
|
+
When the `ACI_CONTENT_PROVIDER` environment variable is set to `file`,
|
|
141
|
+
the SDK reads compiled content from `.aci/compiled/` on disk. This is
|
|
142
|
+
the local development path. Also used as a fallback in preview mode when
|
|
143
|
+
no render input header is present.
|
|
144
|
+
|
|
145
|
+
### Tier 3: S3 Provider (Deployed SSR)
|
|
146
|
+
|
|
147
|
+
When neither render input nor file provider is active, the SDK reads
|
|
148
|
+
from S3. The release ID is resolved from (in order):
|
|
149
|
+
|
|
150
|
+
1. `x-gradial-release-id` header (set by middleware)
|
|
151
|
+
2. `ACI_RELEASE_ID` environment variable
|
|
152
|
+
3. Vercel Edge Config active release pointer
|
|
153
|
+
|
|
154
|
+
## Critical Rule
|
|
155
|
+
|
|
156
|
+
**NEVER import `FileContentProvider` or `S3ContentProvider` directly in
|
|
157
|
+
app code.** Always use `getPage()`, `getSiteConfig()`, `getFragment()`,
|
|
158
|
+
`getLayout()`, or `getRenderInput()` from `@gradial/aci/next`. The SDK
|
|
159
|
+
handles the resolution chain automatically.
|
|
160
|
+
|
|
161
|
+
The only exception is the asset route handler
|
|
162
|
+
(`src/app/gradial/assets/[releaseId]/[...path]/route.ts`), which directly
|
|
163
|
+
uses `FileContentProvider` for local asset serving and
|
|
164
|
+
`getReleaseAssetResponse` for S3 assets.
|
|
165
|
+
|
|
166
|
+
## Layout.tsx Pattern
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { DevRefresh, getSiteConfig } from '@gradial/aci/next';
|
|
170
|
+
|
|
171
|
+
export default async function Layout({ children }: { children: ReactNode }) {
|
|
172
|
+
const siteConfig = await getSiteConfig<SiteConfig>().catch(() => null);
|
|
173
|
+
return (
|
|
174
|
+
<html lang="en">
|
|
175
|
+
<body>
|
|
176
|
+
{children}
|
|
177
|
+
<DevRefresh />
|
|
178
|
+
</body>
|
|
179
|
+
</html>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Chrome (Header/Footer) is CMS-managed via layout fragment defaults and
|
|
185
|
+
rendered by `createPage` through the registry. The `layout.tsx` file
|
|
186
|
+
should be minimal — import CSS, optionally load site config for
|
|
187
|
+
metadata/fonts, and render `<DevRefresh />`.
|
|
188
|
+
|
|
189
|
+
For sites that need site config in the layout (e.g., for fonts or
|
|
190
|
+
metadata), use `getSiteConfig<SiteConfig>()` with a `.catch(() => null)`
|
|
191
|
+
fallback so the layout doesn't crash if content isn't available during
|
|
192
|
+
build.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Type Safety Reference
|
|
2
|
+
|
|
3
|
+
## ContentProps from Contracts
|
|
4
|
+
|
|
5
|
+
Contracts export `ContentProps = z.infer<typeof schema>`. Use this type
|
|
6
|
+
in runtime components for prop typing:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
// src/cms/contracts/components/hero.contract.ts
|
|
10
|
+
import { defineComponentContract, ImageSchema } from '@gradial/aci';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
|
|
13
|
+
export const schema = z.object({
|
|
14
|
+
headline: z.string().min(1),
|
|
15
|
+
image: ImageSchema,
|
|
16
|
+
ctaLabel: z.string().optional(),
|
|
17
|
+
ctaHref: z.string().optional(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export type ContentProps = z.infer<typeof schema>;
|
|
21
|
+
|
|
22
|
+
export const heroContract = defineComponentContract({
|
|
23
|
+
id: 'hero',
|
|
24
|
+
props: schema,
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
// src/components/sections/Hero.tsx
|
|
30
|
+
import type { ContentProps } from '@/cms/contracts/components/hero.contract';
|
|
31
|
+
|
|
32
|
+
type HeroProps = ContentProps & { className?: string };
|
|
33
|
+
|
|
34
|
+
export function Hero({ headline, image, ctaLabel, ctaHref, className }: HeroProps) {
|
|
35
|
+
// ...
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Rules
|
|
40
|
+
|
|
41
|
+
### No `as any` casts
|
|
42
|
+
|
|
43
|
+
**NEVER** use `as any` or `as any[]` casts in component code. If the
|
|
44
|
+
type doesn't fit, fix the contract schema.
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
// BAD
|
|
48
|
+
const items = props.items as any[];
|
|
49
|
+
|
|
50
|
+
// GOOD — fix the schema to match the actual shape
|
|
51
|
+
export const schema = z.object({
|
|
52
|
+
items: z.array(z.object({
|
|
53
|
+
title: z.string(),
|
|
54
|
+
description: z.string(),
|
|
55
|
+
})),
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### No passthrough schemas
|
|
60
|
+
|
|
61
|
+
Contracts must define proper schemas. Do not use
|
|
62
|
+
`z.object({}).passthrough()` or `z.record(z.any())`:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// BAD — hides type errors and allows any content
|
|
66
|
+
export const schema = z.object({}).passthrough();
|
|
67
|
+
export const schema = z.record(z.any());
|
|
68
|
+
|
|
69
|
+
// GOOD — explicit fields
|
|
70
|
+
export const schema = z.object({
|
|
71
|
+
headline: z.string(),
|
|
72
|
+
items: z.array(z.object({ title: z.string() })),
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### CSS custom properties
|
|
77
|
+
|
|
78
|
+
For React `style` props with CSS custom properties, use
|
|
79
|
+
`as React.CSSProperties` (not `as any`):
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
// BAD
|
|
83
|
+
<div style={{ '--accent': 'red' } as any} />
|
|
84
|
+
|
|
85
|
+
// GOOD
|
|
86
|
+
<div style={{ '--accent': 'red' } as React.CSSProperties} />
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Image type
|
|
90
|
+
|
|
91
|
+
Use the `Image` type from `@gradial/aci` for image props. Never
|
|
92
|
+
duplicate the type locally:
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
// BAD — local duplicate
|
|
96
|
+
interface Image { src: string; alt: string; }
|
|
97
|
+
|
|
98
|
+
// GOOD — import from SDK
|
|
99
|
+
import type { Image } from '@gradial/aci';
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Site config
|
|
103
|
+
|
|
104
|
+
Define a `SiteConfig` interface and pass it to `getSiteConfig()`:
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { getSiteConfig } from '@gradial/aci/next';
|
|
108
|
+
|
|
109
|
+
interface SiteConfig {
|
|
110
|
+
title: string;
|
|
111
|
+
domain: string;
|
|
112
|
+
defaultLocale: string;
|
|
113
|
+
navigation: NavItem[];
|
|
114
|
+
footer: FooterConfig;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const config = await getSiteConfig<SiteConfig>();
|
|
118
|
+
// config is typed as SiteConfig
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Block slot types
|
|
122
|
+
|
|
123
|
+
Use `RenderChildren` from `@gradial/aci/react` and `BlockRef` from
|
|
124
|
+
`@gradial/aci` for block slot component props:
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import type { BlockRef } from '@gradial/aci';
|
|
128
|
+
import type { RenderChildren } from '@gradial/aci/react';
|
|
129
|
+
import type { ContentProps } from '@/cms/contracts/components/container.contract';
|
|
130
|
+
|
|
131
|
+
export async function ContainerSection({
|
|
132
|
+
blocks = [],
|
|
133
|
+
renderChildren,
|
|
134
|
+
}: ContentProps & {
|
|
135
|
+
renderChildren?: RenderChildren<readonly BlockRef[]>;
|
|
136
|
+
}) {
|
|
137
|
+
// ...
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
See `references/block-slots.md` for the full block slot pattern.
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
"description": "Global satellite internet from anywhere on Earth.",
|
|
18
18
|
"siteName": "Meridian"
|
|
19
19
|
},
|
|
20
|
+
"personalization": {
|
|
21
|
+
"collect": true,
|
|
22
|
+
"consentPreset": "c15t",
|
|
23
|
+
"consentCategories": "measurement,marketing"
|
|
24
|
+
},
|
|
20
25
|
"navigation": [
|
|
21
26
|
{
|
|
22
27
|
"id": "home",
|
|
@@ -76,6 +76,21 @@
|
|
|
76
76
|
"description": { "type": "string" },
|
|
77
77
|
"siteName": { "type": "string" }
|
|
78
78
|
}
|
|
79
|
+
},
|
|
80
|
+
"personalization": {
|
|
81
|
+
"type": "object",
|
|
82
|
+
"additionalProperties": true,
|
|
83
|
+
"properties": {
|
|
84
|
+
"collect": { "type": "boolean" },
|
|
85
|
+
"consentPreset": {
|
|
86
|
+
"enum": ["c15t", "onetrust", "cookiebot", "trustarc", "manual"]
|
|
87
|
+
},
|
|
88
|
+
"consentCategories": {
|
|
89
|
+
"type": "string",
|
|
90
|
+
"pattern": "^\\s*[A-Za-z0-9._-]+(\\s*,\\s*[A-Za-z0-9._-]+)*\\s*$"
|
|
91
|
+
},
|
|
92
|
+
"debug": { "type": "boolean" }
|
|
93
|
+
}
|
|
79
94
|
}
|
|
80
95
|
},
|
|
81
96
|
"$defs": {
|
|
@@ -43,3 +43,18 @@ src/design-system/ Design tokens and global styles
|
|
|
43
43
|
.agents/skills/ Skills for humans and agents
|
|
44
44
|
.aci/ Generated artifacts (compiled, schemas)
|
|
45
45
|
```
|
|
46
|
+
|
|
47
|
+
## Personalization
|
|
48
|
+
|
|
49
|
+
The `personalization` block in `.content/config/site.json` controls the
|
|
50
|
+
Gradial collect tag (`<script defer src="/_aci/aci.js" …>`); pages emit it
|
|
51
|
+
automatically when `collect` is `true`, and not at all when the block is
|
|
52
|
+
absent. Consent is bridged from c15t (`consentPreset: "c15t"`): the Next kit
|
|
53
|
+
ships a full c15t setup (`src/app/_components/ConsentManager.tsx`, offline
|
|
54
|
+
mode by default, hosted via `NEXT_PUBLIC_C15T_BACKEND_URL`); the Astro kit
|
|
55
|
+
ships the store bridge in `SiteLayout.astro` — add a banner via a React
|
|
56
|
+
island (`@astrojs/react` + `@c15t/react`) and it is picked up automatically.
|
|
57
|
+
|
|
58
|
+
Personalization requires the deployed site to be served through a Gradial
|
|
59
|
+
edge binding, which provides `/collect`, identity, and the SDK itself. See
|
|
60
|
+
the `@gradial/aci` README ("Personalization: The One-Tag Install").
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"build:storybook": "storybook build"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@
|
|
20
|
+
"@c15t/nextjs": "^2.1.0",
|
|
21
|
+
"@gradial/aci": "{{aciVersion}}",
|
|
22
|
+
"js-yaml": "^4.1.1",
|
|
21
23
|
"next": "^15.1.6",
|
|
22
24
|
"react": "^19.0.0",
|
|
23
25
|
"react-dom": "^19.0.0"
|