This commit is contained in:
2026-04-28 17:59:51 -05:00
parent ffe2204597
commit f097f96d06
8 changed files with 628 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ import { DmsService } from '../services/dms.js';
import { SyncService } from '../services/sync.js';
import { DynamoRulesService } from '../services/dynamodb.js';
import { audit } from '../services/audit.js';
import { recordBillingEvent } from '../services/billing.js';
import { domainFromEmail, localPartFromEmail, normalizeEmail } from '../utils/email.js';
export const mailboxesRouter = Router();
@@ -102,6 +103,7 @@ mailboxesRouter.post('/', async (req, res) => {
await sync.syncFromDms();
await refreshQuotaForMailbox(email).catch((err) => console.warn(`Could not refresh quota for ${email}:`, err));
await audit(req.user!.email, 'mailbox.create', 'mailbox', email, { domain }, req.ip);
await recordBillingEvent('created', domain, email, req.user!.email);
res.status(201).json({ email, domain, local_part: localPartFromEmail(email) });
});
@@ -113,6 +115,7 @@ mailboxesRouter.delete('/:email', async (req, res) => {
await dms.syncSesDomain(domain).catch(() => undefined);
await pool.query(`UPDATE mailboxes SET status='deleted', deleted_at=now(), updated_at=now() WHERE email_address=$1`, [email]);
await audit(req.user!.email, 'mailbox.delete', 'mailbox', email, { domain }, req.ip);
await recordBillingEvent('deleted', domain, email, req.user!.email);
res.json({ ok: true });
});
@@ -125,8 +128,6 @@ mailboxesRouter.post('/:email/password', async (req, res) => {
res.json({ ok: true });
});
// Set storage quota for a single mailbox.
// quota_gb is an integer between 1 and 1024 (GB).
mailboxesRouter.post('/:email/quota', async (req, res) => {
const body = z.object({ quota_gb: z.number().int().min(1).max(1024) }).parse(req.body);
const email = normalizeEmail(req.params.email);