Packages
atproto_browser
0.1.0
A browser-native atproto OAuth + XRPC client for Gleam: WebCrypto DPoP, PKCE, and async transport, for building a public-client SPA with no server-side session custody.
Current section
Files
Jump to
Current section
Files
src/atproto/browser/oauth/runner.gleam
//// The async runner for the shared OAuth effect kernel (`atproto/oauth/effect`
//// from atproto_client): a promise-recursive loop that interprets an `Effect`
//// against the browser's async `Client` and a WebCrypto `DpopKey`. Fetches go
//// through `gleam_fetch`, proofs through the WebCrypto-backed `browser/dpop`.
import atproto/browser/dpop.{type DpopKey}
import atproto/browser/xrpc.{type Client}
import atproto_core/oauth/effect.{type Effect}
import gleam/javascript/promise.{type Promise}
pub fn run(effect: Effect(a), client: Client, key: DpopKey) -> Promise(a) {
case effect {
effect.Done(value) -> promise.resolve(value)
effect.Fetch(request, next) -> {
use resp <- promise.await(xrpc.send_text(client, request))
run(next(resp), client, key)
}
effect.FetchBits(request, next) -> {
use resp <- promise.await(client.send(request))
run(next(resp), client, key)
}
effect.DpopProof(method, url, nonce, ath, next) -> {
use proof <- promise.await(dpop.proof(key, method:, url:, nonce:, ath:))
run(next(proof), client, key)
}
}
}