From 05de6ab510c9acdf3948ab232518c7f71e438665 Mon Sep 17 00:00:00 2001 From: Orual Date: Sun, 05 Oct 2025 01:24:18 +0000 Subject: [PATCH] tested one commit too late --- Cargo.lock | 2 +- crates/jacquard/Cargo.toml | 8 +++++--- crates/jacquard/src/main.rs | 2 +- crates/jacquard/src/identity/resolver.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- 4 file(s) changed, 56 insertion(s)(+), 10 deletion(s)(-) diff --git a/Cargo.lock b/Cargo.lock --- a/Cargo.lock +++ b/Cargo.lock @@ -1353,7 +1353,7 @@ [[package]] name = "jacquard" -version = "0.2.0" +version = "0.2.1" dependencies = [ "async-trait", "bon", diff --git a/crates/jacquard/Cargo.toml b/crates/jacquard/Cargo.toml --- a/crates/jacquard/Cargo.toml +++ b/crates/jacquard/Cargo.toml @@ -2,7 +2,7 @@ name = "jacquard" description.workspace = true edition.workspace = true -version.workspace = true +version = "0.2.1" authors.workspace = true repository.workspace = true keywords.workspace = true @@ -12,11 +12,12 @@ license.workspace = true [features] -default = ["api_all", "dns"] +default = ["api_all", "dns", "fancy"] derive = ["dep:jacquard-derive"] api = ["jacquard-api/com_atproto"] api_all = ["api", "jacquard-api/app_bsky", "jacquard-api/chat_bsky", "jacquard-api/tools_ozone"] dns = ["dep:hickory-resolver"] +fancy = ["miette/fancy"] [lib] name = "jacquard" @@ -25,6 +26,7 @@ [[bin]] name = "jacquard" path = "src/main.rs" + [dependencies] bon = "3" @@ -35,7 +37,7 @@ jacquard-api = { version = "0.2.0", path = "../jacquard-api" } jacquard-common = { version = "0.2.0", path = "../jacquard-common" } jacquard-derive = { version = "0.2.0", path = "../jacquard-derive", optional = true } -miette.workspace = true +miette = { workspace = true } reqwest = { workspace = true, features = ["charset", "http2", "json", "system-proxy", "gzip", "rustls-tls"] } serde.workspace = true serde_html_form.workspace = true diff --git a/crates/jacquard/src/main.rs b/crates/jacquard/src/main.rs --- a/crates/jacquard/src/main.rs +++ b/crates/jacquard/src/main.rs @@ -3,7 +3,7 @@ use jacquard::api::app_bsky::feed::get_timeline::GetTimeline; use jacquard::api::com_atproto::server::create_session::CreateSession; use jacquard::client::{BasicClient, Session}; -use jacquard::identity::resolver::{slingshot_resolver_default, IdentityResolver}; +use jacquard::identity::resolver::{IdentityResolver, slingshot_resolver_default}; use jacquard::types::string::Handle; use miette::IntoDiagnostic; diff --git a/crates/jacquard/src/identity/resolver.rs b/crates/jacquard/src/identity/resolver.rs --- a/crates/jacquard/src/identity/resolver.rs +++ b/crates/jacquard/src/identity/resolver.rs @@ -9,11 +9,18 @@ //! Parsing returns a `DidDocResponse` so callers can borrow from the response buffer //! and optionally validate the document `id` against the requested DID. +use std::collections::BTreeMap; +use std::str::FromStr; + // use crate::CowStr; // not currently needed directly here use crate::client::XrpcExt; use bon::Builder; use bytes::Bytes; -use jacquard_common::IntoStatic; +use jacquard_common::types::did_doc::Service; +use jacquard_common::types::string::AtprotoStr; +use jacquard_common::types::uri::Uri; +use jacquard_common::types::value::Data; +use jacquard_common::{CowStr, IntoStatic}; use miette::Diagnostic; use percent_encoding::percent_decode_str; use reqwest::StatusCode; @@ -124,7 +131,26 @@ /// Parse as borrowed DidDocument<'_> pub fn parse<'b>(&'b self) -> Result, IdentityError> { if self.status.is_success() { - serde_json::from_slice::>(&self.buffer).map_err(IdentityError::from) + if let Ok(doc) = serde_json::from_slice::>(&self.buffer) { + Ok(doc) + } else if let Ok(mini_doc) = serde_json::from_slice::>(&self.buffer) { + Ok(DidDocument { + id: mini_doc.did, + also_known_as: Some(vec![CowStr::from(mini_doc.handle)]), + verification_method: None, + service: Some(vec![Service { + id: CowStr::new_static("#atproto_pds"), + r#type: CowStr::new_static("AtprotoPersonalDataServer"), + service_endpoint: Some(Data::String(AtprotoStr::Uri(Uri::Https( + Url::from_str(&mini_doc.pds).unwrap(), + )))), + extra_data: BTreeMap::new(), + }]), + extra_data: BTreeMap::new(), + }) + } else { + Err(IdentityError::MissingPdsEndpoint) + } } else { Err(IdentityError::HttpStatus(self.status)) } @@ -149,9 +175,27 @@ /// Parse as owned DidDocument<'static> pub fn into_owned(self) -> Result, IdentityError> { if self.status.is_success() { - serde_json::from_slice::>(&self.buffer) - .map(|d| d.into_static()) - .map_err(IdentityError::from) + if let Ok(doc) = serde_json::from_slice::>(&self.buffer) { + Ok(doc.into_static()) + } else if let Ok(mini_doc) = serde_json::from_slice::>(&self.buffer) { + Ok(DidDocument { + id: mini_doc.did, + also_known_as: Some(vec![CowStr::from(mini_doc.handle)]), + verification_method: None, + service: Some(vec![Service { + id: CowStr::new_static("#atproto_pds"), + r#type: CowStr::new_static("AtprotoPersonalDataServer"), + service_endpoint: Some(Data::String(AtprotoStr::Uri(Uri::Https( + Url::from_str(&mini_doc.pds).unwrap(), + )))), + extra_data: BTreeMap::new(), + }]), + extra_data: BTreeMap::new(), + } + .into_static()) + } else { + Err(IdentityError::MissingPdsEndpoint) + } } else { Err(IdentityError::HttpStatus(self.status)) } -- tangled.sh