@cmssy/next 16.7.1 → 16.9.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 CHANGED
@@ -113,7 +113,8 @@ re-exported from `@cmssy/next` (and `@cmssy/core`).
113
113
  ## Exports
114
114
 
115
115
  `@cmssy/next/server`: `createCmssyPage`, `createCmssyEditPage`,
116
- `createDraftRoute`, `createCmssyRevalidateRoute`, `CmssyLayoutSlot`,
116
+ `createDraftRoute`, `createCmssyRevalidateRoute`, `createCmssyBlockDataRoute`,
117
+ `CmssyLayoutSlot`,
117
118
  `resolveCmssyLayout`, `isCmssyEditMode`. `@cmssy/next/middleware`:
118
119
  `createCmssyProxy`, `cmssyEditRewrite`, `applyCmssyCsp`, `isCmssyEditRequest`.
119
120
  Root: `defineCmssyConfig`, `localizeHref`, `nextRetryMode`, `cmssyCachedFetch`,
package/dist/server.cjs CHANGED
@@ -4,10 +4,10 @@ require('server-only');
4
4
  var headers = require('next/headers');
5
5
  var navigation = require('next/navigation');
6
6
  var react = require('@cmssy/react');
7
+ var core = require('@cmssy/core');
7
8
  var internal$1 = require('@cmssy/react/internal');
8
9
  var internalServer = require('@cmssy/react/internal-server');
9
10
  var internal = require('@cmssy/core/internal');
10
- var core = require('@cmssy/core');
11
11
  var jsxRuntime = require('react/jsx-runtime');
12
12
  var cache = require('next/cache');
13
13
 
@@ -147,7 +147,13 @@ function buildCmssyPageRenderer(config, blocks, options, editRoute) {
147
147
  enabledLocales,
148
148
  edit: {
149
149
  editorOrigin: bridgeOrigin,
150
- ...config.layout ? { layoutRegions: config.layout.regions } : {}
150
+ ...config.layout ? { layoutRegions: config.layout.regions } : {},
151
+ ...config.draftSecret ? {
152
+ blockDataToken: await core.mintCmssyEditToken(
153
+ config.draftSecret,
154
+ { page: page.slug ?? "" }
155
+ )
156
+ } : {}
151
157
  },
152
158
  forms,
153
159
  data: editorData.data,
@@ -218,7 +224,8 @@ async function renderNothingPublishedPage(config, path) {
218
224
  shown
219
225
  ] }),
220
226
  /* @__PURE__ */ jsxRuntime.jsxs("p", { style: { margin: "0 0 1rem" }, children: [
221
- "Your app is wired to workspace ",
227
+ "Your app is wired to workspace",
228
+ " ",
222
229
  /* @__PURE__ */ jsxRuntime.jsxs("code", { children: [
223
230
  config.org,
224
231
  "/",
@@ -380,25 +387,9 @@ async function CmssyLayoutSlot({
380
387
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children({ groups, settings, page: routed, element }) });
381
388
  }
382
389
  function createCmssyBlockDataRoute(config, blocks, options = {}) {
390
+ const handle = react.createBlockDataHandler(config, blocks, options);
383
391
  return async function POST(request) {
384
- if (!await isCmssyEditMode()) {
385
- return new Response(
386
- "cmssy: block data is only resolved for a verified editor request",
387
- { status: 403 }
388
- );
389
- }
390
- let body;
391
- try {
392
- body = await request.json();
393
- } catch {
394
- return Response.json(
395
- { message: "cmssy: body is not JSON" },
396
- {
397
- status: 400
398
- }
399
- );
400
- }
401
- return react.handleBlockDataRequest(body, { blocks, config, ...options });
392
+ return handle(request);
402
393
  };
403
394
  }
404
395
 
package/dist/server.d.cts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { C as CmssyDataCacheOptions } from './index-D6hhjPH3.cjs';
2
2
  export { a as CMSSY_CONTENT_TAG, b as CmssyAppContext, c as CmssyEditorProps, d as CreateCmssyPageOptions, N as NEXT_BUILD_PHASE, e as cmssyCachedFetch, f as createCmssyEditPage, g as createCmssyPage, n as nextRetryMode } from './index-D6hhjPH3.cjs';
3
- import { CmssyConfig, CmssyRegionOf, RetryOption, CmssyFormDefinition, CmssyClientConfig } from '@cmssy/core';
3
+ import { CmssyConfig, CmssyRegionOf, RetryOption, CmssyClientConfig } from '@cmssy/core';
4
4
  export { CmssyRetryMode, RetryOption, RetryPolicy } from '@cmssy/core';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { ComponentType, ReactNode } from 'react';
7
- import { BlockDefinition, CmssyLayoutEditableProps, CmssyLayoutResolution, ResolveCmssyLayoutOptions as ResolveCmssyLayoutOptions$1 } from '@cmssy/react';
7
+ import { BlockDefinition, CmssyLayoutEditableProps, CmssyLayoutResolution, ResolveCmssyLayoutOptions as ResolveCmssyLayoutOptions$1, CmssyBlockDataHandlerOptions } from '@cmssy/react';
8
8
  export { CmssyLayoutEditableProps, CmssyLayoutResolution } from '@cmssy/react';
9
9
  import '@cmssy/react/client';
10
10
 
@@ -51,11 +51,9 @@ type ResolveCmssyLayoutOptions<C extends CmssyConfig, P extends CmssyRegionOf<C>
51
51
  };
52
52
  declare function resolveCmssyLayout<C extends CmssyConfig, P extends CmssyRegionOf<C>>(config: C, options: ResolveCmssyLayoutOptions<C, P>): Promise<CmssyLayoutResolution<C, P>>;
53
53
 
54
- interface CmssyBlockDataRouteConfig {
55
- forms?: Record<string, CmssyFormDefinition>;
56
- appContext?: Record<string, unknown>;
57
- workspaceId?: string;
58
- }
59
- declare function createCmssyBlockDataRoute(config: CmssyClientConfig, blocks: BlockDefinition[], options?: CmssyBlockDataRouteConfig): (request: Request) => Promise<Response>;
54
+ type CmssyBlockDataRouteConfig = CmssyBlockDataHandlerOptions;
55
+ declare function createCmssyBlockDataRoute(config: CmssyClientConfig & {
56
+ draftSecret?: string;
57
+ }, blocks: BlockDefinition[], options?: CmssyBlockDataRouteConfig): (request: Request) => Promise<Response>;
60
58
 
61
59
  export { type CmssyBlockDataRouteConfig, CmssyDataCacheOptions, type CmssyDraftRouteConfig, CmssyLayoutSlot, type CmssyLayoutSlotProps, type CmssyLayoutSlotRenderProps, type CmssyRevalidateRouteConfig, type ResolveCmssyLayoutOptions, createCmssyBlockDataRoute, createCmssyRevalidateRoute, createDraftRoute, isCmssyEditMode, resolveCmssyLayout };
package/dist/server.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { C as CmssyDataCacheOptions } from './index-D6hhjPH3.js';
2
2
  export { a as CMSSY_CONTENT_TAG, b as CmssyAppContext, c as CmssyEditorProps, d as CreateCmssyPageOptions, N as NEXT_BUILD_PHASE, e as cmssyCachedFetch, f as createCmssyEditPage, g as createCmssyPage, n as nextRetryMode } from './index-D6hhjPH3.js';
3
- import { CmssyConfig, CmssyRegionOf, RetryOption, CmssyFormDefinition, CmssyClientConfig } from '@cmssy/core';
3
+ import { CmssyConfig, CmssyRegionOf, RetryOption, CmssyClientConfig } from '@cmssy/core';
4
4
  export { CmssyRetryMode, RetryOption, RetryPolicy } from '@cmssy/core';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { ComponentType, ReactNode } from 'react';
7
- import { BlockDefinition, CmssyLayoutEditableProps, CmssyLayoutResolution, ResolveCmssyLayoutOptions as ResolveCmssyLayoutOptions$1 } from '@cmssy/react';
7
+ import { BlockDefinition, CmssyLayoutEditableProps, CmssyLayoutResolution, ResolveCmssyLayoutOptions as ResolveCmssyLayoutOptions$1, CmssyBlockDataHandlerOptions } from '@cmssy/react';
8
8
  export { CmssyLayoutEditableProps, CmssyLayoutResolution } from '@cmssy/react';
9
9
  import '@cmssy/react/client';
10
10
 
@@ -51,11 +51,9 @@ type ResolveCmssyLayoutOptions<C extends CmssyConfig, P extends CmssyRegionOf<C>
51
51
  };
52
52
  declare function resolveCmssyLayout<C extends CmssyConfig, P extends CmssyRegionOf<C>>(config: C, options: ResolveCmssyLayoutOptions<C, P>): Promise<CmssyLayoutResolution<C, P>>;
53
53
 
54
- interface CmssyBlockDataRouteConfig {
55
- forms?: Record<string, CmssyFormDefinition>;
56
- appContext?: Record<string, unknown>;
57
- workspaceId?: string;
58
- }
59
- declare function createCmssyBlockDataRoute(config: CmssyClientConfig, blocks: BlockDefinition[], options?: CmssyBlockDataRouteConfig): (request: Request) => Promise<Response>;
54
+ type CmssyBlockDataRouteConfig = CmssyBlockDataHandlerOptions;
55
+ declare function createCmssyBlockDataRoute(config: CmssyClientConfig & {
56
+ draftSecret?: string;
57
+ }, blocks: BlockDefinition[], options?: CmssyBlockDataRouteConfig): (request: Request) => Promise<Response>;
60
58
 
61
59
  export { type CmssyBlockDataRouteConfig, CmssyDataCacheOptions, type CmssyDraftRouteConfig, CmssyLayoutSlot, type CmssyLayoutSlotProps, type CmssyLayoutSlotRenderProps, type CmssyRevalidateRouteConfig, type ResolveCmssyLayoutOptions, createCmssyBlockDataRoute, createCmssyRevalidateRoute, createDraftRoute, isCmssyEditMode, resolveCmssyLayout };
package/dist/server.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import 'server-only';
2
2
  import { draftMode, headers } from 'next/headers';
3
3
  import { notFound, redirect } from 'next/navigation';
4
- import { createCmssyClient, CmssyServerPage, resolveCmssyLayout as resolveCmssyLayout$1, handleBlockDataRequest } from '@cmssy/react';
4
+ import { createCmssyClient, CmssyServerPage, resolveCmssyLayout as resolveCmssyLayout$1, createBlockDataHandler } from '@cmssy/react';
5
+ import { mintCmssyEditToken, CMSSY_SECRET_QUERY_PARAM, resolveEditorOrigin, verifyCmssyWebhook, CmssyWebhookError, CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM } from '@cmssy/core';
5
6
  import { CmssyLocaleProvider } from '@cmssy/react/internal';
6
7
  import { blocksToSchemas, resolveEditorBlockData } from '@cmssy/react/internal-server';
7
8
  import { isDevelopment, resolveSiteLocales, splitLocaleFromPath, fetchPage, resolveForms, toCspOrigin, cmssySecretsMatch } from '@cmssy/core/internal';
8
- import { CMSSY_SECRET_QUERY_PARAM, resolveEditorOrigin, verifyCmssyWebhook, CmssyWebhookError, CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM } from '@cmssy/core';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
  import { revalidateTag } from 'next/cache';
11
11
 
@@ -145,7 +145,13 @@ function buildCmssyPageRenderer(config, blocks, options, editRoute) {
145
145
  enabledLocales,
146
146
  edit: {
147
147
  editorOrigin: bridgeOrigin,
148
- ...config.layout ? { layoutRegions: config.layout.regions } : {}
148
+ ...config.layout ? { layoutRegions: config.layout.regions } : {},
149
+ ...config.draftSecret ? {
150
+ blockDataToken: await mintCmssyEditToken(
151
+ config.draftSecret,
152
+ { page: page.slug ?? "" }
153
+ )
154
+ } : {}
149
155
  },
150
156
  forms,
151
157
  data: editorData.data,
@@ -216,7 +222,8 @@ async function renderNothingPublishedPage(config, path) {
216
222
  shown
217
223
  ] }),
218
224
  /* @__PURE__ */ jsxs("p", { style: { margin: "0 0 1rem" }, children: [
219
- "Your app is wired to workspace ",
225
+ "Your app is wired to workspace",
226
+ " ",
220
227
  /* @__PURE__ */ jsxs("code", { children: [
221
228
  config.org,
222
229
  "/",
@@ -378,25 +385,9 @@ async function CmssyLayoutSlot({
378
385
  return /* @__PURE__ */ jsx(Fragment, { children: children({ groups, settings, page: routed, element }) });
379
386
  }
380
387
  function createCmssyBlockDataRoute(config, blocks, options = {}) {
388
+ const handle = createBlockDataHandler(config, blocks, options);
381
389
  return async function POST(request) {
382
- if (!await isCmssyEditMode()) {
383
- return new Response(
384
- "cmssy: block data is only resolved for a verified editor request",
385
- { status: 403 }
386
- );
387
- }
388
- let body;
389
- try {
390
- body = await request.json();
391
- } catch {
392
- return Response.json(
393
- { message: "cmssy: body is not JSON" },
394
- {
395
- status: 400
396
- }
397
- );
398
- }
399
- return handleBlockDataRequest(body, { blocks, config, ...options });
390
+ return handle(request);
400
391
  };
401
392
  }
402
393
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/next",
3
- "version": "16.7.1",
3
+ "version": "16.9.0",
4
4
  "description": "Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -71,7 +71,7 @@
71
71
  "dist"
72
72
  ],
73
73
  "peerDependencies": {
74
- "@cmssy/react": "^16.7.1",
74
+ "@cmssy/react": "^16.9.0",
75
75
  "next": ">=15",
76
76
  "react": "^18.2.0 || ^19.0.0",
77
77
  "react-dom": "^18.2.0 || ^19.0.0"
@@ -85,12 +85,12 @@
85
85
  "tsup": "^8.3.0",
86
86
  "typescript": "^5.6.0",
87
87
  "vitest": "^2.1.0",
88
- "@cmssy/react": "16.7.1"
88
+ "@cmssy/react": "16.9.0"
89
89
  },
90
90
  "dependencies": {
91
91
  "@cmssy/types": "0.49.0",
92
92
  "server-only": "^0.0.1",
93
- "@cmssy/core": "16.7.1"
93
+ "@cmssy/core": "16.9.0"
94
94
  },
95
95
  "scripts": {
96
96
  "build": "tsup",