Skip to main content

SidecarClient

Struct SidecarClient 

Source
pub struct SidecarClient { /* private fields */ }
Expand description

A client for the atproto OAuth sidecar’s internal API.

This is the live path for every authed repo operation. Rather than the Rust server holding PDS tokens, it POSTs {did, action, …} to the sidecar’s /internal/repo endpoint (gated by the shared X-Internal-Secret); the sidecar restore(did)s the OAuth session — transparent DPoP + token refresh — and runs the matching XRPC call via @atproto/api. The did (plus the shared secret) is what authorizes the call; there is no bearer token on the Rust side.

It also fronts /internal/session/:id, the one-shot handoff the Rust callback uses to turn a session_id (from the sidecar’s browser redirect) into the {did, handle} it keys its own signed cookie by.

Cheap to clone (shared reqwest::Client + Arc’d config).

Implementations§

Source§

impl SidecarClient

Source

pub fn new( http: Client, public_url: impl Into<String>, internal_url: impl Into<String>, internal_secret: impl Into<String>, ) -> Self

Build a sidecar client from the shared reqwest::Client and the resolved public + internal base URLs + internal secret (from crate::config::SidecarConfig). public_url anchors the browser /login redirect; internal_url is the loopback base for the /internal/* API (they collapse to the same value in single-URL local dev).

Source

pub fn login_url(&self, handle: &str, return_to: Option<&str>) -> String

The sidecar’s public /login URL for a handle, round-tripping an opaque return value through OAuth state (used to bounce the browser back to a specific place after login). The browser is redirected here.

Source

pub async fn resolve_session( &self, session_id: &str, ) -> Result<Option<SidecarSession>>

Resolve a one-shot session_id (from the sidecar’s post-OAuth redirect) to the {did, handle} that logged in. Ok(None) on 404 SessionNotFound.

Source

pub async fn revoke_session(&self, did: &str) -> Result<RevokeResult>

Revoke a DID’s OAuth session at the sidecar: POST /internal/revoke.

This revokes the refresh + access tokens at the PDS and purges the sidecar’s stored oauth_session + app_session rows for the DID. It is idempotent — revoking a DID with no live session returns had_session: false. Called on /logout (so the cookie clear isn’t the only thing that ends the session) and on /account/delete.

Source

pub async fn list_records( &self, did: &str, collection: &str, limit: Option<u32>, cursor: Option<&str>, ) -> Result<ListRecordsResponse>

list — one page of a collection’s records for did.

Source

pub async fn list_all_records( &self, did: &str, collection: &str, ) -> Result<Vec<RecordEntry>>

Page through all records in a collection for did.

Source

pub async fn create_record<T: Serialize>( &self, did: &str, collection: &str, record: &T, ) -> Result<WriteResult>

create — create a record (server-assigned rkey). Returns its strong ref.

Source

pub async fn put_record<T: Serialize>( &self, did: &str, collection: &str, rkey: &str, record: &T, ) -> Result<WriteResult>

put — upsert a record at a known rkey. Returns its strong ref.

Source

pub async fn delete_record( &self, did: &str, collection: &str, rkey: &str, ) -> Result<()>

delete — delete a record by collection + rkey.

Source

pub async fn apply_writes(&self, did: &str, writes: &[WriteOp]) -> Result<()>

applyWrites — a batch of create/update/delete ops in one round-trip.

Source

pub async fn list_subscriptions( &self, did: &str, ) -> Result<Vec<(String, Subscription)>>

List every Subscription record in did’s repo (paged fully).

Source

pub async fn create_subscription( &self, did: &str, sub: &Subscription, ) -> Result<WriteResult>

Create a Subscription record (subscribe to a feed).

Source

pub async fn delete_subscription(&self, did: &str, rkey: &str) -> Result<()>

Delete a Subscription record by rkey (unsubscribe).

Source

pub async fn create_subscriptions_batch( &self, did: &str, subs: &[Subscription], ) -> Result<()>

Batch-create many Subscription records in one applyWrites — the OPML import path (one create op per feed, server-assigned rkeys).

Source

pub async fn list_folders(&self, did: &str) -> Result<Vec<(String, Folder)>>

List every Folder record in did’s repo.

Source

pub async fn list_saved(&self, did: &str) -> Result<Vec<(String, Saved)>>

List every Saved record in did’s repo.

Source

pub async fn list_read_states( &self, did: &str, ) -> Result<Vec<(String, ReadState)>>

List every ReadState cursor in did’s repo (the read side a login-time read-state merge would consume).

Source

pub async fn put_read_state( &self, did: &str, rkey: &str, state: &ReadState, ) -> Result<WriteResult>

Upsert a single ReadState cursor at its feed-derived rkey.

Source

pub async fn flush_read_states( &self, did: &str, cursors: &[(String, ReadState, bool)], ) -> Result<()>

Batch-flush many dirty ReadState cursors in one applyWrites call.

Each (rkey, state, pds_created) becomes a create op at the feed-derived rkey when the record does NOT yet exist (pds_created == false), and an update op when it does. This is what makes the FIRST flush of a feed succeed: applyWrites#update errors on a record that does not pre-exist, and applyWrites is atomic per-repo, so a single not-yet-created cursor would otherwise drop the whole DID batch. Both kinds ride the SAME applyWrites batch so batching is preserved.

Source

pub async fn add_subscription( &self, did: &str, sub: &Subscription, ) -> Result<String>

Add a subscription (subscribe to a feed) — createRecord, server-assigned tid rkey. Returns the new record’s rkey so the web layer can offer unsubscribe/rename immediately.

Source

pub async fn remove_subscription(&self, did: &str, rkey: &str) -> Result<()>

Remove a subscription (unsubscribe) by rkey — deleteRecord. Alias of delete_subscription in the reader vocabulary.

Source

pub async fn update_subscription( &self, did: &str, rkey: &str, sub: &Subscription, ) -> Result<WriteResult>

Update / rename a subscription in place at a known rkey — putRecord.

The whole record is replaced (retitle, move to a folder, change the fetch hint …). Upsert semantics: it also creates the record if the rkey is somehow absent, so it is safe as a general “write this exact record”.

Source

pub async fn list_subscriptions_sorted( &self, did: &str, ) -> Result<Vec<(String, Subscription)>>

List every subscription, sorted deterministically — by display title (case-insensitive), then feed URL, then rkey as the final tiebreaker — so the rendered feed list is stable across reads regardless of PDS return order. Untitled feeds sort by their URL.

Source

pub async fn add_subscriptions_bulk( &self, did: &str, subs: &[Subscription], ) -> Result<Vec<String>>

Batch-add many subscriptions in one applyWrites — the OPML-import path.

Each feed becomes one create op. Client-side monotonic tid rkeys are assigned so the batch is deterministic and the imported feeds keep OPML order (server-assigned tids would also be monotonic, but pinning them here makes the whole import reproducible and testable offline). Returns the assigned rkeys in input order.

Source

pub async fn add_folder(&self, did: &str, folder: &Folder) -> Result<String>

Add a folder — createRecord, server-assigned tid rkey. Returns the new folder’s rkey (subscriptions reference it by its at:// URI).

Source

pub async fn remove_folder(&self, did: &str, rkey: &str) -> Result<()>

Remove a folder by rkey — deleteRecord. (Subscriptions referencing it are left untouched; a dangling folder ref reads as “unfiled”.)

Source

pub async fn rename_folder( &self, did: &str, rkey: &str, folder: &Folder, ) -> Result<WriteResult>

Rename / update a folder in place at a known rkey — putRecord (rename, or change its position sort hint).

Source

pub async fn list_folders_sorted( &self, did: &str, ) -> Result<Vec<(String, Folder)>>

List every folder, sorted deterministically — by position (the lexicon’s sort hint; unset sorts last), then name (case-insensitive), then rkey — so the sidebar order is stable.

Source

pub async fn add_saved(&self, did: &str, saved: &Saved) -> Result<String>

Add a saved (starred / save-for-later) entry — createRecord, server-assigned tid rkey. Returns the new record’s rkey.

Source

pub async fn remove_saved(&self, did: &str, rkey: &str) -> Result<()>

Remove a saved entry by rkey — deleteRecord (un-star).

Source

pub async fn list_saved_sorted(&self, did: &str) -> Result<Vec<(String, Saved)>>

List every saved entry, sorted deterministically — newest first by createdAt (RFC-3339 sorts lexicographically), then rkey — so the “saved for later” list reads most-recent-first and is stable.

Trait Implementations§

Source§

impl Clone for SidecarClient

Source§

fn clone(&self) -> SidecarClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more