@cmssy/cli 10.10.0 → 11.0.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.
@@ -3,12 +3,25 @@ import { cmssy } from "@/cmssy.config";
3
3
  import { blocks } from "@/cmssy/blocks";
4
4
  import { CmssyEditor } from "@/cmssy/editor";
5
5
  import { EditableLayout } from "@/cmssy/editable-layout";
6
+ import { publishedPaths } from "@/services/pages";
6
7
 
7
8
  type PageProps = {
8
9
  params: Promise<{ path?: string[] }>;
9
10
  searchParams: Promise<Record<string, string | string[] | undefined>>;
10
11
  };
11
12
 
13
+ // Three lines that decide whether this site is cached at all. Without
14
+ // generateStaticParams a catch-all is rendered on demand every time and
15
+ // `revalidate` is ignored - the build prints a blank Revalidate column, which is
16
+ // the only warning you get. `dynamicParams` keeps pages published after the
17
+ // build working: first request renders them, and they cache from then on.
18
+ export const revalidate = 3600;
19
+ export const dynamicParams = true;
20
+
21
+ export function generateStaticParams() {
22
+ return publishedPaths();
23
+ }
24
+
12
25
  const CmssyPage = createCmssyPage(cmssy, blocks, { editor: CmssyEditor });
13
26
 
14
27
  // The header and footer are layout blocks. They are mounted here rather than in
@@ -22,7 +35,8 @@ export default async function Page(props: PageProps) {
22
35
  config={cmssy}
23
36
  blocks={blocks}
24
37
  position={position}
25
- path={path}
38
+ path={path ?? []}
39
+ editMode={false}
26
40
  editable={EditableLayout}
27
41
  />
28
42
  );
@@ -1,4 +1,8 @@
1
- import { createCmssyEditPage, CmssyLayoutSlot } from "@cmssy/next/server";
1
+ import {
2
+ createCmssyEditPage,
3
+ CmssyLayoutSlot,
4
+ isCmssyEditMode,
5
+ } from "@cmssy/next/server";
2
6
  import { cmssy } from "@/cmssy.config";
3
7
  import { blocks } from "@/cmssy/blocks";
4
8
  import { CmssyEditor } from "@/cmssy/editor";
@@ -24,12 +28,20 @@ const CmssyEditPage = createCmssyEditPage(cmssy, blocks, {
24
28
  // header missing here is a header missing in the editor.
25
29
  export default async function EditPage(props: PageProps) {
26
30
  const { path } = await props.params;
31
+
32
+ // Not a hard `true`: this route is reachable directly, and only the proxy's
33
+ // verified rewrite sets the edit header. Hard-coding it would fetch layouts
34
+ // with the draft secret for anyone who typed the URL. Reading a header costs
35
+ // nothing here - the route is force-dynamic either way.
36
+ const editMode = await isCmssyEditMode();
37
+
27
38
  const slot = (position: "header" | "footer") => (
28
39
  <CmssyLayoutSlot
29
40
  config={cmssy}
30
41
  blocks={blocks}
31
42
  position={position}
32
- path={path}
43
+ path={path ?? []}
44
+ editMode={editMode}
33
45
  editable={EditableLayout}
34
46
  />
35
47
  );
@@ -0,0 +1,58 @@
1
+ import { createCmssyClient } from "@cmssy/core";
2
+ import { cmssy } from "@/cmssy.config";
3
+
4
+ // Your query, in your repo. The SDK does not mirror the graph - it gives you a
5
+ // client and gets out of the way, so adding a field here is your call and not a
6
+ // release of ours.
7
+ const PUBLISHED_PAGES = `query PublishedPages($workspaceSlug: String!) {
8
+ public {
9
+ page {
10
+ list(workspaceSlug: $workspaceSlug) {
11
+ slug
12
+ publishedAt
13
+ }
14
+ }
15
+ }
16
+ }`;
17
+
18
+ type PublishedPages = {
19
+ public?: {
20
+ page?: { list?: { slug?: string | null; publishedAt?: string | null }[] | null } | null;
21
+ } | null;
22
+ };
23
+
24
+ const client = createCmssyClient({
25
+ apiUrl: cmssy.apiUrl,
26
+ org: cmssy.org,
27
+ workspaceSlug: cmssy.workspaceSlug,
28
+ });
29
+
30
+ /**
31
+ * The paths to prerender, as `generateStaticParams` wants them.
32
+ *
33
+ * A catch-all route with no params generated is served on demand and cached by
34
+ * nothing, whatever `revalidate` says - so this function is what makes the
35
+ * route cacheable at all, not an optimisation on top of it.
36
+ */
37
+ export async function publishedPaths(): Promise<{ path: string[] }[]> {
38
+ const data = await client.query<PublishedPages>(
39
+ PUBLISHED_PAGES,
40
+ { workspaceSlug: cmssy.workspaceSlug },
41
+ {
42
+ // `public` routes through the org-scoped delivery path. Without it the
43
+ // request lands on the base endpoint, where an unauthenticated workspace
44
+ // lookup is by slug alone - across every org.
45
+ public: true,
46
+ // A build reads this once. A single 429 from the delivery API would fail
47
+ // the whole deploy, so retry - it is a read, nothing to double-apply.
48
+ retry: {},
49
+ },
50
+ );
51
+
52
+ const pages = data?.public?.page?.list ?? [];
53
+ return pages
54
+ .filter((page) => page.publishedAt)
55
+ .map((page) => ({
56
+ path: (page.slug ?? "").split("/").filter(Boolean),
57
+ }));
58
+ }
package/dist/index.js CHANGED
@@ -161,10 +161,11 @@ var FRAMEWORKS = [
161
161
  label: "Next.js",
162
162
  createCommand: "npx create-next-app@latest",
163
163
  detect: ["next"],
164
- dependencies: ["@cmssy/next", "@cmssy/react"],
164
+ dependencies: ["@cmssy/next", "@cmssy/react", "@cmssy/core"],
165
165
  files: [
166
166
  "cmssy.config.ts",
167
167
  "proxy.ts",
168
+ "services/pages.ts",
168
169
  "cmssy/blocks.ts",
169
170
  "cmssy/editor.tsx",
170
171
  "cmssy/editable-layout.tsx",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/cli",
3
- "version": "10.10.0",
3
+ "version": "11.0.0",
4
4
  "description": "The cmssy CLI: `cmssy init` wires cmssy into an existing Next.js, Astro or React Router app; `cmssy link` connects it to a workspace and verifies the editor wiring.",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -27,7 +27,7 @@
27
27
  "assets"
28
28
  ],
29
29
  "dependencies": {
30
- "@cmssy/core": "10.10.0"
30
+ "@cmssy/core": "11.0.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^20.0.0",