@autonoma-ai/server-express
v0.1.2
Published
Express/Fastify server adapter for Autonoma SDK
Downloads
224
Readme
@autonoma-ai/server-express
Express/Fastify server adapter for the Autonoma SDK.
Install
pnpm add @autonoma-ai/sdk @autonoma-ai/sdk-prisma @autonoma-ai/server-expressUsage
Express
import express from 'express'
import { createExpressHandler } from '@autonoma-ai/server-express'
import { prismaAdapter } from '@autonoma-ai/sdk-prisma'
import { prisma } from './db'
const app = express()
app.post('/api/autonoma', createExpressHandler({
adapter: prismaAdapter(prisma, { scopeField: 'organizationId' }),
sharedSecret: process.env.AUTONOMA_SHARED_SECRET!,
signingSecret: process.env.AUTONOMA_SIGNING_SECRET!,
auth: async (user) => {
const session = await createSession(user.id as string)
return { token: session.token }
},
}))Fastify
import Fastify from 'fastify'
import { createExpressHandler } from '@autonoma-ai/server-express'
const app = Fastify()
const handler = createExpressHandler(config)
app.post('/api/autonoma', async (req, reply) => {
await handler(req.raw, reply.raw)
})Note: Do not add
express.json()middleware before this route. The adapter needs the raw body string to verify the HMAC signature.
Auth callback
The auth callback receives the first User created during setup and must return real credentials that the test runner can use to log in:
// Session cookie
auth: async (user) => {
const session = await createSession(user.id as string)
return {
cookies: [{ name: 'session', value: session.token, httpOnly: true, sameSite: 'lax', path: '/' }],
}
}
// Bearer token
auth: async (user) => {
const token = jwt.sign({ sub: user.id }, SECRET)
return { token }
}Documentation
Full docs: docs/ — see setup guide.
