Something went wrong. Try again.
An Atmosphere in a box
Something went wrong. Try again.
README.md
@vivarium-dev/plugin #
The contract for plugins that run inside a vivarium box: types, definePlugin(), and a few stateless response helpers.
A plugin runs in-process on Bun and gets the box's plumbing through Ctx:
- the relay's firehose, in-process (so
awaitCaughtUpcovers it); - identity resolution and read access to every repo in the atmosphere;
- its own sqlite tables;
- a service identity of its own, stable across resets, plus
verifyServiceAuthfor the service JWTs addressed to it.
That's enough to build an appview:
import { definePlugin, json, xrpcError } from '@vivarium-dev/plugin'
export default definePlugin((options: { greeting: string }) => ({
name: 'myapp',
// Everything under the namespace is ours.
methods: ['com.example.myapp.*'],
// A local account myapp.<domain> whose DID document lists #myapp_appview
// at the box: clients reach it with `atproto-proxy: <ctx.did>#myapp_appview`.
services: [{ id: 'myapp_appview', type: 'MyAppView' }],
// Signed-in calls without an atproto-proxy header come here through the
// PDS (with a service JWT), as a real PDS forwards to its default appview.
defaultFor: ['com.example.myapp.*'],
start(ctx) {
ctx.subscribe((evt) => { /* JSON-form events from every PDS, in order */ })
},
async handle(req, ctx) {
if (new URL(req.url).pathname !== '/xrpc/com.example.myapp.hello') return null
const { iss } = await ctx.verifyServiceAuth(req, { lxm: 'com.example.myapp.hello' })
return json({ message: `${options.greeting}, ${iss}` })
},
reset() {},
}))
Errors from verifyServiceAuth are matched with isServiceAuthError(err) (by name, since your copy of this package and the box's may differ). Publish a plugin as an npm package with @vivarium-dev/plugin as a peer dependency.