doccupine 0.0.133 → 0.0.135
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/README.md +50 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +478 -45
- package/dist/lib/config-manager.d.ts +8 -1
- package/dist/lib/config-manager.js +98 -4
- package/dist/lib/metadata.d.ts +5 -0
- package/dist/lib/metadata.js +15 -4
- package/dist/lib/openapi-types.d.ts +120 -0
- package/dist/lib/openapi-types.js +14 -0
- package/dist/lib/openapi.d.ts +52 -0
- package/dist/lib/openapi.js +603 -0
- package/dist/lib/rss.d.ts +24 -0
- package/dist/lib/rss.js +137 -0
- package/dist/lib/structures.js +50 -4
- package/dist/lib/types.d.ts +22 -0
- package/dist/lib/utils.d.ts +8 -0
- package/dist/lib/utils.js +14 -0
- package/dist/templates/app/api/playground/route.d.ts +1 -0
- package/dist/templates/app/api/playground/route.js +199 -0
- package/dist/templates/app/rssRoute.d.ts +11 -0
- package/dist/templates/app/rssRoute.js +30 -0
- package/dist/templates/components/Docs.d.ts +1 -1
- package/dist/templates/components/Docs.js +15 -3
- package/dist/templates/components/MDXComponents.d.ts +1 -1
- package/dist/templates/components/MDXComponents.js +29 -0
- package/dist/templates/components/SideBar.d.ts +1 -1
- package/dist/templates/components/SideBar.js +13 -0
- package/dist/templates/components/layout/Accordion.d.ts +1 -1
- package/dist/templates/components/layout/Accordion.js +3 -2
- package/dist/templates/components/layout/ActionBar.d.ts +1 -1
- package/dist/templates/components/layout/ActionBar.js +65 -27
- package/dist/templates/components/layout/ApiPlayground.d.ts +1 -0
- package/dist/templates/components/layout/ApiPlayground.js +1075 -0
- package/dist/templates/components/layout/ApiPlaygroundDemo.d.ts +1 -0
- package/dist/templates/components/layout/ApiPlaygroundDemo.js +81 -0
- package/dist/templates/components/layout/Badge.d.ts +1 -0
- package/dist/templates/components/layout/Badge.js +455 -0
- package/dist/templates/components/layout/Code.d.ts +1 -1
- package/dist/templates/components/layout/Code.js +10 -22
- package/dist/templates/components/layout/CopyButton.d.ts +1 -0
- package/dist/templates/components/layout/CopyButton.js +68 -0
- package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
- package/dist/templates/components/layout/DocsComponents.js +14 -0
- package/dist/templates/components/layout/Mermaid.d.ts +1 -1
- package/dist/templates/components/layout/Mermaid.js +21 -3
- package/dist/templates/components/layout/Prompt.d.ts +1 -0
- package/dist/templates/components/layout/Prompt.js +149 -0
- package/dist/templates/components/layout/SharedStyles.d.ts +1 -1
- package/dist/templates/components/layout/SharedStyles.js +0 -4
- package/dist/templates/components/layout/Steps.d.ts +1 -1
- package/dist/templates/components/layout/Steps.js +0 -1
- package/dist/templates/components/layout/Tooltip.d.ts +1 -0
- package/dist/templates/components/layout/Tooltip.js +222 -0
- package/dist/templates/components/layout/Tree.d.ts +1 -0
- package/dist/templates/components/layout/Tree.js +322 -0
- package/dist/templates/components/layout/TreeData.d.ts +1 -0
- package/dist/templates/components/layout/TreeData.js +131 -0
- package/dist/templates/components/layout/Update.d.ts +1 -1
- package/dist/templates/components/layout/Update.js +5 -1
- package/dist/templates/lib/rss.d.ts +1 -0
- package/dist/templates/lib/rss.js +78 -0
- package/dist/templates/mdx/accordion.mdx.d.ts +1 -1
- package/dist/templates/mdx/accordion.mdx.js +19 -1
- package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/ai-assistant.mdx.js +3 -2
- package/dist/templates/mdx/analytics.mdx.d.ts +1 -1
- package/dist/templates/mdx/analytics.mdx.js +2 -2
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -0
- package/dist/templates/mdx/api-playground.mdx.js +158 -0
- package/dist/templates/mdx/authentication.mdx.d.ts +1 -1
- package/dist/templates/mdx/authentication.mdx.js +3 -3
- package/dist/templates/mdx/badges.mdx.d.ts +1 -0
- package/dist/templates/mdx/badges.mdx.js +237 -0
- package/dist/templates/mdx/buttons.mdx.d.ts +1 -1
- package/dist/templates/mdx/buttons.mdx.js +1 -1
- package/dist/templates/mdx/callouts.mdx.d.ts +1 -1
- package/dist/templates/mdx/callouts.mdx.js +1 -1
- package/dist/templates/mdx/cards.mdx.d.ts +1 -1
- package/dist/templates/mdx/cards.mdx.js +1 -1
- package/dist/templates/mdx/color-swatches.mdx.d.ts +1 -1
- package/dist/templates/mdx/color-swatches.mdx.js +1 -1
- package/dist/templates/mdx/columns.mdx.d.ts +1 -1
- package/dist/templates/mdx/columns.mdx.js +1 -1
- package/dist/templates/mdx/commands.mdx.d.ts +1 -1
- package/dist/templates/mdx/commands.mdx.js +3 -2
- package/dist/templates/mdx/components.mdx.d.ts +1 -1
- package/dist/templates/mdx/components.mdx.js +25 -10
- package/dist/templates/mdx/deployment-and-hosting.mdx.d.ts +1 -1
- package/dist/templates/mdx/deployment-and-hosting.mdx.js +4 -3
- package/dist/templates/mdx/fields.mdx.d.ts +1 -1
- package/dist/templates/mdx/fields.mdx.js +1 -1
- package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
- package/dist/templates/mdx/fonts.mdx.js +2 -2
- package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
- package/dist/templates/mdx/footer-links.mdx.js +1 -1
- package/dist/templates/mdx/frames.mdx.d.ts +1 -1
- package/dist/templates/mdx/frames.mdx.js +1 -1
- package/dist/templates/mdx/globals.mdx.d.ts +1 -1
- package/dist/templates/mdx/globals.mdx.js +1 -1
- package/dist/templates/mdx/icons.mdx.d.ts +1 -1
- package/dist/templates/mdx/icons.mdx.js +1 -1
- package/dist/templates/mdx/image-and-embeds.mdx.d.ts +1 -1
- package/dist/templates/mdx/image-and-embeds.mdx.js +1 -1
- package/dist/templates/mdx/images-and-embeds.mdx.d.ts +1 -0
- package/dist/templates/mdx/images-and-embeds.mdx.js +118 -0
- package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
- package/dist/templates/mdx/media-and-assets.mdx.js +2 -2
- package/dist/templates/mdx/mermaid.mdx.d.ts +1 -1
- package/dist/templates/mdx/mermaid.mdx.js +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.js +2 -2
- package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
- package/dist/templates/mdx/navigation.mdx.js +27 -12
- package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/ai-assistant.mdx.js +4 -3
- package/dist/templates/mdx/platform/analytics.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/analytics.mdx.js +2 -2
- package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/api-playground.mdx.js +62 -0
- package/dist/templates/mdx/platform/billing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/billing.mdx.js +1 -1
- package/dist/templates/mdx/platform/build-and-deploy.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/build-and-deploy.mdx.js +1 -1
- package/dist/templates/mdx/platform/creating-a-project.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/creating-a-project.mdx.js +12 -2
- package/dist/templates/mdx/platform/custom-domains.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/custom-domains.mdx.js +1 -1
- package/dist/templates/mdx/platform/fonts-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/fonts-settings.mdx.js +1 -1
- package/dist/templates/mdx/platform/footer-links.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/{external-links.mdx.js → footer-links.mdx.js} +5 -5
- package/dist/templates/mdx/platform/import-from-github.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/import-from-github.mdx.js +91 -0
- package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/mcp.mdx.js +3 -3
- package/dist/templates/mdx/platform/project-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/project-settings.mdx.js +1 -1
- package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/self-updating-docs.mdx.js +113 -0
- package/dist/templates/mdx/platform/team-members.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/team-members.mdx.js +1 -1
- package/dist/templates/mdx/prompt.mdx.d.ts +1 -0
- package/dist/templates/mdx/prompt.mdx.js +69 -0
- package/dist/templates/mdx/sections.mdx.d.ts +1 -1
- package/dist/templates/mdx/sections.mdx.js +1 -1
- package/dist/templates/mdx/steps.mdx.d.ts +1 -1
- package/dist/templates/mdx/steps.mdx.js +1 -1
- package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
- package/dist/templates/mdx/tabs.mdx.js +1 -1
- package/dist/templates/mdx/theme.mdx.d.ts +1 -1
- package/dist/templates/mdx/theme.mdx.js +1 -1
- package/dist/templates/mdx/tooltips.mdx.d.ts +1 -0
- package/dist/templates/mdx/tooltips.mdx.js +57 -0
- package/dist/templates/mdx/tree.mdx.d.ts +1 -0
- package/dist/templates/mdx/tree.mdx.js +158 -0
- package/dist/templates/mdx/update.mdx.d.ts +1 -1
- package/dist/templates/mdx/update.mdx.js +42 -2
- package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
- package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -1
- package/dist/templates/package.js +7 -7
- package/dist/templates/services/openapi/playgroundAllowlistStub.d.ts +1 -0
- package/dist/templates/services/openapi/playgroundAllowlistStub.js +4 -0
- package/dist/templates/types/openapi.d.ts +1 -0
- package/dist/templates/types/openapi.js +93 -0
- package/dist/templates/utils/apiSnippets.d.ts +1 -0
- package/dist/templates/utils/apiSnippets.js +94 -0
- package/dist/templates/utils/orderNavItems.d.ts +1 -1
- package/dist/templates/utils/orderNavItems.js +3 -0
- package/dist/templates/utils/playgroundAllowlist.d.ts +1 -0
- package/dist/templates/utils/playgroundAllowlist.js +70 -0
- package/dist/templates/utils/ssrfGuard.d.ts +1 -0
- package/dist/templates/utils/ssrfGuard.js +217 -0
- package/package.json +4 -3
- package/dist/templates/mdx/platform/external-links.mdx.d.ts +0 -1
package/dist/lib/rss.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Feed extraction for subscribable changelogs: pages that contain <Update>
|
|
2
|
+
// blocks publish an RSS feed at {page-url}/rss.xml.
|
|
3
|
+
//
|
|
4
|
+
// Anchor parity is the load-bearing constraint here. Feed entry links are
|
|
5
|
+
// `{pageUrl}#{anchor}`, and the anchor must byte-match the id the generated
|
|
6
|
+
// app assigns: one shared slugger walks the fenced-code-stripped document
|
|
7
|
+
// collecting markdown headings AND <Update label> open tags in byte order
|
|
8
|
+
// (components/Docs.tsx `extractHeadings` + components/MDXComponents.tsx).
|
|
9
|
+
// `slugify`/`createSlugger` below are byte-exact ports of the generated
|
|
10
|
+
// app's components/layout/Slug.ts, and `parseUpdateBlocks` replays that
|
|
11
|
+
// exact walk - headings consume slugger slots too, so an `## Setup` before
|
|
12
|
+
// `<Update label="Setup">` pushes the entry's anchor to "setup-1".
|
|
13
|
+
// rss.test.ts guards both ports against template drift.
|
|
14
|
+
export function slugify(text) {
|
|
15
|
+
return (text ?? "")
|
|
16
|
+
.toLowerCase()
|
|
17
|
+
.replace(/[^\w\s-]/g, "")
|
|
18
|
+
.replace(/\s+/g, "-")
|
|
19
|
+
.trim();
|
|
20
|
+
}
|
|
21
|
+
export function createSlugger() {
|
|
22
|
+
const seen = new Map();
|
|
23
|
+
return (text) => {
|
|
24
|
+
const base = slugify(text);
|
|
25
|
+
const count = seen.get(base) ?? 0;
|
|
26
|
+
seen.set(base, count + 1);
|
|
27
|
+
return count === 0 ? base : `${base}-${count}`;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function parseUpdateBlocks(mdx) {
|
|
31
|
+
// Fenced code is stripped before any matching, mirroring extractHeadings:
|
|
32
|
+
// an <Update> example inside a fence is not an entry, and positions below
|
|
33
|
+
// are measured in the stripped string on both sides of the parity contract.
|
|
34
|
+
const content = mdx.replace(/```[\s\S]*?```/g, "");
|
|
35
|
+
const entries = [];
|
|
36
|
+
let match;
|
|
37
|
+
const headingRegex = /^(#{1,6})\s+(.+)$/gm;
|
|
38
|
+
while ((match = headingRegex.exec(content)) !== null) {
|
|
39
|
+
entries.push({
|
|
40
|
+
kind: "heading",
|
|
41
|
+
text: match[2].trim(),
|
|
42
|
+
position: match.index,
|
|
43
|
+
tag: "",
|
|
44
|
+
tagEnd: 0,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// [^>] spans newlines, so multi-line open tags match - same as the app.
|
|
48
|
+
const updateRegex = /<Update\b[^>]*?\blabel=["']([^"']+)["'][^>]*>/g;
|
|
49
|
+
while ((match = updateRegex.exec(content)) !== null) {
|
|
50
|
+
entries.push({
|
|
51
|
+
kind: "update",
|
|
52
|
+
text: match[1].trim(),
|
|
53
|
+
position: match.index,
|
|
54
|
+
tag: match[0],
|
|
55
|
+
tagEnd: match.index + match[0].length,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
entries.sort((a, b) => a.position - b.position);
|
|
59
|
+
const slug = createSlugger();
|
|
60
|
+
const items = [];
|
|
61
|
+
for (const entry of entries) {
|
|
62
|
+
const anchor = slug(entry.text);
|
|
63
|
+
if (entry.kind !== "update")
|
|
64
|
+
continue;
|
|
65
|
+
const rssAttr = /\brss=["']([^"']*)["']/.exec(entry.tag)?.[1];
|
|
66
|
+
const inner = entry.tag.endsWith("/>")
|
|
67
|
+
? ""
|
|
68
|
+
: extractInner(content, entry.tagEnd);
|
|
69
|
+
items.push({
|
|
70
|
+
label: entry.text,
|
|
71
|
+
anchor,
|
|
72
|
+
description: rssAttr !== undefined ? rssAttr.trim() : toRssMarkdown(inner),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return items;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Slice out an Update block's children: scan from the end of its open tag to
|
|
79
|
+
* the matching close tag, tracking depth so nested <Update> blocks close
|
|
80
|
+
* correctly. An unclosed block runs to the end of the document (the renderer
|
|
81
|
+
* swallows the rest of the page in that case too).
|
|
82
|
+
*/
|
|
83
|
+
function extractInner(content, from) {
|
|
84
|
+
const token = /<Update\b[^>]*?>|<\/Update\s*>/g;
|
|
85
|
+
token.lastIndex = from;
|
|
86
|
+
let depth = 1;
|
|
87
|
+
let match;
|
|
88
|
+
while ((match = token.exec(content)) !== null) {
|
|
89
|
+
if (match[0].startsWith("</")) {
|
|
90
|
+
depth -= 1;
|
|
91
|
+
if (depth === 0)
|
|
92
|
+
return content.slice(from, match.index);
|
|
93
|
+
}
|
|
94
|
+
else if (!match[0].endsWith("/>")) {
|
|
95
|
+
depth += 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return content.slice(from);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Reduce an Update block's children to pure Markdown for feed readers:
|
|
102
|
+
* components, code, and HTML are removed (tag children text survives),
|
|
103
|
+
* images collapse to their alt text, inline code keeps its text. Markdown
|
|
104
|
+
* inline syntax (emphasis, links, lists, headings) passes through, including
|
|
105
|
+
* autolinks - `<https://...>` never matches the tag pattern because a `:`
|
|
106
|
+
* follows the leading word characters.
|
|
107
|
+
*/
|
|
108
|
+
export function toRssMarkdown(inner) {
|
|
109
|
+
const stripped = inner
|
|
110
|
+
.replace(/```[\s\S]*?```/g, "")
|
|
111
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
112
|
+
.replace(/<\/?[A-Za-z][a-zA-Z0-9]*(?:\s[^>]*)?\/?>/g, "")
|
|
113
|
+
.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1")
|
|
114
|
+
.replace(/`([^`]*)`/g, "$1");
|
|
115
|
+
return dedent(stripped)
|
|
116
|
+
.replace(/[ \t]+$/gm, "")
|
|
117
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
118
|
+
.trim();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Update children are conventionally indented under the open tag; strip the
|
|
122
|
+
* common leading indentation so lists and headings arrive at column 0.
|
|
123
|
+
*/
|
|
124
|
+
function dedent(text) {
|
|
125
|
+
const lines = text.split("\n");
|
|
126
|
+
let minIndent = Infinity;
|
|
127
|
+
for (const line of lines) {
|
|
128
|
+
if (line.trim() === "")
|
|
129
|
+
continue;
|
|
130
|
+
const indent = /^ */.exec(line)[0].length;
|
|
131
|
+
if (indent < minIndent)
|
|
132
|
+
minIndent = indent;
|
|
133
|
+
}
|
|
134
|
+
if (!Number.isFinite(minIndent) || minIndent === 0)
|
|
135
|
+
return text;
|
|
136
|
+
return lines.map((line) => line.slice(minIndent)).join("\n");
|
|
137
|
+
}
|
package/dist/lib/structures.js
CHANGED
|
@@ -33,6 +33,7 @@ import { spinnerTemplate } from "../templates/components/Spinner.js";
|
|
|
33
33
|
import { sectionBarTemplate } from "../templates/components/layout/SectionBar.js";
|
|
34
34
|
import { accordionTemplate } from "../templates/components/layout/Accordion.js";
|
|
35
35
|
import { actionBarTemplate } from "../templates/components/layout/ActionBar.js";
|
|
36
|
+
import { badgeTemplate } from "../templates/components/layout/Badge.js";
|
|
36
37
|
import { buttonTemplate } from "../templates/components/layout/Button.js";
|
|
37
38
|
import { calloutTemplate } from "../templates/components/layout/Callout.js";
|
|
38
39
|
import { cardTemplate } from "../templates/components/layout/Card.js";
|
|
@@ -50,6 +51,7 @@ import { globalStylesTemplate } from "../templates/components/layout/GlobalStyle
|
|
|
50
51
|
import { headerTemplate } from "../templates/components/layout/Header.js";
|
|
51
52
|
import { iconTemplate } from "../templates/components/layout/Icon.js";
|
|
52
53
|
import { pictogramsTemplate } from "../templates/components/layout/Pictograms.js";
|
|
54
|
+
import { promptTemplate } from "../templates/components/layout/Prompt.js";
|
|
53
55
|
import { sharedStyledTemplate } from "../templates/components/layout/SharedStyles.js";
|
|
54
56
|
import { notFoundComponentTemplate } from "../templates/components/layout/NotFound.js";
|
|
55
57
|
import { siteGateComponentTemplate } from "../templates/components/layout/SiteGate.js";
|
|
@@ -57,6 +59,9 @@ import { slugTemplate } from "../templates/components/layout/Slug.js";
|
|
|
57
59
|
import { staticLinksTemplate } from "../templates/components/layout/StaticLinks.js";
|
|
58
60
|
import { stepsTemplate } from "../templates/components/layout/Steps.js";
|
|
59
61
|
import { tabsTemplate } from "../templates/components/layout/Tabs.js";
|
|
62
|
+
import { tooltipTemplate } from "../templates/components/layout/Tooltip.js";
|
|
63
|
+
import { treeTemplate } from "../templates/components/layout/Tree.js";
|
|
64
|
+
import { treeDataTemplate } from "../templates/components/layout/TreeData.js";
|
|
60
65
|
import { typographyTemplate } from "../templates/components/layout/Typography.js";
|
|
61
66
|
import { updateTemplate } from "../templates/components/layout/Update.js";
|
|
62
67
|
import { searchServiceTemplate } from "../templates/services/search.js";
|
|
@@ -72,16 +77,28 @@ import { llmIndexTemplate } from "../templates/services/llm/index.js";
|
|
|
72
77
|
import { llmTypesTemplate } from "../templates/services/llm/types.js";
|
|
73
78
|
import { buildDocsIndexScriptTemplate } from "../templates/scripts/build-docs-index.js";
|
|
74
79
|
import { posthogServerTemplate } from "../templates/lib/posthog.js";
|
|
80
|
+
import { rssLibTemplate } from "../templates/lib/rss.js";
|
|
75
81
|
import { siteGateTemplate } from "../templates/lib/siteGate.js";
|
|
76
82
|
import { styledDTemplate } from "../templates/types/styled.js";
|
|
83
|
+
import { openapiTypesTemplate } from "../templates/types/openapi.js";
|
|
77
84
|
import { orderNavItemsTemplate } from "../templates/utils/orderNavItems.js";
|
|
78
85
|
import { rateLimitTemplate } from "../templates/utils/rateLimit.js";
|
|
79
86
|
import { brandingTemplate } from "../templates/utils/branding.js";
|
|
80
87
|
import { configTemplate } from "../templates/utils/config.js";
|
|
88
|
+
import { playgroundAllowlistTemplate } from "../templates/utils/playgroundAllowlist.js";
|
|
89
|
+
import { ssrfGuardTemplate } from "../templates/utils/ssrfGuard.js";
|
|
90
|
+
import { apiSnippetsTemplate } from "../templates/utils/apiSnippets.js";
|
|
91
|
+
import { playgroundRoutesTemplate } from "../templates/app/api/playground/route.js";
|
|
92
|
+
import { playgroundAllowlistStubTemplate } from "../templates/services/openapi/playgroundAllowlistStub.js";
|
|
93
|
+
import { copyButtonTemplate } from "../templates/components/layout/CopyButton.js";
|
|
94
|
+
import { apiPlaygroundTemplate } from "../templates/components/layout/ApiPlayground.js";
|
|
95
|
+
import { apiPlaygroundDemoTemplate } from "../templates/components/layout/ApiPlaygroundDemo.js";
|
|
81
96
|
import { accordionMdxTemplate } from "../templates/mdx/accordion.mdx.js";
|
|
82
97
|
import { aiAssistantMdxTemplate } from "../templates/mdx/ai-assistant.mdx.js";
|
|
83
98
|
import { analyticsMdxTemplate } from "../templates/mdx/analytics.mdx.js";
|
|
99
|
+
import { apiPlaygroundMdxTemplate } from "../templates/mdx/api-playground.mdx.js";
|
|
84
100
|
import { authenticationMdxTemplate } from "../templates/mdx/authentication.mdx.js";
|
|
101
|
+
import { badgesMdxTemplate } from "../templates/mdx/badges.mdx.js";
|
|
85
102
|
import { buttonsMdxTemplate } from "../templates/mdx/buttons.mdx.js";
|
|
86
103
|
import { calloutsMdxTemplate } from "../templates/mdx/callouts.mdx.js";
|
|
87
104
|
import { cardsMdxTemplate } from "../templates/mdx/cards.mdx.js";
|
|
@@ -96,7 +113,7 @@ import { fontsMdxTemplate } from "../templates/mdx/fonts.mdx.js";
|
|
|
96
113
|
import { globalsMdxTemplate } from "../templates/mdx/globals.mdx.js";
|
|
97
114
|
import { headersAndTextMdxTemplate } from "../templates/mdx/headers-and-text.mdx.js";
|
|
98
115
|
import { iconsMdxTemplate } from "../templates/mdx/icons.mdx.js";
|
|
99
|
-
import {
|
|
116
|
+
import { imagesAndEmbedsMdxTemplate } from "../templates/mdx/images-and-embeds.mdx.js";
|
|
100
117
|
import { indexMdxTemplate } from "../templates/mdx/index.mdx.js";
|
|
101
118
|
import { footerLinksMdxTemplate } from "../templates/mdx/footer-links.mdx.js";
|
|
102
119
|
import { framesMdxTemplate } from "../templates/mdx/frames.mdx.js";
|
|
@@ -105,22 +122,28 @@ import { mediaAndAssetsMdxTemplate } from "../templates/mdx/media-and-assets.mdx
|
|
|
105
122
|
import { mermaidMdxTemplate } from "../templates/mdx/mermaid.mdx.js";
|
|
106
123
|
import { mcpMdxTemplate } from "../templates/mdx/model-context-protocol.mdx.js";
|
|
107
124
|
import { navigationMdxTemplate } from "../templates/mdx/navigation.mdx.js";
|
|
125
|
+
import { promptMdxTemplate } from "../templates/mdx/prompt.mdx.js";
|
|
108
126
|
import { sectionsMdxTemplate } from "../templates/mdx/sections.mdx.js";
|
|
109
127
|
import { stepsMdxTemplate } from "../templates/mdx/steps.mdx.js";
|
|
110
128
|
import { tabsMdxTemplate } from "../templates/mdx/tabs.mdx.js";
|
|
111
129
|
import { themeMdxTemplate } from "../templates/mdx/theme.mdx.js";
|
|
130
|
+
import { tooltipsMdxTemplate } from "../templates/mdx/tooltips.mdx.js";
|
|
131
|
+
import { treeMdxTemplate } from "../templates/mdx/tree.mdx.js";
|
|
112
132
|
import { updateMdxTemplate } from "../templates/mdx/update.mdx.js";
|
|
113
133
|
import { whatIsDoccupineMdxTemplate } from "../templates/mdx/what-is-doccupine.mdx.js";
|
|
114
134
|
import { platformIndexMdxTemplate } from "../templates/mdx/platform/index.mdx.js";
|
|
115
135
|
import { platformFileEditorMdxTemplate } from "../templates/mdx/platform/file-editor.mdx.js";
|
|
116
136
|
import { platformPublishingMdxTemplate } from "../templates/mdx/platform/publishing.mdx.js";
|
|
117
137
|
import { platformCreatingAProjectMdxTemplate } from "../templates/mdx/platform/creating-a-project.mdx.js";
|
|
138
|
+
import { platformImportFromGithubMdxTemplate } from "../templates/mdx/platform/import-from-github.mdx.js";
|
|
139
|
+
import { platformSelfUpdatingDocsMdxTemplate } from "../templates/mdx/platform/self-updating-docs.mdx.js";
|
|
118
140
|
import { platformSiteSettingsMdxTemplate } from "../templates/mdx/platform/site-settings.mdx.js";
|
|
119
141
|
import { platformThemeSettingsMdxTemplate } from "../templates/mdx/platform/theme-settings.mdx.js";
|
|
120
142
|
import { platformNavigationSettingsMdxTemplate } from "../templates/mdx/platform/navigation-settings.mdx.js";
|
|
121
143
|
import { platformFontsSettingsMdxTemplate } from "../templates/mdx/platform/fonts-settings.mdx.js";
|
|
122
|
-
import {
|
|
144
|
+
import { platformFooterLinksMdxTemplate } from "../templates/mdx/platform/footer-links.mdx.js";
|
|
123
145
|
import { platformAnalyticsMdxTemplate } from "../templates/mdx/platform/analytics.mdx.js";
|
|
146
|
+
import { platformApiPlaygroundMdxTemplate } from "../templates/mdx/platform/api-playground.mdx.js";
|
|
124
147
|
import { platformAiAssistantMdxTemplate } from "../templates/mdx/platform/ai-assistant.mdx.js";
|
|
125
148
|
import { platformMcpMdxTemplate } from "../templates/mdx/platform/mcp.mdx.js";
|
|
126
149
|
import { platformCustomDomainsMdxTemplate } from "../templates/mdx/platform/custom-domains.mdx.js";
|
|
@@ -144,6 +167,7 @@ export const appStructure = {
|
|
|
144
167
|
"app/api/mcp/route.ts": mcpRoutesTemplate,
|
|
145
168
|
"app/api/rag/route.ts": ragRoutesTemplate,
|
|
146
169
|
"app/api/search/route.ts": searchRoutesTemplate,
|
|
170
|
+
"app/api/playground/route.ts": playgroundRoutesTemplate,
|
|
147
171
|
"services/search.ts": searchServiceTemplate,
|
|
148
172
|
"services/mcp/index.ts": mcpIndexTemplate,
|
|
149
173
|
"services/mcp/server.ts": mcpServerTemplate,
|
|
@@ -155,9 +179,12 @@ export const appStructure = {
|
|
|
155
179
|
"services/llm/factory.ts": llmFactoryTemplate,
|
|
156
180
|
"services/llm/index.ts": llmIndexTemplate,
|
|
157
181
|
"services/llm/types.ts": llmTypesTemplate,
|
|
182
|
+
"services/openapi/playground-allowlist.json": playgroundAllowlistStubTemplate,
|
|
158
183
|
"scripts/build-docs-index.mts": buildDocsIndexScriptTemplate,
|
|
159
184
|
"types/styled.d.ts": styledDTemplate,
|
|
185
|
+
"types/openapi.ts": openapiTypesTemplate,
|
|
160
186
|
"lib/posthog.ts": posthogServerTemplate,
|
|
187
|
+
"lib/rss.ts": rssLibTemplate,
|
|
161
188
|
"lib/siteGate.ts": siteGateTemplate,
|
|
162
189
|
"utils/branding.ts": brandingTemplate,
|
|
163
190
|
"utils/mermaid.ts": mermaidTemplate,
|
|
@@ -166,6 +193,9 @@ export const appStructure = {
|
|
|
166
193
|
"utils/rateLimit.ts": rateLimitTemplate,
|
|
167
194
|
"utils/rehypeCodeMeta.ts": rehypeCodeMetaTemplate,
|
|
168
195
|
"utils/config.ts": configTemplate,
|
|
196
|
+
"utils/playgroundAllowlist.ts": playgroundAllowlistTemplate,
|
|
197
|
+
"utils/ssrfGuard.ts": ssrfGuardTemplate,
|
|
198
|
+
"utils/apiSnippets.ts": apiSnippetsTemplate,
|
|
169
199
|
"components/Chat.tsx": chatTemplate,
|
|
170
200
|
"components/LockBodyScroll.ts": lockBodyScrollTemplate,
|
|
171
201
|
"components/Docs.tsx": docsTemplate,
|
|
@@ -181,12 +211,16 @@ export const appStructure = {
|
|
|
181
211
|
"components/Spinner.tsx": spinnerTemplate,
|
|
182
212
|
"components/layout/Accordion.tsx": accordionTemplate,
|
|
183
213
|
"components/layout/ActionBar.tsx": actionBarTemplate,
|
|
214
|
+
"components/layout/ApiPlayground.tsx": apiPlaygroundTemplate,
|
|
215
|
+
"components/layout/ApiPlaygroundDemo.tsx": apiPlaygroundDemoTemplate,
|
|
216
|
+
"components/layout/Badge.tsx": badgeTemplate,
|
|
184
217
|
"components/layout/Button.tsx": buttonTemplate,
|
|
185
218
|
"components/layout/Callout.tsx": calloutTemplate,
|
|
186
219
|
"components/layout/Card.tsx": cardTemplate,
|
|
187
220
|
"components/layout/CherryThemeProvider.tsx": cherryThemeProviderTemplate,
|
|
188
221
|
"components/layout/ColorSwatch.tsx": colorSwatchTemplate,
|
|
189
222
|
"components/layout/Code.tsx": codeTemplate,
|
|
223
|
+
"components/layout/CopyButton.tsx": copyButtonTemplate,
|
|
190
224
|
"components/layout/Columns.tsx": columnsTemplate,
|
|
191
225
|
"components/layout/DemoTheme.tsx": demoThemeTemplate,
|
|
192
226
|
"components/layout/DocsComponents.tsx": docsComponentsTemplate,
|
|
@@ -200,6 +234,7 @@ export const appStructure = {
|
|
|
200
234
|
"components/layout/Icon.tsx": iconTemplate,
|
|
201
235
|
"components/layout/Mermaid.tsx": mermaidViewTemplate,
|
|
202
236
|
"components/layout/Pictograms.tsx": pictogramsTemplate,
|
|
237
|
+
"components/layout/Prompt.tsx": promptTemplate,
|
|
203
238
|
"components/layout/SharedStyled.ts": sharedStyledTemplate,
|
|
204
239
|
"components/layout/NotFound.tsx": notFoundComponentTemplate,
|
|
205
240
|
"components/layout/SiteGate.tsx": siteGateComponentTemplate,
|
|
@@ -207,6 +242,9 @@ export const appStructure = {
|
|
|
207
242
|
"components/layout/StaticLinks.tsx": staticLinksTemplate,
|
|
208
243
|
"components/layout/Steps.tsx": stepsTemplate,
|
|
209
244
|
"components/layout/Tabs.tsx": tabsTemplate,
|
|
245
|
+
"components/layout/Tooltip.tsx": tooltipTemplate,
|
|
246
|
+
"components/layout/Tree.tsx": treeTemplate,
|
|
247
|
+
"components/layout/TreeData.ts": treeDataTemplate,
|
|
210
248
|
"components/layout/Typography.ts": typographyTemplate,
|
|
211
249
|
"components/layout/Update.tsx": updateTemplate,
|
|
212
250
|
};
|
|
@@ -223,7 +261,9 @@ export const startingDocsStructure = {
|
|
|
223
261
|
"accordion.mdx": accordionMdxTemplate,
|
|
224
262
|
"ai-assistant.mdx": aiAssistantMdxTemplate,
|
|
225
263
|
"analytics.mdx": analyticsMdxTemplate,
|
|
264
|
+
"api-playground.mdx": apiPlaygroundMdxTemplate,
|
|
226
265
|
"authentication.mdx": authenticationMdxTemplate,
|
|
266
|
+
"badges.mdx": badgesMdxTemplate,
|
|
227
267
|
"buttons.mdx": buttonsMdxTemplate,
|
|
228
268
|
"callouts.mdx": calloutsMdxTemplate,
|
|
229
269
|
"cards.mdx": cardsMdxTemplate,
|
|
@@ -238,7 +278,7 @@ export const startingDocsStructure = {
|
|
|
238
278
|
"globals.mdx": globalsMdxTemplate,
|
|
239
279
|
"headers-and-text.mdx": headersAndTextMdxTemplate,
|
|
240
280
|
"icons.mdx": iconsMdxTemplate,
|
|
241
|
-
"
|
|
281
|
+
"images-and-embeds.mdx": imagesAndEmbedsMdxTemplate,
|
|
242
282
|
"index.mdx": indexMdxTemplate,
|
|
243
283
|
"footer-links.mdx": footerLinksMdxTemplate,
|
|
244
284
|
"frames.mdx": framesMdxTemplate,
|
|
@@ -247,24 +287,30 @@ export const startingDocsStructure = {
|
|
|
247
287
|
"mermaid.mdx": mermaidMdxTemplate,
|
|
248
288
|
"model-context-protocol.mdx": mcpMdxTemplate,
|
|
249
289
|
"navigation.mdx": navigationMdxTemplate,
|
|
290
|
+
"prompt.mdx": promptMdxTemplate,
|
|
250
291
|
"sections.mdx": sectionsMdxTemplate,
|
|
251
292
|
"steps.mdx": stepsMdxTemplate,
|
|
252
293
|
"tabs.mdx": tabsMdxTemplate,
|
|
253
294
|
"theme.mdx": themeMdxTemplate,
|
|
295
|
+
"tooltips.mdx": tooltipsMdxTemplate,
|
|
296
|
+
"tree.mdx": treeMdxTemplate,
|
|
254
297
|
"update.mdx": updateMdxTemplate,
|
|
255
298
|
"what-is-doccupine.mdx": whatIsDoccupineMdxTemplate,
|
|
256
299
|
"platform/index.mdx": platformIndexMdxTemplate,
|
|
257
300
|
"platform/file-editor.mdx": platformFileEditorMdxTemplate,
|
|
258
301
|
"platform/publishing.mdx": platformPublishingMdxTemplate,
|
|
259
302
|
"platform/creating-a-project.mdx": platformCreatingAProjectMdxTemplate,
|
|
303
|
+
"platform/import-from-github.mdx": platformImportFromGithubMdxTemplate,
|
|
304
|
+
"platform/self-updating-docs.mdx": platformSelfUpdatingDocsMdxTemplate,
|
|
260
305
|
"platform/site-settings.mdx": platformSiteSettingsMdxTemplate,
|
|
261
306
|
"platform/theme-settings.mdx": platformThemeSettingsMdxTemplate,
|
|
262
307
|
"platform/navigation-settings.mdx": platformNavigationSettingsMdxTemplate,
|
|
263
308
|
"platform/fonts-settings.mdx": platformFontsSettingsMdxTemplate,
|
|
264
|
-
"platform/
|
|
309
|
+
"platform/footer-links.mdx": platformFooterLinksMdxTemplate,
|
|
265
310
|
"platform/analytics.mdx": platformAnalyticsMdxTemplate,
|
|
266
311
|
"platform/ai-assistant.mdx": platformAiAssistantMdxTemplate,
|
|
267
312
|
"platform/mcp.mdx": platformMcpMdxTemplate,
|
|
313
|
+
"platform/api-playground.mdx": platformApiPlaygroundMdxTemplate,
|
|
268
314
|
"platform/custom-domains.mdx": platformCustomDomainsMdxTemplate,
|
|
269
315
|
"platform/build-and-deploy.mdx": platformBuildAndDeployMdxTemplate,
|
|
270
316
|
"platform/team-members.mdx": platformTeamMembersMdxTemplate,
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export interface PageMeta {
|
|
|
17
17
|
navIcon?: string;
|
|
18
18
|
categoryIcon?: string;
|
|
19
19
|
lastModified?: string;
|
|
20
|
+
/** HTTP verb (e.g. "GET") for synthetic OpenAPI endpoint pages. Set only on
|
|
21
|
+
* generated API-reference pages so the sidebar can render a method badge;
|
|
22
|
+
* omitted on hand-written MDX pages so their serialized nav objects are
|
|
23
|
+
* unchanged. */
|
|
24
|
+
httpMethod?: string;
|
|
20
25
|
}
|
|
21
26
|
export interface SectionConfig {
|
|
22
27
|
label: string;
|
|
@@ -31,6 +36,23 @@ export interface DoccupineConfig {
|
|
|
31
36
|
* ("pnpm" or "npm"), overriding auto-detection. Also settable per run via
|
|
32
37
|
* the `--package-manager` flag, which takes precedence over this field. */
|
|
33
38
|
packageManager?: string;
|
|
39
|
+
/** Optional OpenAPI spec(s) that drive the generated API reference section.
|
|
40
|
+
* Accepts a single path, a list of paths, or named-spec objects; all forms
|
|
41
|
+
* are normalized to `NormalizedOpenApiSpec[]` internally. */
|
|
42
|
+
openapi?: string | string[] | OpenApiSpecConfig[];
|
|
43
|
+
}
|
|
44
|
+
/** A named OpenAPI spec entry as authored in `doccupine.json`. */
|
|
45
|
+
export interface OpenApiSpecConfig {
|
|
46
|
+
/** Display/namespace name; defaults to the file basename when omitted. Used
|
|
47
|
+
* as the sidebar section and route namespace when more than one spec. */
|
|
48
|
+
name?: string;
|
|
49
|
+
/** Path to a `.json`/`.yaml`/`.yml` OpenAPI document, project-relative. */
|
|
50
|
+
file: string;
|
|
51
|
+
}
|
|
52
|
+
/** Internal, fully-resolved form every `openapi` config shape collapses to. */
|
|
53
|
+
export interface NormalizedOpenApiSpec {
|
|
54
|
+
name: string;
|
|
55
|
+
file: string;
|
|
34
56
|
}
|
|
35
57
|
export interface FontConfig {
|
|
36
58
|
[key: string]: any;
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -18,3 +18,11 @@ export declare function findAvailablePort(startPort: number): Promise<number>;
|
|
|
18
18
|
export declare function generateSlug(filePath: string): string;
|
|
19
19
|
export declare function getFullSlug(pageSlug: string, sectionSlug: string): string;
|
|
20
20
|
export declare function escapeTemplateContent(content: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Renders `value` as a JS string literal using the same quote Prettier would
|
|
23
|
+
* choose: double by default, switching to single when that needs fewer escapes
|
|
24
|
+
* (JSON text, for instance, is full of `"`). Backslashes and the chosen quote
|
|
25
|
+
* are escaped. Lets generated code embed a string in a form Prettier leaves
|
|
26
|
+
* untouched, so emitted files stay format-stable without running a formatter.
|
|
27
|
+
*/
|
|
28
|
+
export declare function toJsStringLiteral(value: string): string;
|
package/dist/lib/utils.js
CHANGED
|
@@ -94,3 +94,17 @@ export function escapeTemplateContent(content) {
|
|
|
94
94
|
.replace(/`/g, "\\`")
|
|
95
95
|
.replace(/\$\{/g, "\\${");
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Renders `value` as a JS string literal using the same quote Prettier would
|
|
99
|
+
* choose: double by default, switching to single when that needs fewer escapes
|
|
100
|
+
* (JSON text, for instance, is full of `"`). Backslashes and the chosen quote
|
|
101
|
+
* are escaped. Lets generated code embed a string in a form Prettier leaves
|
|
102
|
+
* untouched, so emitted files stay format-stable without running a formatter.
|
|
103
|
+
*/
|
|
104
|
+
export function toJsStringLiteral(value) {
|
|
105
|
+
const doubleQuotes = (value.match(/"/g) || []).length;
|
|
106
|
+
const singleQuotes = (value.match(/'/g) || []).length;
|
|
107
|
+
const quote = singleQuotes < doubleQuotes ? "'" : '"';
|
|
108
|
+
const escaped = value.replace(/\\/g, "\\\\").split(quote).join(`\\${quote}`);
|
|
109
|
+
return `${quote}${escaped}${quote}`;
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const playgroundRoutesTemplate = "import { NextResponse } from \"next/server\";\nimport { z } from \"zod\";\nimport { rateLimit } from \"@/utils/rateLimit\";\nimport { matchAllowlist } from \"@/utils/playgroundAllowlist\";\nimport { guardedFetch, BlockedError } from \"@/utils/ssrfGuard\";\n\n// The playground proxy runs server-side so it can call APIs that block\n// cross-origin browser requests. It is NOT an open forward proxy: every target\n// is gated by the build-time allowlist (derived from the OpenAPI servers) and\n// then re-validated against private/metadata IP ranges before any socket opens.\nexport const runtime = \"nodejs\";\nexport const maxDuration = 40;\n\nconst MAX_REQUEST_BYTES = 1_000_000;\nconst MAX_RESPONSE_BYTES = 5_000_000;\nconst TIMEOUT_MS = 30_000;\n\nconst envelopeSchema = z.object({\n targetUrl: z.string().url().max(4096),\n method: z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\", \"HEAD\", \"OPTIONS\"]),\n headers: z.record(z.string().max(256), z.string().max(8192)).optional(),\n body: z.string().max(MAX_REQUEST_BYTES).optional(),\n bodyEncoding: z.enum([\"utf8\", \"base64\"]).optional(),\n});\n\n// Headers we never forward upstream: hop-by-hop, or identity/cookie headers\n// that would either leak the docs origin or be set incorrectly.\nconst BLOCKED_REQUEST_HEADERS = new Set([\n \"connection\",\n \"keep-alive\",\n \"proxy-authenticate\",\n \"proxy-authorization\",\n \"te\",\n \"trailer\",\n \"transfer-encoding\",\n \"upgrade\",\n \"host\",\n \"content-length\",\n \"cookie\",\n \"origin\",\n \"referer\",\n \"forwarded\",\n \"x-forwarded-for\",\n \"x-forwarded-host\",\n \"x-forwarded-proto\",\n]);\n\n// The only response headers echoed back to the client. Notably excludes\n// set-cookie, authorization, and www-authenticate.\nconst SAFE_RESPONSE_HEADERS = new Set([\n \"content-type\",\n \"content-length\",\n \"content-language\",\n \"content-disposition\",\n \"cache-control\",\n \"etag\",\n \"last-modified\",\n \"date\",\n \"location\",\n \"retry-after\",\n]);\n\nfunction hasControlChars(value: string): boolean {\n return (\n value.includes(String.fromCharCode(10)) ||\n value.includes(String.fromCharCode(13))\n );\n}\n\nfunction isTextContentType(contentType: string | null): boolean {\n if (!contentType) return false;\n const t = contentType.toLowerCase();\n return (\n t.startsWith(\"text/\") ||\n t.includes(\"json\") ||\n t.includes(\"xml\") ||\n t.includes(\"javascript\") ||\n t.includes(\"x-www-form-urlencoded\") ||\n t.includes(\"csv\")\n );\n}\n\nexport async function POST(req: Request) {\n const ip =\n req.headers.get(\"x-forwarded-for\")?.split(\",\")[0]?.trim() ?? \"unknown\";\n const { allowed, retryAfter } = rateLimit(ip);\n if (!allowed) {\n return NextResponse.json(\n { error: \"Too many requests\" },\n { status: 429, headers: { \"Retry-After\": String(retryAfter) } },\n );\n }\n\n let raw: unknown;\n try {\n raw = await req.json();\n } catch {\n return NextResponse.json({ error: \"Invalid JSON body\" }, { status: 400 });\n }\n\n const parsed = envelopeSchema.safeParse(raw);\n if (!parsed.success) {\n return NextResponse.json(\n { error: \"Invalid request\", details: parsed.error.issues },\n { status: 400 },\n );\n }\n\n const { targetUrl, method, headers = {}, body, bodyEncoding } = parsed.data;\n\n const entry = matchAllowlist(targetUrl);\n if (!entry) {\n console.warn(\"[playground] blocked: non-allowlisted target\");\n return NextResponse.json(\n { error: \"This request target is not allowed by the API reference.\" },\n { status: 403 },\n );\n }\n\n if (Object.keys(headers).length > 50) {\n return NextResponse.json({ error: \"Too many headers\" }, { status: 400 });\n }\n\n const outboundHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(headers)) {\n const lower = key.toLowerCase();\n if (BLOCKED_REQUEST_HEADERS.has(lower)) continue;\n if (hasControlChars(key) || hasControlChars(value)) continue;\n outboundHeaders[key] = value;\n }\n outboundHeaders[\"user-agent\"] =\n outboundHeaders[\"user-agent\"] ?? \"Doccupine-API-Playground\";\n // Ask for an unencoded body so the response byte cap is measured accurately.\n outboundHeaders[\"accept-encoding\"] = \"identity\";\n\n let bodyBuffer: Buffer | undefined;\n if (body !== undefined && method !== \"GET\" && method !== \"HEAD\") {\n bodyBuffer = Buffer.from(\n body,\n bodyEncoding === \"base64\" ? \"base64\" : \"utf8\",\n );\n }\n\n try {\n const result = await guardedFetch(targetUrl, entry, {\n method,\n headers: outboundHeaders,\n body: bodyBuffer,\n timeoutMs: TIMEOUT_MS,\n maxBytes: MAX_RESPONSE_BYTES,\n });\n\n const safeHeaders: Record<string, string> = {};\n let contentType: string | null = null;\n for (const [key, value] of Object.entries(result.headers)) {\n if (key === \"content-type\") contentType = value;\n if (SAFE_RESPONSE_HEADERS.has(key)) safeHeaders[key] = value;\n }\n\n const isText = isTextContentType(contentType);\n\n // Deliberately do NOT log the request/response here: the full URL (path and\n // query) and headers can carry reader secrets. Only blocked/failed attempts\n // are logged below via console.warn, and those record no sensitive values.\n return NextResponse.json({\n status: result.status,\n statusText: result.statusText,\n headers: safeHeaders,\n contentType,\n bodyEncoding: isText ? \"utf8\" : \"base64\",\n body: result.body.toString(isText ? \"utf8\" : \"base64\"),\n truncated: result.truncated,\n byteLength: result.body.length,\n durationMs: result.durationMs,\n });\n } catch (error) {\n if (error instanceof BlockedError) {\n console.warn(\"[playground] \" + error.reason);\n return NextResponse.json(\n { error: \"This request target is not allowed.\" },\n { status: 403 },\n );\n }\n const message = error instanceof Error ? error.message : \"\";\n if (message === \"timeout\") {\n console.warn(\"[playground] upstream timeout\");\n return NextResponse.json(\n { error: \"The upstream request timed out.\" },\n { status: 504 },\n );\n }\n console.warn(\"[playground] upstream request failed\");\n return NextResponse.json(\n { error: \"The upstream request failed.\" },\n { status: 502 },\n );\n }\n}\n";
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
export const playgroundRoutesTemplate = `import { NextResponse } from "next/server";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { rateLimit } from "@/utils/rateLimit";
|
|
4
|
+
import { matchAllowlist } from "@/utils/playgroundAllowlist";
|
|
5
|
+
import { guardedFetch, BlockedError } from "@/utils/ssrfGuard";
|
|
6
|
+
|
|
7
|
+
// The playground proxy runs server-side so it can call APIs that block
|
|
8
|
+
// cross-origin browser requests. It is NOT an open forward proxy: every target
|
|
9
|
+
// is gated by the build-time allowlist (derived from the OpenAPI servers) and
|
|
10
|
+
// then re-validated against private/metadata IP ranges before any socket opens.
|
|
11
|
+
export const runtime = "nodejs";
|
|
12
|
+
export const maxDuration = 40;
|
|
13
|
+
|
|
14
|
+
const MAX_REQUEST_BYTES = 1_000_000;
|
|
15
|
+
const MAX_RESPONSE_BYTES = 5_000_000;
|
|
16
|
+
const TIMEOUT_MS = 30_000;
|
|
17
|
+
|
|
18
|
+
const envelopeSchema = z.object({
|
|
19
|
+
targetUrl: z.string().url().max(4096),
|
|
20
|
+
method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]),
|
|
21
|
+
headers: z.record(z.string().max(256), z.string().max(8192)).optional(),
|
|
22
|
+
body: z.string().max(MAX_REQUEST_BYTES).optional(),
|
|
23
|
+
bodyEncoding: z.enum(["utf8", "base64"]).optional(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Headers we never forward upstream: hop-by-hop, or identity/cookie headers
|
|
27
|
+
// that would either leak the docs origin or be set incorrectly.
|
|
28
|
+
const BLOCKED_REQUEST_HEADERS = new Set([
|
|
29
|
+
"connection",
|
|
30
|
+
"keep-alive",
|
|
31
|
+
"proxy-authenticate",
|
|
32
|
+
"proxy-authorization",
|
|
33
|
+
"te",
|
|
34
|
+
"trailer",
|
|
35
|
+
"transfer-encoding",
|
|
36
|
+
"upgrade",
|
|
37
|
+
"host",
|
|
38
|
+
"content-length",
|
|
39
|
+
"cookie",
|
|
40
|
+
"origin",
|
|
41
|
+
"referer",
|
|
42
|
+
"forwarded",
|
|
43
|
+
"x-forwarded-for",
|
|
44
|
+
"x-forwarded-host",
|
|
45
|
+
"x-forwarded-proto",
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
// The only response headers echoed back to the client. Notably excludes
|
|
49
|
+
// set-cookie, authorization, and www-authenticate.
|
|
50
|
+
const SAFE_RESPONSE_HEADERS = new Set([
|
|
51
|
+
"content-type",
|
|
52
|
+
"content-length",
|
|
53
|
+
"content-language",
|
|
54
|
+
"content-disposition",
|
|
55
|
+
"cache-control",
|
|
56
|
+
"etag",
|
|
57
|
+
"last-modified",
|
|
58
|
+
"date",
|
|
59
|
+
"location",
|
|
60
|
+
"retry-after",
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
function hasControlChars(value: string): boolean {
|
|
64
|
+
return (
|
|
65
|
+
value.includes(String.fromCharCode(10)) ||
|
|
66
|
+
value.includes(String.fromCharCode(13))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isTextContentType(contentType: string | null): boolean {
|
|
71
|
+
if (!contentType) return false;
|
|
72
|
+
const t = contentType.toLowerCase();
|
|
73
|
+
return (
|
|
74
|
+
t.startsWith("text/") ||
|
|
75
|
+
t.includes("json") ||
|
|
76
|
+
t.includes("xml") ||
|
|
77
|
+
t.includes("javascript") ||
|
|
78
|
+
t.includes("x-www-form-urlencoded") ||
|
|
79
|
+
t.includes("csv")
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function POST(req: Request) {
|
|
84
|
+
const ip =
|
|
85
|
+
req.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ?? "unknown";
|
|
86
|
+
const { allowed, retryAfter } = rateLimit(ip);
|
|
87
|
+
if (!allowed) {
|
|
88
|
+
return NextResponse.json(
|
|
89
|
+
{ error: "Too many requests" },
|
|
90
|
+
{ status: 429, headers: { "Retry-After": String(retryAfter) } },
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let raw: unknown;
|
|
95
|
+
try {
|
|
96
|
+
raw = await req.json();
|
|
97
|
+
} catch {
|
|
98
|
+
return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const parsed = envelopeSchema.safeParse(raw);
|
|
102
|
+
if (!parsed.success) {
|
|
103
|
+
return NextResponse.json(
|
|
104
|
+
{ error: "Invalid request", details: parsed.error.issues },
|
|
105
|
+
{ status: 400 },
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const { targetUrl, method, headers = {}, body, bodyEncoding } = parsed.data;
|
|
110
|
+
|
|
111
|
+
const entry = matchAllowlist(targetUrl);
|
|
112
|
+
if (!entry) {
|
|
113
|
+
console.warn("[playground] blocked: non-allowlisted target");
|
|
114
|
+
return NextResponse.json(
|
|
115
|
+
{ error: "This request target is not allowed by the API reference." },
|
|
116
|
+
{ status: 403 },
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (Object.keys(headers).length > 50) {
|
|
121
|
+
return NextResponse.json({ error: "Too many headers" }, { status: 400 });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const outboundHeaders: Record<string, string> = {};
|
|
125
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
126
|
+
const lower = key.toLowerCase();
|
|
127
|
+
if (BLOCKED_REQUEST_HEADERS.has(lower)) continue;
|
|
128
|
+
if (hasControlChars(key) || hasControlChars(value)) continue;
|
|
129
|
+
outboundHeaders[key] = value;
|
|
130
|
+
}
|
|
131
|
+
outboundHeaders["user-agent"] =
|
|
132
|
+
outboundHeaders["user-agent"] ?? "Doccupine-API-Playground";
|
|
133
|
+
// Ask for an unencoded body so the response byte cap is measured accurately.
|
|
134
|
+
outboundHeaders["accept-encoding"] = "identity";
|
|
135
|
+
|
|
136
|
+
let bodyBuffer: Buffer | undefined;
|
|
137
|
+
if (body !== undefined && method !== "GET" && method !== "HEAD") {
|
|
138
|
+
bodyBuffer = Buffer.from(
|
|
139
|
+
body,
|
|
140
|
+
bodyEncoding === "base64" ? "base64" : "utf8",
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
const result = await guardedFetch(targetUrl, entry, {
|
|
146
|
+
method,
|
|
147
|
+
headers: outboundHeaders,
|
|
148
|
+
body: bodyBuffer,
|
|
149
|
+
timeoutMs: TIMEOUT_MS,
|
|
150
|
+
maxBytes: MAX_RESPONSE_BYTES,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const safeHeaders: Record<string, string> = {};
|
|
154
|
+
let contentType: string | null = null;
|
|
155
|
+
for (const [key, value] of Object.entries(result.headers)) {
|
|
156
|
+
if (key === "content-type") contentType = value;
|
|
157
|
+
if (SAFE_RESPONSE_HEADERS.has(key)) safeHeaders[key] = value;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const isText = isTextContentType(contentType);
|
|
161
|
+
|
|
162
|
+
// Deliberately do NOT log the request/response here: the full URL (path and
|
|
163
|
+
// query) and headers can carry reader secrets. Only blocked/failed attempts
|
|
164
|
+
// are logged below via console.warn, and those record no sensitive values.
|
|
165
|
+
return NextResponse.json({
|
|
166
|
+
status: result.status,
|
|
167
|
+
statusText: result.statusText,
|
|
168
|
+
headers: safeHeaders,
|
|
169
|
+
contentType,
|
|
170
|
+
bodyEncoding: isText ? "utf8" : "base64",
|
|
171
|
+
body: result.body.toString(isText ? "utf8" : "base64"),
|
|
172
|
+
truncated: result.truncated,
|
|
173
|
+
byteLength: result.body.length,
|
|
174
|
+
durationMs: result.durationMs,
|
|
175
|
+
});
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (error instanceof BlockedError) {
|
|
178
|
+
console.warn("[playground] " + error.reason);
|
|
179
|
+
return NextResponse.json(
|
|
180
|
+
{ error: "This request target is not allowed." },
|
|
181
|
+
{ status: 403 },
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
const message = error instanceof Error ? error.message : "";
|
|
185
|
+
if (message === "timeout") {
|
|
186
|
+
console.warn("[playground] upstream timeout");
|
|
187
|
+
return NextResponse.json(
|
|
188
|
+
{ error: "The upstream request timed out." },
|
|
189
|
+
{ status: 504 },
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
console.warn("[playground] upstream request failed");
|
|
193
|
+
return NextResponse.json(
|
|
194
|
+
{ error: "The upstream request failed." },
|
|
195
|
+
{ status: 502 },
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface RssRouteData {
|
|
2
|
+
pagePath: string;
|
|
3
|
+
title: string | null;
|
|
4
|
+
description: string | null;
|
|
5
|
+
items: {
|
|
6
|
+
title: string;
|
|
7
|
+
anchor: string;
|
|
8
|
+
description: string;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
export declare const rssRouteTemplate: (feed: RssRouteData) => string;
|