a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm
101
fork

Configure Feed

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

docs(xrpc-server): remove kitchen sink example

Mary 4863caa3 276bffbd

-84
-84
packages/servers/xrpc-server/README.md
··· 91 91 }, 92 92 ); 93 93 ``` 94 - 95 - ## kitchen sink 96 - 97 - ### Bluesky feed generator example 98 - 99 - ```ts 100 - import { parseCanonicalResourceUri, type Nsid } from '@atcute/lexicons'; 101 - 102 - import { AuthRequiredError, InvalidRequestError, XRPCRouter, json } from '@atcute/xrpc-server'; 103 - import { ServiceJwtVerifier, type VerifiedJwt } from '@atcute/xrpc-server/auth'; 104 - import { cors } from '@atucte/xrpc-server/middlewares/cors'; 105 - 106 - import { 107 - CompositeDidDocumentResolver, 108 - PlcDidDocumentResolver, 109 - WebDidDocumentResolver, 110 - } from '@atcute/identity-resolver'; 111 - 112 - import { AppBskyFeedGetFeedSkeleton } from '@atcute/bluesky'; 113 - 114 - const SERVICE_DID = 'did:web:feedgen.example.com'; 115 - 116 - const router = new XRPCRouter({ 117 - middlewares: [cors()], 118 - }); 119 - 120 - const jwtVerifier = new ServiceJwtVerifier({ 121 - serviceDid: SERVICE_DID, 122 - resolver: new CompositeDidDocumentResolver({ 123 - methods: { 124 - plc: new PlcDidDocumentResolver(), 125 - web: new WebDidDocumentResolver(), 126 - }, 127 - }), 128 - }); 129 - 130 - const requireAuth = async (request: Request, lxm: Nsid): Promise<VerifiedJwt> => { 131 - const auth = request.headers.get('authorization'); 132 - if (auth === null) { 133 - throw new AuthRequiredError({ description: `missing authorization header` }); 134 - } 135 - if (!auth.startsWith('Bearer ')) { 136 - throw new AuthRequiredError({ description: `invalid authorization scheme` }); 137 - } 138 - 139 - const jwtString = auth.slice('Bearer '.length).trim(); 140 - 141 - const result = await jwtVerifier.verify(jwtString, { lxm }); 142 - if (!result.ok) { 143 - throw new AuthRequiredError(result.error); 144 - } 145 - 146 - return result.value; 147 - }; 148 - 149 - router.add(AppBskyFeedGetFeedSkeleton.mainSchema, { 150 - async handler({ params: { feed }, request }) { 151 - await requireAuth(request, 'app.bsky.feed.getFeedSkeleton'); 152 - 153 - const feedUri = parseCanonicalResourceUri(feed); 154 - 155 - if ( 156 - !feedUri.ok || 157 - feedUri.value.collection !== 'app.bsky.feed.generator' || 158 - feedUri.value.repo !== SERVICE_DID || 159 - feedUri.value.rkey !== 'feed' 160 - ) { 161 - throw new InvalidRequestError({ 162 - error: 'InvalidFeed', 163 - description: `invalid feed`, 164 - }); 165 - } 166 - 167 - return json({ 168 - feed: [ 169 - { post: 'at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.post/3l6oveex3ii2l' }, 170 - { post: 'at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.post/3lpk2lf7k6k2t' }, 171 - ], 172 - }); 173 - }, 174 - }); 175 - 176 - export default router; 177 - ```