@@ -20,11 +20,9 @@ const sdk = createATProtoSDK({
2020 jwksUri: " https://your-app.com/jwks.json" ,
2121 jwkPrivate: process .env .ATPROTO_JWK_PRIVATE ! ,
2222 },
23- // set up with your pds url.
24- // entryway doesn't work for this. Has to be a PDS URL.
25- servers: {
26- pds: " https://pds-eu-west4.test.certified.app" ,
27- },
23+ // Optional: URL for handle resolution during OAuth.
24+ // If omitted, DNS-based resolution is used.
25+ handleResolver: " https://pds-eu-west4.test.certified.app" ,
2826});
2927
3028// 2. Authenticate user
@@ -80,10 +78,8 @@ const sdk = createATProtoSDK({
8078 // Optional: suppress warnings
8179 developmentMode: true ,
8280 },
83- servers: {
84- // Point to local PDS for testing
85- pds: " http://localhost:2583" ,
86- },
81+ // Optional: handle resolver for local testing
82+ handleResolver: " http://localhost:2583" ,
8783 logger: console , // Enable debug logging
8884});
8985
@@ -155,17 +151,17 @@ The SDK supports two types of AT Protocol servers:
155151- ** Purpose** : User's own data storage (e.g., Bluesky)
156152- ** Use case** : Individual hypercerts, personal records
157153- ** Features** : Profile management, basic CRUD operations
158- - ** Example ** : ` bsky.social ` , any Bluesky PDS
154+ - ** Auto-detected ** : The SDK automatically discovers the user's PDS from the OAuth session -- no configuration needed
159155
160156#### Shared Data Server (SDS)
161157
162158- ** Purpose** : Collaborative data storage with access control
163159- ** Use case** : Organization hypercerts, team collaboration
164160- ** Features** : Organizations, multi-user access, role-based permissions
165- - ** Example ** : ` sds.hypercerts.org `
161+ - ** Configured via ** : ` servers.sds ` in SDK config
166162
167163``` typescript
168- // Connect to user's PDS (default)
164+ // Connect to user's PDS (default) -- auto-detected from session
169165const pdsRepo = sdk .repository (session );
170166await pdsRepo .hypercerts .create ({ ... }); // Creates in user's PDS
171167
@@ -179,20 +175,34 @@ const orgRepo = sdsRepo.repo(orgs.organizations[0].did);
179175await orgRepo .hypercerts .list (); // Queries organization's hypercerts on SDS
180176```
181177
178+ #### How PDS Auto-Detection Works
179+
180+ The SDK automatically discovers each user's PDS URL from their OAuth session. You do not need to configure a PDS URL.
181+
182+ 1 . ** During authentication** (` callback() ` or ` restoreSession() ` ), the SDK extracts the user's PDS URL from the OAuth
183+ token's ` aud ` field, which is resolved from the user's DID Document.
184+
185+ 2 . ** When creating a repository** (` sdk.repository(session) ` ), the SDK uses the cached PDS URL for that session's DID.
186+
187+ 3 . ** For sessions created outside the SDK** , you can manually resolve the PDS:
188+ ``` typescript
189+ await sdk .resolveSessionPds (session );
190+ ```
191+
182192#### How Repository Routing Works
183193
184194The SDK uses a ` ConfigurableAgent ` to route requests to different servers while maintaining your OAuth authentication:
185195
1861961 . ** Initial Repository Creation**
187197
188198 ``` typescript
189- // User authenticates (OAuth session knows user's PDS)
199+ // User authenticates -- PDS URL is automatically cached from the session
190200 const session = await sdk .callback (params );
191201
192- // Create PDS repository - routes to user's PDS
202+ // Create PDS repository -- routes to user's auto-detected PDS
193203 const pdsRepo = sdk .repository (session );
194204
195- // Create SDS repository - routes to SDS server
205+ // Create SDS repository -- routes to configured SDS server
196206 const sdsRepo = sdk .repository (session , { server: " sds" });
197207 ```
198208
@@ -206,21 +216,22 @@ The SDK uses a `ConfigurableAgent` to route requests to different servers while
206216 const orgRepo = userSdsRepo .repo (" did:plc:org-did" );
207217
208218 // All operations on orgRepo still route to SDS, not user's PDS
209- await orgRepo .hypercerts .list (); // ✅ Queries SDS
210- await orgRepo .collaborators .list (); // ✅ Queries SDS
219+ await orgRepo .hypercerts .list (); // Queries SDS
220+ await orgRepo .collaborators .list (); // Queries SDS
211221 ```
212222
2132233 . ** Key Implementation Details**
214224 - Each Repository uses a ` ConfigurableAgent ` that wraps your OAuth session's fetch handler
215225 - The agent routes all requests to the specified server URL (PDS, SDS, or custom)
226+ - The user's PDS URL is auto-detected from the OAuth session's token info (` tokenInfo.aud ` )
216227 - When you call ` .repo(did) ` , a new Repository is created with the same server configuration
217228 - Your OAuth session provides authentication (DPoP, access tokens), while the agent handles routing
218229 - This enables simultaneous connections to multiple servers with one authentication session
219230
220231#### Common Patterns
221232
222233``` typescript
223- // Pattern 1: Personal hypercerts on PDS
234+ // Pattern 1: Personal hypercerts on PDS (auto-detected)
224235const myRepo = sdk .repository (session );
225236await myRepo .hypercerts .create ({ title: " My Personal Impact" });
226237
0 commit comments