@colveor/admin 0.0.0-stage → 0.5.2
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/LICENSE.md +106 -0
- package/TAILWINDADMIN-LICENSE +21 -0
- package/dist/account/data.d.ts +1 -0
- package/dist/account/data.js +44 -0
- package/dist/account/profile.d.ts +6 -0
- package/dist/account/profile.js +118 -0
- package/dist/account/sessions.d.ts +1 -0
- package/dist/account/sessions.js +26 -0
- package/dist/account/shared.d.ts +26 -0
- package/dist/account/shared.js +44 -0
- package/dist/account/two-factor.d.ts +5 -0
- package/dist/account/two-factor.js +60 -0
- package/dist/actions.d.ts +39 -0
- package/dist/actions.js +81 -0
- package/dist/api/audit.gen.d.ts +80 -0
- package/dist/api/audit.gen.js +43 -0
- package/dist/api/auth.gen.d.ts +537 -0
- package/dist/api/auth.gen.js +313 -0
- package/dist/api/errors.gen.d.ts +16 -0
- package/dist/api/errors.gen.js +2 -0
- package/dist/api/gormx.gen.d.ts +60 -0
- package/dist/api/gormx.gen.js +16 -0
- package/dist/api/health.gen.d.ts +103 -0
- package/dist/api/health.gen.js +23 -0
- package/dist/api/index.gen.d.ts +21 -0
- package/dist/api/index.gen.js +22 -0
- package/dist/api/invitations.gen.d.ts +128 -0
- package/dist/api/invitations.gen.js +57 -0
- package/dist/api/ledger.gen.d.ts +269 -0
- package/dist/api/ledger.gen.js +113 -0
- package/dist/api/msgtemplate.gen.d.ts +31 -0
- package/dist/api/msgtemplate.gen.js +2 -0
- package/dist/api/notifications.gen.d.ts +66 -0
- package/dist/api/notifications.gen.js +28 -0
- package/dist/api/outbox.gen.d.ts +8 -0
- package/dist/api/outbox.gen.js +2 -0
- package/dist/api/queue.gen.d.ts +112 -0
- package/dist/api/queue.gen.js +15 -0
- package/dist/api/rbac.gen.d.ts +406 -0
- package/dist/api/rbac.gen.js +191 -0
- package/dist/api/reauth.gen.d.ts +289 -0
- package/dist/api/reauth.gen.js +122 -0
- package/dist/api/recorded_payments.gen.d.ts +171 -0
- package/dist/api/recorded_payments.gen.js +79 -0
- package/dist/api/sessions.gen.d.ts +64 -0
- package/dist/api/sessions.gen.js +48 -0
- package/dist/api/settings.gen.d.ts +147 -0
- package/dist/api/settings.gen.js +69 -0
- package/dist/api/storage.gen.d.ts +327 -0
- package/dist/api/storage.gen.js +208 -0
- package/dist/api/support_access.gen.d.ts +155 -0
- package/dist/api/support_access.gen.js +131 -0
- package/dist/api/users.gen.d.ts +407 -0
- package/dist/api/users.gen.js +159 -0
- package/dist/api/verification.gen.d.ts +427 -0
- package/dist/api/verification.gen.js +280 -0
- package/dist/api/webhooks.gen.d.ts +110 -0
- package/dist/api/webhooks.gen.js +45 -0
- package/dist/auth-layout.d.ts +9 -0
- package/dist/auth-layout.js +5 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.js +72 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.js +82 -0
- package/dist/dates.d.ts +4 -0
- package/dist/dates.js +16 -0
- package/dist/header.d.ts +12 -0
- package/dist/header.js +105 -0
- package/dist/icons.d.ts +2 -0
- package/dist/icons.js +15 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +42 -0
- package/dist/kit/avatar.d.ts +5 -0
- package/dist/kit/avatar.js +16 -0
- package/dist/kit/badge.d.ts +10 -0
- package/dist/kit/badge.js +31 -0
- package/dist/kit/card.d.ts +12 -0
- package/dist/kit/card.js +7 -0
- package/dist/kit/code-area.d.ts +15 -0
- package/dist/kit/code-area.js +69 -0
- package/dist/kit/dropdown.d.ts +26 -0
- package/dist/kit/dropdown.js +67 -0
- package/dist/kit/filter-tabs.d.ts +9 -0
- package/dist/kit/filter-tabs.js +7 -0
- package/dist/kit/modal.d.ts +8 -0
- package/dist/kit/modal.js +15 -0
- package/dist/kit/page-header.d.ts +13 -0
- package/dist/kit/page-header.js +13 -0
- package/dist/kit/search.d.ts +4 -0
- package/dist/kit/search.js +16 -0
- package/dist/kit/tooltip.d.ts +17 -0
- package/dist/kit/tooltip.js +52 -0
- package/dist/message-editor.d.ts +9 -0
- package/dist/message-editor.js +80 -0
- package/dist/money.d.ts +10 -0
- package/dist/money.js +17 -0
- package/dist/next.d.ts +6 -0
- package/dist/next.js +19 -0
- package/dist/pages/account.d.ts +1 -0
- package/dist/pages/account.js +47 -0
- package/dist/pages/audit.d.ts +1 -0
- package/dist/pages/audit.js +88 -0
- package/dist/pages/forgot-password.d.ts +1 -0
- package/dist/pages/forgot-password.js +73 -0
- package/dist/pages/ledger.d.ts +1 -0
- package/dist/pages/ledger.js +132 -0
- package/dist/pages/roles.d.ts +1 -0
- package/dist/pages/roles.js +102 -0
- package/dist/pages/settings.d.ts +1 -0
- package/dist/pages/settings.js +86 -0
- package/dist/pages/sign-in.d.ts +5 -0
- package/dist/pages/sign-in.js +117 -0
- package/dist/pages/status.d.ts +1 -0
- package/dist/pages/status.js +122 -0
- package/dist/pages/support.d.ts +1 -0
- package/dist/pages/support.js +90 -0
- package/dist/pages/teams.d.ts +1 -0
- package/dist/pages/teams.js +94 -0
- package/dist/pages/users.d.ts +1 -0
- package/dist/pages/users.js +158 -0
- package/dist/pages/webhooks.d.ts +1 -0
- package/dist/pages/webhooks.js +88 -0
- package/dist/permissions.d.ts +5 -0
- package/dist/permissions.js +31 -0
- package/dist/proof.d.ts +10 -0
- package/dist/proof.js +78 -0
- package/dist/proxy.d.ts +10 -0
- package/dist/proxy.js +166 -0
- package/dist/retry.d.ts +8 -0
- package/dist/retry.js +30 -0
- package/dist/router.d.ts +13 -0
- package/dist/router.js +14 -0
- package/dist/setting-fields.d.ts +12 -0
- package/dist/setting-fields.js +102 -0
- package/dist/setting-list.d.ts +22 -0
- package/dist/setting-list.js +78 -0
- package/dist/shell.d.ts +40 -0
- package/dist/shell.js +97 -0
- package/dist/support.d.ts +37 -0
- package/dist/support.js +76 -0
- package/dist/table.d.ts +40 -0
- package/dist/table.js +73 -0
- package/dist/ui.d.ts +39 -0
- package/dist/ui.js +56 -0
- package/dist/user-actions.d.ts +30 -0
- package/dist/user-actions.js +129 -0
- package/dist/user-roles.d.ts +4 -0
- package/dist/user-roles.js +51 -0
- package/dist/user-row-menu.d.ts +14 -0
- package/dist/user-row-menu.js +45 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/package.json +59 -4
- package/README.md +0 -3
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Team status (docs/team-status.md), a platform admin's (teams.suspend):
|
|
4
|
+
// the suspended teams, and a team looked up by kind and ID to suspend or
|
|
5
|
+
// reactivate. A suspended team keeps its data; its members, and those of
|
|
6
|
+
// every team under it, can't act in it. Each change asks for a reason.
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { Cancelled, useAction } from "../actions";
|
|
9
|
+
import * as rbac from "../api/rbac.gen";
|
|
10
|
+
import { ApiError, api } from "../client";
|
|
11
|
+
import { formatDateTime } from "../dates";
|
|
12
|
+
import { PageHeader } from "../kit/page-header";
|
|
13
|
+
import { DataTable } from "../table";
|
|
14
|
+
import { Alert } from "../ui";
|
|
15
|
+
const input = "w-full rounded-lg border border-gray-300 bg-transparent px-3 py-2 text-sm text-gray-800 focus:border-brand-300 focus:outline-none dark:border-gray-700 dark:text-white/90";
|
|
16
|
+
const card = "space-y-4 rounded-2xl border border-gray-200 bg-white p-5 dark:border-gray-800 dark:bg-white/[0.03]";
|
|
17
|
+
const teamName = (t) => `${t.kind}/${t.id}`;
|
|
18
|
+
const teamPath = (t) => `/v1/teams/${encodeURIComponent(t.kind)}/${encodeURIComponent(t.id)}`;
|
|
19
|
+
export default function TeamsPage() {
|
|
20
|
+
const [team, setTeam] = useState(null);
|
|
21
|
+
const [reload, setReload] = useState(0);
|
|
22
|
+
const [kind, setKind] = useState("");
|
|
23
|
+
return (_jsxs("div", { className: "space-y-6", children: [_jsx(PageHeader, { title: "Teams" }), _jsx(TeamLookup, { team: team, onTeam: setTeam, onChange: () => setReload((n) => n + 1) }), _jsxs("section", { className: card, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsx("h2", { className: "font-medium text-gray-800 dark:text-white/90", children: "Suspended teams" }), _jsx("input", { "aria-label": "Only this kind", placeholder: "Only this kind (store)", value: kind, onChange: (e) => setKind(e.target.value.trim()), className: `${input} max-w-56` })] }), _jsx(DataTable, { path: "/v1/teams/suspended", query: { kind }, reload: reload, rowKey: (s) => teamName(s.team), empty: "No team is suspended.", columns: [
|
|
24
|
+
{
|
|
25
|
+
header: "Team",
|
|
26
|
+
cell: (s) => (_jsx("button", { type: "button", onClick: () => setTeam(s.team), className: "font-mono text-xs text-brand-500 hover:underline", children: teamName(s.team) })),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
header: "Since",
|
|
30
|
+
cell: (s) => (s.suspended_at ? formatDateTime(s.suspended_at) : ""),
|
|
31
|
+
},
|
|
32
|
+
{ header: "Reason", cell: (s) => s.reason },
|
|
33
|
+
] })] })] }));
|
|
34
|
+
}
|
|
35
|
+
function TeamLookup(props) {
|
|
36
|
+
const { team } = props;
|
|
37
|
+
const [status, setStatus] = useState(null);
|
|
38
|
+
const [error, setError] = useState("");
|
|
39
|
+
const [busy, setBusy] = useState(false);
|
|
40
|
+
const { run, dialogs } = useAction();
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (team === null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let current = true;
|
|
46
|
+
setError("");
|
|
47
|
+
setStatus(null);
|
|
48
|
+
api
|
|
49
|
+
.get(`${teamPath(team)}/status`)
|
|
50
|
+
.then((s) => current && setStatus(s))
|
|
51
|
+
.catch((err) => current &&
|
|
52
|
+
setError(err instanceof ApiError && err.status === 404
|
|
53
|
+
? "No team has this kind and ID."
|
|
54
|
+
: err.message));
|
|
55
|
+
return () => {
|
|
56
|
+
current = false;
|
|
57
|
+
};
|
|
58
|
+
}, [team]);
|
|
59
|
+
const find = (event) => {
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
const f = new FormData(event.currentTarget);
|
|
62
|
+
props.onTeam({ kind: String(f.get("kind")).trim(), id: String(f.get("id")).trim() });
|
|
63
|
+
};
|
|
64
|
+
const change = async (suspend) => {
|
|
65
|
+
if (team === null) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (suspend &&
|
|
69
|
+
!window.confirm(`Suspend ${teamName(team)}? Its members, and those of every team under it, can't act in it until it is reactivated.`)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
setError("");
|
|
73
|
+
setBusy(true);
|
|
74
|
+
try {
|
|
75
|
+
setStatus(await run((o) => api.post(`${teamPath(team)}/${suspend ? "suspend" : "reactivate"}`, undefined, o)));
|
|
76
|
+
props.onChange();
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (!(err instanceof Cancelled)) {
|
|
80
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
setBusy(false);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
// Suspended through a team above it: that one is reactivated instead.
|
|
88
|
+
const above = status?.suspended_by !== undefined && teamName(status.suspended_by) !== teamName(status.team)
|
|
89
|
+
? status.suspended_by
|
|
90
|
+
: undefined;
|
|
91
|
+
return (_jsxs("section", { className: card, children: [_jsx("h2", { className: "font-medium text-gray-800 dark:text-white/90", children: "A team" }), _jsxs("form", { onSubmit: find, className: "flex flex-wrap gap-2", children: [_jsx("input", { name: "kind", required: true, "aria-label": "Kind", placeholder: "Kind (store)", defaultValue: team?.kind, className: `${input} max-w-40` }), _jsx("input", { name: "id", required: true, "aria-label": "ID", placeholder: "ID", defaultValue: team?.id, className: `${input} max-w-sm font-mono` }), _jsx("button", { type: "submit", className: "rounded-lg bg-brand-500 px-4 text-sm font-medium text-white hover:bg-brand-600", children: "Find" })] }, team ? teamName(team) : ""), error !== "" && _jsx(Alert, { children: error }), status !== null && (_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-4", children: [_jsxs("div", { className: "space-y-1 text-sm", children: [_jsxs("p", { children: [_jsx("span", { className: "font-mono text-xs", children: teamName(status.team) }), " ", _jsx("span", { className: `rounded-full px-2 py-0.5 text-xs ${status.status === rbac.TeamSuspended
|
|
92
|
+
? "bg-red-50 text-red-600 dark:bg-red-500/15 dark:text-red-500"
|
|
93
|
+
: "bg-green-50 text-green-700 dark:bg-green-500/15 dark:text-green-500"}`, children: status.status })] }), status.suspended_at && (_jsxs("p", { className: "text-gray-500 dark:text-gray-400", children: ["Since ", formatDateTime(status.suspended_at), status.reason ? `: ${status.reason}` : ""] })), above !== undefined && (_jsxs("p", { className: "text-gray-500 dark:text-gray-400", children: ["Through", " ", _jsx("button", { type: "button", onClick: () => props.onTeam(above), className: "font-mono text-xs text-brand-500 hover:underline", children: teamName(above) }), ", above it: reactivate that one."] }))] }), _jsxs("div", { className: "flex gap-2", children: [status.status === rbac.TeamActive && (_jsx("button", { type: "button", disabled: busy, onClick: () => change(true), className: "rounded-lg border border-red-300 px-3 py-1.5 text-xs text-red-600 hover:bg-red-50 disabled:opacity-40", children: "Suspend" })), status.status === rbac.TeamSuspended && above === undefined && (_jsx("button", { type: "button", disabled: busy, onClick: () => change(false), className: "rounded-lg border border-gray-300 px-3 py-1.5 text-xs text-gray-700 hover:bg-gray-50 disabled:opacity-40 dark:border-gray-700 dark:text-gray-300", children: "Reactivate" }))] })] })), dialogs] }));
|
|
94
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function UsersPage(): import("react").JSX.Element;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
// The users, a page at a time, found by exact email, phone or ID, and one
|
|
4
|
+
// user's details, roles, sessions and the admin's actions on them
|
|
5
|
+
// (docs/user-admin.md).
|
|
6
|
+
import { useEffect, useRef, useState } from "react";
|
|
7
|
+
import * as rbac from "../api/rbac.gen";
|
|
8
|
+
import * as users from "../api/users.gen";
|
|
9
|
+
import { api } from "../client";
|
|
10
|
+
import { formatDate, formatDateTime } from "../dates";
|
|
11
|
+
import { Avatar } from "../kit/avatar";
|
|
12
|
+
import { Badge, humanize, roleTone } from "../kit/badge";
|
|
13
|
+
import { FilterTabs } from "../kit/filter-tabs";
|
|
14
|
+
import { PageHeader } from "../kit/page-header";
|
|
15
|
+
import { SearchToggle } from "../kit/search";
|
|
16
|
+
import { useCan } from "../shell";
|
|
17
|
+
import { DataTable } from "../table";
|
|
18
|
+
import { UserActions, UserSessions } from "../user-actions";
|
|
19
|
+
import { UserRoles } from "../user-roles";
|
|
20
|
+
import { UserRowMenu, userName } from "../user-row-menu";
|
|
21
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
22
|
+
/** The filter a search means: an email, a phone number or a user ID. */
|
|
23
|
+
function searchQuery(text) {
|
|
24
|
+
const t = text.trim();
|
|
25
|
+
if (t === "") {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
if (t.includes("@")) {
|
|
29
|
+
return { email: t };
|
|
30
|
+
}
|
|
31
|
+
if (UUID.test(t)) {
|
|
32
|
+
return { uid: t };
|
|
33
|
+
}
|
|
34
|
+
return { phone: t };
|
|
35
|
+
}
|
|
36
|
+
/** Adds each user's roles: one call for the page (GET /v1/rbac/users/roles). */
|
|
37
|
+
async function withRoles(page) {
|
|
38
|
+
if (page.items.length === 0) {
|
|
39
|
+
return page;
|
|
40
|
+
}
|
|
41
|
+
const roles = await api.get("/v1/rbac/users/roles", {
|
|
42
|
+
ids: page.items.map((u) => u.uid).join(","),
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
...page,
|
|
46
|
+
items: page.items.map((u) => ({ ...u, roles: roles[u.uid] ?? [] })),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** A role's members, as users: the members page, then those users at once. */
|
|
50
|
+
async function membersAsUsers(page) {
|
|
51
|
+
if (page.items.length === 0) {
|
|
52
|
+
return { ...page, items: [] };
|
|
53
|
+
}
|
|
54
|
+
const found = await api.get("/v1/users", {
|
|
55
|
+
ids: page.items.map((m) => m.user_id).join(","),
|
|
56
|
+
limit: page.items.length,
|
|
57
|
+
});
|
|
58
|
+
const byId = new Map(found.items.map((u) => [u.uid, u]));
|
|
59
|
+
return {
|
|
60
|
+
...page,
|
|
61
|
+
items: page.items.flatMap((m) => byId.get(m.user_id) ?? []),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export default function UsersPage() {
|
|
65
|
+
const canReadRoles = useCan(rbac.PermissionRead);
|
|
66
|
+
const [query, setQuery] = useState({});
|
|
67
|
+
const [open, setOpen] = useState(null);
|
|
68
|
+
const [roles, setRoles] = useState([]);
|
|
69
|
+
// "all", or the ID of the role whose members are shown.
|
|
70
|
+
const [tab, setTab] = useState("all");
|
|
71
|
+
// Bumped after a change from a row's menu: the page loads again.
|
|
72
|
+
const [reload, setReload] = useState(0);
|
|
73
|
+
const panel = useRef(null);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (!canReadRoles) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
api
|
|
79
|
+
.get("/v1/rbac/roles")
|
|
80
|
+
.then((r) => setRoles([...r].sort((a, b) => b.level - a.level)))
|
|
81
|
+
.catch(() => undefined);
|
|
82
|
+
}, [canReadRoles]);
|
|
83
|
+
const show = (u) => {
|
|
84
|
+
setOpen(u);
|
|
85
|
+
requestAnimationFrame(() => panel.current?.scrollIntoView({ behavior: "smooth" }));
|
|
86
|
+
};
|
|
87
|
+
// A role's tab lists its members; a search looks among every user.
|
|
88
|
+
const byRole = tab !== "all" && Object.keys(query).length === 0;
|
|
89
|
+
return (_jsxs("div", { className: "space-y-6", children: [_jsx(PageHeader, { title: "Users" }), _jsx("div", { ref: panel, children: open !== null && _jsx(UserPanel, { user: open, onClose: () => setOpen(null) }, open.uid) }), _jsx(DataTable, { title: "Users", download: "users", path: byRole ? `/v1/rbac/roles/${tab}/users` : "/v1/users", query: byRole ? {} : query, transform: async (page) => {
|
|
90
|
+
const list = byRole
|
|
91
|
+
? await membersAsUsers(page)
|
|
92
|
+
: page;
|
|
93
|
+
return canReadRoles ? withRoles(list) : list;
|
|
94
|
+
}, rowKey: (u) => u.uid, reload: reload, onRowClick: show, empty: "No user matches.", actions: _jsx(SearchToggle, { placeholder: "Exact email, phone or user ID", onSearch: (text) => setQuery(searchQuery(text)) }), toolbar: roles.length > 0 && (_jsx(FilterTabs, { value: tab, onChange: setTab, tabs: [
|
|
95
|
+
{ key: "all", label: "All" },
|
|
96
|
+
...roles.map((r) => ({ key: r.id, label: r.name })),
|
|
97
|
+
] })), columns: [
|
|
98
|
+
{
|
|
99
|
+
header: "Name",
|
|
100
|
+
text: userName,
|
|
101
|
+
cell: (u) => (_jsxs("span", { className: "flex items-center gap-3", children: [_jsx(Avatar, { name: userName(u), url: u.details?.photo?.url }), _jsx("span", { className: "font-medium", children: userName(u) }), u.status !== users.UserStatusActive && _jsx(Status, { user: u })] })),
|
|
102
|
+
},
|
|
103
|
+
...(canReadRoles
|
|
104
|
+
? [
|
|
105
|
+
{
|
|
106
|
+
header: "Role",
|
|
107
|
+
text: (u) => (u.roles ?? []).join(" "),
|
|
108
|
+
cell: (u) => (_jsx("span", { className: "flex flex-wrap gap-1.5", children: (u.roles ?? []).map((r) => (_jsx(Badge, { tone: roleTone(r), children: humanize(r) }, r))) })),
|
|
109
|
+
},
|
|
110
|
+
]
|
|
111
|
+
: []),
|
|
112
|
+
{
|
|
113
|
+
header: "Phone",
|
|
114
|
+
cell: (u) => u.phone ?? "—",
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
header: "Email",
|
|
118
|
+
cell: (u) => u.email ?? "—",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
header: "Joined",
|
|
122
|
+
// Role tabs list members in the order they got the role.
|
|
123
|
+
sortKey: byRole ? undefined : "created_at",
|
|
124
|
+
cell: (u) => formatDate(u.created_at),
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
header: "Actions",
|
|
128
|
+
text: () => "",
|
|
129
|
+
cell: (u) => (_jsx(UserRowMenu, { user: u, onView: () => show(u), onChange: () => setReload((n) => n + 1) })),
|
|
130
|
+
},
|
|
131
|
+
] })] }));
|
|
132
|
+
}
|
|
133
|
+
function UserPanel({ user: row, onClose }) {
|
|
134
|
+
const canReadRoles = useCan(rbac.PermissionRead);
|
|
135
|
+
// The list's row first, then the user as GET /v1/users/{id} has them
|
|
136
|
+
// now, and as each action returns them.
|
|
137
|
+
const [u, setUser] = useState(row);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
api
|
|
140
|
+
.get(`/v1/users/${row.uid}`)
|
|
141
|
+
.then(setUser)
|
|
142
|
+
.catch(() => undefined);
|
|
143
|
+
}, [row.uid]);
|
|
144
|
+
return (_jsxs("section", { className: "grid animate-fade-in gap-6 rounded-2xl border border-gray-200 bg-white p-6 md:grid-cols-2 dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsxs("div", { children: [_jsxs("div", { className: "mb-5 flex items-start justify-between gap-3", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-4", children: [_jsx(Avatar, { name: userName(u), url: u.details?.photo?.url, className: "size-14 text-lg" }), _jsxs("div", { className: "min-w-0", children: [_jsx("h2", { className: "truncate text-lg font-medium text-gray-800 dark:text-white/90", children: userName(u) }), _jsx("p", { className: "truncate text-sm text-gray-500 dark:text-gray-400", children: u.email ?? u.phone ?? u.uid })] })] }), _jsx("button", { type: "button", onClick: onClose, className: "text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400", children: "Close" })] }), _jsxs("dl", { className: "grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 text-sm", children: [_jsx(Row, { label: "User ID", children: _jsx("span", { className: "font-mono text-xs", children: u.uid }) }), _jsx(Row, { label: "Status", children: _jsx(Status, { user: u }) }), _jsx(Row, { label: "Email", children: verified(u.email, u.is_email_verified) }), _jsx(Row, { label: "Phone", children: verified(u.phone, u.is_phone_verified) }), _jsx(Row, { label: "Contact email", children: verified(u.contact_email, u.is_contact_email_verified) }), _jsx(Row, { label: "Contact phone", children: verified(u.contact_phone, u.is_contact_phone_verified) }), _jsx(Row, { label: "Country", children: u.country_code ?? "—" }), _jsxs(Row, { label: "Signs in with", children: [u.auth_method, u.has_password ? ", has a password" : ""] }), _jsx(Row, { label: "Two-factor", children: u.mfa_enabled ? "on" : "off" }), _jsx(Row, { label: "Last sign-in", children: u.last_login_at === undefined ? "never" : formatDateTime(u.last_login_at) })] })] }), _jsxs("div", { className: "space-y-6", children: [_jsx(UserActions, { user: u, onChange: setUser }), canReadRoles && (_jsxs("div", { children: [_jsx("h3", { className: "mb-3 font-medium text-gray-800 dark:text-white/90", children: "Roles" }), _jsx(UserRoles, { userId: u.uid })] })), _jsx(UserSessions, { userId: u.uid })] })] }));
|
|
145
|
+
}
|
|
146
|
+
function Status({ user: u }) {
|
|
147
|
+
const locked = u.locked_until !== undefined && Date.parse(u.locked_until) > Date.now();
|
|
148
|
+
return (_jsx(Badge, { tone: u.status === users.UserStatusActive && !locked ? "green" : "red", children: locked ? `locked until ${new Date(u.locked_until ?? "").toLocaleTimeString()}` : u.status }));
|
|
149
|
+
}
|
|
150
|
+
function verified(value, ok) {
|
|
151
|
+
if (value === undefined || value === "") {
|
|
152
|
+
return "—";
|
|
153
|
+
}
|
|
154
|
+
return (_jsxs(_Fragment, { children: [value, " ", _jsx("span", { className: "text-xs text-gray-500", children: ok ? "verified" : "not verified" })] }));
|
|
155
|
+
}
|
|
156
|
+
function Row({ label, children }) {
|
|
157
|
+
return (_jsxs(_Fragment, { children: [_jsx("dt", { className: "text-gray-500 dark:text-gray-400", children: label }), _jsx("dd", { className: "text-gray-800 dark:text-white/90", children: children })] }));
|
|
158
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function WebhooksPage(): import("react").JSX.Element;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
// Incoming webhook events: what each provider sent, whether it was handled,
|
|
4
|
+
// and a replay for one that failed (only a failed one can be).
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { Cancelled, useAction } from "../actions";
|
|
7
|
+
import * as webhooks from "../api/webhooks.gen";
|
|
8
|
+
import { api } from "../client";
|
|
9
|
+
import { formatDateTime } from "../dates";
|
|
10
|
+
import { PageHeader } from "../kit/page-header";
|
|
11
|
+
import { useCan } from "../shell";
|
|
12
|
+
import { DataTable } from "../table";
|
|
13
|
+
const input = "w-full rounded-lg border border-gray-300 bg-transparent px-3 py-2 text-sm text-gray-800 focus:border-brand-300 focus:outline-none dark:border-gray-700 dark:text-white/90";
|
|
14
|
+
const STATUS = {
|
|
15
|
+
pending: "bg-gray-100 text-gray-600 dark:bg-white/5 dark:text-gray-400",
|
|
16
|
+
processed: "bg-green-50 text-green-700 dark:bg-green-500/15 dark:text-green-500",
|
|
17
|
+
failed: "bg-red-50 text-red-600 dark:bg-red-500/15 dark:text-red-500",
|
|
18
|
+
};
|
|
19
|
+
export default function WebhooksPage() {
|
|
20
|
+
const [query, setQuery] = useState({});
|
|
21
|
+
// Bumped after a replay, to load the page again.
|
|
22
|
+
const [reload, setReload] = useState(0);
|
|
23
|
+
const [error, setError] = useState("");
|
|
24
|
+
const canReplay = useCan(webhooks.PermissionReplay);
|
|
25
|
+
const { run, dialogs } = useAction();
|
|
26
|
+
const apply = (event) => {
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
const f = new FormData(event.currentTarget);
|
|
29
|
+
setQuery({
|
|
30
|
+
status: String(f.get("status")) || undefined,
|
|
31
|
+
provider: String(f.get("provider")).trim() || undefined,
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const replay = async (e) => {
|
|
35
|
+
setError("");
|
|
36
|
+
try {
|
|
37
|
+
await run((o) => api.post(`/v1/webhook-events/${e.id}/replay`, undefined, o));
|
|
38
|
+
setReload((n) => n + 1);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (!(err instanceof Cancelled)) {
|
|
42
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsx(PageHeader, { title: "Webhook events" }), _jsxs("form", { onSubmit: apply, className: "flex flex-wrap items-end gap-3 rounded-2xl border border-gray-200 bg-white p-4 dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsxs("div", { className: "w-44", children: [_jsx("label", { htmlFor: "webhooks-status", className: "mb-1 block text-xs text-gray-500", children: "Status" }), _jsxs("select", { id: "webhooks-status", name: "status", className: input, children: [_jsx("option", { value: "", children: "Any" }), _jsx("option", { value: webhooks.StatusFailed, children: "Failed" }), _jsx("option", { value: webhooks.StatusPending, children: "Pending" }), _jsx("option", { value: webhooks.StatusProcessed, children: "Processed" })] })] }), _jsxs("div", { className: "w-56", children: [_jsx("label", { htmlFor: "webhooks-provider", className: "mb-1 block text-xs text-gray-500", children: "Provider" }), _jsx("input", { id: "webhooks-provider", name: "provider", placeholder: "paystack", className: input })] }), _jsx("button", { type: "submit", className: "h-10 rounded-lg bg-brand-500 px-4 text-sm font-medium text-white hover:bg-brand-600", children: "Filter" })] }), error !== "" && _jsx("p", { className: "text-sm text-red-600", children: error }), _jsx(DataTable, { path: "/v1/webhook-events", query: query, reload: reload, empty: "No events match.", columns: [
|
|
47
|
+
{ header: "Received", cell: (e) => formatDateTime(e.received_at) },
|
|
48
|
+
{
|
|
49
|
+
header: "Provider",
|
|
50
|
+
cell: (e) => (_jsxs(_Fragment, { children: [e.provider, e.account !== undefined && e.account !== "" && (_jsx("span", { className: "block text-xs text-gray-500", children: e.account }))] })),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
header: "Event",
|
|
54
|
+
cell: (e) => (_jsxs(_Fragment, { children: [_jsx("span", { className: "font-mono text-xs", children: e.type }), _jsx("span", { className: "block font-mono text-xs text-gray-500", children: e.event_id })] })),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
header: "Status",
|
|
58
|
+
cell: (e) => (_jsxs(_Fragment, { children: [_jsx("span", { className: `rounded-full px-2 py-0.5 text-xs ${STATUS[e.status] ?? ""}`, children: e.status }), _jsxs("span", { className: "ml-2 text-xs text-gray-500", children: [e.attempts, " ", e.attempts === 1 ? "try" : "tries"] }), e.last_error && (_jsx("span", { className: "mt-1 block max-w-xs text-xs text-red-600", children: e.last_error }))] })),
|
|
59
|
+
},
|
|
60
|
+
{ header: "Payload", cell: (e) => _jsx(Payload, { id: e.id }) },
|
|
61
|
+
{
|
|
62
|
+
header: "",
|
|
63
|
+
cell: (e) => canReplay &&
|
|
64
|
+
e.status === webhooks.StatusFailed && (_jsx("button", { type: "button", onClick: () => replay(e), className: "rounded-lg border border-gray-300 px-3 py-1.5 text-xs text-gray-700 hover:bg-gray-50 dark:border-gray-700 dark:text-gray-300", children: "Replay" })),
|
|
65
|
+
},
|
|
66
|
+
] }), dialogs] }));
|
|
67
|
+
}
|
|
68
|
+
/** The raw body the provider sent, loaded when opened (the list leaves it out). */
|
|
69
|
+
function Payload({ id }) {
|
|
70
|
+
const [payload, setPayload] = useState(null);
|
|
71
|
+
const load = (open) => {
|
|
72
|
+
if (open && payload === null) {
|
|
73
|
+
api
|
|
74
|
+
.get(`/v1/webhook-events/${id}`)
|
|
75
|
+
.then((e) => setPayload(pretty(e.payload ?? "")))
|
|
76
|
+
.catch((err) => setPayload(err.message));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return (_jsxs("details", { onToggle: (e) => load(e.currentTarget.open), children: [_jsx("summary", { className: "cursor-pointer text-brand-500", children: "Show" }), _jsx("pre", { className: "mt-2 max-h-80 max-w-md overflow-auto rounded-lg bg-gray-50 p-3 text-xs dark:bg-gray-900", children: payload ?? "Loading…" })] }));
|
|
80
|
+
}
|
|
81
|
+
function pretty(raw) {
|
|
82
|
+
try {
|
|
83
|
+
return JSON.stringify(JSON.parse(raw), null, 2);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return raw;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Permissions as checkboxes, grouped by module (/v1/rbac/modules). A
|
|
4
|
+
// deprecated permission (no module declares it now) is shown only while
|
|
5
|
+
// it is still ticked, so it can be taken away.
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import { api } from "./client";
|
|
8
|
+
import { Alert } from "./ui";
|
|
9
|
+
export function PermissionPicker(props) {
|
|
10
|
+
const { value, onChange, disabled } = props;
|
|
11
|
+
const [modules, setModules] = useState(null);
|
|
12
|
+
const [error, setError] = useState("");
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
// Small by design (one row per module): not paged.
|
|
15
|
+
api
|
|
16
|
+
.get("/v1/rbac/modules")
|
|
17
|
+
.then(setModules)
|
|
18
|
+
.catch((err) => setError(err.message));
|
|
19
|
+
}, []);
|
|
20
|
+
const toggle = (key, on) => onChange(on ? [...value, key] : value.filter((k) => k !== key));
|
|
21
|
+
if (error !== "") {
|
|
22
|
+
return _jsx(Alert, { children: error });
|
|
23
|
+
}
|
|
24
|
+
return (_jsx("div", { className: "grid gap-4 md:grid-cols-2", children: modules?.map((m) => {
|
|
25
|
+
const shown = m.permissions.filter((p) => !p.deprecated || value.includes(p.key));
|
|
26
|
+
if (shown.length === 0) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return (_jsxs("fieldset", { className: "rounded-xl border border-gray-200 p-4 dark:border-gray-800", children: [_jsxs("legend", { className: "px-1 text-sm font-medium text-gray-800 capitalize dark:text-white/90", children: [m.name.replaceAll("_", " "), !m.enabled && _jsx("span", { className: "ml-2 text-xs text-gray-500", children: "(off)" })] }), _jsx("div", { className: "space-y-2", children: shown.map((p) => (_jsxs("label", { className: "flex items-start gap-2 text-sm", children: [_jsx("input", { type: "checkbox", checked: value.includes(p.key), disabled: disabled, onChange: (e) => toggle(p.key, e.target.checked), className: "mt-0.5 size-4 rounded border-gray-300 text-brand-500" }), _jsxs("span", { children: [_jsx("span", { className: "font-mono text-gray-800 dark:text-white/90", children: p.key }), p.deprecated && (_jsx("span", { className: "ml-1 text-xs text-red-600", children: "no longer used" })), _jsx("span", { className: "block text-gray-500 dark:text-gray-400", children: p.description })] })] }, p.key))) })] }, m.name));
|
|
30
|
+
}) }));
|
|
31
|
+
}
|
package/dist/proof.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type Proof = Record<string, string>;
|
|
2
|
+
export interface ProofFormProps {
|
|
3
|
+
/** The methods the API offers; those this form can't take are left out. */
|
|
4
|
+
methods: string[];
|
|
5
|
+
/** Sends an email or phone code and returns its verification ID. */
|
|
6
|
+
sendCode(channel: "email" | "phone"): Promise<string>;
|
|
7
|
+
/** Takes the finished proof ({ method, code }, ...). Throws to show an error. */
|
|
8
|
+
submit(proof: Proof): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare function ProofForm({ methods, sendCode, submit }: ProofFormProps): import("react").JSX.Element;
|
package/dist/proof.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// "Confirm it's you": picks a method, sends a code when the method needs
|
|
4
|
+
// one, and builds the proof the API takes (reauth Proof). Used by the
|
|
5
|
+
// sign-in page's second factor and by <StepUp>.
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { call } from "./client";
|
|
8
|
+
import { Alert, Button, CodeInput, Field } from "./ui";
|
|
9
|
+
// The methods a form can take. Biometric needs the user's device.
|
|
10
|
+
const LABELS = {
|
|
11
|
+
password: "Your password",
|
|
12
|
+
totp: "Code from your authenticator app",
|
|
13
|
+
email_code: "Code sent to your email",
|
|
14
|
+
phone_code: "Code sent to your phone",
|
|
15
|
+
auth_pin: "Your PIN",
|
|
16
|
+
transaction_pin: "Your transaction PIN",
|
|
17
|
+
recovery_code: "A recovery code",
|
|
18
|
+
};
|
|
19
|
+
// The proof field each method fills (docs/two-factor.md).
|
|
20
|
+
const FIELDS = {
|
|
21
|
+
password: "password",
|
|
22
|
+
auth_pin: "pin",
|
|
23
|
+
transaction_pin: "pin",
|
|
24
|
+
recovery_code: "recovery_code",
|
|
25
|
+
};
|
|
26
|
+
export function ProofForm({ methods, sendCode, submit }) {
|
|
27
|
+
const usable = methods.filter((m) => m in LABELS);
|
|
28
|
+
const [method, setMethod] = useState(usable.length === 1 ? usable[0] : "");
|
|
29
|
+
const [verificationId, setVerificationId] = useState("");
|
|
30
|
+
const [error, setError] = useState("");
|
|
31
|
+
const [busy, setBusy] = useState(false);
|
|
32
|
+
const [code, setCode] = useState("");
|
|
33
|
+
const attempt = async (fn) => {
|
|
34
|
+
setError("");
|
|
35
|
+
setBusy(true);
|
|
36
|
+
try {
|
|
37
|
+
await fn();
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
setBusy(false);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const choose = (m) => attempt(async () => {
|
|
47
|
+
setVerificationId(m === "email_code" || m === "phone_code"
|
|
48
|
+
? await sendCode(m === "email_code" ? "email" : "phone")
|
|
49
|
+
: "");
|
|
50
|
+
setMethod(m);
|
|
51
|
+
});
|
|
52
|
+
if (usable.length === 0) {
|
|
53
|
+
return _jsx(Alert, { children: "None of this account's ways to confirm it can be used here." });
|
|
54
|
+
}
|
|
55
|
+
if (method === "") {
|
|
56
|
+
return (_jsxs("div", { className: "space-y-2", children: [error !== "" && _jsx(Alert, { children: error }), usable.map((m) => (_jsx("button", { type: "button", disabled: busy, onClick: () => choose(m), className: "w-full rounded-lg border border-gray-300 px-4 py-3 text-left text-sm hover:bg-gray-50 dark:border-gray-700 dark:hover:bg-white/5", children: LABELS[m] }, m)))] }));
|
|
57
|
+
}
|
|
58
|
+
const field = FIELDS[method] ?? "code";
|
|
59
|
+
// A code (authenticator, email, phone) goes in one box per digit.
|
|
60
|
+
const boxes = field === "code";
|
|
61
|
+
const send = (value) => attempt(async () => {
|
|
62
|
+
if (verificationId !== "") {
|
|
63
|
+
const verified = await call("/v1/auth/verifications/verify", {
|
|
64
|
+
body: { verification_id: verificationId, code: value },
|
|
65
|
+
});
|
|
66
|
+
return submit({ method, verification_token: verified.data.verification_token });
|
|
67
|
+
}
|
|
68
|
+
return submit({ method, [field]: value });
|
|
69
|
+
});
|
|
70
|
+
const onSubmit = (event) => {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
send(boxes ? code : String(new FormData(event.currentTarget).get("proof")));
|
|
73
|
+
};
|
|
74
|
+
return (_jsxs("form", { className: "animate-slide-in space-y-4", onSubmit: onSubmit, children: [error !== "" && _jsx(Alert, { children: error }), boxes ? (_jsxs("div", { className: "space-y-2", children: [_jsx("p", { className: "text-sm text-gray-700 dark:text-gray-400", children: LABELS[method] }), _jsx(CodeInput, { value: code, onChange: setCode, onComplete: send, disabled: busy })] })) : (_jsx(Field, { label: LABELS[method], name: "proof", type: field === "pin" || field === "password" ? "password" : "text", autoComplete: field === "password" ? "current-password" : "one-time-code" })), _jsx(Button, { type: "submit", busy: busy, children: "Continue" }), usable.length > 1 && (_jsx(Button, { quiet: true, onClick: () => {
|
|
75
|
+
setMethod("");
|
|
76
|
+
setCode("");
|
|
77
|
+
}, children: "Use another way" }))] }));
|
|
78
|
+
}
|
package/dist/proxy.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface ProxyOptions {
|
|
2
|
+
/** The API's base URL. Default: the COLVEOR_API_URL environment variable. */
|
|
3
|
+
apiUrl?: string;
|
|
4
|
+
/** Where the proxy is mounted. Default: /api/colveor. */
|
|
5
|
+
prefix?: string;
|
|
6
|
+
}
|
|
7
|
+
/** A Next route handler for every method: export { handler as GET, ... }. */
|
|
8
|
+
export declare function createProxy(options?: ProxyOptions): (req: Request) => Promise<Response>;
|
|
9
|
+
/** The proxy with the default options. */
|
|
10
|
+
export declare const handler: (req: Request) => Promise<Response>;
|