zudoku 0.53.0 → 0.53.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.
Files changed (75) hide show
  1. package/dist/app/demo.js +14 -0
  2. package/dist/app/demo.js.map +1 -1
  3. package/dist/lib/authentication/authentication.d.ts +2 -0
  4. package/dist/lib/authentication/components/SignIn.js +4 -3
  5. package/dist/lib/authentication/components/SignIn.js.map +1 -1
  6. package/dist/lib/authentication/providers/openid.d.ts +4 -2
  7. package/dist/lib/authentication/providers/openid.js +11 -5
  8. package/dist/lib/authentication/providers/openid.js.map +1 -1
  9. package/dist/lib/components/MobileTopNavigation.js +8 -5
  10. package/dist/lib/components/MobileTopNavigation.js.map +1 -1
  11. package/dist/lib/components/TopNavigation.d.ts +5 -0
  12. package/dist/lib/components/TopNavigation.js +16 -12
  13. package/dist/lib/components/TopNavigation.js.map +1 -1
  14. package/dist/lib/core/ZudokuContext.d.ts +2 -1
  15. package/dist/lib/core/ZudokuContext.js +14 -1
  16. package/dist/lib/core/ZudokuContext.js.map +1 -1
  17. package/dist/lib/plugins/api-keys/index.js +1 -1
  18. package/dist/lib/plugins/markdown/MdxPage.js +3 -2
  19. package/dist/lib/plugins/markdown/MdxPage.js.map +1 -1
  20. package/dist/lib/plugins/openapi/OperationList.js +1 -1
  21. package/dist/lib/plugins/openapi/OperationList.js.map +1 -1
  22. package/dist/lib/plugins/openapi/index.js +1 -1
  23. package/dist/lib/plugins/openapi/index.js.map +1 -1
  24. package/lib/{MdxPage-swXPJ0gf.js → MdxPage-8UuEK446.js} +37 -37
  25. package/lib/MdxPage-8UuEK446.js.map +1 -0
  26. package/lib/{OasProvider-CDAM3TB1.js → OasProvider-BsWpguVO.js} +2 -2
  27. package/lib/{OasProvider-CDAM3TB1.js.map → OasProvider-BsWpguVO.js.map} +1 -1
  28. package/lib/{OperationList-C9Hb9ql8.js → OperationList-PnZbf3b2.js} +6 -6
  29. package/lib/{OperationList-C9Hb9ql8.js.map → OperationList-PnZbf3b2.js.map} +1 -1
  30. package/lib/{Pagination-VGlgeCmS.js → Pagination-DY7gCrm4.js} +2 -2
  31. package/lib/{Pagination-VGlgeCmS.js.map → Pagination-DY7gCrm4.js.map} +1 -1
  32. package/lib/{SchemaList-BAbh1BXO.js → SchemaList-D6k4DKWH.js} +3 -3
  33. package/lib/{SchemaList-BAbh1BXO.js.map → SchemaList-D6k4DKWH.js.map} +1 -1
  34. package/lib/{SchemaView-C2Io712T.js → SchemaView-BhgJ9WB8.js} +3 -3
  35. package/lib/{SchemaView-C2Io712T.js.map → SchemaView-BhgJ9WB8.js.map} +1 -1
  36. package/lib/SignUp-CpUD6DUM.js +56 -0
  37. package/lib/SignUp-CpUD6DUM.js.map +1 -0
  38. package/lib/{circular-B42RaanD.js → circular-BUMjK3JF.js} +2 -2
  39. package/lib/{circular-B42RaanD.js.map → circular-BUMjK3JF.js.map} +1 -1
  40. package/lib/{createServer-BKFsRuuk.js → createServer-BPz8ZCrd.js} +3 -3
  41. package/lib/createServer-BPz8ZCrd.js.map +1 -0
  42. package/lib/{errors-CF2X_x5o.js → errors-DY-qOx9n.js} +3 -3
  43. package/lib/{errors-CF2X_x5o.js.map → errors-DY-qOx9n.js.map} +1 -1
  44. package/lib/{index-CLy1XyH0.js → index-C_xVKbf9.js} +1285 -1240
  45. package/lib/index-C_xVKbf9.js.map +1 -0
  46. package/lib/{index-B6Re5_cx.js → index-dVBKCNMa.js} +123 -123
  47. package/lib/{index-B6Re5_cx.js.map → index-dVBKCNMa.js.map} +1 -1
  48. package/lib/zudoku.auth-azureb2c.js +1 -1
  49. package/lib/zudoku.auth-clerk.js +1 -1
  50. package/lib/zudoku.auth-openid.js +114 -105
  51. package/lib/zudoku.auth-openid.js.map +1 -1
  52. package/lib/zudoku.components.js +1 -1
  53. package/lib/zudoku.plugin-api-catalog.js +1 -1
  54. package/lib/zudoku.plugin-api-keys.js +271 -265
  55. package/lib/zudoku.plugin-api-keys.js.map +1 -1
  56. package/lib/zudoku.plugin-markdown.js +1 -1
  57. package/lib/zudoku.plugin-openapi.js +1 -1
  58. package/package.json +4 -4
  59. package/src/app/demo.tsx +16 -1
  60. package/src/lib/authentication/authentication.ts +2 -2
  61. package/src/lib/authentication/components/SignIn.tsx +5 -12
  62. package/src/lib/authentication/providers/openid.tsx +23 -4
  63. package/src/lib/components/MobileTopNavigation.tsx +56 -7
  64. package/src/lib/components/TopNavigation.tsx +30 -14
  65. package/src/lib/core/ZudokuContext.ts +21 -0
  66. package/src/lib/plugins/api-keys/index.tsx +1 -1
  67. package/src/lib/plugins/markdown/MdxPage.tsx +3 -2
  68. package/src/lib/plugins/openapi/OperationList.tsx +1 -1
  69. package/src/lib/plugins/openapi/index.tsx +1 -1
  70. package/dist/flat-config.d.ts +0 -325
  71. package/lib/MdxPage-swXPJ0gf.js.map +0 -1
  72. package/lib/SignUp-5RUdVhnq.js +0 -63
  73. package/lib/SignUp-5RUdVhnq.js.map +0 -1
  74. package/lib/createServer-BKFsRuuk.js.map +0 -1
  75. package/lib/index-CLy1XyH0.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
2
2
  import { MenuIcon } from "lucide-react";
3
- import { useState } from "react";
3
+ import { Fragment, useState } from "react";
4
+ import { Skeleton } from "zudoku/ui/Skeleton.js";
4
5
  import { useAuth } from "../authentication/hook.js";
5
6
  import {
6
7
  Drawer,
@@ -8,6 +9,7 @@ import {
8
9
  DrawerTitle,
9
10
  DrawerTrigger,
10
11
  } from "../ui/Drawer.js";
12
+ import { ClientOnly } from "./ClientOnly.js";
11
13
  import { useZudoku } from "./context/ZudokuContext.js";
12
14
  import { PoweredByZudoku } from "./navigation/PoweredByZudoku.js";
13
15
  import { isHiddenItem } from "./navigation/utils.js";
@@ -15,13 +17,14 @@ import { PageProgress } from "./PageProgress.js";
15
17
  import { Search } from "./Search.js";
16
18
  import { Slot } from "./Slot.js";
17
19
  import { ThemeSwitch } from "./ThemeSwitch.js";
18
- import { TopNavItem } from "./TopNavigation.js";
20
+ import { TopNavItem, TopNavLink } from "./TopNavigation.js";
19
21
 
20
22
  export const MobileTopNavigation = () => {
21
- const { navigation, options } = useZudoku();
22
- const { isAuthenticated } = useAuth();
23
+ const { navigation, options, getProfileMenuItems } = useZudoku();
24
+ const { isAuthenticated, profile, isAuthEnabled, login } = useAuth();
23
25
  const [drawerOpen, setDrawerOpen] = useState(false);
24
26
 
27
+ const accountItems = getProfileMenuItems();
25
28
  const filteredItems = navigation.filter(isHiddenItem(isAuthenticated));
26
29
 
27
30
  return (
@@ -50,9 +53,36 @@ export const MobileTopNavigation = () => {
50
53
  <li className="empty:hidden">
51
54
  <Slot.Target name="top-navigation-side" />
52
55
  </li>
53
- <li>
54
- <ThemeSwitch />
55
- </li>
56
+
57
+ {isAuthEnabled && (
58
+ <ClientOnly
59
+ fallback={<Skeleton className="rounded-sm h-5 w-24 mr-4" />}
60
+ >
61
+ {!isAuthenticated ? (
62
+ <li>
63
+ <TopNavLink
64
+ to="/signin"
65
+ onClick={() => setDrawerOpen(false)}
66
+ >
67
+ Login
68
+ </TopNavLink>
69
+ </li>
70
+ ) : (
71
+ Object.values(getProfileMenuItems()).length > 0 && (
72
+ <Fragment>
73
+ <li>
74
+ {profile?.name ? `${profile.name}` : "My Account"}
75
+ {profile?.email && (
76
+ <div className="font-normal text-muted-foreground">
77
+ {profile.email}
78
+ </div>
79
+ )}
80
+ </li>
81
+ </Fragment>
82
+ )
83
+ )}
84
+ </ClientOnly>
85
+ )}
56
86
  {filteredItems.map((item) => (
57
87
  <li key={item.label}>
58
88
  <button type="button" onClick={() => setDrawerOpen(false)}>
@@ -60,6 +90,25 @@ export const MobileTopNavigation = () => {
60
90
  </button>
61
91
  </li>
62
92
  ))}
93
+ {isAuthEnabled && isAuthenticated && accountItems.length > 0 && (
94
+ <ClientOnly
95
+ fallback={<Skeleton className="rounded-sm h-5 w-24 mr-4" />}
96
+ >
97
+ {accountItems.map((i) => (
98
+ <li key={i.label}>
99
+ <TopNavLink
100
+ to={i.path ?? ""}
101
+ onClick={() => setDrawerOpen(false)}
102
+ >
103
+ {i.label}
104
+ </TopNavLink>
105
+ </li>
106
+ ))}
107
+ </ClientOnly>
108
+ )}
109
+ <li>
110
+ <ThemeSwitch />
111
+ </li>
63
112
  </ul>
64
113
  </div>
65
114
  {options.site?.showPoweredBy !== false && (
@@ -1,7 +1,7 @@
1
1
  import { cx } from "class-variance-authority";
2
2
  import { deepEqual } from "fast-equals";
3
3
  import { Suspense } from "react";
4
- import { NavLink } from "react-router";
4
+ import { NavLink, NavLinkProps } from "react-router";
5
5
  import { type NavigationItem } from "../../config/validators/NavigationSchema.js";
6
6
  import { useAuth } from "../authentication/hook.js";
7
7
  import { joinUrl } from "../util/joinUrl.js";
@@ -62,37 +62,53 @@ const getPathForItem = (item: NavigationItem): string => {
62
62
  }
63
63
  };
64
64
 
65
- export const TopNavItem = (item: NavigationItem) => {
66
- const currentNav = useCurrentNavigation();
67
- const isActiveTopNavItem = deepEqual(currentNav.topNavItem, item);
68
-
69
- const path = getPathForItem(item);
70
-
65
+ export const TopNavLink = ({
66
+ isActive,
67
+ children,
68
+ ...props
69
+ }: {
70
+ isActive?: boolean;
71
+ children: React.ReactNode;
72
+ } & NavLinkProps) => {
71
73
  return (
72
- // We don't use isActive here because it has to be inside the navigation,
73
- // the top nav id doesn't necessarily start with the navigation id
74
74
  <NavLink
75
75
  viewTransition
76
- to={path}
77
76
  className={({ isActive: isActiveNavLink, isPending }) => {
78
- const isActive = isActiveNavLink || isActiveTopNavItem;
77
+ const isActiveReal = isActiveNavLink || isActive;
79
78
  return cx(
80
79
  "flex items-center gap-2 lg:py-3.5 font-medium -mb-px transition duration-150 delay-75 relative",
81
- isActive || isPending
80
+ isActiveReal || isPending
82
81
  ? [
83
82
  "text-foreground",
84
83
  // underline with view transition animation
85
84
  "after:content-[''] after:absolute after:bottom-0 after:left-0 after:right-0",
86
85
  "after:h-0.5 after:bg-primary",
87
- isActive && "after:[view-transition-name:top-nav-underline]",
86
+ isActiveReal &&
87
+ "after:[view-transition-name:top-nav-underline]",
88
88
  isPending && "after:bg-primary/25",
89
89
  ]
90
90
  : "text-foreground/75 hover:text-foreground",
91
91
  );
92
92
  }}
93
+ {...props}
93
94
  >
95
+ {children}
96
+ </NavLink>
97
+ );
98
+ };
99
+
100
+ export const TopNavItem = (item: NavigationItem) => {
101
+ const currentNav = useCurrentNavigation();
102
+ const isActiveTopNavItem = deepEqual(currentNav.topNavItem, item);
103
+
104
+ const path = getPathForItem(item);
105
+
106
+ return (
107
+ // We don't use isActive here because it has to be inside the navigation,
108
+ // the top nav id doesn't necessarily start with the navigation id
109
+ <TopNavLink to={path} isActive={isActiveTopNavItem}>
94
110
  {item.icon && <item.icon size={16} className="align-[-0.125em]" />}
95
111
  {item.label}
96
- </NavLink>
112
+ </TopNavLink>
97
113
  );
98
114
  };
@@ -18,8 +18,10 @@ import {
18
18
  isAuthenticationPlugin,
19
19
  isEventConsumerPlugin,
20
20
  isNavigationPlugin,
21
+ isProfileMenuPlugin,
21
22
  type NavigationPlugin,
22
23
  needsInitialization,
24
+ ProfileNavigationItem,
23
25
  type ZudokuPlugin,
24
26
  } from "./plugins.js";
25
27
 
@@ -182,6 +184,16 @@ export class ZudokuContext {
182
184
  return navigations.flatMap((nav) => nav ?? []);
183
185
  };
184
186
 
187
+ getProfileMenuItems = () => {
188
+ const accountItems = this.plugins
189
+ .filter((p) => isProfileMenuPlugin(p))
190
+ .flatMap((p) => p.getProfileMenuItems(this))
191
+ .sort(sortByCategory(["top", "middle", "bottom"]))
192
+ .sort((i) => i.weight ?? 0);
193
+
194
+ return accountItems;
195
+ };
196
+
185
197
  signRequest = async (request: Request) => {
186
198
  if (!this.authentication) {
187
199
  throw new Error("No authentication provider configured");
@@ -190,3 +202,12 @@ export class ZudokuContext {
190
202
  return await this.authentication.signRequest(request);
191
203
  };
192
204
  }
205
+
206
+ const sortByCategory =
207
+ (categories: string[]) =>
208
+ (a: ProfileNavigationItem, b: ProfileNavigationItem) => {
209
+ const aIndex = categories.indexOf(a.category ?? "middle");
210
+ const bIndex = categories.indexOf(b.category ?? "middle");
211
+
212
+ return aIndex - bIndex;
213
+ };
@@ -154,7 +154,7 @@ const createDefaultHandler = (deploymentName: string): ApiKeyService => {
154
154
 
155
155
  return data.data.map((consumer) => ({
156
156
  id: consumer.id,
157
- label: consumer.label ?? consumer.subject ?? "API Key",
157
+ label: consumer.label || consumer.subject || "API Key",
158
158
  apiKeys: consumer.apiKeys.data,
159
159
  key: consumer.apiKeys.data.at(0),
160
160
  }));
@@ -53,10 +53,11 @@ export const MdxPage = ({
53
53
  const categoryTitle = useCurrentItem()?.categoryLabel;
54
54
 
55
55
  const title = frontmatter.title;
56
+ const description = frontmatter.description ?? excerpt;
56
57
  const category = frontmatter.category ?? categoryTitle;
57
58
  const hideToc = frontmatter.toc === false || defaultOptions?.toc === false;
58
59
  const pageTitle =
59
- tableOfContents.find((item) => item.depth === 1)?.value ?? title;
60
+ title ?? tableOfContents.find((item) => item.depth === 1)?.value;
60
61
  const hidePager =
61
62
  frontmatter.disable_pager ??
62
63
  frontmatter.disablePager ??
@@ -110,7 +111,7 @@ export const MdxPage = ({
110
111
  >
111
112
  <Helmet>
112
113
  <title>{pageTitle}</title>
113
- {excerpt && <meta name="description" content={excerpt} />}
114
+ {description && <meta name="description" content={description} />}
114
115
  </Helmet>
115
116
  <Typography className="max-w-full xl:w-full xl:max-w-3xl flex-1 shrink pt-(--padding-content-top)">
116
117
  {(category || title) && (
@@ -243,7 +243,7 @@ export const OperationList = ({
243
243
  registerNavigationAnchor
244
244
  className="mb-0"
245
245
  >
246
- {schema.tag.name ?? "Other endpoints"}
246
+ {schema.tag.name ?? "Documentation"}
247
247
  {showVersions && (
248
248
  <span className="text-xl text-muted-foreground ms-1.5">
249
249
  {" "}
@@ -166,7 +166,7 @@ export const openApiPlugin = (config: OasPluginConfig): ZudokuPlugin => {
166
166
  if (untaggedOperations) {
167
167
  categories.push(
168
168
  createNavigationCategory({
169
- label: "Other endpoints",
169
+ label: categories.length === 0 ? "Endpoints" : "Other endpoints",
170
170
  path: joinUrl(basePath, versionParam, UNTAGGED_PATH),
171
171
  operations: untaggedOperations,
172
172
  collapsed: !config.options?.expandAllTags,