@nexys/user-management-web 0.0.26

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 (77) hide show
  1. package/README.md +61 -0
  2. package/components.json +21 -0
  3. package/package.json +66 -0
  4. package/src/components/audit/audit-log-table.test.tsx +91 -0
  5. package/src/components/audit/audit-log-table.tsx +226 -0
  6. package/src/components/auth/accept-invitation-card.tsx +100 -0
  7. package/src/components/auth/forgot-password-form.tsx +92 -0
  8. package/src/components/auth/reset-password-form.tsx +143 -0
  9. package/src/components/auth/sign-in-form.test.tsx +140 -0
  10. package/src/components/auth/sign-in-form.tsx +509 -0
  11. package/src/components/auth/sign-up-form.tsx +123 -0
  12. package/src/components/layout/app-shell.tsx +189 -0
  13. package/src/components/layout/auth-shell.tsx +28 -0
  14. package/src/components/layout/theme-toggle.tsx +55 -0
  15. package/src/components/layout/user-menu.tsx +84 -0
  16. package/src/components/primitives/empty-state.tsx +40 -0
  17. package/src/components/primitives/page-header.tsx +27 -0
  18. package/src/components/primitives/spinner.tsx +28 -0
  19. package/src/components/profile/api-tokens-card.tsx +235 -0
  20. package/src/components/profile/change-password-form.tsx +158 -0
  21. package/src/components/profile/passkeys-card.tsx +180 -0
  22. package/src/components/profile/profile-card.tsx +33 -0
  23. package/src/components/profile/two-factor-card.tsx +226 -0
  24. package/src/components/projects/project-consents.tsx +572 -0
  25. package/src/components/projects/project-create-dialog.tsx +209 -0
  26. package/src/components/projects/project-detail-tabs.tsx +63 -0
  27. package/src/components/projects/project-email-templates.tsx +282 -0
  28. package/src/components/projects/project-notices.tsx +458 -0
  29. package/src/components/projects/project-settings.tsx +1133 -0
  30. package/src/components/projects/project-tenants.tsx +107 -0
  31. package/src/components/projects/projects-table.test.tsx +95 -0
  32. package/src/components/projects/projects-table.tsx +240 -0
  33. package/src/components/roles/role-badge.tsx +91 -0
  34. package/src/components/roles/role-select.tsx +76 -0
  35. package/src/components/tenants/tenant-create-dialog.tsx +163 -0
  36. package/src/components/tenants/tenant-detail-tabs.tsx +51 -0
  37. package/src/components/tenants/tenant-members.tsx +578 -0
  38. package/src/components/tenants/tenant-roles.test.tsx +91 -0
  39. package/src/components/tenants/tenant-roles.tsx +414 -0
  40. package/src/components/tenants/tenant-settings.tsx +385 -0
  41. package/src/components/tenants/tenants-table.test.tsx +71 -0
  42. package/src/components/tenants/tenants-table.tsx +245 -0
  43. package/src/components/ui/alert.tsx +52 -0
  44. package/src/components/ui/avatar.tsx +46 -0
  45. package/src/components/ui/badge.tsx +32 -0
  46. package/src/components/ui/button.tsx +64 -0
  47. package/src/components/ui/card.tsx +65 -0
  48. package/src/components/ui/dialog.tsx +99 -0
  49. package/src/components/ui/dropdown-menu.tsx +97 -0
  50. package/src/components/ui/field.tsx +44 -0
  51. package/src/components/ui/input.tsx +23 -0
  52. package/src/components/ui/label.tsx +19 -0
  53. package/src/components/ui/select.tsx +87 -0
  54. package/src/components/ui/separator.tsx +22 -0
  55. package/src/components/ui/skeleton.tsx +13 -0
  56. package/src/components/ui/switch.tsx +29 -0
  57. package/src/components/ui/table.tsx +87 -0
  58. package/src/components/ui/tabs.tsx +51 -0
  59. package/src/components/ui/textarea.tsx +22 -0
  60. package/src/components/ui/tooltip.tsx +27 -0
  61. package/src/components/users/user-create-dialog.tsx +267 -0
  62. package/src/components/users/user-delete-dialog.tsx +88 -0
  63. package/src/components/users/user-detail.tsx +843 -0
  64. package/src/components/users/users-table.test.tsx +97 -0
  65. package/src/components/users/users-table.tsx +382 -0
  66. package/src/context/auth-context.tsx +124 -0
  67. package/src/context/theme-context.test.tsx +78 -0
  68. package/src/context/theme-context.tsx +110 -0
  69. package/src/hooks/use-call.ts +64 -0
  70. package/src/index.ts +159 -0
  71. package/src/lib/error-message.ts +16 -0
  72. package/src/lib/utils.test.ts +61 -0
  73. package/src/lib/utils.ts +79 -0
  74. package/src/lib/webauthn.ts +36 -0
  75. package/src/styles.css +107 -0
  76. package/src/test-setup.ts +5 -0
  77. package/tailwind.preset.cjs +15 -0
@@ -0,0 +1,143 @@
1
+ import { AlertCircle, KeyRound, ShieldCheck } from "lucide-react";
2
+ import { useState, type FormEvent, type ReactNode } from "react";
3
+
4
+ import { useUmClient } from "../../context/auth-context.js";
5
+ import { errorMessage } from "../../lib/error-message.js";
6
+ import { Alert, AlertDescription } from "../ui/alert.js";
7
+ import { Button } from "../ui/button.js";
8
+ import {
9
+ Card,
10
+ CardContent,
11
+ CardDescription,
12
+ CardHeader,
13
+ CardTitle,
14
+ } from "../ui/card.js";
15
+ import { Field } from "../ui/field.js";
16
+ import { Input } from "../ui/input.js";
17
+
18
+ export interface ResetPasswordFormProps {
19
+ /** The token from the reset email's `?token=` query param. */
20
+ token: string;
21
+ /** Rendered after a successful reset (e.g. a sign-in link). */
22
+ successSlot?: ReactNode;
23
+ minLength?: number;
24
+ }
25
+
26
+ /** Sets a new password from an emailed reset link. */
27
+ export const ResetPasswordForm = ({
28
+ token,
29
+ successSlot,
30
+ minLength = 8,
31
+ }: ResetPasswordFormProps) => {
32
+ const client = useUmClient();
33
+ const [next, setNext] = useState("");
34
+ const [confirm, setConfirm] = useState("");
35
+ const [loading, setLoading] = useState(false);
36
+ const [error, setError] = useState<string | null>(null);
37
+ const [done, setDone] = useState(false);
38
+
39
+ const mismatched = confirm.length > 0 && confirm !== next;
40
+ const tooShort = next.length > 0 && next.length < minLength;
41
+
42
+ const submit = async (e: FormEvent) => {
43
+ e.preventDefault();
44
+ if (mismatched || tooShort) return;
45
+ setLoading(true);
46
+ setError(null);
47
+ const res = await client.resetPassword({ token, newPassword: next });
48
+ setLoading(false);
49
+ if (res.ok) {
50
+ setDone(true);
51
+ } else {
52
+ setError(
53
+ errorMessage(
54
+ res.error,
55
+ "This reset link is invalid or has expired. Request a new one."
56
+ )
57
+ );
58
+ }
59
+ };
60
+
61
+ if (done) {
62
+ return (
63
+ <Card className="w-full max-w-md">
64
+ <CardHeader className="space-y-1.5">
65
+ <CardTitle className="flex items-center gap-2 text-2xl">
66
+ <ShieldCheck className="size-5 text-green-600" />
67
+ Password updated
68
+ </CardTitle>
69
+ <CardDescription>
70
+ Your password has been changed. You can sign in with it now.
71
+ </CardDescription>
72
+ </CardHeader>
73
+ {successSlot ? <CardContent>{successSlot}</CardContent> : null}
74
+ </Card>
75
+ );
76
+ }
77
+
78
+ return (
79
+ <Card className="w-full max-w-md">
80
+ <CardHeader className="space-y-1.5">
81
+ <CardTitle className="flex items-center gap-2 text-2xl">
82
+ <KeyRound className="size-5 text-muted-foreground" />
83
+ Choose a new password
84
+ </CardTitle>
85
+ <CardDescription>
86
+ Enter a new password for your account.
87
+ </CardDescription>
88
+ </CardHeader>
89
+ <CardContent>
90
+ <form onSubmit={submit} className="grid gap-4" noValidate>
91
+ <Field
92
+ label="New password"
93
+ htmlFor="reset-pw"
94
+ required
95
+ description={`At least ${minLength} characters.`}
96
+ error={tooShort ? "New password is too short." : undefined}
97
+ >
98
+ <Input
99
+ id="reset-pw"
100
+ type="password"
101
+ autoComplete="new-password"
102
+ required
103
+ autoFocus
104
+ value={next}
105
+ onChange={(e) => setNext(e.target.value)}
106
+ aria-invalid={tooShort || undefined}
107
+ />
108
+ </Field>
109
+ <Field
110
+ label="Confirm new password"
111
+ htmlFor="reset-pw-confirm"
112
+ required
113
+ error={mismatched ? "Passwords don't match." : undefined}
114
+ >
115
+ <Input
116
+ id="reset-pw-confirm"
117
+ type="password"
118
+ autoComplete="new-password"
119
+ required
120
+ value={confirm}
121
+ onChange={(e) => setConfirm(e.target.value)}
122
+ aria-invalid={mismatched || undefined}
123
+ />
124
+ </Field>
125
+ {error ? (
126
+ <Alert variant="destructive">
127
+ <AlertCircle />
128
+ <AlertDescription>{error}</AlertDescription>
129
+ </Alert>
130
+ ) : null}
131
+ <Button
132
+ type="submit"
133
+ className="w-full"
134
+ loading={loading}
135
+ disabled={mismatched || tooShort || !next}
136
+ >
137
+ Set new password
138
+ </Button>
139
+ </form>
140
+ </CardContent>
141
+ </Card>
142
+ );
143
+ };
@@ -0,0 +1,140 @@
1
+ /// <reference lib="dom" />
2
+ import { afterEach, describe, expect, mock, test } from "bun:test";
3
+
4
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
5
+
6
+ import { mockRpc, reply, type RpcReply } from "@nexys/user-management-client/testing";
7
+
8
+ import { AuthProvider } from "../../context/auth-context.js";
9
+ import { SignInForm } from "./sign-in-form.js";
10
+
11
+ const makeFetcher = (responder: (procedure: string) => RpcReply) => mockRpc(responder);
12
+
13
+ afterEach(() => {
14
+ document.body.innerHTML = "";
15
+ });
16
+
17
+ describe("<SignInForm /> with Result-based call pattern", () => {
18
+ test("submits the form and calls onSuccess with the returned user", async () => {
19
+ const onSuccess = mock(() => {});
20
+ const rpc = makeFetcher((p) => {
21
+ if (p === "me") {
22
+ return reply({ code: "unauth" }, 401);
23
+ }
24
+ if (p === "signIn") {
25
+ return reply({ user: { id: "u1", email: "a@b.co" } });
26
+ }
27
+ return reply({ error: "not_found" }, 404);
28
+ });
29
+
30
+ const client = rpc.client;
31
+
32
+ render(
33
+ <AuthProvider client={client} refreshIntervalMs={0}>
34
+ <SignInForm onSuccess={onSuccess} />
35
+ </AuthProvider>
36
+ );
37
+
38
+ fireEvent.change(screen.getByLabelText(/email/i), {
39
+ target: { value: "a@b.co" },
40
+ });
41
+ fireEvent.change(screen.getByLabelText(/password/i), {
42
+ target: { value: "hunter2hunter" },
43
+ });
44
+ fireEvent.click(screen.getByRole("button", { name: /sign in/i }));
45
+
46
+ await waitFor(() => expect(onSuccess).toHaveBeenCalled());
47
+ expect(onSuccess).toHaveBeenCalledWith({ id: "u1", email: "a@b.co" });
48
+ });
49
+
50
+ test("surfaces the API error message inline (no thrown ApiError)", async () => {
51
+ const rpc = makeFetcher((p) => {
52
+ if (p === "me") {
53
+ return reply({}, 401);
54
+ }
55
+ return reply({
56
+ code: "INVALID_EMAIL_OR_PASSWORD",
57
+ message: "Invalid email or password.",
58
+ }, 401);
59
+ });
60
+ const client = rpc.client;
61
+
62
+ render(
63
+ <AuthProvider client={client} refreshIntervalMs={0}>
64
+ <SignInForm />
65
+ </AuthProvider>
66
+ );
67
+
68
+ fireEvent.change(screen.getByLabelText(/email/i), {
69
+ target: { value: "wrong@example.com" },
70
+ });
71
+ fireEvent.change(screen.getByLabelText(/password/i), {
72
+ target: { value: "badpass1" },
73
+ });
74
+ fireEvent.click(screen.getByRole("button", { name: /sign in/i }));
75
+
76
+ await waitFor(() =>
77
+ expect(screen.getByText("Invalid email or password.")).toBeDefined()
78
+ );
79
+ });
80
+
81
+ test("magic-link flow: requests a link and shows the check-inbox state", async () => {
82
+ const requests: string[] = [];
83
+ const rpc = makeFetcher((p) => {
84
+ requests.push(p);
85
+ if (p === "me") {
86
+ return reply({ code: "unauth" }, 401);
87
+ }
88
+ if (p === "requestMagicLink") {
89
+ return reply({ status: true });
90
+ }
91
+ return reply({ error: "not_found" }, 404);
92
+ });
93
+ const client = rpc.client;
94
+
95
+ render(
96
+ <AuthProvider client={client} refreshIntervalMs={0}>
97
+ <SignInForm />
98
+ </AuthProvider>
99
+ );
100
+
101
+ fireEvent.click(screen.getByRole("button", { name: /email me a sign-in link/i }));
102
+ fireEvent.change(screen.getByLabelText(/email/i), {
103
+ target: { value: "a@b.co" },
104
+ });
105
+ fireEvent.click(screen.getByRole("button", { name: /send sign-in link/i }));
106
+
107
+ await waitFor(() => expect(screen.getByText(/check your inbox/i)).toBeDefined());
108
+ expect(
109
+ requests.includes("requestMagicLink")
110
+ ).toBe(true);
111
+
112
+ // "Back to sign-in" returns to the password form.
113
+ fireEvent.click(screen.getByRole("button", { name: /back to sign-in/i }));
114
+ await waitFor(() => expect(screen.getByLabelText(/password/i)).toBeDefined());
115
+ });
116
+
117
+ test("surfaces a friendly network-error string when fetch throws", async () => {
118
+ const rpc = makeFetcher((p) => {
119
+ if (p === "me") {
120
+ return reply({}, 401);
121
+ }
122
+ throw new Error("connect ECONNREFUSED");
123
+ });
124
+ const client = rpc.client;
125
+
126
+ render(
127
+ <AuthProvider client={client} refreshIntervalMs={0}>
128
+ <SignInForm />
129
+ </AuthProvider>
130
+ );
131
+
132
+ fireEvent.change(screen.getByLabelText(/email/i), { target: { value: "a@b.co" } });
133
+ fireEvent.change(screen.getByLabelText(/password/i), {
134
+ target: { value: "hunter2hunter" },
135
+ });
136
+ fireEvent.click(screen.getByRole("button", { name: /sign in/i }));
137
+
138
+ await waitFor(() => expect(screen.getByText(/network error/i)).toBeDefined());
139
+ });
140
+ });