How big the app's data is, and a webhook delivery log with Send again

Settings -> Data -> Storage measures the database, backups and sessions and every
table (size, rows, growth, how long it is kept, how far back it reaches), and flags
histories that are not being trimmed or have no limit.

Event webhooks now keep a delivery log (last 100 per webhook, 14 days): what was
sent, how it went, the message itself, and Send again, which resends it exactly as it
was (same id and signature). Resends are audited and in the Change log.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-21 20:58:57 +02:00
1 parent aebf3c6ce1
commit e114567d64
22 files changed
+6833 -19

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
import { Router } from "express";
import { requireAuth, requireRole } from "../auth/middleware.js";
import { getDataUsage } from "../services/dataUsage.js";
import { asyncHandler } from "../utils/asyncHandler.js";
/** How big the app's own data is and whether it is being trimmed: for administrators (it names every table and how much each holds). */
export const dataUsageRouter = Router();
dataUsageRouter.use(requireAuth, requireRole("admin"));
dataUsageRouter.get("/", asyncHandler(async (_req, res) => {
res.json(await getDataUsage());
}));
+31 -3
View File
@@ -1,11 +1,11 @@
import { Router } from "express";
import { eq } from "drizzle-orm";
import { and, desc, eq } from "drizzle-orm";
import { z } from "zod";
import { db } from "../db/client.js";
import { eventWebhooks, webhookEvents } from "../db/schema.js";
import { eventWebhooks, webhookDeliveries, webhookEvents } from "../db/schema.js";
import { requireAuth, requireRole } from "../auth/middleware.js";
import { recordAudit } from "../services/audit.js";
import { deliver, parseEvents, sealSecret, type EventWebhookRow } from "../services/eventWebhooks.js";
import { deliver, MAX_STORED_BODY, parseEvents, redeliver, sealSecret, type EventWebhookRow } from "../services/eventWebhooks.js";
import { asyncHandler } from "../utils/asyncHandler.js";
export const eventWebhooksRouter = Router();
@@ -86,6 +86,34 @@ eventWebhooksRouter.delete("/:id", asyncHandler(async (req, res) => {
res.status(204).end();
}));
// What was sent to a webhook lately and how each went, with the message itself, newest first.
eventWebhooksRouter.get("/:id/deliveries", asyncHandler(async (req, res) => {
const id = idOf(req.params.id);
if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" });
const [row] = await db.select({ id: eventWebhooks.id }).from(eventWebhooks).where(eq(eventWebhooks.id, id)).limit(1);
if (!row) return res.status(404).json({ error: "not_found" });
const asked = Number(req.query.limit);
const limit = Number.isFinite(asked) ? Math.min(100, Math.max(1, Math.round(asked))) : 50;
const rows = await db.select().from(webhookDeliveries).where(eq(webhookDeliveries.webhookId, id)).orderBy(desc(webhookDeliveries.createdAt), desc(webhookDeliveries.id)).limit(limit);
res.json({
deliveries: rows.map((r) => ({ id: r.id, event: r.event, deliveryId: r.deliveryId, attempts: r.attempts, ok: r.ok, result: r.result, body: r.body.length > MAX_STORED_BODY ? null : r.body, retryable: r.body.length <= MAX_STORED_BODY, retryOf: r.retryOf, createdAt: r.createdAt })),
});
}));
// Sends a delivery again exactly as it was, with the same id — for when the receiver was down, or the fault was at its end.
eventWebhooksRouter.post("/:id/deliveries/:deliveryId/retry", asyncHandler(async (req, res) => {
const id = idOf(req.params.id);
const deliveryRowId = idOf(req.params.deliveryId);
if (!Number.isInteger(id) || !Number.isInteger(deliveryRowId)) return res.status(400).json({ error: "invalid_id" });
const [hook] = await db.select().from(eventWebhooks).where(eq(eventWebhooks.id, id)).limit(1);
const [earlier] = await db.select().from(webhookDeliveries).where(and(eq(webhookDeliveries.id, deliveryRowId), eq(webhookDeliveries.webhookId, id))).limit(1);
if (!hook || !earlier) return res.status(404).json({ error: "not_found" });
if (earlier.body.length > MAX_STORED_BODY) return res.status(409).json({ error: "too_large", message: "That message was too large to keep, so it cannot be sent again." });
const outcome = await redeliver(hook, earlier);
await recordAudit({ actor: req.currentUser!, category: "webhook", action: "retry", targetType: "event_webhook", targetId: id, detail: { label: hook.label, event: earlier.event, ok: outcome.ok } });
res.json(outcome);
}));
// Sends one test message, signed like the real ones, and says how it went — whether or not the webhook is switched on or wants the event.
eventWebhooksRouter.post("/:id/test", asyncHandler(async (req, res) => {
const id = idOf(req.params.id);