From 1d54b0e54065e3ad09093cff658447d0e2ffde3b Mon Sep 17 00:00:00 2001 From: Ryan Vogel Date: Sat, 18 Apr 2026 18:30:28 -0400 Subject: [PATCH] Stefan/enterprise forms waitlist (#23158) Co-authored-by: Ryan Vogel --- .../console/app/src/routes/api/enterprise.ts | 71 ++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/packages/console/app/src/routes/api/enterprise.ts b/packages/console/app/src/routes/api/enterprise.ts index 1bc4d0eb29..6560a93610 100644 --- a/packages/console/app/src/routes/api/enterprise.ts +++ b/packages/console/app/src/routes/api/enterprise.ts @@ -1,5 +1,6 @@ import type { APIEvent } from "@solidjs/start/server" import { AWS } from "@opencode-ai/console-core/aws.js" +import { Resource } from "@opencode-ai/console-resource" import { i18n } from "~/i18n" import { localeFromRequest } from "~/lib/language" import { createLead } from "~/lib/salesforce" @@ -14,6 +15,64 @@ interface EnterpriseFormData { message: string } +const EMAIL_OCTOPUS_LIST_ID = "1b381e5e-39bd-11f1-ba4a-cdd4791f0c43" + +function splitFullName(fullName: string) { + const parts = fullName + .trim() + .split(/\s+/) + .filter((p) => p.length > 0) + if (parts.length === 0) return { firstName: "", lastName: "" } + if (parts.length === 1) return { firstName: parts[0], lastName: "" } + return { firstName: parts[0], lastName: parts.slice(1).join(" ") } +} + +function getEmailOctopusApiKey() { + if (process.env.EMAILOCTOPUS_API_KEY) return process.env.EMAILOCTOPUS_API_KEY + try { + return Resource.EMAILOCTOPUS_API_KEY.value + } catch { + return + } +} + +function subscribe(email: string, fullName: string) { + const apiKey = getEmailOctopusApiKey() + if (!apiKey) { + console.warn("Skipping EmailOctopus subscribe: missing API key") + return Promise.resolve(false) + } + + const name = splitFullName(fullName) + const fields: Record = {} + if (name.firstName) fields.FirstName = name.firstName + if (name.lastName) fields.LastName = name.lastName + + const payload: { email_address: string; fields?: Record } = { email_address: email } + if (Object.keys(fields).length) payload.fields = fields + + return fetch(`https://api.emailoctopus.com/lists/${EMAIL_OCTOPUS_LIST_ID}/contacts`, { + method: "PUT", + headers: { + Authorization: `Bearer ${apiKey}`, + "Content-Type": "application/json", + }, + body: JSON.stringify(payload), + }).then( + (res) => { + if (!res.ok) { + console.error("EmailOctopus subscribe failed:", res.status, res.statusText) + return false + } + return true + }, + (err) => { + console.error("Failed to subscribe enterprise email:", err) + return false + }, + ) +} + export async function POST(event: APIEvent) { const dict = i18n(localeFromRequest(event.request)) try { @@ -41,7 +100,7 @@ ${body.role}
${body.company ? `${body.company}
` : ""}${body.email}
${body.phone ? `${body.phone}
` : ""}`.trim() - const [lead, mail] = await Promise.all([ + const [lead, mail, octopus] = await Promise.all([ createLead({ name: body.name, role: body.role, @@ -49,6 +108,9 @@ ${body.phone ? `${body.phone}
` : ""}`.trim() email: body.email, phone: body.phone, message: body.message, + }).catch((err) => { + console.error("Failed to create Salesforce lead:", err) + return false }), AWS.sendEmail({ to: "contact@anoma.ly", @@ -62,9 +124,14 @@ ${body.phone ? `${body.phone}
` : ""}`.trim() return false }, ), + subscribe(body.email, body.name), ]) - if (!lead && !mail) { + if (!lead && !mail && !octopus) { + if (import.meta.env.DEV) { + console.warn("Enterprise inquiry accepted in dev mode without integrations", { email: body.email }) + return Response.json({ success: true, message: dict["enterprise.form.success.submitted"] }, { status: 200 }) + } console.error("Enterprise inquiry delivery failed", { email: body.email }) return Response.json({ error: dict["enterprise.form.error.internalServer"] }, { status: 500 }) }