zudoku 0.3.0-dev.5 → 0.3.0-dev.7
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/dist/app/App.js +2 -1
- package/dist/app/App.js.map +1 -1
- package/dist/lib/authentication/hook.d.ts +1 -0
- package/dist/lib/authentication/hook.js +1 -0
- package/dist/lib/authentication/hook.js.map +1 -1
- package/dist/lib/authentication/providers/auth0.js +1 -0
- package/dist/lib/authentication/providers/auth0.js.map +1 -1
- package/dist/lib/authentication/providers/clerk.js +2 -0
- package/dist/lib/authentication/providers/clerk.js.map +1 -1
- package/dist/lib/authentication/providers/openid.js +2 -0
- package/dist/lib/authentication/providers/openid.js.map +1 -1
- package/dist/lib/authentication/state.d.ts +1 -0
- package/dist/lib/authentication/state.js +1 -0
- package/dist/lib/authentication/state.js.map +1 -1
- package/dist/lib/components/DevPortal.js +0 -1
- package/dist/lib/components/DevPortal.js.map +1 -1
- package/dist/lib/components/SyntaxHighlight.js +5 -1
- package/dist/lib/components/SyntaxHighlight.js.map +1 -1
- package/dist/lib/core/DevPortalContext.js +5 -4
- package/dist/lib/core/DevPortalContext.js.map +1 -1
- package/dist/lib/plugins/api-key/CreateApiKey.d.ts +2 -3
- package/dist/lib/plugins/api-key/CreateApiKey.js +1 -1
- package/dist/lib/plugins/api-key/CreateApiKey.js.map +1 -1
- package/dist/lib/plugins/api-key/SettingsApiKeys.d.ts +2 -3
- package/dist/lib/plugins/api-key/SettingsApiKeys.js +4 -3
- package/dist/lib/plugins/api-key/SettingsApiKeys.js.map +1 -1
- package/dist/lib/plugins/api-key/index.js +20 -5
- package/dist/lib/plugins/api-key/index.js.map +1 -1
- package/dist/lib/plugins/openapi/playground/Headers.d.ts +2 -3
- package/dist/lib/plugins/openapi/playground/Headers.js +16 -6
- package/dist/lib/plugins/openapi/playground/Headers.js.map +1 -1
- package/dist/lib/plugins/openapi/playground/Playground.d.ts +1 -0
- package/dist/lib/plugins/openapi/playground/Playground.js +3 -3
- package/dist/lib/plugins/openapi/playground/Playground.js.map +1 -1
- package/dist/vite/config.test.js +1 -1
- package/dist/vite/config.test.js.map +1 -1
- package/dist/vite/plugin-docs.test.js +1 -1
- package/dist/vite/plugin-docs.test.js.map +1 -1
- package/lib/{Spinner-DWHrSHMP.js → Spinner-BewqqUU-.js} +7 -5
- package/lib/{index-DNx3xWa2.js → index-PyGcnQFX.js} +13 -12
- package/lib/loglevel-CoH7VSwE.js +152 -0
- package/lib/prism-csharp.min-Yizuc34Y.js +34 -0
- package/lib/prism-objectivec.min-BXSWqpJJ.js +1 -0
- package/lib/{state-DfftBQ9X.js → state-2Hu1renZ.js} +6 -5
- package/lib/zudoku.auth-auth0.js +2 -1
- package/lib/zudoku.auth-clerk.js +9 -7
- package/lib/zudoku.auth-openid.js +442 -587
- package/lib/zudoku.components.js +7 -6
- package/lib/zudoku.plugins.js +3075 -3046
- package/package.json +2 -1
- package/src/app/App.tsx +2 -1
- package/src/lib/authentication/hook.ts +1 -0
- package/src/lib/authentication/providers/auth0.tsx +1 -0
- package/src/lib/authentication/providers/clerk.tsx +2 -0
- package/src/lib/authentication/providers/openid.tsx +2 -0
- package/src/lib/authentication/state.ts +2 -0
- package/src/lib/components/DevPortal.tsx +0 -1
- package/src/lib/components/SyntaxHighlight.tsx +5 -1
- package/src/lib/core/DevPortalContext.ts +5 -4
- package/src/lib/plugins/api-key/CreateApiKey.tsx +2 -8
- package/src/lib/plugins/api-key/SettingsApiKeys.tsx +66 -56
- package/src/lib/plugins/api-key/index.tsx +30 -5
- package/src/lib/plugins/openapi/playground/Headers.tsx +60 -33
- package/src/lib/plugins/openapi/playground/Playground.tsx +3 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zudoku",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
"slugify": "1.6.6",
|
|
101
101
|
"strip-ansi": "7.1.0",
|
|
102
102
|
"tailwindcss": "3.4.4",
|
|
103
|
+
"tiny-invariant": "1.3.3",
|
|
103
104
|
"ulidx": "^2.3.0",
|
|
104
105
|
"unist-util-visit": "5.0.0",
|
|
105
106
|
"urql": "4.1.0",
|
package/src/app/App.tsx
CHANGED
|
@@ -32,8 +32,9 @@ export default function App() {
|
|
|
32
32
|
plugins={[
|
|
33
33
|
...configuredDocsPlugins,
|
|
34
34
|
...configuredApiPlugins,
|
|
35
|
-
configuredApiKeysPlugin,
|
|
36
35
|
configuredRedirectPlugin,
|
|
36
|
+
...(configuredApiKeysPlugin ? [configuredApiKeysPlugin] : []),
|
|
37
|
+
...(configuredAuthProvider ? [configuredAuthProvider] : []),
|
|
37
38
|
]}
|
|
38
39
|
/>
|
|
39
40
|
);
|
|
@@ -34,6 +34,7 @@ const clerkAuth: AuthenticationProviderInitializer<
|
|
|
34
34
|
if (clerkApi.session) {
|
|
35
35
|
useAuthState.setState({
|
|
36
36
|
isAuthenticated: true,
|
|
37
|
+
isPending: false,
|
|
37
38
|
profile: {
|
|
38
39
|
sub: clerkApi.session.user.id,
|
|
39
40
|
name: clerkApi.session.user.fullName ?? undefined,
|
|
@@ -46,6 +47,7 @@ const clerkAuth: AuthenticationProviderInitializer<
|
|
|
46
47
|
} else {
|
|
47
48
|
useAuthState.setState({
|
|
48
49
|
isAuthenticated: false,
|
|
50
|
+
isPending: false,
|
|
49
51
|
profile: undefined,
|
|
50
52
|
});
|
|
51
53
|
}
|
|
@@ -180,6 +180,7 @@ export class OpenIDAuthenticationProvider implements AuthenticationProvider {
|
|
|
180
180
|
async logout(): Promise<void> {
|
|
181
181
|
useAuthState.setState({
|
|
182
182
|
isAuthenticated: false,
|
|
183
|
+
isPending: false,
|
|
183
184
|
profile: undefined,
|
|
184
185
|
});
|
|
185
186
|
|
|
@@ -293,6 +294,7 @@ export class OpenIDAuthenticationProvider implements AuthenticationProvider {
|
|
|
293
294
|
|
|
294
295
|
useAuthState.setState({
|
|
295
296
|
isAuthenticated: true,
|
|
297
|
+
isPending: false,
|
|
296
298
|
profile,
|
|
297
299
|
});
|
|
298
300
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { create } from "zustand";
|
|
2
2
|
|
|
3
3
|
export const useAuthState = create<AuthState>(() => ({
|
|
4
|
+
isPending: true,
|
|
4
5
|
isAuthenticated: false,
|
|
5
6
|
}));
|
|
6
7
|
|
|
7
8
|
export interface AuthState {
|
|
8
9
|
isAuthenticated: boolean;
|
|
10
|
+
isPending: boolean;
|
|
9
11
|
profile?: UserProfile;
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -21,6 +21,10 @@ if (!import.meta.env.SSR) {
|
|
|
21
21
|
import("prismjs/components/prism-json.min.js");
|
|
22
22
|
// @ts-expect-error This is untyped
|
|
23
23
|
import("prismjs/components/prism-java.min.js");
|
|
24
|
+
// @ts-expect-error This is untyped
|
|
25
|
+
import("prismjs/components/prism-csharp.min.js");
|
|
26
|
+
// @ts-expect-error This is untyped
|
|
27
|
+
import("prismjs/components/prism-objectivec.min.js");
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
import { useState } from "react";
|
|
@@ -67,7 +71,7 @@ export const SyntaxHighlight = ({
|
|
|
67
71
|
disabled={isCopied}
|
|
68
72
|
onClick={() => {
|
|
69
73
|
setIsCopied(true);
|
|
70
|
-
navigator.clipboard.writeText(
|
|
74
|
+
void navigator.clipboard.writeText(
|
|
71
75
|
tokens
|
|
72
76
|
.map((line) => line.map(({ content }) => content).join(""))
|
|
73
77
|
.join("\n"),
|
|
@@ -85,10 +85,11 @@ export class DevPortalContext {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
initialize = async () => {
|
|
88
|
-
|
|
89
|
-
.
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
await Promise.all([
|
|
89
|
+
this.plugins
|
|
90
|
+
.filter(needsInitialization)
|
|
91
|
+
.map((plugin) => plugin.initialize(this)),
|
|
92
|
+
]);
|
|
92
93
|
};
|
|
93
94
|
|
|
94
95
|
invalidateCache = async (key: DevPortalCacheKey[]) => {
|
|
@@ -12,17 +12,11 @@ import {
|
|
|
12
12
|
SelectValue,
|
|
13
13
|
} from "../../components/Select.js";
|
|
14
14
|
import { Button } from "../../ui/Button.js";
|
|
15
|
-
import {
|
|
15
|
+
import { ApiKeyService } from "./index.js";
|
|
16
16
|
|
|
17
17
|
type CreateApiKey = { description: string; expiresOn?: string };
|
|
18
18
|
|
|
19
|
-
export const CreateApiKey = ({
|
|
20
|
-
options,
|
|
21
|
-
service,
|
|
22
|
-
}: {
|
|
23
|
-
options: ApiKeyPluginOptions;
|
|
24
|
-
service: ApiKeyService;
|
|
25
|
-
}) => {
|
|
19
|
+
export const CreateApiKey = ({ service }: { service: ApiKeyService }) => {
|
|
26
20
|
const context = useDevPortal();
|
|
27
21
|
const navigate = useNavigate();
|
|
28
22
|
const form = useForm<CreateApiKey>({
|
|
@@ -8,20 +8,15 @@ import { useState } from "react";
|
|
|
8
8
|
import { Link } from "react-router-dom";
|
|
9
9
|
import { useDevPortal } from "../../components/context/DevPortalProvider.js";
|
|
10
10
|
import { Button } from "../../ui/Button.js";
|
|
11
|
-
import {
|
|
11
|
+
import { ApiKeyService } from "./index.js";
|
|
12
12
|
|
|
13
|
-
export const SettingsApiKeys = ({
|
|
14
|
-
options,
|
|
15
|
-
service,
|
|
16
|
-
}: {
|
|
17
|
-
options: ApiKeyPluginOptions;
|
|
18
|
-
service: ApiKeyService;
|
|
19
|
-
}) => {
|
|
13
|
+
export const SettingsApiKeys = ({ service }: { service: ApiKeyService }) => {
|
|
20
14
|
const context = useDevPortal();
|
|
21
15
|
const queryClient = useQueryClient();
|
|
22
16
|
const { data } = useSuspenseQuery({
|
|
23
17
|
queryFn: () => service.getKeys(context),
|
|
24
18
|
queryKey: ["api-keys"],
|
|
19
|
+
retry: false,
|
|
25
20
|
});
|
|
26
21
|
|
|
27
22
|
const deleteKeyMutation = useMutation({
|
|
@@ -38,7 +33,7 @@ export const SettingsApiKeys = ({
|
|
|
38
33
|
});
|
|
39
34
|
|
|
40
35
|
return (
|
|
41
|
-
<div className="max-w-screen-lg pt-[--padding-content-top] pb-[--padding-content-bottom]">
|
|
36
|
+
<div className="max-w-screen-lg h-full pt-[--padding-content-top] pb-[--padding-content-bottom]">
|
|
42
37
|
<div className="flex justify-between mb-4 border-b border-border pb-3">
|
|
43
38
|
<h1 className="font-medium text-2xl">API Keys</h1>
|
|
44
39
|
{service.createKey && (
|
|
@@ -48,56 +43,71 @@ export const SettingsApiKeys = ({
|
|
|
48
43
|
)}
|
|
49
44
|
</div>
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
46
|
+
{data.length === 0 ? (
|
|
47
|
+
<div className="flex flex-col justify-center gap-4 items-center h-1/2 my-8">
|
|
48
|
+
<div className="text-center">
|
|
49
|
+
No API keys created yet.
|
|
50
|
+
<br />
|
|
51
|
+
Get started and create the first one now
|
|
52
|
+
</div>
|
|
53
|
+
{service.createKey && (
|
|
54
|
+
<Button asChild>
|
|
55
|
+
<Link to="/settings/api-keys/new">Create API Key</Link>
|
|
56
|
+
</Button>
|
|
57
|
+
)}
|
|
58
|
+
</div>
|
|
59
|
+
) : (
|
|
60
|
+
<ul className="grid grid-cols-[minmax(250px,min-content)_1fr_min-content] ">
|
|
61
|
+
{data.map((key: any) => (
|
|
62
|
+
<li
|
|
63
|
+
className="border-b border-border p-5 grid grid-cols-subgrid col-span-full gap-2 items-center"
|
|
64
|
+
key={key.id}
|
|
65
|
+
>
|
|
66
|
+
<div className="flex flex-col gap-1 text-sm">
|
|
67
|
+
{key.description ?? key.id}
|
|
68
|
+
<div className="text-muted-foreground text-xs">
|
|
69
|
+
{key.createdOn && (
|
|
70
|
+
<div>
|
|
71
|
+
Created on {new Date(key.createdOn).toLocaleDateString()}
|
|
72
|
+
</div>
|
|
73
|
+
)}
|
|
74
|
+
{key.expiresOn && (
|
|
75
|
+
<div>
|
|
76
|
+
Expires on {new Date(key.expiresOn).toLocaleDateString()}
|
|
77
|
+
</div>
|
|
78
|
+
)}
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
<div className="items-center flex justify-center">
|
|
82
|
+
<RevealApiKey apiKey={key.key} />
|
|
83
|
+
</div>
|
|
84
|
+
<div className="flex gap-2">
|
|
85
|
+
{service.rollKey && (
|
|
86
|
+
<Button size="icon">
|
|
87
|
+
<RotateCwIcon size={16} />
|
|
88
|
+
</Button>
|
|
64
89
|
)}
|
|
65
|
-
{
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
90
|
+
{service.deleteKey && (
|
|
91
|
+
<Button
|
|
92
|
+
variant="ghost"
|
|
93
|
+
size="icon"
|
|
94
|
+
onClick={() => {
|
|
95
|
+
if (!confirm("Do you want to delete this key?")) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
deleteKeyMutation.mutate(key.id);
|
|
100
|
+
}}
|
|
101
|
+
disabled={deleteKeyMutation.isPending}
|
|
102
|
+
>
|
|
103
|
+
<TrashIcon size={16} />
|
|
104
|
+
</Button>
|
|
69
105
|
)}
|
|
70
106
|
</div>
|
|
71
|
-
</
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
<div className="flex gap-2">
|
|
76
|
-
{service.rollKey && (
|
|
77
|
-
<Button size="icon">
|
|
78
|
-
<RotateCwIcon size={16} />
|
|
79
|
-
</Button>
|
|
80
|
-
)}
|
|
81
|
-
{service.deleteKey && (
|
|
82
|
-
<Button
|
|
83
|
-
variant="ghost"
|
|
84
|
-
size="icon"
|
|
85
|
-
onClick={() => {
|
|
86
|
-
if (!confirm("Do you want to delete this key?")) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
deleteKeyMutation.mutate(key.id);
|
|
91
|
-
}}
|
|
92
|
-
disabled={deleteKeyMutation.isPending}
|
|
93
|
-
>
|
|
94
|
-
<TrashIcon size={16} />
|
|
95
|
-
</Button>
|
|
96
|
-
)}
|
|
97
|
-
</div>
|
|
98
|
-
</li>
|
|
99
|
-
))}
|
|
100
|
-
</ul>
|
|
107
|
+
</li>
|
|
108
|
+
))}
|
|
109
|
+
</ul>
|
|
110
|
+
)}
|
|
101
111
|
</div>
|
|
102
112
|
);
|
|
103
113
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import logger from "loglevel";
|
|
2
|
+
import { Outlet, useRouteError } from "react-router-dom";
|
|
3
|
+
import invariant from "tiny-invariant";
|
|
2
4
|
import { useAuth } from "../../authentication/hook.js";
|
|
3
5
|
import { DevPortalContext } from "../../core/DevPortalContext.js";
|
|
4
6
|
import {
|
|
@@ -50,7 +52,8 @@ const createDefaultHandler = (endpoint: string): ApiKeyService => {
|
|
|
50
52
|
|
|
51
53
|
await context.signRequest(request);
|
|
52
54
|
|
|
53
|
-
await fetch(request);
|
|
55
|
+
const response = await fetch(request);
|
|
56
|
+
invariant(response.ok, "Failed to delete API key");
|
|
54
57
|
},
|
|
55
58
|
createKey: async (apiKey, context) => {
|
|
56
59
|
const request = new Request(endpoint + `/v1/developer/api-keys`, {
|
|
@@ -62,7 +65,9 @@ const createDefaultHandler = (endpoint: string): ApiKeyService => {
|
|
|
62
65
|
});
|
|
63
66
|
|
|
64
67
|
await context.signRequest(request);
|
|
65
|
-
|
|
68
|
+
|
|
69
|
+
const response = await fetch(request);
|
|
70
|
+
invariant(response.ok, "Failed to create API key");
|
|
66
71
|
},
|
|
67
72
|
getKeys: async (context) => {
|
|
68
73
|
const request = new Request(endpoint + `/v1/developer/api-keys`);
|
|
@@ -70,6 +75,7 @@ const createDefaultHandler = (endpoint: string): ApiKeyService => {
|
|
|
70
75
|
await context.signRequest(request);
|
|
71
76
|
|
|
72
77
|
const keys = await fetch(request);
|
|
78
|
+
invariant(keys.ok, "Failed to fetch API keys");
|
|
73
79
|
|
|
74
80
|
return await keys.json();
|
|
75
81
|
},
|
|
@@ -78,6 +84,12 @@ const createDefaultHandler = (endpoint: string): ApiKeyService => {
|
|
|
78
84
|
|
|
79
85
|
const ProtectedRoute = () => {
|
|
80
86
|
const auth = useAuth();
|
|
87
|
+
|
|
88
|
+
// TODO: should we suspend here somehow?
|
|
89
|
+
if (auth.isPending) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
81
93
|
return auth.isAuthenticated ? (
|
|
82
94
|
<Outlet />
|
|
83
95
|
) : (
|
|
@@ -88,6 +100,18 @@ const ProtectedRoute = () => {
|
|
|
88
100
|
);
|
|
89
101
|
};
|
|
90
102
|
|
|
103
|
+
const SettingsErrorBoundary = () => {
|
|
104
|
+
const error = useRouteError();
|
|
105
|
+
logger.error(String(error));
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div className="flex flex-col justify-center gap-2 items-center h-1/2 my-12">
|
|
109
|
+
<h1>Something went wrong</h1>
|
|
110
|
+
{error instanceof Error && <p>{error.message}</p>}
|
|
111
|
+
</div>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
91
115
|
export const apiKeyPlugin = (
|
|
92
116
|
options: ApiKeyPluginOptions,
|
|
93
117
|
): DevPortalPlugin & ApiIdentityPlugin => {
|
|
@@ -118,14 +142,15 @@ export const apiKeyPlugin = (
|
|
|
118
142
|
return [
|
|
119
143
|
{
|
|
120
144
|
element: <ProtectedRoute />,
|
|
145
|
+
errorElement: <SettingsErrorBoundary />,
|
|
121
146
|
children: [
|
|
122
147
|
{
|
|
123
148
|
path: "/settings/api-keys",
|
|
124
|
-
element: <SettingsApiKeys
|
|
149
|
+
element: <SettingsApiKeys service={service} />,
|
|
125
150
|
},
|
|
126
151
|
{
|
|
127
152
|
path: "/settings/api-keys/new",
|
|
128
|
-
element: <CreateApiKey
|
|
153
|
+
element: <CreateApiKey service={service} />,
|
|
129
154
|
},
|
|
130
155
|
],
|
|
131
156
|
},
|
|
@@ -1,53 +1,80 @@
|
|
|
1
|
-
import { XIcon } from "lucide-react";
|
|
2
|
-
import {
|
|
1
|
+
import { TriangleAlertIcon, XIcon } from "lucide-react";
|
|
2
|
+
import {
|
|
3
|
+
Control,
|
|
4
|
+
useFieldArray,
|
|
5
|
+
UseFormRegister,
|
|
6
|
+
useWatch,
|
|
7
|
+
} from "react-hook-form";
|
|
3
8
|
import { Button } from "../../../ui/Button.js";
|
|
9
|
+
import { cn } from "../../../util/cn.js";
|
|
4
10
|
import { InlineInput } from "./InlineInput.js";
|
|
5
|
-
import
|
|
11
|
+
import { NO_IDENTITY, type PlaygroundForm } from "./Playground.js";
|
|
6
12
|
|
|
7
13
|
export const Headers = ({
|
|
8
14
|
control,
|
|
9
15
|
register,
|
|
10
|
-
headers,
|
|
11
16
|
}: {
|
|
12
17
|
register: UseFormRegister<PlaygroundForm>;
|
|
13
18
|
control: Control<PlaygroundForm>;
|
|
14
|
-
headers: Header[];
|
|
15
19
|
}) => {
|
|
16
20
|
const { fields, append, remove } = useFieldArray<PlaygroundForm>({
|
|
17
21
|
control,
|
|
18
22
|
name: "headers",
|
|
19
23
|
});
|
|
24
|
+
const selectedIdentity = useWatch({ name: "identity", control });
|
|
25
|
+
const liveHeaders = useWatch({ name: "headers", control });
|
|
26
|
+
|
|
27
|
+
const disableAuth = selectedIdentity !== NO_IDENTITY;
|
|
28
|
+
|
|
20
29
|
return (
|
|
21
30
|
<div className="grid grid-cols-[1fr_1fr_auto]">
|
|
22
|
-
{fields.map((header, i) =>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<
|
|
28
|
-
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/>
|
|
39
|
-
<button
|
|
40
|
-
className="hover:bg-black/5 p-1 rounded mr-2 text-muted-foreground invisible group-hover:visible peer-focus:visible"
|
|
41
|
-
onClick={() => {
|
|
42
|
-
remove(i);
|
|
43
|
-
}}
|
|
44
|
-
type="button"
|
|
31
|
+
{fields.map((header, i) => {
|
|
32
|
+
const isDisabledByAuth =
|
|
33
|
+
disableAuth && liveHeaders.at(i)?.name === "Authorization";
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div
|
|
37
|
+
key={header.id}
|
|
38
|
+
className={cn(
|
|
39
|
+
"grid-cols-subgrid col-span-full grid items-center gap-x-2 has-[:focus]:bg-muted hover:bg-muted rounded overflow-hidden group",
|
|
40
|
+
isDisabledByAuth && "line-through",
|
|
41
|
+
)}
|
|
42
|
+
title={
|
|
43
|
+
isDisabledByAuth
|
|
44
|
+
? "This header is disabled because authentication was selected"
|
|
45
|
+
: undefined
|
|
46
|
+
}
|
|
45
47
|
>
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
<div className="flex gap-2 items-center">
|
|
49
|
+
<InlineInput
|
|
50
|
+
{...register(`headers.${i}.name`)}
|
|
51
|
+
placeholder="Name"
|
|
52
|
+
className="peer"
|
|
53
|
+
autoComplete="off"
|
|
54
|
+
/>
|
|
55
|
+
{isDisabledByAuth && (
|
|
56
|
+
<TriangleAlertIcon size={16} className="text-amber-500" />
|
|
57
|
+
)}
|
|
58
|
+
</div>
|
|
59
|
+
<InlineInput
|
|
60
|
+
placeholder={"Value"}
|
|
61
|
+
className="peer"
|
|
62
|
+
{...register(`headers.${i}.value`)}
|
|
63
|
+
autoComplete="off"
|
|
64
|
+
/>
|
|
65
|
+
<button
|
|
66
|
+
className="hover:bg-black/5 p-1 rounded mr-2 text-muted-foreground invisible group-hover:visible peer-focus:visible"
|
|
67
|
+
onClick={() => {
|
|
68
|
+
remove(i);
|
|
69
|
+
}}
|
|
70
|
+
type="button"
|
|
71
|
+
>
|
|
72
|
+
<XIcon size={16} />
|
|
73
|
+
</button>
|
|
74
|
+
<div className="col-span-full border-b border-border"></div>
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
})}
|
|
51
78
|
<Button
|
|
52
79
|
className="col-span-full mt-4"
|
|
53
80
|
onClick={() => append({ name: "", value: "" })}
|
|
@@ -81,7 +81,7 @@ export type PlaygroundForm = {
|
|
|
81
81
|
identity?: string;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
const NO_IDENTITY = "__none";
|
|
84
|
+
export const NO_IDENTITY = "__none";
|
|
85
85
|
|
|
86
86
|
const Playground = ({
|
|
87
87
|
url,
|
|
@@ -121,7 +121,7 @@ const Playground = ({
|
|
|
121
121
|
const request = new Request(requestUrl, {
|
|
122
122
|
method: method.toUpperCase(),
|
|
123
123
|
headers: Object.fromEntries(
|
|
124
|
-
data.
|
|
124
|
+
data.headers
|
|
125
125
|
.filter((h) => h.name)
|
|
126
126
|
.map((header) => [header.name, header.value]),
|
|
127
127
|
),
|
|
@@ -132,7 +132,6 @@ const Playground = ({
|
|
|
132
132
|
.find((i) => i.id === data.identity)
|
|
133
133
|
?.authorizeRequest(request);
|
|
134
134
|
}
|
|
135
|
-
|
|
136
135
|
const response = await fetch(request);
|
|
137
136
|
|
|
138
137
|
const body = await response.text();
|
|
@@ -263,11 +262,7 @@ const Playground = ({
|
|
|
263
262
|
</div>
|
|
264
263
|
</div>
|
|
265
264
|
<TabsContent value="headers">
|
|
266
|
-
<Headers
|
|
267
|
-
control={control}
|
|
268
|
-
register={register}
|
|
269
|
-
headers={formState.headers}
|
|
270
|
-
/>
|
|
265
|
+
<Headers control={control} register={register} />
|
|
271
266
|
</TabsContent>
|
|
272
267
|
<TabsContent value="parameters">
|
|
273
268
|
<div className="grid grid-cols-[min-content_1fr_1fr_auto]">
|