@bettercms-ai/next 0.12.0 → 0.13.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 +75 -7
- package/dist/index.d.ts +3 -3
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -37,7 +37,8 @@ export default async function Post({ params }: { params: Promise<{ slug: string
|
|
|
37
37
|
const { slug } = await params;
|
|
38
38
|
const entry = await cms.getEntry<{ title: string; body: string }>(slug, {
|
|
39
39
|
revalidate: 300,
|
|
40
|
-
tags
|
|
40
|
+
// The exact tags the revalidation webhook sends on publish (see "Caching & revalidation").
|
|
41
|
+
tags: ["bcms:acme:all", `bcms:acme:entry:${slug}`],
|
|
41
42
|
});
|
|
42
43
|
if (!entry) notFound();
|
|
43
44
|
return <article><h1>{entry.fields.title}</h1>{/* ... */}</article>;
|
|
@@ -49,6 +50,32 @@ export default async function Post({ params }: { params: Promise<{ slug: string
|
|
|
49
50
|
const { items, hasNextPage } = await cms.listEntries("blog", { page: 1, perPage: 20 });
|
|
50
51
|
```
|
|
51
52
|
|
|
53
|
+
## Environment variables
|
|
54
|
+
|
|
55
|
+
`createBetterCMS`, `createDraftModeRoute`, `createRevalidateRoute` and `<VisualEditing>` read
|
|
56
|
+
**no** environment variables. You pass every value as an option, so the names in these examples
|
|
57
|
+
are only a convention. The package reads env in two places:
|
|
58
|
+
|
|
59
|
+
| Variable | Read by | Meaning |
|
|
60
|
+
| --- | --- | --- |
|
|
61
|
+
| `BETTERCMS_API_KEY` | `bettercms-snapshot` CLI | Project key that can read models and entries (required) |
|
|
62
|
+
| `BETTERCMS_WORKSPACE` | `bettercms-snapshot` CLI | Workspace slug (required) |
|
|
63
|
+
| `BETTERCMS_API_URL` | `bettercms-snapshot` CLI | API base, default `https://api.bettercms.ai/api/v1` |
|
|
64
|
+
| `BETTERCMS_PREVIEW` | `getContent()` | `1` reads live instead of `bcms-content.json` (preview builds) |
|
|
65
|
+
|
|
66
|
+
**Revalidation secret.** The value is the project's revalidation webhook secret (Project →
|
|
67
|
+
Settings). The dashboard tells you to store it as `BETTERCMS_WEBHOOK_SECRET`, and that is the
|
|
68
|
+
value `createRevalidateRoute({ secret })` needs. `BCMS_REVALIDATE_SECRET` in the route's source
|
|
69
|
+
comment is the same value under another name. Without `secret` the route accepts unsigned
|
|
70
|
+
requests, so always pass it.
|
|
71
|
+
|
|
72
|
+
**BetterCMS-generated deploy workflow** (connected repo). The repo secret is `BCMS_API_KEY`
|
|
73
|
+
(given only to the content-fetch step, never to the build) and the workspace is the repo
|
|
74
|
+
variable `BCMS_WORKSPACE_SLUG`. The build step gets `PUBLIC_BCMS_API_URL`,
|
|
75
|
+
`PUBLIC_BCMS_WORKSPACE`, `PUBLIC_BCMS_PROJECT_ID` and `PUBLIC_SITE_URL`. This package reads none
|
|
76
|
+
of them for you. Pass them into `createBetterCMS` yourself. They are server-only in Next unless
|
|
77
|
+
you re-export them with a `NEXT_PUBLIC_` prefix.
|
|
78
|
+
|
|
52
79
|
## API
|
|
53
80
|
|
|
54
81
|
### `createBetterCMS<Schema>(config)`
|
|
@@ -72,13 +99,52 @@ Reads flow through `fetch`, which Next patches into the data cache. Pass `tags`
|
|
|
72
99
|
`revalidateTag(tag)` on publish. `revalidate: false` **with** tags = cache-until-tag;
|
|
73
100
|
without tags = `no-store` (always fresh).
|
|
74
101
|
|
|
102
|
+
The revalidation webhook sends exactly two tags for each published or unpublished resource,
|
|
103
|
+
and `createRevalidateRoute` calls `revalidateTag` on each:
|
|
104
|
+
|
|
105
|
+
- `bcms:{workspace}:all`: everything in the workspace
|
|
106
|
+
- `bcms:{workspace}:{type}:{slug}`, where `type` is `entry` or `page`
|
|
107
|
+
|
|
108
|
+
Tag reads with those strings (`bcms:acme:entry:${slug}`, `bcms:acme:page:${slug}`,
|
|
109
|
+
`bcms:acme:all` for lists). The client does not add them for you, and a tag of any other shape
|
|
110
|
+
is never invalidated.
|
|
111
|
+
|
|
75
112
|
### Draft preview
|
|
113
|
+
Drafts come only from the signed preview endpoint, through `getEntry`:
|
|
114
|
+
|
|
76
115
|
```ts
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
116
|
+
// app/api/draft/route.ts — validates the dashboard's preview token, enables Draft Mode,
|
|
117
|
+
// stores the token in a cookie, then redirects
|
|
118
|
+
import { createDraftModeRoute } from "@bettercms-ai/next";
|
|
119
|
+
export const { GET } = createDraftModeRoute({ apiUrl: "https://api.bettercms.ai" });
|
|
80
120
|
```
|
|
81
121
|
|
|
122
|
+
```ts
|
|
123
|
+
import { isDraftEnabled, getPreviewToken } from "@bettercms-ai/next";
|
|
124
|
+
const previewToken = (await isDraftEnabled()) ? await getPreviewToken() : null;
|
|
125
|
+
const entry = previewToken
|
|
126
|
+
? await cms.getEntry(slug, { preview: true, previewToken }) // uncached
|
|
127
|
+
: await cms.getEntry(slug, { tags: [`bcms:acme:entry:${slug}`] });
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`getPage` has **no draft option**. It always returns the published page. To show a draft
|
|
131
|
+
page, use the token-scoped `getEntry` preview read above. For the Visual Editor canvas, wrap
|
|
132
|
+
the page's blocks in `<BcmsDraftBridge>` (`@bettercms-ai/next/draft-bridge`) instead of
|
|
133
|
+
`<BcmsBlocks>`. The editor pushes the draft block tree to it over `postMessage`, so the page
|
|
134
|
+
fetches nothing. Put `<BcmsDraftMarker />` in the root layout for Draft Mode renders.
|
|
135
|
+
|
|
136
|
+
### Static export (`output: "export"`)
|
|
137
|
+
Run `bettercms-snapshot` **before** `next build`, and read content with `getContent(config)`:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{ "scripts": { "build": "bettercms-snapshot && next build" } }
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Without `bcms-content.json`, reads fall back to a live `no-store` fetch. That makes the routes
|
|
144
|
+
dynamic, and `output: "export"` silently drops them, leaving an empty `out/`. `getContent` turns
|
|
145
|
+
that into a loud `SNAPSHOT_MISSING` build error. Set `BETTERCMS_PREVIEW=1` to read live in a
|
|
146
|
+
preview build instead.
|
|
147
|
+
|
|
82
148
|
### `llms.txt`
|
|
83
149
|
```ts
|
|
84
150
|
// app/llms.txt/route.ts
|
|
@@ -224,9 +290,11 @@ export default async function Page({ params }: { params: { slug: string } }) {
|
|
|
224
290
|
|
|
225
291
|
Reads are ISR-cached (`revalidate`, default 60s), so a SEO edit appears after the window
|
|
226
292
|
elapses. For **instant** refresh on publish, configure the project's **revalidation
|
|
227
|
-
webhook** (Project → Settings) to point at a `createRevalidateRoute` handler
|
|
228
|
-
|
|
229
|
-
|
|
293
|
+
webhook** (Project → Settings) to point at a `createRevalidateRoute` handler, passing the
|
|
294
|
+
webhook secret as `secret`. Tag your reads with the `bcms:{workspace}:…` tags from
|
|
295
|
+
"Caching & revalidation". `` cms.getPage(slug, { tags: [`bcms:acme:page:${slug}`] }) `` is the
|
|
296
|
+
page form. Without the webhook, edits still propagate, but on the ISR interval instead of
|
|
297
|
+
immediately.
|
|
230
298
|
|
|
231
299
|
## License
|
|
232
300
|
|
package/dist/index.d.ts
CHANGED
|
@@ -173,9 +173,9 @@ declare function createBetterCMS<Schema extends Record<string, unknown> = Record
|
|
|
173
173
|
* Build a Next.js `Metadata` from a BetterCMS page, layering page meta over site defaults.
|
|
174
174
|
*
|
|
175
175
|
* Pass `location` — `{ siteUrl, path }` — to get a canonical (and `og:url`) on pages that set
|
|
176
|
-
* none of their own.
|
|
177
|
-
*
|
|
178
|
-
*
|
|
176
|
+
* none of their own. Without it, `BETTERCMS_SITE_URL` plus the page's slug stand in; with
|
|
177
|
+
* neither, both tags are absent and development logs one warning. The hosted renderer always
|
|
178
|
+
* emits them. A `noindex` page gets `robots: { index: false }`.
|
|
179
179
|
*/
|
|
180
180
|
declare function buildMetadata(page: SeoInput, siteDefaults?: SiteSeoDefaults, location?: SeoLocation): Metadata;
|
|
181
181
|
|
package/dist/index.js
CHANGED
|
@@ -176,11 +176,26 @@ function createBetterCMS(config) {
|
|
|
176
176
|
|
|
177
177
|
// src/metadata.ts
|
|
178
178
|
import { resolveSeo } from "@bettercms-ai/sdk";
|
|
179
|
+
function withSiteUrlFallback(page, location) {
|
|
180
|
+
const siteUrl = location.siteUrl || (typeof process !== "undefined" ? process.env.BETTERCMS_SITE_URL : void 0);
|
|
181
|
+
const slugPath = page.slug ? page.slug === "home" ? "/" : `/${page.slug.replace(/^\/+/, "")}` : void 0;
|
|
182
|
+
return { siteUrl, path: location.path || slugPath };
|
|
183
|
+
}
|
|
184
|
+
var warnedNoCanonical = false;
|
|
185
|
+
function warnNoCanonical() {
|
|
186
|
+
if (warnedNoCanonical || typeof process === "undefined" || process.env.NODE_ENV !== "development") return;
|
|
187
|
+
warnedNoCanonical = true;
|
|
188
|
+
console.warn(
|
|
189
|
+
"[@bettercms-ai/next] buildMetadata emitted no canonical or og:url. Pass `location` ({ siteUrl, path }) or set BETTERCMS_SITE_URL; the hosted renderer always emits both."
|
|
190
|
+
);
|
|
191
|
+
}
|
|
179
192
|
function buildMetadata(page, siteDefaults = {}, location = {}) {
|
|
180
|
-
const seo = resolveSeo(page, siteDefaults, location);
|
|
193
|
+
const seo = resolveSeo(page, siteDefaults, withSiteUrlFallback(page, location));
|
|
194
|
+
if (!seo.canonical) warnNoCanonical();
|
|
181
195
|
return {
|
|
182
196
|
title: seo.title || void 0,
|
|
183
197
|
description: seo.description || void 0,
|
|
198
|
+
robots: seo.noindex ? { index: false } : void 0,
|
|
184
199
|
alternates: seo.canonical ? { canonical: seo.canonical } : void 0,
|
|
185
200
|
openGraph: {
|
|
186
201
|
title: seo.og.title || void 0,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts","../src/client.ts","../src/metadata.ts","../src/index.ts","../src/snapshot.ts","../src/llms-txt.ts","../src/preview.ts","../src/draft-route.ts","../src/forms-read.ts","../src/pages-read.ts","../src/components-read.ts","../src/field.tsx","../src/live-config.ts","../src/revalidate-route.ts"],"sourcesContent":["/**\n * Public types for @bettercms-ai/next.\n *\n * `BetterCMSEntry` mirrors the envelope emitted by @bettercms-ai/codegen's generated\n * file. The adapter normalizes the raw Delivery API response into exactly this shape,\n * so `getEntry`/`listEntries` line up 1:1 with your generated model types.\n */\n\n/** Normalized error thrown by adapter reads. Mirrors the SDK's BetterCMSError, but kept\n * local so the adapter carries no heavy runtime dependency into a consumer's bundle. */\nexport class BetterCMSError extends Error {\n readonly status: number;\n readonly code: string;\n\n constructor(message: string, status: number, code: string) {\n super(message);\n this.name = \"BetterCMSError\";\n this.status = status;\n this.code = code;\n }\n}\n\n/**\n * Delivery envelope around a model's typed `fields`. Returned by `getEntry`/`listEntries`.\n * Identical to the `BetterCMSEntry<TFields>` your generated types declare.\n *\n * `publishedAt`/`updatedAt` are ISO-8601 strings, or `null` when absent — never a\n * fabricated empty string (so `new Date(...)` is safe to attempt only on non-null).\n */\nexport interface BetterCMSEntry<TFields> {\n readonly slug: string;\n readonly status: \"draft\" | \"published\";\n readonly fields: TFields;\n readonly publishedAt: string | null;\n readonly updatedAt: string | null;\n}\n\nexport interface BetterCMSConfig {\n /** Workspace slug — the `:workspace` segment of the Delivery API path. */\n workspace: string;\n /** Optional delivery API key (sent as `Authorization: Bearer`). */\n apiKey?: string;\n /** Delivery API base. Default: `https://api.bettercms.ai/api/v1/delivery`. */\n baseUrl?: string;\n /** Preview API base. Default: derived from `baseUrl` (`/delivery` → `/preview`). */\n previewBaseUrl?: string;\n /**\n * Default Next.js revalidation for reads (seconds). `false` = always fresh\n * (`cache: \"no-store\"`). Per-call `revalidate` overrides this. Default: `60`.\n */\n revalidate?: number | false;\n}\n\n/** Per-read options shared by `getEntry` and `listEntries`. */\nexport interface ReadOptions {\n /** ISR window in seconds, or `false` for `cache: \"no-store\"`. Overrides config default. */\n revalidate?: number | false;\n /** Next.js cache tags for on-demand `revalidateTag()` invalidation. */\n tags?: string[];\n /** Reference hydration depth (0 = none, 1 = direct refs, 2 = nested). */\n depth?: 0 | 1 | 2;\n /** Field projection — only these field keys are returned. */\n select?: string[];\n}\n\n/** Options for `getEntry`, including draft-preview access. */\nexport interface GetEntryOptions extends ReadOptions {\n /** Fetch draft content via the preview endpoint. Requires `previewToken`. */\n preview?: boolean;\n /** Signed preview token (from `POST .../preview-token`). */\n previewToken?: string;\n}\n\n/** Options for `listEntries`. */\nexport interface ListEntriesOptions extends ReadOptions {\n /** 1-based page number. Default: 1. */\n page?: number;\n /** Items per page (max 100). Default: 20. */\n perPage?: number;\n}\n\n/** Paginated result returned by `listEntries`. */\nexport interface EntryList<TFields> {\n items: BetterCMSEntry<TFields>[];\n page: number;\n perPage: number;\n totalItems: number;\n totalPages: number;\n hasNextPage: boolean;\n hasPreviousPage: boolean;\n}\n","/**\n * createBetterCMS — the Next.js delivery client.\n *\n * Reads run through the standard `fetch`, which the Next.js App Router patches to\n * participate in the data cache. We pass `next: { revalidate, tags }` so content is\n * cached/ISR'd and can be invalidated on publish via `revalidateTag()`.\n *\n * The raw Delivery API response is normalized into `BetterCMSEntry<TFields>` so the\n * return types match what @bettercms-ai/codegen generates.\n */\n\nimport type { ContentBlock, DeliveredLayout, PageMetaJson } from \"@bettercms-ai/types\";\nimport {\n BetterCMSError,\n type BetterCMSConfig,\n type BetterCMSEntry,\n type EntryList,\n type GetEntryOptions,\n type ListEntriesOptions,\n} from \"./types.js\";\n\n/** A published page with its block_json — feed `blocks` to `<BcmsBlocks>`.\n * The SEO fields (FLO-302) feed `buildMetadata` for the route's `generateMetadata`. */\nexport interface BetterCMSPage {\n slug: string;\n title: string;\n metaTitle: string | null;\n metaDescription: string | null;\n /** Rich SEO (OG / Twitter / canonical / JSON-LD). `null` when unset. */\n metaJson: PageMetaJson | null;\n blocks: ContentBlock[];\n layout?: DeliveredLayout | null;\n publishedAt: string | null;\n updatedAt: string | null;\n}\n\n/** Raw single-page shape returned by the Delivery API (`/content/:slug`). */\ninterface RawPageResponse {\n data: {\n slug: string;\n entry: {\n slug: string;\n title: string;\n metaTitle?: string | null;\n metaDescription?: string | null;\n metaJson?: PageMetaJson | null;\n blocks?: ContentBlock[];\n layout?: DeliveredLayout | null;\n updatedAt?: string | null;\n };\n publishedAt: string | null;\n };\n}\n\nconst DEFAULT_BASE_URL = \"https://api.bettercms.ai/api/v1/delivery\";\nconst DEFAULT_REVALIDATE = 60;\n\n/** `fetch`'s init augmented with Next.js's `next` cache directives. (`cache` is declared\n * explicitly because this package compiles without the DOM lib.) */\ntype NextRequestInit = RequestInit & {\n cache?: \"default\" | \"no-store\" | \"force-cache\";\n next?: { revalidate?: number | false; tags?: string[] };\n};\n\n/** Raw single-entry shape returned by the Delivery API. */\ninterface RawEntry {\n id: string;\n slug: string;\n status: \"draft\" | \"published\";\n publishedAt: string | null;\n updatedAt?: string | null;\n data: Record<string, unknown>;\n}\n\ninterface RawListResponse {\n data: {\n items: RawEntry[];\n page: number;\n perPage: number;\n totalItems: number;\n totalPages: number;\n hasNextPage: boolean;\n hasPreviousPage: boolean;\n };\n}\n\nfunction statusToCode(status: number): string {\n if (status === 404) return \"CONTENT_NOT_FOUND\";\n if (status === 401) return \"UNAUTHORIZED\";\n if (status === 403) return \"FORBIDDEN\";\n if (status === 429) return \"RATE_LIMITED\";\n if (status === 422) return \"VALIDATION_ERROR\";\n return \"INTERNAL_ERROR\";\n}\n\n/** Normalize a raw delivery entry into the codegen-aligned envelope. `publishedAt`\n * and `updatedAt` are kept distinct and pass through `null` rather than being\n * conflated or fabricated as \"\" (which would parse to an Invalid Date). */\nfunction mapEntry<TFields>(raw: RawEntry): BetterCMSEntry<TFields> {\n return {\n slug: raw.slug,\n status: raw.status,\n fields: raw.data as TFields,\n publishedAt: raw.publishedAt ?? null,\n updatedAt: raw.updatedAt ?? null,\n };\n}\n\n/**\n * The typed BetterCMS reader for Next.js.\n *\n * @typeParam Schema - your generated `BetterCMSSchema` (slug → fields registry). When\n * supplied, `listEntries(\"blog\")` is typed by the model's fields and the model name\n * autocompletes. Defaults to an open record so it also works untyped.\n */\nexport interface BetterCMSNext<Schema extends Record<string, unknown>> {\n /** Fetch one published entry by its content slug. Returns `null` when not found.\n * Passing `select` narrows the result to `Partial<TFields>` (projection drops fields). */\n getEntry<TFields = unknown>(\n slug: string,\n opts: GetEntryOptions & { select: string[] },\n ): Promise<BetterCMSEntry<Partial<TFields>> | null>;\n getEntry<TFields = unknown>(\n slug: string,\n opts?: GetEntryOptions,\n ): Promise<BetterCMSEntry<TFields> | null>;\n\n /** List published entries, filtered to one model. Throws `BetterCMSError`\n * (CONTENT_NOT_FOUND) for an unknown workspace/model — an empty model returns an\n * empty page. Passing `select` narrows fields to `Partial`. */\n listEntries<M extends keyof Schema & string>(\n model: M,\n opts: ListEntriesOptions & { select: string[] },\n ): Promise<EntryList<Partial<Schema[M]>>>;\n listEntries<M extends keyof Schema & string>(\n model: M,\n opts?: ListEntriesOptions,\n ): Promise<EntryList<Schema[M]>>;\n listEntries<TFields = unknown>(\n model?: string,\n opts?: ListEntriesOptions,\n ): Promise<EntryList<TFields>>;\n\n /** Fetch one published page (with its `blocks` for `<BcmsBlocks>`) by slug.\n * Returns `null` when not found. */\n getPage(\n slug: string,\n opts?: { revalidate?: number | false; tags?: string[] },\n ): Promise<BetterCMSPage | null>;\n /** Fetch the project-scoped published Global Layout. */\n getLayout(opts?: { revalidate?: number | false; tags?: string[] }): Promise<DeliveredLayout | null>;\n}\n\nexport function createBetterCMS<\n Schema extends Record<string, unknown> = Record<string, unknown>,\n>(config: BetterCMSConfig): BetterCMSNext<Schema> {\n const baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n const previewBaseUrl = (\n config.previewBaseUrl ?? baseUrl.replace(/\\/delivery$/, \"/preview\")\n ).replace(/\\/+$/, \"\");\n const defaultRevalidate = config.revalidate ?? DEFAULT_REVALIDATE;\n\n function headers(): Record<string, string> {\n const h: Record<string, string> = { Accept: \"application/json\" };\n if (config.apiKey) h[\"Authorization\"] = `Bearer ${config.apiKey}`;\n return h;\n }\n\n function cacheInit(\n revalidate: number | false | undefined,\n tags: string[] | undefined,\n forceNoStore = false,\n ): NextRequestInit {\n const rv = revalidate ?? defaultRevalidate;\n // Preview is always uncached.\n if (forceNoStore) return { headers: headers(), cache: \"no-store\" };\n if (rv === false) {\n // With tags, \"false\" means cache until `revalidateTag` (the canonical CMS\n // publish-invalidation pattern) — we must NOT drop the tags to no-store, or\n // revalidateTag could never invalidate. Without tags, it means truly fresh.\n return tags?.length\n ? { headers: headers(), next: { revalidate: false, tags } }\n : { headers: headers(), cache: \"no-store\" };\n }\n return { headers: headers(), next: { revalidate: rv, tags } };\n }\n\n async function requestJSON<T>(\n url: string,\n init: NextRequestInit,\n { nullOn404 = false }: { nullOn404?: boolean } = {},\n ): Promise<T | null> {\n let res: Response;\n try {\n res = await fetch(url, init);\n } catch (err) {\n throw new BetterCMSError(\n `Network error: ${err instanceof Error ? err.message : String(err)}`,\n 0,\n \"NETWORK_ERROR\",\n );\n }\n // A single-entry 404 is \"no such entry\" (→ null). A list 404 is a real error\n // (unknown workspace/model) and must surface, not masquerade as an empty list.\n if (res.status === 404 && nullOn404) return null;\n if (!res.ok) {\n let message = res.statusText || \"Request failed\";\n try {\n const body = (await res.json()) as { error?: string; message?: string };\n message = body.error ?? body.message ?? message;\n } catch {\n /* ignore parse errors */\n }\n throw new BetterCMSError(message, res.status, statusToCode(res.status));\n }\n return (await res.json()) as T;\n }\n\n function entryQuery(opts?: { depth?: 0 | 1 | 2; select?: string[] }): string {\n const params = new URLSearchParams();\n if (opts?.depth != null) params.set(\"depth\", String(opts.depth));\n if (opts?.select?.length) params.set(\"select\", opts.select.join(\",\"));\n const qs = params.toString();\n return qs ? `?${qs}` : \"\";\n }\n\n const client = {\n async getEntry<TFields = unknown>(slug: string, opts?: GetEntryOptions) {\n const encoded = encodeURIComponent(slug);\n const query = entryQuery(opts);\n\n // Preview: drafts are only reachable through the signed preview endpoint, and\n // must never be cached (every request re-validates the token server-side).\n if (opts?.preview) {\n if (!opts.previewToken) {\n throw new BetterCMSError(\n \"preview: true requires a previewToken\",\n 400,\n \"VALIDATION_ERROR\",\n );\n }\n const tokenParam = `token=${encodeURIComponent(opts.previewToken)}`;\n const sep = query ? \"&\" : \"?\";\n const url = `${previewBaseUrl}/${encoded}${query}${sep}${tokenParam}`;\n const body = await requestJSON<{ data: RawEntry }>(\n url,\n cacheInit(undefined, undefined, true),\n { nullOn404: true },\n );\n return body ? mapEntry<TFields>(body.data) : null;\n }\n\n const url = `${baseUrl}/${config.workspace}/content-entries/${encoded}${query}`;\n const raw = await requestJSON<RawEntry>(\n url,\n cacheInit(opts?.revalidate, opts?.tags),\n { nullOn404: true },\n );\n return raw ? mapEntry<TFields>(raw) : null;\n },\n\n async listEntries<TFields = unknown>(\n model?: string,\n opts?: ListEntriesOptions,\n ): Promise<EntryList<TFields>> {\n const params = new URLSearchParams();\n if (model) params.set(\"model\", model);\n if (opts?.page != null) params.set(\"page\", String(opts.page));\n if (opts?.perPage != null) params.set(\"perPage\", String(opts.perPage));\n if (opts?.depth != null) params.set(\"depth\", String(opts.depth));\n if (opts?.select?.length) params.set(\"select\", opts.select.join(\",\"));\n\n const url = `${baseUrl}/${config.workspace}/content-entries?${params}`;\n const body = await requestJSON<RawListResponse>(\n url,\n cacheInit(opts?.revalidate, opts?.tags),\n );\n\n const data = body?.data;\n if (!data) {\n return {\n items: [],\n page: opts?.page ?? 1,\n perPage: opts?.perPage ?? 20,\n totalItems: 0,\n totalPages: 1,\n hasNextPage: false,\n hasPreviousPage: false,\n };\n }\n return {\n items: data.items.map((r) => mapEntry<TFields>(r)),\n page: data.page,\n perPage: data.perPage,\n totalItems: data.totalItems,\n totalPages: data.totalPages,\n hasNextPage: data.hasNextPage,\n hasPreviousPage: data.hasPreviousPage,\n };\n },\n\n async getPage(\n slug: string,\n opts?: { revalidate?: number | false; tags?: string[] },\n ): Promise<BetterCMSPage | null> {\n const url = `${baseUrl}/${config.workspace}/content/${encodeURIComponent(slug)}`;\n const body = await requestJSON<RawPageResponse>(\n url,\n cacheInit(opts?.revalidate, opts?.tags),\n { nullOn404: true },\n );\n if (!body) return null;\n const { entry, publishedAt } = body.data;\n return {\n slug: entry.slug,\n title: entry.title,\n metaTitle: entry.metaTitle ?? null,\n metaDescription: entry.metaDescription ?? null,\n metaJson: entry.metaJson ?? null,\n blocks: entry.blocks ?? [],\n layout: entry.layout ?? null,\n publishedAt: publishedAt ?? null,\n updatedAt: entry.updatedAt ?? null,\n };\n },\n\n async getLayout(opts?: { revalidate?: number | false; tags?: string[] }) {\n const body = await requestJSON<{ data: DeliveredLayout }>(\n `${baseUrl}/${config.workspace}/layout`,\n cacheInit(opts?.revalidate, opts?.tags),\n { nullOn404: true },\n );\n return body?.data ?? null;\n },\n };\n\n // The concrete impls use single generic signatures; the public interface exposes\n // richer overloads (select→Partial, model-keyed typing). Cast once here.\n return client as unknown as BetterCMSNext<Schema>;\n}\n","/**\n * buildMetadata — map a BetterCMS page's SEO onto a Next.js `Metadata` object.\n *\n * Wire it into a route's `generateMetadata` so per-page Meta Title / Description and\n * the rich OG / Twitter / canonical the dashboard saves drive the live `<head>`:\n *\n * import { createBetterCMS, buildMetadata } from \"@bettercms-ai/next\";\n * const bcms = createBetterCMS({ workspace: \"acme\" });\n *\n * export async function generateMetadata({ params }): Promise<Metadata> {\n * const page = await bcms.getPage(params.slug);\n * if (!page) return {};\n * return buildMetadata(page, siteDefaults); // siteDefaults optional\n * }\n *\n * JSON-LD isn't part of Next's `Metadata`; render `resolveSeo(page, defaults).jsonLd`\n * as a `<script type=\"application/ld+json\">` in the page component (see the README).\n *\n * The merge (page-over-site) is delegated to `resolveSeo` (@bettercms-ai/sdk), the same\n * resolver the Astro adapter uses — so every surface stays consistent.\n */\nimport type { Metadata } from \"next\";\nimport { resolveSeo, type SeoInput, type SeoLocation } from \"@bettercms-ai/sdk\";\nimport type { SiteSeoDefaults } from \"@bettercms-ai/types\";\n\n/**\n * Build a Next.js `Metadata` from a BetterCMS page, layering page meta over site defaults.\n *\n * Pass `location` — `{ siteUrl, path }` — to get a canonical (and `og:url`) on pages that set\n * none of their own. Omit it and both tags are absent, which is what a headless app shipped\n * before this parameter existed. The hosted renderer always emits them, so a headless site\n * without `location` is the ONE surface that silently differs from its hosted twin.\n */\nexport function buildMetadata(\n page: SeoInput,\n siteDefaults: SiteSeoDefaults = {},\n location: SeoLocation = {},\n): Metadata {\n const seo = resolveSeo(page, siteDefaults, location);\n return {\n title: seo.title || undefined,\n description: seo.description || undefined,\n alternates: seo.canonical ? { canonical: seo.canonical } : undefined,\n openGraph: {\n title: seo.og.title || undefined,\n description: seo.og.description || undefined,\n type: (seo.og.type || \"website\") as \"website\",\n url: seo.og.url || undefined,\n images: seo.og.image ? [{ url: seo.og.image }] : undefined,\n },\n twitter: {\n card: (seo.twitter.card || \"summary\") as \"summary\" | \"summary_large_image\",\n title: seo.twitter.title || undefined,\n description: seo.twitter.description || undefined,\n images: seo.twitter.image ? [seo.twitter.image] : undefined,\n site: seo.twitter.site || undefined,\n },\n };\n}\n","/**\n * @bettercms-ai/next — the BetterCMS adapter for Next.js.\n *\n * Pair with @bettercms-ai/codegen: generate `BetterCMSSchema` from your content models,\n * then `createBetterCMS<BetterCMSSchema>(...)` for typed, cache-aware reads in the App Router.\n */\n\nexport { createBetterCMS } from \"./client.js\";\nexport type { BetterCMSNext, BetterCMSPage } from \"./client.js\";\n\n// SEO (FLO-302): map a page's per-page-over-site SEO into a Next `Metadata` for\n// `generateMetadata`. `resolveSeo` (+ its types) is re-exported for JSON-LD / custom heads.\nexport { buildMetadata } from \"./metadata.js\";\nexport { resolveSeo } from \"@bettercms-ai/sdk\";\nexport type { SeoInput, ResolvedSeo } from \"@bettercms-ai/sdk\";\nexport type { PageMetaJson, SiteSeoDefaults } from \"@bettercms-ai/types\";\nexport type { DeliveredLayout } from \"@bettercms-ai/types\";\n\nexport { BetterCMSError } from \"./types.js\";\nexport type {\n BetterCMSConfig,\n BetterCMSEntry,\n ReadOptions,\n GetEntryOptions,\n ListEntriesOptions,\n EntryList,\n} from \"./types.js\";\n\nexport {\n getContent,\n buildSnapshot,\n writeSnapshot,\n readSnapshot,\n serializeSnapshot,\n parseSnapshot,\n SNAPSHOT_VERSION,\n DEFAULT_SNAPSHOT_FILE,\n} from \"./snapshot.js\";\nexport type { ContentSource, ContentSnapshot } from \"./snapshot.js\";\n\nexport { generateLlmsTxt, llmsTxtRoute, fetchModels } from \"./llms-txt.js\";\nexport type {\n LlmsModel,\n LlmsModelField,\n LlmsTxtOptions,\n LlmsTxtRouteConfig,\n} from \"./llms-txt.js\";\n\nexport { isDraftEnabled, getPreviewToken, BcmsDraftMarker } from \"./preview.js\";\n\n// Draft-mode route-handler factories for the App Router.\nexport {\n createDraftModeRoute,\n createDisableDraftRoute,\n PREVIEW_TOKEN_COOKIE,\n} from \"./draft-route.js\";\nexport type { DraftModeRouteConfig } from \"./draft-route.js\";\n\n// Image URL builder — `import { imageUrlBuilder } from \"@bettercms-ai/next\"`.\nexport { default as imageUrlBuilder, imageUrl } from \"@bettercms-ai/image-url\";\nexport type {\n ImageUrlBuilder,\n ImageSource,\n ImageFormat,\n ImageFit,\n} from \"@bettercms-ai/image-url\";\n\n// Build-time forms reader for the deploy Action's snapshot (server-side).\nexport { readForms, getForm } from \"./forms-read.js\";\nexport type { SnapshotForms } from \"./forms-read.js\";\n\n// Build-time pages reader for the deploy Action's snapshot (server-side). Pair with\n// <BcmsBlocks> to render a page's block_json: readPages()/getPage(slug) → page.blocks.\nexport { readPages, getPage } from \"./pages-read.js\";\nexport type { SnapshotPage } from \"./pages-read.js\";\n\n// Build-time components reader — pass to <BcmsBlocks components={…} /> so `component`\n// blocks resolve their reusable definitions.\nexport { readComponents, getComponent } from \"./components-read.js\";\n\n// <BcmsForm> / <BcmsBlocks> are client components and ship from their own \"use client\"\n// entries so the React Server Components boundary survives bundling:\n// import { BcmsForm } from \"@bettercms-ai/next/form\";\n// import { BcmsBlocks } from \"@bettercms-ai/next/blocks\";\nexport type { BcmsFormProps } from \"./form.js\";\nexport type { BcmsBlocksProps } from \"./blocks.js\";\n\n// <BcmsField> tags an entry field's value so the visual editor binds click-to-edit\n// deterministically. Server-safe (no \"use client\"): import from \"@bettercms-ai/next\".\nexport { BcmsField } from \"./field.js\";\nexport type { BcmsFieldProps } from \"./field.js\";\n\n// Live content + revalidation (mirrors next-sanity defineLive/<SanityLive>).\n// import { BcmsLive } from \"@bettercms-ai/next/live\";\nexport type { BcmsLiveProps } from \"./live.js\";\nexport { defineBetterCMSLive } from \"./live-config.js\";\nexport type { BetterCMSLiveConfig } from \"./live-config.js\";\nexport { createRevalidateRoute } from \"./revalidate-route.js\";\nexport type { RevalidateRouteConfig } from \"./revalidate-route.js\";\n\n// Visual editing overlay (client). import { VisualEditing } from \"@bettercms-ai/next/visual-editing\"\nexport type { VisualEditingProps } from \"./visual-editing.js\";\n","/**\n * Build-time content snapshot — the writer + reader of `bcms-content.json`.\n *\n * Why this exists: a static (`output: \"export\"`) build must resolve all content at\n * build time. If a page instead falls back to a live `cache: \"no-store\"` fetch, its\n * route becomes dynamic and `output: \"export\"` silently drops it — you get an empty\n * `out/`. The fix is a single build-time snapshot the pages read synchronously.\n *\n * The WRITER (`buildSnapshot`/`writeSnapshot`, used by the `bettercms-snapshot` bin)\n * and the READER (`getContent`) share ONE serializer (`serializeSnapshot`/\n * `parseSnapshot`) so the on-disk shape can never drift between the two halves.\n *\n * This is intentionally separate from {@link createBetterCMS}: that stays the live,\n * network-backed client. `getContent` is the snapshot-preferring reader a static\n * site uses. Existing consumers that deliberately rely on the live fallback are\n * unaffected — only `getContent` enforces \"snapshot or bust\".\n */\n\nimport { readFileSync, writeFileSync, mkdirSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport {\n BetterCMSError,\n type BetterCMSConfig,\n type BetterCMSEntry,\n type EntryList,\n type ListEntriesOptions,\n} from \"./types.js\";\nimport { createBetterCMS } from \"./client.js\";\n\n/** Bump when the on-disk shape changes incompatibly — readers reject mismatches. */\nexport const SNAPSHOT_VERSION = 1;\n/** Default snapshot filename, resolved against `process.cwd()`. */\nexport const DEFAULT_SNAPSHOT_FILE = \"bcms-content.json\";\n\n/** The full-site content snapshot. Entries are grouped by model slug so the reader\n * can serve `listEntries(model)` offline without a per-entry model tag. */\nexport interface ContentSnapshot {\n version: number;\n workspace: string;\n generatedAt: string;\n models: Record<string, BetterCMSEntry<unknown>[]>;\n}\n\n// ── Serializer (shared by writer + reader — single source of on-disk shape) ──────\n\n/** Serialize a snapshot to the canonical JSON form written to disk. */\nexport function serializeSnapshot(snapshot: ContentSnapshot): string {\n return JSON.stringify(snapshot, null, 2);\n}\n\n/** Parse + validate a snapshot JSON string. Throws on a version mismatch so a stale\n * snapshot fails loudly rather than feeding the build the wrong shape. */\nexport function parseSnapshot(json: string): ContentSnapshot {\n const parsed = JSON.parse(json) as ContentSnapshot;\n if (parsed.version !== SNAPSHOT_VERSION) {\n throw new BetterCMSError(\n `Unsupported bcms-content.json version ${parsed.version} (expected ${SNAPSHOT_VERSION}). ` +\n `Regenerate it with \"bettercms-snapshot\".`,\n 0,\n \"SNAPSHOT_VERSION_MISMATCH\",\n );\n }\n return parsed;\n}\n\n// ── Disk I/O ─────────────────────────────────────────────────────────────────────\n\n/** Write a snapshot to `path` (relative paths resolve against cwd), creating dirs. */\nexport function writeSnapshot(path: string, snapshot: ContentSnapshot): void {\n const out = resolve(process.cwd(), path);\n mkdirSync(dirname(out), { recursive: true });\n writeFileSync(out, serializeSnapshot(snapshot), \"utf8\");\n}\n\n/** Read + parse a snapshot from `path`. Returns `null` only when the file is absent;\n * a present-but-corrupt/stale file throws (callers must not treat that as \"missing\"). */\nexport function readSnapshot(path: string): ContentSnapshot | null {\n const out = resolve(process.cwd(), path);\n let json: string;\n try {\n json = readFileSync(out, \"utf8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException)?.code === \"ENOENT\") return null;\n throw err;\n }\n return parseSnapshot(json);\n}\n\n// ── Writer: build a snapshot from the live API ────────────────────────────────────\n\n/** Minimal client surface `buildSnapshot` needs — lets tests inject a fake. Kept\n * non-generic so a simple fake (and the live client's matching overload) both fit. */\ntype ListOnly = {\n listEntries(model?: string, opts?: ListEntriesOptions): Promise<EntryList<unknown>>;\n};\n\n/**\n * Page through every model's published entries and assemble a full-site snapshot.\n * `modelSlugs` come from the Management API (`fetchModels`) so the snapshot covers\n * exactly this project's schema. Pass `client` in tests; defaults to the live client.\n */\nexport async function buildSnapshot(opts: {\n config: BetterCMSConfig;\n modelSlugs: string[];\n client?: ListOnly;\n /** Stamped into `generatedAt`; injectable for deterministic tests. */\n now?: string;\n}): Promise<ContentSnapshot> {\n const client = opts.client ?? createBetterCMS(opts.config);\n const models: Record<string, BetterCMSEntry<unknown>[]> = {};\n for (const slug of opts.modelSlugs) {\n const all: BetterCMSEntry<unknown>[] = [];\n let page = 1;\n for (;;) {\n // revalidate:false → bypass any data cache; this is a one-shot build fetch.\n const res = await client.listEntries(slug, { page, perPage: 100, revalidate: false });\n all.push(...res.items);\n if (!res.hasNextPage) break;\n page += 1;\n }\n models[slug] = all;\n }\n return {\n version: SNAPSHOT_VERSION,\n workspace: opts.config.workspace,\n generatedAt: opts.now ?? new Date().toISOString(),\n models,\n };\n}\n\n// ── Reader: getContent (snapshot-preferring, loud on absence) ─────────────────────\n\n/** Snapshot-backed content reader. Async so it can transparently fall back to the\n * live client in preview without changing the call sites. */\nexport interface ContentSource {\n getEntry<TFields = unknown>(slug: string): Promise<BetterCMSEntry<TFields> | null>;\n listEntries<TFields = unknown>(model?: string): Promise<EntryList<TFields>>;\n}\n\n/** `BETTERCMS_PREVIEW` truthy → read live (uncached), never the snapshot. */\nfunction isPreview(): boolean {\n const v = (\n globalThis as { process?: { env?: Record<string, string | undefined> } }\n ).process?.env?.BETTERCMS_PREVIEW;\n return v != null && v !== \"\" && v !== \"0\" && v !== \"false\";\n}\n\n/** Parsed snapshots keyed by resolved path — read+parse once per build process. */\nconst snapshotCache = new Map<string, ContentSnapshot>();\n\n/** Test-only: clear the module-scope snapshot cache between cases. */\nexport function __resetSnapshotCacheForTests(): void {\n snapshotCache.clear();\n}\n\nfunction emptyPage<TFields>(items: BetterCMSEntry<TFields>[]): EntryList<TFields> {\n return {\n items,\n page: 1,\n perPage: items.length,\n totalItems: items.length,\n totalPages: 1,\n hasNextPage: false,\n hasPreviousPage: false,\n };\n}\n\n/**\n * The reader a static site should use. In a normal (export) build it reads the\n * memoized `bcms-content.json` and serves entries from memory. If the snapshot is\n * absent it THROWS a clear, actionable error — the whole point is to turn the old\n * silent empty-`out/` failure into a loud build error. Set `BETTERCMS_PREVIEW=1`\n * for a preview build that reads live instead.\n */\nexport function getContent<\n Schema extends Record<string, unknown> = Record<string, unknown>,\n>(config: BetterCMSConfig, opts: { snapshotPath?: string } = {}): ContentSource {\n const path = opts.snapshotPath ?? DEFAULT_SNAPSHOT_FILE;\n\n if (isPreview()) {\n const live = createBetterCMS<Schema>(config);\n return {\n getEntry: (slug) => live.getEntry(slug, { revalidate: false }),\n listEntries: (model) => live.listEntries(model, { revalidate: false }),\n };\n }\n\n const resolved = resolve(process.cwd(), path);\n function load(): ContentSnapshot {\n const cached = snapshotCache.get(resolved);\n if (cached) return cached;\n const snap = readSnapshot(path);\n if (!snap) {\n throw new BetterCMSError(\n `BetterCMS content snapshot \"${path}\" not found. A static (output: \"export\") build reads ` +\n `content from this snapshot; without it pages fall back to a live no-store fetch, become ` +\n `dynamic routes, and output: \"export\" silently drops them (empty out/). Run ` +\n `\"bettercms-snapshot\" before \"next build\" (make it your build:preview prestep), or set ` +\n `BETTERCMS_PREVIEW=1 to read live in a preview build.`,\n 0,\n \"SNAPSHOT_MISSING\",\n );\n }\n snapshotCache.set(resolved, snap);\n return snap;\n }\n\n return {\n async getEntry<TFields = unknown>(slug: string) {\n const snap = load();\n for (const entries of Object.values(snap.models)) {\n const found = entries.find((e) => e.slug === slug);\n if (found) return found as BetterCMSEntry<TFields>;\n }\n return null;\n },\n async listEntries<TFields = unknown>(model?: string) {\n const snap = load();\n const items = (\n model ? (snap.models[model] ?? []) : Object.values(snap.models).flat()\n ) as BetterCMSEntry<TFields>[];\n return emptyPage(items);\n },\n };\n}\n","/**\n * llms.txt generation — the AI-discovery surface of the deterministic floor.\n *\n * `generateLlmsTxt` is pure (models in → string out), so it is trivially testable and\n * deterministic. `llmsTxtRoute` wraps it as an App Router `route.ts` handler. `fetchModels`\n * pulls the live schema from the Management API for sites that want a self-updating file.\n *\n * Output follows the llmstxt.org convention: an H1 title, a `>` summary, then sections.\n */\n\n/** Minimal field shape needed to describe a model in llms.txt. */\nexport interface LlmsModelField {\n key: string;\n label?: string;\n type: string;\n required?: boolean;\n}\n\n/** Minimal model shape — a subset of the Management API model row. */\nexport interface LlmsModel {\n slug: string;\n name?: string;\n description?: string | null;\n fields: LlmsModelField[];\n}\n\nexport interface LlmsTxtOptions {\n /** H1 title. Default: \"BetterCMS content\". */\n title?: string;\n /** One-line `>` summary under the title. */\n description?: string;\n /** Delivery API base used to render example endpoints. */\n baseUrl?: string;\n /** Workspace slug used in example endpoints. */\n workspace?: string;\n /** Extra free-form lines appended under a \"## Notes\" section. */\n notes?: string[];\n}\n\n// Model name/slug/description and field key/label/type are author/agent-controlled\n// (the same content the sibling codegen package treats as hostile via escapeJsDoc).\n// llms.txt is fed to AI crawlers, so unescaped values could forge headings/blockquotes\n// or break out of code spans — a structure-spoofing / prompt-injection vector.\n\n/** Collapse to a single line — kills newline-based block injection. */\nfunction oneLine(text: string): string {\n return text.replace(/[\\r\\n]+/g, \" \").trim();\n}\n\n/** For text rendered OUTSIDE a code span (titles, descriptions, labels): single-line +\n * escape a leading markdown block-control char so it can't start a heading/list/quote. */\nfunction inlineText(text: string): string {\n return oneLine(text).replace(/^([#>\\-*+=|])/, \"\\\\$1\");\n}\n\n/** For text rendered INSIDE a code span: strip backticks (which would close the span)\n * and newlines. */\nfunction codeSpan(text: string): string {\n return oneLine(text).replace(/`/g, \"\");\n}\n\nfunction fieldLine(f: LlmsModelField): string {\n const req = f.required ? \", required\" : \"\";\n const label = f.label && f.label !== f.key ? ` — ${inlineText(f.label)}` : \"\";\n return ` - \\`${codeSpan(f.key)}\\` (${codeSpan(f.type)}${req})${label}`;\n}\n\n/**\n * Render an llms.txt document describing the available content models. Deterministic:\n * models are sorted by slug; field order is preserved as authored.\n */\nexport function generateLlmsTxt(models: LlmsModel[], opts: LlmsTxtOptions = {}): string {\n const title = opts.title ?? \"BetterCMS content\";\n const sorted = [...models].sort((a, b) =>\n a.slug < b.slug ? -1 : a.slug > b.slug ? 1 : 0,\n );\n\n const lines: string[] = [`# ${inlineText(title)}`, \"\"];\n if (opts.description) {\n lines.push(`> ${inlineText(opts.description)}`, \"\");\n }\n\n const base =\n opts.baseUrl && opts.workspace\n ? `${opts.baseUrl.replace(/\\/+$/, \"\")}/${opts.workspace}/content-entries`\n : undefined;\n\n lines.push(\"## Content models\", \"\");\n if (sorted.length === 0) {\n lines.push(\"_No content models are defined yet._\", \"\");\n }\n for (const model of sorted) {\n const name = model.name ?? model.slug;\n lines.push(`### ${inlineText(name)} (\\`${codeSpan(model.slug)}\\`)`);\n if (model.description) lines.push(\"\", inlineText(model.description));\n if (base) {\n lines.push(\"\", `- List: \\`GET ${base}?model=${codeSpan(model.slug)}\\``);\n lines.push(`- Entry: \\`GET ${base}/{slug}\\``);\n }\n if (model.fields.length) {\n lines.push(\"\", \"Fields:\");\n for (const f of model.fields) lines.push(fieldLine(f));\n }\n lines.push(\"\");\n }\n\n if (opts.notes?.length) {\n lines.push(\"## Notes\", \"\");\n for (const note of opts.notes) lines.push(`- ${inlineText(note)}`);\n lines.push(\"\");\n }\n\n return lines.join(\"\\n\");\n}\n\n// ── Integration SKILL.md ────────────────────────────────────────────────────────\n// A framework-agnostic agent skill (frontmatter + lean body) that teaches an AI how\n// to READ this project's content from the Delivery API. Unlike llms.txt it does NOT\n// dump every field — it points at the live types endpoint so the schema can't go\n// stale, and names content types by slug only. Drop at .claude/skills/<name>/SKILL.md.\n\n/** A content type named in the skill — slug + kind only (no fields). */\nexport interface SkillContentType {\n kind: \"page\" | \"model\";\n slug: string;\n /** \"singleton\" | \"dynamic\" for pages; omitted for models. */\n pageType?: string | null;\n}\n\nexport interface SkillOptions {\n /** Human project name (skill title + description). */\n projectName: string;\n /** Project slug → the skill's kebab-case `name:`. */\n projectSlug: string;\n /** Delivery + management API base, e.g. https://api.bettercms.ai/api/v1. */\n apiUrl: string;\n /** Workspace slug used in the delivery paths. */\n workspace: string;\n /** Where to mint a content:read delivery key. */\n mintUrl: string;\n /** Key-authed live TypeScript types endpoint. */\n typesUrl: string;\n /** This project's content types (pages + models), by slug — no field dump. */\n contentTypes: SkillContentType[];\n}\n\n/**\n * Render a concise, framework-agnostic SKILL.md describing how to read THIS\n * project's content from the BetterCMS Delivery API. Deterministic: content types\n * sorted by slug. Author-controlled strings (project name, slugs, pageType) are\n * injection-escaped, same as {@link generateLlmsTxt}.\n */\nexport type SkillTarget = \"claude\" | \"cursor\" | \"agents\";\n\nexport interface SkillVariant {\n /** The agent/IDE this variant targets. */\n target: SkillTarget;\n /** Human label for a tab/picker. */\n label: string;\n /** Suggested path to save the file, e.g. `.claude/skills/<name>/SKILL.md`. */\n filename: string;\n /** Full file content (target-specific frontmatter + the shared body). */\n content: string;\n}\n\n/** The shared, tool-agnostic instruction body — no frontmatter, no save hint. */\nfunction skillBody(opts: SkillOptions): string {\n const proj = inlineText(opts.projectName);\n const api = opts.apiUrl.replace(/\\/+$/, \"\");\n const deliveryBase = `${api}/delivery/${codeSpan(opts.workspace)}`;\n const sorted = [...opts.contentTypes].sort((a, b) =>\n a.slug < b.slug ? -1 : a.slug > b.slug ? 1 : 0,\n );\n\n const lines: string[] = [\n `# BetterCMS — ${proj}`,\n \"\",\n `${proj}'s content lives in BetterCMS. Read it through the Delivery API with a project ` +\n \"`content:read` key. Pull field shapes live from the types endpoint below — don't hardcode \" +\n \"them, the schema can change.\",\n \"\",\n \"## Auth\",\n \"Send `X-API-Key: <key>` on every read. Mint a long-lived `content:read` key (reads PUBLISHED \" +\n `content, never expires) at ${opts.mintUrl}. For drafts, mint a \\`content:read:draft\\` key ` +\n \"(force-expired to ≤1h), then publish and switch to the long-lived key.\",\n \"\",\n \"## Content types\",\n ];\n if (sorted.length === 0) {\n lines.push(\"_None yet — create pages or models first (e.g. via the BetterCMS MCP)._\");\n } else {\n for (const ct of sorted) {\n const kind =\n ct.kind === \"page\"\n ? `page${ct.pageType ? ` (${codeSpan(ct.pageType)})` : \"\"}`\n : \"model\";\n lines.push(`- \\`${codeSpan(ct.slug)}\\` — ${kind}`);\n }\n }\n lines.push(\n \"\",\n `## Reading (Delivery API · base \\`${deliveryBase}\\`)`,\n \"- Page: `GET .../content/{slug}`\",\n \"- Entries (list): `GET .../content-entries?model={slug}`\",\n \"- Entry: `GET .../content-entries/{slug}`\",\n \"\",\n \"## Typed client\",\n `- Live TypeScript types: \\`GET ${opts.typesUrl}\\` — authoritative field shapes; generate/refresh from here.`,\n \"- `npm i @bettercms-ai/next @bettercms-ai/codegen`, then construct the client. \" +\n \"`baseUrl` + `workspace` are required — there is no `apiUrl`/`endpoint` option:\",\n \"\",\n \"```ts\",\n 'import { createBetterCMS } from \"@bettercms-ai/next\";',\n \"const cms = createBetterCMS<BetterCMSSchema>({\",\n ` baseUrl: \"${api}/delivery\",`,\n ` workspace: \"${codeSpan(opts.workspace)}\",`,\n \" apiKey: process.env.BETTERCMS_API_KEY,\",\n \"});\",\n \"```\",\n \"\",\n \"## Field shapes you'll read\",\n \"Canonical READ shapes the Delivery API returns. Per-field types come from the types \" +\n \"endpoint; these container shapes are stable:\",\n '- **richtext** → `{ html, value: { root: … }, format: \"lexical-…\" }`. Render `html`, ' +\n \"or walk `value.root` for structured rendering.\",\n \"- **image** → `{ url, altText?, width?, height?, id? }` — an object, use `.url` (the \" +\n \"write value is a bare CDN URL string, but reads are normalized to this object).\",\n \"- **array + zones** → `{ nonRepeatable?: { <key>: value }, repeatable?: Array<{ <key>: \" +\n \"value }> }`. `nonRepeatable` is one fixed block; `repeatable` is a list — map over it.\",\n '- **array (primitive)** → a flat list (e.g. `string[]`). `type: \"array\"` alone is ' +\n \"ambiguous — the generated type tells you which.\",\n \"\",\n \"Example entry `fields` (a `sections` zone field + a `tags` primitive array):\",\n \"```jsonc\",\n \"{\",\n ' \"sections\": {',\n ' \"nonRepeatable\": { \"eyebrow\": \"New\", \"heading\": \"Welcome\" },',\n ' \"repeatable\": [{ \"label\": \"Docs\", \"url\": \"/docs\", \"icon\": { \"url\": \"https://cdn…\" } }]',\n \" },\",\n ' \"tags\": [\"alpha\", \"beta\"]',\n \"}\",\n \"```\",\n \"\",\n \"## Live Preview bindings (makes the site visually editable)\",\n \"Generate a bindings module alongside the types and spread it so the dashboard's Live \" +\n \"Preview can edit each field in place:\",\n \"```bash\",\n `BETTERCMS_API_KEY=<key> npx bettercms-codegen --api-url ${api} --bindings-out src/bettercms.bindings.generated.ts`,\n \"```\",\n \"```tsx\",\n 'import { bcms } from \"./bettercms.bindings.generated\";',\n \"// scalar: <h1 {...bcms.<model>.<field>}>{entry.fields.field}</h1>\",\n \"// list item: <article {...bcms.<model>.<arr>.$(i)}><h3 {...bcms.<model>.<arr>.<sub>(i)}>{item.sub}</h3></article>\",\n \"// primitive list:<li {...bcms.<model>.<arr>.value(i)}>{tag}</li>\",\n \"```\",\n \"Bindings emit two inert `data-*` attributes on every build, so spreading them is \" +\n \"always safe.\",\n );\n return lines.join(\"\\n\");\n}\n\nfunction skillDescription(proj: string): string {\n return (\n `Read ${proj}'s content from BetterCMS via the Delivery API — auth, listing and fetching ` +\n \"pages and content entries, pulling live TypeScript types, and the @bettercms-ai/next typed \" +\n \"client. Use whenever fetching, rendering, or typing this project's CMS content.\"\n );\n}\n\n/**\n * Render the integration skill for a specific agent `target`. The instruction body is\n * identical across tools; only the frontmatter (and where you save it) differ:\n * - claude → Claude Code skill (`name` + `description`)\n * - cursor → Cursor `.mdc` rule (`description` + `globs` + `alwaysApply`, \"Agent Requested\")\n * - agents → plain Markdown, no frontmatter (drop into a repo-root `AGENTS.md`)\n */\nexport function generateSkill(opts: SkillOptions, target: SkillTarget = \"claude\"): string {\n const name = `bettercms-${codeSpan(opts.projectSlug)}`;\n const desc = skillDescription(inlineText(opts.projectName));\n const body = skillBody(opts);\n\n let frontmatter = \"\";\n if (target === \"claude\") {\n frontmatter = `---\\nname: ${name}\\ndescription: ${desc}\\n---\\n\\n`;\n } else if (target === \"cursor\") {\n frontmatter = `---\\ndescription: ${desc}\\nglobs:\\nalwaysApply: false\\n---\\n\\n`;\n }\n return `${frontmatter}${body}\\n`;\n}\n\nconst TARGET_META: Record<SkillTarget, { label: string; file: (name: string) => string }> = {\n claude: { label: \"Claude Code\", file: (n) => `.claude/skills/${n}/SKILL.md` },\n cursor: { label: \"Cursor\", file: (n) => `.cursor/rules/${n}.mdc` },\n agents: { label: \"AGENTS.md (generic)\", file: () => \"AGENTS.md\" },\n};\n\n/** Render the skill for every supported agent target — drives a tabbed picker in the UI. */\nexport function generateSkillVariants(opts: SkillOptions): SkillVariant[] {\n const name = `bettercms-${codeSpan(opts.projectSlug)}`;\n return (Object.keys(TARGET_META) as SkillTarget[]).map((target) => ({\n target,\n label: TARGET_META[target].label,\n filename: TARGET_META[target].file(name),\n content: generateSkill(opts, target),\n }));\n}\n\n/** Options for {@link llmsTxtRoute}. Provide one of `models` or `getModels`. */\nexport interface LlmsTxtRouteConfig extends LlmsTxtOptions {\n /** Static model list (e.g. fetched at build time). */\n models?: LlmsModel[];\n /** Dynamic provider — called per request (wrap in your own caching if needed). */\n getModels?: () => Promise<LlmsModel[]> | LlmsModel[];\n /** Cache-Control header value. Default: `public, max-age=3600`. */\n cacheControl?: string;\n}\n\n/**\n * Build an App Router route handler that serves llms.txt as `text/plain`.\n *\n * ```ts\n * // app/llms.txt/route.ts\n * import { llmsTxtRoute } from \"@bettercms-ai/next\";\n * export const GET = llmsTxtRoute({ models, title: \"Acme\", workspace: \"acme\" });\n * ```\n */\nexport function llmsTxtRoute(config: LlmsTxtRouteConfig): () => Promise<Response> {\n const { models, getModels, cacheControl, ...opts } = config;\n return async () => {\n const resolved = getModels ? await getModels() : (models ?? []);\n const body = generateLlmsTxt(resolved, opts);\n return new Response(body, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n \"Cache-Control\": cacheControl ?? \"public, max-age=3600\",\n },\n });\n };\n}\n\n/**\n * Fetch content models from the Management API (`GET /management/content/models`).\n * The key is project-scoped server-side, so this returns exactly this site's schema.\n * Dependency-free so it runs in any runtime (Edge route, build script, Node).\n */\nexport async function fetchModels(opts: {\n /** Management API base, e.g. \"https://api.bettercms.ai/api/v1\". */\n apiUrl: string;\n /** A management-scoped key (content:manage). */\n apiKey: string;\n /** Optional fetch override (testing / custom runtime). */\n fetchImpl?: typeof fetch;\n}): Promise<LlmsModel[]> {\n const doFetch = opts.fetchImpl ?? fetch;\n const base = opts.apiUrl.replace(/\\/+$/, \"\");\n const res = await doFetch(`${base}/management/content/models`, {\n headers: { Authorization: `Bearer ${opts.apiKey}`, Accept: \"application/json\" },\n });\n if (!res.ok) {\n throw new Error(`Management API returned ${res.status} ${res.statusText}`);\n }\n const body = (await res.json()) as { data?: LlmsModel[] };\n return (body.data ?? []).map((m) => ({\n slug: m.slug,\n name: m.name,\n description: m.description ?? null,\n fields: m.fields ?? [],\n }));\n}\n","/**\n * Draft-preview helpers. `next/headers` is imported dynamically so this module is safe\n * to load outside a Next.js request scope (tests, build scripts) without throwing.\n */\nimport { createElement, type ReactElement } from \"react\";\n\n/** True when Next.js Draft Mode is enabled for the current request. */\nexport async function isDraftEnabled(): Promise<boolean> {\n const { draftMode } = await import(\"next/headers\");\n const dm = await draftMode();\n return dm.isEnabled;\n}\n\n/**\n * The preview token stored by `createDraftModeRoute`, or null. Pass it to\n * `getEntry(slug, { preview: true, previewToken })` to read drafts.\n */\nexport async function getPreviewToken(): Promise<string | null> {\n const { cookies } = await import(\"next/headers\");\n const jar = await cookies();\n return jar.get(\"bcms-preview-token\")?.value ?? null;\n}\n\n/**\n * `<BcmsDraftMarker />` — put it in the root layout. In draft mode it stamps\n * `<html data-bcms-draft=\"1\">`, which is the ONLY thing the BetterCMS canvas trusts as proof\n * that the frame it loaded is your app rendering a DRAFT. Without it the editor cannot tell a\n * draft render from the published page and falls back to its own approximate renderer.\n *\n * An inline script rather than an attribute on `<html>` itself, so this stays a drop-in: the\n * layout keeps whatever `<html>` it already has, and a server component cannot reach up and\n * add an attribute to its ancestor. Renders nothing outside draft mode.\n */\nexport async function BcmsDraftMarker(): Promise<ReactElement | null> {\n if (!(await isDraftEnabled())) return null;\n return createElement(\"script\", {\n dangerouslySetInnerHTML: {\n __html: 'document.documentElement.setAttribute(\"data-bcms-draft\",\"1\")',\n },\n });\n}\n","/**\n * createDraftModeRoute — an App Router route-handler factory for entering draft\n * preview. Mount it at e.g. `app/api/draft/route.ts`:\n *\n * import { createDraftModeRoute } from \"@bettercms-ai/next\";\n * export const { GET } = createDraftModeRoute({ apiUrl: \"https://api.bettercms.ai\" });\n *\n * Visiting `/api/draft?token=<jwt>&redirect=/path` validates the preview token\n * against the backend (the signature authority), enables Next Draft Mode, stores\n * the token in an httpOnly cookie, and redirects. Reads can then pass the token\n * via `getPreviewToken()` to `getEntry({ preview: true, previewToken })`.\n */\n\nexport const PREVIEW_TOKEN_COOKIE = \"bcms-preview-token\";\n\nexport interface DraftModeRouteConfig {\n /** Backend base, e.g. `https://api.bettercms.ai`. */\n apiUrl: string;\n}\n\n/** Only same-origin relative paths. Blocks \"//evil.com\", \"https://evil.com\", etc. */\nfunction safeRedirectPath(to: string): string {\n return to.startsWith(\"/\") && !to.startsWith(\"//\") ? to : \"/\";\n}\n\n/** Decode a preview-token JWT payload (UNVERIFIED) to read its `entrySlug`. */\nfunction decodeTokenSlug(token: string): string | null {\n try {\n const part = token.split(\".\")[1];\n if (!part) return null;\n const json = JSON.parse(\n Buffer.from(part, \"base64url\").toString(\"utf8\"),\n ) as { entrySlug?: string };\n return json.entrySlug ?? null;\n } catch {\n return null;\n }\n}\n\nexport function createDraftModeRoute(config: DraftModeRouteConfig) {\n const apiUrl = config.apiUrl.replace(/\\/+$/, \"\");\n\n async function GET(request: Request): Promise<Response> {\n const url = new URL(request.url);\n const token = url.searchParams.get(\"token\");\n const redirectTo = url.searchParams.get(\"redirect\") ?? \"/\";\n\n if (!token) return new Response(\"Missing token\", { status: 400 });\n const slug = decodeTokenSlug(token);\n if (!slug) return new Response(\"Malformed token\", { status: 400 });\n\n const res = await fetch(\n `${apiUrl}/api/v1/preview/${encodeURIComponent(slug)}?token=${encodeURIComponent(token)}`,\n );\n if (!res.ok) return new Response(\"Invalid or expired token\", { status: 401 });\n\n const { draftMode, cookies } = await import(\"next/headers\");\n (await draftMode()).enable();\n (await cookies()).set(PREVIEW_TOKEN_COOKIE, token, {\n httpOnly: true,\n sameSite: \"lax\",\n secure: url.protocol === \"https:\",\n path: \"/\",\n maxAge: 60 * 60 * 24,\n });\n\n return Response.redirect(new URL(safeRedirectPath(redirectTo), url.origin), 302);\n }\n\n return { GET };\n}\n\n/** Exit draft mode and clear the preview-token cookie. */\nexport function createDisableDraftRoute() {\n async function GET(request: Request): Promise<Response> {\n const url = new URL(request.url);\n const redirectTo = url.searchParams.get(\"redirect\") ?? \"/\";\n const { draftMode, cookies } = await import(\"next/headers\");\n (await draftMode()).disable();\n (await cookies()).delete(PREVIEW_TOKEN_COOKIE);\n return Response.redirect(new URL(safeRedirectPath(redirectTo), url.origin), 302);\n }\n return { GET };\n}\n","/**\n * Build-time reader for the forms the deploy Action injects into the content\n * snapshot (schema \"bcms-content/v1\": `{ ...collections, forms, turnstileSiteKey }`).\n *\n * This is intentionally separate from `readSnapshot()` — that reads the\n * `@bettercms-ai/next` \"bettercms-snapshot\" format (`{ version, models }`), which is a\n * different file shape. Connected-repo sites on <name>.bettercms.site get the Action\n * snapshot, so forms live here. Server/build-time only (uses node:fs).\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { DeliveryForm } from \"@bettercms-ai/sdk\";\n\nexport interface SnapshotForms {\n forms: DeliveryForm[];\n /** Public Turnstile site key for any form with `turnstileEnabled`, or null. */\n turnstileSiteKey: string | null;\n}\n\n/**\n * Read forms from the Action's `bcms-content.json`. Missing file or no forms →\n * an empty set (a content-only build never throws). `path` resolves against cwd.\n */\nexport function readForms(path = \"bcms-content.json\"): SnapshotForms {\n let raw: string;\n try {\n raw = readFileSync(resolve(process.cwd(), path), \"utf8\");\n } catch {\n return { forms: [], turnstileSiteKey: null };\n }\n const snap = JSON.parse(raw) as { forms?: DeliveryForm[]; turnstileSiteKey?: string | null };\n return { forms: snap.forms ?? [], turnstileSiteKey: snap.turnstileSiteKey ?? null };\n}\n\n/** Find a single form by `id` or `name` from the Action snapshot. */\nexport function getForm(idOrName: string, path?: string): DeliveryForm | undefined {\n return readForms(path).forms.find((f) => f.id === idOrName || f.name === idOrName);\n}\n","/**\n * Build-time reader for the pages the deploy Action injects into the content\n * snapshot (schema \"bcms-content/v1\": `{ ...collections, forms, pages, turnstileSiteKey }`).\n *\n * Sibling to `forms-read.ts`. Connected-repo sites on <name>.bettercms.site get the\n * Action snapshot, so published pages (with their block_json) live here. Render a page\n * with `<BcmsBlocks blocks={page.blocks} forms={readForms().forms} />`. The same data\n * is also available at runtime via `createBetterCMS(...).getPage(slug)`.\n * Server/build-time only (uses node:fs).\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { ContentBlock, PageMetaJson, DeliveredLayout } from \"@bettercms-ai/types\";\n\nexport interface SnapshotPage {\n projectId?: string | null;\n slug: string;\n title: string;\n metaTitle: string | null;\n metaDescription: string | null;\n /** Rich SEO (OG / Twitter / canonical / JSON-LD) — FLO-302. Feed to `buildMetadata`. */\n metaJson: PageMetaJson | null;\n /** The page's block_json — pass to `<BcmsBlocks blocks={...} />`. */\n blocks: ContentBlock[];\n /** Resolved published project/page chrome, shared with runtime Delivery reads. */\n layout?: DeliveredLayout | null;\n updatedAt: string | null;\n publishedAt: string | null;\n}\n\n/**\n * Read published pages from the Action's `bcms-content.json`. Missing file or no\n * pages → an empty list (a pages-less build never throws). `path` resolves against cwd.\n */\nexport function readPages(path = \"bcms-content.json\"): SnapshotPage[] {\n let raw: string;\n try {\n raw = readFileSync(resolve(process.cwd(), path), \"utf8\");\n } catch {\n return [];\n }\n const snap = JSON.parse(raw) as { pages?: SnapshotPage[] };\n return snap.pages ?? [];\n}\n\n/** Find a single published page by `slug` from the Action snapshot. */\nexport function getPage(slug: string, path?: string): SnapshotPage | undefined {\n return readPages(path).find((p) => p.slug === slug);\n}\n","/**\n * Build-time reader for the reusable components the deploy Action injects into the\n * content snapshot (`bcms-content.json` → `components`). Mirrors `forms-read.ts`.\n *\n * Pass the result to `<BcmsBlocks components={readComponents()} … />` so `component`\n * blocks resolve their definitions. Server/build-time only (uses node:fs).\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { DeliveryComponent } from \"@bettercms-ai/types\";\n\n/**\n * Read components from the Action's `bcms-content.json`. Missing file or no\n * components → an empty array (a content-only build never throws).\n */\nexport function readComponents(path = \"bcms-content.json\"): DeliveryComponent[] {\n let raw: string;\n try {\n raw = readFileSync(resolve(process.cwd(), path), \"utf8\");\n } catch {\n return [];\n }\n const snap = JSON.parse(raw) as { components?: DeliveryComponent[] };\n return snap.components ?? [];\n}\n\n/** Find a single component by `id`, `slug`, or `name` from the Action snapshot. */\nexport function getComponent(idOrSlug: string, path?: string): DeliveryComponent | undefined {\n return readComponents(path).find(\n (c) => c.id === idOrSlug || c.slug === idOrSlug || c.name === idOrSlug,\n );\n}\n","/**\n * <BcmsField> — tag an entry field's rendered value with its identity so the\n * BetterCMS visual editor can bind click-to-edit deterministically (mirrors\n * Sanity's `data-sanity` / BaseHub's `data-basehub`). Entry-backed templates\n * hand-render field values (`f.title`, `f.body.html`), so the field `path` is\n * declared here by the author — the delivery payload carries no source-map.\n *\n * Server-safe (no hooks): renders in a Next Server Component. By default it wraps\n * children in a `display:contents` span, invisible to layout/GSAP; pass `as` to\n * carry the attributes on a real element instead.\n *\n * `path` follows the editor grammar: `title` · `hero.title` · `facts[2].label`\n * (dotted keys, at most one array index). For images, put the attributes on the\n * `<img>` itself (`kind=\"image\"` reflection patches `.src`), not on a wrapper:\n * <img src={f.cover.url} data-bcms-field=\"cover\" data-bcms-kind=\"image\" />\n */\nimport type { ElementType, ReactNode } from \"react\";\n\nexport interface BcmsFieldProps {\n /** Field path in the editor grammar, e.g. `title` or `facts[2].label`. */\n path: string;\n /** Kind hint the editor's reflection branches on. Omit for plain text/number. */\n kind?: \"richtext\" | \"image\";\n /** Wrapper element. Defaults to a `display:contents` span. */\n as?: ElementType;\n children: ReactNode;\n}\n\nexport function BcmsField({ path, kind, as, children }: BcmsFieldProps) {\n const Tag = as ?? \"span\";\n return (\n <Tag\n data-bcms-field={path}\n data-bcms-kind={kind}\n style={as ? undefined : { display: \"contents\" }}\n >\n {children}\n </Tag>\n );\n}\n","/**\n * defineBetterCMSLive — build the live SSE URL for `<BcmsLive>` from your config.\n * Server-safe (no React); pass the returned `liveSrc` to the client component.\n */\nexport interface BetterCMSLiveConfig {\n /** Backend base, e.g. `https://api.bettercms.ai`. */\n apiUrl: string;\n workspace: string;\n /** A content:read key — exposed to the browser via the SSE URL query. */\n apiKey: string;\n /**\n * Reference hydration depth for the pushed document. Default 1, matching the\n * delivery API. Set 0 when you only render top-level fields — a smaller doc is\n * a faster frame.\n */\n depth?: 0 | 1 | 2;\n /**\n * Stream draft autosaves too, so a preview surface repaints as the editor types.\n * Requires a `content:read:draft` key; the server ignores the flag for any other\n * key rather than failing the connection. Never enable this on a public site —\n * the key it needs can read unpublished content.\n */\n drafts?: boolean;\n}\n\nexport function defineBetterCMSLive(config: BetterCMSLiveConfig): { liveSrc: string } {\n const base = config.apiUrl.replace(/\\/+$/, \"\");\n const q = new URLSearchParams({ key: config.apiKey });\n if (config.depth !== undefined) q.set(\"depth\", String(config.depth));\n if (config.drafts) q.set(\"drafts\", \"1\");\n const liveSrc = `${base}/api/v1/delivery/${config.workspace}/live?${q}`;\n return { liveSrc };\n}\n","/**\n * createRevalidateRoute — App Router POST handler that receives the backend's\n * revalidation webhook and calls `revalidateTag()` for each affected tag. This is\n * the production live path (publish → backend webhook → revalidate ISR cache).\n *\n * import { createRevalidateRoute } from \"@bettercms-ai/next\";\n * export const { POST } = createRevalidateRoute({ secret: process.env.BCMS_REVALIDATE_SECRET });\n *\n * When `secret` is set, the `X-BetterCMS-Signature` HMAC-SHA256 header is verified\n * against the raw body (the same secret configured on the project in the dashboard).\n */\nimport { createHmac, timingSafeEqual } from \"node:crypto\";\n\nexport interface RevalidateRouteConfig {\n /** Shared secret matching the project's revalidation webhook secret. */\n secret?: string;\n}\n\nfunction safeEqual(a: string, b: string): boolean {\n const ab = Buffer.from(a);\n const bb = Buffer.from(b);\n return ab.length === bb.length && timingSafeEqual(ab, bb);\n}\n\nexport function createRevalidateRoute(config: RevalidateRouteConfig = {}) {\n async function POST(request: Request): Promise<Response> {\n const body = await request.text();\n\n if (config.secret) {\n const provided = request.headers.get(\"x-bettercms-signature\") ?? \"\";\n const expected = `sha256=${createHmac(\"sha256\", config.secret).update(body).digest(\"hex\")}`;\n if (!safeEqual(provided, expected)) {\n return new Response(\"Invalid signature\", { status: 401 });\n }\n }\n\n let payload: { data?: { tags?: string[] } };\n try {\n payload = JSON.parse(body);\n } catch {\n return new Response(\"Invalid JSON\", { status: 400 });\n }\n\n const tags = payload.data?.tags ?? [];\n const { revalidateTag } = await import(\"next/cache\");\n for (const tag of tags) revalidateTag(tag);\n\n return Response.json({ revalidated: true, tags });\n }\n\n return { POST };\n}\n"],"mappings":";AAUO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAC/B;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAc;AACzD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,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AAE,OAAO,KAAK,CAAC;AACzF,UAAI,CAAC,UAAU,UAAU,QAAQ,GAAG;AAClC,eAAO,IAAI,SAAS,qBAAqB,EAAE,QAAQ,IAAI,CAAC;AAAA,MAC1D;AAAA,IACF;AAEA,QAAI;AACJ,QAAI;AACF,gBAAU,KAAK,MAAM,IAAI;AAAA,IAC3B,QAAQ;AACN,aAAO,IAAI,SAAS,gBAAgB,EAAE,QAAQ,IAAI,CAAC;AAAA,IACrD;AAEA,UAAM,OAAO,QAAQ,MAAM,QAAQ,CAAC;AACpC,UAAM,EAAE,cAAc,IAAI,MAAM,OAAO,YAAY;AACnD,eAAW,OAAO,KAAM,eAAc,GAAG;AAEzC,WAAO,SAAS,KAAK,EAAE,aAAa,MAAM,KAAK,CAAC;AAAA,EAClD;AAEA,SAAO,EAAE,KAAK;AAChB;","names":["url","resolveSeo","default","readFileSync","resolve","readFileSync","resolve","readFileSync","resolve"]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/client.ts","../src/metadata.ts","../src/index.ts","../src/snapshot.ts","../src/llms-txt.ts","../src/preview.ts","../src/draft-route.ts","../src/forms-read.ts","../src/pages-read.ts","../src/components-read.ts","../src/field.tsx","../src/live-config.ts","../src/revalidate-route.ts"],"sourcesContent":["/**\n * Public types for @bettercms-ai/next.\n *\n * `BetterCMSEntry` mirrors the envelope emitted by @bettercms-ai/codegen's generated\n * file. The adapter normalizes the raw Delivery API response into exactly this shape,\n * so `getEntry`/`listEntries` line up 1:1 with your generated model types.\n */\n\n/** Normalized error thrown by adapter reads. Mirrors the SDK's BetterCMSError, but kept\n * local so the adapter carries no heavy runtime dependency into a consumer's bundle. */\nexport class BetterCMSError extends Error {\n readonly status: number;\n readonly code: string;\n\n constructor(message: string, status: number, code: string) {\n super(message);\n this.name = \"BetterCMSError\";\n this.status = status;\n this.code = code;\n }\n}\n\n/**\n * Delivery envelope around a model's typed `fields`. Returned by `getEntry`/`listEntries`.\n * Identical to the `BetterCMSEntry<TFields>` your generated types declare.\n *\n * `publishedAt`/`updatedAt` are ISO-8601 strings, or `null` when absent — never a\n * fabricated empty string (so `new Date(...)` is safe to attempt only on non-null).\n */\nexport interface BetterCMSEntry<TFields> {\n readonly slug: string;\n readonly status: \"draft\" | \"published\";\n readonly fields: TFields;\n readonly publishedAt: string | null;\n readonly updatedAt: string | null;\n}\n\nexport interface BetterCMSConfig {\n /** Workspace slug — the `:workspace` segment of the Delivery API path. */\n workspace: string;\n /** Optional delivery API key (sent as `Authorization: Bearer`). */\n apiKey?: string;\n /** Delivery API base. Default: `https://api.bettercms.ai/api/v1/delivery`. */\n baseUrl?: string;\n /** Preview API base. Default: derived from `baseUrl` (`/delivery` → `/preview`). */\n previewBaseUrl?: string;\n /**\n * Default Next.js revalidation for reads (seconds). `false` = always fresh\n * (`cache: \"no-store\"`). Per-call `revalidate` overrides this. Default: `60`.\n */\n revalidate?: number | false;\n}\n\n/** Per-read options shared by `getEntry` and `listEntries`. */\nexport interface ReadOptions {\n /** ISR window in seconds, or `false` for `cache: \"no-store\"`. Overrides config default. */\n revalidate?: number | false;\n /** Next.js cache tags for on-demand `revalidateTag()` invalidation. */\n tags?: string[];\n /** Reference hydration depth (0 = none, 1 = direct refs, 2 = nested). */\n depth?: 0 | 1 | 2;\n /** Field projection — only these field keys are returned. */\n select?: string[];\n}\n\n/** Options for `getEntry`, including draft-preview access. */\nexport interface GetEntryOptions extends ReadOptions {\n /** Fetch draft content via the preview endpoint. Requires `previewToken`. */\n preview?: boolean;\n /** Signed preview token (from `POST .../preview-token`). */\n previewToken?: string;\n}\n\n/** Options for `listEntries`. */\nexport interface ListEntriesOptions extends ReadOptions {\n /** 1-based page number. Default: 1. */\n page?: number;\n /** Items per page (max 100). Default: 20. */\n perPage?: number;\n}\n\n/** Paginated result returned by `listEntries`. */\nexport interface EntryList<TFields> {\n items: BetterCMSEntry<TFields>[];\n page: number;\n perPage: number;\n totalItems: number;\n totalPages: number;\n hasNextPage: boolean;\n hasPreviousPage: boolean;\n}\n","/**\n * createBetterCMS — the Next.js delivery client.\n *\n * Reads run through the standard `fetch`, which the Next.js App Router patches to\n * participate in the data cache. We pass `next: { revalidate, tags }` so content is\n * cached/ISR'd and can be invalidated on publish via `revalidateTag()`.\n *\n * The raw Delivery API response is normalized into `BetterCMSEntry<TFields>` so the\n * return types match what @bettercms-ai/codegen generates.\n */\n\nimport type { ContentBlock, DeliveredLayout, PageMetaJson } from \"@bettercms-ai/types\";\nimport {\n BetterCMSError,\n type BetterCMSConfig,\n type BetterCMSEntry,\n type EntryList,\n type GetEntryOptions,\n type ListEntriesOptions,\n} from \"./types.js\";\n\n/** A published page with its block_json — feed `blocks` to `<BcmsBlocks>`.\n * The SEO fields (FLO-302) feed `buildMetadata` for the route's `generateMetadata`. */\nexport interface BetterCMSPage {\n slug: string;\n title: string;\n metaTitle: string | null;\n metaDescription: string | null;\n /** Rich SEO (OG / Twitter / canonical / JSON-LD). `null` when unset. */\n metaJson: PageMetaJson | null;\n blocks: ContentBlock[];\n layout?: DeliveredLayout | null;\n publishedAt: string | null;\n updatedAt: string | null;\n}\n\n/** Raw single-page shape returned by the Delivery API (`/content/:slug`). */\ninterface RawPageResponse {\n data: {\n slug: string;\n entry: {\n slug: string;\n title: string;\n metaTitle?: string | null;\n metaDescription?: string | null;\n metaJson?: PageMetaJson | null;\n blocks?: ContentBlock[];\n layout?: DeliveredLayout | null;\n updatedAt?: string | null;\n };\n publishedAt: string | null;\n };\n}\n\nconst DEFAULT_BASE_URL = \"https://api.bettercms.ai/api/v1/delivery\";\nconst DEFAULT_REVALIDATE = 60;\n\n/** `fetch`'s init augmented with Next.js's `next` cache directives. (`cache` is declared\n * explicitly because this package compiles without the DOM lib.) */\ntype NextRequestInit = RequestInit & {\n cache?: \"default\" | \"no-store\" | \"force-cache\";\n next?: { revalidate?: number | false; tags?: string[] };\n};\n\n/** Raw single-entry shape returned by the Delivery API. */\ninterface RawEntry {\n id: string;\n slug: string;\n status: \"draft\" | \"published\";\n publishedAt: string | null;\n updatedAt?: string | null;\n data: Record<string, unknown>;\n}\n\ninterface RawListResponse {\n data: {\n items: RawEntry[];\n page: number;\n perPage: number;\n totalItems: number;\n totalPages: number;\n hasNextPage: boolean;\n hasPreviousPage: boolean;\n };\n}\n\nfunction statusToCode(status: number): string {\n if (status === 404) return \"CONTENT_NOT_FOUND\";\n if (status === 401) return \"UNAUTHORIZED\";\n if (status === 403) return \"FORBIDDEN\";\n if (status === 429) return \"RATE_LIMITED\";\n if (status === 422) return \"VALIDATION_ERROR\";\n return \"INTERNAL_ERROR\";\n}\n\n/** Normalize a raw delivery entry into the codegen-aligned envelope. `publishedAt`\n * and `updatedAt` are kept distinct and pass through `null` rather than being\n * conflated or fabricated as \"\" (which would parse to an Invalid Date). */\nfunction mapEntry<TFields>(raw: RawEntry): BetterCMSEntry<TFields> {\n return {\n slug: raw.slug,\n status: raw.status,\n fields: raw.data as TFields,\n publishedAt: raw.publishedAt ?? null,\n updatedAt: raw.updatedAt ?? null,\n };\n}\n\n/**\n * The typed BetterCMS reader for Next.js.\n *\n * @typeParam Schema - your generated `BetterCMSSchema` (slug → fields registry). When\n * supplied, `listEntries(\"blog\")` is typed by the model's fields and the model name\n * autocompletes. Defaults to an open record so it also works untyped.\n */\nexport interface BetterCMSNext<Schema extends Record<string, unknown>> {\n /** Fetch one published entry by its content slug. Returns `null` when not found.\n * Passing `select` narrows the result to `Partial<TFields>` (projection drops fields). */\n getEntry<TFields = unknown>(\n slug: string,\n opts: GetEntryOptions & { select: string[] },\n ): Promise<BetterCMSEntry<Partial<TFields>> | null>;\n getEntry<TFields = unknown>(\n slug: string,\n opts?: GetEntryOptions,\n ): Promise<BetterCMSEntry<TFields> | null>;\n\n /** List published entries, filtered to one model. Throws `BetterCMSError`\n * (CONTENT_NOT_FOUND) for an unknown workspace/model — an empty model returns an\n * empty page. Passing `select` narrows fields to `Partial`. */\n listEntries<M extends keyof Schema & string>(\n model: M,\n opts: ListEntriesOptions & { select: string[] },\n ): Promise<EntryList<Partial<Schema[M]>>>;\n listEntries<M extends keyof Schema & string>(\n model: M,\n opts?: ListEntriesOptions,\n ): Promise<EntryList<Schema[M]>>;\n listEntries<TFields = unknown>(\n model?: string,\n opts?: ListEntriesOptions,\n ): Promise<EntryList<TFields>>;\n\n /** Fetch one published page (with its `blocks` for `<BcmsBlocks>`) by slug.\n * Returns `null` when not found. */\n getPage(\n slug: string,\n opts?: { revalidate?: number | false; tags?: string[] },\n ): Promise<BetterCMSPage | null>;\n /** Fetch the project-scoped published Global Layout. */\n getLayout(opts?: { revalidate?: number | false; tags?: string[] }): Promise<DeliveredLayout | null>;\n}\n\nexport function createBetterCMS<\n Schema extends Record<string, unknown> = Record<string, unknown>,\n>(config: BetterCMSConfig): BetterCMSNext<Schema> {\n const baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n const previewBaseUrl = (\n config.previewBaseUrl ?? baseUrl.replace(/\\/delivery$/, \"/preview\")\n ).replace(/\\/+$/, \"\");\n const defaultRevalidate = config.revalidate ?? DEFAULT_REVALIDATE;\n\n function headers(): Record<string, string> {\n const h: Record<string, string> = { Accept: \"application/json\" };\n if (config.apiKey) h[\"Authorization\"] = `Bearer ${config.apiKey}`;\n return h;\n }\n\n function cacheInit(\n revalidate: number | false | undefined,\n tags: string[] | undefined,\n forceNoStore = false,\n ): NextRequestInit {\n const rv = revalidate ?? defaultRevalidate;\n // Preview is always uncached.\n if (forceNoStore) return { headers: headers(), cache: \"no-store\" };\n if (rv === false) {\n // With tags, \"false\" means cache until `revalidateTag` (the canonical CMS\n // publish-invalidation pattern) — we must NOT drop the tags to no-store, or\n // revalidateTag could never invalidate. Without tags, it means truly fresh.\n return tags?.length\n ? { headers: headers(), next: { revalidate: false, tags } }\n : { headers: headers(), cache: \"no-store\" };\n }\n return { headers: headers(), next: { revalidate: rv, tags } };\n }\n\n async function requestJSON<T>(\n url: string,\n init: NextRequestInit,\n { nullOn404 = false }: { nullOn404?: boolean } = {},\n ): Promise<T | null> {\n let res: Response;\n try {\n res = await fetch(url, init);\n } catch (err) {\n throw new BetterCMSError(\n `Network error: ${err instanceof Error ? err.message : String(err)}`,\n 0,\n \"NETWORK_ERROR\",\n );\n }\n // A single-entry 404 is \"no such entry\" (→ null). A list 404 is a real error\n // (unknown workspace/model) and must surface, not masquerade as an empty list.\n if (res.status === 404 && nullOn404) return null;\n if (!res.ok) {\n let message = res.statusText || \"Request failed\";\n try {\n const body = (await res.json()) as { error?: string; message?: string };\n message = body.error ?? body.message ?? message;\n } catch {\n /* ignore parse errors */\n }\n throw new BetterCMSError(message, res.status, statusToCode(res.status));\n }\n return (await res.json()) as T;\n }\n\n function entryQuery(opts?: { depth?: 0 | 1 | 2; select?: string[] }): string {\n const params = new URLSearchParams();\n if (opts?.depth != null) params.set(\"depth\", String(opts.depth));\n if (opts?.select?.length) params.set(\"select\", opts.select.join(\",\"));\n const qs = params.toString();\n return qs ? `?${qs}` : \"\";\n }\n\n const client = {\n async getEntry<TFields = unknown>(slug: string, opts?: GetEntryOptions) {\n const encoded = encodeURIComponent(slug);\n const query = entryQuery(opts);\n\n // Preview: drafts are only reachable through the signed preview endpoint, and\n // must never be cached (every request re-validates the token server-side).\n if (opts?.preview) {\n if (!opts.previewToken) {\n throw new BetterCMSError(\n \"preview: true requires a previewToken\",\n 400,\n \"VALIDATION_ERROR\",\n );\n }\n const tokenParam = `token=${encodeURIComponent(opts.previewToken)}`;\n const sep = query ? \"&\" : \"?\";\n const url = `${previewBaseUrl}/${encoded}${query}${sep}${tokenParam}`;\n const body = await requestJSON<{ data: RawEntry }>(\n url,\n cacheInit(undefined, undefined, true),\n { nullOn404: true },\n );\n return body ? mapEntry<TFields>(body.data) : null;\n }\n\n const url = `${baseUrl}/${config.workspace}/content-entries/${encoded}${query}`;\n const raw = await requestJSON<RawEntry>(\n url,\n cacheInit(opts?.revalidate, opts?.tags),\n { nullOn404: true },\n );\n return raw ? mapEntry<TFields>(raw) : null;\n },\n\n async listEntries<TFields = unknown>(\n model?: string,\n opts?: ListEntriesOptions,\n ): Promise<EntryList<TFields>> {\n const params = new URLSearchParams();\n if (model) params.set(\"model\", model);\n if (opts?.page != null) params.set(\"page\", String(opts.page));\n if (opts?.perPage != null) params.set(\"perPage\", String(opts.perPage));\n if (opts?.depth != null) params.set(\"depth\", String(opts.depth));\n if (opts?.select?.length) params.set(\"select\", opts.select.join(\",\"));\n\n const url = `${baseUrl}/${config.workspace}/content-entries?${params}`;\n const body = await requestJSON<RawListResponse>(\n url,\n cacheInit(opts?.revalidate, opts?.tags),\n );\n\n const data = body?.data;\n if (!data) {\n return {\n items: [],\n page: opts?.page ?? 1,\n perPage: opts?.perPage ?? 20,\n totalItems: 0,\n totalPages: 1,\n hasNextPage: false,\n hasPreviousPage: false,\n };\n }\n return {\n items: data.items.map((r) => mapEntry<TFields>(r)),\n page: data.page,\n perPage: data.perPage,\n totalItems: data.totalItems,\n totalPages: data.totalPages,\n hasNextPage: data.hasNextPage,\n hasPreviousPage: data.hasPreviousPage,\n };\n },\n\n async getPage(\n slug: string,\n opts?: { revalidate?: number | false; tags?: string[] },\n ): Promise<BetterCMSPage | null> {\n const url = `${baseUrl}/${config.workspace}/content/${encodeURIComponent(slug)}`;\n const body = await requestJSON<RawPageResponse>(\n url,\n cacheInit(opts?.revalidate, opts?.tags),\n { nullOn404: true },\n );\n if (!body) return null;\n const { entry, publishedAt } = body.data;\n return {\n slug: entry.slug,\n title: entry.title,\n metaTitle: entry.metaTitle ?? null,\n metaDescription: entry.metaDescription ?? null,\n metaJson: entry.metaJson ?? null,\n blocks: entry.blocks ?? [],\n layout: entry.layout ?? null,\n publishedAt: publishedAt ?? null,\n updatedAt: entry.updatedAt ?? null,\n };\n },\n\n async getLayout(opts?: { revalidate?: number | false; tags?: string[] }) {\n const body = await requestJSON<{ data: DeliveredLayout }>(\n `${baseUrl}/${config.workspace}/layout`,\n cacheInit(opts?.revalidate, opts?.tags),\n { nullOn404: true },\n );\n return body?.data ?? null;\n },\n };\n\n // The concrete impls use single generic signatures; the public interface exposes\n // richer overloads (select→Partial, model-keyed typing). Cast once here.\n return client as unknown as BetterCMSNext<Schema>;\n}\n","/**\n * buildMetadata — map a BetterCMS page's SEO onto a Next.js `Metadata` object.\n *\n * Wire it into a route's `generateMetadata` so per-page Meta Title / Description and\n * the rich OG / Twitter / canonical the dashboard saves drive the live `<head>`:\n *\n * import { createBetterCMS, buildMetadata } from \"@bettercms-ai/next\";\n * const bcms = createBetterCMS({ workspace: \"acme\" });\n *\n * export async function generateMetadata({ params }): Promise<Metadata> {\n * const page = await bcms.getPage(params.slug);\n * if (!page) return {};\n * return buildMetadata(page, siteDefaults); // siteDefaults optional\n * }\n *\n * JSON-LD isn't part of Next's `Metadata`; render `resolveSeo(page, defaults).jsonLd`\n * as a `<script type=\"application/ld+json\">` in the page component (see the README).\n *\n * The merge (page-over-site) is delegated to `resolveSeo` (@bettercms-ai/sdk), the same\n * resolver the Astro adapter uses — so every surface stays consistent.\n */\nimport type { Metadata } from \"next\";\nimport { resolveSeo, type SeoInput, type SeoLocation } from \"@bettercms-ai/sdk\";\nimport type { SiteSeoDefaults } from \"@bettercms-ai/types\";\n\n/**\n * `location` with its gaps filled for a self-hosted app: `siteUrl` from `BETTERCMS_SITE_URL`, and\n * `path` from the page's slug (`home` is `/`). An entry from `entrySeoInput` has no slug, so it\n * still needs an explicit `path`.\n */\nfunction withSiteUrlFallback(page: SeoInput, location: SeoLocation): SeoLocation {\n const siteUrl = location.siteUrl || (typeof process !== \"undefined\" ? process.env.BETTERCMS_SITE_URL : undefined);\n const slugPath = page.slug ? (page.slug === \"home\" ? \"/\" : `/${page.slug.replace(/^\\/+/, \"\")}`) : undefined;\n return { siteUrl, path: location.path || slugPath };\n}\n\nlet warnedNoCanonical = false;\n\n/** Once per process, in development only: the Metadata return type has no room for a warning. */\nfunction warnNoCanonical(): void {\n if (warnedNoCanonical || typeof process === \"undefined\" || process.env.NODE_ENV !== \"development\") return;\n warnedNoCanonical = true;\n console.warn(\n \"[@bettercms-ai/next] buildMetadata emitted no canonical or og:url. Pass `location` ({ siteUrl, path }) \" +\n \"or set BETTERCMS_SITE_URL; the hosted renderer always emits both.\",\n );\n}\n\n/**\n * Build a Next.js `Metadata` from a BetterCMS page, layering page meta over site defaults.\n *\n * Pass `location` — `{ siteUrl, path }` — to get a canonical (and `og:url`) on pages that set\n * none of their own. Without it, `BETTERCMS_SITE_URL` plus the page's slug stand in; with\n * neither, both tags are absent and development logs one warning. The hosted renderer always\n * emits them. A `noindex` page gets `robots: { index: false }`.\n */\nexport function buildMetadata(\n page: SeoInput,\n siteDefaults: SiteSeoDefaults = {},\n location: SeoLocation = {},\n): Metadata {\n const seo = resolveSeo(page, siteDefaults, withSiteUrlFallback(page, location));\n if (!seo.canonical) warnNoCanonical();\n return {\n title: seo.title || undefined,\n description: seo.description || undefined,\n robots: seo.noindex ? { index: false } : undefined,\n alternates: seo.canonical ? { canonical: seo.canonical } : undefined,\n openGraph: {\n title: seo.og.title || undefined,\n description: seo.og.description || undefined,\n type: (seo.og.type || \"website\") as \"website\",\n url: seo.og.url || undefined,\n images: seo.og.image ? [{ url: seo.og.image }] : undefined,\n },\n twitter: {\n card: (seo.twitter.card || \"summary\") as \"summary\" | \"summary_large_image\",\n title: seo.twitter.title || undefined,\n description: seo.twitter.description || undefined,\n images: seo.twitter.image ? [seo.twitter.image] : undefined,\n site: seo.twitter.site || undefined,\n },\n };\n}\n","/**\n * @bettercms-ai/next — the BetterCMS adapter for Next.js.\n *\n * Pair with @bettercms-ai/codegen: generate `BetterCMSSchema` from your content models,\n * then `createBetterCMS<BetterCMSSchema>(...)` for typed, cache-aware reads in the App Router.\n */\n\nexport { createBetterCMS } from \"./client.js\";\nexport type { BetterCMSNext, BetterCMSPage } from \"./client.js\";\n\n// SEO (FLO-302): map a page's per-page-over-site SEO into a Next `Metadata` for\n// `generateMetadata`. `resolveSeo` (+ its types) is re-exported for JSON-LD / custom heads.\nexport { buildMetadata } from \"./metadata.js\";\nexport { resolveSeo } from \"@bettercms-ai/sdk\";\nexport type { SeoInput, ResolvedSeo } from \"@bettercms-ai/sdk\";\nexport type { PageMetaJson, SiteSeoDefaults } from \"@bettercms-ai/types\";\nexport type { DeliveredLayout } from \"@bettercms-ai/types\";\n\nexport { BetterCMSError } from \"./types.js\";\nexport type {\n BetterCMSConfig,\n BetterCMSEntry,\n ReadOptions,\n GetEntryOptions,\n ListEntriesOptions,\n EntryList,\n} from \"./types.js\";\n\nexport {\n getContent,\n buildSnapshot,\n writeSnapshot,\n readSnapshot,\n serializeSnapshot,\n parseSnapshot,\n SNAPSHOT_VERSION,\n DEFAULT_SNAPSHOT_FILE,\n} from \"./snapshot.js\";\nexport type { ContentSource, ContentSnapshot } from \"./snapshot.js\";\n\nexport { generateLlmsTxt, llmsTxtRoute, fetchModels } from \"./llms-txt.js\";\nexport type {\n LlmsModel,\n LlmsModelField,\n LlmsTxtOptions,\n LlmsTxtRouteConfig,\n} from \"./llms-txt.js\";\n\nexport { isDraftEnabled, getPreviewToken, BcmsDraftMarker } from \"./preview.js\";\n\n// Draft-mode route-handler factories for the App Router.\nexport {\n createDraftModeRoute,\n createDisableDraftRoute,\n PREVIEW_TOKEN_COOKIE,\n} from \"./draft-route.js\";\nexport type { DraftModeRouteConfig } from \"./draft-route.js\";\n\n// Image URL builder — `import { imageUrlBuilder } from \"@bettercms-ai/next\"`.\nexport { default as imageUrlBuilder, imageUrl } from \"@bettercms-ai/image-url\";\nexport type {\n ImageUrlBuilder,\n ImageSource,\n ImageFormat,\n ImageFit,\n} from \"@bettercms-ai/image-url\";\n\n// Build-time forms reader for the deploy Action's snapshot (server-side).\nexport { readForms, getForm } from \"./forms-read.js\";\nexport type { SnapshotForms } from \"./forms-read.js\";\n\n// Build-time pages reader for the deploy Action's snapshot (server-side). Pair with\n// <BcmsBlocks> to render a page's block_json: readPages()/getPage(slug) → page.blocks.\nexport { readPages, getPage } from \"./pages-read.js\";\nexport type { SnapshotPage } from \"./pages-read.js\";\n\n// Build-time components reader — pass to <BcmsBlocks components={…} /> so `component`\n// blocks resolve their reusable definitions.\nexport { readComponents, getComponent } from \"./components-read.js\";\n\n// <BcmsForm> / <BcmsBlocks> are client components and ship from their own \"use client\"\n// entries so the React Server Components boundary survives bundling:\n// import { BcmsForm } from \"@bettercms-ai/next/form\";\n// import { BcmsBlocks } from \"@bettercms-ai/next/blocks\";\nexport type { BcmsFormProps } from \"./form.js\";\nexport type { BcmsBlocksProps } from \"./blocks.js\";\n\n// <BcmsField> tags an entry field's value so the visual editor binds click-to-edit\n// deterministically. Server-safe (no \"use client\"): import from \"@bettercms-ai/next\".\nexport { BcmsField } from \"./field.js\";\nexport type { BcmsFieldProps } from \"./field.js\";\n\n// Live content + revalidation (mirrors next-sanity defineLive/<SanityLive>).\n// import { BcmsLive } from \"@bettercms-ai/next/live\";\nexport type { BcmsLiveProps } from \"./live.js\";\nexport { defineBetterCMSLive } from \"./live-config.js\";\nexport type { BetterCMSLiveConfig } from \"./live-config.js\";\nexport { createRevalidateRoute } from \"./revalidate-route.js\";\nexport type { RevalidateRouteConfig } from \"./revalidate-route.js\";\n\n// Visual editing overlay (client). import { VisualEditing } from \"@bettercms-ai/next/visual-editing\"\nexport type { VisualEditingProps } from \"./visual-editing.js\";\n","/**\n * Build-time content snapshot — the writer + reader of `bcms-content.json`.\n *\n * Why this exists: a static (`output: \"export\"`) build must resolve all content at\n * build time. If a page instead falls back to a live `cache: \"no-store\"` fetch, its\n * route becomes dynamic and `output: \"export\"` silently drops it — you get an empty\n * `out/`. The fix is a single build-time snapshot the pages read synchronously.\n *\n * The WRITER (`buildSnapshot`/`writeSnapshot`, used by the `bettercms-snapshot` bin)\n * and the READER (`getContent`) share ONE serializer (`serializeSnapshot`/\n * `parseSnapshot`) so the on-disk shape can never drift between the two halves.\n *\n * This is intentionally separate from {@link createBetterCMS}: that stays the live,\n * network-backed client. `getContent` is the snapshot-preferring reader a static\n * site uses. Existing consumers that deliberately rely on the live fallback are\n * unaffected — only `getContent` enforces \"snapshot or bust\".\n */\n\nimport { readFileSync, writeFileSync, mkdirSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport {\n BetterCMSError,\n type BetterCMSConfig,\n type BetterCMSEntry,\n type EntryList,\n type ListEntriesOptions,\n} from \"./types.js\";\nimport { createBetterCMS } from \"./client.js\";\n\n/** Bump when the on-disk shape changes incompatibly — readers reject mismatches. */\nexport const SNAPSHOT_VERSION = 1;\n/** Default snapshot filename, resolved against `process.cwd()`. */\nexport const DEFAULT_SNAPSHOT_FILE = \"bcms-content.json\";\n\n/** The full-site content snapshot. Entries are grouped by model slug so the reader\n * can serve `listEntries(model)` offline without a per-entry model tag. */\nexport interface ContentSnapshot {\n version: number;\n workspace: string;\n generatedAt: string;\n models: Record<string, BetterCMSEntry<unknown>[]>;\n}\n\n// ── Serializer (shared by writer + reader — single source of on-disk shape) ──────\n\n/** Serialize a snapshot to the canonical JSON form written to disk. */\nexport function serializeSnapshot(snapshot: ContentSnapshot): string {\n return JSON.stringify(snapshot, null, 2);\n}\n\n/** Parse + validate a snapshot JSON string. Throws on a version mismatch so a stale\n * snapshot fails loudly rather than feeding the build the wrong shape. */\nexport function parseSnapshot(json: string): ContentSnapshot {\n const parsed = JSON.parse(json) as ContentSnapshot;\n if (parsed.version !== SNAPSHOT_VERSION) {\n throw new BetterCMSError(\n `Unsupported bcms-content.json version ${parsed.version} (expected ${SNAPSHOT_VERSION}). ` +\n `Regenerate it with \"bettercms-snapshot\".`,\n 0,\n \"SNAPSHOT_VERSION_MISMATCH\",\n );\n }\n return parsed;\n}\n\n// ── Disk I/O ─────────────────────────────────────────────────────────────────────\n\n/** Write a snapshot to `path` (relative paths resolve against cwd), creating dirs. */\nexport function writeSnapshot(path: string, snapshot: ContentSnapshot): void {\n const out = resolve(process.cwd(), path);\n mkdirSync(dirname(out), { recursive: true });\n writeFileSync(out, serializeSnapshot(snapshot), \"utf8\");\n}\n\n/** Read + parse a snapshot from `path`. Returns `null` only when the file is absent;\n * a present-but-corrupt/stale file throws (callers must not treat that as \"missing\"). */\nexport function readSnapshot(path: string): ContentSnapshot | null {\n const out = resolve(process.cwd(), path);\n let json: string;\n try {\n json = readFileSync(out, \"utf8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException)?.code === \"ENOENT\") return null;\n throw err;\n }\n return parseSnapshot(json);\n}\n\n// ── Writer: build a snapshot from the live API ────────────────────────────────────\n\n/** Minimal client surface `buildSnapshot` needs — lets tests inject a fake. Kept\n * non-generic so a simple fake (and the live client's matching overload) both fit. */\ntype ListOnly = {\n listEntries(model?: string, opts?: ListEntriesOptions): Promise<EntryList<unknown>>;\n};\n\n/**\n * Page through every model's published entries and assemble a full-site snapshot.\n * `modelSlugs` come from the Management API (`fetchModels`) so the snapshot covers\n * exactly this project's schema. Pass `client` in tests; defaults to the live client.\n */\nexport async function buildSnapshot(opts: {\n config: BetterCMSConfig;\n modelSlugs: string[];\n client?: ListOnly;\n /** Stamped into `generatedAt`; injectable for deterministic tests. */\n now?: string;\n}): Promise<ContentSnapshot> {\n const client = opts.client ?? createBetterCMS(opts.config);\n const models: Record<string, BetterCMSEntry<unknown>[]> = {};\n for (const slug of opts.modelSlugs) {\n const all: BetterCMSEntry<unknown>[] = [];\n let page = 1;\n for (;;) {\n // revalidate:false → bypass any data cache; this is a one-shot build fetch.\n const res = await client.listEntries(slug, { page, perPage: 100, revalidate: false });\n all.push(...res.items);\n if (!res.hasNextPage) break;\n page += 1;\n }\n models[slug] = all;\n }\n return {\n version: SNAPSHOT_VERSION,\n workspace: opts.config.workspace,\n generatedAt: opts.now ?? new Date().toISOString(),\n models,\n };\n}\n\n// ── Reader: getContent (snapshot-preferring, loud on absence) ─────────────────────\n\n/** Snapshot-backed content reader. Async so it can transparently fall back to the\n * live client in preview without changing the call sites. */\nexport interface ContentSource {\n getEntry<TFields = unknown>(slug: string): Promise<BetterCMSEntry<TFields> | null>;\n listEntries<TFields = unknown>(model?: string): Promise<EntryList<TFields>>;\n}\n\n/** `BETTERCMS_PREVIEW` truthy → read live (uncached), never the snapshot. */\nfunction isPreview(): boolean {\n const v = (\n globalThis as { process?: { env?: Record<string, string | undefined> } }\n ).process?.env?.BETTERCMS_PREVIEW;\n return v != null && v !== \"\" && v !== \"0\" && v !== \"false\";\n}\n\n/** Parsed snapshots keyed by resolved path — read+parse once per build process. */\nconst snapshotCache = new Map<string, ContentSnapshot>();\n\n/** Test-only: clear the module-scope snapshot cache between cases. */\nexport function __resetSnapshotCacheForTests(): void {\n snapshotCache.clear();\n}\n\nfunction emptyPage<TFields>(items: BetterCMSEntry<TFields>[]): EntryList<TFields> {\n return {\n items,\n page: 1,\n perPage: items.length,\n totalItems: items.length,\n totalPages: 1,\n hasNextPage: false,\n hasPreviousPage: false,\n };\n}\n\n/**\n * The reader a static site should use. In a normal (export) build it reads the\n * memoized `bcms-content.json` and serves entries from memory. If the snapshot is\n * absent it THROWS a clear, actionable error — the whole point is to turn the old\n * silent empty-`out/` failure into a loud build error. Set `BETTERCMS_PREVIEW=1`\n * for a preview build that reads live instead.\n */\nexport function getContent<\n Schema extends Record<string, unknown> = Record<string, unknown>,\n>(config: BetterCMSConfig, opts: { snapshotPath?: string } = {}): ContentSource {\n const path = opts.snapshotPath ?? DEFAULT_SNAPSHOT_FILE;\n\n if (isPreview()) {\n const live = createBetterCMS<Schema>(config);\n return {\n getEntry: (slug) => live.getEntry(slug, { revalidate: false }),\n listEntries: (model) => live.listEntries(model, { revalidate: false }),\n };\n }\n\n const resolved = resolve(process.cwd(), path);\n function load(): ContentSnapshot {\n const cached = snapshotCache.get(resolved);\n if (cached) return cached;\n const snap = readSnapshot(path);\n if (!snap) {\n throw new BetterCMSError(\n `BetterCMS content snapshot \"${path}\" not found. A static (output: \"export\") build reads ` +\n `content from this snapshot; without it pages fall back to a live no-store fetch, become ` +\n `dynamic routes, and output: \"export\" silently drops them (empty out/). Run ` +\n `\"bettercms-snapshot\" before \"next build\" (make it your build:preview prestep), or set ` +\n `BETTERCMS_PREVIEW=1 to read live in a preview build.`,\n 0,\n \"SNAPSHOT_MISSING\",\n );\n }\n snapshotCache.set(resolved, snap);\n return snap;\n }\n\n return {\n async getEntry<TFields = unknown>(slug: string) {\n const snap = load();\n for (const entries of Object.values(snap.models)) {\n const found = entries.find((e) => e.slug === slug);\n if (found) return found as BetterCMSEntry<TFields>;\n }\n return null;\n },\n async listEntries<TFields = unknown>(model?: string) {\n const snap = load();\n const items = (\n model ? (snap.models[model] ?? []) : Object.values(snap.models).flat()\n ) as BetterCMSEntry<TFields>[];\n return emptyPage(items);\n },\n };\n}\n","/**\n * llms.txt generation — the AI-discovery surface of the deterministic floor.\n *\n * `generateLlmsTxt` is pure (models in → string out), so it is trivially testable and\n * deterministic. `llmsTxtRoute` wraps it as an App Router `route.ts` handler. `fetchModels`\n * pulls the live schema from the Management API for sites that want a self-updating file.\n *\n * Output follows the llmstxt.org convention: an H1 title, a `>` summary, then sections.\n */\n\n/** Minimal field shape needed to describe a model in llms.txt. */\nexport interface LlmsModelField {\n key: string;\n label?: string;\n type: string;\n required?: boolean;\n}\n\n/** Minimal model shape — a subset of the Management API model row. */\nexport interface LlmsModel {\n slug: string;\n name?: string;\n description?: string | null;\n fields: LlmsModelField[];\n}\n\nexport interface LlmsTxtOptions {\n /** H1 title. Default: \"BetterCMS content\". */\n title?: string;\n /** One-line `>` summary under the title. */\n description?: string;\n /** Delivery API base used to render example endpoints. */\n baseUrl?: string;\n /** Workspace slug used in example endpoints. */\n workspace?: string;\n /** Extra free-form lines appended under a \"## Notes\" section. */\n notes?: string[];\n}\n\n// Model name/slug/description and field key/label/type are author/agent-controlled\n// (the same content the sibling codegen package treats as hostile via escapeJsDoc).\n// llms.txt is fed to AI crawlers, so unescaped values could forge headings/blockquotes\n// or break out of code spans — a structure-spoofing / prompt-injection vector.\n\n/** Collapse to a single line — kills newline-based block injection. */\nfunction oneLine(text: string): string {\n return text.replace(/[\\r\\n]+/g, \" \").trim();\n}\n\n/** For text rendered OUTSIDE a code span (titles, descriptions, labels): single-line +\n * escape a leading markdown block-control char so it can't start a heading/list/quote. */\nfunction inlineText(text: string): string {\n return oneLine(text).replace(/^([#>\\-*+=|])/, \"\\\\$1\");\n}\n\n/** For text rendered INSIDE a code span: strip backticks (which would close the span)\n * and newlines. */\nfunction codeSpan(text: string): string {\n return oneLine(text).replace(/`/g, \"\");\n}\n\nfunction fieldLine(f: LlmsModelField): string {\n const req = f.required ? \", required\" : \"\";\n const label = f.label && f.label !== f.key ? ` — ${inlineText(f.label)}` : \"\";\n return ` - \\`${codeSpan(f.key)}\\` (${codeSpan(f.type)}${req})${label}`;\n}\n\n/**\n * Render an llms.txt document describing the available content models. Deterministic:\n * models are sorted by slug; field order is preserved as authored.\n */\nexport function generateLlmsTxt(models: LlmsModel[], opts: LlmsTxtOptions = {}): string {\n const title = opts.title ?? \"BetterCMS content\";\n const sorted = [...models].sort((a, b) =>\n a.slug < b.slug ? -1 : a.slug > b.slug ? 1 : 0,\n );\n\n const lines: string[] = [`# ${inlineText(title)}`, \"\"];\n if (opts.description) {\n lines.push(`> ${inlineText(opts.description)}`, \"\");\n }\n\n const base =\n opts.baseUrl && opts.workspace\n ? `${opts.baseUrl.replace(/\\/+$/, \"\")}/${opts.workspace}/content-entries`\n : undefined;\n\n lines.push(\"## Content models\", \"\");\n if (sorted.length === 0) {\n lines.push(\"_No content models are defined yet._\", \"\");\n }\n for (const model of sorted) {\n const name = model.name ?? model.slug;\n lines.push(`### ${inlineText(name)} (\\`${codeSpan(model.slug)}\\`)`);\n if (model.description) lines.push(\"\", inlineText(model.description));\n if (base) {\n lines.push(\"\", `- List: \\`GET ${base}?model=${codeSpan(model.slug)}\\``);\n lines.push(`- Entry: \\`GET ${base}/{slug}\\``);\n }\n if (model.fields.length) {\n lines.push(\"\", \"Fields:\");\n for (const f of model.fields) lines.push(fieldLine(f));\n }\n lines.push(\"\");\n }\n\n if (opts.notes?.length) {\n lines.push(\"## Notes\", \"\");\n for (const note of opts.notes) lines.push(`- ${inlineText(note)}`);\n lines.push(\"\");\n }\n\n return lines.join(\"\\n\");\n}\n\n// ── Integration SKILL.md ────────────────────────────────────────────────────────\n// A framework-agnostic agent skill (frontmatter + lean body) that teaches an AI how\n// to READ this project's content from the Delivery API. Unlike llms.txt it does NOT\n// dump every field — it points at the live types endpoint so the schema can't go\n// stale, and names content types by slug only. Drop at .claude/skills/<name>/SKILL.md.\n\n/** A content type named in the skill — slug + kind only (no fields). */\nexport interface SkillContentType {\n kind: \"page\" | \"model\";\n slug: string;\n /** \"singleton\" | \"dynamic\" for pages; omitted for models. */\n pageType?: string | null;\n}\n\nexport interface SkillOptions {\n /** Human project name (skill title + description). */\n projectName: string;\n /** Project slug → the skill's kebab-case `name:`. */\n projectSlug: string;\n /** Delivery + management API base, e.g. https://api.bettercms.ai/api/v1. */\n apiUrl: string;\n /** Workspace slug used in the delivery paths. */\n workspace: string;\n /** Where to mint a content:read delivery key. */\n mintUrl: string;\n /** Key-authed live TypeScript types endpoint. */\n typesUrl: string;\n /** This project's content types (pages + models), by slug — no field dump. */\n contentTypes: SkillContentType[];\n}\n\n/**\n * Render a concise, framework-agnostic SKILL.md describing how to read THIS\n * project's content from the BetterCMS Delivery API. Deterministic: content types\n * sorted by slug. Author-controlled strings (project name, slugs, pageType) are\n * injection-escaped, same as {@link generateLlmsTxt}.\n */\nexport type SkillTarget = \"claude\" | \"cursor\" | \"agents\";\n\nexport interface SkillVariant {\n /** The agent/IDE this variant targets. */\n target: SkillTarget;\n /** Human label for a tab/picker. */\n label: string;\n /** Suggested path to save the file, e.g. `.claude/skills/<name>/SKILL.md`. */\n filename: string;\n /** Full file content (target-specific frontmatter + the shared body). */\n content: string;\n}\n\n/** The shared, tool-agnostic instruction body — no frontmatter, no save hint. */\nfunction skillBody(opts: SkillOptions): string {\n const proj = inlineText(opts.projectName);\n const api = opts.apiUrl.replace(/\\/+$/, \"\");\n const deliveryBase = `${api}/delivery/${codeSpan(opts.workspace)}`;\n const sorted = [...opts.contentTypes].sort((a, b) =>\n a.slug < b.slug ? -1 : a.slug > b.slug ? 1 : 0,\n );\n\n const lines: string[] = [\n `# BetterCMS — ${proj}`,\n \"\",\n `${proj}'s content lives in BetterCMS. Read it through the Delivery API with a project ` +\n \"`content:read` key. Pull field shapes live from the types endpoint below — don't hardcode \" +\n \"them, the schema can change.\",\n \"\",\n \"## Auth\",\n \"Send `X-API-Key: <key>` on every read. Mint a long-lived `content:read` key (reads PUBLISHED \" +\n `content, never expires) at ${opts.mintUrl}. For drafts, mint a \\`content:read:draft\\` key ` +\n \"(force-expired to ≤1h), then publish and switch to the long-lived key.\",\n \"\",\n \"## Content types\",\n ];\n if (sorted.length === 0) {\n lines.push(\"_None yet — create pages or models first (e.g. via the BetterCMS MCP)._\");\n } else {\n for (const ct of sorted) {\n const kind =\n ct.kind === \"page\"\n ? `page${ct.pageType ? ` (${codeSpan(ct.pageType)})` : \"\"}`\n : \"model\";\n lines.push(`- \\`${codeSpan(ct.slug)}\\` — ${kind}`);\n }\n }\n lines.push(\n \"\",\n `## Reading (Delivery API · base \\`${deliveryBase}\\`)`,\n \"- Page: `GET .../content/{slug}`\",\n \"- Entries (list): `GET .../content-entries?model={slug}`\",\n \"- Entry: `GET .../content-entries/{slug}`\",\n \"\",\n \"## Typed client\",\n `- Live TypeScript types: \\`GET ${opts.typesUrl}\\` — authoritative field shapes; generate/refresh from here.`,\n \"- `npm i @bettercms-ai/next @bettercms-ai/codegen`, then construct the client. \" +\n \"`baseUrl` + `workspace` are required — there is no `apiUrl`/`endpoint` option:\",\n \"\",\n \"```ts\",\n 'import { createBetterCMS } from \"@bettercms-ai/next\";',\n \"const cms = createBetterCMS<BetterCMSSchema>({\",\n ` baseUrl: \"${api}/delivery\",`,\n ` workspace: \"${codeSpan(opts.workspace)}\",`,\n \" apiKey: process.env.BETTERCMS_API_KEY,\",\n \"});\",\n \"```\",\n \"\",\n \"## Field shapes you'll read\",\n \"Canonical READ shapes the Delivery API returns. Per-field types come from the types \" +\n \"endpoint; these container shapes are stable:\",\n '- **richtext** → `{ html, value: { root: … }, format: \"lexical-…\" }`. Render `html`, ' +\n \"or walk `value.root` for structured rendering.\",\n \"- **image** → `{ url, altText?, width?, height?, id? }` — an object, use `.url` (the \" +\n \"write value is a bare CDN URL string, but reads are normalized to this object).\",\n \"- **array + zones** → `{ nonRepeatable?: { <key>: value }, repeatable?: Array<{ <key>: \" +\n \"value }> }`. `nonRepeatable` is one fixed block; `repeatable` is a list — map over it.\",\n '- **array (primitive)** → a flat list (e.g. `string[]`). `type: \"array\"` alone is ' +\n \"ambiguous — the generated type tells you which.\",\n \"\",\n \"Example entry `fields` (a `sections` zone field + a `tags` primitive array):\",\n \"```jsonc\",\n \"{\",\n ' \"sections\": {',\n ' \"nonRepeatable\": { \"eyebrow\": \"New\", \"heading\": \"Welcome\" },',\n ' \"repeatable\": [{ \"label\": \"Docs\", \"url\": \"/docs\", \"icon\": { \"url\": \"https://cdn…\" } }]',\n \" },\",\n ' \"tags\": [\"alpha\", \"beta\"]',\n \"}\",\n \"```\",\n \"\",\n \"## Live Preview bindings (makes the site visually editable)\",\n \"Generate a bindings module alongside the types and spread it so the dashboard's Live \" +\n \"Preview can edit each field in place:\",\n \"```bash\",\n `BETTERCMS_API_KEY=<key> npx bettercms-codegen --api-url ${api} --bindings-out src/bettercms.bindings.generated.ts`,\n \"```\",\n \"```tsx\",\n 'import { bcms } from \"./bettercms.bindings.generated\";',\n \"// scalar: <h1 {...bcms.<model>.<field>}>{entry.fields.field}</h1>\",\n \"// list item: <article {...bcms.<model>.<arr>.$(i)}><h3 {...bcms.<model>.<arr>.<sub>(i)}>{item.sub}</h3></article>\",\n \"// primitive list:<li {...bcms.<model>.<arr>.value(i)}>{tag}</li>\",\n \"```\",\n \"Bindings emit two inert `data-*` attributes on every build, so spreading them is \" +\n \"always safe.\",\n );\n return lines.join(\"\\n\");\n}\n\nfunction skillDescription(proj: string): string {\n return (\n `Read ${proj}'s content from BetterCMS via the Delivery API — auth, listing and fetching ` +\n \"pages and content entries, pulling live TypeScript types, and the @bettercms-ai/next typed \" +\n \"client. Use whenever fetching, rendering, or typing this project's CMS content.\"\n );\n}\n\n/**\n * Render the integration skill for a specific agent `target`. The instruction body is\n * identical across tools; only the frontmatter (and where you save it) differ:\n * - claude → Claude Code skill (`name` + `description`)\n * - cursor → Cursor `.mdc` rule (`description` + `globs` + `alwaysApply`, \"Agent Requested\")\n * - agents → plain Markdown, no frontmatter (drop into a repo-root `AGENTS.md`)\n */\nexport function generateSkill(opts: SkillOptions, target: SkillTarget = \"claude\"): string {\n const name = `bettercms-${codeSpan(opts.projectSlug)}`;\n const desc = skillDescription(inlineText(opts.projectName));\n const body = skillBody(opts);\n\n let frontmatter = \"\";\n if (target === \"claude\") {\n frontmatter = `---\\nname: ${name}\\ndescription: ${desc}\\n---\\n\\n`;\n } else if (target === \"cursor\") {\n frontmatter = `---\\ndescription: ${desc}\\nglobs:\\nalwaysApply: false\\n---\\n\\n`;\n }\n return `${frontmatter}${body}\\n`;\n}\n\nconst TARGET_META: Record<SkillTarget, { label: string; file: (name: string) => string }> = {\n claude: { label: \"Claude Code\", file: (n) => `.claude/skills/${n}/SKILL.md` },\n cursor: { label: \"Cursor\", file: (n) => `.cursor/rules/${n}.mdc` },\n agents: { label: \"AGENTS.md (generic)\", file: () => \"AGENTS.md\" },\n};\n\n/** Render the skill for every supported agent target — drives a tabbed picker in the UI. */\nexport function generateSkillVariants(opts: SkillOptions): SkillVariant[] {\n const name = `bettercms-${codeSpan(opts.projectSlug)}`;\n return (Object.keys(TARGET_META) as SkillTarget[]).map((target) => ({\n target,\n label: TARGET_META[target].label,\n filename: TARGET_META[target].file(name),\n content: generateSkill(opts, target),\n }));\n}\n\n/** Options for {@link llmsTxtRoute}. Provide one of `models` or `getModels`. */\nexport interface LlmsTxtRouteConfig extends LlmsTxtOptions {\n /** Static model list (e.g. fetched at build time). */\n models?: LlmsModel[];\n /** Dynamic provider — called per request (wrap in your own caching if needed). */\n getModels?: () => Promise<LlmsModel[]> | LlmsModel[];\n /** Cache-Control header value. Default: `public, max-age=3600`. */\n cacheControl?: string;\n}\n\n/**\n * Build an App Router route handler that serves llms.txt as `text/plain`.\n *\n * ```ts\n * // app/llms.txt/route.ts\n * import { llmsTxtRoute } from \"@bettercms-ai/next\";\n * export const GET = llmsTxtRoute({ models, title: \"Acme\", workspace: \"acme\" });\n * ```\n */\nexport function llmsTxtRoute(config: LlmsTxtRouteConfig): () => Promise<Response> {\n const { models, getModels, cacheControl, ...opts } = config;\n return async () => {\n const resolved = getModels ? await getModels() : (models ?? []);\n const body = generateLlmsTxt(resolved, opts);\n return new Response(body, {\n status: 200,\n headers: {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n \"Cache-Control\": cacheControl ?? \"public, max-age=3600\",\n },\n });\n };\n}\n\n/**\n * Fetch content models from the Management API (`GET /management/content/models`).\n * The key is project-scoped server-side, so this returns exactly this site's schema.\n * Dependency-free so it runs in any runtime (Edge route, build script, Node).\n */\nexport async function fetchModels(opts: {\n /** Management API base, e.g. \"https://api.bettercms.ai/api/v1\". */\n apiUrl: string;\n /** A management-scoped key (content:manage). */\n apiKey: string;\n /** Optional fetch override (testing / custom runtime). */\n fetchImpl?: typeof fetch;\n}): Promise<LlmsModel[]> {\n const doFetch = opts.fetchImpl ?? fetch;\n const base = opts.apiUrl.replace(/\\/+$/, \"\");\n const res = await doFetch(`${base}/management/content/models`, {\n headers: { Authorization: `Bearer ${opts.apiKey}`, Accept: \"application/json\" },\n });\n if (!res.ok) {\n throw new Error(`Management API returned ${res.status} ${res.statusText}`);\n }\n const body = (await res.json()) as { data?: LlmsModel[] };\n return (body.data ?? []).map((m) => ({\n slug: m.slug,\n name: m.name,\n description: m.description ?? null,\n fields: m.fields ?? [],\n }));\n}\n","/**\n * Draft-preview helpers. `next/headers` is imported dynamically so this module is safe\n * to load outside a Next.js request scope (tests, build scripts) without throwing.\n */\nimport { createElement, type ReactElement } from \"react\";\n\n/** True when Next.js Draft Mode is enabled for the current request. */\nexport async function isDraftEnabled(): Promise<boolean> {\n const { draftMode } = await import(\"next/headers\");\n const dm = await draftMode();\n return dm.isEnabled;\n}\n\n/**\n * The preview token stored by `createDraftModeRoute`, or null. Pass it to\n * `getEntry(slug, { preview: true, previewToken })` to read drafts.\n */\nexport async function getPreviewToken(): Promise<string | null> {\n const { cookies } = await import(\"next/headers\");\n const jar = await cookies();\n return jar.get(\"bcms-preview-token\")?.value ?? null;\n}\n\n/**\n * `<BcmsDraftMarker />` — put it in the root layout. In draft mode it stamps\n * `<html data-bcms-draft=\"1\">`, which is the ONLY thing the BetterCMS canvas trusts as proof\n * that the frame it loaded is your app rendering a DRAFT. Without it the editor cannot tell a\n * draft render from the published page and falls back to its own approximate renderer.\n *\n * An inline script rather than an attribute on `<html>` itself, so this stays a drop-in: the\n * layout keeps whatever `<html>` it already has, and a server component cannot reach up and\n * add an attribute to its ancestor. Renders nothing outside draft mode.\n */\nexport async function BcmsDraftMarker(): Promise<ReactElement | null> {\n if (!(await isDraftEnabled())) return null;\n return createElement(\"script\", {\n dangerouslySetInnerHTML: {\n __html: 'document.documentElement.setAttribute(\"data-bcms-draft\",\"1\")',\n },\n });\n}\n","/**\n * createDraftModeRoute — an App Router route-handler factory for entering draft\n * preview. Mount it at e.g. `app/api/draft/route.ts`:\n *\n * import { createDraftModeRoute } from \"@bettercms-ai/next\";\n * export const { GET } = createDraftModeRoute({ apiUrl: \"https://api.bettercms.ai\" });\n *\n * Visiting `/api/draft?token=<jwt>&redirect=/path` validates the preview token\n * against the backend (the signature authority), enables Next Draft Mode, stores\n * the token in an httpOnly cookie, and redirects. Reads can then pass the token\n * via `getPreviewToken()` to `getEntry({ preview: true, previewToken })`.\n */\n\nexport const PREVIEW_TOKEN_COOKIE = \"bcms-preview-token\";\n\nexport interface DraftModeRouteConfig {\n /** Backend base, e.g. `https://api.bettercms.ai`. */\n apiUrl: string;\n}\n\n/** Only same-origin relative paths. Blocks \"//evil.com\", \"https://evil.com\", etc. */\nfunction safeRedirectPath(to: string): string {\n return to.startsWith(\"/\") && !to.startsWith(\"//\") ? to : \"/\";\n}\n\n/** Decode a preview-token JWT payload (UNVERIFIED) to read its `entrySlug`. */\nfunction decodeTokenSlug(token: string): string | null {\n try {\n const part = token.split(\".\")[1];\n if (!part) return null;\n const json = JSON.parse(\n Buffer.from(part, \"base64url\").toString(\"utf8\"),\n ) as { entrySlug?: string };\n return json.entrySlug ?? null;\n } catch {\n return null;\n }\n}\n\nexport function createDraftModeRoute(config: DraftModeRouteConfig) {\n const apiUrl = config.apiUrl.replace(/\\/+$/, \"\");\n\n async function GET(request: Request): Promise<Response> {\n const url = new URL(request.url);\n const token = url.searchParams.get(\"token\");\n const redirectTo = url.searchParams.get(\"redirect\") ?? \"/\";\n\n if (!token) return new Response(\"Missing token\", { status: 400 });\n const slug = decodeTokenSlug(token);\n if (!slug) return new Response(\"Malformed token\", { status: 400 });\n\n const res = await fetch(\n `${apiUrl}/api/v1/preview/${encodeURIComponent(slug)}?token=${encodeURIComponent(token)}`,\n );\n if (!res.ok) return new Response(\"Invalid or expired token\", { status: 401 });\n\n const { draftMode, cookies } = await import(\"next/headers\");\n (await draftMode()).enable();\n (await cookies()).set(PREVIEW_TOKEN_COOKIE, token, {\n httpOnly: true,\n sameSite: \"lax\",\n secure: url.protocol === \"https:\",\n path: \"/\",\n maxAge: 60 * 60 * 24,\n });\n\n return Response.redirect(new URL(safeRedirectPath(redirectTo), url.origin), 302);\n }\n\n return { GET };\n}\n\n/** Exit draft mode and clear the preview-token cookie. */\nexport function createDisableDraftRoute() {\n async function GET(request: Request): Promise<Response> {\n const url = new URL(request.url);\n const redirectTo = url.searchParams.get(\"redirect\") ?? \"/\";\n const { draftMode, cookies } = await import(\"next/headers\");\n (await draftMode()).disable();\n (await cookies()).delete(PREVIEW_TOKEN_COOKIE);\n return Response.redirect(new URL(safeRedirectPath(redirectTo), url.origin), 302);\n }\n return { GET };\n}\n","/**\n * Build-time reader for the forms the deploy Action injects into the content\n * snapshot (schema \"bcms-content/v1\": `{ ...collections, forms, turnstileSiteKey }`).\n *\n * This is intentionally separate from `readSnapshot()` — that reads the\n * `@bettercms-ai/next` \"bettercms-snapshot\" format (`{ version, models }`), which is a\n * different file shape. Connected-repo sites on <name>.bettercms.site get the Action\n * snapshot, so forms live here. Server/build-time only (uses node:fs).\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { DeliveryForm } from \"@bettercms-ai/sdk\";\n\nexport interface SnapshotForms {\n forms: DeliveryForm[];\n /** Public Turnstile site key for any form with `turnstileEnabled`, or null. */\n turnstileSiteKey: string | null;\n}\n\n/**\n * Read forms from the Action's `bcms-content.json`. Missing file or no forms →\n * an empty set (a content-only build never throws). `path` resolves against cwd.\n */\nexport function readForms(path = \"bcms-content.json\"): SnapshotForms {\n let raw: string;\n try {\n raw = readFileSync(resolve(process.cwd(), path), \"utf8\");\n } catch {\n return { forms: [], turnstileSiteKey: null };\n }\n const snap = JSON.parse(raw) as { forms?: DeliveryForm[]; turnstileSiteKey?: string | null };\n return { forms: snap.forms ?? [], turnstileSiteKey: snap.turnstileSiteKey ?? null };\n}\n\n/** Find a single form by `id` or `name` from the Action snapshot. */\nexport function getForm(idOrName: string, path?: string): DeliveryForm | undefined {\n return readForms(path).forms.find((f) => f.id === idOrName || f.name === idOrName);\n}\n","/**\n * Build-time reader for the pages the deploy Action injects into the content\n * snapshot (schema \"bcms-content/v1\": `{ ...collections, forms, pages, turnstileSiteKey }`).\n *\n * Sibling to `forms-read.ts`. Connected-repo sites on <name>.bettercms.site get the\n * Action snapshot, so published pages (with their block_json) live here. Render a page\n * with `<BcmsBlocks blocks={page.blocks} forms={readForms().forms} />`. The same data\n * is also available at runtime via `createBetterCMS(...).getPage(slug)`.\n * Server/build-time only (uses node:fs).\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { ContentBlock, PageMetaJson, DeliveredLayout } from \"@bettercms-ai/types\";\n\nexport interface SnapshotPage {\n projectId?: string | null;\n slug: string;\n title: string;\n metaTitle: string | null;\n metaDescription: string | null;\n /** Rich SEO (OG / Twitter / canonical / JSON-LD) — FLO-302. Feed to `buildMetadata`. */\n metaJson: PageMetaJson | null;\n /** The page's block_json — pass to `<BcmsBlocks blocks={...} />`. */\n blocks: ContentBlock[];\n /** Resolved published project/page chrome, shared with runtime Delivery reads. */\n layout?: DeliveredLayout | null;\n updatedAt: string | null;\n publishedAt: string | null;\n}\n\n/**\n * Read published pages from the Action's `bcms-content.json`. Missing file or no\n * pages → an empty list (a pages-less build never throws). `path` resolves against cwd.\n */\nexport function readPages(path = \"bcms-content.json\"): SnapshotPage[] {\n let raw: string;\n try {\n raw = readFileSync(resolve(process.cwd(), path), \"utf8\");\n } catch {\n return [];\n }\n const snap = JSON.parse(raw) as { pages?: SnapshotPage[] };\n return snap.pages ?? [];\n}\n\n/** Find a single published page by `slug` from the Action snapshot. */\nexport function getPage(slug: string, path?: string): SnapshotPage | undefined {\n return readPages(path).find((p) => p.slug === slug);\n}\n","/**\n * Build-time reader for the reusable components the deploy Action injects into the\n * content snapshot (`bcms-content.json` → `components`). Mirrors `forms-read.ts`.\n *\n * Pass the result to `<BcmsBlocks components={readComponents()} … />` so `component`\n * blocks resolve their definitions. Server/build-time only (uses node:fs).\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { DeliveryComponent } from \"@bettercms-ai/types\";\n\n/**\n * Read components from the Action's `bcms-content.json`. Missing file or no\n * components → an empty array (a content-only build never throws).\n */\nexport function readComponents(path = \"bcms-content.json\"): DeliveryComponent[] {\n let raw: string;\n try {\n raw = readFileSync(resolve(process.cwd(), path), \"utf8\");\n } catch {\n return [];\n }\n const snap = JSON.parse(raw) as { components?: DeliveryComponent[] };\n return snap.components ?? [];\n}\n\n/** Find a single component by `id`, `slug`, or `name` from the Action snapshot. */\nexport function getComponent(idOrSlug: string, path?: string): DeliveryComponent | undefined {\n return readComponents(path).find(\n (c) => c.id === idOrSlug || c.slug === idOrSlug || c.name === idOrSlug,\n );\n}\n","/**\n * <BcmsField> — tag an entry field's rendered value with its identity so the\n * BetterCMS visual editor can bind click-to-edit deterministically (mirrors\n * Sanity's `data-sanity` / BaseHub's `data-basehub`). Entry-backed templates\n * hand-render field values (`f.title`, `f.body.html`), so the field `path` is\n * declared here by the author — the delivery payload carries no source-map.\n *\n * Server-safe (no hooks): renders in a Next Server Component. By default it wraps\n * children in a `display:contents` span, invisible to layout/GSAP; pass `as` to\n * carry the attributes on a real element instead.\n *\n * `path` follows the editor grammar: `title` · `hero.title` · `facts[2].label`\n * (dotted keys, at most one array index). For images, put the attributes on the\n * `<img>` itself (`kind=\"image\"` reflection patches `.src`), not on a wrapper:\n * <img src={f.cover.url} data-bcms-field=\"cover\" data-bcms-kind=\"image\" />\n */\nimport type { ElementType, ReactNode } from \"react\";\n\nexport interface BcmsFieldProps {\n /** Field path in the editor grammar, e.g. `title` or `facts[2].label`. */\n path: string;\n /** Kind hint the editor's reflection branches on. Omit for plain text/number. */\n kind?: \"richtext\" | \"image\";\n /** Wrapper element. Defaults to a `display:contents` span. */\n as?: ElementType;\n children: ReactNode;\n}\n\nexport function BcmsField({ path, kind, as, children }: BcmsFieldProps) {\n const Tag = as ?? \"span\";\n return (\n <Tag\n data-bcms-field={path}\n data-bcms-kind={kind}\n style={as ? undefined : { display: \"contents\" }}\n >\n {children}\n </Tag>\n );\n}\n","/**\n * defineBetterCMSLive — build the live SSE URL for `<BcmsLive>` from your config.\n * Server-safe (no React); pass the returned `liveSrc` to the client component.\n */\nexport interface BetterCMSLiveConfig {\n /** Backend base, e.g. `https://api.bettercms.ai`. */\n apiUrl: string;\n workspace: string;\n /** A content:read key — exposed to the browser via the SSE URL query. */\n apiKey: string;\n /**\n * Reference hydration depth for the pushed document. Default 1, matching the\n * delivery API. Set 0 when you only render top-level fields — a smaller doc is\n * a faster frame.\n */\n depth?: 0 | 1 | 2;\n /**\n * Stream draft autosaves too, so a preview surface repaints as the editor types.\n * Requires a `content:read:draft` key; the server ignores the flag for any other\n * key rather than failing the connection. Never enable this on a public site —\n * the key it needs can read unpublished content.\n */\n drafts?: boolean;\n}\n\nexport function defineBetterCMSLive(config: BetterCMSLiveConfig): { liveSrc: string } {\n const base = config.apiUrl.replace(/\\/+$/, \"\");\n const q = new URLSearchParams({ key: config.apiKey });\n if (config.depth !== undefined) q.set(\"depth\", String(config.depth));\n if (config.drafts) q.set(\"drafts\", \"1\");\n const liveSrc = `${base}/api/v1/delivery/${config.workspace}/live?${q}`;\n return { liveSrc };\n}\n","/**\n * createRevalidateRoute — App Router POST handler that receives the backend's\n * revalidation webhook and calls `revalidateTag()` for each affected tag. This is\n * the production live path (publish → backend webhook → revalidate ISR cache).\n *\n * import { createRevalidateRoute } from \"@bettercms-ai/next\";\n * export const { POST } = createRevalidateRoute({ secret: process.env.BCMS_REVALIDATE_SECRET });\n *\n * When `secret` is set, the `X-BetterCMS-Signature` HMAC-SHA256 header is verified\n * against the raw body (the same secret configured on the project in the dashboard).\n */\nimport { createHmac, timingSafeEqual } from \"node:crypto\";\n\nexport interface RevalidateRouteConfig {\n /** Shared secret matching the project's revalidation webhook secret. */\n secret?: string;\n}\n\nfunction safeEqual(a: string, b: string): boolean {\n const ab = Buffer.from(a);\n const bb = Buffer.from(b);\n return ab.length === bb.length && timingSafeEqual(ab, bb);\n}\n\nexport function createRevalidateRoute(config: RevalidateRouteConfig = {}) {\n async function POST(request: Request): Promise<Response> {\n const body = await request.text();\n\n if (config.secret) {\n const provided = request.headers.get(\"x-bettercms-signature\") ?? \"\";\n const expected = `sha256=${createHmac(\"sha256\", config.secret).update(body).digest(\"hex\")}`;\n if (!safeEqual(provided, expected)) {\n return new Response(\"Invalid signature\", { status: 401 });\n }\n }\n\n let payload: { data?: { tags?: string[] } };\n try {\n payload = JSON.parse(body);\n } catch {\n return new Response(\"Invalid JSON\", { status: 400 });\n }\n\n const tags = payload.data?.tags ?? [];\n const { revalidateTag } = await import(\"next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AAK,CAAC;AAAA,EAClD;AAEA,SAAO,EAAE,KAAK;AAChB;","names":["url","resolveSeo","default","readFileSync","resolve","readFileSync","resolve","readFileSync","resolve"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bettercms-ai/next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The BetterCMS adapter for Next.js — typed, cache-aware content reads (getEntry/listEntries), draft preview, build-time content snapshot, and llms.txt generation for the App Router. The /blocks, /form, /field, /search and /visual-editing entries are framework-free React and work in any React app (see the React+TS starter), which is why `next` is an OPTIONAL peer.",
|
|
6
6
|
"bin": {
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@bettercms-ai/image-url": "^0.3.0",
|
|
62
|
-
"@bettercms-ai/sdk": "^1.
|
|
62
|
+
"@bettercms-ai/sdk": "^1.20.0",
|
|
63
63
|
"@bettercms-ai/types": "^1.11.0",
|
|
64
|
-
"@bettercms-ai/ui": "^0.
|
|
65
|
-
"@bettercms-ai/richtext": "^0.
|
|
64
|
+
"@bettercms-ai/ui": "^0.7.0",
|
|
65
|
+
"@bettercms-ai/richtext": "^0.3.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"next": ">=14",
|