Add connection tests for Workforce and SMTP integrations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-02 00:33:48 +00:00
parent 2339a75d07
commit a886b4b30e

View file

@ -87,6 +87,26 @@ export async function integrationRoutes(app) {
try {
if (req.params.slug === 'newbook') await newbookTest(creds)
else if (req.params.slug === 'resos') await resosTest(creds)
else if (req.params.slug === 'workforce') {
const baseUrl = creds.base_url || 'https://my.workforce.com'
const res = await fetch(`${baseUrl}/api/oauth/token`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ grant_type: 'password', username: creds.email, password: creds.password, scope: 'default' }),
signal: AbortSignal.timeout(8000),
})
if (!res.ok) throw new Error(`Workforce auth failed (${res.status})`)
const data = await res.json()
if (!data.access_token) throw new Error('No access token returned')
}
else if (req.params.slug === 'smtp') {
const nodemailer = await import('nodemailer')
const transporter = nodemailer.default.createTransport({
host: creds.host, port: parseInt(creds.port || '587'),
auth: { user: creds.user, pass: creds.pass },
})
await transporter.verify()
}
else return reply.status(400).send({ error: `No test available for ${req.params.slug}` })
return { ok: true }
} catch (e) {