diff --git a/apps/api/src/controllers/Campaigns.ts b/apps/api/src/controllers/Campaigns.ts
index 5982e2b..5ec2503 100644
--- a/apps/api/src/controllers/Campaigns.ts
+++ b/apps/api/src/controllers/Campaigns.ts
@@ -1,6 +1,6 @@
import {Controller, Delete, Get, Middleware, Post, Put} from '@overnightjs/core';
import {CampaignAudienceType, CampaignStatus} from '@plunk/db';
-import {CampaignSchemas} from '@plunk/shared';
+import {CampaignSchemas, UtilitySchemas} from '@plunk/shared';
import type {NextFunction, Request, Response} from 'express';
import {HttpException} from '../exceptions/index.js';
@@ -97,7 +97,7 @@ export class Campaigns {
@CatchAsync
private async get(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
const campaign = await CampaignService.get(auth.projectId, id!);
@@ -116,7 +116,7 @@ export class Campaigns {
@CatchAsync
private async update(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
const {name, description, subject, body, from, fromName, replyTo, audienceType, audienceCondition, segmentId} =
req.body;
@@ -162,7 +162,7 @@ export class Campaigns {
@CatchAsync
private async delete(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
await CampaignService.delete(auth.projectId, id!);
@@ -181,7 +181,7 @@ export class Campaigns {
@CatchAsync
private async duplicate(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
const campaign = await CampaignService.duplicate(auth.projectId, id!);
@@ -201,7 +201,7 @@ export class Campaigns {
@CatchAsync
private async send(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
const scheduledFor = req.body?.scheduledFor;
// Parse scheduledFor if provided
@@ -232,7 +232,7 @@ export class Campaigns {
@CatchAsync
private async cancel(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
const campaign = await CampaignService.cancel(auth.projectId, id!);
@@ -252,7 +252,7 @@ export class Campaigns {
@CatchAsync
private async stats(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
const stats = await CampaignService.getStats(auth.projectId, id!);
@@ -271,7 +271,7 @@ export class Campaigns {
@CatchAsync
private async sendTest(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
const {email} = CampaignSchemas.sendTest.parse(req.body);
await CampaignService.sendTest(auth.projectId, id!, email);
diff --git a/apps/api/src/controllers/Projects.ts b/apps/api/src/controllers/Projects.ts
index a45d62f..b65c5cd 100644
--- a/apps/api/src/controllers/Projects.ts
+++ b/apps/api/src/controllers/Projects.ts
@@ -1,11 +1,12 @@
import {Controller, Delete, Get, Middleware, Patch, Post} from '@overnightjs/core';
import type {NextFunction, Request, Response} from 'express';
-import {MembershipSchemas} from '@plunk/shared';
+import {MembershipSchemas, UtilitySchemas} from '@plunk/shared';
import {prisma} from '../database/prisma.js';
import {HttpException} from '../exceptions/index.js';
import type {AuthResponse} from '../middleware/auth.js';
import {requireAuth} from '../middleware/auth.js';
+import {SecurityService} from '../services/SecurityService.js';
import {CatchAsync} from '../utils/asyncHandler.js';
@Controller('projects')
@@ -19,7 +20,7 @@ export class Projects {
@CatchAsync
private async getSetupState(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
// Verify user has access to this project
const membership = await prisma.membership.findFirst({
@@ -83,6 +84,38 @@ export class Projects {
});
}
+ /**
+ * Get project security metrics
+ * GET /projects/:id/security
+ */
+ @Get(':id/security')
+ @Middleware([requireAuth])
+ @CatchAsync
+ private async getSecurityMetrics(req: Request, res: Response, _next: NextFunction) {
+ const auth = res.locals.auth as AuthResponse;
+ const {id} = UtilitySchemas.id.parse(req.params);
+
+ // Verify user has access to this project
+ const membership = await prisma.membership.findFirst({
+ where: {
+ userId: auth.userId,
+ projectId: id,
+ },
+ });
+
+ if (!membership) {
+ throw new HttpException(404, 'Project not found or you do not have access');
+ }
+
+ // Use existing SecurityService
+ const metrics = await SecurityService.getProjectSecurityMetrics(id);
+
+ return res.json({
+ success: true,
+ data: metrics,
+ });
+ }
+
/**
* Get all members of a project
* GET /projects/:id/members
@@ -92,7 +125,7 @@ export class Projects {
@CatchAsync
private async getMembers(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
// Verify user has access to this project
const membership = await prisma.membership.findFirst({
@@ -141,7 +174,7 @@ export class Projects {
@CatchAsync
private async addMember(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
// Validate params
if (!id) {
diff --git a/apps/api/src/controllers/Users.ts b/apps/api/src/controllers/Users.ts
index 0a18669..09ed62f 100644
--- a/apps/api/src/controllers/Users.ts
+++ b/apps/api/src/controllers/Users.ts
@@ -1,7 +1,7 @@
import {randomBytes} from 'node:crypto';
import {Controller, Delete, Get, Middleware, Patch, Post, Put} from '@overnightjs/core';
-import {BillingLimitSchemas, ProjectSchemas} from '@plunk/shared';
+import {BillingLimitSchemas, ProjectSchemas, UtilitySchemas} from '@plunk/shared';
import type {NextFunction, Request, Response} from 'express';
import {DASHBOARD_URI, STRIPE_ENABLED, STRIPE_PRICE_EMAIL_USAGE, STRIPE_PRICE_ONBOARDING} from '../app/constants.js';
@@ -95,7 +95,7 @@ export class Users {
@CatchAsync
public async updateProject(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
const data = ProjectSchemas.update.parse(req.body);
// Verify user has access to this project
@@ -127,7 +127,7 @@ export class Users {
@CatchAsync
public async regenerateProjectKeys(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
// Verify user has admin/owner access to this project
const membership = await prisma.membership.findFirst({
@@ -179,7 +179,7 @@ export class Users {
@CatchAsync
public async createCheckoutSession(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
// Check if billing is enabled
if (!STRIPE_ENABLED || !stripe) {
@@ -258,7 +258,7 @@ export class Users {
@CatchAsync
public async createBillingPortalSession(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
// Check if billing is enabled
if (!STRIPE_ENABLED || !stripe) {
@@ -308,7 +308,7 @@ export class Users {
@CatchAsync
public async getBillingLimits(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
if (!auth.userId) {
throw new NotAuthenticated();
@@ -341,7 +341,7 @@ export class Users {
@CatchAsync
public async updateBillingLimits(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
if (!auth.userId) {
throw new NotAuthenticated();
@@ -408,7 +408,7 @@ export class Users {
@CatchAsync
public async getBillingConsumption(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
// Check if billing is enabled
if (!STRIPE_ENABLED || !stripe) {
@@ -534,7 +534,7 @@ export class Users {
@CatchAsync
public async getBillingInvoices(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
// Check if billing is enabled
if (!STRIPE_ENABLED || !stripe) {
@@ -622,7 +622,7 @@ export class Users {
@CatchAsync
public async getSecurityHealth(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
if (!auth.userId) {
throw new NotAuthenticated();
@@ -655,7 +655,7 @@ export class Users {
@CatchAsync
public async resetProject(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
if (!auth.userId) {
throw new NotAuthenticated();
@@ -731,7 +731,7 @@ export class Users {
@CatchAsync
public async deleteProject(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth as AuthResponse;
- const {id} = req.params;
+ const {id} = UtilitySchemas.id.parse(req.params);
if (!auth.userId) {
throw new NotAuthenticated();
diff --git a/apps/web/src/components/SecuritySettings.tsx b/apps/web/src/components/SecuritySettings.tsx
new file mode 100644
index 0000000..8c82a63
--- /dev/null
+++ b/apps/web/src/components/SecuritySettings.tsx
@@ -0,0 +1,267 @@
+import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ Progress,
+} from '@plunk/ui';
+import {AlertCircle, AlertTriangle, CheckCircle, Shield} from 'lucide-react';
+import type {ProjectSecurityMetrics} from '@plunk/types';
+
+interface SecuritySettingsProps {
+ metrics: ProjectSecurityMetrics;
+ isLoading: boolean;
+}
+
+export function SecuritySettings({metrics, isLoading}: SecuritySettingsProps) {
+ if (isLoading) {
+ return (
+ Loading security metrics...
+ {count.toLocaleString()} / {total.toLocaleString()} emails + • + {rate.toFixed(decimals)}% +
++ Your project has exceeded security thresholds. Current rates: 7-day bounce rate{' '} + {sevenDayBounceRate}%, 7-day complaint rate{' '} + {sevenDayComplaintRate}%. +
++ High bounce or complaint rates can lead to project suspension. Review the detailed metrics + and take action to improve your email quality. +
++ {isLoadingSecurityMetrics ? 'Loading...' : 'Unable to load security metrics'} +
+