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@core@effect.erl
Raw

src/atproto@oauth@core@effect.erl

-module(atproto@oauth@core@effect).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/atproto/oauth/core/effect.gleam").
-export([done/1, then/2, map/2, fetch/1, fetch_bits/1, proof/4]).
-export_type([effect/1]).
-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(
" A sans-IO effect kernel for the OAuth orchestration. An `Effect(a)` is a\n"
" pure description of the HTTP + DPoP steps a flow needs; a per-target runner\n"
" interprets it (sync `xrpc.Client` + `gose.Key` on erlang, async `Promise`\n"
" `Client` + WebCrypto `CryptoKey` in the browser). Keys never appear here:\n"
" `DpopProof` asks the runner for a proof and each runner closes over its own\n"
" platform key. Bodies come in two shapes: `Fetch` for the string-shaped OAuth\n"
" endpoints, `FetchBits` for the binary resource path (blobs).\n"
).
-type effect(ADZZ) :: {fetch,
gleam@http@request:request(binary()),
fun(({ok, gleam@http@response:response(binary())} |
{error, atproto@xrpc:transport_error()}) -> effect(ADZZ))} |
{fetch_bits,
gleam@http@request:request(bitstring()),
fun(({ok, gleam@http@response:response(bitstring())} |
{error, atproto@xrpc:transport_error()}) -> effect(ADZZ))} |
{dpop_proof,
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
fun(({ok, binary()} | {error, binary()}) -> effect(ADZZ))} |
{done, ADZZ}.
-file("src/atproto/oauth/core/effect.gleam", 33).
-spec done(AEAA) -> effect(AEAA).
done(Value) ->
{done, Value}.
-file("src/atproto/oauth/core/effect.gleam", 38).
?DOC(" Monadic bind, `use`-syntax friendly: `use x <- effect.then(some_effect)`.\n").
-spec then(effect(AEAC), fun((AEAC) -> effect(AEAE))) -> effect(AEAE).
then(Effect, F) ->
case Effect of
{done, Value} ->
F(Value);
{fetch, Request, Next} ->
{fetch, Request, fun(R) -> then(Next(R), F) end};
{fetch_bits, Request@1, Next@1} ->
{fetch_bits, Request@1, fun(R@1) -> then(Next@1(R@1), F) end};
{dpop_proof, Method, Url, Nonce, Ath, Next@2} ->
{dpop_proof,
Method,
Url,
Nonce,
Ath,
fun(R@2) -> then(Next@2(R@2), F) end}
end.
-file("src/atproto/oauth/core/effect.gleam", 48).
-spec map(effect(AEAH), fun((AEAH) -> AEAJ)) -> effect(AEAJ).
map(Effect, F) ->
then(Effect, fun(A) -> {done, F(A)} end).
-file("src/atproto/oauth/core/effect.gleam", 53).
?DOC(" A string-bodied HTTP request, yielding the response (or a transport error).\n").
-spec fetch(gleam@http@request:request(binary())) -> effect({ok,
gleam@http@response:response(binary())} |
{error, atproto@xrpc:transport_error()}).
fetch(Request) ->
{fetch, Request, fun(Field@0) -> {done, Field@0} end}.
-file("src/atproto/oauth/core/effect.gleam", 60).
?DOC(" A binary HTTP request (the resource path, for blobs), yielding the response.\n").
-spec fetch_bits(gleam@http@request:request(bitstring())) -> effect({ok,
gleam@http@response:response(bitstring())} |
{error, atproto@xrpc:transport_error()}).
fetch_bits(Request) ->
{fetch_bits, Request, fun(Field@0) -> {done, Field@0} end}.
-file("src/atproto/oauth/core/effect.gleam", 68).
?DOC(
" Ask the runner for a DPoP proof bound to this method+URL (and optional nonce\n"
" and access-token hash). The runner signs it with its platform key.\n"
).
-spec proof(
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary())
) -> effect({ok, binary()} | {error, binary()}).
proof(Method, Url, Nonce, Ath) ->
{dpop_proof, Method, Url, Nonce, Ath, fun(Field@0) -> {done, Field@0} end}.