@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,15 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // A dialog over the page: a title, a close button, the content and an
4
+ // optional footer of buttons. Escape closes it. size "xl" is wide, for an
5
+ // editor with a preview beside it.
6
+ import { useEffect } from "react";
7
+ export function Modal(props) {
8
+ const { onClose } = props;
9
+ useEffect(() => {
10
+ const onKey = (e) => e.key === "Escape" && onClose();
11
+ document.addEventListener("keydown", onKey);
12
+ return () => document.removeEventListener("keydown", onKey);
13
+ }, [onClose]);
14
+ return (_jsx("div", { role: "dialog", "aria-modal": "true", className: "fixed inset-0 z-[100] flex animate-fade-in items-center justify-center bg-gray-900/50 p-4 backdrop-blur-sm", children: _jsxs("div", { className: `flex max-h-[calc(100vh-2rem)] w-full animate-pop-in flex-col rounded-2xl border border-gray-200 bg-white shadow-xl dark:border-gray-800 dark:bg-gray-900 ${props.size === "xl" ? "max-w-6xl" : "max-w-md"}`, children: [_jsxs("div", { className: "flex items-center justify-between gap-4 border-b border-gray-100 px-6 py-4 dark:border-gray-800", children: [_jsx("h2", { className: "text-lg font-medium text-gray-800 dark:text-white/90", children: props.title }), _jsx("button", { type: "button", "aria-label": "Close", onClick: onClose, className: "flex size-9 items-center justify-center rounded-full text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-800 dark:text-gray-400 dark:hover:bg-white/5", children: _jsx("svg", { width: 18, height: 18, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M6 6l12 12M18 6L6 18", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round" }) }) })] }), _jsx("div", { className: "min-h-0 flex-1 overflow-y-auto p-6", children: props.children }), props.footer && (_jsx("div", { className: "flex justify-end gap-3 border-t border-gray-100 px-6 py-4 dark:border-gray-800", children: props.footer }))] }) }));
15
+ }
@@ -0,0 +1,13 @@
1
+ import type { ReactNode } from "react";
2
+ export interface Crumb {
3
+ label: string;
4
+ /** A crumb with no href is the current page. */
5
+ href?: string;
6
+ }
7
+ export declare function PageHeader(props: {
8
+ title: string;
9
+ /** Between Home and the page: [{ label: "Users", href: "/users" }]. */
10
+ crumbs?: Crumb[];
11
+ /** Buttons on the right. */
12
+ actions?: ReactNode;
13
+ }): import("react").JSX.Element;
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useConfig } from "../shell";
4
+ export function PageHeader(props) {
5
+ const { router } = useConfig();
6
+ const { Link } = router;
7
+ const trail = [
8
+ { label: "Home", href: "/" },
9
+ ...(props.crumbs ?? []),
10
+ { label: props.title },
11
+ ];
12
+ return (_jsxs("div", { className: "mb-6 flex animate-fade-in flex-wrap items-center justify-between gap-4 rounded-2xl bg-brand-50 px-6 py-5 dark:bg-brand-500/10", children: [_jsxs("div", { children: [_jsx("h1", { className: "text-xl font-medium text-gray-800 dark:text-white/90", children: props.title }), _jsx("nav", { "aria-label": "Breadcrumb", className: "mt-1.5", children: _jsx("ol", { className: "flex flex-wrap items-center gap-2 text-sm", children: trail.map((c, i) => (_jsxs("li", { className: "flex items-center gap-2", children: [i > 0 && _jsx("span", { className: "size-1 rounded-full bg-gray-400", "aria-hidden": "true" }), c.href !== undefined && i < trail.length - 1 ? (_jsx(Link, { href: c.href, className: "text-gray-500 transition-colors hover:text-brand-500 dark:text-gray-400", children: c.label })) : (_jsx("span", { className: "text-brand-500", "aria-current": "page", children: c.label }))] }, `${c.label}-${i}`))) }) })] }), props.actions && _jsx("div", { className: "flex items-center gap-3", children: props.actions })] }));
13
+ }
@@ -0,0 +1,4 @@
1
+ export declare function SearchToggle(props: {
2
+ placeholder?: string;
3
+ onSearch(text: string): void;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // A search icon for a card's header that opens into a box; Enter searches,
4
+ // clearing it shows everything again.
5
+ import { useState } from "react";
6
+ import { iconButton } from "./dropdown";
7
+ export function SearchToggle(props) {
8
+ const [open, setOpen] = useState(false);
9
+ const submit = (event) => {
10
+ event.preventDefault();
11
+ props.onSearch(String(new FormData(event.currentTarget).get("q")).trim());
12
+ };
13
+ return (_jsxs("form", { onSubmit: submit, className: "flex items-center", children: [open && (_jsx("input", { name: "q", type: "search",
14
+ // biome-ignore lint/a11y/noAutofocus: opened by the user to type
15
+ autoFocus: true, "aria-label": props.placeholder ?? "Search", placeholder: props.placeholder ?? "Search", onChange: (e) => e.target.value === "" && props.onSearch(""), className: "w-64 animate-slide-in 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" })), _jsx("button", { type: open ? "submit" : "button", "aria-label": "Search", title: "Search", onClick: () => !open && setOpen(true), className: iconButton, children: _jsxs("svg", { width: 20, height: 20, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: [_jsx("circle", { cx: 11, cy: 11, r: 7, stroke: "currentColor", strokeWidth: 1.8 }), _jsx("path", { d: "M20 20l-3.5-3.5", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round" })] }) })] }));
16
+ }
@@ -0,0 +1,17 @@
1
+ import { type ReactNode } from "react";
2
+ export declare function Tooltip(props: {
3
+ /** What the tip says. */
4
+ tip: ReactNode;
5
+ /** The trigger's content: an icon, a word. */
6
+ children: ReactNode;
7
+ /** The trigger's name for screen readers. */
8
+ label: string;
9
+ /** The trigger's classes. */
10
+ className?: string;
11
+ }): import("react").JSX.Element;
12
+ /** A "?" in a circle whose tip explains what it sits beside. */
13
+ export declare function InfoTip(props: {
14
+ children: ReactNode;
15
+ label?: string;
16
+ className?: string;
17
+ }): import("react").JSX.Element;
@@ -0,0 +1,52 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // A tip shown when its trigger is clicked, and hidden on a click outside,
4
+ // Escape, a scroll, or when focus moves away. It is drawn at the top of the
5
+ // page (a portal), so no list that scrolls, and no moving parent, can clip
6
+ // or shift it. InfoTip is the "?" version.
7
+ import { useEffect, useRef, useState } from "react";
8
+ import { createPortal } from "react-dom";
9
+ export function Tooltip(props) {
10
+ const [place, setPlace] = useState(null);
11
+ const ref = useRef(null);
12
+ useEffect(() => {
13
+ if (place === null) {
14
+ return;
15
+ }
16
+ const hide = () => setPlace(null);
17
+ const outside = (e) => {
18
+ if (!ref.current?.contains(e.target)) {
19
+ hide();
20
+ }
21
+ };
22
+ const onKey = (e) => e.key === "Escape" && hide();
23
+ document.addEventListener("mousedown", outside);
24
+ document.addEventListener("keydown", onKey);
25
+ window.addEventListener("scroll", hide, true);
26
+ window.addEventListener("resize", hide);
27
+ return () => {
28
+ document.removeEventListener("mousedown", outside);
29
+ document.removeEventListener("keydown", onKey);
30
+ window.removeEventListener("scroll", hide, true);
31
+ window.removeEventListener("resize", hide);
32
+ };
33
+ }, [place]);
34
+ const toggle = () => {
35
+ const box = ref.current?.getBoundingClientRect();
36
+ if (place !== null || box === undefined) {
37
+ setPlace(null);
38
+ return;
39
+ }
40
+ // Beside the trigger when there is room on the right, else under it.
41
+ setPlace(box.right + 300 < window.innerWidth
42
+ ? { left: box.right + 10, top: Math.max(8, box.top - 8) }
43
+ : { right: Math.max(8, window.innerWidth - box.right), top: box.bottom + 8 });
44
+ };
45
+ return (_jsxs(_Fragment, { children: [_jsx("button", { ref: ref, type: "button", "aria-label": props.label, "aria-expanded": place !== null, onClick: toggle, onBlur: () => setPlace(null), className: props.className, children: props.children }), place !== null &&
46
+ createPortal(_jsx("span", { role: "tooltip", style: place, className: "fixed z-[999] w-72 animate-pop-in rounded-xl bg-gray-900 px-4 py-3 text-xs leading-relaxed text-white shadow-lg dark:bg-gray-700", children: props.tip }), document.body)] }));
47
+ }
48
+ /** A "?" in a circle whose tip explains what it sits beside. */
49
+ export function InfoTip(props) {
50
+ return (_jsx(Tooltip, { tip: props.children, label: props.label ?? "More about this", className: `flex size-5 shrink-0 items-center justify-center rounded-full border text-[11px] font-medium transition-colors ${props.className ??
51
+ "border-gray-300 text-gray-500 hover:border-brand-500 hover:text-brand-500 dark:border-gray-600 dark:text-gray-400"}`, children: "?" }));
52
+ }
@@ -0,0 +1,9 @@
1
+ import type * as settings from "./api/settings.gen";
2
+ type Setting = settings.SettingResponse;
3
+ export declare function MessageEditor(props: {
4
+ setting: Setting;
5
+ editable: boolean;
6
+ onSaved(s: Setting): void;
7
+ onClose(): void;
8
+ }): import("react").JSX.Element;
9
+ export {};
@@ -0,0 +1,80 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ // The editor of a message setting (a verification code, a notice, an
4
+ // invitation): the email's subject, text and HTML, and the SMS, beside a
5
+ // preview the API renders with sample data as you type
6
+ // (POST /v1/settings/{key}/preview). Saving goes through the usual PATCH,
7
+ // which checks the templates again and refuses a broken one.
8
+ import { useEffect, useState } from "react";
9
+ import { Cancelled, useAction } from "./actions";
10
+ import { api } from "./client";
11
+ import { CodeArea } from "./kit/code-area";
12
+ import { FilterTabs } from "./kit/filter-tabs";
13
+ import { Modal } from "./kit/modal";
14
+ import { InfoTip } from "./kit/tooltip";
15
+ export function MessageEditor(props) {
16
+ const { setting: s, editable } = props;
17
+ const [draft, setDraft] = useState(() => read(s.value));
18
+ const [preview, setPreview] = useState(null);
19
+ const [shown, setShown] = useState(0);
20
+ const [asText, setAsText] = useState(false);
21
+ const [error, setError] = useState("");
22
+ const [busy, setBusy] = useState(false);
23
+ const { run, dialogs } = useAction();
24
+ const value = JSON.stringify(draft);
25
+ // The preview follows the typing, a moment after it stops.
26
+ useEffect(() => {
27
+ const timer = setTimeout(() => {
28
+ api
29
+ .post(`/v1/settings/${encodeURIComponent(s.key)}/preview`, {
30
+ value: JSON.parse(value),
31
+ })
32
+ .then(setPreview)
33
+ .catch((err) => setPreview({ rendered: [], problem: err.message }));
34
+ }, 400);
35
+ return () => clearTimeout(timer);
36
+ }, [s.key, value]);
37
+ const email = (part, v) => setDraft({ ...draft, email: { ...draft.email, [part]: v } });
38
+ const save = async () => {
39
+ setError("");
40
+ setBusy(true);
41
+ try {
42
+ props.onSaved(await run((o) => api.patch(`/v1/settings/${encodeURIComponent(s.key)}`, { value: JSON.parse(value) }, o)));
43
+ props.onClose();
44
+ }
45
+ catch (err) {
46
+ if (!(err instanceof Cancelled)) {
47
+ setError(err instanceof Error ? err.message : String(err));
48
+ }
49
+ }
50
+ finally {
51
+ setBusy(false);
52
+ }
53
+ };
54
+ const rendered = preview?.rendered ?? [];
55
+ const current = rendered[Math.min(shown, rendered.length - 1)];
56
+ return (_jsxs(Modal, { size: "xl", onClose: props.onClose, title: _jsxs("span", { className: "flex items-center gap-2", children: [(s.key.split(".").pop() ?? s.key).replaceAll("_", " "), " message", _jsx(InfoTip, { label: "Variables you can use", children: s.description })] }), footer: _jsxs(_Fragment, { children: [_jsx("button", { type: "button", onClick: props.onClose, className: "rounded-lg border border-gray-300 px-4 py-2 text-sm text-gray-700 hover:bg-gray-50 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-white/5", children: editable ? "Cancel" : "Close" }), editable && (_jsx("button", { type: "button", disabled: busy || value === JSON.stringify(read(s.value)), onClick: save, className: "rounded-lg bg-brand-500 px-5 py-2 text-sm font-medium text-white hover:bg-brand-600 disabled:opacity-40", children: "Save" }))] }), children: [_jsxs("div", { className: "grid gap-6 lg:grid-cols-2", children: [_jsxs("div", { className: "space-y-4", children: [_jsx(Part, { label: "Email subject", children: _jsx(CodeArea, { singleLine: true, lang: "template", label: "Email subject", value: draft.email.subject, disabled: !editable, onChange: (v) => email("subject", v) }) }), _jsx(Part, { label: "Email HTML", hint: "Optional. Most inboxes show this; leave it empty to send text only.", children: _jsx(CodeArea, { rows: 12, label: "Email HTML", value: draft.email.html, disabled: !editable, onChange: (v) => email("html", v) }) }), _jsx(Part, { label: "Email text", hint: "Required: shown by inboxes that don't show HTML.", children: _jsx(CodeArea, { rows: 7, lang: "template", label: "Email text", value: draft.email.text, disabled: !editable, onChange: (v) => email("text", v) }) }), _jsx(Part, { label: "SMS", hint: `${draft.sms.length} characters; an SMS holds about 160.`, children: _jsx(CodeArea, { rows: 3, lang: "template", label: "SMS", value: draft.sms, disabled: !editable, onChange: (v) => setDraft({ ...draft, sms: v }) }) })] }), _jsxs("div", { className: "space-y-3 lg:sticky lg:top-0 lg:self-start", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsx("p", { className: "text-sm font-medium text-gray-700 dark:text-gray-300", children: "Preview" }), rendered.length > 0 && (_jsx(FilterTabs, { value: String(Math.min(shown, rendered.length - 1)), onChange: (k) => setShown(Number(k)), tabs: rendered.map((r, i) => ({ key: String(i), label: r.name })) }))] }), error !== "" && (_jsx("p", { className: "rounded-lg bg-red-50 px-4 py-3 text-sm text-red-600", children: error })), preview?.problem && (_jsxs("p", { className: "rounded-lg bg-amber-50 px-4 py-3 text-sm text-amber-800 dark:bg-amber-500/10 dark:text-amber-400", children: ["It can't be saved like this: ", preview.problem] })), current !== undefined && (_jsx(Rendered, { message: current, asText: asText, onAsText: setAsText })), _jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: "Shown with sample values (app \"Example\", code 246810)." })] })] }), dialogs] }));
57
+ }
58
+ function Rendered(props) {
59
+ const m = props.message;
60
+ if (m.sms) {
61
+ return (_jsx("div", { className: "rounded-2xl bg-gray-100 p-4 dark:bg-white/5", children: _jsx("p", { className: "max-w-xs rounded-2xl rounded-bl-sm bg-white px-4 py-3 text-sm whitespace-pre-wrap text-gray-800 shadow-sm dark:bg-gray-800 dark:text-white/90", children: m.sms }) }));
62
+ }
63
+ const html = m.html && !props.asText;
64
+ return (_jsxs("div", { className: "overflow-hidden rounded-xl border border-gray-200 dark:border-gray-800", children: [_jsxs("div", { className: "flex items-center justify-between gap-3 border-b border-gray-200 bg-gray-50 px-4 py-2.5 dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsx("p", { className: "truncate text-sm font-medium text-gray-800 dark:text-white/90", children: m.subject }), m.html && (_jsx("button", { type: "button", onClick: () => props.onAsText(!props.asText), className: "shrink-0 text-xs text-brand-500 hover:text-brand-600", children: props.asText ? "Show HTML" : "Show text" }))] }), html ? (
65
+ // No scripts or links run in it: a sandbox with nothing allowed.
66
+ _jsx("iframe", { title: "Email preview", sandbox: "", srcDoc: m.html, className: "h-96 w-full bg-white" })) : (_jsx("pre", { className: "h-96 overflow-auto p-4 font-sans text-sm whitespace-pre-wrap text-gray-800 dark:text-white/90", children: m.text }))] }));
67
+ }
68
+ function Part(props) {
69
+ return (
70
+ // biome-ignore lint/a11y/noLabelWithoutControl: the control is the child
71
+ _jsxs("label", { className: "block", children: [_jsx("span", { className: "mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300", children: props.label }), props.children, props.hint && (_jsx("span", { className: "mt-1 block text-xs text-gray-500 dark:text-gray-400", children: props.hint }))] }));
72
+ }
73
+ /** The stored value as a template, its missing parts empty. */
74
+ function read(value) {
75
+ const t = JSON.parse(value || "{}");
76
+ return {
77
+ email: { subject: "", text: "", html: "", ...t.email },
78
+ sms: t.sms ?? "",
79
+ };
80
+ }
@@ -0,0 +1,10 @@
1
+ export interface Money {
2
+ amount: number;
3
+ currency: string;
4
+ }
5
+ /**
6
+ * For showing only: the browser's currency data gives the decimals, and
7
+ * for a few currencies differs from the API's (pkg/platform/money). So
8
+ * amounts are sent in minor units, never converted from this.
9
+ */
10
+ export declare function formatMoney(m: Money): string;
package/dist/money.js ADDED
@@ -0,0 +1,17 @@
1
+ // Money as the API sends it: an amount in minor units (1250 is NGN 12.50)
2
+ // and an ISO 4217 currency.
3
+ /**
4
+ * For showing only: the browser's currency data gives the decimals, and
5
+ * for a few currencies differs from the API's (pkg/platform/money). So
6
+ * amounts are sent in minor units, never converted from this.
7
+ */
8
+ export function formatMoney(m) {
9
+ try {
10
+ const f = new Intl.NumberFormat(undefined, { style: "currency", currency: m.currency });
11
+ const digits = f.resolvedOptions().maximumFractionDigits ?? 2;
12
+ return f.format(m.amount / 10 ** digits);
13
+ }
14
+ catch {
15
+ return `${m.amount} ${m.currency} (minor units)`;
16
+ }
17
+ }
package/dist/next.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { type ReactNode } from "react";
2
+ import type { AdminConfig } from "./config";
3
+ export declare function NextAdmin({ config, children }: {
4
+ config: AdminConfig;
5
+ children: ReactNode;
6
+ }): import("react").JSX.Element;
package/dist/next.js ADDED
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ // The Next router adapter: with the proxy, the only part of the package
4
+ // that imports Next (docs/admin.md). The template's app/layout.tsx wraps
5
+ // the app in <NextAdmin config={config}>.
6
+ import Link from "next/link";
7
+ import { usePathname, useRouter } from "next/navigation";
8
+ import { useMemo } from "react";
9
+ import { ColveorAdmin } from "./shell";
10
+ export function NextAdmin({ config, children }) {
11
+ const pathname = usePathname();
12
+ const next = useRouter();
13
+ const router = useMemo(() => ({
14
+ pathname,
15
+ navigate: (href) => next.push(href),
16
+ Link,
17
+ }), [pathname, next]);
18
+ return (_jsx(ColveorAdmin, { config: config, router: router, children: children }));
19
+ }
@@ -0,0 +1 @@
1
+ export default function AccountPage(): import("react").JSX.Element;
@@ -0,0 +1,47 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Account settings (the user menu's "Account"): the signed-in admin's
4
+ // profile, password, two-step verification, devices and data.
5
+ import { useEffect, useState } from "react";
6
+ import { DataTab } from "../account/data";
7
+ import { PasswordTab, ProfileTab } from "../account/profile";
8
+ import { SessionsTab } from "../account/sessions";
9
+ import { TwoFactorTab } from "../account/two-factor";
10
+ import { api } from "../client";
11
+ import { ACCOUNT_TAB_EVENT } from "../header";
12
+ import { PageHeader } from "../kit/page-header";
13
+ import { Alert } from "../ui";
14
+ const TABS = [
15
+ ["profile", "Profile"],
16
+ ["password", "Password"],
17
+ ["two-factor", "Two-step verification"],
18
+ ["sessions", "Devices"],
19
+ ["data", "Your data"],
20
+ ];
21
+ export default function AccountPage() {
22
+ const [tab, setTab] = useState("profile");
23
+ // ?tab=, and the user menu's links while the page is open.
24
+ useEffect(() => {
25
+ const pick = (key) => {
26
+ if (TABS.some(([k]) => k === key)) {
27
+ setTab(key);
28
+ }
29
+ };
30
+ pick(new URLSearchParams(window.location.search).get("tab"));
31
+ const onTab = (e) => pick(e.detail);
32
+ window.addEventListener(ACCOUNT_TAB_EVENT, onTab);
33
+ return () => window.removeEventListener(ACCOUNT_TAB_EVENT, onTab);
34
+ }, []);
35
+ const [me, setMe] = useState(null);
36
+ const [error, setError] = useState("");
37
+ const load = () => api
38
+ .get("/v1/me")
39
+ .then(setMe)
40
+ .catch((err) => setError(err.message));
41
+ useEffect(() => {
42
+ load();
43
+ }, []);
44
+ return (_jsxs("div", { className: "space-y-6", children: [_jsx(PageHeader, { title: "Account settings" }), error !== "" && _jsx(Alert, { children: error }), _jsx("div", { className: "flex gap-6 overflow-x-auto border-b border-gray-200 dark:border-gray-800", children: TABS.map(([key, label]) => (_jsxs("button", { type: "button", onClick: () => setTab(key), className: `relative shrink-0 pb-3 text-sm font-medium transition-colors ${tab === key
45
+ ? "text-brand-500"
46
+ : "text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"}`, children: [label, _jsx("span", { className: `absolute inset-x-0 -bottom-px h-0.5 rounded-full bg-brand-500 transition-transform duration-200 ${tab === key ? "scale-x-100" : "scale-x-0"}` })] }, key))) }), me !== null && (_jsxs("div", { className: "animate-slide-in", children: [tab === "profile" && _jsx(ProfileTab, { me: me, onSaved: load }), tab === "password" && _jsx(PasswordTab, {}), tab === "two-factor" && _jsx(TwoFactorTab, { me: me, onSaved: load }), tab === "sessions" && _jsx(SessionsTab, {}), tab === "data" && _jsx(DataTab, {})] }, tab))] }));
47
+ }
@@ -0,0 +1 @@
1
+ export default function AuditPage(): 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
+ // The audit log: what users and admins did, newest first, with its
4
+ // filters, and the monthly archives. Reading it is recorded too.
5
+ import { useEffect, useState } from "react";
6
+ import { api } from "../client";
7
+ import { formatDateTime } from "../dates";
8
+ import { PageHeader } from "../kit/page-header";
9
+ import { DataTable } from "../table";
10
+ import { Alert } from "../ui";
11
+ 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";
12
+ export default function AuditPage() {
13
+ const [tab, setTab] = useState("events");
14
+ return (_jsxs("div", { className: "space-y-6", children: [_jsx(PageHeader, { title: "Audit log", actions: _jsx("div", { className: "flex gap-1 rounded-lg bg-gray-100 p-1 text-sm dark:bg-gray-800", children: ["events", "archives"].map((t) => (_jsx("button", { type: "button", onClick: () => setTab(t), className: `rounded-md px-3 py-1.5 capitalize ${tab === t
15
+ ? "bg-white text-gray-800 shadow-sm dark:bg-gray-900 dark:text-white/90"
16
+ : "text-gray-500 dark:text-gray-400"}`, children: t }, t))) }) }), tab === "events" ? _jsx(Events, {}) : _jsx(Archives, {})] }));
17
+ }
18
+ function Events() {
19
+ const [query, setQuery] = useState({});
20
+ const apply = (event) => {
21
+ event.preventDefault();
22
+ const f = new FormData(event.currentTarget);
23
+ const get = (k) => String(f.get(k) ?? "").trim() || undefined;
24
+ // datetime-local is the admin's local time: the API takes RFC 3339.
25
+ const at = (k) => {
26
+ const v = get(k);
27
+ return v === undefined ? undefined : new Date(v).toISOString();
28
+ };
29
+ setQuery({
30
+ action: get("action"),
31
+ outcome: get("outcome"),
32
+ actor_id: get("actor_id"),
33
+ target_type: get("target_type"),
34
+ target_id: get("target_id"),
35
+ from: at("from"),
36
+ to: at("to"),
37
+ });
38
+ };
39
+ return (_jsxs("div", { className: "space-y-4", children: [_jsxs("form", { onSubmit: apply, className: "grid gap-3 rounded-2xl border border-gray-200 bg-white p-4 md:grid-cols-4 dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsx(Filter, { label: "Action", name: "action", placeholder: "rbac.RoleCreated" }), _jsxs("div", { children: [_jsx("label", { htmlFor: "audit-outcome", className: "mb-1 block text-xs text-gray-500", children: "Outcome" }), _jsxs("select", { id: "audit-outcome", name: "outcome", className: input, children: [_jsx("option", { value: "", children: "Any" }), _jsx("option", { value: "success", children: "Success" }), _jsx("option", { value: "failure", children: "Failure" })] })] }), _jsx(Filter, { label: "Actor (user ID)", name: "actor_id" }), _jsx(Filter, { label: "Target type", name: "target_type", placeholder: "user" }), _jsx(Filter, { label: "Target ID", name: "target_id" }), _jsx(Filter, { label: "From", name: "from", type: "datetime-local" }), _jsx(Filter, { label: "Until", name: "to", type: "datetime-local" }), _jsxs("div", { className: "flex items-end gap-2", children: [_jsx("button", { type: "submit", className: "h-10 flex-1 rounded-lg bg-brand-500 text-sm font-medium text-white hover:bg-brand-600", children: "Filter" }), _jsx("button", { type: "reset", onClick: () => setQuery({}), className: "h-10 rounded-lg px-3 text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400", children: "Clear" })] })] }), _jsx(DataTable, { path: "/v1/audit", query: query, empty: "No events match.", columns: [
40
+ { header: "When", cell: (e) => formatDateTime(e.occurred_at) },
41
+ {
42
+ header: "Action",
43
+ cell: (e) => (_jsxs(_Fragment, { children: [_jsx("span", { className: "font-mono text-xs", children: e.action }), e.outcome === "failure" && (_jsx("span", { className: "ml-2 rounded-full bg-red-50 px-2 py-0.5 text-xs text-red-600", children: "failed" }))] })),
44
+ },
45
+ { header: "Actor", cell: (e) => _jsx(Mono, { children: e.actor_id ?? "system" }) },
46
+ {
47
+ header: "Target",
48
+ cell: (e) => (_jsxs(Mono, { children: [e.target_type, e.target_id !== "" && `: ${e.target_id}`] })),
49
+ },
50
+ { header: "Reason", cell: (e) => e.reason },
51
+ {
52
+ header: "Details",
53
+ cell: (e) => (_jsxs("details", { children: [_jsx("summary", { className: "cursor-pointer text-brand-500", children: "Show" }), _jsx("pre", { className: "mt-2 max-w-md overflow-auto rounded-lg bg-gray-50 p-3 text-xs dark:bg-gray-900", children: JSON.stringify({
54
+ metadata: e.metadata,
55
+ ip: e.ip,
56
+ user_agent: e.user_agent,
57
+ request_id: e.request_id,
58
+ seq: e.seq,
59
+ }, null, 2) })] })),
60
+ },
61
+ ] })] }));
62
+ }
63
+ function Archives() {
64
+ const [archives, setArchives] = useState(null);
65
+ const [error, setError] = useState("");
66
+ useEffect(() => {
67
+ // Small by design (one per month): not paged.
68
+ api
69
+ .get("/v1/audit/archives")
70
+ .then(setArchives)
71
+ .catch((err) => setError(err.message));
72
+ }, []);
73
+ if (error !== "") {
74
+ return _jsx(Alert, { children: error });
75
+ }
76
+ return (_jsxs("div", { className: "overflow-hidden rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsxs("table", { className: "min-w-full text-left text-sm", children: [_jsx("thead", { className: "border-b border-gray-100 text-gray-500 dark:border-gray-800 dark:text-gray-400", children: _jsxs("tr", { children: [_jsx("th", { className: "px-5 py-3 font-medium", children: "Month" }), _jsx("th", { className: "px-5 py-3 font-medium", children: "Events" }), _jsx("th", { className: "px-5 py-3 font-medium", children: "Size" }), _jsx("th", { className: "px-5 py-3 font-medium", children: "Status" }), _jsx("th", { className: "px-5 py-3 font-medium", children: "File" })] }) }), _jsx("tbody", { className: "divide-y divide-gray-100 text-gray-800 dark:divide-gray-800 dark:text-white/90", children: archives?.map((a) => (_jsxs("tr", { children: [_jsx("td", { className: "px-5 py-3", children: new Date(a.period_start).toLocaleDateString(undefined, {
77
+ year: "numeric",
78
+ month: "long",
79
+ timeZone: a.timezone,
80
+ }) }), _jsx("td", { className: "px-5 py-3", children: a.record_count.toLocaleString() }), _jsxs("td", { className: "px-5 py-3", children: [(a.size_bytes / 1024).toFixed(0), " KB"] }), _jsxs("td", { className: "px-5 py-3", children: [a.status, a.error !== "" && _jsx("span", { className: "block text-xs text-red-600", children: a.error })] }), _jsx("td", { className: "px-5 py-3", children: _jsx(Mono, { children: a.key }) })] }, a.id))) })] }), archives?.length === 0 && (_jsx("p", { className: "p-5 text-sm text-gray-500 dark:text-gray-400", children: "No months archived yet." }))] }));
81
+ }
82
+ function Filter(props) {
83
+ const id = `audit-${props.name}`;
84
+ return (_jsxs("div", { children: [_jsx("label", { htmlFor: id, className: "mb-1 block text-xs text-gray-500", children: props.label }), _jsx("input", { id: id, name: props.name, type: props.type ?? "text", placeholder: props.placeholder, className: input })] }));
85
+ }
86
+ function Mono({ children }) {
87
+ return _jsx("span", { className: "font-mono text-xs break-all", children: children });
88
+ }
@@ -0,0 +1 @@
1
+ export default function ForgotPasswordPage(): import("react").JSX.Element;
@@ -0,0 +1,73 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ // Forgot password: the admin's email, the code sent to it, then a new
4
+ // password. The project's app/forgot-password/page.tsx re-exports it.
5
+ import { useState } from "react";
6
+ import { AuthLayout } from "../auth-layout";
7
+ import { call } from "../client";
8
+ import { useConfig } from "../shell";
9
+ import { Alert, Button, CodeInput, Field } from "../ui";
10
+ export default function ForgotPasswordPage() {
11
+ const { config, router } = useConfig();
12
+ const { Link } = router;
13
+ const signIn = config.signInPath ?? "/login";
14
+ const [step, setStep] = useState({ kind: "email" });
15
+ const [code, setCode] = useState("");
16
+ const [error, setError] = useState("");
17
+ const [busy, setBusy] = useState(false);
18
+ const attempt = async (fn) => {
19
+ setError("");
20
+ setBusy(true);
21
+ try {
22
+ await fn();
23
+ }
24
+ catch (err) {
25
+ setError(err instanceof Error ? err.message : String(err));
26
+ }
27
+ finally {
28
+ setBusy(false);
29
+ }
30
+ };
31
+ const back = (_jsx(Link, { href: signIn, className: "text-brand-500 hover:text-brand-600", children: "Back to sign in" }));
32
+ if (step.kind === "done") {
33
+ return (_jsx(AuthLayout, { name: config.name, title: "Password changed", footer: back, children: _jsx("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Your password is changed, and you are signed out everywhere. Sign in with the new one." }) }));
34
+ }
35
+ if (step.kind === "password") {
36
+ const save = (event) => {
37
+ event.preventDefault();
38
+ const f = new FormData(event.currentTarget);
39
+ if (f.get("password") !== f.get("again")) {
40
+ setError("The two passwords aren't the same.");
41
+ return;
42
+ }
43
+ attempt(async () => {
44
+ await call("/v1/auth/reset-password", {
45
+ body: { token: step.token, password: f.get("password") },
46
+ });
47
+ setStep({ kind: "done" });
48
+ });
49
+ };
50
+ return (_jsxs(AuthLayout, { name: config.name, title: "Choose a new password", footer: back, children: [error !== "" && _jsx(Alert, { children: error }), _jsxs("form", { className: "animate-slide-in space-y-5", onSubmit: save, children: [_jsx(Field, { label: "New password", name: "password", type: "password", autoComplete: "new-password" }), _jsx(Field, { label: "Again", name: "again", type: "password", autoComplete: "new-password" }), _jsx(Button, { type: "submit", busy: busy, children: "Change password" })] })] }));
51
+ }
52
+ if (step.kind === "code") {
53
+ const verify = (value) => attempt(async () => {
54
+ const verified = await call("/v1/auth/verifications/verify", {
55
+ body: { verification_id: step.verificationId, code: value },
56
+ });
57
+ setStep({ kind: "password", token: verified.data.verification_token });
58
+ });
59
+ return (_jsx(AuthLayout, { name: config.name, title: "Check your email", subtitle: _jsxs(_Fragment, { children: ["If ", _jsx("span", { className: "font-medium", children: step.email }), " has an account, we sent it a code."] }), footer: back, children: _jsxs("div", { className: "animate-slide-in space-y-4", children: [error !== "" && _jsx(Alert, { children: error }), _jsx(CodeInput, { value: code, onChange: setCode, onComplete: verify, disabled: busy }), _jsx(Button, { busy: busy, onClick: () => verify(code), children: "Continue" })] }) }));
60
+ }
61
+ const send = (event) => {
62
+ event.preventDefault();
63
+ const email = String(new FormData(event.currentTarget).get("email")).trim();
64
+ attempt(async () => {
65
+ const res = await call("/v1/auth/forgot-password", {
66
+ body: { email, mode: "code" },
67
+ });
68
+ setCode("");
69
+ setStep({ kind: "code", email, verificationId: res.verification_id });
70
+ });
71
+ };
72
+ return (_jsxs(AuthLayout, { name: config.name, title: "Forgot your password?", subtitle: "Enter your email, and we'll send you a code to choose a new one.", footer: back, children: [error !== "" && _jsx(Alert, { children: error }), _jsxs("form", { className: "animate-fade-in space-y-5", onSubmit: send, children: [_jsx(Field, { label: "Email", name: "email", type: "email", autoComplete: "username" }), _jsx(Button, { type: "submit", busy: busy, children: "Send the code" })] })] }));
73
+ }
@@ -0,0 +1 @@
1
+ export default function LedgerPage(): import("react").JSX.Element;