zudoku 0.1.1-dev.18 → 0.1.1-dev.19

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 (139) hide show
  1. package/dist/lib/plugins/openapi/worker/createSharedWorkerClient.js +2 -3
  2. package/dist/lib/plugins/openapi/worker/createSharedWorkerClient.js.map +1 -1
  3. package/dist/lib/plugins/openapi/worker/shared-worker.d.ts +1 -0
  4. package/dist/lib/plugins/openapi/worker/shared-worker.js +6 -0
  5. package/dist/lib/plugins/openapi/worker/shared-worker.js.map +1 -0
  6. package/dist/vite/config.d.ts +1 -1
  7. package/dist/vite/config.js +13 -13
  8. package/dist/vite/config.js.map +1 -1
  9. package/dist/vite/dev-server.js +1 -1
  10. package/dist/vite/dev-server.js.map +1 -1
  11. package/lib/zudoku.openapi-worker.js +12 -0
  12. package/lib/zudoku.plugins.js +1318 -1323
  13. package/package.json +5 -2
  14. package/src/cli/build/handler.ts +14 -0
  15. package/src/cli/cli.ts +77 -0
  16. package/src/cli/cmds/build.ts +24 -0
  17. package/src/cli/cmds/dev.ts +29 -0
  18. package/src/cli/common/analytics/lib.ts +89 -0
  19. package/src/cli/common/constants.ts +10 -0
  20. package/src/cli/common/logger.ts +5 -0
  21. package/src/cli/common/machine-id/lib.ts +85 -0
  22. package/src/cli/common/outdated.ts +102 -0
  23. package/src/cli/common/output.ts +86 -0
  24. package/src/cli/common/utils/box.license.txt +202 -0
  25. package/src/cli/common/utils/box.ts +116 -0
  26. package/src/cli/common/utils/ports.ts +21 -0
  27. package/src/cli/common/validators/lib.ts +43 -0
  28. package/src/cli/common/xdg/lib.ts +36 -0
  29. package/src/cli/dev/handler.ts +42 -0
  30. package/src/config/config.ts +56 -0
  31. package/src/index.ts +8 -0
  32. package/src/lib/DevPortal.tsx +93 -0
  33. package/src/lib/Heading.tsx +60 -0
  34. package/src/lib/Router.tsx +28 -0
  35. package/src/lib/auth.ts +1 -0
  36. package/src/lib/authentication/authentication.ts +18 -0
  37. package/src/lib/authentication/clerk.ts +45 -0
  38. package/src/lib/authentication/openid.ts +192 -0
  39. package/src/lib/components/AnchorLink.tsx +19 -0
  40. package/src/lib/components/CategoryHeading.tsx +16 -0
  41. package/src/lib/components/Dialog.tsx +119 -0
  42. package/src/lib/components/DynamicIcon.tsx +60 -0
  43. package/src/lib/components/Header.tsx +69 -0
  44. package/src/lib/components/Input.tsx +24 -0
  45. package/src/lib/components/Layout.tsx +56 -0
  46. package/src/lib/components/Markdown.tsx +37 -0
  47. package/src/lib/components/SyntaxHighlight.tsx +94 -0
  48. package/src/lib/components/TopNavigation.tsx +32 -0
  49. package/src/lib/components/context/ComponentsContext.tsx +24 -0
  50. package/src/lib/components/context/DevPortalProvider.ts +54 -0
  51. package/src/lib/components/context/PluginSystem.ts +0 -0
  52. package/src/lib/components/context/ThemeContext.tsx +46 -0
  53. package/src/lib/components/context/ViewportAnchorContext.tsx +139 -0
  54. package/src/lib/components/navigation/SideNavigation.tsx +18 -0
  55. package/src/lib/components/navigation/SideNavigationCategory.tsx +74 -0
  56. package/src/lib/components/navigation/SideNavigationItem.tsx +143 -0
  57. package/src/lib/components/navigation/SideNavigationWrapper.tsx +15 -0
  58. package/src/lib/components/navigation/useNavigationCollapsibleState.ts +27 -0
  59. package/src/lib/components/navigation/util.ts +38 -0
  60. package/src/lib/components.ts +3 -0
  61. package/src/lib/core/DevPortalContext.ts +164 -0
  62. package/src/lib/core/helmet.ts +5 -0
  63. package/src/lib/core/icons.tsx +1 -0
  64. package/src/lib/core/plugins.ts +43 -0
  65. package/src/lib/core/router.tsx +1 -0
  66. package/src/lib/core/types/combine.ts +16 -0
  67. package/src/lib/oas/graphql/index.ts +422 -0
  68. package/src/lib/oas/graphql/server.ts +10 -0
  69. package/src/lib/oas/parser/dereference/index.ts +59 -0
  70. package/src/lib/oas/parser/dereference/resolveRef.ts +32 -0
  71. package/src/lib/oas/parser/index.ts +94 -0
  72. package/src/lib/oas/parser/schemas/v3.0.json +1489 -0
  73. package/src/lib/oas/parser/schemas/v3.1.json +1298 -0
  74. package/src/lib/oas/parser/upgrade/index.ts +108 -0
  75. package/src/lib/plugins/api-key/SettingsApiKeys.tsx +22 -0
  76. package/src/lib/plugins/api-key/index.tsx +123 -0
  77. package/src/lib/plugins/markdown/MdxPage.tsx +128 -0
  78. package/src/lib/plugins/markdown/Toc.tsx +122 -0
  79. package/src/lib/plugins/markdown/generateRoutes.tsx +72 -0
  80. package/src/lib/plugins/markdown/index.tsx +31 -0
  81. package/src/lib/plugins/openapi/ColorizedParam.tsx +82 -0
  82. package/src/lib/plugins/openapi/MakeRequest.tsx +49 -0
  83. package/src/lib/plugins/openapi/MethodBadge.tsx +36 -0
  84. package/src/lib/plugins/openapi/OperationList.tsx +117 -0
  85. package/src/lib/plugins/openapi/OperationListItem.tsx +55 -0
  86. package/src/lib/plugins/openapi/ParameterList.tsx +32 -0
  87. package/src/lib/plugins/openapi/ParameterListItem.tsx +60 -0
  88. package/src/lib/plugins/openapi/RequestBodySidecarBox.tsx +51 -0
  89. package/src/lib/plugins/openapi/ResponsesSidecarBox.tsx +60 -0
  90. package/src/lib/plugins/openapi/Select.tsx +35 -0
  91. package/src/lib/plugins/openapi/Sidecar.tsx +160 -0
  92. package/src/lib/plugins/openapi/SidecarBox.tsx +36 -0
  93. package/src/lib/plugins/openapi/graphql/fragment-masking.ts +111 -0
  94. package/src/lib/plugins/openapi/graphql/gql.ts +70 -0
  95. package/src/lib/plugins/openapi/graphql/graphql.ts +795 -0
  96. package/src/lib/plugins/openapi/graphql/index.ts +2 -0
  97. package/src/lib/plugins/openapi/index.tsx +142 -0
  98. package/src/lib/plugins/openapi/playground/Playground.tsx +309 -0
  99. package/src/lib/plugins/openapi/queries.graphql +6 -0
  100. package/src/lib/plugins/openapi/util/generateSchemaExample.ts +59 -0
  101. package/src/lib/plugins/openapi/util/urql.ts +8 -0
  102. package/src/lib/plugins/openapi/worker/createSharedWorkerClient.ts +60 -0
  103. package/src/lib/plugins/openapi/worker/shared-worker.ts +5 -0
  104. package/src/lib/plugins/openapi/worker/worker.ts +30 -0
  105. package/src/lib/plugins/redirect/index.tsx +20 -0
  106. package/src/lib/plugins.ts +5 -0
  107. package/src/lib/ui/Button.tsx +56 -0
  108. package/src/lib/ui/Callout.tsx +87 -0
  109. package/src/lib/ui/Card.tsx +82 -0
  110. package/src/lib/ui/Note.tsx +58 -0
  111. package/src/lib/ui/Tabs.tsx +52 -0
  112. package/src/lib/util/MdxComponents.tsx +70 -0
  113. package/src/lib/util/cn.ts +6 -0
  114. package/src/lib/util/createVariantComponent.tsx +30 -0
  115. package/src/lib/util/createWaitForNotify.ts +18 -0
  116. package/src/lib/util/groupBy.ts +24 -0
  117. package/src/lib/util/joinPath.tsx +10 -0
  118. package/src/lib/util/pastellize.ts +25 -0
  119. package/src/lib/util/slugify.ts +3 -0
  120. package/src/lib/util/traverseNavigation.ts +55 -0
  121. package/src/lib/util/useScrollToAnchor.ts +38 -0
  122. package/src/lib/util/useScrollToTop.ts +13 -0
  123. package/src/ts.ts +94 -0
  124. package/src/types.d.ts +24 -0
  125. package/src/vite/build.ts +33 -0
  126. package/src/vite/config.test.ts +10 -0
  127. package/src/vite/config.ts +183 -0
  128. package/src/vite/dev-server.ts +64 -0
  129. package/src/vite/html.ts +37 -0
  130. package/src/vite/plugin-api.ts +57 -0
  131. package/src/vite/plugin-auth.ts +32 -0
  132. package/src/vite/plugin-component.ts +26 -0
  133. package/src/vite/plugin-config.ts +31 -0
  134. package/src/vite/plugin-docs.test.ts +32 -0
  135. package/src/vite/plugin-docs.ts +52 -0
  136. package/src/vite/plugin-html.ts +50 -0
  137. package/src/vite/plugin-mdx.ts +74 -0
  138. package/src/vite/plugin-metadata.ts +30 -0
  139. package/src/vite/plugin.ts +23 -0
@@ -0,0 +1,27 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { useLocation } from "react-router-dom";
3
+ import type { NavigationNode } from "../../util/traverseNavigation.js";
4
+ import { checkHasActiveItem } from "./util.js";
5
+
6
+ export const useNavigationCollapsibleState = ({
7
+ item,
8
+ defaultOpen,
9
+ path,
10
+ }: {
11
+ item: NavigationNode;
12
+ defaultOpen: () => boolean;
13
+ path: string;
14
+ }) => {
15
+ const [isOpen, setIsOpen] = useState(defaultOpen);
16
+ const location = useLocation();
17
+ const previousLocationPath = useRef(location.pathname);
18
+
19
+ useEffect(() => {
20
+ if (!isOpen && previousLocationPath.current !== location.pathname) {
21
+ setIsOpen(checkHasActiveItem(item, location.pathname, path));
22
+ }
23
+ previousLocationPath.current = location.pathname;
24
+ }, [isOpen, item, path, location.pathname]);
25
+
26
+ return [isOpen, setIsOpen] as const;
27
+ };
@@ -0,0 +1,38 @@
1
+ import { matchPath } from "react-router-dom";
2
+ import type {
3
+ HrefNavigationCategoryItem,
4
+ PathNavigationCategoryItem,
5
+ } from "../../core/DevPortalContext.js";
6
+ import {
7
+ traverseNavigationNode,
8
+ type NavigationNode,
9
+ } from "../../util/traverseNavigation.js";
10
+
11
+ export const isPathItem = (
12
+ item: NavigationNode,
13
+ ): item is PathNavigationCategoryItem => "path" in item;
14
+
15
+ export const isLinkItem = (
16
+ item: NavigationNode,
17
+ ): item is HrefNavigationCategoryItem => "href" in item;
18
+
19
+ /**
20
+ * Recursively checks if the current item or any of its children are active.
21
+ */
22
+ export const checkHasActiveItem = (
23
+ item: NavigationNode,
24
+ locationPath: string,
25
+ basePath: string,
26
+ ) => {
27
+ return Boolean(
28
+ traverseNavigationNode(
29
+ item,
30
+ (node, fullPath) => {
31
+ if (isPathItem(node) && matchPath(fullPath, locationPath)) {
32
+ return true;
33
+ }
34
+ },
35
+ basePath,
36
+ ),
37
+ );
38
+ };
@@ -0,0 +1,3 @@
1
+ export { DynamicIcon } from "./components/DynamicIcon.js";
2
+ export { Link } from "./core/router.js";
3
+ export { DevPortal } from "./DevPortal.js";
@@ -0,0 +1,164 @@
1
+ import { QueryClient } from "@tanstack/react-query";
2
+ import { type ReactNode } from "react";
3
+ import { create } from "zustand";
4
+ import { type DevPortalPath, type DevPortalProps } from "../DevPortal.js";
5
+ import { type AuthProvider } from "../authentication/authentication.js";
6
+ import {
7
+ isApiKeyPlugin,
8
+ isNavigationPlugin,
9
+ needsInitialization,
10
+ type DevPortalPlugin,
11
+ type NavigationPlugin,
12
+ } from "./plugins.js";
13
+
14
+ import type { LucideIcon } from "lucide-react";
15
+ import type { IconName } from "../components/DynamicIcon.js";
16
+
17
+ export interface ApiIdentity {
18
+ authorizeRequest: (request: Request) => Request;
19
+ name: string;
20
+ id: string;
21
+ }
22
+
23
+ type BaseNavigationCategoryItem = {
24
+ label: ReactNode;
25
+ title?: string;
26
+ icon?: ReactNode | IconName;
27
+ };
28
+
29
+ export type PathNavigationCategoryItem = BaseNavigationCategoryItem & {
30
+ path: string;
31
+ children?: NavigationCategoryItem[];
32
+ };
33
+
34
+ export type HrefNavigationCategoryItem = BaseNavigationCategoryItem & {
35
+ href: string;
36
+ };
37
+
38
+ export type NavigationCategoryItem =
39
+ | PathNavigationCategoryItem
40
+ | HrefNavigationCategoryItem;
41
+
42
+ export type NavigationCategory = {
43
+ label: string;
44
+ path?: string;
45
+ expanded?: boolean;
46
+ collapsible?: boolean;
47
+ icon?: LucideIcon;
48
+ children: NavigationCategoryItem[];
49
+ };
50
+
51
+ export type NavigationItem = {
52
+ label: string;
53
+ path: DevPortalPath;
54
+ categories?: NavigationCategory[];
55
+ };
56
+
57
+ export type SessionProfileState = {
58
+ isLoggedIn: boolean;
59
+ sub?: string;
60
+ email?: string;
61
+ name?: string;
62
+ email_verified?: string;
63
+ picture?: string;
64
+ };
65
+
66
+ export type RoutingState = {
67
+ path?: string;
68
+ };
69
+
70
+ export const queryClient = new QueryClient();
71
+
72
+ export const useDevPortalState = create<SessionProfileState & RoutingState>(
73
+ () => ({
74
+ isLoggedIn: false,
75
+ }),
76
+ );
77
+
78
+ export type ApiKeyCache = "api-keys";
79
+ export type DevPortalCacheKey = ApiKeyCache | string;
80
+
81
+ export class DevPortalContext {
82
+ private plugins: DevPortalPlugin[] = [];
83
+ private navigationPlugins: NavigationPlugin[];
84
+
85
+ public navigation: NavigationItem[];
86
+ public meta: DevPortalProps["meta"];
87
+ public authentication?: AuthProvider;
88
+ public state: typeof useDevPortalState;
89
+
90
+ constructor(private config: DevPortalProps) {
91
+ this.plugins = config.plugins ?? [];
92
+ this.navigation = config.navigation;
93
+ this.navigationPlugins = this.plugins.filter(isNavigationPlugin);
94
+ this.authentication = config.authentication;
95
+ this.meta = config.meta;
96
+ this.state = useDevPortalState;
97
+ }
98
+
99
+ initialize = async () => {
100
+ this.plugins
101
+ .filter(needsInitialization)
102
+ .forEach((plugin) => plugin.initialize(this));
103
+ this.authentication?.initialize(this);
104
+ };
105
+
106
+ setUserProfile = async (profile: Partial<SessionProfileState>) => {
107
+ return useDevPortalState.setState(profile);
108
+ };
109
+
110
+ invalidateCache = async (key: DevPortalCacheKey[]) => {
111
+ queryClient.invalidateQueries({ queryKey: key });
112
+ };
113
+
114
+ getApiIdentities = async () => {
115
+ const keys = await Promise.all(
116
+ this.plugins
117
+ .filter(isApiKeyPlugin)
118
+ .map((plugin) => plugin.getIdentities(this)),
119
+ );
120
+
121
+ return keys.flat();
122
+ };
123
+
124
+ login = async () => {
125
+ if (!this.authentication) {
126
+ throw new Error("No authentication configured");
127
+ }
128
+
129
+ return this.authentication.login(this);
130
+ };
131
+
132
+ logout = async () => {
133
+ if (!this.authentication) {
134
+ throw new Error("No authentication configured");
135
+ }
136
+
137
+ return this.authentication.signOut(this);
138
+ };
139
+
140
+ handleAuthenticationResponse = async (path: {
141
+ pathname: string;
142
+ search: string;
143
+ hash: string;
144
+ }) => {
145
+ this.config.authentication?.handleAuthenticationResponse?.(path, this);
146
+ };
147
+
148
+ getNavigation = async (path: string) => {
149
+ const navigations = await Promise.all(
150
+ this.navigationPlugins.map(async (plugin) =>
151
+ plugin.getNavigation?.(path),
152
+ ),
153
+ );
154
+
155
+ return navigations.flatMap((nav) => nav ?? []);
156
+ };
157
+
158
+ sessionStorage = {
159
+ get: async (key: string) => localStorage.getItem(`session-${key}`) ?? "",
160
+ setProfile: async () => {},
161
+ set: async (key: string, value: string) =>
162
+ localStorage.setItem(`session-${key}`, value),
163
+ };
164
+ }
@@ -0,0 +1,5 @@
1
+ import * as helmet from "react-helmet-async";
2
+
3
+ export const Helmet = helmet.Helmet;
4
+ export const HelmetData = helmet.HelmetData;
5
+ export const HelmetProvider = helmet.HelmetProvider;
@@ -0,0 +1 @@
1
+ export * from "lucide-react";
@@ -0,0 +1,43 @@
1
+ import { type RouteObject } from "react-router-dom";
2
+ import {
3
+ DevPortalContext,
4
+ type ApiIdentity,
5
+ type NavigationCategory,
6
+ } from "./DevPortalContext.js";
7
+ import { type Combine } from "./types/combine.js";
8
+
9
+ export type PluginNavigationCategory = {
10
+ path: string;
11
+ } & NavigationCategory;
12
+
13
+ export type DevPortalPlugin = Combine<
14
+ [NavigationPlugin, ApiIdentityPlugin, InitializationPlugin]
15
+ >;
16
+
17
+ export interface NavigationPlugin {
18
+ getRoutes: () => RouteObject[];
19
+ getNavigation?: (path: string) => Promise<PluginNavigationCategory[]>;
20
+ }
21
+
22
+ export interface ApiIdentityPlugin {
23
+ getIdentities: (context: DevPortalContext) => Promise<ApiIdentity[]>;
24
+ }
25
+
26
+ export interface InitializationPlugin {
27
+ initialize: (context: DevPortalContext) => Promise<void> | void;
28
+ }
29
+
30
+ export const isNavigationPlugin = (
31
+ obj: DevPortalPlugin,
32
+ ): obj is NavigationPlugin =>
33
+ "getRoutes" in obj && typeof obj.getRoutes === "function";
34
+
35
+ export const needsInitialization = (
36
+ obj: DevPortalPlugin,
37
+ ): obj is InitializationPlugin =>
38
+ "initialize" in obj && typeof obj.initialize === "function";
39
+
40
+ export const isApiKeyPlugin = (
41
+ obj: DevPortalPlugin,
42
+ ): obj is ApiIdentityPlugin =>
43
+ "getIdentities" in obj && typeof obj.getIdentities === "function";
@@ -0,0 +1 @@
1
+ export * from "react-router-dom";
@@ -0,0 +1,16 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
3
+ k: infer I,
4
+ ) => void
5
+ ? I
6
+ : never;
7
+
8
+ type AnyCombination<T, U = T> = T extends any
9
+ ? U extends any
10
+ ? T | (T & U)
11
+ : never
12
+ : never;
13
+
14
+ export type Combine<T extends any[]> =
15
+ | UnionToIntersection<T[number]>
16
+ | AnyCombination<T[number]>;