{"_id":"@affordant/server","name":"@affordant/server","dist-tags":{"latest":"0.2.0"},"versions":{"0.2.0":{"name":"@affordant/server","version":"0.2.0","description":"Server-side builder for the Affordant hypermedia envelope. Framework-agnostic: declare affordances once, gate them on state, emit _self / _actions that the affordant client consumes.","license":"MIT","author":{"name":"Florian Leroy"},"repository":{"type":"git","url":"git+https://github.com/Leroy-Florian/Affordant.git","directory":"packages/server"},"homepage":"https://leroy-florian.github.io/Affordant/","bugs":{"url":"https://github.com/Leroy-Florian/Affordant/issues"},"keywords":["hateoas","hypermedia","affordance","rest","server","node"],"type":"module","sideEffects":false,"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"publishConfig":{"access":"public"},"dependencies":{"@affordant/contract":"^0.2.0"},"scripts":{"build":"node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json","typecheck":"tsc -p tsconfig.json","test":"vitest run"},"_id":"@affordant/server@0.2.0","gitHead":"f6e1abef80c7cbbf221fc6781d60c66a683cc7a9","_nodeVersion":"20.20.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-RdsS/gRJbNgQihkuZ04FQ71649ZXZmgT9rE4x8/EyL1NwODvsVVfgCWCDVG9ysw8pnoGVUBg0Drzakivr2WtDw==","shasum":"5fb4715d5b27185d9cb8715099201382fba5baea","tarball":"https://registry.npmjs.org/@affordant/server/-/server-0.2.0.tgz","fileCount":10,"unpackedSize":8693,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@affordant%2fserver@0.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC9283z4+rm/1qqeEB/4yhzWayiRsV3jRd4K3LCv93t+QIhAJ8GcwAscKGQfLIDmMKVjTEt/mBxaZzf/LQdyA8fS8qG"}]},"_npmUser":{"name":"hijoxx","email":"floroy32@gmail.com"},"directories":{},"maintainers":[{"name":"hijoxx","email":"floroy32@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/server_0.2.0_1780691935839_0.681827769471866"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-05T20:38:55.715Z","0.2.0":"2026-06-05T20:38:56.018Z","modified":"2026-06-05T20:38:56.377Z"},"maintainers":[{"name":"hijoxx","email":"floroy32@gmail.com"}],"description":"Server-side builder for the Affordant hypermedia envelope. Framework-agnostic: declare affordances once, gate them on state, emit _self / _actions that the affordant client consumes.","homepage":"https://leroy-florian.github.io/Affordant/","keywords":["hateoas","hypermedia","affordance","rest","server","node"],"repository":{"type":"git","url":"git+https://github.com/Leroy-Florian/Affordant.git","directory":"packages/server"},"author":{"name":"Florian Leroy"},"bugs":{"url":"https://github.com/Leroy-Florian/Affordant/issues"},"license":"MIT","readme":"# @affordant/server\n\nServer-side builder for the **Affordant** hypermedia envelope. It is the mirror of the [`affordant`](https://www.npmjs.com/package/affordant) client: where the client asks `can(resource, rel)`, the server declares each affordance once and gates it on authoritative state.\n\nFramework-agnostic and zero runtime dependency (it shares only the [`@affordant/contract`](https://www.npmjs.com/package/@affordant/contract) types). URL generation is *injected*, so it stays decoupled from any router — thin adapters such as [`@affordant/express`](https://www.npmjs.com/package/@affordant/express) wire that part up.\n\n## Install\n\n```sh\nnpm install @affordant/server\n```\n\n## Usage\n\n```ts\nimport { resource } from '@affordant/server'\n\nfunction serializeOrder(order, caller, route) {\n  return resource(order)\n    .self(route('orders.show', order.id))\n    .action('track', route('orders.tracking', order.id))\n    .action('cancel', route('orders.cancel', order.id), {\n      method: 'POST',\n      when: caller.id === order.ownerId && order.status !== 'shipped',\n    })\n    .build()\n}\n```\n\nThe result is exactly what `can(order, 'cancel')` consumes on the client. When `when` is `false`, the rel is **not emitted** — so the client never offers it. Presence of the link *is* the permission.\n\n## API\n\n| Export | Description |\n|---|---|\n| `resource(data)` | Start a builder over a plain object. |\n| `.self(href, { method? })` | Set the `_self` link (method defaults to `GET`). |\n| `.action(rel, href, { method?, accepts?, when? })` | Offer `rel`. `when: false` omits it. `method` defaults to `GET`. |\n| `.build()` | Return the `_self` / `_actions` wire resource. `_actions` is always present. |\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-35e797e58ee739a840d95114a048616f"}