@aegislog/express 0.2.1 → 0.2.3

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 +75 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # @aegislog/express 🚂
2
+
3
+ Express request/response lifecycle middleware and ambient context propagation adapter for [AegisLog](https://github.com/syedmuzamilm/aegislog).
4
+
5
+ ---
6
+
7
+ ## 📦 Installation
8
+
9
+ ```bash
10
+ pnpm add @aegislog/express aegislog
11
+ # or
12
+ npm install @aegislog/express aegislog
13
+ ```
14
+
15
+ ---
16
+
17
+ ## 🚀 Quickstart
18
+
19
+ ```typescript
20
+ import express from "express";
21
+ import { aegisExpressMiddleware } from "@aegislog/express";
22
+ import { logger, audit } from "aegislog";
23
+
24
+ const app = express();
25
+ app.use(express.json());
26
+
27
+ // Attach AegisLog middleware
28
+ app.use(
29
+ aegisExpressMiddleware({
30
+ logRequests: true,
31
+ getActor: (req) => {
32
+ const auth = req.headers.authorization;
33
+ return auth ? { id: "usr_sarah", email: "sarah@acme.com", role: "admin" } : undefined;
34
+ },
35
+ getTenant: (req) => {
36
+ const tenant = req.headers["x-tenant-id"] as string;
37
+ return tenant ? { id: tenant, slug: "acme-corp" } : undefined;
38
+ },
39
+ }),
40
+ );
41
+
42
+ app.post("/api/checkout", async (req, res) => {
43
+ // Sarah's user/tenant context and requestId are automatically attached!
44
+ logger.info("Processing checkout", { amount: req.body.amount });
45
+
46
+ await audit.record({
47
+ action: "billing.checkout_completed",
48
+ resource: { type: "order", id: "ord_123" },
49
+ outcome: "success",
50
+ });
51
+
52
+ res.json({ success: true });
53
+ });
54
+
55
+ app.listen(3000, () => {
56
+ logger.info("Express server running on http://localhost:3000");
57
+ });
58
+ ```
59
+
60
+ ---
61
+
62
+ ## ⚙️ Options (`ExpressAegisOptions`)
63
+
64
+ | Option | Type | Description |
65
+ | :------------ | :---------------------------------------------------------- | :--------------------------------------------------------------------------------- |
66
+ | `logger` | `AegisLogger` | Custom logger instance to use (default: global `logger`). |
67
+ | `logRequests` | `boolean` | Log inbound requests and outbound response status with duration (default: `true`). |
68
+ | `getActor` | `(req: Request) => ActorContext \| Promise<ActorContext>` | Extract authenticated user info from the request. |
69
+ | `getTenant` | `(req: Request) => TenantContext \| Promise<TenantContext>` | Extract organization/tenant info from headers or session. |
70
+
71
+ ---
72
+
73
+ ## 📄 License
74
+
75
+ MIT © [AegisLog Contributors](https://github.com/syedmuzamilm/aegislog)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aegislog/express",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Express middleware adapter for AegisLog.",
5
5
  "homepage": "https://github.com/syedmuzamilm/aegislog#readme",
6
6
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "aegislog": "0.2.1"
32
+ "aegislog": "0.2.3"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/express": "^5.0.0",