@cmssy/next 4.5.0 → 4.6.1
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 +29 -0
- package/dist/index.js +29 -0
- 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');
|
|
@@ -113,6 +114,15 @@ function defineCmssyConfig(config) {
|
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
if (missing.length > 0) {
|
|
117
|
+
if (typeof window !== "undefined") {
|
|
118
|
+
throw new Error(
|
|
119
|
+
`cmssy: the config was evaluated in the browser, so it cannot see the server's environment variables.
|
|
120
|
+
|
|
121
|
+
This is an import problem, not a config problem: a client component ("use client") imported a VALUE from a module that reads the cmssy config - directly, or through a helper next to one.
|
|
122
|
+
|
|
123
|
+
Fix it by importing types only (they are erased at build time), or by moving the value into a module that does not touch the config.`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
116
126
|
throw new Error(
|
|
117
127
|
`cmssy: missing required configuration:
|
|
118
128
|
- ${missing.join(
|
|
@@ -408,6 +418,7 @@ async function cmssyEditRewrite(request2, config, options = {}) {
|
|
|
408
418
|
if (!await cmssySecretsMatch(provided, config.draftSecret)) return null;
|
|
409
419
|
const url = request2.nextUrl.clone();
|
|
410
420
|
url.pathname = `${CMSSY_EDIT_PATH_PREFIX}${pathname === "/" ? "" : pathname}`;
|
|
421
|
+
warnIfEditRouteMissing(url);
|
|
411
422
|
return server.NextResponse.rewrite(
|
|
412
423
|
url,
|
|
413
424
|
options.requestHeaders ? { request: { headers: options.requestHeaders } } : void 0
|
|
@@ -418,6 +429,24 @@ function createCmssyEditMiddleware(config) {
|
|
|
418
429
|
return await cmssyEditRewrite(request2, config) ?? server.NextResponse.next();
|
|
419
430
|
};
|
|
420
431
|
}
|
|
432
|
+
var probed = false;
|
|
433
|
+
function warnIfEditRouteMissing(url) {
|
|
434
|
+
if (process.env.NODE_ENV === "production" || probed) return;
|
|
435
|
+
probed = true;
|
|
436
|
+
void fetch(url, { method: "HEAD" }).then((response) => {
|
|
437
|
+
if (response.status !== 404) return;
|
|
438
|
+
console.error(
|
|
439
|
+
`[cmssy] The editor request was rewritten to ${url.pathname}, but nothing is mounted there (404). Add the edit route:
|
|
440
|
+
|
|
441
|
+
// app/cmssy-edit/[[...path]]/page.tsx
|
|
442
|
+
export const dynamic = "force-dynamic";
|
|
443
|
+
export default createCmssyEditPage(cmssy, blocks, { editor: CmssyEditor });
|
|
444
|
+
|
|
445
|
+
Until then the editor preview stays blank.`
|
|
446
|
+
);
|
|
447
|
+
}).catch(() => {
|
|
448
|
+
});
|
|
449
|
+
}
|
|
421
450
|
function DefaultNotFound() {
|
|
422
451
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
423
452
|
"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';
|
|
@@ -112,6 +113,15 @@ function defineCmssyConfig(config) {
|
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
if (missing.length > 0) {
|
|
116
|
+
if (typeof window !== "undefined") {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`cmssy: the config was evaluated in the browser, so it cannot see the server's environment variables.
|
|
119
|
+
|
|
120
|
+
This is an import problem, not a config problem: a client component ("use client") imported a VALUE from a module that reads the cmssy config - directly, or through a helper next to one.
|
|
121
|
+
|
|
122
|
+
Fix it by importing types only (they are erased at build time), or by moving the value into a module that does not touch the config.`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
115
125
|
throw new Error(
|
|
116
126
|
`cmssy: missing required configuration:
|
|
117
127
|
- ${missing.join(
|
|
@@ -407,6 +417,7 @@ async function cmssyEditRewrite(request2, config, options = {}) {
|
|
|
407
417
|
if (!await cmssySecretsMatch(provided, config.draftSecret)) return null;
|
|
408
418
|
const url = request2.nextUrl.clone();
|
|
409
419
|
url.pathname = `${CMSSY_EDIT_PATH_PREFIX}${pathname === "/" ? "" : pathname}`;
|
|
420
|
+
warnIfEditRouteMissing(url);
|
|
410
421
|
return NextResponse.rewrite(
|
|
411
422
|
url,
|
|
412
423
|
options.requestHeaders ? { request: { headers: options.requestHeaders } } : void 0
|
|
@@ -417,6 +428,24 @@ function createCmssyEditMiddleware(config) {
|
|
|
417
428
|
return await cmssyEditRewrite(request2, config) ?? NextResponse.next();
|
|
418
429
|
};
|
|
419
430
|
}
|
|
431
|
+
var probed = false;
|
|
432
|
+
function warnIfEditRouteMissing(url) {
|
|
433
|
+
if (process.env.NODE_ENV === "production" || probed) return;
|
|
434
|
+
probed = true;
|
|
435
|
+
void fetch(url, { method: "HEAD" }).then((response) => {
|
|
436
|
+
if (response.status !== 404) return;
|
|
437
|
+
console.error(
|
|
438
|
+
`[cmssy] The editor request was rewritten to ${url.pathname}, but nothing is mounted there (404). Add the edit route:
|
|
439
|
+
|
|
440
|
+
// app/cmssy-edit/[[...path]]/page.tsx
|
|
441
|
+
export const dynamic = "force-dynamic";
|
|
442
|
+
export default createCmssyEditPage(cmssy, blocks, { editor: CmssyEditor });
|
|
443
|
+
|
|
444
|
+
Until then the editor preview stays blank.`
|
|
445
|
+
);
|
|
446
|
+
}).catch(() => {
|
|
447
|
+
});
|
|
448
|
+
}
|
|
420
449
|
function DefaultNotFound() {
|
|
421
450
|
return /* @__PURE__ */ jsxs(
|
|
422
451
|
"main",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/next",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.1",
|
|
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.1",
|
|
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.1"
|
|
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",
|