@autonoma-ai/server-web 0.1.2 → 0.1.4
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 +8 -3
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ export const POST = createHandler({
|
|
|
24
24
|
signingSecret: process.env.AUTONOMA_SIGNING_SECRET!,
|
|
25
25
|
auth: async (user) => {
|
|
26
26
|
const session = await createSession(user.id as string)
|
|
27
|
-
return {
|
|
27
|
+
return { headers: { Authorization: `Bearer ${session.token}` } }
|
|
28
28
|
},
|
|
29
29
|
})
|
|
30
30
|
```
|
|
@@ -60,7 +60,7 @@ Bun.serve({
|
|
|
60
60
|
|
|
61
61
|
## Auth callback
|
|
62
62
|
|
|
63
|
-
The `auth` callback receives the first `User` created during setup and must return
|
|
63
|
+
The `auth` callback receives the first `User` record created during setup (or `null` if no User model exists) and must return credentials for the test runner to authenticate:
|
|
64
64
|
|
|
65
65
|
```typescript
|
|
66
66
|
// Session cookie
|
|
@@ -74,7 +74,12 @@ auth: async (user) => {
|
|
|
74
74
|
// Bearer token
|
|
75
75
|
auth: async (user) => {
|
|
76
76
|
const token = jwt.sign({ sub: user.id }, SECRET)
|
|
77
|
-
return { token }
|
|
77
|
+
return { headers: { Authorization: `Bearer ${token}` } }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Username + password (for login-page flows)
|
|
81
|
+
auth: async (user) => {
|
|
82
|
+
return { credentials: { email: user.email as string, password: 'TestP@ssw0rd123!' } }
|
|
78
83
|
}
|
|
79
84
|
```
|
|
80
85
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { handleRequest } from "@autonoma-ai/sdk";
|
|
3
3
|
function createHandler(config) {
|
|
4
|
+
const enrichedConfig = { ...config, sdk: { ...config.sdk, server: "web" } };
|
|
4
5
|
return async (req) => {
|
|
5
6
|
const body = await req.text();
|
|
6
7
|
const headers = {};
|
|
@@ -8,7 +9,7 @@ function createHandler(config) {
|
|
|
8
9
|
headers[key.toLowerCase()] = value;
|
|
9
10
|
});
|
|
10
11
|
const handlerReq = { body, headers };
|
|
11
|
-
const res = await handleRequest(
|
|
12
|
+
const res = await handleRequest(enrichedConfig, handlerReq);
|
|
12
13
|
return new Response(JSON.stringify(res.body), {
|
|
13
14
|
status: res.status,
|
|
14
15
|
headers: { "Content-Type": "application/json" }
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { handleRequest } from '@autonoma-ai/sdk'\nimport type { HandlerConfig, HandlerRequest } from '@autonoma-ai/sdk'\n\n/**\n * Create a Web standard handler (works with Next App Router, Hono, Bun, Deno).\n *\n * @example\n * ```ts\n * import { createHandler } from '@autonoma-ai/server-web'\n * const handler = createHandler(config)\n * // Next.js App Router:\n * export const POST = handler\n * ```\n */\nexport function createHandler(config: HandlerConfig) {\n return async (req: Request): Promise<Response> => {\n const body = await req.text()\n const headers: Record<string, string> = {}\n req.headers.forEach((value, key) => {\n headers[key.toLowerCase()] = value\n })\n\n const handlerReq: HandlerRequest = { body, headers }\n const res = await handleRequest(
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { handleRequest } from '@autonoma-ai/sdk'\nimport type { HandlerConfig, HandlerRequest } from '@autonoma-ai/sdk'\n\n/**\n * Create a Web standard handler (works with Next App Router, Hono, Bun, Deno).\n *\n * @example\n * ```ts\n * import { createHandler } from '@autonoma-ai/server-web'\n * const handler = createHandler(config)\n * // Next.js App Router:\n * export const POST = handler\n * ```\n */\nexport function createHandler(config: HandlerConfig) {\n const enrichedConfig = { ...config, sdk: { ...config.sdk, server: 'web' } }\n return async (req: Request): Promise<Response> => {\n const body = await req.text()\n const headers: Record<string, string> = {}\n req.headers.forEach((value, key) => {\n headers[key.toLowerCase()] = value\n })\n\n const handlerReq: HandlerRequest = { body, headers }\n const res = await handleRequest(enrichedConfig, handlerReq)\n\n return new Response(JSON.stringify(res.body), {\n status: res.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAcvB,SAAS,cAAc,QAAuB;AACnD,QAAM,iBAAiB,EAAE,GAAG,QAAQ,KAAK,EAAE,GAAG,OAAO,KAAK,QAAQ,MAAM,EAAE;AAC1E,SAAO,OAAO,QAAoC;AAChD,UAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAM,UAAkC,CAAC;AACzC,QAAI,QAAQ,QAAQ,CAAC,OAAO,QAAQ;AAClC,cAAQ,IAAI,YAAY,CAAC,IAAI;AAAA,IAC/B,CAAC;AAED,UAAM,aAA6B,EAAE,MAAM,QAAQ;AACnD,UAAM,MAAM,MAAM,cAAc,gBAAgB,UAAU;AAE1D,WAAO,IAAI,SAAS,KAAK,UAAU,IAAI,IAAI,GAAG;AAAA,MAC5C,QAAQ,IAAI;AAAA,MACZ,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,IAChD,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonoma-ai/server-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Web standard (Hono, Next App Router, Bun, Deno) 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.4"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^22.0.0",
|