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
|
@@ -11,7 +11,7 @@ export const packageJsonTemplate = JSON.stringify({
|
|
|
11
11
|
"type-check": "tsgo --noEmit",
|
|
12
12
|
},
|
|
13
13
|
dependencies: {
|
|
14
|
-
"@langchain/anthropic": "^1.5.
|
|
14
|
+
"@langchain/anthropic": "^1.5.2",
|
|
15
15
|
"@langchain/core": "^1.2.3",
|
|
16
16
|
"@langchain/google-genai": "^2.2.0",
|
|
17
17
|
"@langchain/openai": "^1.5.5",
|
|
@@ -19,10 +19,10 @@ export const packageJsonTemplate = JSON.stringify({
|
|
|
19
19
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
20
20
|
"beautiful-mermaid": "^1.1.3",
|
|
21
21
|
"cherry-styled-components": "^0.2.11",
|
|
22
|
-
langchain: "^1.5.
|
|
23
|
-
"lucide-react": "^1.
|
|
22
|
+
langchain: "^1.5.4",
|
|
23
|
+
"lucide-react": "^1.27.0",
|
|
24
24
|
minisearch: "^7.2.0",
|
|
25
|
-
next: "16.2.
|
|
25
|
+
next: "16.2.12",
|
|
26
26
|
"next-mdx-remote": "^6.0.0",
|
|
27
27
|
"posthog-js": "^1.407.2",
|
|
28
28
|
"posthog-node": "^5.46.1",
|
|
@@ -37,8 +37,8 @@ export const packageJsonTemplate = JSON.stringify({
|
|
|
37
37
|
zod: "^4.4.3",
|
|
38
38
|
},
|
|
39
39
|
devDependencies: {
|
|
40
|
-
"@next/env": "16.2.
|
|
41
|
-
"@next/eslint-plugin-next": "16.2.
|
|
40
|
+
"@next/env": "16.2.12",
|
|
41
|
+
"@next/eslint-plugin-next": "16.2.12",
|
|
42
42
|
"@types/node": "^26",
|
|
43
43
|
"@types/react": "^19",
|
|
44
44
|
"@types/react-dom": "^19",
|
|
@@ -50,7 +50,7 @@ export const packageJsonTemplate = JSON.stringify({
|
|
|
50
50
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
51
51
|
"eslint-plugin-react": "^7.37.5",
|
|
52
52
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
53
|
-
globals: "^17.
|
|
53
|
+
globals: "^17.8.0",
|
|
54
54
|
prettier: "^3.9.6",
|
|
55
55
|
tsx: "^4.23.1",
|
|
56
56
|
typescript: "npm:@typescript/typescript6@^6.0.2",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const playgroundAllowlistStubTemplate = "[]\n";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Placeholder request-execution allowlist for the API playground. Overwritten
|
|
2
|
+
// at build time with the union of the configured OpenAPI spec servers. The
|
|
3
|
+
// empty stub keeps the import path present when no spec is configured.
|
|
4
|
+
export const playgroundAllowlistStubTemplate = `[]\n`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const openapiTypesTemplate = "// Runtime mirror of the operation descriptor the CLI embeds into each generated\n// API reference page. Kept in lockstep with the CLI's src/lib/openapi-types.ts.\n\nexport type JsonSchema = unknown;\n\nexport type HttpMethod =\n \"get\" | \"put\" | \"post\" | \"delete\" | \"options\" | \"head\" | \"patch\" | \"trace\";\n\nexport type ParameterLocation = \"query\" | \"header\" | \"path\" | \"cookie\";\n\nexport interface ParameterDescriptor {\n name: string;\n in: ParameterLocation;\n required: boolean;\n deprecated?: boolean;\n description?: string;\n schema?: JsonSchema;\n example?: unknown;\n anchorId: string;\n}\n\nexport interface MediaTypeDescriptor {\n contentType: string;\n schema?: JsonSchema;\n example?: unknown;\n}\n\nexport interface RequestBodyDescriptor {\n required: boolean;\n description?: string;\n content: MediaTypeDescriptor[];\n}\n\nexport interface ResponseHeaderDescriptor {\n name: string;\n description?: string;\n schema?: JsonSchema;\n}\n\nexport interface ResponseDescriptor {\n status: string;\n description?: string;\n content: MediaTypeDescriptor[];\n headers: ResponseHeaderDescriptor[];\n}\n\nexport interface SecuritySchemeDescriptor {\n type: \"apiKey\" | \"http\" | \"oauth2\" | \"openIdConnect\" | \"mutualTLS\";\n description?: string;\n name?: string;\n in?: \"query\" | \"header\" | \"cookie\";\n scheme?: string;\n bearerFormat?: string;\n openIdConnectUrl?: string;\n flows?: unknown;\n}\n\nexport interface SecurityRequirementDescriptor {\n schemeName: string;\n scopes: string[];\n scheme?: SecuritySchemeDescriptor;\n}\n\nexport interface ServerVariableDescriptor {\n default: string;\n enum?: string[];\n description?: string;\n}\n\nexport interface ServerDescriptor {\n url: string;\n description?: string;\n variables?: Record<string, ServerVariableDescriptor>;\n}\n\nexport interface OperationDescriptor {\n specName: string;\n operationId?: string;\n method: HttpMethod;\n path: string;\n summary?: string;\n description?: string;\n deprecated?: boolean;\n tags: string[];\n parameters: ParameterDescriptor[];\n requestBody?: RequestBodyDescriptor;\n responses: ResponseDescriptor[];\n servers: ServerDescriptor[];\n security: SecurityRequirementDescriptor[];\n slug: string;\n endpointAnchor: string;\n}\n";
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export const openapiTypesTemplate = `// Runtime mirror of the operation descriptor the CLI embeds into each generated
|
|
2
|
+
// API reference page. Kept in lockstep with the CLI's src/lib/openapi-types.ts.
|
|
3
|
+
|
|
4
|
+
export type JsonSchema = unknown;
|
|
5
|
+
|
|
6
|
+
export type HttpMethod =
|
|
7
|
+
"get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace";
|
|
8
|
+
|
|
9
|
+
export type ParameterLocation = "query" | "header" | "path" | "cookie";
|
|
10
|
+
|
|
11
|
+
export interface ParameterDescriptor {
|
|
12
|
+
name: string;
|
|
13
|
+
in: ParameterLocation;
|
|
14
|
+
required: boolean;
|
|
15
|
+
deprecated?: boolean;
|
|
16
|
+
description?: string;
|
|
17
|
+
schema?: JsonSchema;
|
|
18
|
+
example?: unknown;
|
|
19
|
+
anchorId: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MediaTypeDescriptor {
|
|
23
|
+
contentType: string;
|
|
24
|
+
schema?: JsonSchema;
|
|
25
|
+
example?: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface RequestBodyDescriptor {
|
|
29
|
+
required: boolean;
|
|
30
|
+
description?: string;
|
|
31
|
+
content: MediaTypeDescriptor[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ResponseHeaderDescriptor {
|
|
35
|
+
name: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
schema?: JsonSchema;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ResponseDescriptor {
|
|
41
|
+
status: string;
|
|
42
|
+
description?: string;
|
|
43
|
+
content: MediaTypeDescriptor[];
|
|
44
|
+
headers: ResponseHeaderDescriptor[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SecuritySchemeDescriptor {
|
|
48
|
+
type: "apiKey" | "http" | "oauth2" | "openIdConnect" | "mutualTLS";
|
|
49
|
+
description?: string;
|
|
50
|
+
name?: string;
|
|
51
|
+
in?: "query" | "header" | "cookie";
|
|
52
|
+
scheme?: string;
|
|
53
|
+
bearerFormat?: string;
|
|
54
|
+
openIdConnectUrl?: string;
|
|
55
|
+
flows?: unknown;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface SecurityRequirementDescriptor {
|
|
59
|
+
schemeName: string;
|
|
60
|
+
scopes: string[];
|
|
61
|
+
scheme?: SecuritySchemeDescriptor;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ServerVariableDescriptor {
|
|
65
|
+
default: string;
|
|
66
|
+
enum?: string[];
|
|
67
|
+
description?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ServerDescriptor {
|
|
71
|
+
url: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
variables?: Record<string, ServerVariableDescriptor>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface OperationDescriptor {
|
|
77
|
+
specName: string;
|
|
78
|
+
operationId?: string;
|
|
79
|
+
method: HttpMethod;
|
|
80
|
+
path: string;
|
|
81
|
+
summary?: string;
|
|
82
|
+
description?: string;
|
|
83
|
+
deprecated?: boolean;
|
|
84
|
+
tags: string[];
|
|
85
|
+
parameters: ParameterDescriptor[];
|
|
86
|
+
requestBody?: RequestBodyDescriptor;
|
|
87
|
+
responses: ResponseDescriptor[];
|
|
88
|
+
servers: ServerDescriptor[];
|
|
89
|
+
security: SecurityRequirementDescriptor[];
|
|
90
|
+
slug: string;
|
|
91
|
+
endpointAnchor: string;
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const apiSnippetsTemplate = "// Pure, isomorphic request-to-snippet generators for the API playground.\n// Given the fully-resolved request, produce copy-pasteable cURL / fetch /\n// requests examples. Secret redaction is the caller's responsibility: pass\n// already-redacted header values when secrets should not appear.\n\nexport interface SnippetRequest {\n method: string;\n url: string;\n headers: Record<string, string>;\n body?: string | null;\n}\n\nexport type SnippetLanguage = \"curl\" | \"javascript\" | \"python\";\n\nexport interface SnippetTab {\n label: string;\n code: string;\n language: string;\n}\n\n// A literal backslash, built without writing one (keeps escaping simple).\nconst BACKSLASH = String.fromCharCode(92);\n\n// POSIX single-quote a shell argument: wrap in quotes, and represent any inner\n// single quote as '\\'' by ending the quote, adding an escaped quote, reopening.\nfunction shellQuote(value: string): string {\n const escaped = value.split(\"'\").join(\"'\" + BACKSLASH + \"''\");\n return \"'\" + escaped + \"'\";\n}\n\nfunction toCurl(req: SnippetRequest): string {\n const parts: string[] = [\"curl\", \"-X\", req.method, shellQuote(req.url)];\n for (const [key, value] of Object.entries(req.headers)) {\n parts.push(\"-H\", shellQuote(key + \": \" + value));\n }\n if (req.body) {\n parts.push(\"--data\", shellQuote(req.body));\n }\n return parts.join(\" \");\n}\n\nfunction toFetch(req: SnippetRequest): string {\n const options: {\n method: string;\n headers?: Record<string, string>;\n body?: string;\n } = { method: req.method };\n if (Object.keys(req.headers).length > 0) options.headers = req.headers;\n if (req.body) options.body = req.body;\n return (\n \"const response = await fetch(\" +\n JSON.stringify(req.url) +\n \", \" +\n JSON.stringify(options, null, 2) +\n \");\"\n );\n}\n\nfunction toPython(req: SnippetRequest): string {\n const lines: string[] = [\"import requests\", \"\"];\n lines.push(\"response = requests.\" + req.method.toLowerCase() + \"(\");\n lines.push(\" \" + JSON.stringify(req.url) + \",\");\n if (Object.keys(req.headers).length > 0) {\n lines.push(\" headers=\" + JSON.stringify(req.headers) + \",\");\n }\n if (req.body) {\n lines.push(\" data=\" + JSON.stringify(req.body) + \",\");\n }\n lines.push(\")\");\n lines.push(\"print(response.status_code, response.text)\");\n return lines.join(\"\\n\");\n}\n\nexport function buildSnippets(\n req: SnippetRequest,\n languages: SnippetLanguage[],\n): SnippetTab[] {\n const tabs: SnippetTab[] = [];\n for (const language of languages) {\n if (language === \"curl\") {\n tabs.push({ label: \"cURL\", code: toCurl(req), language: \"bash\" });\n } else if (language === \"javascript\") {\n tabs.push({\n label: \"JavaScript\",\n code: toFetch(req),\n language: \"javascript\",\n });\n } else if (language === \"python\") {\n tabs.push({ label: \"Python\", code: toPython(req), language: \"python\" });\n }\n }\n return tabs;\n}\n";
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export const apiSnippetsTemplate = `// Pure, isomorphic request-to-snippet generators for the API playground.
|
|
2
|
+
// Given the fully-resolved request, produce copy-pasteable cURL / fetch /
|
|
3
|
+
// requests examples. Secret redaction is the caller's responsibility: pass
|
|
4
|
+
// already-redacted header values when secrets should not appear.
|
|
5
|
+
|
|
6
|
+
export interface SnippetRequest {
|
|
7
|
+
method: string;
|
|
8
|
+
url: string;
|
|
9
|
+
headers: Record<string, string>;
|
|
10
|
+
body?: string | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type SnippetLanguage = "curl" | "javascript" | "python";
|
|
14
|
+
|
|
15
|
+
export interface SnippetTab {
|
|
16
|
+
label: string;
|
|
17
|
+
code: string;
|
|
18
|
+
language: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// A literal backslash, built without writing one (keeps escaping simple).
|
|
22
|
+
const BACKSLASH = String.fromCharCode(92);
|
|
23
|
+
|
|
24
|
+
// POSIX single-quote a shell argument: wrap in quotes, and represent any inner
|
|
25
|
+
// single quote as '\\'' by ending the quote, adding an escaped quote, reopening.
|
|
26
|
+
function shellQuote(value: string): string {
|
|
27
|
+
const escaped = value.split("'").join("'" + BACKSLASH + "''");
|
|
28
|
+
return "'" + escaped + "'";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function toCurl(req: SnippetRequest): string {
|
|
32
|
+
const parts: string[] = ["curl", "-X", req.method, shellQuote(req.url)];
|
|
33
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
34
|
+
parts.push("-H", shellQuote(key + ": " + value));
|
|
35
|
+
}
|
|
36
|
+
if (req.body) {
|
|
37
|
+
parts.push("--data", shellQuote(req.body));
|
|
38
|
+
}
|
|
39
|
+
return parts.join(" ");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function toFetch(req: SnippetRequest): string {
|
|
43
|
+
const options: {
|
|
44
|
+
method: string;
|
|
45
|
+
headers?: Record<string, string>;
|
|
46
|
+
body?: string;
|
|
47
|
+
} = { method: req.method };
|
|
48
|
+
if (Object.keys(req.headers).length > 0) options.headers = req.headers;
|
|
49
|
+
if (req.body) options.body = req.body;
|
|
50
|
+
return (
|
|
51
|
+
"const response = await fetch(" +
|
|
52
|
+
JSON.stringify(req.url) +
|
|
53
|
+
", " +
|
|
54
|
+
JSON.stringify(options, null, 2) +
|
|
55
|
+
");"
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function toPython(req: SnippetRequest): string {
|
|
60
|
+
const lines: string[] = ["import requests", ""];
|
|
61
|
+
lines.push("response = requests." + req.method.toLowerCase() + "(");
|
|
62
|
+
lines.push(" " + JSON.stringify(req.url) + ",");
|
|
63
|
+
if (Object.keys(req.headers).length > 0) {
|
|
64
|
+
lines.push(" headers=" + JSON.stringify(req.headers) + ",");
|
|
65
|
+
}
|
|
66
|
+
if (req.body) {
|
|
67
|
+
lines.push(" data=" + JSON.stringify(req.body) + ",");
|
|
68
|
+
}
|
|
69
|
+
lines.push(")");
|
|
70
|
+
lines.push("print(response.status_code, response.text)");
|
|
71
|
+
return lines.join("\\n");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function buildSnippets(
|
|
75
|
+
req: SnippetRequest,
|
|
76
|
+
languages: SnippetLanguage[],
|
|
77
|
+
): SnippetTab[] {
|
|
78
|
+
const tabs: SnippetTab[] = [];
|
|
79
|
+
for (const language of languages) {
|
|
80
|
+
if (language === "curl") {
|
|
81
|
+
tabs.push({ label: "cURL", code: toCurl(req), language: "bash" });
|
|
82
|
+
} else if (language === "javascript") {
|
|
83
|
+
tabs.push({
|
|
84
|
+
label: "JavaScript",
|
|
85
|
+
code: toFetch(req),
|
|
86
|
+
language: "javascript",
|
|
87
|
+
});
|
|
88
|
+
} else if (language === "python") {
|
|
89
|
+
tabs.push({ label: "Python", code: toPython(req), language: "python" });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return tabs;
|
|
93
|
+
}
|
|
94
|
+
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const orderNavItemsTemplate = "export interface PagesProps {\n slug: string;\n title: string;\n date: string | null;\n category: string;\n description?: string;\n path?: string;\n categoryOrder?: number;\n order?: number;\n section?: string;\n navIcon?: string;\n categoryIcon?: string;\n}\n\ninterface AccProps {\n [key: string]: {\n categoryOrder: number;\n icon?: string;\n pages: {\n date: string | null;\n slug: string;\n title: string;\n order: number;\n icon?: string;\n }[];\n };\n}\n\nfunction transformPagesToGroupedStructure(pages: PagesProps[]) {\n const grouped = pages.reduce((acc: AccProps, page: PagesProps) => {\n const category = page.category || \"Uncategorized\";\n\n if (!acc[category]) {\n acc[category] = {\n categoryOrder: page.categoryOrder || 0,\n pages: [],\n };\n }\n\n // The first page in a category to declare a categoryIcon sets it.\n if (!acc[category].icon && page.categoryIcon) {\n acc[category].icon = page.categoryIcon;\n }\n\n acc[category].pages.push({\n date: page.date,\n slug: page.slug,\n title: page.title,\n order: page.order || 0,\n icon: page.navIcon,\n });\n\n return acc;\n }, {});\n\n return Object.entries(grouped)\n .sort(([, a], [, b]) => a.categoryOrder - b.categoryOrder)\n .map(([categoryName, categoryData], index) => ({\n slug: index === 0 ? \"\" : categoryName.toLowerCase().replace(/s+/g, \"-\"),\n label: categoryName,\n icon: categoryData.icon,\n links: categoryData.pages.sort((a, b) => a.order - b.order),\n }));\n}\n\nexport { transformPagesToGroupedStructure };\n";
|
|
1
|
+
export declare const orderNavItemsTemplate = "export interface PagesProps {\n slug: string;\n title: string;\n date: string | null;\n category: string;\n description?: string;\n path?: string;\n categoryOrder?: number;\n order?: number;\n section?: string;\n navIcon?: string;\n categoryIcon?: string;\n httpMethod?: string;\n}\n\ninterface AccProps {\n [key: string]: {\n categoryOrder: number;\n icon?: string;\n pages: {\n date: string | null;\n slug: string;\n title: string;\n order: number;\n icon?: string;\n httpMethod?: string;\n }[];\n };\n}\n\nfunction transformPagesToGroupedStructure(pages: PagesProps[]) {\n const grouped = pages.reduce((acc: AccProps, page: PagesProps) => {\n const category = page.category || \"Uncategorized\";\n\n if (!acc[category]) {\n acc[category] = {\n categoryOrder: page.categoryOrder || 0,\n pages: [],\n };\n }\n\n // The first page in a category to declare a categoryIcon sets it.\n if (!acc[category].icon && page.categoryIcon) {\n acc[category].icon = page.categoryIcon;\n }\n\n acc[category].pages.push({\n date: page.date,\n slug: page.slug,\n title: page.title,\n order: page.order || 0,\n icon: page.navIcon,\n httpMethod: page.httpMethod,\n });\n\n return acc;\n }, {});\n\n return Object.entries(grouped)\n .sort(([, a], [, b]) => a.categoryOrder - b.categoryOrder)\n .map(([categoryName, categoryData], index) => ({\n slug: index === 0 ? \"\" : categoryName.toLowerCase().replace(/s+/g, \"-\"),\n label: categoryName,\n icon: categoryData.icon,\n links: categoryData.pages.sort((a, b) => a.order - b.order),\n }));\n}\n\nexport { transformPagesToGroupedStructure };\n";
|
|
@@ -10,6 +10,7 @@ export const orderNavItemsTemplate = `export interface PagesProps {
|
|
|
10
10
|
section?: string;
|
|
11
11
|
navIcon?: string;
|
|
12
12
|
categoryIcon?: string;
|
|
13
|
+
httpMethod?: string;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
interface AccProps {
|
|
@@ -22,6 +23,7 @@ interface AccProps {
|
|
|
22
23
|
title: string;
|
|
23
24
|
order: number;
|
|
24
25
|
icon?: string;
|
|
26
|
+
httpMethod?: string;
|
|
25
27
|
}[];
|
|
26
28
|
};
|
|
27
29
|
}
|
|
@@ -48,6 +50,7 @@ function transformPagesToGroupedStructure(pages: PagesProps[]) {
|
|
|
48
50
|
title: page.title,
|
|
49
51
|
order: page.order || 0,
|
|
50
52
|
icon: page.navIcon,
|
|
53
|
+
httpMethod: page.httpMethod,
|
|
51
54
|
});
|
|
52
55
|
|
|
53
56
|
return acc;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const playgroundAllowlistTemplate = "import allowlistData from \"@/services/openapi/playground-allowlist.json\";\n\n// A single request-execution target the API playground is permitted to call.\n// Derived at build time from the union of every OpenAPI spec's `servers`.\n// `allowPrivate` is set ONLY when the spec's own declared server host is itself\n// a loopback/private/metadata literal (the local-dev case).\nexport interface AllowlistEntry {\n scheme: \"http\" | \"https\";\n host: string;\n port: number | null;\n basePath?: string;\n allowPrivate?: boolean;\n}\n\nconst allowlist: AllowlistEntry[] = Array.isArray(allowlistData)\n ? (allowlistData as AllowlistEntry[])\n : [];\n\nexport function getAllowlist(): AllowlistEntry[] {\n return allowlist;\n}\n\nfunction defaultPort(scheme: string): number {\n return scheme === \"https\" ? 443 : 80;\n}\n\n/**\n * Returns the matching allowlist entry for a target URL, or null. Matches on\n * exact scheme + hostname + effective port, plus an optional base-path prefix.\n * This is isomorphic: the server proxy uses it as a hard gate; the client uses\n * it for a consistent pre-flight check (NOT a security boundary on its own).\n */\nexport function matchAllowlistIn(\n entries: AllowlistEntry[],\n targetUrl: string,\n): AllowlistEntry | null {\n let url: URL;\n try {\n url = new URL(targetUrl);\n } catch {\n return null;\n }\n const scheme =\n url.protocol === \"https:\"\n ? \"https\"\n : url.protocol === \"http:\"\n ? \"http\"\n : null;\n if (!scheme) return null;\n // Reject embedded credentials (userinfo) outright.\n if (url.username || url.password) return null;\n\n const host = url.hostname.toLowerCase().replace(/\\.$/, \"\");\n const port = url.port ? Number(url.port) : defaultPort(scheme);\n\n for (const entry of entries) {\n if (entry.scheme !== scheme) continue;\n if (entry.host !== host) continue;\n const entryPort = entry.port ?? defaultPort(entry.scheme);\n if (entryPort !== port) continue;\n if (entry.basePath && !url.pathname.startsWith(entry.basePath)) continue;\n return entry;\n }\n return null;\n}\n\nexport function matchAllowlist(targetUrl: string): AllowlistEntry | null {\n return matchAllowlistIn(allowlist, targetUrl);\n}\n";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export const playgroundAllowlistTemplate = `import allowlistData from "@/services/openapi/playground-allowlist.json";
|
|
2
|
+
|
|
3
|
+
// A single request-execution target the API playground is permitted to call.
|
|
4
|
+
// Derived at build time from the union of every OpenAPI spec's \`servers\`.
|
|
5
|
+
// \`allowPrivate\` is set ONLY when the spec's own declared server host is itself
|
|
6
|
+
// a loopback/private/metadata literal (the local-dev case).
|
|
7
|
+
export interface AllowlistEntry {
|
|
8
|
+
scheme: "http" | "https";
|
|
9
|
+
host: string;
|
|
10
|
+
port: number | null;
|
|
11
|
+
basePath?: string;
|
|
12
|
+
allowPrivate?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const allowlist: AllowlistEntry[] = Array.isArray(allowlistData)
|
|
16
|
+
? (allowlistData as AllowlistEntry[])
|
|
17
|
+
: [];
|
|
18
|
+
|
|
19
|
+
export function getAllowlist(): AllowlistEntry[] {
|
|
20
|
+
return allowlist;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function defaultPort(scheme: string): number {
|
|
24
|
+
return scheme === "https" ? 443 : 80;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns the matching allowlist entry for a target URL, or null. Matches on
|
|
29
|
+
* exact scheme + hostname + effective port, plus an optional base-path prefix.
|
|
30
|
+
* This is isomorphic: the server proxy uses it as a hard gate; the client uses
|
|
31
|
+
* it for a consistent pre-flight check (NOT a security boundary on its own).
|
|
32
|
+
*/
|
|
33
|
+
export function matchAllowlistIn(
|
|
34
|
+
entries: AllowlistEntry[],
|
|
35
|
+
targetUrl: string,
|
|
36
|
+
): AllowlistEntry | null {
|
|
37
|
+
let url: URL;
|
|
38
|
+
try {
|
|
39
|
+
url = new URL(targetUrl);
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const scheme =
|
|
44
|
+
url.protocol === "https:"
|
|
45
|
+
? "https"
|
|
46
|
+
: url.protocol === "http:"
|
|
47
|
+
? "http"
|
|
48
|
+
: null;
|
|
49
|
+
if (!scheme) return null;
|
|
50
|
+
// Reject embedded credentials (userinfo) outright.
|
|
51
|
+
if (url.username || url.password) return null;
|
|
52
|
+
|
|
53
|
+
const host = url.hostname.toLowerCase().replace(/\\.$/, "");
|
|
54
|
+
const port = url.port ? Number(url.port) : defaultPort(scheme);
|
|
55
|
+
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
if (entry.scheme !== scheme) continue;
|
|
58
|
+
if (entry.host !== host) continue;
|
|
59
|
+
const entryPort = entry.port ?? defaultPort(entry.scheme);
|
|
60
|
+
if (entryPort !== port) continue;
|
|
61
|
+
if (entry.basePath && !url.pathname.startsWith(entry.basePath)) continue;
|
|
62
|
+
return entry;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function matchAllowlist(targetUrl: string): AllowlistEntry | null {
|
|
68
|
+
return matchAllowlistIn(allowlist, targetUrl);
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ssrfGuardTemplate = "// SERVER-ONLY. Imported solely by app/api/playground/route.ts (a route handler,\n// which never ships to the client). Performs SSRF-safe outbound requests for\n// the API playground proxy: it resolves the target host, rejects any address in\n// a private/loopback/link-local/metadata range, and pins the connection to the\n// pre-validated IPs so DNS rebinding between check and connect cannot redirect\n// the socket to an internal address.\n\nimport dns from \"node:dns/promises\";\nimport net from \"node:net\";\nimport http from \"node:http\";\nimport https from \"node:https\";\nimport type { LookupAddress } from \"node:dns\";\nimport type { LookupFunction } from \"node:net\";\nimport type { AllowlistEntry } from \"@/utils/playgroundAllowlist\";\n\nexport class BlockedError extends Error {\n constructor(public reason: string) {\n super(reason);\n this.name = \"BlockedError\";\n }\n}\n\nexport interface GuardedInit {\n method: string;\n headers: Record<string, string>;\n body?: Buffer;\n timeoutMs: number;\n maxBytes: number;\n}\n\nexport interface GuardedResult {\n status: number;\n statusText: string;\n headers: Record<string, string>;\n body: Buffer;\n truncated: boolean;\n durationMs: number;\n}\n\nfunction isBlockedIpv4(ip: string): boolean {\n const parts = ip.split(\".\");\n if (parts.length !== 4) return true;\n const nums = parts.map((p) => Number(p));\n if (nums.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) return true;\n const a = nums[0];\n const b = nums[1];\n const c = nums[2];\n if (a === 0 || a === 10 || a === 127) return true;\n if (a === 169 && b === 254) return true; // link-local incl. metadata\n if (a === 172 && b >= 16 && b <= 31) return true;\n if (a === 192 && b === 168) return true;\n if (a === 192 && b === 0 && c === 0) return true;\n if (a === 100 && b >= 64 && b <= 127) return true; // CGNAT\n if (a === 198 && (b === 18 || b === 19)) return true; // benchmarking\n if (a >= 224) return true; // multicast + reserved + broadcast\n return false;\n}\n\nfunction isBlockedIpv6(ip: string): boolean {\n const clean = ip.toLowerCase().split(\"%\")[0];\n if (clean === \"::\" || clean === \"::1\") return true;\n if (clean.startsWith(\"::ffff:\")) {\n const rest = clean.slice(\"::ffff:\".length);\n if (rest.includes(\".\")) return isBlockedIpv4(rest);\n const segs = rest.split(\":\");\n if (segs.length === 2) {\n const hi = parseInt(segs[0], 16);\n const lo = parseInt(segs[1], 16);\n if (Number.isInteger(hi) && Number.isInteger(lo)) {\n const v4 = [(hi >> 8) & 255, hi & 255, (lo >> 8) & 255, lo & 255].join(\n \".\",\n );\n return isBlockedIpv4(v4);\n }\n }\n }\n const head = clean.split(\":\")[0];\n if (\n head.startsWith(\"fe8\") ||\n head.startsWith(\"fe9\") ||\n head.startsWith(\"fea\") ||\n head.startsWith(\"feb\")\n ) {\n return true; // link-local fe80::/10\n }\n if (head.startsWith(\"fc\") || head.startsWith(\"fd\")) return true; // unique-local\n return false;\n}\n\nfunction isBlockedIp(ip: string): boolean {\n const type = net.isIP(ip);\n if (type === 4) return isBlockedIpv4(ip);\n if (type === 6) return isBlockedIpv6(ip);\n return true; // not a parseable IP -> fail closed\n}\n\nfunction flattenHeaders(\n headers: http.IncomingHttpHeaders,\n): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(headers)) {\n if (value === undefined) continue;\n out[key.toLowerCase()] = Array.isArray(value) ? value.join(\", \") : value;\n }\n return out;\n}\n\nexport async function guardedFetch(\n targetUrl: string,\n entry: AllowlistEntry,\n init: GuardedInit,\n): Promise<GuardedResult> {\n const url = new URL(targetUrl);\n let host = url.hostname.toLowerCase();\n if (host.endsWith(\".\")) host = host.slice(0, -1);\n\n const literalType = net.isIP(host);\n let validated: LookupAddress[];\n\n if (literalType !== 0) {\n // Raw-IP target: only allowed if the spec itself declared this host, and\n // only into a private range when it opted in via allowPrivate.\n if (isBlockedIp(host) && !entry.allowPrivate) {\n throw new BlockedError(\"blocked: private IP-literal target\");\n }\n validated = [{ address: host, family: literalType }];\n } else {\n let records: LookupAddress[];\n try {\n records = await dns.lookup(host, { all: true, verbatim: true });\n } catch {\n throw new BlockedError(\"blocked: DNS resolution failed\");\n }\n if (records.length === 0) throw new BlockedError(\"blocked: no DNS records\");\n if (!entry.allowPrivate) {\n for (const record of records) {\n if (isBlockedIp(record.address)) {\n throw new BlockedError(\"blocked: private IP\");\n }\n }\n }\n validated = records;\n }\n\n const isHttps = url.protocol === \"https:\";\n const transport = isHttps ? https : http;\n\n // Pin resolution to the addresses we just validated so a re-resolution\n // between check and connect (DNS rebinding) cannot swap in a private IP.\n const lookup: LookupFunction = (_hostname, options, callback) => {\n if (options && options.all) {\n callback(null, validated);\n } else {\n callback(null, validated[0].address, validated[0].family);\n }\n };\n\n const requestOptions: https.RequestOptions = {\n method: init.method,\n headers: init.headers,\n lookup,\n timeout: init.timeoutMs,\n };\n\n return await new Promise<GuardedResult>((resolve, reject) => {\n const start = Date.now();\n let settled = false;\n const done = (fn: () => void) => {\n if (settled) return;\n settled = true;\n fn();\n };\n\n const req = transport.request(url, requestOptions, (res) => {\n const chunks: Buffer[] = [];\n let received = 0;\n let truncated = false;\n\n res.on(\"data\", (chunk: Buffer) => {\n received += chunk.length;\n if (received > init.maxBytes) {\n truncated = true;\n res.destroy();\n return;\n }\n chunks.push(chunk);\n });\n\n const finish = () =>\n done(() =>\n resolve({\n status: res.statusCode ?? 0,\n statusText: res.statusMessage ?? \"\",\n headers: flattenHeaders(res.headers),\n body: Buffer.concat(chunks),\n truncated,\n durationMs: Date.now() - start,\n }),\n );\n\n res.on(\"end\", finish);\n res.on(\"close\", finish);\n res.on(\"error\", () => done(() => reject(new Error(\"stream error\"))));\n });\n\n req.on(\"timeout\", () => {\n req.destroy(new Error(\"timeout\"));\n });\n req.on(\"error\", (err) => done(() => reject(err)));\n\n if (init.body && init.method !== \"GET\" && init.method !== \"HEAD\") {\n req.write(init.body);\n }\n req.end();\n });\n}\n";
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
export const ssrfGuardTemplate = `// SERVER-ONLY. Imported solely by app/api/playground/route.ts (a route handler,
|
|
2
|
+
// which never ships to the client). Performs SSRF-safe outbound requests for
|
|
3
|
+
// the API playground proxy: it resolves the target host, rejects any address in
|
|
4
|
+
// a private/loopback/link-local/metadata range, and pins the connection to the
|
|
5
|
+
// pre-validated IPs so DNS rebinding between check and connect cannot redirect
|
|
6
|
+
// the socket to an internal address.
|
|
7
|
+
|
|
8
|
+
import dns from "node:dns/promises";
|
|
9
|
+
import net from "node:net";
|
|
10
|
+
import http from "node:http";
|
|
11
|
+
import https from "node:https";
|
|
12
|
+
import type { LookupAddress } from "node:dns";
|
|
13
|
+
import type { LookupFunction } from "node:net";
|
|
14
|
+
import type { AllowlistEntry } from "@/utils/playgroundAllowlist";
|
|
15
|
+
|
|
16
|
+
export class BlockedError extends Error {
|
|
17
|
+
constructor(public reason: string) {
|
|
18
|
+
super(reason);
|
|
19
|
+
this.name = "BlockedError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface GuardedInit {
|
|
24
|
+
method: string;
|
|
25
|
+
headers: Record<string, string>;
|
|
26
|
+
body?: Buffer;
|
|
27
|
+
timeoutMs: number;
|
|
28
|
+
maxBytes: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface GuardedResult {
|
|
32
|
+
status: number;
|
|
33
|
+
statusText: string;
|
|
34
|
+
headers: Record<string, string>;
|
|
35
|
+
body: Buffer;
|
|
36
|
+
truncated: boolean;
|
|
37
|
+
durationMs: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isBlockedIpv4(ip: string): boolean {
|
|
41
|
+
const parts = ip.split(".");
|
|
42
|
+
if (parts.length !== 4) return true;
|
|
43
|
+
const nums = parts.map((p) => Number(p));
|
|
44
|
+
if (nums.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) return true;
|
|
45
|
+
const a = nums[0];
|
|
46
|
+
const b = nums[1];
|
|
47
|
+
const c = nums[2];
|
|
48
|
+
if (a === 0 || a === 10 || a === 127) return true;
|
|
49
|
+
if (a === 169 && b === 254) return true; // link-local incl. metadata
|
|
50
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
51
|
+
if (a === 192 && b === 168) return true;
|
|
52
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
53
|
+
if (a === 100 && b >= 64 && b <= 127) return true; // CGNAT
|
|
54
|
+
if (a === 198 && (b === 18 || b === 19)) return true; // benchmarking
|
|
55
|
+
if (a >= 224) return true; // multicast + reserved + broadcast
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isBlockedIpv6(ip: string): boolean {
|
|
60
|
+
const clean = ip.toLowerCase().split("%")[0];
|
|
61
|
+
if (clean === "::" || clean === "::1") return true;
|
|
62
|
+
if (clean.startsWith("::ffff:")) {
|
|
63
|
+
const rest = clean.slice("::ffff:".length);
|
|
64
|
+
if (rest.includes(".")) return isBlockedIpv4(rest);
|
|
65
|
+
const segs = rest.split(":");
|
|
66
|
+
if (segs.length === 2) {
|
|
67
|
+
const hi = parseInt(segs[0], 16);
|
|
68
|
+
const lo = parseInt(segs[1], 16);
|
|
69
|
+
if (Number.isInteger(hi) && Number.isInteger(lo)) {
|
|
70
|
+
const v4 = [(hi >> 8) & 255, hi & 255, (lo >> 8) & 255, lo & 255].join(
|
|
71
|
+
".",
|
|
72
|
+
);
|
|
73
|
+
return isBlockedIpv4(v4);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const head = clean.split(":")[0];
|
|
78
|
+
if (
|
|
79
|
+
head.startsWith("fe8") ||
|
|
80
|
+
head.startsWith("fe9") ||
|
|
81
|
+
head.startsWith("fea") ||
|
|
82
|
+
head.startsWith("feb")
|
|
83
|
+
) {
|
|
84
|
+
return true; // link-local fe80::/10
|
|
85
|
+
}
|
|
86
|
+
if (head.startsWith("fc") || head.startsWith("fd")) return true; // unique-local
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isBlockedIp(ip: string): boolean {
|
|
91
|
+
const type = net.isIP(ip);
|
|
92
|
+
if (type === 4) return isBlockedIpv4(ip);
|
|
93
|
+
if (type === 6) return isBlockedIpv6(ip);
|
|
94
|
+
return true; // not a parseable IP -> fail closed
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function flattenHeaders(
|
|
98
|
+
headers: http.IncomingHttpHeaders,
|
|
99
|
+
): Record<string, string> {
|
|
100
|
+
const out: Record<string, string> = {};
|
|
101
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
102
|
+
if (value === undefined) continue;
|
|
103
|
+
out[key.toLowerCase()] = Array.isArray(value) ? value.join(", ") : value;
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function guardedFetch(
|
|
109
|
+
targetUrl: string,
|
|
110
|
+
entry: AllowlistEntry,
|
|
111
|
+
init: GuardedInit,
|
|
112
|
+
): Promise<GuardedResult> {
|
|
113
|
+
const url = new URL(targetUrl);
|
|
114
|
+
let host = url.hostname.toLowerCase();
|
|
115
|
+
if (host.endsWith(".")) host = host.slice(0, -1);
|
|
116
|
+
|
|
117
|
+
const literalType = net.isIP(host);
|
|
118
|
+
let validated: LookupAddress[];
|
|
119
|
+
|
|
120
|
+
if (literalType !== 0) {
|
|
121
|
+
// Raw-IP target: only allowed if the spec itself declared this host, and
|
|
122
|
+
// only into a private range when it opted in via allowPrivate.
|
|
123
|
+
if (isBlockedIp(host) && !entry.allowPrivate) {
|
|
124
|
+
throw new BlockedError("blocked: private IP-literal target");
|
|
125
|
+
}
|
|
126
|
+
validated = [{ address: host, family: literalType }];
|
|
127
|
+
} else {
|
|
128
|
+
let records: LookupAddress[];
|
|
129
|
+
try {
|
|
130
|
+
records = await dns.lookup(host, { all: true, verbatim: true });
|
|
131
|
+
} catch {
|
|
132
|
+
throw new BlockedError("blocked: DNS resolution failed");
|
|
133
|
+
}
|
|
134
|
+
if (records.length === 0) throw new BlockedError("blocked: no DNS records");
|
|
135
|
+
if (!entry.allowPrivate) {
|
|
136
|
+
for (const record of records) {
|
|
137
|
+
if (isBlockedIp(record.address)) {
|
|
138
|
+
throw new BlockedError("blocked: private IP");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
validated = records;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const isHttps = url.protocol === "https:";
|
|
146
|
+
const transport = isHttps ? https : http;
|
|
147
|
+
|
|
148
|
+
// Pin resolution to the addresses we just validated so a re-resolution
|
|
149
|
+
// between check and connect (DNS rebinding) cannot swap in a private IP.
|
|
150
|
+
const lookup: LookupFunction = (_hostname, options, callback) => {
|
|
151
|
+
if (options && options.all) {
|
|
152
|
+
callback(null, validated);
|
|
153
|
+
} else {
|
|
154
|
+
callback(null, validated[0].address, validated[0].family);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const requestOptions: https.RequestOptions = {
|
|
159
|
+
method: init.method,
|
|
160
|
+
headers: init.headers,
|
|
161
|
+
lookup,
|
|
162
|
+
timeout: init.timeoutMs,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return await new Promise<GuardedResult>((resolve, reject) => {
|
|
166
|
+
const start = Date.now();
|
|
167
|
+
let settled = false;
|
|
168
|
+
const done = (fn: () => void) => {
|
|
169
|
+
if (settled) return;
|
|
170
|
+
settled = true;
|
|
171
|
+
fn();
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const req = transport.request(url, requestOptions, (res) => {
|
|
175
|
+
const chunks: Buffer[] = [];
|
|
176
|
+
let received = 0;
|
|
177
|
+
let truncated = false;
|
|
178
|
+
|
|
179
|
+
res.on("data", (chunk: Buffer) => {
|
|
180
|
+
received += chunk.length;
|
|
181
|
+
if (received > init.maxBytes) {
|
|
182
|
+
truncated = true;
|
|
183
|
+
res.destroy();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
chunks.push(chunk);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const finish = () =>
|
|
190
|
+
done(() =>
|
|
191
|
+
resolve({
|
|
192
|
+
status: res.statusCode ?? 0,
|
|
193
|
+
statusText: res.statusMessage ?? "",
|
|
194
|
+
headers: flattenHeaders(res.headers),
|
|
195
|
+
body: Buffer.concat(chunks),
|
|
196
|
+
truncated,
|
|
197
|
+
durationMs: Date.now() - start,
|
|
198
|
+
}),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
res.on("end", finish);
|
|
202
|
+
res.on("close", finish);
|
|
203
|
+
res.on("error", () => done(() => reject(new Error("stream error"))));
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
req.on("timeout", () => {
|
|
207
|
+
req.destroy(new Error("timeout"));
|
|
208
|
+
});
|
|
209
|
+
req.on("error", (err) => done(() => reject(err)));
|
|
210
|
+
|
|
211
|
+
if (init.body && init.method !== "GET" && init.method !== "HEAD") {
|
|
212
|
+
req.write(init.body);
|
|
213
|
+
}
|
|
214
|
+
req.end();
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doccupine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.135",
|
|
4
4
|
"description": "Free and open-source documentation platform. Write MDX, get a production-ready site with AI chat, built-in components, and an MCP server - in one command.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -34,12 +34,13 @@
|
|
|
34
34
|
"author": "Luan Gjokaj",
|
|
35
35
|
"license": "SEE LICENSE IN LICENSE",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"
|
|
37
|
+
"@readme/openapi-parser": "^6.3.0",
|
|
38
|
+
"chalk": "^6.0.0",
|
|
38
39
|
"chokidar": "^5.0.0",
|
|
39
40
|
"commander": "^15.0.0",
|
|
40
41
|
"fs-extra": "^11.4.0",
|
|
41
42
|
"gray-matter": "^4.0.3",
|
|
42
|
-
"next": "^16.2.
|
|
43
|
+
"next": "^16.2.12",
|
|
43
44
|
"prompts": "^2.4.2",
|
|
44
45
|
"react": "^19.2.8",
|
|
45
46
|
"react-dom": "^19.2.8"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const platformExternalLinksMdxTemplate = "---\ntitle: \"External Links\"\ndescription: \"Add quick-access link buttons to your site's footer for GitHub, Discord, and other external resources.\"\ndate: \"2026-02-19\"\ncategory: \"Configuration\"\ncategoryOrder: 2\norder: 5\nsection: \"Platform\"\n---\n# External Links\n\nThe External Links settings page lets you add external link buttons to your documentation site's footer. These provide quick access to your project's GitHub repository, Discord server, social profiles, and other resources.\n\n## Adding a link\n\nClick **Add Link** and configure:\n\n- **Icon** (optional) - search and pick from any [Lucide](https://lucide.dev/) icon\n- **Title** - the display text for the link\n- **URL** - the target URL\n\n## Choosing an icon\n\nThe icon picker lets you search through the full [Lucide](https://lucide.dev/) icon set. Type a keyword to filter (e.g. \"git-branch\", \"mail\", \"globe\") and click to select.\n\nLeave the icon unset for a text-only link.\n\nIf you edit `links.json` directly, use Lucide icon names in kebab-case (e.g. `git-branch`, `message-circle`, `heart`).\n\n## How it works\n\nLink settings are stored in `links.json` at the root of your repository:\n\n```json\n[\n {\n \"title\": \"GitHub\",\n \"url\": \"https://github.com/your-org/your-repo\",\n \"icon\": \"git-branch\"\n },\n {\n \"title\": \"Discord\",\n \"url\": \"https://discord.gg/your-invite\",\n \"icon\": \"discord\"\n }\n]\n```";
|