@alepha/ui 0.35.0 → 0.36.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/README.md +54 -1
- package/dist/account/AccountBrand.d.ts +10 -3
- package/dist/account/AccountBrand.d.ts.map +1 -1
- package/dist/account/AccountBrand.js +12 -6
- package/dist/account/AccountBrand.js.map +1 -1
- package/dist/account/AccountLayout.d.ts.map +1 -1
- package/dist/account/AccountLayout.js +1 -1
- package/dist/account/AccountLayout.js.map +1 -1
- package/dist/admin/AdminUserDetail.d.ts +3 -3
- package/dist/admin/AdminUserDetail.js +3 -3
- package/dist/admin/AdminUserDetail.js.map +1 -1
- package/dist/ai/AiChat.d.ts +36 -6
- package/dist/ai/AiChat.d.ts.map +1 -1
- package/dist/ai/AiChat.js +101 -63
- package/dist/ai/AiChat.js.map +1 -1
- package/dist/ai/AiChatComposer.d.ts +22 -0
- package/dist/ai/AiChatComposer.d.ts.map +1 -0
- package/dist/ai/AiChatComposer.js +75 -0
- package/dist/ai/AiChatComposer.js.map +1 -0
- package/dist/ai/AiChatConfirmCard.d.ts +5 -2
- package/dist/ai/AiChatConfirmCard.d.ts.map +1 -1
- package/dist/ai/AiChatConfirmCard.js +7 -6
- package/dist/ai/AiChatConfirmCard.js.map +1 -1
- package/dist/ai/AiChatConfirmFields.d.ts +9 -0
- package/dist/ai/AiChatConfirmFields.d.ts.map +1 -0
- package/dist/ai/AiChatConfirmFields.js +45 -0
- package/dist/ai/AiChatConfirmFields.js.map +1 -0
- package/dist/ai/AiChatEmpty.d.ts +26 -0
- package/dist/ai/AiChatEmpty.d.ts.map +1 -0
- package/dist/ai/AiChatEmpty.js +47 -0
- package/dist/ai/AiChatEmpty.js.map +1 -0
- package/dist/ai/AiChatHistory.d.ts +3 -2
- package/dist/ai/AiChatHistory.d.ts.map +1 -1
- package/dist/ai/AiChatHistory.js +51 -22
- package/dist/ai/AiChatHistory.js.map +1 -1
- package/dist/ai/AiChatMessage.d.ts +14 -0
- package/dist/ai/AiChatMessage.d.ts.map +1 -1
- package/dist/ai/AiChatMessage.js +20 -12
- package/dist/ai/AiChatMessage.js.map +1 -1
- package/dist/ai/index.d.ts +3 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +4 -1
- package/dist/ai/useAiChat.d.ts +4 -0
- package/dist/ai/useAiChat.d.ts.map +1 -1
- package/dist/ai/useAiChat.js +15 -1
- package/dist/ai/useAiChat.js.map +1 -1
- package/dist/core/Sidebar.js +2 -2
- package/dist/core/Sidebar.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/useToast.d.ts +22 -1
- package/dist/core/useToast.d.ts.map +1 -1
- package/dist/core/useToast.js +4 -1
- package/dist/core/useToast.js.map +1 -1
- package/dist/core/useUndoable.d.ts +93 -0
- package/dist/core/useUndoable.d.ts.map +1 -0
- package/dist/core/useUndoable.js +172 -0
- package/dist/core/useUndoable.js.map +1 -0
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +50 -1
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/markdown/MarkdownView.d.ts +15 -0
- package/dist/markdown/MarkdownView.d.ts.map +1 -1
- package/dist/markdown/MarkdownView.js +4 -1
- package/dist/markdown/MarkdownView.js.map +1 -1
- package/dist/organizations/useInviteOrganizationMember.d.ts +2 -2
- package/dist/organizations/useInviteOrganizationMember.js.map +1 -1
- package/dist/shell/AppShellSidebarNavItem.d.ts.map +1 -1
- package/dist/shell/AppShellSidebarNavItem.js +25 -2
- package/dist/shell/AppShellSidebarNavItem.js.map +1 -1
- package/dist/shell/PlateTabBar.d.ts.map +1 -1
- package/dist/shell/PlateTabBar.js +2 -2
- package/dist/shell/PlateTabBar.js.map +1 -1
- package/dist/shell/SidebarBackHeader.d.ts +35 -0
- package/dist/shell/SidebarBackHeader.d.ts.map +1 -0
- package/dist/shell/SidebarBackHeader.js +34 -0
- package/dist/shell/SidebarBackHeader.js.map +1 -0
- package/dist/shell/appShellNav.d.ts +30 -0
- package/dist/shell/appShellNav.d.ts.map +1 -1
- package/dist/shell/appShellNav.js.map +1 -1
- package/dist/shell/index.d.ts +2 -1
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +2 -1
- package/dist/swagger/$uiSwagger.d.ts +75 -0
- package/dist/swagger/$uiSwagger.d.ts.map +1 -0
- package/dist/swagger/$uiSwagger.js +51 -0
- package/dist/swagger/$uiSwagger.js.map +1 -0
- package/dist/swagger/OpenApiSpec.d.ts +113 -0
- package/dist/swagger/OpenApiSpec.d.ts.map +1 -0
- package/dist/swagger/OpenApiSpec.js +186 -0
- package/dist/swagger/OpenApiSpec.js.map +1 -0
- package/dist/swagger/SwaggerAccessBadge.d.ts +16 -0
- package/dist/swagger/SwaggerAccessBadge.d.ts.map +1 -0
- package/dist/swagger/SwaggerAccessBadge.js +40 -0
- package/dist/swagger/SwaggerAccessBadge.js.map +1 -0
- package/dist/swagger/SwaggerAlephaMeta.d.ts +11 -0
- package/dist/swagger/SwaggerAlephaMeta.d.ts.map +1 -0
- package/dist/swagger/SwaggerAlephaMeta.js +103 -0
- package/dist/swagger/SwaggerAlephaMeta.js.map +1 -0
- package/dist/swagger/SwaggerCredentials.d.ts +11 -0
- package/dist/swagger/SwaggerCredentials.d.ts.map +1 -0
- package/dist/swagger/SwaggerCredentials.js +35 -0
- package/dist/swagger/SwaggerCredentials.js.map +1 -0
- package/dist/swagger/SwaggerExplorer.d.ts +31 -0
- package/dist/swagger/SwaggerExplorer.d.ts.map +1 -0
- package/dist/swagger/SwaggerExplorer.js +156 -0
- package/dist/swagger/SwaggerExplorer.js.map +1 -0
- package/dist/swagger/SwaggerMethodBadge.d.ts +10 -0
- package/dist/swagger/SwaggerMethodBadge.d.ts.map +1 -0
- package/dist/swagger/SwaggerMethodBadge.js +27 -0
- package/dist/swagger/SwaggerMethodBadge.js.map +1 -0
- package/dist/swagger/SwaggerNav.d.ts +16 -0
- package/dist/swagger/SwaggerNav.d.ts.map +1 -0
- package/dist/swagger/SwaggerNav.js +63 -0
- package/dist/swagger/SwaggerNav.js.map +1 -0
- package/dist/swagger/SwaggerOperationView.d.ts +22 -0
- package/dist/swagger/SwaggerOperationView.d.ts.map +1 -0
- package/dist/swagger/SwaggerOperationView.js +89 -0
- package/dist/swagger/SwaggerOperationView.js.map +1 -0
- package/dist/swagger/SwaggerParameters.d.ts +11 -0
- package/dist/swagger/SwaggerParameters.d.ts.map +1 -0
- package/dist/swagger/SwaggerParameters.js +80 -0
- package/dist/swagger/SwaggerParameters.js.map +1 -0
- package/dist/swagger/SwaggerRequestBuilder.d.ts +83 -0
- package/dist/swagger/SwaggerRequestBuilder.d.ts.map +1 -0
- package/dist/swagger/SwaggerRequestBuilder.js +231 -0
- package/dist/swagger/SwaggerRequestBuilder.js.map +1 -0
- package/dist/swagger/SwaggerResponseView.d.ts +25 -0
- package/dist/swagger/SwaggerResponseView.d.ts.map +1 -0
- package/dist/swagger/SwaggerResponseView.js +94 -0
- package/dist/swagger/SwaggerResponseView.js.map +1 -0
- package/dist/swagger/SwaggerResponses.d.ts +12 -0
- package/dist/swagger/SwaggerResponses.d.ts.map +1 -0
- package/dist/swagger/SwaggerResponses.js +75 -0
- package/dist/swagger/SwaggerResponses.js.map +1 -0
- package/dist/swagger/SwaggerSchemaView.d.ts +19 -0
- package/dist/swagger/SwaggerSchemaView.d.ts.map +1 -0
- package/dist/swagger/SwaggerSchemaView.js +98 -0
- package/dist/swagger/SwaggerSchemaView.js.map +1 -0
- package/dist/swagger/SwaggerSection.d.ts +14 -0
- package/dist/swagger/SwaggerSection.d.ts.map +1 -0
- package/dist/swagger/SwaggerSection.js +23 -0
- package/dist/swagger/SwaggerSection.js.map +1 -0
- package/dist/swagger/SwaggerTryIt.d.ts +31 -0
- package/dist/swagger/SwaggerTryIt.d.ts.map +1 -0
- package/dist/swagger/SwaggerTryIt.js +68 -0
- package/dist/swagger/SwaggerTryIt.js.map +1 -0
- package/dist/swagger/SwaggerTryItForm.d.ts +20 -0
- package/dist/swagger/SwaggerTryItForm.d.ts.map +1 -0
- package/dist/swagger/SwaggerTryItForm.js +52 -0
- package/dist/swagger/SwaggerTryItForm.js.map +1 -0
- package/dist/swagger/index.d.ts +29 -0
- package/dist/swagger/index.d.ts.map +1 -0
- package/dist/swagger/index.js +18 -0
- package/dist/swagger/useSwaggerAccess.d.ts +24 -0
- package/dist/swagger/useSwaggerAccess.d.ts.map +1 -0
- package/dist/swagger/useSwaggerAccess.js +33 -0
- package/dist/swagger/useSwaggerAccess.js.map +1 -0
- package/dist/table/DataTable.d.ts.map +1 -1
- package/dist/table/DataTable.js +50 -13
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableBody.d.ts +18 -1
- package/dist/table/DataTableBody.d.ts.map +1 -1
- package/dist/table/DataTableBody.js +83 -58
- package/dist/table/DataTableBody.js.map +1 -1
- package/dist/table/DataTableRowActionsInline.d.ts +17 -0
- package/dist/table/DataTableRowActionsInline.d.ts.map +1 -0
- package/dist/table/DataTableRowActionsInline.js +45 -0
- package/dist/table/DataTableRowActionsInline.js.map +1 -0
- package/dist/table/PermissionMatrix.d.ts +4 -4
- package/dist/table/PermissionMatrix.js +2 -2
- package/dist/table/PermissionMatrix.js.map +1 -1
- package/dist/table/dataTableBaseProps.d.ts +31 -0
- package/dist/table/dataTableBaseProps.d.ts.map +1 -1
- package/dist/table/dataTableTypes.d.ts +16 -2
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/useDataTableData.d.ts +3 -0
- package/dist/table/useDataTableData.d.ts.map +1 -1
- package/dist/table/useDataTableData.js +9 -2
- package/dist/table/useDataTableData.js.map +1 -1
- package/dist/table/useDataTableRefresh.d.ts +1 -0
- package/dist/table/useDataTableRefresh.d.ts.map +1 -1
- package/dist/table/useDataTableRefresh.js +13 -1
- package/dist/table/useDataTableRefresh.js.map +1 -1
- package/dist/table/useOptimisticRows.d.ts +64 -0
- package/dist/table/useOptimisticRows.d.ts.map +1 -0
- package/dist/table/useOptimisticRows.js +185 -0
- package/dist/table/useOptimisticRows.js.map +1 -0
- package/dist/table/useRowMotion.d.ts +27 -0
- package/dist/table/useRowMotion.d.ts.map +1 -0
- package/dist/table/useRowMotion.js +112 -0
- package/dist/table/useRowMotion.js.map +1 -0
- package/docs/packages-alepha-ui-core.md +1 -0
- package/docs/packages-alepha-ui-overview.md +53 -1
- package/docs/packages-alepha-ui-swagger.md +35 -0
- package/package.json +11 -3
- package/src/account/AccountBrand.tsx +25 -6
- package/src/account/AccountLayout.tsx +5 -1
- package/src/admin/AdminUserDetail.tsx +3 -3
- package/src/admin/__tests__/AdminUserDetail.spec.ts +2 -2
- package/src/ai/AiChat.tsx +160 -82
- package/src/ai/AiChatComposer.tsx +117 -0
- package/src/ai/AiChatConfirmCard.tsx +7 -5
- package/src/ai/AiChatConfirmFields.tsx +65 -0
- package/src/ai/AiChatEmpty.tsx +73 -0
- package/src/ai/AiChatHistory.tsx +64 -28
- package/src/ai/AiChatMessage.tsx +41 -14
- package/src/ai/__tests__/AiChat.browser.spec.tsx +146 -5
- package/src/ai/index.ts +3 -0
- package/src/ai/useAiChat.ts +18 -0
- package/src/core/Sidebar.tsx +2 -2
- package/src/core/__tests__/useUndoable.browser.spec.tsx +201 -0
- package/src/core/index.ts +7 -0
- package/src/core/useToast.tsx +30 -2
- package/src/core/useUndoable.tsx +285 -0
- package/src/form/__tests__/ControlChoices.browser.spec.tsx +2 -1
- package/src/i18n/fr/uiFr.ts +52 -0
- package/src/markdown/MarkdownView.tsx +27 -9
- package/src/organizations/useInviteOrganizationMember.ts +2 -2
- package/src/shell/AppShellSidebarNavItem.tsx +51 -1
- package/src/shell/PlateTabBar.tsx +8 -2
- package/src/shell/SidebarBackHeader.tsx +58 -0
- package/src/shell/appShellNav.tsx +31 -0
- package/src/shell/index.ts +5 -1
- package/src/swagger/$uiSwagger.tsx +95 -0
- package/src/swagger/OpenApiSpec.ts +300 -0
- package/src/swagger/SwaggerAccessBadge.tsx +64 -0
- package/src/swagger/SwaggerAlephaMeta.tsx +141 -0
- package/src/swagger/SwaggerCredentials.tsx +44 -0
- package/src/swagger/SwaggerExplorer.tsx +208 -0
- package/src/swagger/SwaggerMethodBadge.tsx +32 -0
- package/src/swagger/SwaggerNav.tsx +92 -0
- package/src/swagger/SwaggerOperationView.tsx +102 -0
- package/src/swagger/SwaggerParameters.tsx +74 -0
- package/src/swagger/SwaggerRequestBuilder.ts +331 -0
- package/src/swagger/SwaggerResponseView.tsx +107 -0
- package/src/swagger/SwaggerResponses.tsx +83 -0
- package/src/swagger/SwaggerSchemaView.tsx +134 -0
- package/src/swagger/SwaggerSection.tsx +29 -0
- package/src/swagger/SwaggerTryIt.tsx +95 -0
- package/src/swagger/SwaggerTryItForm.tsx +87 -0
- package/src/swagger/__tests__/$uiSwagger.spec.ts +52 -0
- package/src/swagger/__tests__/OpenApiSpec.spec.ts +139 -0
- package/src/swagger/__tests__/SwaggerAccess.browser.spec.tsx +124 -0
- package/src/swagger/__tests__/SwaggerOperationView.browser.spec.tsx +194 -0
- package/src/swagger/__tests__/SwaggerRequestBuilder.spec.ts +250 -0
- package/src/swagger/index.ts +75 -0
- package/src/swagger/useSwaggerAccess.ts +59 -0
- package/src/table/DataTable.tsx +85 -34
- package/src/table/DataTableBody.tsx +51 -7
- package/src/table/DataTableRowActionsInline.tsx +80 -0
- package/src/table/PermissionMatrix.tsx +4 -4
- package/src/table/__tests__/DataTableEmptyState.browser.spec.tsx +1 -1
- package/src/table/__tests__/DataTableListMode.browser.spec.tsx +174 -0
- package/src/table/__tests__/DataTableOptimistic.browser.spec.tsx +173 -0
- package/src/table/__tests__/PermissionMatrix.browser.spec.tsx +2 -2
- package/src/table/__tests__/queryFilters.spec.ts +10 -12
- package/src/table/dataTableBaseProps.ts +31 -0
- package/src/table/dataTableTypes.ts +16 -2
- package/src/table/useDataTableData.ts +18 -2
- package/src/table/useDataTableRefresh.ts +26 -2
- package/src/table/useOptimisticRows.ts +265 -0
- package/src/table/useRowMotion.ts +152 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Middleware } from "alepha";
|
|
2
|
+
import { type PagePrimitive } from "alepha/react/router";
|
|
3
|
+
import type { SwaggerExplorerProps } from "./SwaggerExplorer.tsx";
|
|
4
|
+
export interface UiSwaggerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The page's name in the router, for `router.push(name)`.
|
|
7
|
+
*
|
|
8
|
+
* @default "swagger"
|
|
9
|
+
*/
|
|
10
|
+
name?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Where the explorer is mounted.
|
|
13
|
+
*
|
|
14
|
+
* @default "/docs"
|
|
15
|
+
*/
|
|
16
|
+
path?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Where the OpenAPI document is served: `<prefix>/json` of the app's
|
|
19
|
+
* `$swagger`, or any OpenAPI 3 document the browser may fetch.
|
|
20
|
+
*
|
|
21
|
+
* @default "/docs/json"
|
|
22
|
+
*/
|
|
23
|
+
spec?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The browser tab's title.
|
|
26
|
+
*
|
|
27
|
+
* @default "API"
|
|
28
|
+
*/
|
|
29
|
+
title?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Where to sign in, linked from a gated operation when nobody is signed in.
|
|
32
|
+
*
|
|
33
|
+
* @default "/auth/login"
|
|
34
|
+
*/
|
|
35
|
+
signIn?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Middlewares guarding the page, `[$secure({ roles: ["admin"] })]` for an
|
|
38
|
+
* explorer only the team should see. The OpenAPI document itself is served
|
|
39
|
+
* by `$swagger`: guard that route too, or the JSON stays public.
|
|
40
|
+
*/
|
|
41
|
+
use?: Middleware[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* An API explorer page, reading the app's OpenAPI document.
|
|
45
|
+
*
|
|
46
|
+
* `alepha/server/swagger` serves the document only (`$swagger`, at
|
|
47
|
+
* `/docs/json` by default); this is the viewer, built on `@alepha/ui`. It
|
|
48
|
+
* lists the operations by tag with a search, and shows each in full:
|
|
49
|
+
* parameters, request body, responses, their schemas, and what Alepha
|
|
50
|
+
* declared about it (the action, who may call it, middlewares, declared
|
|
51
|
+
* errors, timeout) from the `x-alepha-*` extensions. Each operation can be
|
|
52
|
+
* called from a form built from its schemas, as the signed-in user (the
|
|
53
|
+
* session cookie) or with a token typed in, and a gated one says whether the
|
|
54
|
+
* viewer's permissions reach it.
|
|
55
|
+
*
|
|
56
|
+
* The page and the document share the `/docs` prefix by default, which is
|
|
57
|
+
* fine: the page is `/docs`, the document `/docs/json`.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { $swagger } from "alepha/server/swagger";
|
|
61
|
+
* import { $uiSwagger } from "@alepha/ui/swagger";
|
|
62
|
+
*
|
|
63
|
+
* class App {
|
|
64
|
+
* openapi = $swagger({ info: { title: "Shop API", version: "1.0.0" } });
|
|
65
|
+
* docs = $uiSwagger();
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* It carries the `$` prefix to sit with the framework's other declarations
|
|
70
|
+
* at a call site, but it is a plain function wrapping `$page`, like
|
|
71
|
+
* `$pageAdmin`. The page component is a lazy chunk, so an app pays for the
|
|
72
|
+
* explorer only when someone opens it.
|
|
73
|
+
*/
|
|
74
|
+
export declare const $uiSwagger: (options?: UiSwaggerOptions) => PagePrimitive<any, SwaggerExplorerProps>;
|
|
75
|
+
//# sourceMappingURL=$uiSwagger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"$uiSwagger.d.ts","sourceRoot":"","sources":["../../src/swagger/$uiSwagger.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAS,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAElE,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,UAAU,aACZ,gBAAgB,KACxB,aAAa,CAAC,GAAG,EAAE,oBAAoB,CAWzC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { $page } from "alepha/react/router";
|
|
2
|
+
// src/swagger/$uiSwagger.tsx
|
|
3
|
+
/**
|
|
4
|
+
* An API explorer page, reading the app's OpenAPI document.
|
|
5
|
+
*
|
|
6
|
+
* `alepha/server/swagger` serves the document only (`$swagger`, at
|
|
7
|
+
* `/docs/json` by default); this is the viewer, built on `@alepha/ui`. It
|
|
8
|
+
* lists the operations by tag with a search, and shows each in full:
|
|
9
|
+
* parameters, request body, responses, their schemas, and what Alepha
|
|
10
|
+
* declared about it (the action, who may call it, middlewares, declared
|
|
11
|
+
* errors, timeout) from the `x-alepha-*` extensions. Each operation can be
|
|
12
|
+
* called from a form built from its schemas, as the signed-in user (the
|
|
13
|
+
* session cookie) or with a token typed in, and a gated one says whether the
|
|
14
|
+
* viewer's permissions reach it.
|
|
15
|
+
*
|
|
16
|
+
* The page and the document share the `/docs` prefix by default, which is
|
|
17
|
+
* fine: the page is `/docs`, the document `/docs/json`.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { $swagger } from "alepha/server/swagger";
|
|
21
|
+
* import { $uiSwagger } from "@alepha/ui/swagger";
|
|
22
|
+
*
|
|
23
|
+
* class App {
|
|
24
|
+
* openapi = $swagger({ info: { title: "Shop API", version: "1.0.0" } });
|
|
25
|
+
* docs = $uiSwagger();
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* It carries the `$` prefix to sit with the framework's other declarations
|
|
30
|
+
* at a call site, but it is a plain function wrapping `$page`, like
|
|
31
|
+
* `$pageAdmin`. The page component is a lazy chunk, so an app pays for the
|
|
32
|
+
* explorer only when someone opens it.
|
|
33
|
+
*/
|
|
34
|
+
const $uiSwagger = (options = {}) => {
|
|
35
|
+
const specUrl = options.spec ?? "/docs/json";
|
|
36
|
+
const signIn = options.signIn ?? "/auth/login";
|
|
37
|
+
return $page({
|
|
38
|
+
name: options.name ?? "swagger",
|
|
39
|
+
path: options.path ?? "/docs",
|
|
40
|
+
use: options.use,
|
|
41
|
+
head: { title: options.title ?? "API" },
|
|
42
|
+
props: () => ({
|
|
43
|
+
specUrl,
|
|
44
|
+
signIn
|
|
45
|
+
}),
|
|
46
|
+
lazy: () => import("./SwaggerExplorer.js")
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
export { $uiSwagger };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=$uiSwagger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"$uiSwagger.js","names":[],"sources":["../../src/swagger/$uiSwagger.tsx"],"sourcesContent":["import type { Middleware } from \"alepha\";\nimport { $page, type PagePrimitive } from \"alepha/react/router\";\n\nimport type { SwaggerExplorerProps } from \"./SwaggerExplorer.tsx\";\n\nexport interface UiSwaggerOptions {\n /**\n * The page's name in the router, for `router.push(name)`.\n *\n * @default \"swagger\"\n */\n name?: string;\n\n /**\n * Where the explorer is mounted.\n *\n * @default \"/docs\"\n */\n path?: string;\n\n /**\n * Where the OpenAPI document is served: `<prefix>/json` of the app's\n * `$swagger`, or any OpenAPI 3 document the browser may fetch.\n *\n * @default \"/docs/json\"\n */\n spec?: string;\n\n /**\n * The browser tab's title.\n *\n * @default \"API\"\n */\n title?: string;\n\n /**\n * Where to sign in, linked from a gated operation when nobody is signed in.\n *\n * @default \"/auth/login\"\n */\n signIn?: string;\n\n /**\n * Middlewares guarding the page, `[$secure({ roles: [\"admin\"] })]` for an\n * explorer only the team should see. The OpenAPI document itself is served\n * by `$swagger`: guard that route too, or the JSON stays public.\n */\n use?: Middleware[];\n}\n\n/**\n * An API explorer page, reading the app's OpenAPI document.\n *\n * `alepha/server/swagger` serves the document only (`$swagger`, at\n * `/docs/json` by default); this is the viewer, built on `@alepha/ui`. It\n * lists the operations by tag with a search, and shows each in full:\n * parameters, request body, responses, their schemas, and what Alepha\n * declared about it (the action, who may call it, middlewares, declared\n * errors, timeout) from the `x-alepha-*` extensions. Each operation can be\n * called from a form built from its schemas, as the signed-in user (the\n * session cookie) or with a token typed in, and a gated one says whether the\n * viewer's permissions reach it.\n *\n * The page and the document share the `/docs` prefix by default, which is\n * fine: the page is `/docs`, the document `/docs/json`.\n *\n * ```ts\n * import { $swagger } from \"alepha/server/swagger\";\n * import { $uiSwagger } from \"@alepha/ui/swagger\";\n *\n * class App {\n * openapi = $swagger({ info: { title: \"Shop API\", version: \"1.0.0\" } });\n * docs = $uiSwagger();\n * }\n * ```\n *\n * It carries the `$` prefix to sit with the framework's other declarations\n * at a call site, but it is a plain function wrapping `$page`, like\n * `$pageAdmin`. The page component is a lazy chunk, so an app pays for the\n * explorer only when someone opens it.\n */\nexport const $uiSwagger = (\n options: UiSwaggerOptions = {},\n): PagePrimitive<any, SwaggerExplorerProps> => {\n const specUrl = options.spec ?? \"/docs/json\";\n const signIn = options.signIn ?? \"/auth/login\";\n return $page<any, SwaggerExplorerProps>({\n name: options.name ?? \"swagger\",\n path: options.path ?? \"/docs\",\n use: options.use,\n head: { title: options.title ?? \"API\" },\n props: () => ({ specUrl, signIn }),\n lazy: () => import(\"./SwaggerExplorer.tsx\"),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,MAAa,cACX,UAA4B,CAAC,MACgB;CAC7C,MAAM,UAAU,QAAQ,QAAQ;CAChC,MAAM,SAAS,QAAQ,UAAU;CACjC,OAAO,MAAiC;EACtC,MAAM,QAAQ,QAAQ;EACtB,MAAM,QAAQ,QAAQ;EACtB,KAAK,QAAQ;EACb,MAAM,EAAE,OAAO,QAAQ,SAAS,MAAM;EACtC,cAAc;GAAE;GAAS;EAAO;EAChC,YAAY,OAAO;CACrB,CAAC;AACH"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { OpenApiDocument, OpenApiOperation } from "alepha/server/swagger";
|
|
2
|
+
/**
|
|
3
|
+
* One operation of the document, with where it lives.
|
|
4
|
+
*/
|
|
5
|
+
export interface SwaggerEntry {
|
|
6
|
+
/**
|
|
7
|
+
* Stable identifier: the `operationId`, else `METHOD path`.
|
|
8
|
+
*/
|
|
9
|
+
id: string;
|
|
10
|
+
method: string;
|
|
11
|
+
path: string;
|
|
12
|
+
tag: string;
|
|
13
|
+
operation: OpenApiOperation;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The operations of one tag, in document order.
|
|
17
|
+
*/
|
|
18
|
+
export interface SwaggerGroup {
|
|
19
|
+
tag: string;
|
|
20
|
+
entries: SwaggerEntry[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* What `$secure` and friends declared about an operation, from its
|
|
24
|
+
* `x-alepha-security` extension. `{}` means a signed-in user is enough.
|
|
25
|
+
*/
|
|
26
|
+
export interface SwaggerSecurity {
|
|
27
|
+
roles?: string[];
|
|
28
|
+
permissions?: string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The Alepha extensions an operation may carry; see the OpenAPI guide.
|
|
32
|
+
*/
|
|
33
|
+
export interface SwaggerAlephaMetadata {
|
|
34
|
+
action?: {
|
|
35
|
+
name: string;
|
|
36
|
+
group: string;
|
|
37
|
+
};
|
|
38
|
+
middlewares?: string[];
|
|
39
|
+
security?: SwaggerSecurity;
|
|
40
|
+
errors?: string[];
|
|
41
|
+
timeout?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A read-only view of an OpenAPI document, shaped for the explorer.
|
|
45
|
+
*
|
|
46
|
+
* Plain data in, plain data out: it holds no React state, so a spec can
|
|
47
|
+
* build one from a literal document and every component reads the same
|
|
48
|
+
* answers.
|
|
49
|
+
*/
|
|
50
|
+
export declare class OpenApiSpec {
|
|
51
|
+
/**
|
|
52
|
+
* The HTTP methods OpenAPI allows under a path, in the order the explorer
|
|
53
|
+
* lists them. Anything else under a path (`parameters`, `summary`, an
|
|
54
|
+
* extension) is not an operation.
|
|
55
|
+
*/
|
|
56
|
+
static readonly METHODS: string[];
|
|
57
|
+
readonly document: OpenApiDocument;
|
|
58
|
+
readonly entries: SwaggerEntry[];
|
|
59
|
+
constructor(document: OpenApiDocument);
|
|
60
|
+
get title(): string;
|
|
61
|
+
get version(): string | undefined;
|
|
62
|
+
get description(): string | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* The operations grouped by their first tag, groups in first-seen order,
|
|
65
|
+
* keeping only those matching `query` (see {@link matches}).
|
|
66
|
+
*/
|
|
67
|
+
groups(query?: string): SwaggerGroup[];
|
|
68
|
+
/**
|
|
69
|
+
* Whether an entry matches a free-text query: every whitespace-separated
|
|
70
|
+
* term must appear, case-insensitively, in its method, path, tag, summary,
|
|
71
|
+
* operation id or action name.
|
|
72
|
+
*/
|
|
73
|
+
matches(entry: SwaggerEntry, query: string): boolean;
|
|
74
|
+
find(id: string | undefined): SwaggerEntry | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Follow a local `$ref` (`#/components/schemas/X`) to its target, at most
|
|
77
|
+
* once per call: the schema viewer resolves lazily, one level at a time, so
|
|
78
|
+
* a recursive schema never loops.
|
|
79
|
+
*/
|
|
80
|
+
resolve(schema: any): any;
|
|
81
|
+
/**
|
|
82
|
+
* A copy of a schema with every local `$ref` inlined, down to `maxDepth`
|
|
83
|
+
* levels; past it a reference becomes `{}`, which is what keeps a recursive
|
|
84
|
+
* schema finite. For consumers that need the whole tree at once (the form
|
|
85
|
+
* builder), where the viewer resolves one level at a time.
|
|
86
|
+
*/
|
|
87
|
+
dereference(schema: any, maxDepth?: number, depth?: number): any;
|
|
88
|
+
/**
|
|
89
|
+
* The name a `$ref` points at (`Product` for `#/components/schemas/Product`).
|
|
90
|
+
*/
|
|
91
|
+
refName(schema: any): string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* A one-line type for a schema: `string<email>`, `Product` (a `$ref`, or a
|
|
94
|
+
* titled object), `array<Product>`, `"a" | "b"`, `string | null`.
|
|
95
|
+
*/
|
|
96
|
+
typeLabel(schema: any): string;
|
|
97
|
+
/**
|
|
98
|
+
* Whether the viewer can open a schema further: an object with properties,
|
|
99
|
+
* an array of one, a reference, or a union.
|
|
100
|
+
*/
|
|
101
|
+
isExpandable(schema: any): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* The `x-alepha-*` extensions of an operation, typed.
|
|
104
|
+
*/
|
|
105
|
+
metadata(operation: OpenApiOperation): SwaggerAlephaMetadata;
|
|
106
|
+
/**
|
|
107
|
+
* Whether the operation needs an identity: Alepha's own `x-alepha-security`
|
|
108
|
+
* when present, else a non-empty OpenAPI `security` requirement.
|
|
109
|
+
*/
|
|
110
|
+
isSecured(operation: OpenApiOperation): boolean;
|
|
111
|
+
protected collect(): SwaggerEntry[];
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=OpenApiSpec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenApiSpec.d.ts","sourceRoot":"","sources":["../../src/swagger/OpenApiSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,YAAY;IAC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G,SAAS,GAAG,YAAY,GAAG,SAAS,CAE5D;IAED;;;;OAIG;IACI,OAAO,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,CAU/B;IAED;;;;;OAKG;IACI,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,SAAI,EAAE,KAAK,SAAI,GAAG,GAAG,CAkB5D;IAED;;OAEG;IACI,OAAO,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAG9C;IAED;;;OAGG;IACI,SAAS,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,CA+CpC;IAED;;;OAGG;IACI,YAAY,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAYxC;IAED;;OAEG;IACI,QAAQ,CAAC,SAAS,EAAE,gBAAgB,GAAG,qBAAqB,CAQlE;IAED;;;OAGG;IACI,SAAS,CAAC,SAAS,EAAE,gBAAgB,GAAG,OAAO,CAKrD;IAED,SAAS,CAAC,OAAO,IAAI,YAAY,EAAE,CAkBlC;CACF"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// src/swagger/OpenApiSpec.ts
|
|
2
|
+
/**
|
|
3
|
+
* A read-only view of an OpenAPI document, shaped for the explorer.
|
|
4
|
+
*
|
|
5
|
+
* Plain data in, plain data out: it holds no React state, so a spec can
|
|
6
|
+
* build one from a literal document and every component reads the same
|
|
7
|
+
* answers.
|
|
8
|
+
*/
|
|
9
|
+
var OpenApiSpec = class OpenApiSpec {
|
|
10
|
+
/**
|
|
11
|
+
* The HTTP methods OpenAPI allows under a path, in the order the explorer
|
|
12
|
+
* lists them. Anything else under a path (`parameters`, `summary`, an
|
|
13
|
+
* extension) is not an operation.
|
|
14
|
+
*/
|
|
15
|
+
static METHODS = [
|
|
16
|
+
"get",
|
|
17
|
+
"post",
|
|
18
|
+
"put",
|
|
19
|
+
"patch",
|
|
20
|
+
"delete",
|
|
21
|
+
"head",
|
|
22
|
+
"options",
|
|
23
|
+
"trace"
|
|
24
|
+
];
|
|
25
|
+
document;
|
|
26
|
+
entries;
|
|
27
|
+
constructor(document) {
|
|
28
|
+
this.document = document;
|
|
29
|
+
this.entries = this.collect();
|
|
30
|
+
}
|
|
31
|
+
get title() {
|
|
32
|
+
return this.document.info?.title ?? "API";
|
|
33
|
+
}
|
|
34
|
+
get version() {
|
|
35
|
+
return this.document.info?.version;
|
|
36
|
+
}
|
|
37
|
+
get description() {
|
|
38
|
+
return this.document.info?.description;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The operations grouped by their first tag, groups in first-seen order,
|
|
42
|
+
* keeping only those matching `query` (see {@link matches}).
|
|
43
|
+
*/
|
|
44
|
+
groups(query = "") {
|
|
45
|
+
const groups = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const entry of this.entries) {
|
|
47
|
+
if (!this.matches(entry, query)) continue;
|
|
48
|
+
const list = groups.get(entry.tag) ?? [];
|
|
49
|
+
list.push(entry);
|
|
50
|
+
groups.set(entry.tag, list);
|
|
51
|
+
}
|
|
52
|
+
return [...groups].map(([tag, entries]) => ({
|
|
53
|
+
tag,
|
|
54
|
+
entries
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether an entry matches a free-text query: every whitespace-separated
|
|
59
|
+
* term must appear, case-insensitively, in its method, path, tag, summary,
|
|
60
|
+
* operation id or action name.
|
|
61
|
+
*/
|
|
62
|
+
matches(entry, query) {
|
|
63
|
+
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
64
|
+
if (!terms.length) return true;
|
|
65
|
+
const meta = this.metadata(entry.operation);
|
|
66
|
+
const haystack = [
|
|
67
|
+
entry.method,
|
|
68
|
+
entry.path,
|
|
69
|
+
entry.tag,
|
|
70
|
+
entry.operation.summary,
|
|
71
|
+
entry.operation.operationId,
|
|
72
|
+
meta.action?.name
|
|
73
|
+
].filter(Boolean).join(" ").toLowerCase();
|
|
74
|
+
return terms.every((term) => haystack.includes(term));
|
|
75
|
+
}
|
|
76
|
+
find(id) {
|
|
77
|
+
return id ? this.entries.find((entry) => entry.id === id) : void 0;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Follow a local `$ref` (`#/components/schemas/X`) to its target, at most
|
|
81
|
+
* once per call: the schema viewer resolves lazily, one level at a time, so
|
|
82
|
+
* a recursive schema never loops.
|
|
83
|
+
*/
|
|
84
|
+
resolve(schema) {
|
|
85
|
+
const ref = schema?.$ref;
|
|
86
|
+
if (typeof ref !== "string" || !ref.startsWith("#/")) return schema;
|
|
87
|
+
let target = this.document;
|
|
88
|
+
for (const part of ref.slice(2).split("/")) target = target?.[part.replace(/~1/g, "/").replace(/~0/g, "~")];
|
|
89
|
+
return target ?? schema;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A copy of a schema with every local `$ref` inlined, down to `maxDepth`
|
|
93
|
+
* levels; past it a reference becomes `{}`, which is what keeps a recursive
|
|
94
|
+
* schema finite. For consumers that need the whole tree at once (the form
|
|
95
|
+
* builder), where the viewer resolves one level at a time.
|
|
96
|
+
*/
|
|
97
|
+
dereference(schema, maxDepth = 8, depth = 0) {
|
|
98
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
99
|
+
if (Array.isArray(schema)) return schema.map((it) => this.dereference(it, maxDepth, depth));
|
|
100
|
+
if (typeof schema.$ref === "string") {
|
|
101
|
+
if (depth >= maxDepth) return {};
|
|
102
|
+
return this.dereference(this.resolve(schema), maxDepth, depth + 1);
|
|
103
|
+
}
|
|
104
|
+
const out = {};
|
|
105
|
+
for (const [key, value] of Object.entries(schema)) out[key] = this.dereference(value, maxDepth, depth);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The name a `$ref` points at (`Product` for `#/components/schemas/Product`).
|
|
110
|
+
*/
|
|
111
|
+
refName(schema) {
|
|
112
|
+
const ref = schema?.$ref;
|
|
113
|
+
return typeof ref === "string" ? ref.split("/").pop() : void 0;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A one-line type for a schema: `string<email>`, `Product` (a `$ref`, or a
|
|
117
|
+
* titled object), `array<Product>`, `"a" | "b"`, `string | null`.
|
|
118
|
+
*/
|
|
119
|
+
typeLabel(schema) {
|
|
120
|
+
if (!schema || typeof schema !== "object") return "any";
|
|
121
|
+
const name = this.refName(schema);
|
|
122
|
+
if (name) return name;
|
|
123
|
+
if (typeof schema.title === "string" && schema.properties) return schema.title;
|
|
124
|
+
if (Array.isArray(schema.enum)) return schema.enum.map((it) => JSON.stringify(it)).join(" | ");
|
|
125
|
+
if (schema.const !== void 0) return JSON.stringify(schema.const);
|
|
126
|
+
const variants = schema.oneOf ?? schema.anyOf;
|
|
127
|
+
if (Array.isArray(variants)) return variants.map((it) => this.typeLabel(it)).join(" | ");
|
|
128
|
+
if (Array.isArray(schema.allOf)) return schema.allOf.map((it) => this.typeLabel(it)).join(" & ");
|
|
129
|
+
const label = (Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : []).map((type) => {
|
|
130
|
+
if (type === "array") return `array<${this.typeLabel(schema.items)}>`;
|
|
131
|
+
if (type === "object" && schema.additionalProperties && !schema.properties) return `record<${this.typeLabel(schema.additionalProperties)}>`;
|
|
132
|
+
return schema.format ? `${type}<${schema.format}>` : type;
|
|
133
|
+
}).join(" | ");
|
|
134
|
+
const nullable = schema.nullable ? " | null" : "";
|
|
135
|
+
return (label || (schema.properties ? "object" : "any")) + nullable;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Whether the viewer can open a schema further: an object with properties,
|
|
139
|
+
* an array of one, a reference, or a union.
|
|
140
|
+
*/
|
|
141
|
+
isExpandable(schema) {
|
|
142
|
+
const target = this.resolve(schema);
|
|
143
|
+
if (!target || typeof target !== "object") return false;
|
|
144
|
+
if (target.properties && Object.keys(target.properties).length) return true;
|
|
145
|
+
if (target.items) return this.isExpandable(target.items);
|
|
146
|
+
return Array.isArray(target.oneOf ?? target.anyOf ?? target.allOf);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The `x-alepha-*` extensions of an operation, typed.
|
|
150
|
+
*/
|
|
151
|
+
metadata(operation) {
|
|
152
|
+
return {
|
|
153
|
+
action: operation["x-alepha-action"],
|
|
154
|
+
middlewares: operation["x-alepha-middlewares"],
|
|
155
|
+
security: operation["x-alepha-security"],
|
|
156
|
+
errors: operation["x-alepha-errors"],
|
|
157
|
+
timeout: operation["x-alepha-timeout"]
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Whether the operation needs an identity: Alepha's own `x-alepha-security`
|
|
162
|
+
* when present, else a non-empty OpenAPI `security` requirement.
|
|
163
|
+
*/
|
|
164
|
+
isSecured(operation) {
|
|
165
|
+
if (operation["x-alepha-security"] !== void 0) return true;
|
|
166
|
+
return !!operation.security?.some((it) => Object.keys(it).length > 0);
|
|
167
|
+
}
|
|
168
|
+
collect() {
|
|
169
|
+
const entries = [];
|
|
170
|
+
for (const [path, item] of Object.entries(this.document.paths ?? {})) for (const method of OpenApiSpec.METHODS) {
|
|
171
|
+
const operation = item?.[method];
|
|
172
|
+
if (!operation || typeof operation !== "object") continue;
|
|
173
|
+
entries.push({
|
|
174
|
+
id: operation.operationId ?? `${method.toUpperCase()} ${path}`,
|
|
175
|
+
method,
|
|
176
|
+
path,
|
|
177
|
+
tag: operation.tags?.[0] ?? "default",
|
|
178
|
+
operation
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return entries;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
export { OpenApiSpec };
|
|
185
|
+
|
|
186
|
+
//# sourceMappingURL=OpenApiSpec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenApiSpec.js","names":[],"sources":["../../src/swagger/OpenApiSpec.ts"],"sourcesContent":["import type { OpenApiDocument, OpenApiOperation } from \"alepha/server/swagger\";\n\n/**\n * One operation of the document, with where it lives.\n */\nexport interface SwaggerEntry {\n /**\n * Stable identifier: the `operationId`, else `METHOD path`.\n */\n id: string;\n method: string;\n path: string;\n tag: string;\n operation: OpenApiOperation;\n}\n\n/**\n * The operations of one tag, in document order.\n */\nexport interface SwaggerGroup {\n tag: string;\n entries: SwaggerEntry[];\n}\n\n/**\n * What `$secure` and friends declared about an operation, from its\n * `x-alepha-security` extension. `{}` means a signed-in user is enough.\n */\nexport interface SwaggerSecurity {\n roles?: string[];\n permissions?: string[];\n}\n\n/**\n * The Alepha extensions an operation may carry; see the OpenAPI guide.\n */\nexport interface SwaggerAlephaMetadata {\n action?: { name: string; group: string };\n middlewares?: string[];\n security?: SwaggerSecurity;\n errors?: string[];\n timeout?: number;\n}\n\n/**\n * A read-only view of an OpenAPI document, shaped for the explorer.\n *\n * Plain data in, plain data out: it holds no React state, so a spec can\n * build one from a literal document and every component reads the same\n * answers.\n */\nexport class OpenApiSpec {\n /**\n * The HTTP methods OpenAPI allows under a path, in the order the explorer\n * lists them. Anything else under a path (`parameters`, `summary`, an\n * extension) is not an operation.\n */\n public static readonly METHODS = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"head\",\n \"options\",\n \"trace\",\n ];\n\n public readonly document: OpenApiDocument;\n public readonly entries: SwaggerEntry[];\n\n constructor(document: OpenApiDocument) {\n this.document = document;\n this.entries = this.collect();\n }\n\n public get title(): string {\n return this.document.info?.title ?? \"API\";\n }\n\n public get version(): string | undefined {\n return this.document.info?.version;\n }\n\n public get description(): string | undefined {\n return this.document.info?.description;\n }\n\n /**\n * The operations grouped by their first tag, groups in first-seen order,\n * keeping only those matching `query` (see {@link matches}).\n */\n public groups(query = \"\"): SwaggerGroup[] {\n const groups = new Map<string, SwaggerEntry[]>();\n for (const entry of this.entries) {\n if (!this.matches(entry, query)) {\n continue;\n }\n const list = groups.get(entry.tag) ?? [];\n list.push(entry);\n groups.set(entry.tag, list);\n }\n return [...groups].map(([tag, entries]) => ({ tag, entries }));\n }\n\n /**\n * Whether an entry matches a free-text query: every whitespace-separated\n * term must appear, case-insensitively, in its method, path, tag, summary,\n * operation id or action name.\n */\n public matches(entry: SwaggerEntry, query: string): boolean {\n const terms = query.toLowerCase().split(/\\s+/).filter(Boolean);\n if (!terms.length) {\n return true;\n }\n const meta = this.metadata(entry.operation);\n const haystack = [\n entry.method,\n entry.path,\n entry.tag,\n entry.operation.summary,\n entry.operation.operationId,\n meta.action?.name,\n ]\n .filter(Boolean)\n .join(\" \")\n .toLowerCase();\n return terms.every((term) => haystack.includes(term));\n }\n\n public find(id: string | undefined): SwaggerEntry | undefined {\n return id ? this.entries.find((entry) => entry.id === id) : undefined;\n }\n\n /**\n * Follow a local `$ref` (`#/components/schemas/X`) to its target, at most\n * once per call: the schema viewer resolves lazily, one level at a time, so\n * a recursive schema never loops.\n */\n public resolve(schema: any): any {\n const ref = schema?.$ref;\n if (typeof ref !== \"string\" || !ref.startsWith(\"#/\")) {\n return schema;\n }\n let target: any = this.document;\n for (const part of ref.slice(2).split(\"/\")) {\n target = target?.[part.replace(/~1/g, \"/\").replace(/~0/g, \"~\")];\n }\n return target ?? schema;\n }\n\n /**\n * A copy of a schema with every local `$ref` inlined, down to `maxDepth`\n * levels; past it a reference becomes `{}`, which is what keeps a recursive\n * schema finite. For consumers that need the whole tree at once (the form\n * builder), where the viewer resolves one level at a time.\n */\n public dereference(schema: any, maxDepth = 8, depth = 0): any {\n if (!schema || typeof schema !== \"object\") {\n return schema;\n }\n if (Array.isArray(schema)) {\n return schema.map((it) => this.dereference(it, maxDepth, depth));\n }\n if (typeof schema.$ref === \"string\") {\n if (depth >= maxDepth) {\n return {};\n }\n return this.dereference(this.resolve(schema), maxDepth, depth + 1);\n }\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(schema)) {\n out[key] = this.dereference(value, maxDepth, depth);\n }\n return out;\n }\n\n /**\n * The name a `$ref` points at (`Product` for `#/components/schemas/Product`).\n */\n public refName(schema: any): string | undefined {\n const ref = schema?.$ref;\n return typeof ref === \"string\" ? ref.split(\"/\").pop() : undefined;\n }\n\n /**\n * A one-line type for a schema: `string<email>`, `Product` (a `$ref`, or a\n * titled object), `array<Product>`, `\"a\" | \"b\"`, `string | null`.\n */\n public typeLabel(schema: any): string {\n if (!schema || typeof schema !== \"object\") {\n return \"any\";\n }\n const name = this.refName(schema);\n if (name) {\n return name;\n }\n // A titled schema the generator inlined (array items are not hoisted).\n if (typeof schema.title === \"string\" && schema.properties) {\n return schema.title;\n }\n if (Array.isArray(schema.enum)) {\n return schema.enum.map((it: unknown) => JSON.stringify(it)).join(\" | \");\n }\n if (schema.const !== undefined) {\n return JSON.stringify(schema.const);\n }\n const variants = schema.oneOf ?? schema.anyOf;\n if (Array.isArray(variants)) {\n return variants.map((it: any) => this.typeLabel(it)).join(\" | \");\n }\n if (Array.isArray(schema.allOf)) {\n return schema.allOf.map((it: any) => this.typeLabel(it)).join(\" & \");\n }\n const types: string[] = Array.isArray(schema.type)\n ? schema.type\n : schema.type\n ? [schema.type]\n : [];\n const label = types\n .map((type) => {\n if (type === \"array\") {\n return `array<${this.typeLabel(schema.items)}>`;\n }\n if (\n type === \"object\" &&\n schema.additionalProperties &&\n !schema.properties\n ) {\n return `record<${this.typeLabel(schema.additionalProperties)}>`;\n }\n return schema.format ? `${type}<${schema.format}>` : type;\n })\n .join(\" | \");\n const nullable = schema.nullable ? \" | null\" : \"\";\n return (label || (schema.properties ? \"object\" : \"any\")) + nullable;\n }\n\n /**\n * Whether the viewer can open a schema further: an object with properties,\n * an array of one, a reference, or a union.\n */\n public isExpandable(schema: any): boolean {\n const target = this.resolve(schema);\n if (!target || typeof target !== \"object\") {\n return false;\n }\n if (target.properties && Object.keys(target.properties).length) {\n return true;\n }\n if (target.items) {\n return this.isExpandable(target.items);\n }\n return Array.isArray(target.oneOf ?? target.anyOf ?? target.allOf);\n }\n\n /**\n * The `x-alepha-*` extensions of an operation, typed.\n */\n public metadata(operation: OpenApiOperation): SwaggerAlephaMetadata {\n return {\n action: operation[\"x-alepha-action\"] as SwaggerAlephaMetadata[\"action\"],\n middlewares: operation[\"x-alepha-middlewares\"] as string[] | undefined,\n security: operation[\"x-alepha-security\"] as SwaggerSecurity | undefined,\n errors: operation[\"x-alepha-errors\"] as string[] | undefined,\n timeout: operation[\"x-alepha-timeout\"] as number | undefined,\n };\n }\n\n /**\n * Whether the operation needs an identity: Alepha's own `x-alepha-security`\n * when present, else a non-empty OpenAPI `security` requirement.\n */\n public isSecured(operation: OpenApiOperation): boolean {\n if (operation[\"x-alepha-security\"] !== undefined) {\n return true;\n }\n return !!operation.security?.some((it) => Object.keys(it).length > 0);\n }\n\n protected collect(): SwaggerEntry[] {\n const entries: SwaggerEntry[] = [];\n for (const [path, item] of Object.entries(this.document.paths ?? {})) {\n for (const method of OpenApiSpec.METHODS) {\n const operation = (item as Record<string, OpenApiOperation>)?.[method];\n if (!operation || typeof operation !== \"object\") {\n continue;\n }\n entries.push({\n id: operation.operationId ?? `${method.toUpperCase()} ${path}`,\n method,\n path,\n tag: operation.tags?.[0] ?? \"default\",\n operation,\n });\n }\n }\n return entries;\n }\n}\n"],"mappings":";;;;;;;;AAmDA,IAAa,cAAb,MAAa,YAAY;;;;;;CAMvB,OAAuB,UAAU;EAC/B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA;CACA;CAEA,YAAY,UAA2B;EACrC,KAAK,WAAW;EAChB,KAAK,UAAU,KAAK,QAAQ;CAC9B;CAEA,IAAW,QAAgB;EACzB,OAAO,KAAK,SAAS,MAAM,SAAS;CACtC;CAEA,IAAW,UAA8B;EACvC,OAAO,KAAK,SAAS,MAAM;CAC7B;CAEA,IAAW,cAAkC;EAC3C,OAAO,KAAK,SAAS,MAAM;CAC7B;;;;;CAMA,OAAc,QAAQ,IAAoB;EACxC,MAAM,yBAAS,IAAI,IAA4B;EAC/C,KAAK,MAAM,SAAS,KAAK,SAAS;GAChC,IAAI,CAAC,KAAK,QAAQ,OAAO,KAAK,GAC5B;GAEF,MAAM,OAAO,OAAO,IAA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A,KAAK,UAAU,OAAO,MAAM;IAC5B;GACF,CAAC;EACH;EAEF,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SwaggerAccess } from "./useSwaggerAccess.ts";
|
|
2
|
+
export interface SwaggerAccessBadgeProps {
|
|
3
|
+
access: SwaggerAccess;
|
|
4
|
+
/**
|
|
5
|
+
* Where to sign in, offered when the operation is gated and nobody is
|
|
6
|
+
* signed in.
|
|
7
|
+
*/
|
|
8
|
+
signIn?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Whether the viewer may call an operation, as a chip: allowed, not allowed,
|
|
12
|
+
* sign in first, or signed in with nothing to check against. Renders nothing
|
|
13
|
+
* for an open operation.
|
|
14
|
+
*/
|
|
15
|
+
export declare const SwaggerAccessBadge: (props: SwaggerAccessBadgeProps) => import("react").JSX.Element | null;
|
|
16
|
+
//# sourceMappingURL=SwaggerAccessBadge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwaggerAccessBadge.d.ts","sourceRoot":"","sources":["../../src/swagger/SwaggerAccessBadge.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,aAAa,CAAC;IACtB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,UAAW,uBAAuB,uCA2ChE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Badge } from "../core/Badge.js";
|
|
2
|
+
import { useI18n } from "alepha/react/i18n";
|
|
3
|
+
import { Lock, LockOpen, ShieldCheck, ShieldX } from "lucide-react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/swagger/SwaggerAccessBadge.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Whether the viewer may call an operation, as a chip: allowed, not allowed,
|
|
8
|
+
* sign in first, or signed in with nothing to check against. Renders nothing
|
|
9
|
+
* for an open operation.
|
|
10
|
+
*/
|
|
11
|
+
const SwaggerAccessBadge = (props) => {
|
|
12
|
+
const { tr } = useI18n();
|
|
13
|
+
switch (props.access) {
|
|
14
|
+
case "open": return null;
|
|
15
|
+
case "allowed": return /* @__PURE__ */ jsxs(Badge, {
|
|
16
|
+
variant: "tint",
|
|
17
|
+
tone: "success",
|
|
18
|
+
children: [/* @__PURE__ */ jsx(ShieldCheck, {}), tr("swagger.access.allowed", { default: "You can call this" })]
|
|
19
|
+
});
|
|
20
|
+
case "denied": return /* @__PURE__ */ jsxs(Badge, {
|
|
21
|
+
variant: "tint",
|
|
22
|
+
tone: "danger",
|
|
23
|
+
children: [/* @__PURE__ */ jsx(ShieldX, {}), tr("swagger.access.denied", { default: "Your permissions do not reach this" })]
|
|
24
|
+
});
|
|
25
|
+
case "anonymous": return /* @__PURE__ */ jsxs(Badge, {
|
|
26
|
+
variant: "tint",
|
|
27
|
+
tone: "warning",
|
|
28
|
+
render: props.signIn ? /* @__PURE__ */ jsx("a", { href: props.signIn }) : void 0,
|
|
29
|
+
children: [/* @__PURE__ */ jsx(Lock, {}), tr("swagger.access.signIn", { default: "Sign in to call this" })]
|
|
30
|
+
});
|
|
31
|
+
case "unknown": return /* @__PURE__ */ jsxs(Badge, {
|
|
32
|
+
variant: "tint",
|
|
33
|
+
tone: "neutral",
|
|
34
|
+
children: [/* @__PURE__ */ jsx(LockOpen, {}), tr("swagger.access.unknown", { default: "Signed in; access checked on call" })]
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export { SwaggerAccessBadge };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=SwaggerAccessBadge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwaggerAccessBadge.js","names":[],"sources":["../../src/swagger/SwaggerAccessBadge.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { Lock, LockOpen, ShieldCheck, ShieldX } from \"lucide-react\";\n\nimport { Badge } from \"../core/Badge.tsx\";\nimport type { SwaggerAccess } from \"./useSwaggerAccess.ts\";\n\nexport interface SwaggerAccessBadgeProps {\n access: SwaggerAccess;\n /**\n * Where to sign in, offered when the operation is gated and nobody is\n * signed in.\n */\n signIn?: string;\n}\n\n/**\n * Whether the viewer may call an operation, as a chip: allowed, not allowed,\n * sign in first, or signed in with nothing to check against. Renders nothing\n * for an open operation.\n */\nexport const SwaggerAccessBadge = (props: SwaggerAccessBadgeProps) => {\n const { tr } = useI18n();\n\n switch (props.access) {\n case \"open\":\n return null;\n case \"allowed\":\n return (\n <Badge variant=\"tint\" tone=\"success\">\n <ShieldCheck />\n {tr(\"swagger.access.allowed\", { default: \"You can call this\" })}\n </Badge>\n );\n case \"denied\":\n return (\n <Badge variant=\"tint\" tone=\"danger\">\n <ShieldX />\n {tr(\"swagger.access.denied\", {\n default: \"Your permissions do not reach this\",\n })}\n </Badge>\n );\n case \"anonymous\":\n return (\n <Badge\n variant=\"tint\"\n tone=\"warning\"\n render={props.signIn ? <a href={props.signIn} /> : undefined}\n >\n <Lock />\n {tr(\"swagger.access.signIn\", { default: \"Sign in to call this\" })}\n </Badge>\n );\n case \"unknown\":\n return (\n <Badge variant=\"tint\" tone=\"neutral\">\n <LockOpen />\n {tr(\"swagger.access.unknown\", {\n default: \"Signed in; access checked on call\",\n })}\n </Badge>\n );\n }\n};\n"],"mappings":";;;;;;;;;;AAoBA,MAAa,sBAAsB,UAAmC;CACpE,MAAM,EAAE,OAAO,QAAQ;CAEvB,QAAQ,MAAM,QAAd;EACE,KAAK,QACH,OAAO;EACT,KAAK,WACH,OACE,qBAAC,OAAD;GAAO,SAAQ;GAAO,MAAK;GAA3B,UAAA,CACE,oBAAC,aAAD,CAAc,CAAA,GACb,GAAG,0BAA0B,EAAE,SAAS,oBAAoB,CAAC,CACzD;;EAEX,KAAK,UACH,OACE,qBAAC,OAAD;GAAO,SAAQ;GAAO,MAAK;GAA3B,UAAA,CACE,oBAAC,SAAD,CAAU,CAAA,GACT,GAAG,yBAAyB,EAC3B,SAAS,qCACX,CAAC,CACI;;EAEX,KAAK,aACH,OACE,qBAAC,OAAD;GACE,SAAQ;GACR,MAAK;GACL,QAAQ,MAAM,SAAS,oBAAC,KAAD,EAAG,MAAM,MAAM,OAAS,CAAA,IAAI,KAAA;GAHrD,UAAA,CAKE,oBAAC,MAAD,CAAO,CAAA,GACN,GAAG,yBAAyB,EAAE,SAAS,uBAAuB,CAAC,CAC3D;;EAEX,KAAK,WACH,OACE,qBAAC,OAAD;GAAO,SAAQ;GAAO,MAAK;GAA3B,UAAA,CACE,oBAAC,UAAD,CAAW,CAAA,GACV,GAAG,0BAA0B,EAC5B,SAAS,oCACX,CAAC,CACI;;CAEb;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SwaggerAlephaMetadata } from "./OpenApiSpec.ts";
|
|
2
|
+
export interface SwaggerAlephaMetaProps {
|
|
3
|
+
metadata: SwaggerAlephaMetadata;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* What Alepha declared about an operation, from its `x-alepha-*` extensions:
|
|
7
|
+
* the action, who may call it, its middlewares, declared errors and timeout.
|
|
8
|
+
* Renders nothing for an operation that carries none of them.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SwaggerAlephaMeta: (props: SwaggerAlephaMetaProps) => import("react").JSX.Element | null;
|
|
11
|
+
//# sourceMappingURL=SwaggerAlephaMeta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwaggerAlephaMeta.d.ts","sourceRoot":"","sources":["../../src/swagger/SwaggerAlephaMeta.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,qBAAqB,CAAC;CACjC;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,UAAW,sBAAsB,uCAuH9D,CAAC"}
|