diff --git a/pubky/pkg/.gitignore b/pubky/pkg/.gitignore index 7355b75..d2a005f 100644 --- a/pubky/pkg/.gitignore +++ b/pubky/pkg/.gitignore @@ -1,4 +1,3 @@ -index.cjs browser.js coverage node_modules diff --git a/pubky/pkg/index.cjs b/pubky/pkg/index.cjs new file mode 100644 index 0000000..bd8a6a2 --- /dev/null +++ b/pubky/pkg/index.cjs @@ -0,0 +1,6 @@ +const makeFetchCookie = require("fetch-cookie").default; + +let originalFetch = globalThis.fetch; +globalThis.fetch = makeFetchCookie(originalFetch); + +module.exports = require('./nodejs/pubky') diff --git a/pubky/pkg/package.json b/pubky/pkg/package.json index be3e6df..1c08264 100644 --- a/pubky/pkg/package.json +++ b/pubky/pkg/package.json @@ -37,5 +37,8 @@ "esmify": "^2.1.1", "tape": "^5.8.1", "tape-run": "^11.0.0" + }, + "dependencies": { + "fetch-cookie": "^3.0.1" } } diff --git a/pubky/src/bin/patch.mjs b/pubky/src/bin/patch.mjs index a8ed503..86983b6 100644 --- a/pubky/src/bin/patch.mjs +++ b/pubky/src/bin/patch.mjs @@ -55,12 +55,3 @@ const bytes = __toBinary(${JSON.stringify(await readFile(path.join(__dirname, `. ); await writeFile(path.join(__dirname, `../../pkg/browser.js`), patched + "\nglobalThis['pubky'] = imports"); - -// Move outside of nodejs - -await Promise.all([".js", ".d.ts", "_bg.wasm"].map(suffix => - rename( - path.join(__dirname, `../../pkg/nodejs/${name}${suffix}`), - path.join(__dirname, `../../pkg/${suffix === '.js' ? "index.cjs" : (name + suffix)}`), - )) -) diff --git a/pubky/src/native/internals.rs b/pubky/src/native/internals.rs index 9f3ae40..c40ba77 100644 --- a/pubky/src/native/internals.rs +++ b/pubky/src/native/internals.rs @@ -1,6 +1,6 @@ use pkarr::SignedPacket; use pubky_common::crypto::PublicKey; -use reqwest::{RequestBuilder, Response}; +use reqwest::RequestBuilder; use url::Url; use crate::error::Result; @@ -28,7 +28,4 @@ impl PubkyClient { pub(crate) fn inner_request(&self, method: reqwest::Method, url: Url) -> RequestBuilder { self.http.request(method, url) } - - pub(crate) fn store_session(&self, _: &Response) {} - pub(crate) fn remove_session(&self, _: &PublicKey) {} } diff --git a/pubky/src/shared/auth.rs b/pubky/src/shared/auth.rs index bdb8473..7c3d9e1 100644 --- a/pubky/src/shared/auth.rs +++ b/pubky/src/shared/auth.rs @@ -43,8 +43,6 @@ impl PubkyClient { .send() .await?; - self.store_session(&response); - self.publish_pubky_homeserver(keypair, &homeserver).await?; let bytes = response.bytes().await?; @@ -84,8 +82,6 @@ impl PubkyClient { self.inner_request(Method::DELETE, url).send().await?; - self.remove_session(pubky); - Ok(()) } @@ -175,8 +171,6 @@ impl PubkyClient { .send() .await?; - self.store_session(&response); - let bytes = response.bytes().await?; Ok(Session::deserialize(&bytes)?) diff --git a/pubky/src/wasm/internals/http.rs b/pubky/src/wasm/internals/http.rs index b28d9f9..83c7821 100644 --- a/pubky/src/wasm/internals/http.rs +++ b/pubky/src/wasm/internals/http.rs @@ -1,6 +1,6 @@ use crate::PubkyClient; -use reqwest::{Method, RequestBuilder, Response}; +use reqwest::{Method, RequestBuilder}; use url::Url; impl PubkyClient { @@ -13,28 +13,4 @@ impl PubkyClient { request } - - // Support cookies for nodejs - - pub(crate) fn store_session(&self, response: &Response) { - if let Some(cookie) = response - .headers() - .get("set-cookie") - .and_then(|h| h.to_str().ok()) - .and_then(|s| s.split(';').next()) - { - self.session_cookies - .write() - .unwrap() - .insert(cookie.to_string()); - } - } - pub(crate) fn remove_session(&self, pubky: &pkarr::PublicKey) { - let key = pubky.to_string(); - - self.session_cookies - .write() - .unwrap() - .retain(|cookie| !cookie.starts_with(&key)); - } }