@cmssy/next 4.4.0 → 4.6.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/dist/index.cjs +22 -2
- package/dist/index.js +22 -2
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
require('server-only');
|
|
3
4
|
var headers = require('next/headers');
|
|
4
5
|
var navigation = require('next/navigation');
|
|
5
6
|
var react = require('@cmssy/react');
|
|
@@ -9,7 +10,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
9
10
|
var server = require('next/server');
|
|
10
11
|
var crypto$1 = require('crypto');
|
|
11
12
|
|
|
12
|
-
// src/
|
|
13
|
+
// src/index.ts
|
|
13
14
|
var CMSSY_SESSION_COOKIE = "cmssy_session";
|
|
14
15
|
var SESSION_MAX_AGE_SECONDS = 30 * 24 * 60 * 60;
|
|
15
16
|
var MIN_SESSION_SECRET_LENGTH = 32;
|
|
@@ -295,7 +296,7 @@ function buildCmssyPageRenderer(config, blocks, options, editRoute) {
|
|
|
295
296
|
let defaultLocale;
|
|
296
297
|
let enabledLocales = config.enabledLocales;
|
|
297
298
|
if (config.resolveLocale) {
|
|
298
|
-
defaultLocale = config.defaultLocale ??
|
|
299
|
+
defaultLocale = config.defaultLocale ?? (await react.resolveSiteLocales(clientConfig)).defaultLocale;
|
|
299
300
|
locale = await config.resolveLocale();
|
|
300
301
|
} else {
|
|
301
302
|
const siteLocales = await react.resolveSiteLocales(clientConfig);
|
|
@@ -408,6 +409,7 @@ async function cmssyEditRewrite(request2, config, options = {}) {
|
|
|
408
409
|
if (!await cmssySecretsMatch(provided, config.draftSecret)) return null;
|
|
409
410
|
const url = request2.nextUrl.clone();
|
|
410
411
|
url.pathname = `${CMSSY_EDIT_PATH_PREFIX}${pathname === "/" ? "" : pathname}`;
|
|
412
|
+
warnIfEditRouteMissing(url);
|
|
411
413
|
return server.NextResponse.rewrite(
|
|
412
414
|
url,
|
|
413
415
|
options.requestHeaders ? { request: { headers: options.requestHeaders } } : void 0
|
|
@@ -418,6 +420,24 @@ function createCmssyEditMiddleware(config) {
|
|
|
418
420
|
return await cmssyEditRewrite(request2, config) ?? server.NextResponse.next();
|
|
419
421
|
};
|
|
420
422
|
}
|
|
423
|
+
var probed = false;
|
|
424
|
+
function warnIfEditRouteMissing(url) {
|
|
425
|
+
if (process.env.NODE_ENV === "production" || probed) return;
|
|
426
|
+
probed = true;
|
|
427
|
+
void fetch(url, { method: "HEAD" }).then((response) => {
|
|
428
|
+
if (response.status !== 404) return;
|
|
429
|
+
console.error(
|
|
430
|
+
`[cmssy] The editor request was rewritten to ${url.pathname}, but nothing is mounted there (404). Add the edit route:
|
|
431
|
+
|
|
432
|
+
// app/cmssy-edit/[[...path]]/page.tsx
|
|
433
|
+
export const dynamic = "force-dynamic";
|
|
434
|
+
export default createCmssyEditPage(cmssy, blocks, { editor: CmssyEditor });
|
|
435
|
+
|
|
436
|
+
Until then the editor preview stays blank.`
|
|
437
|
+
);
|
|
438
|
+
}).catch(() => {
|
|
439
|
+
});
|
|
440
|
+
}
|
|
421
441
|
function DefaultNotFound() {
|
|
422
442
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
423
443
|
"main",
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import 'server-only';
|
|
1
2
|
import { headers, draftMode, cookies } from 'next/headers';
|
|
2
3
|
import { notFound, redirect } from 'next/navigation';
|
|
3
4
|
import { createCmssyClient, resolveSiteLocales, splitLocaleFromPath, fetchPage, resolveForms, CmssyServerPage, fetchSiteConfig, fetchPageById, fetchPages, normalizeSlug as normalizeSlug$1, fetchPageMeta, resolveWorkspaceId, graphqlRequest, resolveApiUrl } from '@cmssy/react';
|
|
@@ -8,7 +9,7 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
8
9
|
import { NextResponse } from 'next/server';
|
|
9
10
|
import { createHmac, timingSafeEqual } from 'crypto';
|
|
10
11
|
|
|
11
|
-
// src/
|
|
12
|
+
// src/index.ts
|
|
12
13
|
var CMSSY_SESSION_COOKIE = "cmssy_session";
|
|
13
14
|
var SESSION_MAX_AGE_SECONDS = 30 * 24 * 60 * 60;
|
|
14
15
|
var MIN_SESSION_SECRET_LENGTH = 32;
|
|
@@ -294,7 +295,7 @@ function buildCmssyPageRenderer(config, blocks, options, editRoute) {
|
|
|
294
295
|
let defaultLocale;
|
|
295
296
|
let enabledLocales = config.enabledLocales;
|
|
296
297
|
if (config.resolveLocale) {
|
|
297
|
-
defaultLocale = config.defaultLocale ??
|
|
298
|
+
defaultLocale = config.defaultLocale ?? (await resolveSiteLocales(clientConfig)).defaultLocale;
|
|
298
299
|
locale = await config.resolveLocale();
|
|
299
300
|
} else {
|
|
300
301
|
const siteLocales = await resolveSiteLocales(clientConfig);
|
|
@@ -407,6 +408,7 @@ async function cmssyEditRewrite(request2, config, options = {}) {
|
|
|
407
408
|
if (!await cmssySecretsMatch(provided, config.draftSecret)) return null;
|
|
408
409
|
const url = request2.nextUrl.clone();
|
|
409
410
|
url.pathname = `${CMSSY_EDIT_PATH_PREFIX}${pathname === "/" ? "" : pathname}`;
|
|
411
|
+
warnIfEditRouteMissing(url);
|
|
410
412
|
return NextResponse.rewrite(
|
|
411
413
|
url,
|
|
412
414
|
options.requestHeaders ? { request: { headers: options.requestHeaders } } : void 0
|
|
@@ -417,6 +419,24 @@ function createCmssyEditMiddleware(config) {
|
|
|
417
419
|
return await cmssyEditRewrite(request2, config) ?? NextResponse.next();
|
|
418
420
|
};
|
|
419
421
|
}
|
|
422
|
+
var probed = false;
|
|
423
|
+
function warnIfEditRouteMissing(url) {
|
|
424
|
+
if (process.env.NODE_ENV === "production" || probed) return;
|
|
425
|
+
probed = true;
|
|
426
|
+
void fetch(url, { method: "HEAD" }).then((response) => {
|
|
427
|
+
if (response.status !== 404) return;
|
|
428
|
+
console.error(
|
|
429
|
+
`[cmssy] The editor request was rewritten to ${url.pathname}, but nothing is mounted there (404). Add the edit route:
|
|
430
|
+
|
|
431
|
+
// app/cmssy-edit/[[...path]]/page.tsx
|
|
432
|
+
export const dynamic = "force-dynamic";
|
|
433
|
+
export default createCmssyEditPage(cmssy, blocks, { editor: CmssyEditor });
|
|
434
|
+
|
|
435
|
+
Until then the editor preview stays blank.`
|
|
436
|
+
);
|
|
437
|
+
}).catch(() => {
|
|
438
|
+
});
|
|
439
|
+
}
|
|
420
440
|
function DefaultNotFound() {
|
|
421
441
|
return /* @__PURE__ */ jsxs(
|
|
422
442
|
"main",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/next",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cmssy",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dist"
|
|
47
47
|
],
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@cmssy/react": "^4.
|
|
49
|
+
"@cmssy/react": "^4.6.0",
|
|
50
50
|
"next": ">=15",
|
|
51
51
|
"react": "^18.2.0 || ^19.0.0",
|
|
52
52
|
"react-dom": "^18.2.0 || ^19.0.0"
|
|
@@ -60,11 +60,12 @@
|
|
|
60
60
|
"tsup": "^8.3.0",
|
|
61
61
|
"typescript": "^5.6.0",
|
|
62
62
|
"vitest": "^2.1.0",
|
|
63
|
-
"@cmssy/react": "4.
|
|
63
|
+
"@cmssy/react": "4.6.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"jose": "^6.2.3",
|
|
67
|
-
"@cmssy/types": "0.27.0"
|
|
67
|
+
"@cmssy/types": "0.27.0",
|
|
68
|
+
"server-only": "^0.0.1"
|
|
68
69
|
},
|
|
69
70
|
"scripts": {
|
|
70
71
|
"build": "tsup",
|