π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Generate types for Space creation and link results
Manav Rathic1b59743bdf9
diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex db1b06b300..5781f5a1a4 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -2888,6 +2888,7 @@ dependencies = ["serde-wasm-bindgen","thiserror 2.0.18","tokio",+ "tsify","wasm-bindgen","wasm-bindgen-futures",]diff --git a/rust/bindings/wasm/space/Cargo.toml b/rust/bindings/wasm/space/Cargo.tomlindex ce4be1f593..86f8f8f951 100644--- a/rust/bindings/wasm/space/Cargo.toml+++ b/rust/bindings/wasm/space/Cargo.toml@@ -14,6 +14,7 @@ log.workspace = trueserde.workspace = trueserde-wasm-bindgen.workspace = truethiserror.workspace = true+tsify.workspace = truewasm-bindgen.workspace = truewasm-bindgen-futures.workspace = truediff --git a/rust/bindings/wasm/space/src/space.rs b/rust/bindings/wasm/space/src/space.rsindex d951ca1544..6c6bd40710 100644--- a/rust/bindings/wasm/space/src/space.rs+++ b/rust/bindings/wasm/space/src/space.rs@@ -9,6 +9,7 @@ use ente_space::{};use serde::{Deserialize, Serialize};use serde_wasm_bindgen as swb;+use tsify::Tsify;use wasm_bindgen::prelude::*;#[derive(Debug, thiserror::Error)]@@ -97,16 +98,16 @@ struct PostPhotoAssetOptionsJsInput {thumb_hash: Option<String>,}-#[derive(Serialize)]+#[derive(Serialize, Tsify)]#[serde(rename_all = "camelCase")]-struct CreatedSpaceJs {+pub struct CreatedSpaceJs {space_id: String,space_slug: String,}-#[derive(Serialize)]+#[derive(Serialize, Tsify)]#[serde(rename_all = "camelCase")]-struct CreatedSpaceLinkJs {+pub struct CreatedSpaceLinkJs {space_id: String,space_slug: String,access_key: String,@@ -798,24 +799,32 @@ pub struct SpaceAccountCtxHandle {#[wasm_bindgen]impl SpaceAccountCtxHandle {#[wasm_bindgen(js_name = getOrCreateSpaceLink)]- pub async fn get_or_create_space_link(&self, space_id: String) -> Result<JsValue, Error> {+ pub async fn get_or_create_space_link(+ &self,+ space_id: String,+ ) -> Result<<CreatedSpaceLinkJs as Tsify>::JsType, Error> {let value = self.inner.get_or_create_space_link(&space_id).await?;- swb::to_value(&CreatedSpaceLinkJs {+ CreatedSpaceLinkJs {space_id: value.space_id,space_slug: value.space_slug,access_key: value.access_key,- })+ }+ .into_js().map_err(Into::into)}#[wasm_bindgen(js_name = rotateSpaceLink)]- pub async fn rotate_space_link(&self, space_id: String) -> Result<JsValue, Error> {+ pub async fn rotate_space_link(+ &self,+ space_id: String,+ ) -> Result<<CreatedSpaceLinkJs as Tsify>::JsType, Error> {let value = self.inner.rotate_space_link(&space_id).await?;- swb::to_value(&CreatedSpaceLinkJs {+ CreatedSpaceLinkJs {space_id: value.space_id,space_slug: value.space_slug,access_key: value.access_key,- })+ }+ .into_js().map_err(Into::into)}@@ -825,8 +834,8 @@ impl SpaceAccountCtxHandle {space_slug: String,profile: String,referred_by_space_id: Option<String>,- ) -> Result<JsValue, Error> {- swb::to_value(&created_space_to_js(+ ) -> Result<<CreatedSpaceJs as Tsify>::JsType, Error> {+ created_space_to_js(self.inner.create_space_with_referrer(&space_slug,@@ -834,7 +843,8 @@ impl SpaceAccountCtxHandle {referred_by_space_id.as_deref(),).await?,- ))+ )+ .into_js().map_err(Into::into)}diff --git a/web/apps/space/src/services/profile.ts b/web/apps/space/src/services/profile.tsindex b986a9fe7c..42149e7a09 100644--- a/web/apps/space/src/services/profile.ts+++ b/web/apps/space/src/services/profile.ts@@ -44,11 +44,6 @@ interface SpaceAvatar {type SpaceCover = SpaceAvatar;-interface CreatedSpace {- spaceId: string;- spaceSlug: string;-}-interface SpaceLookup {spaceId: string;spaceSlug: string;@@ -511,11 +506,11 @@ export const saveSpaceProfile = async (spaceSlug = updatedSlug.spaceSlug;}} else {- const created = (await ctx.createSpace(+ const created = await ctx.createSpace(username,profilePayload,referredBySpaceId?.trim() || undefined,- )) as CreatedSpace;+ );spaceId = created.spaceId;spaceSlug = created.spaceSlug;const createdSpaces = (await ctx.listOwnedSpaces()) as OwnedSpace[];diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.tsindex ea605e301d..a524aa83f0 100644--- a/web/apps/space/src/services/space.ts+++ b/web/apps/space/src/services/space.ts@@ -247,12 +247,6 @@ export interface PublicSpaceLinkSession {unsubscribeWebPush: (endpoint: string) => Promise<void>;}-export interface CurrentSpaceLink {- accessKey: string;- spaceId: string;- spaceSlug: string;-}-export type SpacePostAssetURLLoader = (asset: SpacePostAsset,) => Promise<string>;@@ -788,16 +782,12 @@ const withCurrentSpaceContext = async <T>(};export const getOrCreateCurrentSpaceLink = () =>- withCurrentSpaceContext(- async (ctx, spaceId) =>- (await ctx.getOrCreateSpaceLink(spaceId)) as CurrentSpaceLink,+ withCurrentSpaceContext((ctx, spaceId) =>+ ctx.getOrCreateSpaceLink(spaceId),);export const rotateCurrentSpaceLink = () =>- withCurrentSpaceContext(- async (ctx, spaceId) =>- (await ctx.rotateSpaceLink(spaceId)) as CurrentSpaceLink,- );+ withCurrentSpaceContext((ctx, spaceId) => ctx.rotateSpaceLink(spaceId));const messageQuoteFromPostResponse = async (ctx: SpaceAccountCtxHandle,