// 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 --did \ // --collection app.bsky.graph.follow --op create --subject --write // bun lib/scripts/dev-jetstream-event.ts --as --did \ // --collection app.bsky.graph.follow --op delete --rkey --write // bun lib/scripts/dev-jetstream-event.ts --as --did \ // --collection sh.tangled.actor.profile --op create --rkey self // // `--record ''` 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) : undefined; const port = process.env.PORT ?? "5176"; const secret = process.env.COOKIE_SECRET; if (!as || !did || !collection || !operation || !secret) { console.error( "usage: --as --did --collection --op create|delete [--rkey ] [--subject ] [--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);