Something went wrong. Try again.
Automations and webhooks for the AT Protocol airglow.run
automation webhook atproto atprotocol
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455// Dev-only: inject a Jetstream commit into the running dev server, which the// public Jetstream never delivers for accounts on the local PDS.//// bun lib/scripts/dev-jetstream-event.ts --as <admin-did> --did <did> \// --collection app.bsky.graph.follow --op create --subject <did> --write// bun lib/scripts/dev-jetstream-event.ts --as <admin-did> --did <did> \// --collection app.bsky.graph.follow --op delete --rkey <rkey> --write// bun lib/scripts/dev-jetstream-event.ts --as <admin-did> --did <did> \// --collection sh.tangled.actor.profile --op create --rkey self//// `--record '<json>'` dispatches that record without reading the PDS, or with// `--write` writes it as-is (at `--rkey` when given), e.g. a profile at "self".// `--write` performs the follow or unfollow on the local PDS first, through// the account's Airglow OAuth session. `--as` must be an admin DID; the script// signs a session cookie for it with COOKIE_SECRET from .env.
import { serializeSigned } from "hono/utils/cookie";
function arg(name: string): string | undefined { const i = process.argv.indexOf(`--${name}`); return i === -1 ? undefined : process.argv[i + 1];}
const as = arg("as");const did = arg("did");const collection = arg("collection");const operation = arg("op");const rkey = arg("rkey");const subject = arg("subject");const write = process.argv.includes("--write");const recordArg = arg("record");const record = recordArg ? (JSON.parse(recordArg) as Record<string, unknown>) : undefined;const port = process.env.PORT ?? "5176";const secret = process.env.COOKIE_SECRET;
if (!as || !did || !collection || !operation || !secret) { console.error( "usage: --as <admin-did> --did <did> --collection <nsid> --op create|delete [--rkey <rkey>] [--subject <did>] [--write]", ); process.exit(1);}
const cookie = await serializeSigned("airglow_session", as, secret, { path: "/" });const res = await fetch(`http://127.0.0.1:${port}/api/admin/jetstream-inject`, { method: "POST", headers: { "Content-Type": "application/json", "X-Airglow-Action": "inject-jetstream-event", Cookie: cookie.split(";")[0]!, }, body: JSON.stringify({ did, collection, operation, rkey, subject, write, record }),});console.log(res.status, JSON.stringify(await res.json(), null, 2));process.exit(res.ok ? 0 : 1);