Packages

A small, transport-agnostic atproto client for Gleam: XRPC, identity, OAuth discovery, blobs, and repo CRUD.

Current section

Files

Jump to
atproto_client src atproto identity.gleam
Raw

src/atproto/identity.gleam

//// Resolve a handle or DID to its PDS endpoint via an injected
//// Slingshot-compatible `resolveMiniDoc` resolver. This is not native atproto
//// identity resolution (DID doc / PLC / did:web / DNS); consumers depend on the
//// resolver service being available.
import atproto/xrpc.{type Client, type XrpcError}
import gleam/dynamic/decode
import gleam/option.{None}
import gleam/result
import gleam/uri
pub const default_resolver = "https://slingshot.microcosm.blue"
pub type MiniDoc {
MiniDoc(did: String, pds: String)
}
pub fn resolve_pds(
client: Client,
resolver: String,
identifier: String,
) -> Result(String, XrpcError) {
resolve_mini_doc(client, resolver, identifier)
|> result.map(fn(doc) { doc.pds })
}
pub fn resolve_mini_doc(
client: Client,
resolver: String,
identifier: String,
) -> Result(MiniDoc, XrpcError) {
let query = uri.query_to_string([#("identifier", identifier)])
let url =
resolver <> "/xrpc/com.bad-example.identity.resolveMiniDoc?" <> query
use resp <- result.try(xrpc.get(client, url, None))
let decoder = {
use did <- decode.field("did", decode.string)
use pds <- decode.field("pds", decode.string)
decode.success(MiniDoc(did:, pds:))
}
xrpc.parse(resp.body, decoder)
}