@autonoma-ai/server-node 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
|
@@ -22,7 +22,7 @@ const handler = createNodeHandler({
|
|
|
22
22
|
signingSecret: process.env.AUTONOMA_SIGNING_SECRET!,
|
|
23
23
|
auth: async (user) => {
|
|
24
24
|
const session = await createSession(user.id as string)
|
|
25
|
-
return {
|
|
25
|
+
return { headers: { Authorization: `Bearer ${session.token}` } }
|
|
26
26
|
},
|
|
27
27
|
})
|
|
28
28
|
|
|
@@ -36,7 +36,7 @@ http.createServer((req, res) => {
|
|
|
36
36
|
|
|
37
37
|
## Auth callback
|
|
38
38
|
|
|
39
|
-
The `auth` callback receives the first `User` created during setup and must return
|
|
39
|
+
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:
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
42
|
// Session cookie
|
|
@@ -50,7 +50,12 @@ auth: async (user) => {
|
|
|
50
50
|
// Bearer token
|
|
51
51
|
auth: async (user) => {
|
|
52
52
|
const token = jwt.sign({ sub: user.id }, SECRET)
|
|
53
|
-
return { token }
|
|
53
|
+
return { headers: { Authorization: `Bearer ${token}` } }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Username + password (for login-page flows)
|
|
57
|
+
auth: async (user) => {
|
|
58
|
+
return { credentials: { email: user.email as string, password: 'TestP@ssw0rd123!' } }
|
|
54
59
|
}
|
|
55
60
|
```
|
|
56
61
|
|
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 createNodeHandler(config) {
|
|
4
|
+
const enrichedConfig = { ...config, sdk: { ...config.sdk, server: "node" } };
|
|
4
5
|
return async (req, res) => {
|
|
5
6
|
const body = await readBody(req);
|
|
6
7
|
const headers = {};
|
|
@@ -9,7 +10,7 @@ function createNodeHandler(config) {
|
|
|
9
10
|
else if (Array.isArray(val)) headers[key] = val[0] ?? "";
|
|
10
11
|
}
|
|
11
12
|
const handlerReq = { body, headers };
|
|
12
|
-
const result = await handleRequest(
|
|
13
|
+
const result = await handleRequest(enrichedConfig, handlerReq);
|
|
13
14
|
res.writeHead(result.status, { "Content-Type": "application/json" });
|
|
14
15
|
res.end(JSON.stringify(result.body));
|
|
15
16
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from 'node:http'\nimport { handleRequest } from '@autonoma-ai/sdk'\nimport type { HandlerConfig, HandlerRequest } from '@autonoma-ai/sdk'\n\n/**\n * Create a Node.js http handler.\n *\n * @example\n * ```ts\n * import { createNodeHandler } from '@autonoma-ai/server-node'\n * import http from 'node:http'\n * http.createServer(createNodeHandler(config)).listen(3000)\n * ```\n */\nexport function createNodeHandler(config: HandlerConfig) {\n return async (req: IncomingMessage, res: ServerResponse): Promise<void> => {\n const body = await readBody(req)\n const headers: Record<string, string> = {}\n for (const [key, val] of Object.entries(req.headers)) {\n if (typeof val === 'string') headers[key] = val\n else if (Array.isArray(val)) headers[key] = val[0] ?? ''\n }\n\n const handlerReq: HandlerRequest = { body, headers }\n const result = await handleRequest(
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from 'node:http'\nimport { handleRequest } from '@autonoma-ai/sdk'\nimport type { HandlerConfig, HandlerRequest } from '@autonoma-ai/sdk'\n\n/**\n * Create a Node.js http handler.\n *\n * @example\n * ```ts\n * import { createNodeHandler } from '@autonoma-ai/server-node'\n * import http from 'node:http'\n * http.createServer(createNodeHandler(config)).listen(3000)\n * ```\n */\nexport function createNodeHandler(config: HandlerConfig) {\n const enrichedConfig = { ...config, sdk: { ...config.sdk, server: 'node' } }\n return async (req: IncomingMessage, res: ServerResponse): Promise<void> => {\n const body = await readBody(req)\n const headers: Record<string, string> = {}\n for (const [key, val] of Object.entries(req.headers)) {\n if (typeof val === 'string') headers[key] = val\n else if (Array.isArray(val)) headers[key] = val[0] ?? ''\n }\n\n const handlerReq: HandlerRequest = { body, headers }\n const result = await handleRequest(enrichedConfig, handlerReq)\n\n res.writeHead(result.status, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(result.body))\n }\n}\n\nfunction readBody(req: IncomingMessage): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = []\n req.on('data', (chunk: Buffer) => chunks.push(chunk))\n req.on('end', () => resolve(Buffer.concat(chunks).toString()))\n req.on('error', reject)\n })\n}\n"],"mappings":";AACA,SAAS,qBAAqB;AAavB,SAAS,kBAAkB,QAAuB;AACvD,QAAM,iBAAiB,EAAE,GAAG,QAAQ,KAAK,EAAE,GAAG,OAAO,KAAK,QAAQ,OAAO,EAAE;AAC3E,SAAO,OAAO,KAAsB,QAAuC;AACzE,UAAM,OAAO,MAAM,SAAS,GAAG;AAC/B,UAAM,UAAkC,CAAC;AACzC,eAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAQ,IAAI,OAAO,GAAG;AACpD,UAAI,OAAO,QAAQ,SAAU,SAAQ,GAAG,IAAI;AAAA,eACnC,MAAM,QAAQ,GAAG,EAAG,SAAQ,GAAG,IAAI,IAAI,CAAC,KAAK;AAAA,IACxD;AAEA,UAAM,aAA6B,EAAE,MAAM,QAAQ;AACnD,UAAM,SAAS,MAAM,cAAc,gBAAgB,UAAU;AAE7D,QAAI,UAAU,OAAO,QAAQ,EAAE,gBAAgB,mBAAmB,CAAC;AACnE,QAAI,IAAI,KAAK,UAAU,OAAO,IAAI,CAAC;AAAA,EACrC;AACF;AAEA,SAAS,SAAS,KAAuC;AACvD,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAmB,CAAC;AAC1B,QAAI,GAAG,QAAQ,CAAC,UAAkB,OAAO,KAAK,KAAK,CAAC;AACpD,QAAI,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,MAAM,EAAE,SAAS,CAAC,CAAC;AAC7D,QAAI,GAAG,SAAS,MAAM;AAAA,EACxB,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonoma-ai/server-node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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.
|
|
19
|
+
"@autonoma-ai/sdk": "0.1.4"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^22.0.0",
|