fumadocs-openapi 12.0.0 → 12.0.1

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.
@@ -9,8 +9,8 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
9
9
  import { useArray, useDataEngine, useFieldValue, useObject } from "@fumari/stf";
10
10
  import { stringifyFieldKey } from "@fumari/stf/lib/utils";
11
11
  import { useTranslations } from "@fuma-translate/react";
12
- import { ChevronRight, Plus, Trash2, X } from "lucide-react";
13
12
  import { cva } from "class-variance-authority";
13
+ import { ChevronRight, Plus, Trash2, X } from "lucide-react";
14
14
  import { buttonVariants } from "fumadocs-ui/components/ui/button";
15
15
  //#region ../shared-api/dist/components/playground/inputs.js
16
16
  const fieldLabelVariants = cva("w-full inline-flex items-center gap-0.5");
@@ -6,8 +6,8 @@ import { mergeRefs } from "../../utils/merge-refs.js";
6
6
  import { Fragment, Suspense, createContext, use, useCallback, useDeferredValue, useEffect, useMemo, useRef, useState } from "react";
7
7
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
8
  import { useTranslations } from "@fuma-translate/react";
9
- import { CheckIcon, FilterIcon, LinkIcon } from "lucide-react";
10
9
  import { cva } from "class-variance-authority";
10
+ import { CheckIcon, FilterIcon, LinkIcon } from "lucide-react";
11
11
  import { buttonVariants } from "fumadocs-ui/components/ui/button";
12
12
  import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
13
13
  //#region ../shared-api/dist/components/schema/client.js
@@ -1,7 +1,26 @@
1
- import { SecuritySchemeObject } from "../types.js";
1
+ import { OAuth2SecurityScheme, OperationObject, SecuritySchemeObject } from "../types.js";
2
2
  import { ReactNode } from "react";
3
- import { FieldKey } from "@fumari/stf";
3
+ import { DataEngine, FieldKey } from "@fumari/stf";
4
4
  //#region src/playground/auth.d.ts
5
+ export type OAuthFlowType = keyof NonNullable<OAuth2SecurityScheme['flows']>;
6
+ export interface OAuthFlowInput {
7
+ /** name of the security scheme */
8
+ schemeId: string;
9
+ scopes: string[];
10
+ clientId: string;
11
+ clientSecret: string;
12
+ username: string;
13
+ password: string;
14
+ /** where the password flow sends the client credentials */
15
+ clientAuth: 'body' | 'header';
16
+ }
17
+ /**
18
+ * Run an OAuth flow and resolve its token.
19
+ *
20
+ * `implicit` and `authorizationCode` leave the page instead: the token is picked up on return,
21
+ * in `usePlaygroundAuth().store`.
22
+ */
23
+ export declare function requestOAuthToken(scheme: OAuth2SecurityScheme, type: OAuthFlowType, { schemeId, scopes, clientId, clientSecret, username, password, clientAuth }: OAuthFlowInput): Promise<string | undefined>;
5
24
  /** scheme name -> token info */
6
25
  type TokenStore = Record<string, TokenInfo | undefined>;
7
26
  type TokenInfo = {
@@ -22,6 +41,12 @@ interface AuthContextType {
22
41
  error?: unknown;
23
42
  }
24
43
  export declare function usePlaygroundAuth(): AuthContextType;
44
+ export interface AuthRequirement {
45
+ /** id of the security scheme */
46
+ id: string;
47
+ scopes: string[];
48
+ scheme: SecuritySchemeObject;
49
+ }
25
50
  export interface AuthField {
26
51
  schemeId: string;
27
52
  scheme: SecuritySchemeObject;
@@ -34,4 +59,27 @@ export interface AuthField {
34
59
  /** encode the value into request data, like the header of Basic auth */
35
60
  mapOutput?: (value: unknown) => unknown;
36
61
  }
62
+ export interface AuthFields {
63
+ /** the security requirements of the operation, one of them authorizes the request */
64
+ requirements: AuthRequirement[][];
65
+ /** index of the selected requirement, `-1` when the operation needs no authorization */
66
+ selected: number;
67
+ select: (index: number) => void;
68
+ /** the fields of the selected requirement */
69
+ fields: AuthField[];
70
+ /** encode the auth fields of form values into request data */
71
+ mapValues: <T>(values: T) => T;
72
+ /** write the persisted values into the form, returns a cleanup removing them */
73
+ init: () => () => void;
74
+ }
75
+ export interface AuthFieldsOptions {
76
+ /** the operation to authorize, defaults to the security of the document */
77
+ operation?: OperationObject;
78
+ /** customise the generated fields, like their default values */
79
+ transform?: (fields: AuthField[]) => AuthField[];
80
+ }
81
+ /**
82
+ * The auth fields of an API playground: the values it persists, and the request data they encode into.
83
+ */
84
+ export declare function useAuthFields(engine: DataEngine, { operation, transform }?: AuthFieldsOptions): AuthFields;
37
85
  //#endregion
@@ -1,3 +1,3 @@
1
1
  import { BrowserFetcherOptions, FetchErrorResult, FetchResponseResult, FetchResult, Fetcher, createBrowserFetcher } from "./fetcher.js";
2
- import { usePlaygroundAuth } from "./auth.js";
3
- export { type BrowserFetcherOptions, type FetchErrorResult, type FetchResponseResult, type FetchResult, type Fetcher, createBrowserFetcher, usePlaygroundAuth };
2
+ import { AuthField, AuthRequirement, OAuthFlowType, requestOAuthToken, useAuthFields, usePlaygroundAuth } from "./auth.js";
3
+ export { type AuthField, type AuthRequirement, type BrowserFetcherOptions, type FetchErrorResult, type FetchResponseResult, type FetchResult, type Fetcher, type OAuthFlowType, createBrowserFetcher, requestOAuthToken, useAuthFields, usePlaygroundAuth };
@@ -1,3 +1,3 @@
1
- import { usePlaygroundAuth } from "./auth.js";
1
+ import { requestOAuthToken, useAuthFields, usePlaygroundAuth } from "./auth.js";
2
2
  import { createBrowserFetcher } from "./fetcher.js";
3
- export { createBrowserFetcher, usePlaygroundAuth };
3
+ export { createBrowserFetcher, requestOAuthToken, useAuthFields, usePlaygroundAuth };
@@ -1,9 +1,9 @@
1
1
  import { fromSchema, getPageProps } from "../utils/pages/builder.js";
2
2
  import { toStaticData } from "../utils/pages/to-static-data.js";
3
3
  import { createAutoPreset } from "../utils/pages/preset-auto.js";
4
- import { MethodLabel } from "../ui/components/method-label.js";
5
4
  import { createProxy } from "./proxy.js";
6
5
  import { loadDocument } from "../utils/document/load.js";
6
+ import { MethodLabel } from "../ui/components/method-label.js";
7
7
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
8
  import path from "node:path";
9
9
  import { PathUtils } from "fumadocs-core/source";
@@ -1,12 +1,12 @@
1
1
  "use client";
2
2
  import { useOpenAPI, useRenderContext, useTypeScriptDefinitions } from "../../utils/create-page.js";
3
3
  import { OperationProvider, useOperation } from "../../operation.js";
4
+ import { Badge } from "../../packages/shared-api/dist/components/badge.js";
5
+ import { MethodLabel } from "../components/method-label.js";
4
6
  import { AnchorSection } from "../../packages/shared-api/dist/auto-anchor/client.js";
5
7
  import { AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger, Accordions } from "../../packages/shared-api/dist/components/accordion.js";
6
8
  import { Markdown } from "../components/markdown.js";
7
9
  import { UsageTabs } from "./usage-tabs.js";
8
- import { Badge } from "../../packages/shared-api/dist/components/badge.js";
9
- import { MethodLabel } from "../components/method-label.js";
10
10
  import { SchemaUI } from "../components/schema.js";
11
11
  import { RequestTabs } from "./request-tabs.js";
12
12
  import { cn } from "../../utils/cn.js";
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import { useRenderContext } from "../../utils/create-page.js";
3
3
  import { useExampleRequests, useOperation } from "../../operation.js";
4
+ import { MethodLabel } from "../components/method-label.js";
4
5
  import { AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger, Accordions } from "../../packages/shared-api/dist/components/accordion.js";
5
6
  import { Markdown } from "../components/markdown.js";
6
7
  import { ClientCodeBlock } from "../components/codeblock.js";
7
- import { MethodLabel } from "../components/method-label.js";
8
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
9
  import { useTranslations } from "@fuma-translate/react";
10
10
  import { Tabs, TabsContent, TabsList, TabsTrigger } from "fumadocs-ui/components/tabs";
@@ -6,8 +6,8 @@ import { useServer } from "../../utils/use-server.js";
6
6
  import { useOpenAPI } from "../../utils/create-page.js";
7
7
  import { encodeRequestData } from "../../requests/media/encode.js";
8
8
  import { useExampleRequests, useOperation } from "../../operation.js";
9
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../packages/shared-api/dist/components/select.js";
10
9
  import { MethodLabel } from "../components/method-label.js";
10
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../packages/shared-api/dist/components/select.js";
11
11
  import { cn } from "../../utils/cn.js";
12
12
  import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../../packages/shared-api/dist/components/collapsible.js";
13
13
  import { DefaultResultDisplay } from "./components/result-display.js";
@@ -76,7 +76,7 @@ function PlaygroundClient({ writeOnly, readOnly, transformAuthInputs, fetchOptio
76
76
  transform: transformAuthInputs
77
77
  });
78
78
  const testQuery = useQuery(async (input) => {
79
- const fetcher = await import("../../playground/fetcher.js").then((mod) => mod.createBrowserFetcher(mediaAdapters, {
79
+ const fetcher = await import("../../playground/index.js").then((mod) => mod.createBrowserFetcher(mediaAdapters, {
80
80
  proxyUrl,
81
81
  ...fetchOptions
82
82
  }));
@@ -7,8 +7,8 @@ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../../../pa
7
7
  import { Fragment, useEffect, useMemo, useState } from "react";
8
8
  import { jsx, jsxs } from "react/jsx-runtime";
9
9
  import { useTranslations } from "@fuma-translate/react";
10
- import { ChevronDown, CircleX, SignpostIcon } from "lucide-react";
11
10
  import { cva } from "class-variance-authority";
11
+ import { ChevronDown, CircleX, SignpostIcon } from "lucide-react";
12
12
  import { buttonVariants } from "fumadocs-ui/components/ui/button";
13
13
  //#region src/ui/playground/components/result-display.tsx
14
14
  var import_fast_content_type_parse = require_fast_content_type_parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "12.0.0",
3
+ "version": "12.0.1",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "Docs",
@@ -77,7 +77,7 @@
77
77
  "@types/react": "^19.3.0",
78
78
  "@types/react-dom": "^19.3.0",
79
79
  "fast-content-type-parse": "^4.0.0",
80
- "fuma-cli": "^0.1.1",
80
+ "fuma-cli": "^0.3.1",
81
81
  "fumadocs-core": "16.15.12",
82
82
  "fumadocs-ui": "npm:@fumadocs/base-ui@16.15.12",
83
83
  "json-schema-typed": "^8.0.2",