@colveor/admin 0.0.0-stage → 0.5.3

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 (156) hide show
  1. package/LICENSE.md +106 -0
  2. package/README.md +365 -2
  3. package/TAILWINDADMIN-LICENSE +21 -0
  4. package/dist/account/data.d.ts +1 -0
  5. package/dist/account/data.js +44 -0
  6. package/dist/account/profile.d.ts +6 -0
  7. package/dist/account/profile.js +118 -0
  8. package/dist/account/sessions.d.ts +1 -0
  9. package/dist/account/sessions.js +26 -0
  10. package/dist/account/shared.d.ts +26 -0
  11. package/dist/account/shared.js +44 -0
  12. package/dist/account/two-factor.d.ts +5 -0
  13. package/dist/account/two-factor.js +60 -0
  14. package/dist/actions.d.ts +39 -0
  15. package/dist/actions.js +81 -0
  16. package/dist/api/audit.gen.d.ts +80 -0
  17. package/dist/api/audit.gen.js +43 -0
  18. package/dist/api/auth.gen.d.ts +537 -0
  19. package/dist/api/auth.gen.js +313 -0
  20. package/dist/api/errors.gen.d.ts +16 -0
  21. package/dist/api/errors.gen.js +2 -0
  22. package/dist/api/gormx.gen.d.ts +60 -0
  23. package/dist/api/gormx.gen.js +16 -0
  24. package/dist/api/health.gen.d.ts +103 -0
  25. package/dist/api/health.gen.js +23 -0
  26. package/dist/api/index.gen.d.ts +21 -0
  27. package/dist/api/index.gen.js +22 -0
  28. package/dist/api/invitations.gen.d.ts +128 -0
  29. package/dist/api/invitations.gen.js +57 -0
  30. package/dist/api/ledger.gen.d.ts +269 -0
  31. package/dist/api/ledger.gen.js +113 -0
  32. package/dist/api/msgtemplate.gen.d.ts +31 -0
  33. package/dist/api/msgtemplate.gen.js +2 -0
  34. package/dist/api/notifications.gen.d.ts +66 -0
  35. package/dist/api/notifications.gen.js +28 -0
  36. package/dist/api/outbox.gen.d.ts +8 -0
  37. package/dist/api/outbox.gen.js +2 -0
  38. package/dist/api/queue.gen.d.ts +112 -0
  39. package/dist/api/queue.gen.js +15 -0
  40. package/dist/api/rbac.gen.d.ts +406 -0
  41. package/dist/api/rbac.gen.js +191 -0
  42. package/dist/api/reauth.gen.d.ts +289 -0
  43. package/dist/api/reauth.gen.js +122 -0
  44. package/dist/api/recorded_payments.gen.d.ts +171 -0
  45. package/dist/api/recorded_payments.gen.js +79 -0
  46. package/dist/api/sessions.gen.d.ts +64 -0
  47. package/dist/api/sessions.gen.js +48 -0
  48. package/dist/api/settings.gen.d.ts +147 -0
  49. package/dist/api/settings.gen.js +69 -0
  50. package/dist/api/storage.gen.d.ts +327 -0
  51. package/dist/api/storage.gen.js +208 -0
  52. package/dist/api/support_access.gen.d.ts +155 -0
  53. package/dist/api/support_access.gen.js +131 -0
  54. package/dist/api/users.gen.d.ts +407 -0
  55. package/dist/api/users.gen.js +159 -0
  56. package/dist/api/verification.gen.d.ts +427 -0
  57. package/dist/api/verification.gen.js +280 -0
  58. package/dist/api/webhooks.gen.d.ts +110 -0
  59. package/dist/api/webhooks.gen.js +45 -0
  60. package/dist/auth-layout.d.ts +9 -0
  61. package/dist/auth-layout.js +5 -0
  62. package/dist/banner.d.ts +1 -0
  63. package/dist/banner.js +49 -0
  64. package/dist/client.d.ts +41 -0
  65. package/dist/client.js +72 -0
  66. package/dist/config.d.ts +27 -0
  67. package/dist/config.js +82 -0
  68. package/dist/dates.d.ts +4 -0
  69. package/dist/dates.js +16 -0
  70. package/dist/header.d.ts +12 -0
  71. package/dist/header.js +105 -0
  72. package/dist/icons.d.ts +2 -0
  73. package/dist/icons.js +15 -0
  74. package/dist/index.d.ts +28 -0
  75. package/dist/index.js +42 -0
  76. package/dist/kit/avatar.d.ts +5 -0
  77. package/dist/kit/avatar.js +16 -0
  78. package/dist/kit/badge.d.ts +10 -0
  79. package/dist/kit/badge.js +31 -0
  80. package/dist/kit/card.d.ts +12 -0
  81. package/dist/kit/card.js +7 -0
  82. package/dist/kit/code-area.d.ts +15 -0
  83. package/dist/kit/code-area.js +69 -0
  84. package/dist/kit/dropdown.d.ts +26 -0
  85. package/dist/kit/dropdown.js +67 -0
  86. package/dist/kit/filter-tabs.d.ts +9 -0
  87. package/dist/kit/filter-tabs.js +7 -0
  88. package/dist/kit/modal.d.ts +8 -0
  89. package/dist/kit/modal.js +15 -0
  90. package/dist/kit/page-header.d.ts +13 -0
  91. package/dist/kit/page-header.js +13 -0
  92. package/dist/kit/search.d.ts +4 -0
  93. package/dist/kit/search.js +16 -0
  94. package/dist/kit/tooltip.d.ts +17 -0
  95. package/dist/kit/tooltip.js +52 -0
  96. package/dist/message-editor.d.ts +9 -0
  97. package/dist/message-editor.js +80 -0
  98. package/dist/money.d.ts +10 -0
  99. package/dist/money.js +17 -0
  100. package/dist/next.d.ts +6 -0
  101. package/dist/next.js +19 -0
  102. package/dist/pages/account.d.ts +1 -0
  103. package/dist/pages/account.js +47 -0
  104. package/dist/pages/audit.d.ts +1 -0
  105. package/dist/pages/audit.js +88 -0
  106. package/dist/pages/forgot-password.d.ts +1 -0
  107. package/dist/pages/forgot-password.js +73 -0
  108. package/dist/pages/ledger.d.ts +1 -0
  109. package/dist/pages/ledger.js +132 -0
  110. package/dist/pages/roles.d.ts +1 -0
  111. package/dist/pages/roles.js +102 -0
  112. package/dist/pages/settings.d.ts +1 -0
  113. package/dist/pages/settings.js +86 -0
  114. package/dist/pages/sign-in.d.ts +5 -0
  115. package/dist/pages/sign-in.js +117 -0
  116. package/dist/pages/status.d.ts +1 -0
  117. package/dist/pages/status.js +122 -0
  118. package/dist/pages/support.d.ts +1 -0
  119. package/dist/pages/support.js +90 -0
  120. package/dist/pages/teams.d.ts +1 -0
  121. package/dist/pages/teams.js +94 -0
  122. package/dist/pages/users.d.ts +1 -0
  123. package/dist/pages/users.js +158 -0
  124. package/dist/pages/webhooks.d.ts +1 -0
  125. package/dist/pages/webhooks.js +88 -0
  126. package/dist/permissions.d.ts +5 -0
  127. package/dist/permissions.js +31 -0
  128. package/dist/proof.d.ts +10 -0
  129. package/dist/proof.js +78 -0
  130. package/dist/proxy.d.ts +10 -0
  131. package/dist/proxy.js +166 -0
  132. package/dist/retry.d.ts +8 -0
  133. package/dist/retry.js +30 -0
  134. package/dist/router.d.ts +13 -0
  135. package/dist/router.js +14 -0
  136. package/dist/setting-fields.d.ts +12 -0
  137. package/dist/setting-fields.js +102 -0
  138. package/dist/setting-list.d.ts +22 -0
  139. package/dist/setting-list.js +78 -0
  140. package/dist/shell.d.ts +40 -0
  141. package/dist/shell.js +97 -0
  142. package/dist/support.d.ts +37 -0
  143. package/dist/support.js +76 -0
  144. package/dist/table.d.ts +40 -0
  145. package/dist/table.js +73 -0
  146. package/dist/ui.d.ts +39 -0
  147. package/dist/ui.js +56 -0
  148. package/dist/user-actions.d.ts +30 -0
  149. package/dist/user-actions.js +129 -0
  150. package/dist/user-roles.d.ts +4 -0
  151. package/dist/user-roles.js +51 -0
  152. package/dist/user-row-menu.d.ts +14 -0
  153. package/dist/user-row-menu.js +45 -0
  154. package/dist/version.d.ts +1 -0
  155. package/dist/version.js +3 -0
  156. package/package.json +63 -4
@@ -0,0 +1,118 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // The account's profile (PATCH /v1/profile) and password
4
+ // (POST /v1/auth/change-password).
5
+ import { useState } from "react";
6
+ import { api } from "../client";
7
+ import { Dialog } from "../ui";
8
+ import { input, Labelled, Messages, primary, Section, secondary, useStep } from "./shared";
9
+ export function ProfileTab({ me, onSaved }) {
10
+ const p = me.details;
11
+ const [editing, setEditing] = useState(null);
12
+ const { step, error, notice, busy } = useStep();
13
+ const name = p?.display_name || [p?.first_name, p?.last_name].filter(Boolean).join(" ") || me.email || "";
14
+ const initials = name
15
+ .split(/\s+/)
16
+ .map((w) => w[0])
17
+ .join("")
18
+ .slice(0, 2)
19
+ .toUpperCase() || "?";
20
+ const place = [p?.address?.city, p?.address?.country].filter(Boolean).join(", ");
21
+ const save = (event) => {
22
+ event.preventDefault();
23
+ const f = new FormData(event.currentTarget);
24
+ const text = (k) => String(f.get(k) ?? "").trim() || undefined;
25
+ const body = editing === "personal"
26
+ ? {
27
+ first_name: text("first_name"),
28
+ last_name: text("last_name"),
29
+ display_name: text("display_name"),
30
+ occupation: text("occupation"),
31
+ website_url: text("website_url"),
32
+ timezone: text("timezone"),
33
+ }
34
+ : {
35
+ address: {
36
+ address_line_1: text("address_line_1"),
37
+ address_line_2: text("address_line_2"),
38
+ city: text("city"),
39
+ state: text("state"),
40
+ postal_code: text("postal_code"),
41
+ country: text("country"),
42
+ },
43
+ };
44
+ step(async () => {
45
+ await api.patch("/v1/profile", body);
46
+ setEditing(null);
47
+ onSaved();
48
+ }, "Your profile is saved.");
49
+ };
50
+ return (_jsxs("div", { className: "space-y-6", children: [_jsx(Messages, { error: error, notice: notice }), _jsxs("section", { className: "flex animate-fade-in flex-col items-center gap-6 rounded-2xl border border-gray-200 bg-white p-6 sm:flex-row dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsx("span", { className: "flex size-20 shrink-0 items-center justify-center rounded-full bg-brand-500 text-2xl font-medium text-white shadow-md ring-4 ring-brand-50 dark:ring-brand-500/20", children: initials }), _jsxs("div", { className: "text-center sm:text-left", children: [_jsx("h2", { className: "text-lg font-medium text-gray-800 dark:text-white/90", children: name }), _jsxs("p", { className: "mt-1 flex flex-wrap items-center justify-center gap-x-3 gap-y-1 text-sm text-gray-500 sm:justify-start dark:text-gray-400", children: [p?.occupation && _jsx("span", { children: p.occupation }), p?.occupation && place && _jsx("span", { className: "h-4 w-px bg-gray-300 dark:bg-gray-700" }), place && _jsx("span", { children: place }), p?.timezone && _jsxs("span", { children: ["\u00B7 ", p.timezone] })] })] })] }), _jsxs("div", { className: "grid gap-6 xl:grid-cols-2", children: [_jsx(InfoCard, { title: "Personal information", onEdit: () => setEditing("personal"), rows: [
51
+ ["First name", p?.first_name],
52
+ ["Last name", p?.last_name],
53
+ ["Display name", p?.display_name],
54
+ ["Role or job", p?.occupation],
55
+ ["Email", me.email],
56
+ ["Phone", me.phone],
57
+ ["Website", p?.website_url],
58
+ ["Time zone", p?.timezone],
59
+ ] }), _jsx(InfoCard, { title: "Address", onEdit: () => setEditing("address"), rows: [
60
+ ["Address", p?.address?.address_line_1],
61
+ ["", p?.address?.address_line_2],
62
+ ["City", p?.address?.city],
63
+ ["State or region", p?.address?.state],
64
+ ["Postal code", p?.address?.postal_code],
65
+ ["Country", p?.address?.country],
66
+ ] })] }), editing !== null && (_jsx(Dialog, { title: editing === "personal" ? "Edit personal information" : "Edit address", children: _jsxs("form", { onSubmit: save, className: "grid gap-4 sm:grid-cols-2", children: [(editing === "personal"
67
+ ? [
68
+ ["first_name", "First name", p?.first_name],
69
+ ["last_name", "Last name", p?.last_name],
70
+ ["display_name", "Display name", p?.display_name],
71
+ ["occupation", "Role or job", p?.occupation],
72
+ ["website_url", "Website", p?.website_url],
73
+ [
74
+ "timezone",
75
+ "Time zone",
76
+ p?.timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone,
77
+ ],
78
+ ]
79
+ : [
80
+ ["address_line_1", "Address", p?.address?.address_line_1],
81
+ ["address_line_2", "Address, line 2", p?.address?.address_line_2],
82
+ ["city", "City", p?.address?.city],
83
+ ["state", "State or region", p?.address?.state],
84
+ ["postal_code", "Postal code", p?.address?.postal_code],
85
+ ["country", "Country", p?.address?.country],
86
+ ]).map(([field, label, value]) => (_jsx(Labelled, { label: label ?? "", htmlFor: `edit-${field}`, children: _jsx("input", { id: `edit-${field}`, name: field, defaultValue: value, type: field === "website_url" ? "url" : "text", className: input }) }, field))), _jsxs("div", { className: "flex justify-end gap-3 sm:col-span-2", children: [_jsx("button", { type: "button", className: secondary, onClick: () => setEditing(null), children: "Cancel" }), _jsx("button", { type: "submit", disabled: busy, className: primary, children: "Save" })] })] }) }))] }));
87
+ }
88
+ function InfoCard(props) {
89
+ return (_jsxs("section", { className: "animate-fade-in rounded-2xl border border-gray-200 bg-white p-6 dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsxs("div", { className: "mb-5 flex items-center justify-between", children: [_jsx("h3", { className: "text-lg font-medium text-gray-800 dark:text-white/90", children: props.title }), _jsxs("button", { type: "button", onClick: props.onEdit, className: "flex items-center gap-2 rounded-full border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-all duration-200 hover:border-brand-500 hover:bg-brand-500 hover:text-white dark:border-gray-700 dark:text-gray-300", children: [_jsx("svg", { width: 16, height: 16, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M4 20h4L18.5 9.5a2.1 2.1 0 00-3-3L5 17v3z", stroke: "currentColor", strokeWidth: 1.6, strokeLinejoin: "round" }) }), "Edit"] })] }), _jsx("dl", { className: "grid gap-x-8 gap-y-5 sm:grid-cols-2", children: props.rows
90
+ .filter(([label, value]) => label !== "" || (value ?? "") !== "")
91
+ .map(([label, value]) => (_jsxs("div", { children: [_jsx("dt", { className: "text-xs text-gray-500 dark:text-gray-400", children: label }), _jsx("dd", { className: "mt-1 text-sm font-medium break-words text-gray-800 dark:text-white/90", children: value || "—" })] }, label || value))) })] }));
92
+ }
93
+ export function PasswordTab() {
94
+ const { step, error, notice, busy } = useStep();
95
+ const change = (event) => {
96
+ event.preventDefault();
97
+ const form = event.currentTarget;
98
+ const f = new FormData(form);
99
+ if (f.get("new_password") !== f.get("again")) {
100
+ step(async () => {
101
+ throw new Error("The two new passwords aren't the same.");
102
+ });
103
+ return;
104
+ }
105
+ step(async () => {
106
+ await api.post("/v1/auth/change-password", {
107
+ current_password: f.get("current_password"),
108
+ new_password: f.get("new_password"),
109
+ });
110
+ form.reset();
111
+ }, "Your password is changed.");
112
+ };
113
+ return (_jsxs(Section, { title: "Change password", about: "Use one you don't use anywhere else.", children: [_jsx(Messages, { error: error, notice: notice }), _jsxs("form", { onSubmit: change, className: "max-w-md space-y-5", children: [[
114
+ ["current_password", "Current password", "current-password"],
115
+ ["new_password", "New password", "new-password"],
116
+ ["again", "New password again", "new-password"],
117
+ ].map(([name, label, auto]) => (_jsx(Labelled, { label: label, htmlFor: `pw-${name}`, children: _jsx("input", { id: `pw-${name}`, name: name, type: "password", required: true, autoComplete: auto, className: input }) }, name))), _jsx("button", { type: "submit", disabled: busy, className: primary, children: "Change password" })] })] }));
118
+ }
@@ -0,0 +1 @@
1
+ export declare function SessionsTab(): import("react").JSX.Element;
@@ -0,0 +1,26 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // The devices signed in to the account (GET /v1/sessions): sign one out,
4
+ // or every other one (each asks to confirm it's you).
5
+ import { useEffect, useState } from "react";
6
+ import { useAction } from "../actions";
7
+ import { api } from "../client";
8
+ import { formatDateTime } from "../dates";
9
+ import { Messages, Section, secondary, useStep } from "./shared";
10
+ export function SessionsTab() {
11
+ const [list, setList] = useState(null);
12
+ const { run, dialogs } = useAction();
13
+ const { step, error, notice, busy } = useStep();
14
+ const load = () => api
15
+ .get("/v1/sessions")
16
+ .then((r) => setList(r.sessions))
17
+ .catch(() => setList([]));
18
+ useEffect(() => {
19
+ load();
20
+ }, []);
21
+ const end = (path, done) => step(async () => {
22
+ await run((o) => api.delete(path, o));
23
+ await load();
24
+ }, done);
25
+ return (_jsxs(Section, { title: "Where you're signed in", about: "Sign out a device you don't recognise.", children: [_jsx(Messages, { error: error, notice: notice }), _jsx("ul", { className: "divide-y divide-gray-100 dark:divide-gray-800", children: list?.map((s) => (_jsxs("li", { className: "flex flex-wrap items-center justify-between gap-3 py-3", children: [_jsxs("div", { children: [_jsxs("p", { className: "text-sm font-medium text-gray-800 dark:text-white/90", children: [s.device_name || s.device_type || "A browser", s.current && (_jsx("span", { className: "ml-2 rounded-full bg-brand-50 px-2 py-0.5 text-xs text-brand-500", children: "this one" }))] }), _jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: [s.last_ip, " \u00B7 last seen ", formatDateTime(s.last_seen_at)] })] }), !s.current && (_jsx("button", { type: "button", disabled: busy, className: secondary, onClick: () => end(`/v1/sessions/${s.id}`, "That device is signed out."), children: "Sign out" }))] }, s.id))) }), (list?.length ?? 0) > 1 && (_jsx("button", { type: "button", disabled: busy, className: `${secondary} mt-4`, onClick: () => end("/v1/sessions", "Every other device is signed out."), children: "Sign out every other device" })), dialogs] }));
26
+ }
@@ -0,0 +1,26 @@
1
+ import { type ReactNode } from "react";
2
+ export declare const input = "h-11 w-full rounded-lg border border-gray-300 bg-transparent px-4 text-sm text-gray-800 transition focus:border-brand-300 focus:outline-none focus:ring-3 focus:ring-brand-500/10 disabled:opacity-60 dark:border-gray-700 dark:text-white/90";
3
+ export declare const primary = "rounded-lg bg-brand-500 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-brand-600 disabled:opacity-40";
4
+ export declare const secondary = "rounded-lg border border-gray-300 px-4 py-2.5 text-sm text-gray-700 transition hover:bg-gray-50 disabled:opacity-40 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-white/5";
5
+ /** A section of a tab: title, what it's for, then its content. */
6
+ export declare function Section(props: {
7
+ title: string;
8
+ about?: string;
9
+ children: ReactNode;
10
+ }): import("react").JSX.Element;
11
+ /** Runs a step, keeping what went wrong (not a closed dialog) and "busy". */
12
+ export declare function useStep(): {
13
+ step: (fn: () => Promise<unknown>, done?: string) => Promise<void>;
14
+ error: string;
15
+ notice: string;
16
+ busy: boolean;
17
+ };
18
+ export declare function Messages({ error, notice }: {
19
+ error: string;
20
+ notice: string;
21
+ }): import("react").JSX.Element;
22
+ export declare function Labelled(props: {
23
+ label: string;
24
+ htmlFor: string;
25
+ children: ReactNode;
26
+ }): import("react").JSX.Element;
@@ -0,0 +1,44 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ // What the account tabs share.
4
+ import { useState } from "react";
5
+ import { Cancelled } from "../actions";
6
+ export const input = "h-11 w-full rounded-lg border border-gray-300 bg-transparent px-4 text-sm text-gray-800 transition focus:border-brand-300 focus:outline-none focus:ring-3 focus:ring-brand-500/10 disabled:opacity-60 dark:border-gray-700 dark:text-white/90";
7
+ export const primary = "rounded-lg bg-brand-500 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-brand-600 disabled:opacity-40";
8
+ export const secondary = "rounded-lg border border-gray-300 px-4 py-2.5 text-sm text-gray-700 transition hover:bg-gray-50 disabled:opacity-40 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-white/5";
9
+ /** A section of a tab: title, what it's for, then its content. */
10
+ export function Section(props) {
11
+ return (_jsxs("section", { className: "animate-fade-in rounded-2xl border border-gray-200 bg-white p-6 dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsx("h2", { className: "text-lg font-medium text-gray-800 dark:text-white/90", children: props.title }), props.about && (_jsx("p", { className: "mt-1 text-sm text-gray-500 dark:text-gray-400", children: props.about })), _jsx("div", { className: "mt-5", children: props.children })] }));
12
+ }
13
+ /** Runs a step, keeping what went wrong (not a closed dialog) and "busy". */
14
+ export function useStep() {
15
+ const [error, setError] = useState("");
16
+ const [notice, setNotice] = useState("");
17
+ const [busy, setBusy] = useState(false);
18
+ const step = async (fn, done) => {
19
+ setError("");
20
+ setNotice("");
21
+ setBusy(true);
22
+ try {
23
+ await fn();
24
+ if (done) {
25
+ setNotice(done);
26
+ }
27
+ }
28
+ catch (err) {
29
+ if (!(err instanceof Cancelled)) {
30
+ setError(err instanceof Error ? err.message : String(err));
31
+ }
32
+ }
33
+ finally {
34
+ setBusy(false);
35
+ }
36
+ };
37
+ return { step, error, notice, busy };
38
+ }
39
+ export function Messages({ error, notice }) {
40
+ return (_jsxs(_Fragment, { children: [error !== "" && (_jsx("p", { role: "alert", className: "mb-4 rounded-lg bg-red-50 px-4 py-3 text-sm text-red-600", children: error })), notice !== "" && (_jsx("p", { className: "mb-4 animate-slide-down rounded-lg bg-green-50 px-4 py-3 text-sm text-green-700 dark:bg-green-500/15 dark:text-green-500", children: notice }))] }));
41
+ }
42
+ export function Labelled(props) {
43
+ return (_jsxs("div", { children: [_jsx("label", { htmlFor: props.htmlFor, className: "mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-400", children: props.label }), props.children] }));
44
+ }
@@ -0,0 +1,5 @@
1
+ import type * as users from "../api/users.gen";
2
+ export declare function TwoFactorTab({ me, onSaved }: {
3
+ me: users.UserResponse;
4
+ onSaved(): void;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,60 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Two-step verification (docs/two-factor.md): an authenticator app, set up
4
+ // with a QR code; two-factor sign-in on or off; recovery codes. Each change
5
+ // asks the user to confirm it's them (useAction, reauth.required).
6
+ import qrcode from "qrcode-generator";
7
+ import { useEffect, useState } from "react";
8
+ import { useAction } from "../actions";
9
+ import { api, signOut } from "../client";
10
+ import { CodeInput } from "../ui";
11
+ import { Messages, primary, Section, secondary, useStep } from "./shared";
12
+ export function TwoFactorTab({ me, onSaved }) {
13
+ const [methods, setMethods] = useState([]);
14
+ const [setup, setSetup] = useState(null);
15
+ const [code, setCode] = useState("");
16
+ const [codes, setCodes] = useState([]);
17
+ const [signedOut, setSignedOut] = useState(false);
18
+ const { run, dialogs } = useAction();
19
+ const { step, error, notice, busy } = useStep();
20
+ const hasApp = methods.includes("totp");
21
+ const load = () => api
22
+ .get("/v1/reauth/methods")
23
+ .then((r) => setMethods(r.methods))
24
+ .catch(() => setMethods([]));
25
+ useEffect(() => {
26
+ load();
27
+ }, []);
28
+ const start = () => step(async () => {
29
+ setSetup(await api.post("/v1/reauth/totp"));
30
+ setCode("");
31
+ });
32
+ const confirm = (value) => step(async () => {
33
+ await run((o) => api.post("/v1/reauth/totp/confirm", { code: value }, o));
34
+ setSetup(null);
35
+ await load();
36
+ }, "Your authenticator app is added.");
37
+ const removeApp = () => step(async () => {
38
+ await run((o) => api.delete("/v1/reauth/totp", o));
39
+ await load();
40
+ }, "The authenticator app is removed.");
41
+ const setTwoFactor = (enabled) => step(async () => {
42
+ const res = await run((o) => api.put("/v1/reauth/2fa", { enabled }, o));
43
+ setCodes(res.recovery_codes ?? []);
44
+ setSignedOut(res.signed_out);
45
+ onSaved();
46
+ }, enabled ? "Two-step sign-in is on." : "Two-step sign-in is off.");
47
+ const newCodes = () => step(async () => {
48
+ const res = await run((o) => api.post("/v1/reauth/recovery-codes", undefined, o));
49
+ setCodes(res.recovery_codes);
50
+ });
51
+ return (_jsxs("div", { className: "space-y-6", children: [_jsx(Messages, { error: error, notice: notice }), _jsx(Section, { title: "Authenticator app", about: "Google Authenticator, Microsoft Authenticator, 1Password: a new code every 30 seconds.", children: setup !== null ? (_jsxs("div", { className: "grid animate-slide-in gap-6 md:grid-cols-[auto_1fr] md:items-start", children: [_jsx("img", { src: qrDataURL(setup.otpauth_url), alt: "Scan with your authenticator app", className: "size-44 rounded-lg border border-gray-200 bg-white p-2" }), _jsxs("div", { className: "space-y-4", children: [_jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: ["Scan the code with the app, or type this key:", " ", _jsx("span", { className: "font-mono text-gray-800 dark:text-white/90", children: setup.secret }), ". Then enter the code the app shows."] }), _jsx(CodeInput, { value: code, onChange: setCode, onComplete: confirm, disabled: busy }), _jsxs("div", { className: "flex gap-3", children: [_jsx("button", { type: "button", disabled: busy, className: primary, onClick: () => confirm(code), children: "Add the app" }), _jsx("button", { type: "button", className: secondary, onClick: () => setSetup(null), children: "Cancel" })] })] })] })) : hasApp ? (_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsx("span", { className: "text-sm text-green-700 dark:text-green-500", children: "Added" }), _jsx("button", { type: "button", disabled: busy, className: secondary, onClick: removeApp, children: "Remove" })] })) : (_jsx("button", { type: "button", disabled: busy, className: primary, onClick: start, children: "Set up an authenticator app" })) }), _jsxs(Section, { title: "Two-step sign-in", about: "Signing in also asks for a second proof: a code from the app, your email or phone, or a PIN. It needs two such ways set up.", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsx("span", { className: `rounded-full px-2.5 py-0.5 text-xs font-medium ${me.mfa_enabled
52
+ ? "bg-green-50 text-green-700 dark:bg-green-500/15 dark:text-green-500"
53
+ : "bg-gray-100 text-gray-600 dark:bg-white/5 dark:text-gray-400"}`, children: me.mfa_enabled ? "On" : "Off" }), _jsxs("div", { className: "flex gap-3", children: [me.mfa_enabled && (_jsx("button", { type: "button", disabled: busy, className: secondary, onClick: newCodes, children: "New recovery codes" })), _jsx("button", { type: "button", disabled: busy, className: me.mfa_enabled ? secondary : primary, onClick: () => setTwoFactor(!me.mfa_enabled), children: me.mfa_enabled ? "Turn off" : "Turn on" })] })] }), codes.length > 0 && (_jsxs("div", { className: "mt-5 animate-slide-down rounded-xl bg-gray-50 p-4 dark:bg-white/5", children: [_jsx("p", { className: "text-sm text-gray-700 dark:text-gray-300", children: "Your recovery codes: keep them somewhere safe. Each works once, if you lose your second factor. They are shown only now." }), _jsx("ul", { className: "mt-3 grid grid-cols-2 gap-2 font-mono text-sm text-gray-800 sm:grid-cols-4 dark:text-white/90", children: codes.map((c) => (_jsx("li", { children: c }, c))) })] })), signedOut && (_jsxs("div", { className: "mt-4 flex flex-wrap items-center justify-between gap-3 text-sm text-gray-600 dark:text-gray-400", children: ["Turning it on signed you out everywhere: save your codes, then sign in again.", _jsx("button", { type: "button", className: primary, onClick: () => signOut(), children: "Sign in again" })] }))] }), dialogs] }));
54
+ }
55
+ function qrDataURL(text) {
56
+ const qr = qrcode(0, "M");
57
+ qr.addData(text);
58
+ qr.make();
59
+ return qr.createDataURL(5, 2);
60
+ }
@@ -0,0 +1,39 @@
1
+ import { type ReactNode } from "react";
2
+ import { type SendOptions } from "./client";
3
+ /** Thrown by run when the user closes a dialog instead of answering it. */
4
+ export declare class Cancelled extends Error {
5
+ constructor();
6
+ }
7
+ /** Asks why a change is made: the reason goes to the audit log. */
8
+ export declare function ReasonDialog(props: {
9
+ onReason(reason: string): void;
10
+ onCancel(): void;
11
+ }): import("react").JSX.Element;
12
+ export interface StepUpProps {
13
+ /** The action the API names in reauth.required (data.action). */
14
+ action: string;
15
+ /** The methods it allows (data.methods); all the user's when empty. */
16
+ methods?: string[];
17
+ onToken(token: string): void;
18
+ onCancel(): void;
19
+ }
20
+ /** "Confirm it's you": re-authenticates for one action, for a token. */
21
+ export declare function StepUp({ action, methods, onToken, onCancel }: StepUpProps): import("react").JSX.Element;
22
+ /**
23
+ * run(send) calls send with the options a change needs, asking for a
24
+ * reason or a re-authentication when the API refuses without one, then
25
+ * sending again. Render dialogs in the page.
26
+ *
27
+ * const { run, dialogs } = useAction()
28
+ * await run((o) => api.patch(`/v1/settings/${key}`, { value }, o))
29
+ */
30
+ export declare function useAction(): {
31
+ run<T>(send: (options: SendOptions) => Promise<T>): Promise<T>;
32
+ dialogs: ReactNode;
33
+ };
34
+ /**
35
+ * A key for one change, for a form that sends it itself: the same key
36
+ * while the same request is resent (a network error), a new one once it is
37
+ * done or changed (renew).
38
+ */
39
+ export declare function useIdempotencyKey(): [key: string, renew: () => void];
@@ -0,0 +1,81 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Changes that need more than a click: a reason for the audit log
4
+ // (X-Reason), a re-authentication (X-Reauth-Token), a key that makes a
5
+ // resent request run once (Idempotency-Key). useAction asks for the first
6
+ // two when the API says so, and retries.
7
+ import { useEffect, useState } from "react";
8
+ import { api } from "./client";
9
+ import { ProofForm } from "./proof";
10
+ import { sendAsking } from "./retry";
11
+ import { Button, Dialog, Field } from "./ui";
12
+ /** Thrown by run when the user closes a dialog instead of answering it. */
13
+ export class Cancelled extends Error {
14
+ constructor() {
15
+ super("cancelled");
16
+ }
17
+ }
18
+ /** Asks why a change is made: the reason goes to the audit log. */
19
+ export function ReasonDialog(props) {
20
+ const onSubmit = (event) => {
21
+ event.preventDefault();
22
+ const reason = String(new FormData(event.currentTarget).get("reason")).trim();
23
+ if (reason !== "") {
24
+ props.onReason(reason);
25
+ }
26
+ };
27
+ return (_jsx(Dialog, { title: "Why are you making this change?", children: _jsxs("form", { className: "space-y-4", onSubmit: onSubmit, children: [_jsx(Field, { label: "Reason (kept in the audit log)", name: "reason", multiline: true }), _jsx(Button, { type: "submit", children: "Continue" }), _jsx(Button, { quiet: true, onClick: props.onCancel, children: "Cancel" })] }) }));
28
+ }
29
+ /** "Confirm it's you": re-authenticates for one action, for a token. */
30
+ export function StepUp({ action, methods, onToken, onCancel }) {
31
+ const [own, setOwn] = useState(null);
32
+ useEffect(() => {
33
+ api
34
+ .get("/v1/reauth/methods")
35
+ .then((res) => setOwn(res.methods))
36
+ .catch(() => setOwn([]));
37
+ }, []);
38
+ // The user's methods, narrowed to those the action allows.
39
+ const usable = own?.filter((m) => methods === undefined || methods.length === 0 || methods.includes(m));
40
+ return (_jsxs(Dialog, { title: "Confirm it's you", children: [usable !== undefined && (_jsx(ProofForm, { methods: usable, sendCode: async (channel) => {
41
+ const sent = await api.post("/v1/reauth/codes", { channel }, { idempotencyKey: crypto.randomUUID() });
42
+ return sent.data.verification_id;
43
+ }, submit: async (proof) => {
44
+ const res = await api.post("/v1/reauth/tokens", {
45
+ ...proof,
46
+ action,
47
+ });
48
+ onToken(res.reauth_token);
49
+ } })), _jsx("div", { className: "mt-2", children: _jsx(Button, { quiet: true, onClick: onCancel, children: "Cancel" }) })] }));
50
+ }
51
+ /**
52
+ * run(send) calls send with the options a change needs, asking for a
53
+ * reason or a re-authentication when the API refuses without one, then
54
+ * sending again. Render dialogs in the page.
55
+ *
56
+ * const { run, dialogs } = useAction()
57
+ * await run((o) => api.patch(`/v1/settings/${key}`, { value }, o))
58
+ */
59
+ export function useAction() {
60
+ const [ask, setAsk] = useState(null);
61
+ const reason = () => new Promise((resolve, reject) => setAsk({ kind: "reason", resolve, reject: () => reject(new Cancelled()) })).finally(() => setAsk(null));
62
+ const stepUp = (action, methods) => new Promise((resolve, reject) => setAsk({ kind: "stepUp", action, methods, resolve, reject: () => reject(new Cancelled()) })).finally(() => setAsk(null));
63
+ const run = (send) => sendAsking(send, { reason, stepUp });
64
+ let dialogs = null;
65
+ if (ask?.kind === "reason") {
66
+ dialogs = _jsx(ReasonDialog, { onReason: ask.resolve, onCancel: ask.reject });
67
+ }
68
+ else if (ask?.kind === "stepUp") {
69
+ dialogs = (_jsx(StepUp, { action: ask.action, methods: ask.methods, onToken: ask.resolve, onCancel: ask.reject }));
70
+ }
71
+ return { run, dialogs };
72
+ }
73
+ /**
74
+ * A key for one change, for a form that sends it itself: the same key
75
+ * while the same request is resent (a network error), a new one once it is
76
+ * done or changed (renew).
77
+ */
78
+ export function useIdempotencyKey() {
79
+ const [key, setKey] = useState(() => crypto.randomUUID());
80
+ return [key, () => setKey(crypto.randomUUID())];
81
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Actions this module records about the log itself.
3
+ */
4
+ export declare const ActionLogViewed = "audit.LogViewed";
5
+ /**
6
+ * Actions this module records about the log itself.
7
+ */
8
+ export declare const ActionChainVerified = "audit.ChainVerified";
9
+ /**
10
+ * Actions this module records about the log itself.
11
+ */
12
+ export declare const ActionMonthArchived = "audit.MonthArchived";
13
+ /**
14
+ * JobArchive moves every month older than audit.keep_months to storage.
15
+ */
16
+ export declare const JobArchive = "audit.archive";
17
+ /**
18
+ * JobVerify checks the hash chain since the last check (daily).
19
+ */
20
+ export declare const JobVerify = "audit.verify";
21
+ /**
22
+ * JobVerifyFull checks the whole chain in the database (monthly).
23
+ */
24
+ export declare const JobVerifyFull = "audit.verify_full";
25
+ /**
26
+ * EventResponse is one recorded event. Seq is its place in the hash chain,
27
+ * null for the second or so until it is sealed.
28
+ */
29
+ export interface EventResponse {
30
+ id: string;
31
+ seq?: number;
32
+ occurred_at: string;
33
+ action: string;
34
+ outcome: string;
35
+ actor_id?: string;
36
+ target_type: string;
37
+ target_id: string;
38
+ reason: string;
39
+ metadata: {
40
+ [key: string]: unknown;
41
+ };
42
+ ip: string;
43
+ user_agent: string;
44
+ request_id: string;
45
+ }
46
+ /**
47
+ * ArchiveResponse is one month moved to storage.
48
+ */
49
+ export interface ArchiveResponse {
50
+ id: string;
51
+ period_start: string;
52
+ period_end: string;
53
+ timezone: string;
54
+ first_seq: number;
55
+ last_seq: number;
56
+ record_count: number;
57
+ key: string;
58
+ size_bytes: number;
59
+ checksum: string;
60
+ status: string;
61
+ error: string;
62
+ created_at: string;
63
+ updated_at: string;
64
+ }
65
+ /**
66
+ * PermissionRead lets an admin read the audit log.
67
+ */
68
+ export declare const PermissionRead: string;
69
+ /**
70
+ * Service is the module's admin surface, used by its HTTP handlers.
71
+ */
72
+ export type Service = unknown;
73
+ /**
74
+ * SettingTimezone is the timezone months are cut in.
75
+ */
76
+ export declare const SettingTimezone: string;
77
+ /**
78
+ * SettingKeepMonths is how many whole months stay in the database.
79
+ */
80
+ export declare const SettingKeepMonths: string;
@@ -0,0 +1,43 @@
1
+ // Code generated by tygo. DO NOT EDIT.
2
+ //////////
3
+ // source: actions.go
4
+ /**
5
+ * Actions this module records about the log itself.
6
+ */
7
+ export const ActionLogViewed = "audit.LogViewed";
8
+ /**
9
+ * Actions this module records about the log itself.
10
+ */
11
+ export const ActionChainVerified = "audit.ChainVerified";
12
+ /**
13
+ * Actions this module records about the log itself.
14
+ */
15
+ export const ActionMonthArchived = "audit.MonthArchived";
16
+ /**
17
+ * JobArchive moves every month older than audit.keep_months to storage.
18
+ */
19
+ export const JobArchive = "audit.archive";
20
+ /**
21
+ * JobVerify checks the hash chain since the last check (daily).
22
+ */
23
+ export const JobVerify = "audit.verify";
24
+ /**
25
+ * JobVerifyFull checks the whole chain in the database (monthly).
26
+ */
27
+ export const JobVerifyFull = "audit.verify_full";
28
+ //////////
29
+ // source: permissions.go
30
+ /**
31
+ * PermissionRead lets an admin read the audit log.
32
+ */
33
+ export const PermissionRead = "audit.read";
34
+ //////////
35
+ // source: settings.go
36
+ /**
37
+ * SettingTimezone is the timezone months are cut in.
38
+ */
39
+ export const SettingTimezone = "audit.timezone";
40
+ /**
41
+ * SettingKeepMonths is how many whole months stay in the database.
42
+ */
43
+ export const SettingKeepMonths = "audit.keep_months";