fumadocs-openapi 12.4.2 → 12.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/generated/shared.css +1 -1
- package/dist/.translations/index.d.ts +12 -1
- package/dist/.translations/keys.js +12 -1
- package/dist/generate-file.js +3 -1
- package/dist/index.browser.d.ts +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/operation.js +2 -2
- package/dist/packages/shared-api/dist/codegen.js +1 -3
- package/dist/packages/shared-api/dist/components/schema/client.js +1 -1
- package/dist/playground/auth.d.ts +84 -30
- package/dist/playground/auth.js +250 -150
- package/dist/playground/fetcher.js +11 -6
- package/dist/playground/index.d.ts +2 -2
- package/dist/playground/index.js +2 -2
- package/dist/playground/use-playground.d.ts +3 -3
- package/dist/playground/use-playground.js +46 -31
- package/dist/requests/generators/python.d.ts +0 -1
- package/dist/requests/generators/python.js +1 -1
- package/dist/server/index.d.ts +2 -9
- package/dist/server/index.js +0 -4
- package/dist/server/proxy.d.ts +5 -4
- package/dist/server/proxy.js +105 -25
- package/dist/types/openapi.d.ts +7 -2
- package/dist/types.d.ts +1 -0
- package/dist/ui/operation/index.js +48 -27
- package/dist/ui/operation/usage-tabs.js +251 -34
- package/dist/ui/playground/client.js +8 -4
- package/dist/ui/playground/components/oauth-panel.js +150 -39
- package/dist/ui/playground/components/request-panel.js +18 -3
- package/dist/ui/playground/components/response-panel.js +53 -90
- package/dist/utils/create-page.d.ts +1 -1
- package/dist/utils/pages/to-static-data.d.ts +12 -0
- package/dist/utils/use-server.js +1 -1
- package/package.json +7 -6
- package/dist/packages/shared-api/dist/components/accordion.js +0 -63
- package/dist/ui/operation/request-tabs.js +0 -92
- package/dist/ui/operation/response-tabs.js +0 -53
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { pathnameFromRequest } from "../requests/generators/index.js";
|
|
3
|
+
import { useServer } from "../utils/use-server.js";
|
|
3
4
|
import { encodeRequestData } from "../requests/media/encode.js";
|
|
4
5
|
import { getPreferredType } from "../utils/schema.js";
|
|
5
|
-
import { useServer } from "../utils/use-server.js";
|
|
6
6
|
import { useExampleRequests, useOperation } from "../operation.js";
|
|
7
|
-
import { readPendingFlow, requestOAuthToken, useAuthFields, usePlaygroundAuth } from "./auth.js";
|
|
8
|
-
import { useOpenAPI } from "../utils/create-page.js";
|
|
9
7
|
import { createBrowserFetcher } from "./fetcher.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { requestOAuthToken, useAuthFields, usePlaygroundAuth } from "./auth.js";
|
|
9
|
+
import { useOpenAPI } from "../utils/create-page.js";
|
|
10
|
+
import { useEffect, useEffectEvent, useMemo, useState } from "react";
|
|
11
|
+
import { DataEngine } from "@fumari/stf";
|
|
13
12
|
//#region src/playground/use-playground.tsx
|
|
14
|
-
|
|
13
|
+
/** the form of a playground, its `auth` is the auth values of page */
|
|
14
|
+
var PlaygroundForm = class extends DataEngine {
|
|
15
|
+
constructor(defaultValues, auth) {
|
|
16
|
+
super(defaultValues);
|
|
17
|
+
this.auth = auth;
|
|
18
|
+
}
|
|
19
|
+
get(key) {
|
|
20
|
+
return key[0] === "auth" ? this.auth.get(key) : super.get(key);
|
|
21
|
+
}
|
|
22
|
+
init(key, defaultValue, ctx) {
|
|
23
|
+
return key[0] === "auth" ? this.auth.init(key, defaultValue, ctx) : super.init(key, defaultValue, ctx);
|
|
24
|
+
}
|
|
25
|
+
update(key, value, ctx) {
|
|
26
|
+
return key[0] === "auth" ? this.auth.update(key, value, ctx) : super.update(key, value, ctx);
|
|
27
|
+
}
|
|
28
|
+
delete(key, ctx) {
|
|
29
|
+
return key[0] === "auth" ? this.auth.delete(key, ctx) : super.delete(key, ctx);
|
|
30
|
+
}
|
|
31
|
+
listen(listener) {
|
|
32
|
+
const [root] = listener.field ?? [];
|
|
33
|
+
if (root !== "auth") super.listen(listener);
|
|
34
|
+
if (root === void 0 || root === "auth") this.auth.listen(listener);
|
|
35
|
+
}
|
|
36
|
+
unlisten(listener) {
|
|
37
|
+
super.unlisten(listener);
|
|
38
|
+
this.auth.unlisten(listener);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
15
41
|
/**
|
|
16
42
|
* The state of an API playground under `<OperationProvider />`: a form starting from the selected example request, its auth and the request it sends.
|
|
17
43
|
*
|
|
@@ -23,12 +49,9 @@ function usePlayground({ authProviders, transformAuthInputs, fetchOptions } = {}
|
|
|
23
49
|
const { items: examples, selected, update } = useExampleRequests();
|
|
24
50
|
const { resolveUrl } = useServer();
|
|
25
51
|
const origin = `${method} ${path}`;
|
|
26
|
-
const
|
|
27
|
-
const returnedScheme =
|
|
28
|
-
|
|
29
|
-
if (flow?.origin === origin) return flow.scheme;
|
|
30
|
-
}, () => void 0);
|
|
31
|
-
const flowReturned = returnedScheme !== void 0 || oauthOrigin === origin;
|
|
52
|
+
const page = usePlaygroundAuth();
|
|
53
|
+
const returnedScheme = page.returned?.origin === origin ? page.returned.scheme : void 0;
|
|
54
|
+
const flowReturned = returnedScheme !== void 0;
|
|
32
55
|
const [response, setResponse] = useState();
|
|
33
56
|
const [isSending, setSending] = useState(false);
|
|
34
57
|
let body;
|
|
@@ -49,7 +72,7 @@ function usePlayground({ authProviders, transformAuthInputs, fetchOptions } = {}
|
|
|
49
72
|
body: data?.body ?? {}
|
|
50
73
|
};
|
|
51
74
|
}, [examples, selected]);
|
|
52
|
-
const stf =
|
|
75
|
+
const stf = useMemo(() => ({ dataEngine: new PlaygroundForm(defaultValues, page.stf.dataEngine) }), [defaultValues, page.stf.dataEngine]);
|
|
53
76
|
const engine = stf.dataEngine;
|
|
54
77
|
const auth = useAuthFields(engine, {
|
|
55
78
|
operation,
|
|
@@ -64,13 +87,12 @@ function usePlayground({ authProviders, transformAuthInputs, fetchOptions } = {}
|
|
|
64
87
|
});
|
|
65
88
|
}
|
|
66
89
|
const syncExample = useEffectEvent(() => update(getRequestData()));
|
|
67
|
-
|
|
68
|
-
|
|
90
|
+
const [selectedFor, setSelectedFor] = useState();
|
|
91
|
+
if (returnedScheme !== selectedFor) {
|
|
92
|
+
setSelectedFor(returnedScheme);
|
|
93
|
+
const idx = auth.requirements.findIndex((req) => req.some((item) => item.id === returnedScheme));
|
|
69
94
|
if (idx !== -1) auth.select(idx);
|
|
70
|
-
}
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (engine.getData() !== defaultValues) engine.reset(defaultValues);
|
|
73
|
-
}, [engine, defaultValues]);
|
|
95
|
+
}
|
|
74
96
|
const initAuth = auth.init;
|
|
75
97
|
useEffect(() => {
|
|
76
98
|
const reset = initAuth();
|
|
@@ -86,11 +108,7 @@ function usePlayground({ authProviders, transformAuthInputs, fetchOptions } = {}
|
|
|
86
108
|
window.clearTimeout(timer);
|
|
87
109
|
reset();
|
|
88
110
|
};
|
|
89
|
-
}, [
|
|
90
|
-
engine,
|
|
91
|
-
defaultValues,
|
|
92
|
-
initAuth
|
|
93
|
-
]);
|
|
111
|
+
}, [engine, initAuth]);
|
|
94
112
|
return {
|
|
95
113
|
stf,
|
|
96
114
|
body,
|
|
@@ -99,17 +117,14 @@ function usePlayground({ authProviders, transformAuthInputs, fetchOptions } = {}
|
|
|
99
117
|
selected: auth.selected,
|
|
100
118
|
select: auth.select,
|
|
101
119
|
fields: auth.fields,
|
|
102
|
-
async authorize(field, { type, scopes = field.scopes,
|
|
120
|
+
async authorize(field, { type, scopes = field.scopes, ...input }) {
|
|
103
121
|
const token = await requestOAuthToken(field.scheme, type, {
|
|
104
|
-
|
|
105
|
-
clientSecret: input.clientSecret ?? "",
|
|
106
|
-
username: input.username ?? "",
|
|
107
|
-
password: input.password ?? "",
|
|
122
|
+
...input,
|
|
108
123
|
scopes,
|
|
109
|
-
clientAuth,
|
|
110
124
|
schemeId: field.schemeId,
|
|
111
125
|
serverUrl: resolveUrl(),
|
|
112
126
|
redirectUrl: oauthRedirectUrl,
|
|
127
|
+
proxyUrl,
|
|
113
128
|
origin
|
|
114
129
|
});
|
|
115
130
|
if (token) engine.update(field.fieldName, token);
|
package/dist/server/index.d.ts
CHANGED
|
@@ -3,10 +3,11 @@ import { OpenAPIPageProps_Preloaded, OpenAPIPageProps_Spec } from "../utils/page
|
|
|
3
3
|
import { SchemaToPagesOptions } from "../utils/pages/preset-auto.js";
|
|
4
4
|
import { CreateProxyOptions, Proxy, createProxy } from "./proxy.js";
|
|
5
5
|
import { createOAuthHandler } from "./oauth.js";
|
|
6
|
+
import { InternalOpenAPIMeta } from "../utils/pages/to-static-data.js";
|
|
6
7
|
import "../ui/index.js";
|
|
7
8
|
import { DynamicSource, LoaderPlugin, MetaData, Page, PageData, Source } from "fumadocs-core/source";
|
|
8
|
-
import { StructuredData } from "fumadocs-core/mdx-plugins/remark-structure";
|
|
9
9
|
import { TOCItemType } from "fumadocs-core/toc";
|
|
10
|
+
import { StructuredData } from "fumadocs-core/mdx-plugins/remark-structure";
|
|
10
11
|
//#region src/server/index.d.ts
|
|
11
12
|
/**
|
|
12
13
|
* schema ID -> file path, URL, downloaded schema object, or a function returning them
|
|
@@ -54,8 +55,6 @@ export interface OpenAPIServer {
|
|
|
54
55
|
* Fumadocs Source API integration, pass this to `plugins` array in `loader()`.
|
|
55
56
|
*/
|
|
56
57
|
loaderPlugin: () => LoaderPlugin;
|
|
57
|
-
/** @private internal API */
|
|
58
|
-
_getWatchPaths: () => string[];
|
|
59
58
|
}
|
|
60
59
|
export interface OpenAPIPageData extends PageData {
|
|
61
60
|
getOpenAPIPageProps: () => OpenAPIPageProps_Spec;
|
|
@@ -75,12 +74,6 @@ export type OpenAPISourceOptions = SchemaToPagesOptions & {
|
|
|
75
74
|
};
|
|
76
75
|
};
|
|
77
76
|
export declare function createOpenAPI(options?: OpenAPIOptions): OpenAPIServer;
|
|
78
|
-
export interface InternalOpenAPIMeta {
|
|
79
|
-
method?: string;
|
|
80
|
-
webhook?: boolean;
|
|
81
|
-
deprecated?: boolean;
|
|
82
|
-
preload?: string[];
|
|
83
|
-
}
|
|
84
77
|
/**
|
|
85
78
|
* Fumadocs Source API integration, pass this to `plugins` array in `loader()`.
|
|
86
79
|
*/
|
package/dist/server/index.js
CHANGED
|
@@ -8,7 +8,6 @@ import { MethodLabel } from "../ui/components/method-label.js";
|
|
|
8
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { PathUtils } from "fumadocs-core/source";
|
|
11
|
-
import fs from "node:fs";
|
|
12
11
|
//#region src/server/index.tsx
|
|
13
12
|
function createOpenAPI(options = {}) {
|
|
14
13
|
const { disableCache = false } = options;
|
|
@@ -115,9 +114,6 @@ function createOpenAPI(options = {}) {
|
|
|
115
114
|
options,
|
|
116
115
|
createProxy,
|
|
117
116
|
createOAuthHandler,
|
|
118
|
-
_getWatchPaths() {
|
|
119
|
-
return Object.keys(resolvedInput).filter((key) => !URL.canParse(key) && fs.existsSync(key));
|
|
120
|
-
},
|
|
121
117
|
async preloadOpenAPIPage(page) {
|
|
122
118
|
const out = {
|
|
123
119
|
docs: {},
|
package/dist/server/proxy.d.ts
CHANGED
|
@@ -7,11 +7,12 @@ export interface Proxy extends Record<(typeof methods)[number], Handler> {
|
|
|
7
7
|
}
|
|
8
8
|
export interface CreateProxyOptions {
|
|
9
9
|
/**
|
|
10
|
-
* List of allowed origins to proxy to, also enforced on redirects.
|
|
10
|
+
* List of allowed origins to proxy to, also enforced on redirects. Listed origins are trusted,
|
|
11
|
+
* including private ones like `http://localhost:8080`.
|
|
11
12
|
*
|
|
12
|
-
* @defaultValue
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* @defaultValue any public HTTP(S) origin. Hosts resolving to private network addresses (e.g.
|
|
14
|
+
* loopback, link-local) are refused when connecting, this requires Node.js or Deno. Cookies of
|
|
15
|
+
* your site and `Set-Cookie` headers of responses are not forwarded.
|
|
15
16
|
*/
|
|
16
17
|
allowedOrigins?: OriginMatcher[];
|
|
17
18
|
/**
|
package/dist/server/proxy.js
CHANGED
|
@@ -35,42 +35,52 @@ function matchOrigin(origin, matcher) {
|
|
|
35
35
|
function createProxy(options = {}) {
|
|
36
36
|
const { allowedOrigins, filterRequest, overrides } = options;
|
|
37
37
|
const handlers = { handle: handler };
|
|
38
|
-
|
|
38
|
+
function isAllowed(url) {
|
|
39
|
+
if (allowedOrigins) return allowedOrigins.some((matcher) => matchOrigin(url.origin, matcher));
|
|
40
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
41
|
+
}
|
|
39
42
|
async function handler(req) {
|
|
40
|
-
const
|
|
41
|
-
const searchParams = reqUrl.searchParams;
|
|
43
|
+
const searchParams = new URL(req.url).searchParams;
|
|
42
44
|
const rawUrl = searchParams.get("url");
|
|
43
45
|
if (!rawUrl) return Response.json("[Proxy] A `url` query parameter is required for proxy url", { status: 400 });
|
|
44
46
|
const targetUrl = URL.parse(rawUrl);
|
|
45
47
|
if (!targetUrl) return Response.json("[Proxy] Invalid `url` parameter value.", { status: 400 });
|
|
46
|
-
|
|
47
|
-
if (allowed.every((matcher) => !matchOrigin(targetUrl.origin, matcher))) return Response.json(`[Proxy] The origin "${targetUrl.origin}" is not allowed.`, { status: 400 });
|
|
48
|
+
if (!isAllowed(targetUrl)) return Response.json(`[Proxy] The origin "${targetUrl.origin}" is not allowed.`, { status: 400 });
|
|
48
49
|
const proxied = await rewriteRequest(req, targetUrl, searchParams.get("cookie"));
|
|
49
50
|
if (filterRequest && !filterRequest(proxied)) return Response.json("[Proxy] The proxied request is not allowed", { status: 403 });
|
|
50
51
|
try {
|
|
51
|
-
return
|
|
52
|
-
} catch (
|
|
52
|
+
return await proxyFetch(proxied);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
const err = e instanceof Error && e.cause instanceof ProxyError ? e.cause : e;
|
|
53
55
|
if (err instanceof ProxyError) return Response.json(`[Proxy] ${err.message}`, { status: err.status });
|
|
54
56
|
return Response.json(`[Proxy] Failed to proxy request: ${err instanceof Error ? err.message : "unknown reason"}`, { status: 500 });
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
|
-
async function proxyFetch(initial
|
|
59
|
+
async function proxyFetch(initial) {
|
|
60
|
+
const send = allowedOrigins ? fetch : await (publicFetch ??= createPublicFetch());
|
|
58
61
|
let method = initial.method;
|
|
59
|
-
let url = initial.url;
|
|
62
|
+
let url = new URL(initial.url);
|
|
60
63
|
const headers = new Headers(initial.headers);
|
|
61
64
|
let body = initial.body && methodsWithBody.has(method.toUpperCase()) ? await initial.arrayBuffer() : void 0;
|
|
62
65
|
for (let redirects = 0; redirects <= maxRedirects; redirects++) {
|
|
63
|
-
const response = await
|
|
66
|
+
const response = await send(url, {
|
|
64
67
|
method,
|
|
65
68
|
headers,
|
|
66
69
|
body,
|
|
67
70
|
cache: "no-cache",
|
|
68
|
-
redirect: "manual"
|
|
69
|
-
|
|
71
|
+
redirect: "manual",
|
|
72
|
+
signal: initial.signal
|
|
73
|
+
});
|
|
70
74
|
const location = response.headers.get("location");
|
|
71
|
-
if (!redirectStatus.has(response.status) || !location) return response;
|
|
75
|
+
if (!redirectStatus.has(response.status) || !location) return rewriteResponse(response, url);
|
|
76
|
+
await response.body?.cancel();
|
|
72
77
|
const next = new URL(location, url);
|
|
73
|
-
if (
|
|
78
|
+
if (!isAllowed(next)) throw new ProxyError(`The redirect origin "${next.origin}" is not allowed.`);
|
|
79
|
+
if (next.origin !== url.origin) {
|
|
80
|
+
headers.delete("authorization");
|
|
81
|
+
headers.delete("proxy-authorization");
|
|
82
|
+
headers.delete("cookie");
|
|
83
|
+
}
|
|
74
84
|
switch (response.status) {
|
|
75
85
|
case 301:
|
|
76
86
|
case 302: if (method === "GET" || method === "HEAD") break;
|
|
@@ -80,33 +90,53 @@ function createProxy(options = {}) {
|
|
|
80
90
|
headers.delete("content-length");
|
|
81
91
|
headers.delete("content-type");
|
|
82
92
|
}
|
|
83
|
-
url = next
|
|
93
|
+
url = next;
|
|
84
94
|
}
|
|
85
95
|
throw new ProxyError("Too many redirects.", 508);
|
|
86
96
|
}
|
|
87
97
|
async function rewriteRequest(request, url, cookie) {
|
|
88
98
|
const headers = new Headers(request.headers);
|
|
89
99
|
headers.delete("origin");
|
|
100
|
+
if (!allowedOrigins) headers.delete("cookie");
|
|
90
101
|
if (cookie) headers.set("Cookie", cookie);
|
|
91
|
-
const contentLength = headers.get("content-length");
|
|
92
|
-
const hasBody = contentLength && parseInt(contentLength) > 0;
|
|
93
102
|
const proxied = new Request(url, {
|
|
94
103
|
method: request.method,
|
|
95
104
|
cache: "no-cache",
|
|
96
105
|
headers,
|
|
97
|
-
body:
|
|
106
|
+
body: methodsWithBody.has(request.method.toUpperCase()) ? request.body : null,
|
|
107
|
+
signal: request.signal,
|
|
108
|
+
duplex: "half"
|
|
98
109
|
});
|
|
99
110
|
return overrides?.request ? overrides.request(proxied) : proxied;
|
|
100
111
|
}
|
|
101
|
-
async function rewriteResponse(response) {
|
|
112
|
+
async function rewriteResponse(response, url) {
|
|
102
113
|
if (overrides?.response) response = overrides.response(response);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
114
|
+
if (response.status < 200 || response.status > 599) {
|
|
115
|
+
await response.body?.cancel();
|
|
116
|
+
throw new ProxyError(`The upstream responded with an unsupported status ${response.status}.`, 502);
|
|
117
|
+
}
|
|
118
|
+
const headers = new Headers();
|
|
119
|
+
response.headers.forEach((value, key) => {
|
|
120
|
+
if (key.startsWith("access-control-")) return;
|
|
121
|
+
switch (key) {
|
|
122
|
+
case "set-cookie":
|
|
123
|
+
if (!allowedOrigins) return;
|
|
124
|
+
break;
|
|
125
|
+
case "content-encoding":
|
|
126
|
+
case "content-length":
|
|
127
|
+
case "alt-svc":
|
|
128
|
+
case "clear-site-data":
|
|
129
|
+
case "nel":
|
|
130
|
+
case "refresh":
|
|
131
|
+
case "report-to":
|
|
132
|
+
case "reporting-endpoints":
|
|
133
|
+
case "set-login":
|
|
134
|
+
case "strict-transport-security": return;
|
|
135
|
+
}
|
|
136
|
+
headers.append(key, value);
|
|
108
137
|
});
|
|
109
|
-
headers.set("X-Forwarded-Host",
|
|
138
|
+
headers.set("X-Forwarded-Host", url.href);
|
|
139
|
+
headers.append("Content-Security-Policy", "sandbox");
|
|
110
140
|
return new Response(response.body, {
|
|
111
141
|
status: response.status,
|
|
112
142
|
statusText: response.statusText,
|
|
@@ -116,5 +146,55 @@ function createProxy(options = {}) {
|
|
|
116
146
|
for (const key of methods) handlers[key] = handler;
|
|
117
147
|
return handlers;
|
|
118
148
|
}
|
|
149
|
+
const privateRanges = [
|
|
150
|
+
["0.0.0.0", 8],
|
|
151
|
+
["10.0.0.0", 8],
|
|
152
|
+
["100.64.0.0", 10],
|
|
153
|
+
["127.0.0.0", 8],
|
|
154
|
+
["169.254.0.0", 16],
|
|
155
|
+
["172.16.0.0", 12],
|
|
156
|
+
["192.0.0.0", 24],
|
|
157
|
+
["192.168.0.0", 16],
|
|
158
|
+
["240.0.0.0", 4],
|
|
159
|
+
["::", 96],
|
|
160
|
+
["fc00::", 7],
|
|
161
|
+
["fe80::", 10],
|
|
162
|
+
["2001::", 32],
|
|
163
|
+
["2002::", 16],
|
|
164
|
+
["64:ff9b::", 96],
|
|
165
|
+
["64:ff9b:1::", 48]
|
|
166
|
+
];
|
|
167
|
+
let publicFetch;
|
|
168
|
+
/**
|
|
169
|
+
* `fetch()` refusing hosts on private networks, checked against the resolved addresses of every
|
|
170
|
+
* connection.
|
|
171
|
+
*/
|
|
172
|
+
async function createPublicFetch() {
|
|
173
|
+
if ("Bun" in globalThis) throw new ProxyError("Private networks cannot be blocked on Bun, specify `allowedOrigins`.", 500);
|
|
174
|
+
const [{ Agent, fetch }, dns, { BlockList, isIP }] = await Promise.all([
|
|
175
|
+
import("undici"),
|
|
176
|
+
import("node:dns"),
|
|
177
|
+
import("node:net")
|
|
178
|
+
]);
|
|
179
|
+
const ipType = (address) => isIP(address) === 6 ? "ipv6" : "ipv4";
|
|
180
|
+
const blockList = new BlockList();
|
|
181
|
+
for (const [address, prefix] of privateRanges) blockList.addSubnet(address, prefix, ipType(address));
|
|
182
|
+
const isPrivate = (address) => blockList.check(address, ipType(address));
|
|
183
|
+
const refuse = (hostname) => new ProxyError(`The host "${hostname}" doesn't resolve to a public address, add its origin to \`allowedOrigins\` to proxy to private hosts.`);
|
|
184
|
+
const dispatcher = new Agent({ connect: { lookup(hostname, options, callback) {
|
|
185
|
+
dns.lookup(hostname, options, (err, address, family) => {
|
|
186
|
+
if (err || (typeof address === "string" ? [{ address }] : address).some((item) => isPrivate(item.address))) callback(refuse(hostname), address, family);
|
|
187
|
+
else callback(null, address, family);
|
|
188
|
+
});
|
|
189
|
+
} } });
|
|
190
|
+
return async (url, init) => {
|
|
191
|
+
const hostname = url.hostname.replace(/^\[(.*)\]$/, "$1");
|
|
192
|
+
if (isIP(hostname) && isPrivate(hostname)) throw refuse(hostname);
|
|
193
|
+
return fetch(url, {
|
|
194
|
+
...init,
|
|
195
|
+
dispatcher
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
}
|
|
119
199
|
//#endregion
|
|
120
200
|
export { createProxy };
|
package/dist/types/openapi.d.ts
CHANGED
|
@@ -161,7 +161,7 @@ export declare namespace OpenAPIV3_2 {
|
|
|
161
161
|
pathItems?: Record<string, ReferenceObject | PathItemObject>;
|
|
162
162
|
mediaTypes?: Record<string, MediaTypeObject | ReferenceObject>;
|
|
163
163
|
}>;
|
|
164
|
-
type SecuritySchemeObject = (HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme) & {
|
|
164
|
+
type SecuritySchemeObject = (HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme | MutualTLSSecurityScheme) & {
|
|
165
165
|
deprecated?: boolean;
|
|
166
166
|
};
|
|
167
167
|
type HttpSecurityScheme = OpenAPIV3_1.HttpSecurityScheme;
|
|
@@ -175,6 +175,7 @@ export declare namespace OpenAPIV3_2 {
|
|
|
175
175
|
flows?: OAuthFlows;
|
|
176
176
|
}>;
|
|
177
177
|
type OpenIdSecurityScheme = OpenAPIV3_1.OpenIdSecurityScheme;
|
|
178
|
+
type MutualTLSSecurityScheme = OpenAPIV3_1.MutualTLSSecurityScheme;
|
|
178
179
|
type TagObject = OpenAPIV3_1.TagObject & {
|
|
179
180
|
summary?: string;
|
|
180
181
|
parent?: string;
|
|
@@ -329,12 +330,16 @@ export declare namespace OpenAPIV3_1 {
|
|
|
329
330
|
callbacks?: Record<string, ReferenceObject | CallbackObject>;
|
|
330
331
|
pathItems?: Record<string, ReferenceObject | PathItemObject>;
|
|
331
332
|
}>;
|
|
332
|
-
type SecuritySchemeObject = OpenAPIV3.SecuritySchemeObject;
|
|
333
|
+
type SecuritySchemeObject = OpenAPIV3.SecuritySchemeObject | MutualTLSSecurityScheme;
|
|
333
334
|
type HttpSecurityScheme = OpenAPIV3.HttpSecurityScheme;
|
|
334
335
|
type ApiKeySecurityScheme = OpenAPIV3.ApiKeySecurityScheme;
|
|
335
336
|
type OAuthFlows = OpenAPIV3.OAuthFlows;
|
|
336
337
|
type OAuth2SecurityScheme = OpenAPIV3.OAuth2SecurityScheme;
|
|
337
338
|
type OpenIdSecurityScheme = OpenAPIV3.OpenIdSecurityScheme;
|
|
339
|
+
type MutualTLSSecurityScheme = {
|
|
340
|
+
type?: 'mutualTLS';
|
|
341
|
+
description?: string;
|
|
342
|
+
};
|
|
338
343
|
type TagObject = OpenAPIV3.TagObject;
|
|
339
344
|
}
|
|
340
345
|
export declare namespace OpenAPIV3 {
|
package/dist/types.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type CallbackObject = OpenAPIV3_2.CallbackObject;
|
|
|
17
17
|
export type ServerVariableObject = OpenAPIV3.ServerVariableObject;
|
|
18
18
|
export type ResponseObject = OpenAPIV3_2.ResponseObject;
|
|
19
19
|
export type OAuth2SecurityScheme = OpenAPIV3_2.OAuth2SecurityScheme;
|
|
20
|
+
export type OAuthFlows = OpenAPIV3_2.OAuthFlows;
|
|
20
21
|
export type HttpMethods = OpenAPIV3_2.HttpMethods;
|
|
21
22
|
export type ExampleObject = OpenAPIV3_2.ExampleObject;
|
|
22
23
|
export type MediaTypeObject = OpenAPIV3_2.MediaTypeObject;
|
|
@@ -3,12 +3,11 @@ import { OperationProvider, useOperation } from "../../operation.js";
|
|
|
3
3
|
import { useOpenAPI, useRenderContext, useTypeScriptDefinitions } from "../../utils/create-page.js";
|
|
4
4
|
import { Badge } from "../../packages/shared-api/dist/components/badge.js";
|
|
5
5
|
import { MethodLabel } from "../components/method-label.js";
|
|
6
|
-
import { AnchorSection, useAnchorLink } from "../../packages/shared-api/dist/auto-anchor/index.js";
|
|
7
6
|
import { Markdown } from "../components/markdown.js";
|
|
8
|
-
import { UsageTabs } from "./usage-tabs.js";
|
|
9
|
-
import { SchemaUI } from "../components/schema.js";
|
|
10
|
-
import { RequestTabs } from "./request-tabs.js";
|
|
11
7
|
import { cn } from "../../utils/cn.js";
|
|
8
|
+
import { RequestTabs, UsageTabs } from "./usage-tabs.js";
|
|
9
|
+
import { AnchorSection, useAnchorLink } from "../../packages/shared-api/dist/auto-anchor/index.js";
|
|
10
|
+
import { SchemaUI } from "../components/schema.js";
|
|
12
11
|
import { SelectTab, SelectTabTrigger, SelectTabs } from "../../packages/shared-api/dist/components/select-tab.js";
|
|
13
12
|
import { Heading } from "../components/heading.js";
|
|
14
13
|
import { Segmented, SegmentedList, SegmentedPanel } from "../components/segmented.js";
|
|
@@ -227,7 +226,7 @@ function OperationContent({ showTitle, showDescription, headingLevel = 2 }) {
|
|
|
227
226
|
slots.callbacks
|
|
228
227
|
]
|
|
229
228
|
}), /* @__PURE__ */ jsx("div", {
|
|
230
|
-
className: "@4xl:sticky @4xl:top-[calc(var(--fd-docs-row-
|
|
229
|
+
className: "@4xl:sticky @4xl:top-[calc(var(--fd-docs-row-3,0px)+1rem)] @4xl:flex @4xl:max-h-[calc(var(--fd-docs-height,100dvh)-var(--fd-docs-row-3,0px)-2rem)] @4xl:w-[400px] @4xl:flex-col",
|
|
231
230
|
children: slots.apiExample
|
|
232
231
|
})]
|
|
233
232
|
});
|
|
@@ -257,7 +256,7 @@ function OperationContent({ showTitle, showDescription, headingLevel = 2 }) {
|
|
|
257
256
|
slots.callbacks
|
|
258
257
|
]
|
|
259
258
|
}), /* @__PURE__ */ jsx("div", {
|
|
260
|
-
className: "@4xl:sticky @4xl:top-[calc(var(--fd-docs-row-
|
|
259
|
+
className: "@4xl:sticky @4xl:top-[calc(var(--fd-docs-row-3,0px)+1rem)] @4xl:flex @4xl:max-h-[calc(var(--fd-docs-height,100dvh)-var(--fd-docs-row-3,0px)-2rem)] @4xl:w-[400px] @4xl:flex-col",
|
|
261
260
|
children: slots.requests
|
|
262
261
|
})]
|
|
263
262
|
});
|
|
@@ -382,24 +381,38 @@ function ResponseContent({ item: { status, response, content }, onLink }) {
|
|
|
382
381
|
}
|
|
383
382
|
function AuthScheme({ scheme, scopes }) {
|
|
384
383
|
const t = useTranslations({ note: "security scheme" });
|
|
385
|
-
let name;
|
|
386
|
-
let type = "<token>";
|
|
387
|
-
let location;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
384
|
+
let name = t("Authorization");
|
|
385
|
+
let type = t("Bearer <token>");
|
|
386
|
+
let location = "header";
|
|
387
|
+
const configUrl = scheme.type === "openIdConnect" ? scheme.openIdConnectUrl : void 0;
|
|
388
|
+
switch (scheme.type) {
|
|
389
|
+
case "apiKey":
|
|
390
|
+
name = scheme.name;
|
|
391
|
+
type = "<token>";
|
|
392
|
+
location = scheme.in;
|
|
393
|
+
break;
|
|
394
|
+
case "mutualTLS":
|
|
395
|
+
name = t("Client certificate");
|
|
396
|
+
type = void 0;
|
|
397
|
+
location = "tls";
|
|
398
|
+
break;
|
|
399
|
+
case "http": {
|
|
400
|
+
const auth = scheme.scheme?.toLowerCase();
|
|
401
|
+
if (auth === "basic") type = t("Basic <token>");
|
|
402
|
+
else if (auth === "bearer" && scheme.bearerFormat) type = `Bearer <${scheme.bearerFormat}>`;
|
|
403
|
+
else if (scheme.scheme && auth !== "bearer") type = `${scheme.scheme[0].toUpperCase()}${scheme.scheme.slice(1)} <token>`;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
case "oauth2":
|
|
407
|
+
case "openIdConnect": break;
|
|
408
|
+
default: return null;
|
|
409
|
+
}
|
|
397
410
|
return /* @__PURE__ */ jsxs("div", {
|
|
398
411
|
className: "border-t py-2.5 first:border-t-0",
|
|
399
412
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
400
413
|
className: "flex flex-wrap items-center gap-2 not-prose",
|
|
401
414
|
children: [
|
|
402
|
-
|
|
415
|
+
/* @__PURE__ */ jsx("span", {
|
|
403
416
|
className: "rounded-md border bg-fd-secondary px-1.5 font-mono text-xs leading-5 text-fd-muted-foreground",
|
|
404
417
|
children: location
|
|
405
418
|
}),
|
|
@@ -407,7 +420,7 @@ function AuthScheme({ scheme, scopes }) {
|
|
|
407
420
|
className: "text-[0.8125rem] font-medium text-fd-primary",
|
|
408
421
|
children: name
|
|
409
422
|
}),
|
|
410
|
-
/* @__PURE__ */ jsx("code", {
|
|
423
|
+
type && /* @__PURE__ */ jsx("code", {
|
|
411
424
|
className: "text-xs text-fd-muted-foreground",
|
|
412
425
|
children: type
|
|
413
426
|
}),
|
|
@@ -417,13 +430,21 @@ function AuthScheme({ scheme, scopes }) {
|
|
|
417
430
|
children: t("Deprecated")
|
|
418
431
|
})
|
|
419
432
|
]
|
|
420
|
-
}), (scheme.description || scopes.length > 0) && /* @__PURE__ */ jsxs("div", {
|
|
433
|
+
}), (scheme.description || scopes.length > 0 || configUrl) && /* @__PURE__ */ jsxs("div", {
|
|
421
434
|
className: "mt-1 prose-no-margin text-fd-muted-foreground",
|
|
422
|
-
children: [
|
|
423
|
-
|
|
424
|
-
":
|
|
425
|
-
|
|
426
|
-
|
|
435
|
+
children: [
|
|
436
|
+
scheme.description && /* @__PURE__ */ jsx(Markdown, { md: scheme.description }),
|
|
437
|
+
configUrl && /* @__PURE__ */ jsxs("p", { children: [
|
|
438
|
+
t("OpenID Connect"),
|
|
439
|
+
": ",
|
|
440
|
+
/* @__PURE__ */ jsx("code", { children: configUrl })
|
|
441
|
+
] }),
|
|
442
|
+
scopes.length > 0 && /* @__PURE__ */ jsxs("p", { children: [
|
|
443
|
+
t("Scope"),
|
|
444
|
+
": ",
|
|
445
|
+
/* @__PURE__ */ jsx("code", { children: scopes.join(", ") })
|
|
446
|
+
] })
|
|
447
|
+
]
|
|
427
448
|
})]
|
|
428
449
|
});
|
|
429
450
|
}
|
|
@@ -482,7 +503,7 @@ function Callback({ item, path, headingLevel }) {
|
|
|
482
503
|
}),
|
|
483
504
|
/* @__PURE__ */ jsx("div", {
|
|
484
505
|
ref,
|
|
485
|
-
className: "fd-scroll-container prose min-h-0 flex-1 overflow-y-auto border-t p-5
|
|
506
|
+
className: "fd-scroll-container prose prose-sm min-h-0 flex-1 overflow-y-auto border-t p-5 @container [--fd-docs-row-3:0px]",
|
|
486
507
|
children: /* @__PURE__ */ jsx(AnchorSection, {
|
|
487
508
|
segments,
|
|
488
509
|
children: /* @__PURE__ */ jsx(Operation, {
|