The firehose test script creates posts and subscribes to the event stream to verify everything works.
Make sure you have your .dev.vars file set up with:
DID=did:web:pds.mk.gg
HANDLE=your-handle.bsky.social
PDS_HOSTNAME=pds.mk.gg
AUTH_TOKEN=your-secret-token
SIGNING_KEY=your-signing-key
SIGNING_KEY_PUBLIC=your-public-key# Run the automated test
node scripts/test-firehose.jsThis will:
- Create 3 initial test posts
- Subscribe to the firehose from cursor 0 (should backfill those posts)
- Create 2 more posts while subscribed (should see in real-time)
- Delete one post (should see delete event)
- Show all 6 events received
# Install wscat
npm install -g wscat
# Connect to firehose
wscat -c "wss://pds.mk.gg/xrpc/com.atproto.sync.subscribeRepos"
# Or with cursor to backfill from beginning
wscat -c "wss://pds.mk.gg/xrpc/com.atproto.sync.subscribeRepos?cursor=0"In another terminal, create a post:
curl -X POST https://pds.mk.gg/xrpc/com.atproto.repo.createRecord \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"repo": "did:web:pds.mk.gg",
"collection": "app.bsky.feed.post",
"record": {
"text": "Testing the firehose!",
"createdAt": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}
}'You should see the event appear on the WebSocket connection!
curl -X POST https://pds.mk.gg/xrpc/com.atproto.repo.createRecord \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"repo": "did:web:pds.mk.gg",
"collection": "app.bsky.feed.post",
"record": {
"text": "Hello, World!",
"createdAt": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}
}'curl "https://pds.mk.gg/xrpc/com.atproto.repo.listRecords?repo=did:web:pds.mk.gg&collection=app.bsky.feed.post"# Use the rkey from creating the post
curl "https://pds.mk.gg/xrpc/com.atproto.repo.getRecord?repo=did:web:pds.mk.gg&collection=app.bsky.feed.post&rkey=YOUR_RKEY"curl -X POST https://pds.mk.gg/xrpc/com.atproto.repo.deleteRecord \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"repo": "did:web:pds.mk.gg",
"collection": "app.bsky.feed.post",
"rkey": "YOUR_RKEY"
}'curl "https://pds.mk.gg/xrpc/com.atproto.sync.getRepo?did=did:web:pds.mk.gg" > repo.carcurl "https://pds.mk.gg/xrpc/com.atproto.sync.getRepoStatus?did=did:web:pds.mk.gg"# Run all tests
pnpm test
# Run in watch mode
pnpm test --watch
# Run specific test file
pnpm test storage.test.ts# Install AT Protocol dev tools
npm install -g @atproto/dev-env
# Subscribe to your firehose
atproto subscribe wss://pds.mk.gg/xrpc/com.atproto.sync.subscribeReposEach WebSocket frame contains two concatenated CBOR objects:
Header:
{ op: 1, t: "#commit" } // Normal commit
{ op: -1 } // ErrorBody (commit event):
{
seq: 123, // Sequence number
repo: "did:web:...", // Repository DID
commit: CID, // Commit CID
rev: "...", // Revision
since: "...", // Previous revision
blocks: Uint8Array, // CAR file with blocks
ops: [ // Operations
{
action: "create", // or "update", "delete"
path: "app.bsky.feed.post/abc123",
cid: CID // null for deletes
}
],
blobs: [], // Referenced blobs
time: "2024-01-01T00:00:00Z"
}