doccupine 0.0.139 → 0.0.141

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.
Files changed (151) hide show
  1. package/README.md +14 -7
  2. package/dist/cli.d.ts +1 -0
  3. package/dist/cli.js +191 -0
  4. package/dist/index.d.ts +3 -7
  5. package/dist/index.js +5 -1895
  6. package/dist/lib/config-manager.d.ts +1 -0
  7. package/dist/lib/config-manager.js +63 -3
  8. package/dist/lib/generated-artifacts.d.ts +26 -0
  9. package/dist/lib/generated-artifacts.js +147 -0
  10. package/dist/lib/layout.js +30 -30
  11. package/dist/lib/metadata.js +58 -30
  12. package/dist/lib/openapi-types.d.ts +2 -2
  13. package/dist/lib/openapi.d.ts +6 -3
  14. package/dist/lib/openapi.js +330 -50
  15. package/dist/lib/output-safety.d.ts +15 -0
  16. package/dist/lib/output-safety.js +428 -0
  17. package/dist/lib/structures.js +11 -0
  18. package/dist/lib/utils.d.ts +18 -0
  19. package/dist/lib/utils.js +125 -0
  20. package/dist/mdx-to-nextjs-generator.d.ts +166 -0
  21. package/dist/mdx-to-nextjs-generator.js +2229 -0
  22. package/dist/templates/app/api/gate/route.d.ts +1 -1
  23. package/dist/templates/app/api/gate/route.js +18 -6
  24. package/dist/templates/app/api/mcp/route.d.ts +1 -1
  25. package/dist/templates/app/api/mcp/route.js +181 -111
  26. package/dist/templates/app/api/playground/route.d.ts +1 -1
  27. package/dist/templates/app/api/playground/route.js +45 -13
  28. package/dist/templates/app/api/rag/route.d.ts +1 -1
  29. package/dist/templates/app/api/rag/route.js +102 -25
  30. package/dist/templates/app/api/search/route.d.ts +1 -1
  31. package/dist/templates/app/api/search/route.js +5 -0
  32. package/dist/templates/app/robots.d.ts +1 -1
  33. package/dist/templates/app/robots.js +1 -26
  34. package/dist/templates/app/theme.d.ts +1 -1
  35. package/dist/templates/app/theme.js +31 -19
  36. package/dist/templates/components/Chat.d.ts +1 -1
  37. package/dist/templates/components/Chat.js +411 -104
  38. package/dist/templates/components/Docs.d.ts +1 -1
  39. package/dist/templates/components/Docs.js +56 -13
  40. package/dist/templates/components/SearchDocs.d.ts +1 -1
  41. package/dist/templates/components/SearchDocs.js +63 -11
  42. package/dist/templates/components/SearchModalContent.d.ts +1 -1
  43. package/dist/templates/components/SearchModalContent.js +191 -49
  44. package/dist/templates/components/SideBar.d.ts +1 -1
  45. package/dist/templates/components/SideBar.js +8 -2
  46. package/dist/templates/components/layout/Accordion.d.ts +1 -1
  47. package/dist/templates/components/layout/Accordion.js +26 -3
  48. package/dist/templates/components/layout/ApiPlayground.d.ts +1 -1
  49. package/dist/templates/components/layout/ApiPlayground.js +4 -7
  50. package/dist/templates/components/layout/Badge.d.ts +1 -1
  51. package/dist/templates/components/layout/Badge.js +1 -1
  52. package/dist/templates/components/layout/Button.d.ts +1 -1
  53. package/dist/templates/components/layout/Button.js +4 -4
  54. package/dist/templates/components/layout/Callout.d.ts +1 -1
  55. package/dist/templates/components/layout/Callout.js +6 -6
  56. package/dist/templates/components/layout/Card.d.ts +1 -1
  57. package/dist/templates/components/layout/Card.js +9 -4
  58. package/dist/templates/components/layout/CherryThemeProvider.d.ts +1 -1
  59. package/dist/templates/components/layout/CherryThemeProvider.js +63 -12
  60. package/dist/templates/components/layout/Code.d.ts +1 -1
  61. package/dist/templates/components/layout/Code.js +5 -5
  62. package/dist/templates/components/layout/CopyButton.d.ts +1 -1
  63. package/dist/templates/components/layout/CopyButton.js +1 -1
  64. package/dist/templates/components/layout/DemoTheme.d.ts +1 -1
  65. package/dist/templates/components/layout/DemoTheme.js +8 -28
  66. package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
  67. package/dist/templates/components/layout/DocsComponents.js +57 -18
  68. package/dist/templates/components/layout/GlobalStyles.d.ts +1 -1
  69. package/dist/templates/components/layout/GlobalStyles.js +15 -9
  70. package/dist/templates/components/layout/Prompt.d.ts +1 -1
  71. package/dist/templates/components/layout/Prompt.js +4 -7
  72. package/dist/templates/components/layout/Steps.d.ts +1 -1
  73. package/dist/templates/components/layout/Steps.js +7 -1
  74. package/dist/templates/components/layout/Tabs.d.ts +1 -1
  75. package/dist/templates/components/layout/Tabs.js +108 -19
  76. package/dist/templates/env.example.d.ts +1 -1
  77. package/dist/templates/env.example.js +11 -0
  78. package/dist/templates/eslint.config.d.ts +1 -1
  79. package/dist/templates/eslint.config.js +20 -0
  80. package/dist/templates/gitignore.d.ts +1 -1
  81. package/dist/templates/gitignore.js +4 -3
  82. package/dist/templates/lib/access.d.ts +1 -0
  83. package/dist/templates/lib/access.js +41 -0
  84. package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
  85. package/dist/templates/mdx/ai-assistant.mdx.js +17 -1
  86. package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
  87. package/dist/templates/mdx/api-playground.mdx.js +5 -3
  88. package/dist/templates/mdx/authentication.mdx.d.ts +1 -1
  89. package/dist/templates/mdx/authentication.mdx.js +5 -3
  90. package/dist/templates/mdx/commands.mdx.d.ts +1 -1
  91. package/dist/templates/mdx/commands.mdx.js +20 -6
  92. package/dist/templates/mdx/components.mdx.d.ts +1 -1
  93. package/dist/templates/mdx/components.mdx.js +3 -0
  94. package/dist/templates/mdx/deployment-and-hosting.mdx.d.ts +1 -1
  95. package/dist/templates/mdx/deployment-and-hosting.mdx.js +2 -2
  96. package/dist/templates/mdx/globals.mdx.d.ts +1 -1
  97. package/dist/templates/mdx/globals.mdx.js +14 -11
  98. package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
  99. package/dist/templates/mdx/model-context-protocol.mdx.js +22 -35
  100. package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
  101. package/dist/templates/mdx/platform/ai-assistant.mdx.js +23 -0
  102. package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
  103. package/dist/templates/mdx/platform/api-playground.mdx.js +7 -0
  104. package/dist/templates/mdx/platform/authentication.mdx.d.ts +1 -0
  105. package/dist/templates/mdx/platform/authentication.mdx.js +63 -0
  106. package/dist/templates/mdx/platform/build-and-deploy.mdx.d.ts +1 -1
  107. package/dist/templates/mdx/platform/build-and-deploy.mdx.js +1 -1
  108. package/dist/templates/mdx/platform/import-from-github.mdx.d.ts +1 -1
  109. package/dist/templates/mdx/platform/import-from-github.mdx.js +2 -2
  110. package/dist/templates/mdx/platform/index.mdx.d.ts +1 -1
  111. package/dist/templates/mdx/platform/index.mdx.js +1 -0
  112. package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
  113. package/dist/templates/mdx/platform/mcp.mdx.js +2 -1
  114. package/dist/templates/mdx/platform/navigation-settings.mdx.d.ts +1 -1
  115. package/dist/templates/mdx/platform/navigation-settings.mdx.js +12 -1
  116. package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
  117. package/dist/templates/mdx/platform/publishing.mdx.js +43 -10
  118. package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
  119. package/dist/templates/mdx/platform/self-updating-docs.mdx.js +48 -9
  120. package/dist/templates/mdx/sections.mdx.d.ts +1 -1
  121. package/dist/templates/mdx/sections.mdx.js +4 -0
  122. package/dist/templates/mdx/space.mdx.d.ts +1 -0
  123. package/dist/templates/mdx/space.mdx.js +125 -0
  124. package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
  125. package/dist/templates/mdx/tabs.mdx.js +4 -0
  126. package/dist/templates/next.config.js +20 -8
  127. package/dist/templates/package.js +3 -3
  128. package/dist/templates/prettierignore.d.ts +1 -1
  129. package/dist/templates/prettierignore.js +1 -0
  130. package/dist/templates/proxy.js +47 -19
  131. package/dist/templates/scripts/build-docs-index.d.ts +1 -1
  132. package/dist/templates/scripts/build-docs-index.js +1 -0
  133. package/dist/templates/services/mcp/docsContentStub.d.ts +1 -0
  134. package/dist/templates/services/mcp/docsContentStub.js +1 -0
  135. package/dist/templates/services/mcp/server.d.ts +1 -1
  136. package/dist/templates/services/mcp/server.js +140 -83
  137. package/dist/templates/services/mcp/tools.d.ts +1 -1
  138. package/dist/templates/services/mcp/tools.js +65 -137
  139. package/dist/templates/utils/playgroundAllowlist.d.ts +1 -1
  140. package/dist/templates/utils/playgroundAllowlist.js +13 -4
  141. package/dist/templates/utils/rateLimit.d.ts +1 -1
  142. package/dist/templates/utils/rateLimit.js +40 -3
  143. package/dist/templates/utils/requestBody.d.ts +1 -0
  144. package/dist/templates/utils/requestBody.js +56 -0
  145. package/dist/templates/utils/ssrfGuard.d.ts +1 -1
  146. package/dist/templates/utils/ssrfGuard.js +138 -33
  147. package/package.json +14 -9
  148. package/dist/lib/mdxToMarkdown.d.ts +0 -1
  149. package/dist/lib/mdxToMarkdown.js +0 -134
  150. package/dist/templates/mdx/image-and-embeds.mdx.d.ts +0 -1
  151. package/dist/templates/mdx/image-and-embeds.mdx.js +0 -118
@@ -1,4 +1,5 @@
1
1
  import type { DoccupineConfig, NormalizedOpenApiSpec } from "./types.js";
2
+ export declare function validateConfig(value: unknown, rootDir?: string): DoccupineConfig;
2
3
  /**
3
4
  * Collapses every accepted `openapi` config shape (a single path, a list of
4
5
  * paths, or named-spec objects) into a uniform `NormalizedOpenApiSpec[]`. Names
@@ -2,6 +2,63 @@ import fs from "fs-extra";
2
2
  import path from "path";
3
3
  import chalk from "chalk";
4
4
  import prompts from "prompts";
5
+ import { isPathInside } from "./output-safety.js";
6
+ function pathsOverlap(a, b) {
7
+ return isPathInside(a, b) || isPathInside(b, a);
8
+ }
9
+ function isValidOpenApiConfig(value) {
10
+ if (value === undefined || typeof value === "string")
11
+ return true;
12
+ if (!Array.isArray(value))
13
+ return false;
14
+ return value.every((entry) => typeof entry === "string" ||
15
+ (entry !== null &&
16
+ typeof entry === "object" &&
17
+ typeof entry.file === "string" &&
18
+ (entry.name === undefined ||
19
+ typeof entry.name === "string")));
20
+ }
21
+ export function validateConfig(value, rootDir = process.cwd()) {
22
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
23
+ throw new Error("doccupine.json must contain a JSON object.");
24
+ }
25
+ const config = value;
26
+ if (typeof config.watchDir !== "string" || !config.watchDir.trim()) {
27
+ throw new Error("doccupine.json watchDir must be a non-empty string.");
28
+ }
29
+ if (typeof config.outputDir !== "string" || !config.outputDir.trim()) {
30
+ throw new Error("doccupine.json outputDir must be a non-empty string.");
31
+ }
32
+ const watchDir = path.resolve(rootDir, config.watchDir);
33
+ const outputDir = path.resolve(rootDir, config.outputDir);
34
+ if (outputDir === path.resolve(rootDir)) {
35
+ throw new Error("outputDir cannot be the project root.");
36
+ }
37
+ if (pathsOverlap(watchDir, outputDir)) {
38
+ throw new Error("watchDir and outputDir must not overlap.");
39
+ }
40
+ const port = config.port ?? "3000";
41
+ if (typeof port !== "string" ||
42
+ !/^\d+$/.test(port) ||
43
+ Number(port) < 1 ||
44
+ Number(port) > 65535) {
45
+ throw new Error("doccupine.json port must be an integer from 1 to 65535.");
46
+ }
47
+ if (config.packageManager !== undefined &&
48
+ config.packageManager !== "npm" &&
49
+ config.packageManager !== "pnpm") {
50
+ throw new Error('packageManager must be either "npm" or "pnpm".');
51
+ }
52
+ if (!isValidOpenApiConfig(config.openapi)) {
53
+ throw new Error("openapi must be a path or an array of paths/{ name, file } objects.");
54
+ }
55
+ return {
56
+ ...config,
57
+ watchDir: config.watchDir,
58
+ outputDir: config.outputDir,
59
+ port,
60
+ };
61
+ }
5
62
  /** Strips a `.json`/`.yaml`/`.yml` extension to derive a spec's default name. */
6
63
  function basenameWithoutExt(file) {
7
64
  return path.basename(file).replace(/\.(json|ya?ml)$/i, "");
@@ -127,13 +184,15 @@ export class ConfigManager {
127
184
  try {
128
185
  if (await fs.pathExists(this.configPath)) {
129
186
  const configContent = await fs.readFile(this.configPath, "utf8");
130
- const config = JSON.parse(configContent);
187
+ const config = validateConfig(JSON.parse(configContent));
131
188
  console.log(chalk.blue("📄 Using existing configuration from doccupine.json"));
132
189
  return config;
133
190
  }
134
191
  }
135
192
  catch (error) {
136
- console.warn(chalk.yellow("⚠️ Error reading config file, will create new one"));
193
+ if (await fs.pathExists(this.configPath)) {
194
+ throw new Error(`Unable to use ${this.configPath}: ${error instanceof Error ? error.message : String(error)}. Run "doccupine config --reset" to repair the configuration.`);
195
+ }
137
196
  }
138
197
  return null;
139
198
  }
@@ -200,7 +259,7 @@ export class ConfigManager {
200
259
  }
201
260
  if (!config || options.reset) {
202
261
  console.log(chalk.blue("🔧 Setting up Doccupine configuration..."));
203
- config = await this.promptForConfig(config || {});
262
+ config = validateConfig(await this.promptForConfig(config || {}));
204
263
  dirty = true;
205
264
  }
206
265
  else {
@@ -217,6 +276,7 @@ export class ConfigManager {
217
276
  config.port = options.port;
218
277
  dirty = true;
219
278
  }
279
+ config = validateConfig(config);
220
280
  if (dirty) {
221
281
  await this.saveConfig(config);
222
282
  }
@@ -0,0 +1,26 @@
1
+ export type RouteOwnerKind = "mdx" | "openapi";
2
+ interface RouteArtifact {
3
+ kind: RouteOwnerKind;
4
+ source: string;
5
+ slug: string;
6
+ }
7
+ export declare class GeneratedArtifacts {
8
+ private readonly outputDir;
9
+ private routes;
10
+ private llmsFiles;
11
+ constructor(outputDir: string);
12
+ private manifestPath;
13
+ private routeKey;
14
+ load(): Promise<void>;
15
+ routeFor(kind: RouteOwnerKind, source: string): string | undefined;
16
+ routesFor(kind: RouteOwnerKind): RouteArtifact[];
17
+ replaceRoutes(kind: RouteOwnerKind, routes: Iterable<{
18
+ source: string;
19
+ slug: string;
20
+ }>): void;
21
+ removeRoute(kind: RouteOwnerKind, source: string): void;
22
+ llmsPageFiles(): Set<string>;
23
+ replaceLlmsPageFiles(files: Iterable<string>): void;
24
+ save(): Promise<void>;
25
+ }
26
+ export {};
@@ -0,0 +1,147 @@
1
+ import fs from "fs-extra";
2
+ import path from "node:path";
3
+ import { readOutputFileIfPresent, resolveOutputPath } from "./output-safety.js";
4
+ import { writeFileAtomic } from "./utils.js";
5
+ const MANIFEST_FILE = ".doccupine-artifacts.json";
6
+ const LEGACY_LLMS_MANIFEST = ".doccupine-llms-manifest.json";
7
+ const LEGACY_API_MANIFEST = ".doccupine-api-manifest.json";
8
+ function normalizeRelativePath(value, allowEmpty = false) {
9
+ const normalized = value.replace(/\\/g, "/").replace(/^\.\//, "");
10
+ if ((allowEmpty && normalized === "") || normalized === "") {
11
+ return allowEmpty ? "" : null;
12
+ }
13
+ if (path.posix.isAbsolute(normalized))
14
+ return null;
15
+ const parts = normalized.split("/");
16
+ if (parts.some((part) => part === "" || part === "." || part === "..")) {
17
+ return null;
18
+ }
19
+ return normalized;
20
+ }
21
+ function normalizeRoute(value) {
22
+ if (!value || typeof value !== "object")
23
+ return null;
24
+ const route = value;
25
+ if (route.kind !== "mdx" && route.kind !== "openapi")
26
+ return null;
27
+ if (typeof route.source !== "string" || typeof route.slug !== "string") {
28
+ return null;
29
+ }
30
+ const source = normalizeRelativePath(route.source);
31
+ const slug = normalizeRelativePath(route.slug, true);
32
+ return source === null || slug === null
33
+ ? null
34
+ : { kind: route.kind, source, slug };
35
+ }
36
+ function normalizeLlmsPageFile(value) {
37
+ if (typeof value !== "string")
38
+ return null;
39
+ const normalized = normalizeRelativePath(value);
40
+ return normalized?.endsWith(".md") ? normalized : null;
41
+ }
42
+ export class GeneratedArtifacts {
43
+ outputDir;
44
+ routes = new Map();
45
+ llmsFiles = new Set();
46
+ constructor(outputDir) {
47
+ this.outputDir = outputDir;
48
+ }
49
+ manifestPath(fileName) {
50
+ return resolveOutputPath(this.outputDir, fileName);
51
+ }
52
+ routeKey(kind, source) {
53
+ return `${kind}:${source.replace(/\\/g, "/")}`;
54
+ }
55
+ async load() {
56
+ this.routes.clear();
57
+ this.llmsFiles.clear();
58
+ const manifestContent = await readOutputFileIfPresent(this.outputDir, MANIFEST_FILE);
59
+ if (manifestContent !== null) {
60
+ try {
61
+ const parsed = JSON.parse(manifestContent);
62
+ if (Array.isArray(parsed.routes)) {
63
+ for (const value of parsed.routes) {
64
+ const route = normalizeRoute(value);
65
+ if (route)
66
+ this.routes.set(this.routeKey(route.kind, route.source), route);
67
+ }
68
+ }
69
+ if (Array.isArray(parsed.llmsPageFiles)) {
70
+ for (const value of parsed.llmsPageFiles) {
71
+ const file = normalizeLlmsPageFile(value);
72
+ if (file)
73
+ this.llmsFiles.add(file);
74
+ }
75
+ }
76
+ }
77
+ catch {
78
+ // A corrupt manifest owns nothing. Generated output is rebuilt safely.
79
+ }
80
+ }
81
+ // Import only valid paths from the old llms manifest. This preserves stale
82
+ // mirror cleanup across upgrades without trusting its historical contents.
83
+ const legacyContent = await readOutputFileIfPresent(this.outputDir, LEGACY_LLMS_MANIFEST);
84
+ if (legacyContent !== null) {
85
+ try {
86
+ const parsed = JSON.parse(legacyContent);
87
+ if (Array.isArray(parsed.pageFiles)) {
88
+ for (const value of parsed.pageFiles) {
89
+ const file = normalizeLlmsPageFile(value);
90
+ if (file)
91
+ this.llmsFiles.add(file);
92
+ }
93
+ }
94
+ }
95
+ catch {
96
+ // Ignore corrupt legacy state.
97
+ }
98
+ }
99
+ await Promise.all([
100
+ fs.remove(this.manifestPath(LEGACY_LLMS_MANIFEST)),
101
+ fs.remove(this.manifestPath(LEGACY_API_MANIFEST)),
102
+ ]);
103
+ }
104
+ routeFor(kind, source) {
105
+ return this.routes.get(this.routeKey(kind, source))?.slug;
106
+ }
107
+ routesFor(kind) {
108
+ return [...this.routes.values()].filter((route) => route.kind === kind);
109
+ }
110
+ replaceRoutes(kind, routes) {
111
+ for (const [key, route] of this.routes) {
112
+ if (route.kind === kind)
113
+ this.routes.delete(key);
114
+ }
115
+ for (const value of routes) {
116
+ const route = normalizeRoute({ kind, ...value });
117
+ if (!route) {
118
+ throw new Error(`Refusing to record unsafe ${kind} route ownership`);
119
+ }
120
+ this.routes.set(this.routeKey(kind, route.source), route);
121
+ }
122
+ }
123
+ removeRoute(kind, source) {
124
+ this.routes.delete(this.routeKey(kind, source));
125
+ }
126
+ llmsPageFiles() {
127
+ return new Set(this.llmsFiles);
128
+ }
129
+ replaceLlmsPageFiles(files) {
130
+ const next = new Set();
131
+ for (const value of files) {
132
+ const file = normalizeLlmsPageFile(value);
133
+ if (!file)
134
+ throw new Error("Refusing to record an unsafe llms page path");
135
+ next.add(file);
136
+ }
137
+ this.llmsFiles = next;
138
+ }
139
+ async save() {
140
+ const manifest = {
141
+ schemaVersion: 1,
142
+ routes: [...this.routes.values()].sort((a, b) => `${a.kind}:${a.source}`.localeCompare(`${b.kind}:${b.source}`)),
143
+ llmsPageFiles: [...this.llmsFiles].sort(),
144
+ };
145
+ await writeFileAtomic(this.manifestPath(MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
146
+ }
147
+ }
@@ -62,24 +62,25 @@ function fontDeclLine(fontConfig) {
62
62
  });`
63
63
  : 'const font = Inter({ subsets: ["latin"] });';
64
64
  }
65
- // The inline blocking script that resolves dark mode before first paint.
66
- // Adds the "dark" class to <html> (so the CSS variables emitted by
67
- // GlobalStyles paint dark immediately) and, on dark visits, injects a
68
- // "#__theme-init" style that hides the body AND forces a dark html
69
- // background: the server always renders with the light theme (pages are
70
- // force-static, so no cookie read), and Cherry's ClientThemeProvider
71
- // briefly re-syncs the "dark" class off the initial light theme during
72
- // mount, so without the forced background the html would flash white for a
73
- // frame. A second "__theme-transitions" style disables all transitions so
74
- // the light-to-dark swap on mount snaps instantly instead of animating every
75
- // element that declares a color transition. It can't live in "__theme-init":
76
- // the provider removes that in the same frame the dark colors commit, so the
77
- // browser would compute one light-to-dark style diff with transitions
78
- // re-enabled and animate it anyway. Instead a MutationObserver waits for the
79
- // provider to remove "__theme-init" (themeDark committed, body unhidden),
80
- // forces a reflow, and drops the transition suppression two painted frames
81
- // later — restoring transitions for user-initiated toggles.
82
- const THEME_INIT_SCRIPT = `(function(){try{var c=document.cookie.split(";").map(function(s){return s.trim();}).find(function(s){return s.indexOf("theme=")===0;});var v=c?c.split("=")[1]:null;var d=v?v==="dark":(window.matchMedia&&window.matchMedia("(prefers-color-scheme:dark)").matches);if(!v){document.cookie="theme="+(d?"dark":"light")+";path=/;max-age=31536000;SameSite=Lax";}if(d){document.documentElement.classList.add("dark");document.documentElement.style.colorScheme="dark";var s=document.createElement("style");s.id="__theme-init";s.textContent="html{background:#000!important;color-scheme:dark}body{visibility:hidden}";document.head.appendChild(s);var t=document.createElement("style");t.id="__theme-transitions";t.textContent="*,*::before,*::after{transition:none!important}";document.head.appendChild(t);var f=function(){var e=document.getElementById("__theme-transitions");if(!e)return;void document.body.offsetHeight;requestAnimationFrame(function(){requestAnimationFrame(function(){e.remove();});});};var o=new MutationObserver(function(){if(!document.getElementById("__theme-init")){o.disconnect();f();}});o.observe(document.head,{childList:true});setTimeout(f,10000);}else{document.documentElement.style.colorScheme="light";}}catch(e){}})();`;
65
+ // The inline blocking script that resolves dark mode before the first paint.
66
+ // It only has to decide the mode and record it on <html>: every painted color
67
+ // in the app resolves through the CSS custom properties that GlobalStyles
68
+ // emits under :root and :root[data-theme="dark"], so that one attribute is
69
+ // enough to make a statically rendered page arrive dark. Nothing is hidden and
70
+ // nothing waits for hydration — the markup streams and paints in the right
71
+ // theme exactly like a light visit does.
72
+ //
73
+ // The mode lives on our own data-theme attribute rather than on the "dark"
74
+ // class, because that class belongs to Cherry's ClientThemeProvider, which
75
+ // syncs it from the theme object: releases before 0.2.12 strip it for a frame
76
+ // on mount, since the server render is always the light theme, and every color
77
+ // on the page would flash light with it. The class is still set here so CSS
78
+ // written against it — Cherry's own, or a user's — keeps working.
79
+ //
80
+ // The mode comes from the "theme" cookie, falling back to the OS preference
81
+ // and seeding the cookie so Cherry's ClientThemeProvider reconciles against
82
+ // the same answer on mount instead of flipping the class back.
83
+ const THEME_INIT_SCRIPT = `(function(){try{var c=document.cookie.split(";").map(function(s){return s.trim();}).find(function(s){return s.indexOf("theme=")===0;});var v=c?c.split("=")[1]:null;var d=v?v==="dark":(window.matchMedia&&window.matchMedia("(prefers-color-scheme:dark)").matches);if(!v){document.cookie="theme="+(d?"dark":"light")+";path=/;max-age=31536000;SameSite=Lax";}var r=document.documentElement;r.dataset.theme=d?"dark":"light";if(d){r.classList.add("dark");}}catch(e){}})();`;
83
84
  /**
84
85
  * Root layout ("app/layout.tsx"). Minimal shell: html/body, fonts, the theme
85
86
  * provider stack, and (optionally) PostHog. It renders `children` directly so
@@ -133,16 +134,13 @@ export default function RootLayout({
133
134
  return (
134
135
  <html lang="en" suppressHydrationWarning>
135
136
  <head>
136
- {/* Resolves dark mode before first paint: adds the "dark" class to
137
- <html> (flipping the CSS variables in GlobalStyles) and hides the
138
- body until Cherry's ClientThemeProvider has swapped in themeDark
139
- on mount — the server always renders the light theme since pages
140
- are force-static. Inlined as a plain <script> (not next/script) so
141
- it ships in the SSR HTML and runs synchronously before paint —
142
- next/script with beforeInteractive is async in App Router and
143
- would still show a flash. suppressHydrationWarning on <html>
144
- tells React the class/colorScheme attributes are intentionally
145
- different between server (no class) and client (after script). */}
137
+ {/* Resolves dark mode before the first paint by stamping data-theme
138
+ on <html>, which flips the CSS variables in GlobalStyles.
139
+ Inlined as a plain <script> (not next/script) so it ships in the
140
+ SSR HTML and runs synchronously before paint — next/script with
141
+ beforeInteractive is async in App Router and would flash.
142
+ suppressHydrationWarning on <html> tells React the class is
143
+ intentionally different between server (none) and client. */}
146
144
  <script
147
145
  dangerouslySetInnerHTML={{
148
146
  __html: \`${THEME_INIT_SCRIPT}\`,
@@ -198,8 +196,10 @@ ${hasSections
198
196
  ? ""
199
197
  : `import { StaticLinks } from "@/components/layout/StaticLinks";
200
198
  `}import { verifyBrandingKey } from "@/utils/branding";
201
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
202
- import navigation from "@/navigation.json";
199
+ ${hasSections
200
+ ? ""
201
+ : `import navigation from "@/navigation.json";
202
+ `}
203
203
  ${hasSections
204
204
  ? `import { SectionBar } from "@/components/layout/SectionBar";
205
205
  import { SectionNavProvider } from "@/components/SectionNavProvider";
@@ -88,22 +88,34 @@ export function generateJsonLdScript(opts) {
88
88
  }
89
89
  function buildFieldExpression(staticValue, configKey, defaultValue) {
90
90
  if (staticValue)
91
- return staticValue;
92
- return `\${config.${configKey} || "${defaultValue}"}`;
91
+ return JSON.stringify(String(staticValue));
92
+ return `config.${configKey} || ${JSON.stringify(defaultValue)}`;
93
93
  }
94
94
  function buildTitleExpression(opts) {
95
- const title = opts.title || opts.titleFallback;
95
+ const title = String(opts.title || opts.titleFallback);
96
96
  if (opts.titleOrder === "page-first") {
97
- const suffix = opts.name
98
- ? `- ${opts.name}`
99
- : `\${config.name ? "- " + config.name : "- ${DEFAULT_SITE_NAME}"}`;
100
- return `${title} ${suffix}`;
97
+ if (opts.name) {
98
+ return JSON.stringify(`${title} - ${String(opts.name)}`);
99
+ }
100
+ return `[
101
+ ${JSON.stringify(title)},
102
+ config.name ? "- " + config.name : ${JSON.stringify(`- ${DEFAULT_SITE_NAME}`)},
103
+ ].join(" ")`;
101
104
  }
102
- // name-first
103
- const prefix = opts.name
104
- ? `${opts.name} -`
105
- : `\${config.name ? config.name + " -" : "${DEFAULT_SITE_NAME} -"}`;
106
- return `${prefix} ${title}`;
105
+ if (opts.name) {
106
+ return JSON.stringify(`${String(opts.name)} - ${title}`);
107
+ }
108
+ return `[
109
+ config.name ? config.name + " -" : ${JSON.stringify(`${DEFAULT_SITE_NAME} -`)},
110
+ ${JSON.stringify(title)},
111
+ ].join(" ")`;
112
+ }
113
+ function formatProperty(indent, name, expression) {
114
+ const prefix = " ".repeat(indent);
115
+ const inline = `${prefix}${name}: ${expression},`;
116
+ return inline.length <= 80
117
+ ? inline
118
+ : `${prefix}${name}:\n${prefix} ${expression},`;
107
119
  }
108
120
  function buildAlternatesBlock(canonicalPath, rssPath) {
109
121
  if (canonicalPath === undefined)
@@ -130,31 +142,47 @@ export function generateMetadataBlock(opts) {
130
142
  const icon = buildFieldExpression(opts.icon, "icon", DEFAULT_FAVICON);
131
143
  const image = buildFieldExpression(opts.image, "image", DEFAULT_OG_IMAGE);
132
144
  const canonical = buildAlternatesBlock(opts.canonicalPath, opts.rssPath);
133
- return `export const metadata: Metadata = {
134
- title: \`${title}\`,
135
- description: \`${desc}\`,
136
- icons: \`${icon}\`,${canonical}
145
+ const inlineTitleDeclaration = `const pageTitle = ${title};`;
146
+ const titleDeclaration = title.includes("\n") || inlineTitleDeclaration.length <= 80
147
+ ? inlineTitleDeclaration
148
+ : `const pageTitle =\n ${title};`;
149
+ const descriptionLine = formatProperty(2, "description", desc);
150
+ const iconLine = formatProperty(2, "icons", icon);
151
+ const openGraphDescriptionLine = formatProperty(4, "description", desc);
152
+ const imageLine = formatProperty(4, "images", image);
153
+ return `${titleDeclaration}
154
+
155
+ export const metadata: Metadata = {
156
+ title: pageTitle,
157
+ ${descriptionLine}
158
+ ${iconLine}${canonical}
137
159
  openGraph: {
138
- title: \`${title}\`,
139
- description: \`${desc}\`,
140
- images: \`${image}\`,
160
+ title: pageTitle,
161
+ ${openGraphDescriptionLine}
162
+ ${imageLine}
141
163
  },
142
164
  };`;
143
165
  }
144
166
  export function generateRuntimeOnlyMetadataBlock() {
145
- const title = `\${config.name || "${DEFAULT_SITE_NAME}"}`;
146
- const desc = `\${config.description || "${DEFAULT_META_DESCRIPTION}"}`;
147
- const icon = `\${config.icon || "${DEFAULT_FAVICON}"}`;
148
- const image = `\${config.image || "${DEFAULT_OG_IMAGE}"}`;
149
- return `export const metadata: Metadata = {
150
- title: \`${title}\`,
151
- description: \`${desc}\`,
152
- icons: \`${icon}\`,
167
+ const title = `config.name || ${JSON.stringify(DEFAULT_SITE_NAME)}`;
168
+ const desc = `config.description || ${JSON.stringify(DEFAULT_META_DESCRIPTION)}`;
169
+ const icon = `config.icon || ${JSON.stringify(DEFAULT_FAVICON)}`;
170
+ const image = `config.image || ${JSON.stringify(DEFAULT_OG_IMAGE)}`;
171
+ const descriptionLine = formatProperty(2, "description", desc);
172
+ const iconLine = formatProperty(2, "icons", icon);
173
+ const openGraphDescriptionLine = formatProperty(4, "description", desc);
174
+ const imageLine = formatProperty(4, "images", image);
175
+ return `const pageTitle = ${title};
176
+
177
+ export const metadata: Metadata = {
178
+ title: pageTitle,
179
+ ${descriptionLine}
180
+ ${iconLine}
153
181
  alternates: { canonical: "/" },
154
182
  openGraph: {
155
- title: \`${title}\`,
156
- description: \`${desc}\`,
157
- images: \`${image}\`,
183
+ title: pageTitle,
184
+ ${openGraphDescriptionLine}
185
+ ${imageLine}
158
186
  },
159
187
  };`;
160
188
  }
@@ -107,8 +107,8 @@ export interface OperationDescriptor {
107
107
  * A single entry in the request-execution allowlist emitted at build time from
108
108
  * the union of every spec's `servers[]`. The proxy route (server) and the
109
109
  * playground component (client) both read this to decide whether a target URL
110
- * may be called. `allowPrivate` is set ONLY when the spec's own declared server
111
- * host is itself a loopback/private/metadata literal (the local-dev case).
110
+ * may be called. `allowPrivate` is set ONLY for an explicit loopback server
111
+ * (the local-development case); other private and metadata targets stay blocked.
112
112
  */
113
113
  export interface AllowlistEntry {
114
114
  scheme: "http" | "https";
@@ -15,14 +15,16 @@ export declare function slugifySegment(input: string): string;
15
15
  * properties append their parent path: `param-body-user-address-city`.
16
16
  */
17
17
  export declare function buildParamAnchor(name: string, location: string, parentPath?: string[]): string;
18
+ export declare function isLocalOpenApiPath(reference: string): boolean;
18
19
  /**
19
20
  * Parses one or more OpenAPI specs and exposes everything the generator needs:
20
21
  * the operation descriptors, lookup indices for the MDX frontmatter path,
21
22
  * synthetic sidebar/sitemap `PageMeta` objects, per-endpoint markdown bodies
22
23
  * (for llms output), and the request-execution allowlist.
23
24
  *
24
- * `load()` never throws: a spec that fails to parse is logged and skipped so one
25
- * malformed file cannot abort a build or crash a watcher.
25
+ * `load()` is transactional: every configured spec must parse and process
26
+ * successfully before the current registry is replaced. A failed reload throws
27
+ * and leaves the last-known-good state available to callers.
26
28
  */
27
29
  export declare class OpenApiRegistry {
28
30
  private operations;
@@ -47,6 +49,7 @@ export declare class OpenApiRegistry {
47
49
  /**
48
50
  * Builds the MDX body for a generated endpoint page: the operation description,
49
51
  * followed by `<Field>` documentation for the parameters and request body, and
50
- * a schema/example code block per response. Rendered above the playground.
52
+ * a schema/example code block per response. Spec-derived strings are emitted
53
+ * only through serialized JSX expressions. Rendered above the playground.
51
54
  */
52
55
  export declare function buildEndpointDoc(op: OperationDescriptor): string;