Suite of AT Protocol TypeScript libraries built on web standards
20
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 73 lines 2.5 kB view raw
1/** 2 * # AT Protocol Sync Tool 3 * 4 * This module provides tools for syncing data from AT Protocol. 5 * Currently, it supports firehose (relay) subscriptions. 6 * 7 * The firehose class will spin up a websocket connection to 8 * com.atproto.sync.subscribeRepos on a given repo host 9 * (by default the Relay run by Bluesky). 10 * Each event will be parsed, authenticated, and then passed on to the 11 * supplied handleEvt which can handle indexing. 12 * On Commit events, the firehose will verify signatures and repo proofs 13 * to ensure that the event is authentic. This can be disabled with the 14 * unauthenticatedCommits flag. Similarly on Identity events, the firehose 15 * will fetch the latest DID document for the repo and do bidirectional 16 * verification on the associated handle. This can be disabled with the 17 * unauthenticatedHandles flag. 18 * 19 * Events of a certain type can be excluded using the 20 * excludeIdentity/excludeAccount/excludeCommit flags. 21 * 22 * And repo writes can be filtered down to specific collections using 23 * filterCollections. By default, all events are parsed and passed 24 * through to the handler. Note that this filtered currently happens 25 * client-side, though it is likely we will introduce server-side 26 * methods for doing so in the future. 27 * 28 * Non-fatal errors that are encountered will be passed to the required 29 * onError handler. In most cases, these can just be logged. 30 * 31 * When using the firehose class, events are processed serially. 32 * Each event must be finished being handled before the next one is parsed 33 * and authenticated. 34 * 35 * @example Simple indexing service 36 * ```typescript 37 * import { Firehose } from '@atproto/sync' 38 * import { IdResolver } from '@atproto/identity' 39 * 40 * const idResolver = new IdResolver() 41 * const firehose = new Firehose({ 42 * idResolver, 43 * service: 'wss://bsky.network', 44 * handleEvt: async (evt) => { 45 * if (evt.event === 'identity') { 46 * // ... 47 * } else if (evt.event === 'account') { 48 * // ... 49 * } else if (evt.event === 'create') { 50 * // ... 51 * } else if (evt.event === 'update') { 52 * // ... 53 * } else if (evt.event === 'delete') { 54 * // ... 55 * } 56 * }, 57 * onError: (err) => { 58 * console.error(err) 59 * }, 60 * filterCollections: ['com.myexample.app'], 61 * }) 62 * firehose.start() 63 * 64 * // on service shutdown 65 * await firehose.destroy() 66 * ``` 67 * 68 * @module 69 */ 70export * from "./runner/index.ts"; 71export * from "./firehose/index.ts"; 72export * from "./events.ts"; 73export * from "./telemetry.ts";