From d8ee28ad0b0dadf44d52670d1e6836ea4df91167 Mon Sep 17 00:00:00 2001 From: "kacaii.dev" Date: Sat, 11 Jul 2026 13:25:10 -0300 Subject: [PATCH] possum: resolve_well_known_did takes a String for hostname --- CHANGELOG.md | 3 +-- README.md | 13 ++++++++++--- pages/consulting-your-did.md | 4 +++- src/possum.gleam | 20 ++++++++++++++++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d3aa55..9e329f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [possum/did] Renamed `did.DidError` to `did.ParseError`. - [possum/did] Rename `did.InvalidFormat` to `did.InvalidSyntax`. -- [possuum] Functions now use `prepend_header` instead of `set_header`. -- [possum] `resolve_well_known_did` now take a `handle.Handle` as parameter. +- [possum] Functions now use `prepend_header` instead of `set_header`. - [possum] `resolve_handle` now takes a `handle.Handle` as parameter. - [possum] Functions now take a parsed `nsid.Nsid` as the "collection" parameter. diff --git a/README.md b/README.md index 99aa2d6..41a0d73 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,12 @@ gleam add possum gleam_http gleam_json ```gleam import gleam/http/request +import possum/did +import possum/handle import possum +let assert Ok(handle) = handle.parse("gleam.run") + // Resolve an atproto handle (hostname) to a DID. // // You can consult your identifier by sending a request directly to your PDS, @@ -33,7 +37,7 @@ import possum // for easy access to cached data when resolving a handle. request.new() |> request.set_host("slingshot.microcosm.blue") -|> possum.resolve_handle("gleam.run") +|> possum.resolve_handle(handle) // Use `did.parse` to turn strings into valid DID format let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz") @@ -43,10 +47,12 @@ let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz") ```gleam import gleam/http/request -import possum import possum/did +import possum/nsid +import possum let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz") +let assert Ok(collection) = nsid.parse("sh.tangled.repo") // Reading public data from repositories. // No authorization needed. @@ -54,7 +60,7 @@ request.new() |> request.set_host("personal.data-server.pds") |> possum.list_records( did, - collection: "sh.tangled.repo", + collection:, limit: option.Some(3), cursor: option.None, reverse: option.None, @@ -65,6 +71,7 @@ request.new() ```gleam import gleam/http/request +import possum/did import possum let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz") diff --git a/pages/consulting-your-did.md b/pages/consulting-your-did.md index 22df2bc..7cb8ef1 100644 --- a/pages/consulting-your-did.md +++ b/pages/consulting-your-did.md @@ -17,12 +17,14 @@ handles for them, using the `com.atproto.identity.resolveHandle` endpoint, and don't usually need to implement resolution directly themselves. ```gleam +let assert Ok(handle) = handle.parse("gleam.run") + // You can consult your identifier by sending a request directly to your PDS, // or you can use projects like [Slingshot](https://slingshot.microcosm.blue) // for easy access to cached data when resolving a handle. request.new() |> request.set_host("slingshot.microcosm.blue") -|> possum.resolve_handle("gleam.run") +|> possum.resolve_handle(handle) ``` ## HTTPS well-known Method diff --git a/src/possum.gleam b/src/possum.gleam index 4534b14..34b84c5 100644 --- a/src/possum.gleam +++ b/src/possum.gleam @@ -59,6 +59,7 @@ const com_atproto_server = "xrpc/com.atproto.server" /// /// ```gleam /// import gleam/http/request +/// import possum/did /// import possum /// /// let assert Ok(did) = did.parse("did:plc:z72i7hdynmk6r22z27h6tvur") @@ -131,10 +132,10 @@ pub fn get_plc_data( /// Documentation: [HTTPS well-known Method](https://atproto.com/specs/handle#https-well-known-method) pub fn resolve_well_known_did( request: request.Request(_), - handle: handle.Handle, + host: String, ) -> request.Request(_) { request - |> request.set_host(handle.to_string(handle)) + |> request.set_host(host) |> request.set_method(http.Get) |> request.set_path(".well-known/atproto-did") } @@ -195,8 +196,11 @@ pub fn resolve_handle( /// /// ```gleam /// import gleam/http/request +/// import possum/did /// import possum /// +/// let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz") +/// /// let request = /// request.new() /// |> request.set_host("personal.data-server.pds") @@ -367,8 +371,11 @@ pub fn authorized( /// /// ```gleam /// import gleam/http/request +/// import possum/did /// import possum /// +/// let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz") +/// /// let request = /// request.new() /// |> request.set_host("personal.data-server.pds") @@ -502,6 +509,8 @@ pub fn create_record( /// /// ```gleam /// import gleam/http/request +/// import possum/did +/// import possum/nsid /// import possum /// /// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") @@ -562,8 +571,11 @@ pub fn get_record( /// /// ```gleam /// import gleam/http/request +/// import possum/did +/// import possum/nsid /// import possum /// +/// let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz") /// let assert Ok(collection) = nsid.parse("site.standard.document") /// /// let request = @@ -642,6 +654,8 @@ pub fn list_records( /// /// ```gleam /// import gleam/http/request +/// import possum/did +/// import possum/nsid /// import possum /// /// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") @@ -724,6 +738,8 @@ pub fn delete_record( /// /// ```gleam /// import gleam/http/request +/// import possum/did +/// import possum/nsid /// import possum /// /// let assert Ok(did) = did.parse("did:plc:k5vecqzf4d5mdvkcu3mx6l5g") -- 2.51.2