@datacules/agent-identity-express 0.9.0 → 0.10.0
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 +68 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="../../../assets/logo.svg" alt="Agent Identity — by Datacules LLC" width="360"/>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# `@datacules/agent-identity-express`
|
|
6
|
+
|
|
7
|
+
Express middleware for the agent-identity framework. Resolves credentials server-side and attaches the result to `req.resolvedCredential` before your route handler runs.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @datacules/agent-identity-express @datacules/agent-identity
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import express from 'express';
|
|
19
|
+
import { agentIdentityMiddleware } from '@datacules/agent-identity-express';
|
|
20
|
+
import { credentials, rules, logger } from './config';
|
|
21
|
+
|
|
22
|
+
const app = express();
|
|
23
|
+
app.use(express.json()); // required before the middleware
|
|
24
|
+
|
|
25
|
+
// Mount on any route prefix
|
|
26
|
+
app.use('/ai', agentIdentityMiddleware({ credentials, rules, logger }));
|
|
27
|
+
|
|
28
|
+
app.post('/ai/complete', (req, res) => {
|
|
29
|
+
const { ref, resolvedFor, credentialId } = req.resolvedCredential!;
|
|
30
|
+
// ref → look up the raw secret in your vault (server-side only)
|
|
31
|
+
// Never return ref or the raw secret to the client
|
|
32
|
+
res.json({ resolvedFor });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
app.listen(3000);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
agentIdentityMiddleware({
|
|
42
|
+
credentials, // Credential[] (or omit if using `store`)
|
|
43
|
+
rules, // RoutingRule[]
|
|
44
|
+
logger, // AuditLogger (optional)
|
|
45
|
+
store, // CredentialStore (alternative to credentials[])
|
|
46
|
+
contextKey: 'body.agentContext', // default: reads req.body.agentContext
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Override `contextKey` to read the context from a header or nested body field.
|
|
51
|
+
|
|
52
|
+
## TypeScript augmentation
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// src/types/express.d.ts
|
|
56
|
+
import type { ResolvedCredential } from '@datacules/agent-identity';
|
|
57
|
+
declare global {
|
|
58
|
+
namespace Express {
|
|
59
|
+
interface Request {
|
|
60
|
+
resolvedCredential?: ResolvedCredential;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
Part of the [agent-identity monorepo](https://github.com/hvrcharon1/agent-identity) by [Datacules LLC](https://datacules.com).
|