@bettercms-ai/next 0.5.2
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 +223 -0
- package/dist/bettercms-snapshot.js +292 -0
- package/dist/bettercms-snapshot.js.map +1 -0
- package/dist/blocks.d.ts +36 -0
- package/dist/blocks.js +496 -0
- package/dist/blocks.js.map +1 -0
- package/dist/form.d.ts +28 -0
- package/dist/form.js +203 -0
- package/dist/form.js.map +1 -0
- package/dist/index.d.ts +516 -0
- package/dist/index.js +583 -0
- package/dist/index.js.map +1 -0
- package/dist/live.d.ts +15 -0
- package/dist/live.js +27 -0
- package/dist/live.js.map +1 -0
- package/dist/search.d.ts +32 -0
- package/dist/search.js +111 -0
- package/dist/search.js.map +1 -0
- package/dist/visual-editing.d.ts +7 -0
- package/dist/visual-editing.js +35 -0
- package/dist/visual-editing.js.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +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/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, 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 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 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}\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 publishedAt: publishedAt ?? null,\n updatedAt: entry.updatedAt ?? null,\n };\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 } from \"@bettercms-ai/sdk\";\nimport type { SiteSeoDefaults } from \"@bettercms-ai/types\";\n\n/** Build a Next.js `Metadata` from a BetterCMS page, layering page meta over site defaults. */\nexport function buildMetadata(page: SeoInput, siteDefaults: SiteSeoDefaults = {}): Metadata {\n const seo = resolveSeo(page, siteDefaults);\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\";\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 } 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// 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 attributes only when the platform builds with `BCMS_ANNOTATE` (preview \" +\n \"builds); production ships nothing extra, so spreading them is 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 */\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 * 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 } from \"@bettercms-ai/types\";\n\nexport interface SnapshotPage {\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 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 * 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\nexport function defineBetterCMSLive(config: BetterCMSLiveConfig): { liveSrc: string } {\n const base = config.apiUrl.replace(/\\/+$/, \"\");\n const liveSrc = `${base}/api/v1/delivery/${config.workspace}/live?key=${encodeURIComponent(config.apiKey)}`;\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,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;;;ACgCA,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AA+B3B,SAAS,aAAa,QAAwB;AAC5C,MAAI,WAAW,IAAK,QAAO;AAC3B,MAAI,WAAW,IAAK,QAAO;AAC3B,MAAI,WAAW,IAAK,QAAO;AAC3B,MAAI,WAAW,IAAK,QAAO;AAC3B,MAAI,WAAW,IAAK,QAAO;AAC3B,SAAO;AACT;AAKA,SAAS,SAAkB,KAAwC;AACjE,SAAO;AAAA,IACL,MAAM,IAAI;AAAA,IACV,QAAQ,IAAI;AAAA,IACZ,QAAQ,IAAI;AAAA,IACZ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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"]}
|
package/dist/live.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface BcmsLiveProps {
|
|
2
|
+
/** Live SSE URL, e.g. from `defineBetterCMSLive().liveSrc`. */
|
|
3
|
+
src: string;
|
|
4
|
+
/** Refresh the route on each change event. Default true. */
|
|
5
|
+
refreshOnChange?: boolean;
|
|
6
|
+
/** Optional callback for custom handling (e.g. targeted revalidation). */
|
|
7
|
+
onChange?: (event: {
|
|
8
|
+
type: string;
|
|
9
|
+
slug: string;
|
|
10
|
+
tags: string[];
|
|
11
|
+
}) => void;
|
|
12
|
+
}
|
|
13
|
+
declare function BcmsLive({ src, refreshOnChange, onChange }: BcmsLiveProps): null;
|
|
14
|
+
|
|
15
|
+
export { BcmsLive, type BcmsLiveProps };
|
package/dist/live.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/live.tsx
|
|
5
|
+
import { useEffect } from "react";
|
|
6
|
+
import { useRouter } from "next/navigation";
|
|
7
|
+
function BcmsLive({ src, refreshOnChange = true, onChange }) {
|
|
8
|
+
const router = useRouter();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const es = new EventSource(src);
|
|
11
|
+
es.addEventListener("change", (e) => {
|
|
12
|
+
if (onChange) {
|
|
13
|
+
try {
|
|
14
|
+
onChange(JSON.parse(e.data));
|
|
15
|
+
} catch {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (refreshOnChange) router.refresh();
|
|
19
|
+
});
|
|
20
|
+
return () => es.close();
|
|
21
|
+
}, [src, refreshOnChange, onChange, router]);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
BcmsLive
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=live.js.map
|
package/dist/live.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/live.tsx"],"sourcesContent":["\"use client\";\n/**\n * <BcmsLive> — subscribes to the BetterCMS delivery live SSE stream and refreshes\n * the App Router on every content change, so edits appear without a manual\n * reload (dev + draft preview). Ships from its own \"use client\" entry.\n *\n * import { BcmsLive } from \"@bettercms-ai/next/live\";\n * import { defineBetterCMSLive } from \"@bettercms-ai/next\";\n * const { liveSrc } = defineBetterCMSLive({ apiUrl, workspace, apiKey });\n * // in layout.tsx: <BcmsLive src={liveSrc} />\n *\n * `src` embeds a content:read key as a query param because browser EventSource\n * cannot send headers — use a read-only key.\n */\nimport { useEffect } from \"react\";\nimport { useRouter } from \"next/navigation\";\n\nexport interface BcmsLiveProps {\n /** Live SSE URL, e.g. from `defineBetterCMSLive().liveSrc`. */\n src: string;\n /** Refresh the route on each change event. Default true. */\n refreshOnChange?: boolean;\n /** Optional callback for custom handling (e.g. targeted revalidation). */\n onChange?: (event: { type: string; slug: string; tags: string[] }) => void;\n}\n\nexport function BcmsLive({ src, refreshOnChange = true, onChange }: BcmsLiveProps) {\n const router = useRouter();\n useEffect(() => {\n const es = new EventSource(src);\n es.addEventListener(\"change\", (e) => {\n if (onChange) {\n try {\n onChange(JSON.parse((e as MessageEvent).data));\n } catch {\n /* ignore malformed */\n }\n }\n if (refreshOnChange) router.refresh();\n });\n return () => es.close();\n }, [src, refreshOnChange, onChange, router]);\n return null;\n}\n"],"mappings":";;;;AAcA,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAWnB,SAAS,SAAS,EAAE,KAAK,kBAAkB,MAAM,SAAS,GAAkB;AACjF,QAAM,SAAS,UAAU;AACzB,YAAU,MAAM;AACd,UAAM,KAAK,IAAI,YAAY,GAAG;AAC9B,OAAG,iBAAiB,UAAU,CAAC,MAAM;AACnC,UAAI,UAAU;AACZ,YAAI;AACF,mBAAS,KAAK,MAAO,EAAmB,IAAI,CAAC;AAAA,QAC/C,QAAQ;AAAA,QAER;AAAA,MACF;AACA,UAAI,gBAAiB,QAAO,QAAQ;AAAA,IACtC,CAAC;AACD,WAAO,MAAM,GAAG,MAAM;AAAA,EACxB,GAAG,CAAC,KAAK,iBAAiB,UAAU,MAAM,CAAC;AAC3C,SAAO;AACT;","names":[]}
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { SearchHit } from '@bettercms-ai/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* <BcmsSearch> — an instant, typo-tolerant site-search box for React/Next.
|
|
6
|
+
*
|
|
7
|
+
* Debounced search-as-you-type against the public delivery search endpoint (via
|
|
8
|
+
* `@bettercms-ai/sdk`'s `search`), rendering a dropdown of results under the input.
|
|
9
|
+
* No API key — `project` (from the dashboard's Site Search settings) is the only
|
|
10
|
+
* scope. All markup is unstyled and `bcms-search-*` class-driven, so the host
|
|
11
|
+
* site owns the look. Mirrors <BcmsForm>.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
interface BcmsSearchProps {
|
|
15
|
+
/** The project id (from Site Search settings). */
|
|
16
|
+
project: string;
|
|
17
|
+
/** API origin. Defaults to the SDK default (https://api.bettercms.ai). */
|
|
18
|
+
apiBase?: string;
|
|
19
|
+
/** Placeholder for the input. */
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
/** Max results, 1–20 (default 8). */
|
|
22
|
+
limit?: number;
|
|
23
|
+
/** Debounce in ms (default 200). */
|
|
24
|
+
debounceMs?: number;
|
|
25
|
+
/** Class for the wrapper; inner elements use `bcms-search-*` classes. */
|
|
26
|
+
className?: string;
|
|
27
|
+
/** Called when a result is chosen; return false to suppress the default navigation. */
|
|
28
|
+
onSelect?: (hit: SearchHit) => boolean | void;
|
|
29
|
+
}
|
|
30
|
+
declare function BcmsSearch({ project, apiBase, placeholder, limit, debounceMs, className, onSelect, }: BcmsSearchProps): ReactElement;
|
|
31
|
+
|
|
32
|
+
export { BcmsSearch, type BcmsSearchProps };
|
package/dist/search.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/search.tsx
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
import { search } from "@bettercms-ai/sdk";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
function BcmsSearch({
|
|
9
|
+
project,
|
|
10
|
+
apiBase,
|
|
11
|
+
placeholder = "Search\u2026",
|
|
12
|
+
limit,
|
|
13
|
+
debounceMs = 200,
|
|
14
|
+
className,
|
|
15
|
+
onSelect
|
|
16
|
+
}) {
|
|
17
|
+
const [query, setQuery] = useState("");
|
|
18
|
+
const [hits, setHits] = useState([]);
|
|
19
|
+
const [open, setOpen] = useState(false);
|
|
20
|
+
const [active, setActive] = useState(-1);
|
|
21
|
+
const wrap = useRef(null);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const q = query.trim();
|
|
24
|
+
if (q.length < 2) {
|
|
25
|
+
setHits([]);
|
|
26
|
+
setOpen(false);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const ctrl = new AbortController();
|
|
30
|
+
const t = setTimeout(() => {
|
|
31
|
+
search({ project, q, limit, baseUrl: apiBase, signal: ctrl.signal }).then((r) => {
|
|
32
|
+
setHits(r);
|
|
33
|
+
setActive(-1);
|
|
34
|
+
setOpen(true);
|
|
35
|
+
});
|
|
36
|
+
}, debounceMs);
|
|
37
|
+
return () => {
|
|
38
|
+
clearTimeout(t);
|
|
39
|
+
ctrl.abort();
|
|
40
|
+
};
|
|
41
|
+
}, [query, project, apiBase, limit, debounceMs]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const onClick = (e) => {
|
|
44
|
+
if (wrap.current && !wrap.current.contains(e.target)) setOpen(false);
|
|
45
|
+
};
|
|
46
|
+
document.addEventListener("click", onClick);
|
|
47
|
+
return () => document.removeEventListener("click", onClick);
|
|
48
|
+
}, []);
|
|
49
|
+
const choose = (hit) => {
|
|
50
|
+
if (onSelect?.(hit) === false) return;
|
|
51
|
+
window.location.href = hit.url;
|
|
52
|
+
};
|
|
53
|
+
const onKeyDown = (e) => {
|
|
54
|
+
if (!open || !hits.length) return;
|
|
55
|
+
if (e.key === "ArrowDown") {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
setActive((i) => (i + 1) % hits.length);
|
|
58
|
+
} else if (e.key === "ArrowUp") {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
setActive((i) => (i - 1 + hits.length) % hits.length);
|
|
61
|
+
} else if (e.key === "Enter" && active >= 0) {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
choose(hits[active]);
|
|
64
|
+
} else if (e.key === "Escape") {
|
|
65
|
+
setOpen(false);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return /* @__PURE__ */ jsxs("div", { ref: wrap, className: `bcms-search${className ? ` ${className}` : ""}`, style: { position: "relative" }, children: [
|
|
69
|
+
/* @__PURE__ */ jsx(
|
|
70
|
+
"input",
|
|
71
|
+
{
|
|
72
|
+
type: "search",
|
|
73
|
+
className: "bcms-search-input",
|
|
74
|
+
placeholder,
|
|
75
|
+
"aria-label": "Search this site",
|
|
76
|
+
value: query,
|
|
77
|
+
onChange: (e) => setQuery(e.target.value),
|
|
78
|
+
onKeyDown,
|
|
79
|
+
onFocus: () => hits.length && setOpen(true)
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
open && /* @__PURE__ */ jsx("div", { className: "bcms-search-results", role: "listbox", children: hits.length === 0 ? /* @__PURE__ */ jsx("div", { className: "bcms-search-empty", children: "No results" }) : hits.map((hit, i) => /* @__PURE__ */ jsxs(
|
|
83
|
+
"a",
|
|
84
|
+
{
|
|
85
|
+
href: hit.url,
|
|
86
|
+
role: "option",
|
|
87
|
+
"aria-selected": i === active,
|
|
88
|
+
className: `bcms-search-hit${i === active ? " is-active" : ""}`,
|
|
89
|
+
onClick: (e) => {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
choose(hit);
|
|
92
|
+
},
|
|
93
|
+
children: [
|
|
94
|
+
/* @__PURE__ */ jsx("span", { className: "bcms-search-title", children: hit.title }),
|
|
95
|
+
hit.snippet && /* @__PURE__ */ jsx(
|
|
96
|
+
"span",
|
|
97
|
+
{
|
|
98
|
+
className: "bcms-search-snippet",
|
|
99
|
+
dangerouslySetInnerHTML: { __html: hit.snippet }
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
`${hit.type}:${hit.slug}`
|
|
105
|
+
)) })
|
|
106
|
+
] });
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
BcmsSearch
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/search.tsx"],"sourcesContent":["\"use client\";\n\n/**\n * <BcmsSearch> — an instant, typo-tolerant site-search box for React/Next.\n *\n * Debounced search-as-you-type against the public delivery search endpoint (via\n * `@bettercms-ai/sdk`'s `search`), rendering a dropdown of results under the input.\n * No API key — `project` (from the dashboard's Site Search settings) is the only\n * scope. All markup is unstyled and `bcms-search-*` class-driven, so the host\n * site owns the look. Mirrors <BcmsForm>.\n */\n\nimport { useEffect, useRef, useState, type ReactElement } from \"react\";\nimport { search, type SearchHit } from \"@bettercms-ai/sdk\";\n\nexport interface BcmsSearchProps {\n /** The project id (from Site Search settings). */\n project: string;\n /** API origin. Defaults to the SDK default (https://api.bettercms.ai). */\n apiBase?: string;\n /** Placeholder for the input. */\n placeholder?: string;\n /** Max results, 1–20 (default 8). */\n limit?: number;\n /** Debounce in ms (default 200). */\n debounceMs?: number;\n /** Class for the wrapper; inner elements use `bcms-search-*` classes. */\n className?: string;\n /** Called when a result is chosen; return false to suppress the default navigation. */\n onSelect?: (hit: SearchHit) => boolean | void;\n}\n\nexport function BcmsSearch({\n project,\n apiBase,\n placeholder = \"Search…\",\n limit,\n debounceMs = 200,\n className,\n onSelect,\n}: BcmsSearchProps): ReactElement {\n const [query, setQuery] = useState(\"\");\n const [hits, setHits] = useState<SearchHit[]>([]);\n const [open, setOpen] = useState(false);\n const [active, setActive] = useState(-1);\n const wrap = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const q = query.trim();\n if (q.length < 2) {\n setHits([]);\n setOpen(false);\n return;\n }\n const ctrl = new AbortController();\n const t = setTimeout(() => {\n search({ project, q, limit, baseUrl: apiBase, signal: ctrl.signal }).then((r) => {\n setHits(r);\n setActive(-1);\n setOpen(true);\n });\n }, debounceMs);\n return () => {\n clearTimeout(t);\n ctrl.abort();\n };\n }, [query, project, apiBase, limit, debounceMs]);\n\n // Close on outside click.\n useEffect(() => {\n const onClick = (e: MouseEvent) => {\n if (wrap.current && !wrap.current.contains(e.target as Node)) setOpen(false);\n };\n document.addEventListener(\"click\", onClick);\n return () => document.removeEventListener(\"click\", onClick);\n }, []);\n\n const choose = (hit: SearchHit) => {\n if (onSelect?.(hit) === false) return;\n window.location.href = hit.url;\n };\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (!open || !hits.length) return;\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n setActive((i) => (i + 1) % hits.length);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n setActive((i) => (i - 1 + hits.length) % hits.length);\n } else if (e.key === \"Enter\" && active >= 0) {\n e.preventDefault();\n choose(hits[active]);\n } else if (e.key === \"Escape\") {\n setOpen(false);\n }\n };\n\n return (\n <div ref={wrap} className={`bcms-search${className ? ` ${className}` : \"\"}`} style={{ position: \"relative\" }}>\n <input\n type=\"search\"\n className=\"bcms-search-input\"\n placeholder={placeholder}\n aria-label=\"Search this site\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n onKeyDown={onKeyDown}\n onFocus={() => hits.length && setOpen(true)}\n />\n {open && (\n <div className=\"bcms-search-results\" role=\"listbox\">\n {hits.length === 0 ? (\n <div className=\"bcms-search-empty\">No results</div>\n ) : (\n hits.map((hit, i) => (\n <a\n key={`${hit.type}:${hit.slug}`}\n href={hit.url}\n role=\"option\"\n aria-selected={i === active}\n className={`bcms-search-hit${i === active ? \" is-active\" : \"\"}`}\n onClick={(e) => {\n e.preventDefault();\n choose(hit);\n }}\n >\n <span className=\"bcms-search-title\">{hit.title}</span>\n {hit.snippet && (\n <span\n className=\"bcms-search-snippet\"\n dangerouslySetInnerHTML={{ __html: hit.snippet }}\n />\n )}\n </a>\n ))\n )}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;AAYA,SAAS,WAAW,QAAQ,gBAAmC;AAC/D,SAAS,cAA8B;AAuFjC,cAgBQ,YAhBR;AApEC,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA;AACF,GAAkC;AAChC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,EAAE;AACrC,QAAM,CAAC,MAAM,OAAO,IAAI,SAAsB,CAAC,CAAC;AAChD,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AACtC,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,EAAE;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Defaults to https://dashboard.bettercms.ai. */
|
|
3
|
+
studioUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
declare function VisualEditing({ studioUrl }: VisualEditingProps): null;
|
|
6
|
+
|
|
7
|
+
export { VisualEditing, type VisualEditingProps };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/visual-editing.tsx
|
|
5
|
+
import { useEffect } from "react";
|
|
6
|
+
import { decodeStega } from "@bettercms-ai/sdk";
|
|
7
|
+
function editHref(studioUrl, p) {
|
|
8
|
+
const base = studioUrl.replace(/\/+$/, "");
|
|
9
|
+
const section = p.type === "page" ? "pages" : "content";
|
|
10
|
+
return `${base}/${section}/${encodeURIComponent(p.id)}?field=${encodeURIComponent(p.field)}`;
|
|
11
|
+
}
|
|
12
|
+
function VisualEditing({ studioUrl = "https://dashboard.bettercms.ai" }) {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
function onClick(e) {
|
|
15
|
+
if (!e.altKey) return;
|
|
16
|
+
const text = e.target?.textContent;
|
|
17
|
+
if (!text) return;
|
|
18
|
+
const decoded = decodeStega(text);
|
|
19
|
+
if (!decoded) return;
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
window.open(editHref(studioUrl, decoded.payload), "_blank", "noopener");
|
|
22
|
+
}
|
|
23
|
+
document.addEventListener("click", onClick, true);
|
|
24
|
+
document.documentElement.dataset.bcmsVisualEditing = "on";
|
|
25
|
+
return () => {
|
|
26
|
+
document.removeEventListener("click", onClick, true);
|
|
27
|
+
delete document.documentElement.dataset.bcmsVisualEditing;
|
|
28
|
+
};
|
|
29
|
+
}, [studioUrl]);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
VisualEditing
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=visual-editing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/visual-editing.tsx"],"sourcesContent":["\"use client\";\n/**\n * <VisualEditing> — click-to-edit overlay for draft preview. Decodes the\n * invisible stega provenance embedded in draft string values and, on Alt+Click,\n * opens the matching dashboard editor. Render it only in draft mode.\n *\n * import { VisualEditing } from \"@bettercms-ai/next/visual-editing\";\n * {isDraft && <VisualEditing studioUrl=\"https://dashboard.bettercms.ai\" />}\n */\nimport { useEffect } from \"react\";\nimport { decodeStega, type StegaPayload } from \"@bettercms-ai/sdk\";\n\nexport interface VisualEditingProps {\n /** Dashboard base for deep links. Defaults to https://dashboard.bettercms.ai. */\n studioUrl?: string;\n}\n\nfunction editHref(studioUrl: string, p: StegaPayload): string {\n const base = studioUrl.replace(/\\/+$/, \"\");\n const section = p.type === \"page\" ? \"pages\" : \"content\";\n return `${base}/${section}/${encodeURIComponent(p.id)}?field=${encodeURIComponent(p.field)}`;\n}\n\nexport function VisualEditing({ studioUrl = \"https://dashboard.bettercms.ai\" }: VisualEditingProps) {\n useEffect(() => {\n function onClick(e: MouseEvent) {\n if (!e.altKey) return;\n const text = (e.target as HTMLElement | null)?.textContent;\n if (!text) return;\n const decoded = decodeStega(text);\n if (!decoded) return;\n e.preventDefault();\n window.open(editHref(studioUrl, decoded.payload), \"_blank\", \"noopener\");\n }\n document.addEventListener(\"click\", onClick, true);\n document.documentElement.dataset.bcmsVisualEditing = \"on\";\n return () => {\n document.removeEventListener(\"click\", onClick, true);\n delete document.documentElement.dataset.bcmsVisualEditing;\n };\n }, [studioUrl]);\n return null;\n}\n"],"mappings":";;;;AASA,SAAS,iBAAiB;AAC1B,SAAS,mBAAsC;AAO/C,SAAS,SAAS,WAAmB,GAAyB;AAC5D,QAAM,OAAO,UAAU,QAAQ,QAAQ,EAAE;AACzC,QAAM,UAAU,EAAE,SAAS,SAAS,UAAU;AAC9C,SAAO,GAAG,IAAI,IAAI,OAAO,IAAI,mBAAmB,EAAE,EAAE,CAAC,UAAU,mBAAmB,EAAE,KAAK,CAAC;AAC5F;AAEO,SAAS,cAAc,EAAE,YAAY,iCAAiC,GAAuB;AAClG,YAAU,MAAM;AACd,aAAS,QAAQ,GAAe;AAC9B,UAAI,CAAC,EAAE,OAAQ;AACf,YAAM,OAAQ,EAAE,QAA+B;AAC/C,UAAI,CAAC,KAAM;AACX,YAAM,UAAU,YAAY,IAAI;AAChC,UAAI,CAAC,QAAS;AACd,QAAE,eAAe;AACjB,aAAO,KAAK,SAAS,WAAW,QAAQ,OAAO,GAAG,UAAU,UAAU;AAAA,IACxE;AACA,aAAS,iBAAiB,SAAS,SAAS,IAAI;AAChD,aAAS,gBAAgB,QAAQ,oBAAoB;AACrD,WAAO,MAAM;AACX,eAAS,oBAAoB,SAAS,SAAS,IAAI;AACnD,aAAO,SAAS,gBAAgB,QAAQ;AAAA,IAC1C;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AACd,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bettercms-ai/next",
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"type": "module",
|
|
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.",
|
|
6
|
+
"bin": {
|
|
7
|
+
"bettercms-snapshot": "./dist/bettercms-snapshot.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./form": {
|
|
20
|
+
"types": "./dist/form.d.ts",
|
|
21
|
+
"import": "./dist/form.js",
|
|
22
|
+
"default": "./dist/form.js"
|
|
23
|
+
},
|
|
24
|
+
"./search": {
|
|
25
|
+
"types": "./dist/search.d.ts",
|
|
26
|
+
"import": "./dist/search.js",
|
|
27
|
+
"default": "./dist/search.js"
|
|
28
|
+
},
|
|
29
|
+
"./blocks": {
|
|
30
|
+
"types": "./dist/blocks.d.ts",
|
|
31
|
+
"import": "./dist/blocks.js",
|
|
32
|
+
"default": "./dist/blocks.js"
|
|
33
|
+
},
|
|
34
|
+
"./live": {
|
|
35
|
+
"types": "./dist/live.d.ts",
|
|
36
|
+
"import": "./dist/live.js",
|
|
37
|
+
"default": "./dist/live.js"
|
|
38
|
+
},
|
|
39
|
+
"./visual-editing": {
|
|
40
|
+
"types": "./dist/visual-editing.d.ts",
|
|
41
|
+
"import": "./dist/visual-editing.js",
|
|
42
|
+
"default": "./dist/visual-editing.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist",
|
|
47
|
+
"README.md"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"build": "tsup",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"test:watch": "vitest"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@bettercms-ai/image-url": "^0.1.0",
|
|
57
|
+
"@bettercms-ai/sdk": "^1.5.0",
|
|
58
|
+
"@bettercms-ai/types": "^1.4.0",
|
|
59
|
+
"@bettercms-ai/ui": "^0.3.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"next": ">=14",
|
|
63
|
+
"react": ">=18"
|
|
64
|
+
},
|
|
65
|
+
"peerDependenciesMeta": {
|
|
66
|
+
"next": {
|
|
67
|
+
"optional": false
|
|
68
|
+
},
|
|
69
|
+
"react": {
|
|
70
|
+
"optional": true
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@types/node": "^20",
|
|
75
|
+
"@types/react": "^19.0.0",
|
|
76
|
+
"next": "^15.0.0",
|
|
77
|
+
"react": "^19.0.0",
|
|
78
|
+
"tsup": "^8.5.1",
|
|
79
|
+
"typescript": "^5",
|
|
80
|
+
"vitest": "^4.1.4"
|
|
81
|
+
},
|
|
82
|
+
"publishConfig": {
|
|
83
|
+
"registry": "https://registry.npmjs.org/",
|
|
84
|
+
"access": "public"
|
|
85
|
+
}
|
|
86
|
+
}
|