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@oauth@runner.erl
Raw

src/atproto@oauth@runner.erl

-module(atproto@oauth@runner).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/atproto/oauth/runner.gleam").
-export([run/3, run_readonly/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" The sync runner for the OAuth effect kernel: a tail-recursive loop that\n"
" interprets an `Effect` against a synchronous `xrpc.Client` and a `gose`\n"
" DPoP key. `run_readonly` is for fetch-only flows (metadata discovery) that\n"
" never sign a proof, so they need no key.\n"
).
-file("src/atproto/oauth/runner.gleam", 11).
-spec run(
atproto_core@oauth@effect:effect(AEUP),
atproto@xrpc:client(),
gose:key(binary())
) -> AEUP.
run(Effect, Client, Key) ->
case Effect of
{done, Value} ->
Value;
{fetch, Request, Next} ->
run(Next(atproto@xrpc:send_text(Client, Request)), Client, Key);
{fetch_bits, Request@1, Next@1} ->
run(Next@1((erlang:element(2, Client))(Request@1)), Client, Key);
{dpop_proof, Method, Url, Nonce, Ath, Next@2} ->
run(
Next@2(atproto@oauth@dpop:proof(Key, Method, Url, Nonce, Ath)),
Client,
Key
)
end.
-file("src/atproto/oauth/runner.gleam", 25).
?DOC(
" Interpret a fetch-only effect (no `DpopProof` steps). The `DpopProof` branch\n"
" is unreachable for such flows; it fails defensively rather than panicking.\n"
).
-spec run_readonly(
atproto_core@oauth@effect:effect(AEUS),
atproto@xrpc:client()
) -> AEUS.
run_readonly(Effect, Client) ->
case Effect of
{done, Value} ->
Value;
{fetch, Request, Next} ->
run_readonly(Next(atproto@xrpc:send_text(Client, Request)), Client);
{fetch_bits, Request@1, Next@1} ->
run_readonly(Next@1((erlang:element(2, Client))(Request@1)), Client);
{dpop_proof, _, _, _, _, Next@2} ->
run_readonly(
Next@2(
{error, <<"dpop proof required in read-only flow"/utf8>>}
),
Client
)
end.