@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,572 @@
1
+ import {
2
+ type ConsentDocumentRow,
3
+ } from "@nexys/user-management-client";
4
+ import { AlertCircle, Trash2, Users } from "lucide-react";
5
+ import { useState, type FormEvent } from "react";
6
+
7
+ import { useUmClient } from "../../context/auth-context.js";
8
+ import { useCall } from "../../hooks/use-call.js";
9
+ import { errorMessage } from "../../lib/error-message.js";
10
+ import { Alert, AlertDescription } from "../ui/alert.js";
11
+ import { Badge } from "../ui/badge.js";
12
+ import { Button } from "../ui/button.js";
13
+ import {
14
+ Card,
15
+ CardContent,
16
+ CardDescription,
17
+ CardHeader,
18
+ CardTitle,
19
+ } from "../ui/card.js";
20
+ import {
21
+ Dialog,
22
+ DialogContent,
23
+ DialogDescription,
24
+ DialogFooter,
25
+ DialogHeader,
26
+ DialogTitle,
27
+ DialogTrigger,
28
+ } from "../ui/dialog.js";
29
+ import { Field } from "../ui/field.js";
30
+ import { Input } from "../ui/input.js";
31
+ import { Label } from "../ui/label.js";
32
+ import {
33
+ Select,
34
+ SelectContent,
35
+ SelectItem,
36
+ SelectTrigger,
37
+ SelectValue,
38
+ } from "../ui/select.js";
39
+ import { Skeleton } from "../ui/skeleton.js";
40
+ import { Switch } from "../ui/switch.js";
41
+ import {
42
+ Table,
43
+ TableBody,
44
+ TableCell,
45
+ TableEmpty,
46
+ TableHead,
47
+ TableHeader,
48
+ TableRow,
49
+ } from "../ui/table.js";
50
+ import { Textarea } from "../ui/textarea.js";
51
+
52
+ export interface ProjectConsentsProps {
53
+ projectId: string;
54
+ canManage?: boolean;
55
+ }
56
+
57
+ /** Newest version first within each key; keys alphabetical. */
58
+ const groupByKey = (docs: ConsentDocumentRow[]) => {
59
+ const byKey = new Map<string, ConsentDocumentRow[]>();
60
+ for (const d of docs) {
61
+ const list = byKey.get(d.key) ?? [];
62
+ list.push(d);
63
+ byKey.set(d.key, list);
64
+ }
65
+ return [...byKey.entries()]
66
+ .map(([key, versions]) => ({
67
+ key,
68
+ versions: [...versions].sort((a, b) => b.version - a.version),
69
+ }))
70
+ .sort((a, b) => a.key.localeCompare(b.key));
71
+ };
72
+
73
+ export const ProjectConsents = ({
74
+ projectId,
75
+ canManage = false,
76
+ }: ProjectConsentsProps) => {
77
+ const { data, loading, error, refresh } = useCall("listConsentDocuments", {
78
+ projectId,
79
+ });
80
+ const groups = groupByKey(data?.documents ?? []);
81
+
82
+ if (error) {
83
+ return (
84
+ <Alert variant="destructive">
85
+ <AlertCircle />
86
+ <AlertDescription>{errorMessage(error)}</AlertDescription>
87
+ </Alert>
88
+ );
89
+ }
90
+
91
+ return (
92
+ <div className="grid gap-6">
93
+ <Card>
94
+ <CardHeader>
95
+ <CardTitle>Agreements</CardTitle>
96
+ <CardDescription>
97
+ Terms, privacy notices and opt-ins users accept. Publishing new
98
+ wording adds a version — the old text is kept so past acceptances
99
+ still say what was agreed to.
100
+ </CardDescription>
101
+ </CardHeader>
102
+ <CardContent className="grid gap-4">
103
+ {loading ? (
104
+ <Skeleton className="h-24 w-full" />
105
+ ) : groups.length === 0 ? (
106
+ <p className="text-muted-foreground text-sm">
107
+ No agreements yet. Publish one to start collecting consent.
108
+ </p>
109
+ ) : (
110
+ groups.map((g) => (
111
+ <DocumentGroup
112
+ key={g.key}
113
+ projectId={projectId}
114
+ docKey={g.key}
115
+ versions={g.versions}
116
+ canManage={canManage}
117
+ onChanged={refresh}
118
+ />
119
+ ))
120
+ )}
121
+ {canManage ? (
122
+ <PublishDialog
123
+ projectId={projectId}
124
+ existingKeys={groups.map((g) => g.key)}
125
+ onPublished={refresh}
126
+ />
127
+ ) : null}
128
+ </CardContent>
129
+ </Card>
130
+ </div>
131
+ );
132
+ };
133
+
134
+ const DocumentGroup = ({
135
+ projectId,
136
+ docKey,
137
+ versions,
138
+ canManage,
139
+ onChanged,
140
+ }: {
141
+ projectId: string;
142
+ docKey: string;
143
+ versions: ConsentDocumentRow[];
144
+ canManage: boolean;
145
+ onChanged: () => void;
146
+ }) => {
147
+ const client = useUmClient();
148
+ const [busy, setBusy] = useState<string | null>(null);
149
+ // Groups are only built from non-empty version lists.
150
+ const current = versions[0];
151
+ if (!current) return null;
152
+
153
+ const togglePublished = async (d: ConsentDocumentRow) => {
154
+ setBusy(d.id);
155
+ await client.updateConsentDocument({
156
+ projectId,
157
+ documentId: d.id,
158
+ published: !d.published,
159
+ });
160
+ setBusy(null);
161
+ onChanged();
162
+ };
163
+
164
+ const remove = async (d: ConsentDocumentRow) => {
165
+ setBusy(d.id);
166
+ await client.deleteConsentDocument({ projectId, documentId: d.id });
167
+ setBusy(null);
168
+ onChanged();
169
+ };
170
+
171
+ return (
172
+ <div className="rounded-lg border bg-card">
173
+ <div className="flex flex-wrap items-center justify-between gap-2 border-b p-3">
174
+ <div className="grid gap-0.5">
175
+ <div className="flex items-center gap-2">
176
+ <span className="text-sm font-medium">{current.title}</span>
177
+ <Badge
178
+ variant={
179
+ current.enforcement === "blocking" ? "default" : "muted"
180
+ }
181
+ >
182
+ {current.enforcement === "blocking"
183
+ ? "blocks sign-in"
184
+ : "report only"}
185
+ </Badge>
186
+ </div>
187
+ <code className="text-muted-foreground font-mono text-xs">
188
+ {docKey} · {versions.length} version
189
+ {versions.length === 1 ? "" : "s"}
190
+ </code>
191
+ </div>
192
+ </div>
193
+ <Table>
194
+ <TableHeader>
195
+ <TableRow>
196
+ <TableHead>Version</TableHead>
197
+ <TableHead>Status</TableHead>
198
+ <TableHead>Re-accept</TableHead>
199
+ <TableHead className="text-right">Acceptances</TableHead>
200
+ {canManage ? <TableHead /> : null}
201
+ </TableRow>
202
+ </TableHeader>
203
+ <TableBody>
204
+ {versions.map((d) => (
205
+ <TableRow key={d.id}>
206
+ <TableCell className="font-mono text-xs">v{d.version}</TableCell>
207
+ <TableCell>
208
+ {canManage ? (
209
+ <div className="flex items-center gap-2">
210
+ <Switch
211
+ checked={d.published}
212
+ onCheckedChange={() => void togglePublished(d)}
213
+ disabled={busy === d.id}
214
+ aria-label="Published"
215
+ />
216
+ <span className="text-muted-foreground text-xs">
217
+ {d.published ? "published" : "draft"}
218
+ </span>
219
+ </div>
220
+ ) : (
221
+ <Badge variant={d.published ? "default" : "muted"}>
222
+ {d.published ? "published" : "draft"}
223
+ </Badge>
224
+ )}
225
+ </TableCell>
226
+ <TableCell className="text-muted-foreground text-xs">
227
+ {d.requiresReacceptance ? "required" : "not required"}
228
+ </TableCell>
229
+ <TableCell className="text-right">
230
+ <AcceptancesDialog projectId={projectId} document={d} />
231
+ </TableCell>
232
+ {canManage ? (
233
+ <TableCell className="text-right">
234
+ <Button
235
+ variant="ghost"
236
+ size="icon"
237
+ className="size-8"
238
+ onClick={() => void remove(d)}
239
+ disabled={busy === d.id}
240
+ aria-label="Delete version"
241
+ >
242
+ <Trash2 className="size-4" />
243
+ </Button>
244
+ </TableCell>
245
+ ) : null}
246
+ </TableRow>
247
+ ))}
248
+ </TableBody>
249
+ </Table>
250
+ </div>
251
+ );
252
+ };
253
+
254
+ /// Who accepted one version — the compliance view.
255
+ const AcceptancesDialog = ({
256
+ projectId,
257
+ document,
258
+ }: {
259
+ projectId: string;
260
+ document: ConsentDocumentRow;
261
+ }) => {
262
+ const [open, setOpen] = useState(false);
263
+
264
+ return (
265
+ <Dialog open={open} onOpenChange={setOpen}>
266
+ <DialogTrigger asChild>
267
+ <Button variant="ghost" size="sm">
268
+ <Users className="size-3.5" /> View
269
+ </Button>
270
+ </DialogTrigger>
271
+ <DialogContent className="max-w-2xl">
272
+ <DialogHeader>
273
+ <DialogTitle>
274
+ {document.title} — v{document.version}
275
+ </DialogTitle>
276
+ <DialogDescription>
277
+ Everyone who accepted this exact version.
278
+ </DialogDescription>
279
+ </DialogHeader>
280
+ {open ? (
281
+ <AcceptancesTable projectId={projectId} documentId={document.id} />
282
+ ) : null}
283
+ </DialogContent>
284
+ </Dialog>
285
+ );
286
+ };
287
+
288
+ const AcceptancesTable = ({
289
+ projectId,
290
+ documentId,
291
+ }: {
292
+ projectId: string;
293
+ documentId: string;
294
+ }) => {
295
+ const { data, loading, error } = useCall("listConsentAcceptances", {
296
+ projectId,
297
+ documentId,
298
+ });
299
+
300
+ if (error) {
301
+ return (
302
+ <Alert variant="destructive">
303
+ <AlertCircle />
304
+ <AlertDescription>{errorMessage(error)}</AlertDescription>
305
+ </Alert>
306
+ );
307
+ }
308
+ if (loading) {
309
+ return <Skeleton className="h-24 w-full" />;
310
+ }
311
+
312
+ const rows = data?.acceptances ?? [];
313
+ return (
314
+ <div className="max-h-96 overflow-y-auto">
315
+ <Table>
316
+ <TableHeader>
317
+ <TableRow>
318
+ <TableHead>User</TableHead>
319
+ <TableHead>Accepted</TableHead>
320
+ <TableHead>IP</TableHead>
321
+ </TableRow>
322
+ </TableHeader>
323
+ <TableBody>
324
+ {rows.length === 0 ? (
325
+ <TableEmpty>Nobody has accepted this version yet.</TableEmpty>
326
+ ) : (
327
+ rows.map((a) => (
328
+ <TableRow key={a.userId}>
329
+ <TableCell>
330
+ <div className="grid gap-0.5">
331
+ <span className="text-sm">{a.userName}</span>
332
+ <span className="text-muted-foreground text-xs">
333
+ {a.userEmail}
334
+ </span>
335
+ </div>
336
+ </TableCell>
337
+ <TableCell className="text-xs">
338
+ {new Date(a.acceptedAt).toLocaleString()}
339
+ </TableCell>
340
+ <TableCell className="font-mono text-xs">
341
+ {a.ipAddress ?? "—"}
342
+ </TableCell>
343
+ </TableRow>
344
+ ))
345
+ )}
346
+ </TableBody>
347
+ </Table>
348
+ {data ? (
349
+ <p className="text-muted-foreground mt-2 text-xs">
350
+ {rows.length} of {data.total}
351
+ </p>
352
+ ) : null}
353
+ </div>
354
+ );
355
+ };
356
+
357
+ const PublishDialog = ({
358
+ projectId,
359
+ existingKeys,
360
+ onPublished,
361
+ }: {
362
+ projectId: string;
363
+ existingKeys: string[];
364
+ onPublished: () => void;
365
+ }) => {
366
+ const client = useUmClient();
367
+ const [open, setOpen] = useState(false);
368
+ const [key, setKey] = useState("");
369
+ const [title, setTitle] = useState("");
370
+ const [body, setBody] = useState("");
371
+ const [url, setUrl] = useState("");
372
+ const [enforcement, setEnforcement] = useState<"blocking" | "report_only">(
373
+ "blocking"
374
+ );
375
+ const [requiresReacceptance, setRequiresReacceptance] = useState(true);
376
+ const [published, setPublished] = useState(true);
377
+ const [loading, setLoading] = useState(false);
378
+ const [error, setError] = useState<string | null>(null);
379
+
380
+ const isNewVersion = existingKeys.includes(key.trim().toLowerCase());
381
+
382
+ const reset = () => {
383
+ setKey("");
384
+ setTitle("");
385
+ setBody("");
386
+ setUrl("");
387
+ setEnforcement("blocking");
388
+ setRequiresReacceptance(true);
389
+ setPublished(true);
390
+ setError(null);
391
+ setLoading(false);
392
+ };
393
+
394
+ const submit = async (e: FormEvent) => {
395
+ e.preventDefault();
396
+ setLoading(true);
397
+ setError(null);
398
+ const res = await client.publishConsentDocument({
399
+ projectId,
400
+ key: key.trim().toLowerCase(),
401
+ title: title.trim(),
402
+ body,
403
+ url: url.trim() || null,
404
+ enforcement,
405
+ requiresReacceptance,
406
+ published,
407
+ });
408
+ setLoading(false);
409
+ if (res.ok) {
410
+ onPublished();
411
+ reset();
412
+ setOpen(false);
413
+ } else {
414
+ setError(errorMessage(res.error, "Couldn't publish this agreement."));
415
+ }
416
+ };
417
+
418
+ return (
419
+ <Dialog
420
+ open={open}
421
+ onOpenChange={(o) => {
422
+ setOpen(o);
423
+ if (!o) reset();
424
+ }}
425
+ >
426
+ <DialogTrigger asChild>
427
+ <Button variant="outline" size="sm">
428
+ Publish agreement
429
+ </Button>
430
+ </DialogTrigger>
431
+ <DialogContent className="max-w-xl">
432
+ <DialogHeader>
433
+ <DialogTitle>Publish an agreement</DialogTitle>
434
+ <DialogDescription>
435
+ Reusing an existing key publishes the next version of it. Text is
436
+ never edited in place, so past acceptances stay meaningful.
437
+ </DialogDescription>
438
+ </DialogHeader>
439
+ <form onSubmit={submit} className="grid gap-4" noValidate>
440
+ <div className="grid gap-4 sm:grid-cols-2">
441
+ <Field
442
+ label="Key"
443
+ htmlFor="consent-key"
444
+ description="Stable id across versions, e.g. terms."
445
+ required
446
+ >
447
+ <Input
448
+ id="consent-key"
449
+ value={key}
450
+ onChange={(e) => setKey(e.target.value)}
451
+ placeholder="terms"
452
+ className="font-mono"
453
+ list="consent-key-options"
454
+ />
455
+ <datalist id="consent-key-options">
456
+ {existingKeys.map((k) => (
457
+ <option key={k} value={k} />
458
+ ))}
459
+ </datalist>
460
+ </Field>
461
+ <Field label="Title" htmlFor="consent-title" required>
462
+ <Input
463
+ id="consent-title"
464
+ value={title}
465
+ onChange={(e) => setTitle(e.target.value)}
466
+ placeholder="Terms of Service"
467
+ />
468
+ </Field>
469
+ </div>
470
+ {isNewVersion ? (
471
+ <p className="text-muted-foreground text-xs">
472
+ <strong className="font-mono">{key.trim().toLowerCase()}</strong>{" "}
473
+ already exists — this publishes its next version.
474
+ </p>
475
+ ) : null}
476
+ <Field label="Body" htmlFor="consent-body" required>
477
+ <Textarea
478
+ id="consent-body"
479
+ value={body}
480
+ onChange={(e) => setBody(e.target.value)}
481
+ rows={8}
482
+ className="text-xs"
483
+ />
484
+ </Field>
485
+ <Field
486
+ label="Link"
487
+ htmlFor="consent-url"
488
+ description="Optional link to the canonical hosted document."
489
+ >
490
+ <Input
491
+ id="consent-url"
492
+ value={url}
493
+ onChange={(e) => setUrl(e.target.value)}
494
+ placeholder="https://example.com/terms"
495
+ className="font-mono"
496
+ />
497
+ </Field>
498
+ <Field
499
+ label="Enforcement"
500
+ htmlFor="consent-enforcement"
501
+ description="Blocking withholds sign-in until the user accepts."
502
+ >
503
+ <Select
504
+ value={enforcement}
505
+ onValueChange={(v) =>
506
+ setEnforcement(v as "blocking" | "report_only")
507
+ }
508
+ >
509
+ <SelectTrigger id="consent-enforcement">
510
+ <SelectValue />
511
+ </SelectTrigger>
512
+ <SelectContent>
513
+ <SelectItem value="blocking">Blocks sign-in</SelectItem>
514
+ <SelectItem value="report_only">Report only</SelectItem>
515
+ </SelectContent>
516
+ </Select>
517
+ </Field>
518
+ <div className="flex items-center justify-between gap-4">
519
+ <div className="grid gap-0.5">
520
+ <Label htmlFor="consent-reaccept">Requires re-acceptance</Label>
521
+ <p className="text-muted-foreground text-xs">
522
+ On for a material change — everyone who accepted an earlier
523
+ version is asked again. Off for a typo fix.
524
+ </p>
525
+ </div>
526
+ <Switch
527
+ id="consent-reaccept"
528
+ checked={requiresReacceptance}
529
+ onCheckedChange={setRequiresReacceptance}
530
+ />
531
+ </div>
532
+ <div className="flex items-center justify-between gap-4">
533
+ <div className="grid gap-0.5">
534
+ <Label htmlFor="consent-published">Publish now</Label>
535
+ <p className="text-muted-foreground text-xs">
536
+ Off saves it as a draft: never shown, never enforced.
537
+ </p>
538
+ </div>
539
+ <Switch
540
+ id="consent-published"
541
+ checked={published}
542
+ onCheckedChange={setPublished}
543
+ />
544
+ </div>
545
+ {error ? (
546
+ <Alert variant="destructive">
547
+ <AlertCircle />
548
+ <AlertDescription>{error}</AlertDescription>
549
+ </Alert>
550
+ ) : null}
551
+ <DialogFooter>
552
+ <Button
553
+ type="button"
554
+ variant="ghost"
555
+ onClick={() => setOpen(false)}
556
+ disabled={loading}
557
+ >
558
+ Cancel
559
+ </Button>
560
+ <Button
561
+ type="submit"
562
+ loading={loading}
563
+ disabled={!key.trim() || !title.trim() || !body.trim()}
564
+ >
565
+ Publish
566
+ </Button>
567
+ </DialogFooter>
568
+ </form>
569
+ </DialogContent>
570
+ </Dialog>
571
+ );
572
+ };