@cmssy/next

中文文档
19.30.0发布于 2026/11/06MITTypeScriptESM + CJS构建来源已验证近 30 天下载 6166

Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)

原始使用文档
文档目录9 节
  1. Render every page
  2. Let the editor frame your site
  3. Draft preview
  4. Cache, and expire it on publish
  5. Edit-mode CSP
  6. Localized navigation (path prefix)
  7. Exports
  8. Versioning: this package, not the API
  9. License

@cmssy/next

Next.js (App Router) bindings for a cmssy headless site. One catch-all route renders your published cmssy content with local block components, with live edit-mode preview built in. Pairs with @cmssy/react (blocks + data).

pnpm add @cmssy/next @cmssy/react

Render every page

// app/[[...path]]/page.tsx
import { createCmssyPage } from "@cmssy/next/server";
import { cmssy } from "@/cmssy/config";
import { blocks } from "@/cmssy/blocks";
import { CmssyEditor } from "@/cmssy/editor";

export default createCmssyPage(cmssy, blocks, { editor: CmssyEditor });
// cmssy/config.ts
import { defineCmssyConfig } from "@cmssy/next";

// defineCmssyConfig validates the required env vars and throws a clear error if
// any is missing - never mask them with `?? ""` (an empty org/slug builds a
// broken delivery URL like `/public//graphql`).
export const cmssy = defineCmssyConfig({
  org: process.env.CMSSY_ORG_SLUG,
  workspaceSlug: process.env.CMSSY_WORKSPACE_SLUG,
  draftSecret: process.env.CMSSY_DRAFT_SECRET, // edit-mode preview handshake
  // apiUrl + editorOrigin default to cmssy cloud; set them only for self-host/staging.
  // Locales come from the workspace site config - no need to repeat them here.
});

createCmssyPage fetches the published page for the request path and renders it; an unpublished page answers 404. It does not handle the editor - that needs the edit route and proxy below. A published build does not require editorOrigin.

Let the editor frame your site

The cmssy editor frames the page's own URL with ?cmssyEdit=1&cmssySecret=<draft secret>. The proxy verifies the secret and rewrites that request to /cmssy-edit/..., which renders draft content with your editor. Both files are required; without them the editor reports that the preview did not respond.

// app/cmssy-edit/[[...path]]/page.tsx
import { createCmssyEditPage } from "@cmssy/next/server";
import { cmssy } from "@/cmssy/config";
import { blocks } from "@/cmssy/blocks";
import { CmssyEditor } from "@/cmssy/editor";

export const dynamic = "force-dynamic";

export default createCmssyEditPage(cmssy, blocks, { editor: CmssyEditor });
// proxy.ts (Next.js 16) - on Next.js 15 name it middleware.ts and export `middleware`
import { createCmssyProxy } from "@cmssy/next/middleware";
import { cmssy } from "@/cmssy/config";

export const proxy = createCmssyProxy(cmssy);
export const config = { matcher: ["/((?!_next/|api/|.*\\..*).*)"] };

proxy.ts sits next to app/ (in src/ when the app is src/app). Set the workspace preview URL to the exact deployed origin, e.g. https://my-site.vercel.app.

Draft preview

// app/api/draft/route.ts
import { createDraftRoute } from "@cmssy/next/server";
export const GET = createDraftRoute(cmssy);

Cache, and expire it on publish

// app/[[...path]]/page.tsx
export const revalidate = 3600;
const cache = { revalidate };
export default createCmssyPage(cmssy, blocks, { editor: CmssyEditor, cache });

// app/api/revalidate/route.ts
import { createCmssyRevalidateRoute } from "@cmssy/next/server";
export const POST = createCmssyRevalidateRoute({
  secret: process.env.CMSSY_WEBHOOK_SECRET,
});

cache puts the SDK's published reads into the Next data cache under the cmssy-content tag; the route expires that tag for a verified content.changed webhook. Draft mode and the editor always read live.

Edit-mode CSP

createCmssyProxy already sets it on editor requests. For a hand-written proxy, applyCmssyCsp(response, { editorOrigin: cmssy.editorOrigin }) from @cmssy/next/middleware lets the cmssy editor frame the response.

Localized navigation (path prefix)

The active locale lives in the URL path prefix (/en/about; the default locale stays bare). createCmssyPage resolves it and exposes it via CmssyLocaleProvider. For the locale to survive navigation, internal links must carry the prefix - prefix hrefs yourself with localizeHref and pass the result to next/link:

// any block component
import Link from "next/link";
import { localizeHref } from "@cmssy/next";

<Link href={localizeHref("/about", locale)}>About</Link>; // → /en/about while EN is active

The root layout can't read the path, so the proxy resolves the locale from the path prefix: the createCmssyProxy from the editor section already does it.

localizeHref(href, locale) and the CMSSY_LOCALE_HEADER constant are re-exported from @cmssy/next (and @cmssy/core).

Exports

@cmssy/next/server: createCmssyPage, createCmssyEditPage, createDraftRoute, createCmssyRevalidateRoute, createCmssyBlockDataRoute, CmssyLayoutSlot, resolveCmssyLayout, isCmssyEditMode. @cmssy/next/middleware: createCmssyProxy, cmssyEditRewrite, applyCmssyCsp, isCmssyEditRequest. Root: defineCmssyConfig, localizeHref, nextRetryMode, cmssyCachedFetch, CMSSY_CONTENT_TAG and the types. The full list, with signatures, is in docs/reference/sdk-api.md.

Versioning: this package, not the API

Pinning this package does not pin the API it talks to. The package version covers this client - its exports and their behaviour, normal semver. The cmssy delivery API is a hosted service whose GraphQL schema can change on any deploy, without a release here.

There is no dated API version to pin; the delivery endpoint has no version segment. What protects you today is that a breaking schema change cannot merge silently - it is caught by a gate that validates the SDK's own operations, and shipping one anyway takes a recorded approval - and that fields we intend to remove are marked @deprecated first. There is no guaranteed deprecation window and no minimum notice period. Details in @cmssy/core.

License

MIT

版本与发布记录

@cmssy/next 共发布 222 个版本,首次发布于 2026/06/07;过去 12 个月发布了 222 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
19.30.0latest2026/11/063 天前
19.29.02026/11/045 天前
19.28.12026/11/045 天前
19.28.02026/11/045 天前
19.27.02026/10/319 天前
19.26.32026/10/3010 天前

关于 @cmssy/next 的常见问题

@cmssy/next 是什么?

Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)

如何安装 @cmssy/next?

在项目目录运行 npm install @cmssy/next,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(>=15)、react(^18.2.0 || ^19.0.0)、react-dom(^18.2.0 || ^19.0.0)、@cmssy/react(^19.30.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cmssy/next 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cmssy/next 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cmssy/next 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cmssy/next 可以商用吗?

@cmssy/next 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cmssy/next 的下载量有多少?

根据 npm 官方下载统计,@cmssy/next 在 2026/10/10 – 2026/11/08 这 30 天内被下载 6,166 次,日均约 206 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cmssy/next 还在维护吗?

最新版本 19.30.0 发布于 2026/11/06(3 天前);至今共发布 222 个版本,其中过去 12 个月发布了 222 个;首次发布于 2026/06/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。