@autonoma-ai/server-node 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.
Files changed (2) hide show
  1. package/README.md +59 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @autonoma-ai/server-node
2
+
3
+ Node.js `http` 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-node
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import http from 'node:http'
15
+ import { createNodeHandler } from '@autonoma-ai/server-node'
16
+ import { prismaAdapter } from '@autonoma-ai/sdk-prisma'
17
+ import { prisma } from './db'
18
+
19
+ const handler = createNodeHandler({
20
+ adapter: prismaAdapter(prisma, { scopeField: 'organizationId' }),
21
+ sharedSecret: process.env.AUTONOMA_SHARED_SECRET!,
22
+ signingSecret: process.env.AUTONOMA_SIGNING_SECRET!,
23
+ auth: async (user) => {
24
+ const session = await createSession(user.id as string)
25
+ return { token: session.token }
26
+ },
27
+ })
28
+
29
+ http.createServer((req, res) => {
30
+ if (req.method === 'POST' && req.url === '/api/autonoma') {
31
+ return handler(req, res)
32
+ }
33
+ res.writeHead(404).end()
34
+ }).listen(3000)
35
+ ```
36
+
37
+ ## Auth callback
38
+
39
+ The `auth` callback receives the first `User` created during setup and must return real credentials that the test runner can use to log in:
40
+
41
+ ```typescript
42
+ // Session cookie
43
+ auth: async (user) => {
44
+ const session = await createSession(user.id as string)
45
+ return {
46
+ cookies: [{ name: 'session', value: session.token, httpOnly: true, sameSite: 'lax', path: '/' }],
47
+ }
48
+ }
49
+
50
+ // Bearer token
51
+ auth: async (user) => {
52
+ const token = jwt.sign({ sub: user.id }, SECRET)
53
+ return { token }
54
+ }
55
+ ```
56
+
57
+ ## Documentation
58
+
59
+ 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-node",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Node.js http 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.0"
19
+ "@autonoma-ai/sdk": "0.1.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.0.0",