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
@@ -0,0 +1,166 @@
1
+ import type { MDXFile, PageMeta, SectionConfig, FontConfig, AnalyticsConfig, NormalizedOpenApiSpec } from "./lib/types.js";
2
+ import type { OperationDescriptor } from "./lib/openapi-types.js";
3
+ export declare class MDXToNextJSGenerator {
4
+ private watchDir;
5
+ private outputDir;
6
+ private rootDir;
7
+ private watcher;
8
+ private configWatcher;
9
+ private fontWatcher;
10
+ private publicWatcher;
11
+ private rootDirWatcher;
12
+ private analyticsWatcher;
13
+ private openApiWatcher;
14
+ private doccupineConfigWatcher;
15
+ private doccupineConfigFile;
16
+ private configFiles;
17
+ private fontConfigFile;
18
+ private analyticsConfigFile;
19
+ private analyticsConfig;
20
+ private sectionsConfig;
21
+ /** Guards against recursive reprocessing when maybeUpdateSections() triggers processAllMDXFiles() */
22
+ private isReprocessing;
23
+ /** OpenAPI specs (build config) that drive the generated API reference. */
24
+ private openApiSpecs;
25
+ private apiBaseSlug;
26
+ private apiRegistry;
27
+ private artifacts;
28
+ /** Section slugs whose index redirect we wrote this session, for cleanup. */
29
+ private generatedSectionIndexSlugs;
30
+ /** Serializes watcher mutations so aggregate files never race one another. */
31
+ private mutationQueue;
32
+ constructor(watchDir: string, outputDir: string, openApiSpecs?: NormalizedOpenApiSpec[], rootDir?: string);
33
+ private outputPath;
34
+ private publicOutputFilePath;
35
+ private sourcePathError;
36
+ private realSourceRoot;
37
+ private readSafeSourceFile;
38
+ private readMdxSourceFile;
39
+ private ensureSafeStarterPath;
40
+ private copyRegularPublicFile;
41
+ private copyRootSourceFile;
42
+ private enqueueMutation;
43
+ init(): Promise<void>;
44
+ createNextJSStructure(): Promise<void>;
45
+ createStartingDocs(): Promise<void>;
46
+ copyCustomConfigFiles(): Promise<void>;
47
+ copyFontConfig(): Promise<void>;
48
+ loadFontConfig(): Promise<FontConfig | null>;
49
+ loadAnalyticsConfig(): Promise<AnalyticsConfig | null>;
50
+ copyAnalyticsConfig(): Promise<void>;
51
+ loadSectionsConfig(): Promise<SectionConfig[] | null>;
52
+ discoverSectionsFromFrontmatter(): Promise<SectionConfig[] | null>;
53
+ resolveSections(): Promise<SectionConfig[] | null>;
54
+ /**
55
+ * Promotes the generated OpenAPI endpoints into a dedicated "API Reference"
56
+ * section so they get their own top-level nav, separate from hand-written
57
+ * docs. When the site had no sections, a root "Documentation" section is added
58
+ * for the existing pages so both appear in the section switcher.
59
+ */
60
+ private withApiReferenceSection;
61
+ private reloadSections;
62
+ private maybeUpdateSections;
63
+ private determineSectionForFile;
64
+ handleConfigFileChange(filePath: string): Promise<void>;
65
+ handleConfigFileDelete(filePath: string): Promise<void>;
66
+ handleFontConfigChange(): Promise<void>;
67
+ handleFontConfigDelete(): Promise<void>;
68
+ handleAnalyticsConfigChange(): Promise<void>;
69
+ handleAnalyticsConfigDelete(): Promise<void>;
70
+ copyPublicFiles(): Promise<void>;
71
+ handlePublicFileChange(filePath: string): Promise<void>;
72
+ handlePublicFileDelete(filePath: string): Promise<void>;
73
+ startWatching(): Promise<void>;
74
+ private setupPublicWatcher;
75
+ private parseMDXFile;
76
+ private buildRealPagesMeta;
77
+ private buildAllPagesMeta;
78
+ private removeOwnedRoute;
79
+ private removeStaleMdxRoutes;
80
+ /**
81
+ * Writes the generated page(s) for a single MDX file: the doc page and, for a
82
+ * section-index file, the section landing page. Deliberately does NOT run the
83
+ * site-wide aggregations (pages index, layout, sitemap, llms, section
84
+ * redirects) - the caller batches those so a bulk build runs them once at the
85
+ * end instead of once per file (which is what made large builds O(n²)).
86
+ */
87
+ private writePageForFile;
88
+ /**
89
+ * Regenerates every file that depends on the full set of pages (pages index,
90
+ * root/site layout, sitemap, llms files, section redirects). Parses all MDX
91
+ * exactly once and threads the result through each generator, so one refresh
92
+ * is a single scan rather than one scan per generator.
93
+ */
94
+ private refreshSiteAggregates;
95
+ handleFileChange(action: string, filePath: string): Promise<void>;
96
+ handleFileDelete(filePath: string): Promise<void>;
97
+ processAllMDXFiles(): Promise<void>;
98
+ getAllMDXFiles(): Promise<string[]>;
99
+ generateRootLayout(): Promise<string>;
100
+ generateSiteLayout(pages?: PageMeta[]): Promise<string>;
101
+ generateSectionIndexPages(pages?: PageMeta[]): Promise<void>;
102
+ /**
103
+ * Removes section index redirects written earlier in this session whose
104
+ * section has since disappeared (e.g. the API Reference section after the
105
+ * `openapi` config is removed mid-watch). Only files that still contain the
106
+ * generated redirect are deleted, so a hand-written page that has taken
107
+ * over the slug is never touched. Fresh processes start clean anyway -
108
+ * init() wipes app/ - so in-session tracking is enough.
109
+ */
110
+ private cleanupStaleSectionIndexPages;
111
+ /** Best-effort removal of now-empty directories up to (not incl.) stopDir. */
112
+ private removeEmptyDirsUpTo;
113
+ generatePageFromMDX(mdxFile: MDXFile, options?: {
114
+ apiOperation?: OperationDescriptor;
115
+ }): Promise<void>;
116
+ /** Parses the configured OpenAPI spec(s) into the shared registry. */
117
+ private loadOpenApiRegistry;
118
+ /**
119
+ * Generates one page per OpenAPI operation, (re)writes the request-execution
120
+ * allowlist consumed by the playground proxy + component, and removes endpoint
121
+ * pages that no longer exist in the spec. Safe to call when there are no specs
122
+ * - it still emits an empty allowlist and prunes any previously generated
123
+ * pages (e.g. after the `openapi` config is removed).
124
+ */
125
+ private writeApiPages;
126
+ /** Writes the request-execution allowlist (overwrites the shipped stub). */
127
+ private writeApiAllowlist;
128
+ /** Removes endpoint page directories that are no longer in the spec. */
129
+ private cleanupStaleApiPages;
130
+ /**
131
+ * (Re)points the spec-file watcher at the currently configured spec paths.
132
+ * Called at startup and whenever doccupine.json changes the `openapi` set,
133
+ * so specs added mid-session are watched without a restart.
134
+ */
135
+ private syncOpenApiSpecWatcher;
136
+ /**
137
+ * Reparses the spec(s) and rewrites everything derived from them: the
138
+ * endpoint pages and allowlist, the sections (the "API Reference" section
139
+ * appears and disappears with the registry), and the site aggregates.
140
+ */
141
+ private rebuildApiReference;
142
+ /** Reparses the spec(s) and regenerates the API reference on a watch event. */
143
+ handleOpenApiChange(): Promise<void>;
144
+ /**
145
+ * Applies `openapi` edits in doccupine.json without a restart: reloads the
146
+ * registry, regenerates or prunes the endpoint pages and allowlist,
147
+ * refreshes nav/sitemap/llms, and re-points the spec-file watcher. Other
148
+ * fields (watchDir, outputDir, port) cannot be hot-applied, so a change
149
+ * there only logs a restart hint. Invalid or missing JSON (e.g. a
150
+ * half-written editor save) keeps the current configuration.
151
+ */
152
+ handleDoccupineConfigChange(): Promise<void>;
153
+ updatePagesIndex(): Promise<void>;
154
+ updateSectionIndex(sectionSlug: string, frontmatter: Record<string, any>, mdxContent: string, sourcePath?: string): Promise<void>;
155
+ updateRootLayout(pages?: PageMeta[]): Promise<void>;
156
+ loadSiteUrl(): Promise<string | null>;
157
+ private buildSitemapEntries;
158
+ updateSitemap(pages?: PageMeta[]): Promise<void>;
159
+ updateRobots(): Promise<void>;
160
+ private loadSiteMetadata;
161
+ private readPageWithBody;
162
+ private findSourcePublicAsset;
163
+ private writePublicAggregate;
164
+ updateLlmsFiles(pages?: PageMeta[]): Promise<void>;
165
+ stop(): Promise<void>;
166
+ }