zudoku 0.3.0-dev.6 → 0.3.0-dev.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zudoku",
3
- "version": "0.3.0-dev.6",
3
+ "version": "0.3.0-dev.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -1,4 +1,4 @@
1
- import { MoonStarIcon, SearchIcon, SunIcon } from "lucide-react";
1
+ import { MoonStarIcon, SunIcon } from "lucide-react";
2
2
  import { memo } from "react";
3
3
 
4
4
  import { useAuth } from "../authentication/hook.js";
@@ -27,7 +27,7 @@ export const Header = memo(function HeaderInner() {
27
27
  </div>
28
28
  <div className="grid grid-cols-[--sidecar-grid-cols] items-center gap-8">
29
29
  <div className="w-full max-w-prose">
30
- <button className="flex items-center border border-input hover:bg-accent hover:text-accent-foreground p-4 relative h-8 justify-start rounded-lg bg-background text-sm text-muted-foreground shadow-none w-40 sm:w-72">
30
+ {/*<button className="flex items-center border border-input hover:bg-accent hover:text-accent-foreground p-4 relative h-8 justify-start rounded-lg bg-background text-sm text-muted-foreground shadow-none w-40 sm:w-72">
31
31
  <div className="flex items-center gap-2 flex-grow">
32
32
  <SearchIcon size={14} />
33
33
  Search
@@ -35,7 +35,7 @@ export const Header = memo(function HeaderInner() {
35
35
  <kbd className="absolute right-[0.3rem] top-[0.3rem] hidden h-5 select-none items-center gap-1 rounded border border-border bg-muted px-1.5 font-mono text-[11px] font-medium opacity-100 sm:flex">
36
36
  ⌘K
37
37
  </kbd>
38
- </button>
38
+ </button>*/}
39
39
  </div>
40
40
 
41
41
  <div className="items-center justify-self-end text-sm hidden lg:flex">
@@ -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";
@@ -33,7 +33,7 @@ export const SettingsApiKeys = ({ service }: { service: ApiKeyService }) => {
33
33
  });
34
34
 
35
35
  return (
36
- <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]">
37
37
  <div className="flex justify-between mb-4 border-b border-border pb-3">
38
38
  <h1 className="font-medium text-2xl">API Keys</h1>
39
39
  {service.createKey && (
@@ -43,56 +43,71 @@ export const SettingsApiKeys = ({ service }: { service: ApiKeyService }) => {
43
43
  )}
44
44
  </div>
45
45
 
46
- <ul className="grid grid-cols-[min-content_1fr_min-content] ">
47
- {data.map((key) => (
48
- <li
49
- className="border-b border-border p-5 grid grid-cols-subgrid col-span-full gap-2 items-center"
50
- key={key.id}
51
- >
52
- <div className="flex flex-col gap-1 text-sm">
53
- {key.description ?? key.id}
54
- <div className="text-muted-foreground text-xs">
55
- {key.createdOn && (
56
- <div>
57
- Created on {new Date(key.createdOn).toLocaleDateString()}
58
- </div>
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>
59
89
  )}
60
- {key.expiresOn && (
61
- <div>
62
- Expires on {new Date(key.expiresOn).toLocaleDateString()}
63
- </div>
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>
64
105
  )}
65
106
  </div>
66
- </div>
67
- <div className="items-center flex justify-center">
68
- <RevealApiKey apiKey={key.key} />
69
- </div>
70
- <div className="flex gap-2">
71
- {service.rollKey && (
72
- <Button size="icon">
73
- <RotateCwIcon size={16} />
74
- </Button>
75
- )}
76
- {service.deleteKey && (
77
- <Button
78
- variant="ghost"
79
- size="icon"
80
- onClick={() => {
81
- if (!confirm("Do you want to delete this key?")) {
82
- return;
83
- }
84
-
85
- deleteKeyMutation.mutate(key.id);
86
- }}
87
- disabled={deleteKeyMutation.isPending}
88
- >
89
- <TrashIcon size={16} />
90
- </Button>
91
- )}
92
- </div>
93
- </li>
94
- ))}
95
- </ul>
107
+ </li>
108
+ ))}
109
+ </ul>
110
+ )}
96
111
  </div>
97
112
  );
98
113
  };
@@ -1,53 +1,80 @@
1
- import { XIcon } from "lucide-react";
2
- import { Control, useFieldArray, UseFormRegister } from "react-hook-form";
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 type { Header, PlaygroundForm } from "./Playground.js";
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
- <div
24
- key={header.id}
25
- className="grid-cols-subgrid col-span-full grid items-center gap-x-2 has-[:focus]:bg-muted hover:bg-muted rounded overflow-hidden group"
26
- >
27
- <InlineInput
28
- {...register(`headers.${i}.name`)}
29
- placeholder="Name"
30
- className="peer"
31
- autoComplete="off"
32
- />
33
- <InlineInput
34
- placeholder={"Value"}
35
- className="peer"
36
- {...register(`headers.${i}.value`)}
37
- autoComplete="off"
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
- <XIcon size={16} />
47
- </button>
48
- <div className="col-span-full border-b border-border"></div>
49
- </div>
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.pathParams
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]">