diff --git a/examples/authn/signup.rs b/examples/authn/signup.rs index 13d8b45c..850cd875 100644 --- a/examples/authn/signup.rs +++ b/examples/authn/signup.rs @@ -1,6 +1,6 @@ use anyhow::Result; use clap::Parser; -use pubky::PubkyClient; +use pubky::Client; use std::path::PathBuf; use pubky_common::crypto::PublicKey; @@ -24,7 +24,7 @@ async fn main() -> Result<()> { let homeserver = cli.homeserver; - let client = PubkyClient::new()?; + let client = Client::new()?; println!("Enter your recovery_file's passphrase to signup:"); let passphrase = rpassword::read_password()?; diff --git a/examples/authz/3rd-party-app/src/pubky-auth-widget.js b/examples/authz/3rd-party-app/src/pubky-auth-widget.js index 628f3167..20c73caf 100644 --- a/examples/authz/3rd-party-app/src/pubky-auth-widget.js +++ b/examples/authz/3rd-party-app/src/pubky-auth-widget.js @@ -56,8 +56,8 @@ export class PubkyAuthWidget extends LitElement { this.testnet = false; this.open = false; - /** @type {import("@synonymdev/pubky").PubkyClient} */ - this.pubkyClient = new window.pubky.PubkyClient(); + /** @type {import("@synonymdev/pubky").Client} */ + this.pubkyClient = new window.pubky.Client(); this.caps = this.caps || "" } @@ -74,9 +74,9 @@ export class PubkyAuthWidget extends LitElement { console.debug("Switching testnet"); if (this.testnet) { - this.pubkyClient = window.pubky.PubkyClient.testnet() + this.pubkyClient = window.pubky.Client.testnet() } else { - this.pubkyClient = new window.pubky.PubkyClient(); + this.pubkyClient = new window.pubky.Client(); } console.debug("Pkarr Relays: " + this.pubkyClient.getPkarrRelays()) diff --git a/examples/authz/authenticator.rs b/examples/authz/authenticator.rs index aeeb55de..633ae1d6 100644 --- a/examples/authz/authenticator.rs +++ b/examples/authz/authenticator.rs @@ -1,6 +1,6 @@ use anyhow::Result; use clap::Parser; -use pubky::PubkyClient; +use pubky::Client; use std::path::PathBuf; use url::Url; @@ -66,7 +66,7 @@ async fn main() -> Result<()> { println!("PublicKey: {}", keypair.public_key()); let client = if cli.testnet.unwrap_or_default() { - let client = PubkyClient::testnet()?; + let client = Client::testnet()?; // For the purposes of this demo, we need to make sure // the user has an account on the local homeserver. @@ -78,7 +78,7 @@ async fn main() -> Result<()> { client } else { - PubkyClient::new()? + Client::new()? }; println!("Sending AuthToken to the 3rd party app..."); diff --git a/examples/request/main.rs b/examples/request/main.rs index 673a87a7..a0d6841d 100644 --- a/examples/request/main.rs +++ b/examples/request/main.rs @@ -3,7 +3,7 @@ use clap::Parser; use reqwest::Method; use url::Url; -use pubky::PubkyClient; +use pubky::Client; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] @@ -18,7 +18,7 @@ struct Cli { async fn main() -> Result<()> { let cli = Cli::parse(); - let client = PubkyClient::new()?; + let client = Client::new()?; match cli.url.scheme() { "https" => { diff --git a/pubky/README.md b/pubky/README.md index b5bc014e..d8844435 100644 --- a/pubky/README.md +++ b/pubky/README.md @@ -8,7 +8,7 @@ Rust implementation implementation of [Pubky](https://github.com/pubky/pubky-cor use pkarr::mainline::Testnet; use pkarr::Keypair; use pubky_homeserver::Homeserver; -use pubky::PubkyClient; +use pubky::Client; #[tokio::main] async fn main () { @@ -16,10 +16,10 @@ async fn main () { let testnet = Testnet::new(10); let server = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); // Uncomment the following line instead if you are not just testing. - // let client PubkyClient::new().unwrap(); + // let client Client::new().unwrap(); // Generate a keypair let keypair = Keypair::random(); diff --git a/pubky/pkg/README.md b/pubky/pkg/README.md index 4704ffff..1c75e004 100644 --- a/pubky/pkg/README.md +++ b/pubky/pkg/README.md @@ -21,10 +21,10 @@ For Nodejs, you need Node v20 or later. ## Getting started ```js -import { PubkyClient, Keypair, PublicKey } from '../index.js' +import { Client, Keypair, PublicKey } from '../index.js' -// Initialize PubkyClient with Pkarr relay(s). -let client = new PubkyClient(); +// Initialize Client with Pkarr relay(s). +let client = new Client(); // Generate a keypair let keypair = Keypair.random(); @@ -49,7 +49,7 @@ await client.put(url, body); // GET public data without signup or signin { - const client = new PubkyClient(); + const client = new Client(); let response = await client.get(url); } @@ -60,11 +60,11 @@ await client.delete(url); ## API -### PubkyClient +### Client #### constructor ```js -let client = new PubkyClient() +let client = new Client() ``` #### signup @@ -257,10 +257,10 @@ Run the local testnet server npm run testnet ``` -Use the logged addresses as inputs to `PubkyClient` +Use the logged addresses as inputs to `Client` ```js -import { PubkyClient } from '../index.js' +import { Client } from '../index.js' -const client = PubkyClient().testnet(); +const client = Client().testnet(); ``` diff --git a/pubky/pkg/package.json b/pubky/pkg/package.json index 87459b58..24894c64 100644 --- a/pubky/pkg/package.json +++ b/pubky/pkg/package.json @@ -2,11 +2,11 @@ "name": "@synonymdev/pubky", "type": "module", "description": "Pubky client", - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/pubky/pubky" + "url": "git+https://github.com/pubky/pubky-core.git" }, "scripts": { "testnet": "cargo run -p pubky_homeserver -- --testnet", diff --git a/pubky/pkg/test/auth.js b/pubky/pkg/test/auth.js index fe7e559e..a3d68987 100644 --- a/pubky/pkg/test/auth.js +++ b/pubky/pkg/test/auth.js @@ -1,11 +1,11 @@ import test from 'tape' -import { PubkyClient, Keypair, PublicKey } from '../index.cjs' +import { Client, Keypair, PublicKey } from '../index.cjs' const Homeserver = PublicKey.from('8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo') test('auth', async (t) => { - const client = PubkyClient.testnet(); + const client = Client.testnet(); const keypair = Keypair.random() const publicKey = keypair.publicKey() @@ -36,7 +36,7 @@ test("3rd party signin", async (t) => { // Third party app side let capabilities = "/pub/pubky.app/:rw,/pub/foo.bar/file:r"; - let client = PubkyClient.testnet(); + let client = Client.testnet(); let [pubkyauth_url, pubkyauthResponse] = client .authRequest("https://demo.httprelay.io/link", capabilities); @@ -49,7 +49,7 @@ test("3rd party signin", async (t) => { // Authenticator side { - let client = PubkyClient.testnet(); + let client = Client.testnet(); await client.signup(keypair, Homeserver); diff --git a/pubky/pkg/test/http.js b/pubky/pkg/test/http.js index e861f265..6759b9b7 100644 --- a/pubky/pkg/test/http.js +++ b/pubky/pkg/test/http.js @@ -1,13 +1,13 @@ import test from 'tape' -import { PubkyClient, Keypair, PublicKey } from '../index.cjs' +import { Client, Keypair, PublicKey } from '../index.cjs' const TLD = '8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo'; // TODO: test HTTPs too somehow. test.skip("basic fetch", async (t) => { - let client = PubkyClient.testnet(); + let client = Client.testnet(); // Normal TLD { diff --git a/pubky/pkg/test/public.js b/pubky/pkg/test/public.js index ec30bb2c..d2bc2f3a 100644 --- a/pubky/pkg/test/public.js +++ b/pubky/pkg/test/public.js @@ -1,11 +1,11 @@ import test from 'tape' -import { PubkyClient, Keypair, PublicKey } from '../index.cjs' +import { Client, Keypair, PublicKey } from '../index.cjs' const Homeserver = PublicKey.from('8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo'); test('public: put/get', async (t) => { - const client = PubkyClient.testnet(); + const client = Client.testnet(); const keypair = Keypair.random(); @@ -20,7 +20,7 @@ test('public: put/get', async (t) => { // PUT public data, by authorized client await client.put(url, body); - const otherClient = PubkyClient.testnet(); + const otherClient = Client.testnet(); // GET public data without signup or signin { @@ -42,7 +42,7 @@ test('public: put/get', async (t) => { }) test("not found", async (t) => { - const client = PubkyClient.testnet(); + const client = Client.testnet(); const keypair = Keypair.random(); @@ -59,7 +59,7 @@ test("not found", async (t) => { }) test("unauthorized", async (t) => { - const client = PubkyClient.testnet(); + const client = Client.testnet(); const keypair = Keypair.random() const publicKey = keypair.publicKey() @@ -86,7 +86,7 @@ test("unauthorized", async (t) => { }) test("forbidden", async (t) => { - const client = PubkyClient.testnet(); + const client = Client.testnet(); const keypair = Keypair.random() const publicKey = keypair.publicKey() @@ -111,7 +111,7 @@ test("forbidden", async (t) => { }) test("list", async (t) => { - const client = PubkyClient.testnet(); + const client = Client.testnet(); const keypair = Keypair.random() const publicKey = keypair.publicKey() @@ -242,7 +242,7 @@ test("list", async (t) => { }) test('list shallow', async (t) => { - const client = PubkyClient.testnet(); + const client = Client.testnet(); const keypair = Keypair.random() const publicKey = keypair.publicKey() diff --git a/pubky/src/lib.rs b/pubky/src/lib.rs index e503c345..69583c55 100644 --- a/pubky/src/lib.rs +++ b/pubky/src/lib.rs @@ -20,7 +20,7 @@ pub use crate::shared::list_builder::ListBuilder; /// A client for Pubky homeserver API, as well as generic HTTP requests to Pubky urls. #[derive(Debug, Clone)] #[wasm_bindgen] -pub struct PubkyClient { +pub struct Client { http: reqwest::Client, pub(crate) pkarr: pkarr::Client, } diff --git a/pubky/src/native.rs b/pubky/src/native.rs index 98bd638d..63a19064 100644 --- a/pubky/src/native.rs +++ b/pubky/src/native.rs @@ -2,7 +2,7 @@ use std::time::Duration; use pkarr::mainline::Testnet; -use crate::PubkyClient; +use crate::Client; mod api; mod internals; @@ -42,13 +42,11 @@ impl Settings { self } - /// Build [PubkyClient] - pub fn build(self) -> Result { - // TODO: convert to Result - + /// Build [Client] + pub fn build(self) -> Result { let pkarr = pkarr::Client::new(self.pkarr_settings)?; - Ok(PubkyClient { + Ok(Client { http: reqwest::Client::builder() .cookie_store(true) // .dns_resolver(Arc::new(dns_resolver)) @@ -60,13 +58,13 @@ impl Settings { } } -impl PubkyClient { - /// Create a new [PubkyClient] with default [Settings] +impl Client { + /// Create a new [Client] with default [Settings] pub fn new() -> Result { Self::builder().build() } - /// Returns a builder to edit settings before creating [PubkyClient]. + /// Returns a builder to edit settings before creating [Client]. pub fn builder() -> Settings { Settings::default() } @@ -83,8 +81,8 @@ impl PubkyClient { } #[cfg(test)] - /// Alias to `PubkyClient::builder().testnet(testnet).build().unwrap()` - pub(crate) fn test(testnet: &Testnet) -> PubkyClient { - PubkyClient::builder().testnet(testnet).build().unwrap() + /// Alias to `pubky::Client::builder().testnet(testnet).build().unwrap()` + pub(crate) fn test(testnet: &Testnet) -> Client { + Client::builder().testnet(testnet).build().unwrap() } } diff --git a/pubky/src/native/api/auth.rs b/pubky/src/native/api/auth.rs index e9ea0985..bd74c402 100644 --- a/pubky/src/native/api/auth.rs +++ b/pubky/src/native/api/auth.rs @@ -8,9 +8,9 @@ use pkarr::PublicKey; use pubky_common::capabilities::Capabilities; use crate::error::{Error, Result}; -use crate::PubkyClient; +use crate::Client; -impl PubkyClient { +impl Client { /// Signup to a homeserver and update Pkarr accordingly. /// /// The homeserver is a Pkarr domain name, where the TLD is a Pkarr public key diff --git a/pubky/src/native/api/http.rs b/pubky/src/native/api/http.rs index d8799418..5f29b6b1 100644 --- a/pubky/src/native/api/http.rs +++ b/pubky/src/native/api/http.rs @@ -1,8 +1,8 @@ use reqwest::{IntoUrl, Method, RequestBuilder}; -use crate::PubkyClient; +use crate::Client; -impl PubkyClient { +impl Client { /// Start building a `Request` with the `Method` and `Url`. /// /// Returns a `RequestBuilder`, which will allow setting headers and @@ -25,7 +25,7 @@ mod tests { use pkarr::mainline::Testnet; use pubky_homeserver::Homeserver; - use crate::*; + use crate::Client; // #[tokio::test] async fn http_get_pubky() { @@ -33,7 +33,7 @@ mod tests { let homeserver = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let url = format!("http://{}/", homeserver.public_key()); @@ -50,7 +50,7 @@ mod tests { async fn http_get_icann() { let testnet = Testnet::new(10).unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let url = format!("http://example.com/"); diff --git a/pubky/src/native/api/public.rs b/pubky/src/native/api/public.rs index dfee0531..6e5c1beb 100644 --- a/pubky/src/native/api/public.rs +++ b/pubky/src/native/api/public.rs @@ -1,9 +1,9 @@ use bytes::Bytes; use url::Url; -use crate::{error::Result, shared::list_builder::ListBuilder, PubkyClient}; +use crate::{error::Result, shared::list_builder::ListBuilder, Client}; -impl PubkyClient { +impl Client { /// Upload a small payload to a given path. pub async fn put>(&self, url: T, content: &[u8]) -> Result<()> { self.inner_put(url, content).await diff --git a/pubky/src/native/api/recovery_file.rs b/pubky/src/native/api/recovery_file.rs index 0eace091..ce8fc730 100644 --- a/pubky/src/native/api/recovery_file.rs +++ b/pubky/src/native/api/recovery_file.rs @@ -3,9 +3,9 @@ use pubky_common::{ recovery_file::{create_recovery_file, decrypt_recovery_file}, }; -use crate::{error::Result, PubkyClient}; +use crate::{error::Result, Client}; -impl PubkyClient { +impl Client { /// Create a recovery file of the `keypair`, containing the secret key encrypted /// using the `passphrase`. pub fn create_recovery_file(keypair: &Keypair, passphrase: &str) -> Result> { diff --git a/pubky/src/native/internals.rs b/pubky/src/native/internals.rs index 69ef73cd..0fcd454f 100644 --- a/pubky/src/native/internals.rs +++ b/pubky/src/native/internals.rs @@ -1,9 +1,9 @@ use reqwest::RequestBuilder; use url::Url; -use crate::PubkyClient; +use crate::Client; -impl PubkyClient { +impl Client { // === HTTP === /// A wrapper around [reqwest::Client::request], with the same signature between native and wasm. diff --git a/pubky/src/shared/auth.rs b/pubky/src/shared/auth.rs index ae96a0a8..670c1f00 100644 --- a/pubky/src/shared/auth.rs +++ b/pubky/src/shared/auth.rs @@ -14,12 +14,12 @@ use pubky_common::{ use crate::{ error::{Error, Result}, - PubkyClient, + Client, }; use super::pkarr::Endpoint; -impl PubkyClient { +impl Client { /// Signup to a homeserver and update Pkarr accordingly. /// /// The homeserver is a Pkarr domain name, where the TLD is a Pkarr public key @@ -225,7 +225,7 @@ mod tests { let testnet = Testnet::new(10).unwrap(); let server = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let keypair = Keypair::random(); @@ -272,14 +272,14 @@ mod tests { // Third party app side let capabilities: Capabilities = "/pub/pubky.app/:rw,/pub/foo.bar/file:r".try_into().unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let (pubkyauth_url, pubkyauth_response) = client .auth_request("https://demo.httprelay.io/link", &capabilities) .unwrap(); // Authenticator side { - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); client.signup(&keypair, &server.public_key()).await.unwrap(); diff --git a/pubky/src/shared/list_builder.rs b/pubky/src/shared/list_builder.rs index 851007f8..f44b1ca1 100644 --- a/pubky/src/shared/list_builder.rs +++ b/pubky/src/shared/list_builder.rs @@ -1,7 +1,7 @@ use reqwest::Method; use url::Url; -use crate::{error::Result, PubkyClient}; +use crate::{error::Result, Client}; /// Helper struct to edit Pubky homeserver's list API options before sending them. #[derive(Debug)] @@ -10,13 +10,13 @@ pub struct ListBuilder<'a> { reverse: bool, limit: Option, cursor: Option<&'a str>, - client: &'a PubkyClient, + client: &'a Client, shallow: bool, } impl<'a> ListBuilder<'a> { /// Create a new List request builder - pub(crate) fn new(client: &'a PubkyClient, url: Url) -> Self { + pub(crate) fn new(client: &'a Client, url: Url) -> Self { Self { client, url, diff --git a/pubky/src/shared/pkarr.rs b/pubky/src/shared/pkarr.rs index e202b120..67ef638a 100644 --- a/pubky/src/shared/pkarr.rs +++ b/pubky/src/shared/pkarr.rs @@ -7,12 +7,12 @@ use pkarr::{ use crate::{ error::{Error, Result}, - PubkyClient, + Client, }; const MAX_ENDPOINT_RESOLUTION_RECURSION: u8 = 3; -impl PubkyClient { +impl Client { /// Publish the SVCB record for `_pubky.`. pub(crate) async fn publish_pubky_homeserver( &self, @@ -265,7 +265,7 @@ mod tests { target = format!("pubky.{}", keypair.public_key()) } - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let endpoint = client.resolve_endpoint(&target).await.unwrap(); @@ -300,7 +300,7 @@ mod tests { pkarr_client.publish(&signed_packet).await.unwrap(); { - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let pubky = Keypair::random(); diff --git a/pubky/src/shared/public.rs b/pubky/src/shared/public.rs index ce772ee7..45f08deb 100644 --- a/pubky/src/shared/public.rs +++ b/pubky/src/shared/public.rs @@ -6,12 +6,12 @@ use url::Url; use crate::{ error::{Error, Result}, - PubkyClient, + Client, }; use super::{list_builder::ListBuilder, pkarr::Endpoint}; -impl PubkyClient { +impl Client { pub(crate) async fn inner_put>(&self, url: T, content: &[u8]) -> Result<()> { let url = self.pubky_to_http(url).await?; @@ -109,7 +109,7 @@ mod tests { let testnet = Testnet::new(10).unwrap(); let server = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let keypair = Keypair::random(); @@ -136,7 +136,7 @@ mod tests { let testnet = Testnet::new(10).unwrap(); let server = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let keypair = Keypair::random(); @@ -147,7 +147,7 @@ mod tests { let url = format!("pubky://{public_key}/pub/foo.txt"); let url = url.as_str(); - let other_client = PubkyClient::test(&testnet); + let other_client = Client::test(&testnet); { let other = Keypair::random(); @@ -202,7 +202,7 @@ mod tests { let testnet = Testnet::new(10).unwrap(); let server = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let keypair = Keypair::random(); @@ -406,7 +406,7 @@ mod tests { let testnet = Testnet::new(10).unwrap(); let server = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let keypair = Keypair::random(); @@ -617,7 +617,7 @@ mod tests { let testnet = Testnet::new(10).unwrap(); let server = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let keypair = Keypair::random(); @@ -646,7 +646,7 @@ mod tests { let feed_url = format!("http://localhost:{}/events/", server.port()); let feed_url = feed_url.as_str(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let cursor; @@ -714,7 +714,7 @@ mod tests { let testnet = Testnet::new(10).unwrap(); let server = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let keypair = Keypair::random(); @@ -730,7 +730,7 @@ mod tests { let feed_url = format!("http://localhost:{}/events/", server.port()); let feed_url = feed_url.as_str(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); { let response = client @@ -762,7 +762,7 @@ mod tests { async fn dont_delete_shared_blobs() { let testnet = Testnet::new(10).unwrap(); let homeserver = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let homeserver_pubky = homeserver.public_key(); @@ -818,7 +818,7 @@ mod tests { let testnet = Testnet::new(10).unwrap(); let server = Homeserver::start_test(&testnet).await.unwrap(); - let client = PubkyClient::test(&testnet); + let client = Client::test(&testnet); let keypair = Keypair::random(); diff --git a/pubky/src/wasm.rs b/pubky/src/wasm.rs index c574ce3a..a9c63e8d 100644 --- a/pubky/src/wasm.rs +++ b/pubky/src/wasm.rs @@ -1,12 +1,12 @@ use wasm_bindgen::prelude::*; -use crate::PubkyClient; +use crate::Client; mod api; mod internals; mod wrappers; -impl Default for PubkyClient { +impl Default for Client { fn default() -> Self { Self::new() } @@ -15,9 +15,9 @@ impl Default for PubkyClient { static TESTNET_RELAYS: [&str; 1] = ["http://localhost:15411/pkarr"]; #[wasm_bindgen] -impl PubkyClient { +impl Client { #[wasm_bindgen(constructor)] - /// Create PubkyClient with default Settings including default relays + /// Create Client with default Settings including default relays pub fn new() -> Self { Self { http: reqwest::Client::builder().build().unwrap(), diff --git a/pubky/src/wasm/api/auth.rs b/pubky/src/wasm/api/auth.rs index d75c7169..deaa14d6 100644 --- a/pubky/src/wasm/api/auth.rs +++ b/pubky/src/wasm/api/auth.rs @@ -2,8 +2,8 @@ use url::Url; use pubky_common::capabilities::Capabilities; +use crate::Client; use crate::Error; -use crate::PubkyClient; use crate::wasm::wrappers::keys::{Keypair, PublicKey}; use crate::wasm::wrappers::session::Session; @@ -11,7 +11,7 @@ use crate::wasm::wrappers::session::Session; use wasm_bindgen::prelude::*; #[wasm_bindgen] -impl PubkyClient { +impl Client { /// Signup to a homeserver and update Pkarr accordingly. /// /// The homeserver is a Pkarr domain name, where the TLD is a Pkarr public key diff --git a/pubky/src/wasm/api/http.rs b/pubky/src/wasm/api/http.rs index 46c57338..5b7d54ea 100644 --- a/pubky/src/wasm/api/http.rs +++ b/pubky/src/wasm/api/http.rs @@ -5,12 +5,12 @@ use wasm_bindgen::prelude::*; use reqwest::Url; -use crate::PubkyClient; +use crate::Client; use super::super::internals::resolve; #[wasm_bindgen] -impl PubkyClient { +impl Client { #[wasm_bindgen] pub async fn fetch( &self, @@ -18,16 +18,19 @@ impl PubkyClient { init: &web_sys::RequestInit, ) -> Result { let mut url: Url = url.try_into().map_err(|err| { - JsValue::from_str(&format!("PubkyClient::fetch(): Invalid `url`; {:?}", err)) + JsValue::from_str(&format!("pubky::Client::fetch(): Invalid `url`; {:?}", err)) })?; resolve(&self.pkarr, &mut url) .await - .map_err(|err| JsValue::from_str(&format!("PubkyClient::fetch(): {:?}", err)))?; + .map_err(|err| JsValue::from_str(&format!("pubky::Client::fetch(): {:?}", err)))?; let js_req = web_sys::Request::new_with_str_and_init(url.as_str(), init).map_err(|err| { - JsValue::from_str(&format!("PubkyClient::fetch(): Invalid `init`; {:?}", err)) + JsValue::from_str(&format!( + "pubky::Client::fetch(): Invalid `init`; {:?}", + err + )) })?; Ok(js_fetch(&js_req)) diff --git a/pubky/src/wasm/api/public.rs b/pubky/src/wasm/api/public.rs index 9bd8a17d..9b7f03da 100644 --- a/pubky/src/wasm/api/public.rs +++ b/pubky/src/wasm/api/public.rs @@ -2,10 +2,10 @@ use wasm_bindgen::prelude::*; use js_sys::{Array, Uint8Array}; -use crate::PubkyClient; +use crate::Client; #[wasm_bindgen] -impl PubkyClient { +impl Client { #[wasm_bindgen] /// Upload a small payload to a given path. pub async fn put(&self, url: &str, content: &[u8]) -> Result<(), JsValue> { diff --git a/pubky/src/wasm/internals.rs b/pubky/src/wasm/internals.rs index 95b625dc..61803153 100644 --- a/pubky/src/wasm/internals.rs +++ b/pubky/src/wasm/internals.rs @@ -3,7 +3,7 @@ use url::Url; use pkarr::{EndpointResolver, PublicKey}; -use crate::{error::Result, PubkyClient}; +use crate::{error::Result, Client}; // TODO: remove expect pub async fn resolve(pkarr: &pkarr::Client, url: &mut Url) -> Result<()> { @@ -25,7 +25,7 @@ pub async fn resolve(pkarr: &pkarr::Client, url: &mut Url) -> Result<()> { Ok(()) } -impl PubkyClient { +impl Client { /// A wrapper around [reqwest::Client::request], with the same signature between native and wasm. pub(crate) async fn inner_request(&self, method: Method, url: Url) -> RequestBuilder { self.http.request(method, url).fetch_credentials_include()