tokensafe-backend-node 0.0.0-stage → 0.2.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 CHANGED
@@ -1,3 +1,76 @@
1
- # Temporary Holding Version
1
+ # tokensafe-backend-node
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ OUMV adapter for Node.js backends — **Express** and **Fastify** — sharing one
4
+ framework-neutral runtime, so every Node framework answers the same wire shapes
5
+ (spec §4) and certifies identically.
6
+
7
+ ```bash
8
+ npm install tokensafe-backend-node
9
+ ```
10
+
11
+ ## Express
12
+
13
+ ```ts
14
+ import express from 'express';
15
+ import { OumvRuntime, mountTokensafe, tracingMiddleware } from 'tokensafe-backend-node';
16
+
17
+ const app = express();
18
+ const runtime = new OumvRuntime({ workspaceDir: process.cwd() });
19
+ app.use(tracingMiddleware(runtime)); // L4 traces for every request
20
+ app.get('/api/orders', async () => ({ orders: [] }));
21
+ const oumv = mountTokensafe(app, { runtime, publicUrl: 'http://127.0.0.1:3000/__oumv/rpc' });
22
+ const server = app.listen(3000);
23
+ const ws = oumv.attachWebSocket(server); // optional, spec §2.4
24
+ ```
25
+
26
+ ## Fastify
27
+
28
+ ```ts
29
+ import Fastify from 'fastify';
30
+ import { OumvRuntime, registerTokensafe } from 'tokensafe-backend-node';
31
+
32
+ const app = Fastify();
33
+ const oumv = await registerTokensafe(app, { runtime: new OumvRuntime({ workspaceDir: process.cwd() }) });
34
+ app.get('/api/orders', async () => ({ orders: [] })); // captured by the onRoute hook
35
+ await app.listen({ port: 3000 });
36
+ const ws = oumv.attachWebSocket();
37
+ ```
38
+
39
+ ## What it implements
40
+
41
+ | Pillar | Behaviour |
42
+ | :--- | :--- |
43
+ | observe | L0 pulse, L1 route surface, L2 route contract, L3 source + sha256 OCC token, L4 trace ring |
44
+ | understand | impact from the registered route table, causality from real traces (`observed: false` + note when there are none) |
45
+ | mutate | `getSource`/`applyEdit` with mandatory `expectedVersion`, guarded in the normative order `-32003 → -32009 → -32002 → -32011 → -32001`; backups under `.tokensafe/backups/` |
46
+ | verify | loopback HTTP dispatch against the live handler with `timings`/`durationMs`/`scope`, and the result feeds the L4 ring |
47
+ | transports | HTTP POST + batch, SSE (`GET …/events`, `Last-Event-ID`), WebSocket upgrade on `/__oumv/rpc`, stdio NDJSON |
48
+ | discovery | `~/.tokensafe/runtimes/<hash16>.json` registry entry (0600, outside the repo), profile-keyed |
49
+
50
+ ## stdio (headless)
51
+
52
+ Same runtime, no listener:
53
+
54
+ ```bash
55
+ tokensafe-oumv-stdio --workspace /path/to/app
56
+ tokensafe-oumv-stdio --app ./src/app.js --workspace /path/to/app # Express or Fastify
57
+ ```
58
+
59
+ One JSON-RPC object per line, responses on stdout, diagnostics on stderr. With
60
+ `--app` the module's default export is mounted (routes + in-process verify work);
61
+ without it, the file-based pillar (`observe L3`, `getSource`, `applyEdit`) still does.
62
+
63
+ ## Certification
64
+
65
+ ```bash
66
+ CERT_OUT_DIR=../certification OUMV_REPO=../../agent-oumv pnpm test
67
+ ```
68
+
69
+ The fixture suite (owner: `tokensafe-dev/oumv`) runs over real HTTP against both
70
+ adapters and over stdio against the shared runtime. Committed reports:
71
+ `../certification/node-express.json`, `node-fastify.json` (Level 3, 20/20,
72
+ fixtureVersion 5) and `../certification/transports/node-stdio.json` (Level 3, 20/20).
73
+
74
+ Notes: paths are workspace-jailed and credential files are refused; a Node backend
75
+ adapter is development-time tooling and must not be exposed publicly without the
76
+ session token.