@autonoma-ai/server-express 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @autonoma-ai/server-express
|
|
2
|
+
|
|
3
|
+
Express/Fastify server adapter for the Autonoma SDK.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @autonoma-ai/sdk @autonoma-ai/sdk-prisma @autonoma-ai/server-express
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Express
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import express from 'express'
|
|
17
|
+
import { createExpressHandler } from '@autonoma-ai/server-express'
|
|
18
|
+
import { prismaAdapter } from '@autonoma-ai/sdk-prisma'
|
|
19
|
+
import { prisma } from './db'
|
|
20
|
+
|
|
21
|
+
const app = express()
|
|
22
|
+
|
|
23
|
+
app.post('/api/autonoma', createExpressHandler({
|
|
24
|
+
adapter: prismaAdapter(prisma, { scopeField: 'organizationId' }),
|
|
25
|
+
sharedSecret: process.env.AUTONOMA_SHARED_SECRET!,
|
|
26
|
+
signingSecret: process.env.AUTONOMA_SIGNING_SECRET!,
|
|
27
|
+
auth: async (user) => {
|
|
28
|
+
const session = await createSession(user.id as string)
|
|
29
|
+
return { token: session.token }
|
|
30
|
+
},
|
|
31
|
+
}))
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Fastify
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import Fastify from 'fastify'
|
|
38
|
+
import { createExpressHandler } from '@autonoma-ai/server-express'
|
|
39
|
+
|
|
40
|
+
const app = Fastify()
|
|
41
|
+
const handler = createExpressHandler(config)
|
|
42
|
+
|
|
43
|
+
app.post('/api/autonoma', async (req, reply) => {
|
|
44
|
+
await handler(req.raw, reply.raw)
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
> **Note:** Do not add `express.json()` middleware before this route. The adapter needs the raw body string to verify the HMAC signature.
|
|
49
|
+
|
|
50
|
+
## Auth callback
|
|
51
|
+
|
|
52
|
+
The `auth` callback receives the first `User` created during setup and must return real credentials that the test runner can use to log in:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// Session cookie
|
|
56
|
+
auth: async (user) => {
|
|
57
|
+
const session = await createSession(user.id as string)
|
|
58
|
+
return {
|
|
59
|
+
cookies: [{ name: 'session', value: session.token, httpOnly: true, sameSite: 'lax', path: '/' }],
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Bearer token
|
|
64
|
+
auth: async (user) => {
|
|
65
|
+
const token = jwt.sign({ sub: user.id }, SECRET)
|
|
66
|
+
return { token }
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
Full docs: [docs/](../../docs/) — see [setup guide](../../docs/setup.txt).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonoma-ai/server-express",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Express/Fastify server adapter for Autonoma SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@autonoma-ai/sdk": "0.1.
|
|
19
|
+
"@autonoma-ai/sdk": "0.1.2"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^22.0.0",
|