railyard/apps/mail/dashboard/js/views/suppressions.js
caelum0x 70653ae53b feat(mail): mount the dashboard, email event + webhook delivery logs, billing shape, friendly bad magic links
mail-server serves apps/mail/dashboard at /dashboard/ (tower-http fs,
DASHBOARD_DIR, mock/ and MOUNT.md never served). New account-scoped,
Resend-shaped endpoints the dashboard reads: GET /emails/{id}/events
(status history with timestamps and a one-line detail from the stored
payload), GET /emails/{id}/webhook-deliveries and
GET /webhooks/{id}/deliveries (delivery log joined with event + endpoint),
GET /emails?test=true|false and GET /suppressions?q= server filters.
GET /billing now carries description, next_plan, upgrade_label,
current_period_end/renews_at; POST /billing/checkout accepts success_url
(own origin only) and returns url. mail-auth: a bad, used or expired link
opened in a browser redirects to <redirect_to>#error=invalid_token (or a
plain HTML page when the token was never ours); the dashboard shows the
message on the login form. Dashboard uses the server-side test filter,
portal via POST /billing/portal, docs updated.

Verified live against local Postgres mail_e2e + fake relay + webhook
listener: curl of every endpoint (404 for another account's ids, 401
without auth, 422 on test=maybe), and a headless-browser pass through the
real magic-link login, email timeline, webhook delivery log, usage card
and the expired-link redirect.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-13 13:01:01 +03:00

61 lines
3.1 KiB
JavaScript

// Suppressions: addresses we will not send to. Search, add, remove. The
// search filters the loaded page instantly; when the account has more rows
// than one page (1000) the same query is also run server-side (`?q=`).
import * as api from "../api.js";
import { badge, button, confirmAction, el, errorBox, fullTime, label, loading, pageHead, table, toast } from "../ui.js";
const PAGE = 1000;
export async function suppressionsView() {
const list = el("div.card.tight");
const msg = el("div");
const search = el("input.input", { type: "search", placeholder: "Search address or reason", style: "max-width:320px" });
const add = el("input.input", { type: "email", placeholder: "person@example.com", required: true });
let rows = [];
let serverSearch = null;
function paint() {
const q = search.value.trim().toLowerCase();
if (q && rows.length >= PAGE) {
// Too many rows for one page: ask the server (debounced) instead.
clearTimeout(serverSearch);
serverSearch = setTimeout(async () => {
try { const r = (await api.listSuppressions(q)).data || []; list.replaceChildren(render(r, q)); } catch (e) { list.replaceChildren(errorBox(e)); }
}, 250);
return;
}
const shown = q ? rows.filter((s) => s.email.includes(q) || (s.reason || "").includes(q)) : rows;
list.replaceChildren(render(shown, q));
}
function render(shown, q) {
return table(
["Address", "Reason", "Source email", "Added", ""],
shown.map((s) => el("tr",
el("td", s.email),
el("td", badge(s.reason === "manual" ? "manual" : s.reason, s.reason === "manual" ? "" : "bad"), s.detail ? el("div.small.muted", s.detail) : null),
el("td", s.source_email_id ? el("a.mono.small", { href: `#/emails/${s.source_email_id}` }, s.source_email_id.slice(0, 8)) : el("span.faint", "-")),
el("td.muted", fullTime(s.created_at)),
el("td", button("Remove", async () => {
if (!confirmAction(`Allow sending to ${s.email} again?`)) return;
try { await api.removeSuppression(s.email); toast("Removed"); load(); } catch (err) { alert(err.message); }
}, "btn secondary sm")))),
q ? "No matches." : "Nothing suppressed. Hard bounces, complaints and unsubscribes land here automatically.");
}
async function load() {
list.replaceChildren(loading());
try { rows = (await api.listSuppressions()).data || []; paint(); } catch (e) { list.replaceChildren(errorBox(e)); }
}
search.oninput = paint;
await load();
const form = el("form.inline-form", { onsubmit: async (e) => {
e.preventDefault(); msg.replaceChildren();
try { await api.addSuppression(add.value.trim()); add.value = ""; toast("Suppressed"); load(); } catch (err) { msg.append(errorBox(err)); }
} },
el("div.field", el("label", "Suppress an address"), add), el("button.btn.secondary", { type: "submit" }, "Add"));
return el("div",
pageHead("Suppressions", "Addresses this account will not send to. Sends to them are refused with 403."),
el("div.card", el("div.row", { style: "justify-content:space-between" }, search, form), msg),
list);
}