@peac/middleware-express 0.12.5 → 0.12.7

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 +48 -26
  2. package/package.json +17 -5
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @peac/middleware-express
2
2
 
3
- Express.js middleware for automatic PEAC receipt issuance.
3
+ Express.js middleware for automatic PEAC receipt issuance. Adds signed receipts to HTTP responses with zero application code changes.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,7 +10,13 @@ pnpm add @peac/middleware-express
10
10
 
11
11
  Requires Express as a peer dependency (`^4.18.0 || ^5.0.0`).
12
12
 
13
- ## Quick Start
13
+ ## What It Does
14
+
15
+ `@peac/middleware-express` is an Express.js middleware that automatically attaches signed PEAC receipts to HTTP responses. It wraps `@peac/middleware-core` with Express-specific request/response handling, route skipping, and error isolation. Receipt generation failures never break the HTTP response.
16
+
17
+ ## How Do I Use It?
18
+
19
+ ### Add receipt issuance to an Express app
14
20
 
15
21
  ```typescript
16
22
  import express from 'express';
@@ -28,6 +34,7 @@ app.use(
28
34
  d: '<base64url private key>',
29
35
  },
30
36
  keyId: 'prod-2026-02',
37
+ skip: (req) => req.path === '/health',
31
38
  })
32
39
  );
33
40
 
@@ -37,45 +44,60 @@ app.get('/api/data', (req, res) => {
37
44
  });
38
45
  ```
39
46
 
40
- ## API
41
-
42
- ### `peacMiddleware(config)`
43
-
44
- Returns Express middleware that automatically adds PEAC receipts to responses.
47
+ ### Check receipt context on a request
45
48
 
46
49
  ```typescript
47
- interface ExpressMiddlewareConfig extends MiddlewareConfig {
48
- skip?: (req: Request) => boolean;
49
- audienceExtractor?: (req: Request) => string;
50
- subjectExtractor?: (req: Request) => string | undefined;
51
- onError?: (error: Error, req: Request, res: Response) => void;
50
+ import { hasPeacContext, getReceiptFromResponse } from '@peac/middleware-express';
51
+ import type { RequestWithPeacContext } from '@peac/middleware-express';
52
+
53
+ if (hasPeacContext(req)) {
54
+ // Request has PEAC context attached by middleware
52
55
  }
56
+
57
+ // Extract receipt from response (useful for testing)
58
+ const receipt = getReceiptFromResponse(res);
53
59
  ```
54
60
 
55
- ### `peacMiddlewareSync(config)`
61
+ ### Use the synchronous variant
56
62
 
57
- Synchronous variant for simpler setups where async signing is not needed.
63
+ ```typescript
64
+ import { peacMiddlewareSync } from '@peac/middleware-express';
65
+
66
+ app.use(
67
+ peacMiddlewareSync({
68
+ issuer: 'https://api.example.com',
69
+ signingKey: privateJwk,
70
+ keyId: 'prod-2026-02',
71
+ })
72
+ );
73
+ ```
58
74
 
59
- ### `getReceiptFromResponse(res)`
75
+ ## Integrates With
60
76
 
61
- Extract the PEAC receipt from a response (for testing/debugging).
77
+ - `@peac/middleware-core`: Framework-agnostic primitives (signing, transport, config validation)
78
+ - `@peac/kernel` (Layer 0): Types and constants (via middleware-core)
79
+ - `@peac/schema` (Layer 1): Zod validators (via middleware-core)
80
+ - `@peac/crypto` (Layer 2): Ed25519 signing (via middleware-core)
62
81
 
63
- ### `hasPeacContext(req)`
82
+ ## For Agent Developers
64
83
 
65
- Type guard checking if the request has PEAC context attached.
84
+ If you are building an AI agent or service that issues receipts:
66
85
 
67
- ## Configuration Options
86
+ - Add `peacMiddleware()` to your Express app and receipts are issued automatically
87
+ - Use `@peac/middleware-core` directly for non-Express frameworks
88
+ - Use `@peac/protocol` for lower-level receipt issuance without HTTP middleware
89
+ - See the [llms.txt](https://github.com/peacprotocol/peac/blob/main/llms.txt) for a concise overview
68
90
 
69
- - **`skip`**: Skip receipt generation for certain routes (e.g., health checks)
70
- - **`audienceExtractor`**: Custom audience extraction from request (default: request origin)
71
- - **`subjectExtractor`**: Custom subject extraction from request
72
- - **`onError`**: Error handler for receipt generation failures (failures never break the response)
91
+ ## For Operators
73
92
 
74
- All options from `@peac/middleware-core` `MiddlewareConfig` are also supported (issuer, signingKey, keyId, expiresIn, transport, maxHeaderSize).
93
+ All `@peac/middleware-core` configuration options are supported (issuer, signingKey, keyId, expiresIn, transport, maxHeaderSize). Additional Express-specific options:
75
94
 
76
- ## Error Handling
95
+ - **`skip`**: predicate function to skip receipt generation for certain routes (such as health checks)
96
+ - **`audienceExtractor`**: custom audience extraction from the request (default: request origin)
97
+ - **`subjectExtractor`**: custom subject extraction from the request
98
+ - **`onError`**: custom error handler for receipt generation failures (default: console logging)
77
99
 
78
- Receipt generation failures are isolated: they never break the HTTP response. By default, errors are logged to console. Provide an `onError` callback for custom handling.
100
+ Receipt generation failures are isolated and never break the HTTP response.
79
101
 
80
102
  ## License
81
103
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peac/middleware-express",
3
- "version": "0.12.5",
3
+ "version": "0.12.7",
4
4
  "description": "Express.js middleware for automatic PEAC receipt issuance",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/index.d.ts",
@@ -15,10 +15,10 @@
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://github.com/peacprotocol/peac.git",
18
+ "url": "git+https://github.com/peacprotocol/peac.git",
19
19
  "directory": "packages/middleware-express"
20
20
  },
21
- "author": "jithinraj <7850727+jithinraj@users.noreply.github.com>",
21
+ "author": "PEAC Protocol Contributors",
22
22
  "license": "Apache-2.0",
23
23
  "bugs": {
24
24
  "url": "https://github.com/peacprotocol/peac/issues"
@@ -33,7 +33,7 @@
33
33
  "provenance": true
34
34
  },
35
35
  "dependencies": {
36
- "@peac/middleware-core": "0.12.5"
36
+ "@peac/middleware-core": "0.12.7"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "express": "^4.18.0 || ^5.0.0"
@@ -47,8 +47,20 @@
47
47
  "typescript": "^5.3.3",
48
48
  "vitest": "^4.0.0",
49
49
  "tsup": "^8.0.0",
50
- "@peac/crypto": "0.12.5"
50
+ "@peac/crypto": "0.12.7"
51
51
  },
52
+ "keywords": [
53
+ "peac",
54
+ "peacprotocol",
55
+ "interaction-records",
56
+ "signed-records",
57
+ "receipts",
58
+ "originary",
59
+ "express",
60
+ "middleware",
61
+ "receipt-header",
62
+ "node-http"
63
+ ],
52
64
  "scripts": {
53
65
  "prebuild": "rm -rf dist tsconfig.tsbuildinfo",
54
66
  "build": "pnpm run build:js && pnpm run build:types",