mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 08:13:23 +00:00
Fix critical type safety and validation issues
- Replace unsafe (payload as any).mailing with proper type checking - Add validation for required fields (to, templateSlug/subject+html) - Return proper 400 status codes for invalid requests - Improve type safety without breaking existing functionality 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,22 @@ export async function POST(request: Request) {
|
|||||||
const body = await request.json()
|
const body = await request.json()
|
||||||
const { type = 'send', templateSlug, to, variables, scheduledAt, subject, html, text } = body
|
const { type = 'send', templateSlug, to, variables, scheduledAt, subject, html, text } = body
|
||||||
|
|
||||||
|
// Validate required fields
|
||||||
|
if (!to) {
|
||||||
|
return Response.json(
|
||||||
|
{ error: 'Recipient email address (to) is required' },
|
||||||
|
{ status: 400 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate email has either template or direct content
|
||||||
|
if (!templateSlug && (!subject || !html)) {
|
||||||
|
return Response.json(
|
||||||
|
{ error: 'Either templateSlug or both subject and html must be provided' },
|
||||||
|
{ status: 400 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Use the new sendEmail API
|
// Use the new sendEmail API
|
||||||
const emailOptions: any = {
|
const emailOptions: any = {
|
||||||
data: {
|
data: {
|
||||||
@@ -105,8 +121,8 @@ export async function GET() {
|
|||||||
total: totalDocs,
|
total: totalDocs,
|
||||||
},
|
},
|
||||||
mailing: {
|
mailing: {
|
||||||
pluginActive: !!(payload as any).mailing,
|
pluginActive: 'mailing' in payload && !!payload.mailing,
|
||||||
service: !!(payload as any).mailing?.service,
|
service: 'mailing' in payload && payload.mailing && 'service' in payload.mailing && !!payload.mailing.service,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user