summaryrefslogtreecommitdiffhomepage
path: root/packages/console/app/src/routes/api/enterprise.ts
blob: 6776a7b3c7351956ab4f233ecec9ef4b09f4d2e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { APIEvent } from "@solidjs/start/server"
import { AWS } from "@opencode-ai/console-core/aws.js"

interface EnterpriseFormData {
  name: string
  role: string
  email: string
  message: string
}

export async function POST(event: APIEvent) {
  try {
    const body = (await event.request.json()) as EnterpriseFormData

    // Validate required fields
    if (!body.name || !body.role || !body.email || !body.message) {
      return Response.json({ error: "All fields are required" }, { status: 400 })
    }

    // Validate email format
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
    if (!emailRegex.test(body.email)) {
      return Response.json({ error: "Invalid email format" }, { status: 400 })
    }

    // Create email content
    const emailContent = `
${body.message}<br><br>
--<br>
${body.name}<br>
${body.role}<br>
${body.email}`.trim()

    // Send email using AWS SES
    await AWS.sendEmail({
      to: "[email protected]",
      subject: `Enterprise Inquiry from ${body.name}`,
      body: emailContent,
      replyTo: body.email,
    })

    return Response.json({ success: true, message: "Form submitted successfully" }, { status: 200 })
  } catch (error) {
    console.error("Error processing enterprise form:", error)
    return Response.json({ error: "Internal server error" }, { status: 500 })
  }
}