AI-native design editor. Open-source Figma alternative.
refactor: build Cloud links with ufo in one place for the editor and the server (#1288)
Danila Poyarkovc6621d2e4c55
diff --git a/bun.lock b/bun.lockindex fbd72eeb3..588144cc7 100644--- a/bun.lock+++ b/bun.lock@@ -87,6 +87,7 @@"tailwind-variants": "^3.3.1","tailwindcss": "^4.3.3","tinykeys": "^3.1.0",+ "ufo": "^1.6.4","valibot": "^1.5.0","vee-validate": "5.0.0-beta.0","vue": "^3.5.43",@@ -226,6 +227,7 @@"lib0": "^0.2.117","nodemailer": "^9.0.5","smol-toml": "^1.8.0",+ "ufo": "^1.6.4","valibot": "^1.5.0","vue": "^3.5.43","ws": "^8.21.3",diff --git a/desktop/src/deep_link.rs b/desktop/src/deep_link.rsindex 44fb2f8ff..62580cb58 100644--- a/desktop/src/deep_link.rs+++ b/desktop/src/deep_link.rs@@ -323,6 +323,13 @@ mod tests {..}))));+ // The editor builds links with ufo, which leaves `:` in a query value as it is.+ assert!(matches!(+ cloud(&format!(+ "openpencil://cloud/share/{CLOUD_ID}?server=https:%2F%2Fcloud.example.com#{CLOUD_SECRET}"+ )),+ Ok(DeepLink::Cloud(CloudLink { ref server, .. })) if server == "https://cloud.example.com/"+ ));}#[test]diff --git a/package.json b/package.jsonindex 81ba02307..94942187e 100644--- a/package.json+++ b/package.json@@ -200,6 +200,7 @@"tailwind-variants": "^3.3.1","tailwindcss": "^4.3.3","tinykeys": "^3.1.0",+ "ufo": "^1.6.4","valibot": "^1.5.0","vee-validate": "5.0.0-beta.0","vue": "^3.5.43",diff --git a/packages/cloud/package.json b/packages/cloud/package.jsonindex 44b0d59ae..3855743c0 100644--- a/packages/cloud/package.json+++ b/packages/cloud/package.json@@ -90,6 +90,7 @@"lib0": "^0.2.117","nodemailer": "^9.0.5","smol-toml": "^1.8.0",+ "ufo": "^1.6.4","valibot": "^1.5.0","vue": "^3.5.43","ws": "^8.21.3",diff --git a/packages/cloud/src/client/auth/client.ts b/packages/cloud/src/client/auth/client.tsindex ce614aeb7..776408759 100644--- a/packages/cloud/src/client/auth/client.ts+++ b/packages/cloud/src/client/auth/client.ts@@ -2,6 +2,7 @@ import type { CloudDiscovery } from '#cloud/contract'import { passkeyClient } from '@better-auth/passkey/client'import { createAuthClient } from 'better-auth/client'import { deviceAuthorizationClient, twoFactorClient } from 'better-auth/client/plugins'+import { withoutFragment } from 'ufo'import type { CloudFetch } from '../discovery'import { cloudAuthFailure, type CloudAuthResult } from './failure'@@ -9,9 +10,7 @@ import { cloudAuthFailure, type CloudAuthResult } from './failure'export type CloudSocialProvider = CloudDiscovery['authentication']['socialProviders'][number]function returnURL(): string {- const url = new URL(globalThis.location.href)- url.hash = ''- return url.href+ return withoutFragment(globalThis.location.href)}type DeviceActionResult = Promise<{diff --git a/packages/cloud/src/client/auth/navigation.ts b/packages/cloud/src/client/auth/navigation.tsindex 815ecf1ef..470e0cf01 100644--- a/packages/cloud/src/client/auth/navigation.ts+++ b/packages/cloud/src/client/auth/navigation.ts@@ -1,4 +1,5 @@import type { CloudDiscovery } from '#cloud/contract'+import { withoutFragment, withQuery } from 'ufo'import type { CloudSocialProvider } from './client'@@ -15,8 +16,7 @@ export function cloudEditorReturnURL(discovery: CloudDiscovery, value: string):) {throw new Error('Authentication return URL must belong to this instance editor')}- destination.hash = ''- return destination.href+ return withoutFragment(destination.href)}/**@@ -29,13 +29,19 @@ export function cloudSignInURL(returnURL: string,provider?: CloudSocialProvider): string {- const destination = cloudEditorReturnURL(discovery, returnURL)- const continuation = new URL('/auth/return', discovery.authURL)- continuation.searchParams.set('editor', destination)- const signIn = new URL('/auth/sign-in', discovery.authURL)- signIn.searchParams.set('redirect', `${continuation.pathname}${continuation.search}`)- if (provider && discovery.authentication.socialProviders.includes(provider)) {- signIn.searchParams.set('provider', provider)- }- return signIn.href+ const offered = provider && discovery.authentication.socialProviders.includes(provider)+ // The pages are at the server's root, whatever path the auth API has.+ return withQuery(new URL('/auth/sign-in', discovery.authURL).href, {+ redirect: withQuery('/auth/return', { editor: cloudEditorReturnURL(discovery, returnURL) }),+ provider: offered ? provider : undefined+ })+}++/** Accept only same-origin application paths for post-authentication navigation. */+export function cloudRedirectPath(value: unknown, fallback = '/app'): string {+ if (typeof value !== 'string' || !value.startsWith('/') || value.startsWith('//')) return fallback+ const origin = 'https://redirect.invalid'+ const url = new URL(value, origin)+ if (url.origin !== origin) return fallback+ return `${url.pathname}${url.search}${url.hash}`}diff --git a/packages/cloud/src/client/device-authorization.ts b/packages/cloud/src/client/device-authorization.tsindex 9f02d14d4..300c5bee9 100644--- a/packages/cloud/src/client/device-authorization.ts+++ b/packages/cloud/src/client/device-authorization.ts@@ -1,4 +1,5 @@import type { CloudDiscovery } from '#cloud/contract'+import { joinURL } from 'ufo'import * as v from 'valibot'import type { CloudFetch } from './discovery'@@ -59,7 +60,7 @@ function abortableSleep(milliseconds: number, signal?: AbortSignal): Promise<voi}function authEndpoint(discovery: CloudDiscovery, path: string): string {- return new URL(path, `${discovery.authURL.replace(/\/$/, '')}/`).href+ return joinURL(discovery.authURL, path)}export type CloudDeviceAuthorizationOptions = {diff --git a/packages/cloud/src/client/index.ts b/packages/cloud/src/client/index.tsindex edc5951f7..411237c1f 100644--- a/packages/cloud/src/client/index.ts+++ b/packages/cloud/src/client/index.ts@@ -1,12 +1,4 @@-export { cloudEditorReturnURL, cloudSignInURL } from './auth/navigation'-export {- cloudDesktopLinkURL,- cloudDocumentPath,- cloudDocumentURL,- cloudRedirectPath,- cloudShareURL,- type CloudLinkKind-} from './links'+export { cloudEditorReturnURL, cloudRedirectPath, cloudSignInURL } from './auth/navigation'export {CloudAPIError,createCloudAPIClient,diff --git a/packages/cloud/src/client/links.ts b/packages/cloud/src/client/links.tsdeleted file mode 100644index eeee165cf..000000000--- a/packages/cloud/src/client/links.ts+++ /dev/null@@ -1,73 +0,0 @@-import type { CloudDiscovery } from '#cloud/contract'--/** Canonical web links come from the owning instance, never the caller's window. */-function editorURL(discovery: CloudDiscovery, path: string, serverURL: string): URL {- if (!discovery.appURL) throw new Error('This instance does not advertise a public editor URL')- const url = new URL(discovery.appURL)- if (url.protocol !== 'https:' && url.protocol !== 'http:') {- throw new Error('The public editor URL must use HTTP or HTTPS')- }- url.pathname = path- url.search = ''- url.hash = ''- url.searchParams.set('server', serverURL)- return url-}--export function cloudShareURL(- discovery: CloudDiscovery,- serverURL: string,- shareId: string,- secret: string-): string {- const url = editorURL(discovery, `/cloud/share/${encodeURIComponent(shareId)}`, serverURL)- url.hash = secret- return url.href-}--/**- * A document's address for its members, `/cloud/documents/:id?server=…`, or one of its versions- * with `&version=…`. It carries no secret: whoever opens it signs in, and the server decides.- */-export function cloudDocumentURL(- discovery: CloudDiscovery,- serverURL: string,- documentId: string,- versionId: string | null = null-): string {- const url = editorURL(discovery, cloudDocumentPath(documentId), serverURL)- if (versionId) url.searchParams.set('version', versionId)- return url.href-}--export function cloudDocumentPath(documentId: string): string {- return `/cloud/documents/${encodeURIComponent(documentId)}`-}--/** The two kinds of Cloud link that carry a secret: invitations and documents shared by link. */-export type CloudLinkKind = 'invitations' | 'share'--/**- * The desktop app's form of a Cloud link, `openpencil://cloud/<kind>/<id>?server=…#secret`, which- * `desktop/src/deep_link.rs` validates before the editor sees it.- */-export function cloudDesktopLinkURL(- kind: CloudLinkKind,- id: string,- serverURL: string,- secret: string-): string {- const url = new URL(`openpencil://cloud/${kind}/${encodeURIComponent(id)}`)- url.searchParams.set('server', serverURL)- url.hash = secret- return url.href-}--/** Accept only same-origin application paths for post-authentication navigation. */-export function cloudRedirectPath(value: unknown, fallback = '/app'): string {- if (typeof value !== 'string' || !value.startsWith('/') || value.startsWith('//')) return fallback- const origin = 'https://redirect.invalid'- const url = new URL(value, origin)- if (url.origin !== origin) return fallback- return `${url.pathname}${url.search}${url.hash}`-}diff --git a/packages/cloud/src/contract/index.ts b/packages/cloud/src/contract/index.tsindex bee9b63bf..4376771c6 100644--- a/packages/cloud/src/contract/index.ts+++ b/packages/cloud/src/contract/index.ts@@ -124,5 +124,13 @@ export {type WorkspaceRole,type WorkspaceSummary} from './workspaces'+export {+ cloudDesktopLinkURL,+ cloudDocumentPath,+ cloudDocumentURL,+ cloudInvitationURL,+ cloudShareURL,+ type CloudLinkKind+} from './links'export { CLOUD_PORTAL_PAGE_ROOTS, isCloudPortalPage } from './portal'export * from './versions'diff --git a/packages/cloud/src/contract/links.ts b/packages/cloud/src/contract/links.tsnew file mode 100644index 000000000..ecacf99f8--- /dev/null+++ b/packages/cloud/src/contract/links.ts@@ -0,0 +1,85 @@+import { encodeParam, parseURL, withFragment, withQuery } from 'ufo'++/** The two kinds of Cloud link that carry a secret: invitations and documents shared by link. */+export type CloudLinkKind = 'invitations' | 'share'++/**+ * A link on an instance's public editor, `appURL`, naming the server it belongs to. Canonical+ * links come from the owning instance, never the caller's window; a secret travels in the+ * fragment, so it never reaches access logs or `Referer` headers.+ */+function editorLink(+ appURL: string | undefined,+ path: string,+ query: Record<string, string | undefined>,+ secret?: string+): string {+ if (!appURL) throw new Error('This instance does not advertise a public editor URL')+ const { protocol, host } = parseURL(appURL)+ if (protocol !== 'https:' && protocol !== 'http:') {+ throw new Error('The public editor URL must use HTTP or HTTPS')+ }+ const link = withQuery(`${protocol}//${host}${path}`, query)+ return secret ? withFragment(link, secret) : link+}++/** An invitation to a document or a workspace, `/cloud/invitations/:id?server=…#token`. */+export function cloudInvitationURL(+ appURL: string | undefined,+ serverURL: string,+ invitationId: string,+ token: string+): string {+ return editorLink(+ appURL,+ `/cloud/invitations/${encodeParam(invitationId)}`,+ { server: serverURL },+ token+ )+}++/** A document shared by link, `/cloud/share/:id?server=…#secret`. */+export function cloudShareURL(+ appURL: string | undefined,+ serverURL: string,+ shareId: string,+ secret: string+): string {+ return editorLink(appURL, `/cloud/share/${encodeParam(shareId)}`, { server: serverURL }, secret)+}++/**+ * A document's address for its members, `/cloud/documents/:id?server=…`, or one of its versions+ * with `&version=…`. It carries no secret: whoever opens it signs in, and the server decides.+ */+export function cloudDocumentURL(+ appURL: string | undefined,+ serverURL: string,+ documentId: string,+ versionId: string | null = null+): string {+ return editorLink(appURL, cloudDocumentPath(documentId), {+ server: serverURL,+ version: versionId ?? undefined+ })+}++export function cloudDocumentPath(documentId: string): string {+ return `/cloud/documents/${encodeParam(documentId)}`+}++/**+ * The desktop app's form of a Cloud link, `openpencil://cloud/<kind>/<id>?server=…#secret`, which+ * `desktop/src/deep_link.rs` validates before the editor sees it.+ */+export function cloudDesktopLinkURL(+ kind: CloudLinkKind,+ id: string,+ serverURL: string,+ secret: string+): string {+ return withFragment(+ withQuery(`openpencil://cloud/${kind}/${encodeParam(id)}`, { server: serverURL }),+ secret+ )+}diff --git a/packages/cloud/src/server/config/public.ts b/packages/cloud/src/server/config/public.tsindex fc8574aa5..7cd95ffe7 100644--- a/packages/cloud/src/server/config/public.ts+++ b/packages/cloud/src/server/config/public.ts@@ -1,4 +1,5 @@import { CLOUD_PROTOCOL_VERSION, parseCloudDiscovery, type CloudDiscovery } from '#cloud/contract'+import { withoutTrailingSlash } from 'ufo'import type { CloudServerConfig } from './schema'@@ -40,8 +41,8 @@ export function cloudDiscoveryFromConfig(config: CloudServerConfig): CloudDiscovreturn parseCloudDiscovery({protocolVersion: CLOUD_PROTOCOL_VERSION,deployment: config.deployment,- apiURL: new URL('/api', config.publicURL).href.replace(/\/$/, ''),- authURL: new URL('/api/auth', config.publicURL).href.replace(/\/$/, ''),+ apiURL: withoutTrailingSlash(new URL('/api', config.publicURL).href),+ authURL: withoutTrailingSlash(new URL('/api/auth', config.publicURL).href),appURL: config.appURL ?? config.publicURL,authentication,capabilities: {diff --git a/packages/cloud/src/server/sharing/invitations/service.ts b/packages/cloud/src/server/sharing/invitations/service.tsindex 86ccaac87..f5e0aec04 100644--- a/packages/cloud/src/server/sharing/invitations/service.ts+++ b/packages/cloud/src/server/sharing/invitations/service.ts@@ -7,6 +7,7 @@ import type {InvitationPreview,WorkspaceRole} from '#cloud/contract'+import { cloudInvitationURL } from '#cloud/contract'import type { CloudActor } from '#cloud/server/auth'import type { CloudDatabase } from '#cloud/server/db'import { DocumentNotFoundError } from '#cloud/server/documents/service'@@ -146,10 +147,7 @@ export function createInvitationService(: nullconst acceptanceURL =deliveryContext && options.publicURL && options.appURL- ? new URL(- `/cloud/invitations/${id}?server=${encodeURIComponent(options.publicURL)}#${token}`,- options.appURL- ).href+ ? cloudInvitationURL(options.appURL, options.publicURL, id, token): nullconst message =deliveryContext && acceptanceURLdiff --git a/packages/cloud/src/server/workspaces/members.ts b/packages/cloud/src/server/workspaces/members.tsindex 8cbe62879..232d74198 100644--- a/packages/cloud/src/server/workspaces/members.ts+++ b/packages/cloud/src/server/workspaces/members.ts@@ -7,6 +7,7 @@ import type {WorkspaceRole,WorkspaceSummary} from '#cloud/contract'+import { cloudInvitationURL } from '#cloud/contract'import type { CloudActor } from '#cloud/server/auth'import type { CloudDatabase } from '#cloud/server/db'import type { TransactionalEmailService } from '#cloud/server/email/types'@@ -163,10 +164,7 @@ export function createWorkspaceMemberService(}function acceptanceURL(invitationId: string, token: string): string {- return new URL(- `/cloud/invitations/${invitationId}?server=${encodeURIComponent(options.publicURL)}#${token}`,- options.appURL- ).href+ return cloudInvitationURL(options.appURL, options.publicURL, invitationId, token)}return {diff --git a/packages/cloud/tests/client/auth/navigation.test.ts b/packages/cloud/tests/client/auth/navigation.test.tsindex f99d2b115..4a799991b 100644--- a/packages/cloud/tests/client/auth/navigation.test.ts+++ b/packages/cloud/tests/client/auth/navigation.test.ts@@ -1,6 +1,6 @@import { expect, test } from 'bun:test'-import { cloudEditorReturnURL, cloudSignInURL } from '#cloud/client'+import { cloudEditorReturnURL, cloudRedirectPath, cloudSignInURL } from '#cloud/client'import type { CloudDiscovery } from '#cloud/contract'const discovery: CloudDiscovery = {@@ -52,3 +52,17 @@ test('a chosen provider rides along only when the server offers it', () => {const apple = new URL(cloudSignInURL(social, 'https://editor.example/', 'apple'))expect(apple.searchParams.has('provider')).toBe(false)})++test('authentication continuation stays on the issuing origin', () => {+ expect(cloudRedirectPath('/cloud/device?user_code=ABCD')).toBe('/cloud/device?user_code=ABCD')+ for (const input of [+ '//evil.example',+ '/\\evil.example',+ 'https://evil.example',+ // eslint-disable-next-line no-script-url -- Reject script URLs at the untrusted navigation boundary.+ 'javascript:alert(1)',+ undefined+ ]) {+ expect(cloudRedirectPath(input)).toBe('/app')+ }+})diff --git a/packages/cloud/tests/client/links.test.ts b/packages/cloud/tests/contract/links.test.tssimilarity index 51%rename from packages/cloud/tests/client/links.test.tsrename to packages/cloud/tests/contract/links.test.tsindex a0b132cf9..d2f168548 100644--- a/packages/cloud/tests/client/links.test.ts+++ b/packages/cloud/tests/contract/links.test.ts@@ -3,23 +3,14 @@ import { expect, test } from 'bun:test'import {cloudDesktopLinkURL,cloudDocumentURL,- cloudRedirectPath,+ cloudInvitationURL,cloudShareURL-} from '#cloud/client'-import type { CloudDiscovery } from '#cloud/contract'+} from '#cloud/contract'-const discovery: CloudDiscovery = {- protocolVersion: '1',- deployment: 'self-hosted',- apiURL: 'https://company.example/api',- authURL: 'https://company.example/api/auth',- appURL: 'https://editor.company.example',- authentication: { socialProviders: [], enterpriseSSO: false, enrollmentMode: 'open' },- capabilities: { documents: true, workspaces: true, collaboration: true }-}+const appURL = 'https://editor.company.example'test('sharing uses the owning public editor without requiring browser globals', () => {- const url = new URL(cloudShareURL(discovery, 'https://company.example', 'share-id', 'secret'))+ const url = new URL(cloudShareURL(appURL, 'https://company.example', 'share-id', 'secret'))expect(url.origin).toBe('https://editor.company.example')expect(url.pathname).toBe('/cloud/share/share-id')expect(url.searchParams.get('server')).toBe('https://company.example')@@ -28,16 +19,14 @@ test('sharing uses the owning public editor without requiring browser globals',})test('sharing rejects absent or non-web editor URLs', () => {+ expect(() => cloudShareURL(undefined, 'https://company.example', 'id', 'secret')).toThrow()expect(() =>- cloudShareURL({ ...discovery, appURL: undefined }, discovery.apiURL, 'id', 'secret')- ).toThrow()- expect(() =>- cloudShareURL({ ...discovery, appURL: 'tauri://localhost' }, discovery.apiURL, 'id', 'secret')+ cloudShareURL('tauri://localhost', 'https://company.example', 'id', 'secret')).toThrow()})test('a document or version address names its server and carries no secret', () => {- const document = new URL(cloudDocumentURL(discovery, 'https://company.example', 'doc-id'))+ const document = new URL(cloudDocumentURL(appURL, 'https://company.example', 'doc-id'))expect(document.origin).toBe('https://editor.company.example')expect(document.pathname).toBe('/cloud/documents/doc-id')expect(document.searchParams.get('server')).toBe('https://company.example')@@ -45,26 +34,23 @@ test('a document or version address names its server and carries no secret', ()expect(document.hash).toBe('')const version = new URL(- cloudDocumentURL(discovery, 'https://company.example', 'doc-id', 'version-id')+ cloudDocumentURL(appURL, 'https://company.example', 'doc-id', 'version-id'))expect(version.searchParams.get('version')).toBe('version-id')- const anchored = { ...discovery, appURL: 'https://editor.company.example/#welcome' }+ const anchored = 'https://editor.company.example/#welcome'expect(new URL(cloudDocumentURL(anchored, 'https://company.example', 'doc-id')).hash).toBe('')})-test('authentication continuation stays on the issuing origin', () => {- expect(cloudRedirectPath('/cloud/device?user_code=ABCD')).toBe('/cloud/device?user_code=ABCD')- for (const input of [- '//evil.example',- '/\\evil.example',- 'https://evil.example',- // eslint-disable-next-line no-script-url -- Reject script URLs at the untrusted navigation boundary.- 'javascript:alert(1)',- undefined- ]) {- expect(cloudRedirectPath(input)).toBe('/app')- }+test('an invitation names its server and carries its token in the fragment', () => {+ const url = new URL(+ cloudInvitationURL(appURL, 'https://company.example', 'invitation/id', 'token')+ )+ expect(url.origin).toBe('https://editor.company.example')+ expect(url.pathname).toBe('/cloud/invitations/invitation%2Fid')+ expect(url.searchParams.get('server')).toBe('https://company.example')+ expect(url.hash).toBe('#token')+ expect(url.search).not.toContain('token')})test('desktop links keep the web link path, server, and secret under the app scheme', () => {diff --git a/src/app/cloud/documents/link.ts b/src/app/cloud/documents/link.tsindex 6f9ed2ace..0ff01d091 100644--- a/src/app/cloud/documents/link.ts+++ b/src/app/cloud/documents/link.ts@@ -2,7 +2,7 @@ import { useSessionStorage } from '@vueuse/core'import * as v from 'valibot'import { ref, watch } from 'vue'-import { cloudDocumentPath, cloudDocumentURL } from '@open-pencil/cloud/client'+import { cloudDocumentPath, cloudDocumentURL } from '@open-pencil/cloud/contract'import { cloudMessages } from '@open-pencil/vue'import type { EditorStore } from '@/app/editor/session'@@ -92,7 +92,7 @@ export function cloudVersionLinkURL(store: EditorStore, versionId: string): striconst target = linkTarget(store)if (!target) return nullconst { binding, server, discovery } = target- return cloudDocumentURL(discovery, server.url, binding.documentId, versionId)+ return cloudDocumentURL(discovery.appURL, server.url, binding.documentId, versionId)}/**diff --git a/src/app/cloud/invitations/flow.ts b/src/app/cloud/invitations/flow.tsindex e83c61fc9..8b97221c0 100644--- a/src/app/cloud/invitations/flow.ts+++ b/src/app/cloud/invitations/flow.ts@@ -2,8 +2,12 @@ import { useSessionStorage } from '@vueuse/core'import * as v from 'valibot'import { computed, ref, shallowRef } from 'vue'-import { CloudAPIError, cloudDesktopLinkURL, createCloudAPIClient } from '@open-pencil/cloud/client'-import type { AcceptedInvitation, InvitationPreview } from '@open-pencil/cloud/contract'+import { CloudAPIError, createCloudAPIClient } from '@open-pencil/cloud/client'+import {+ cloudDesktopLinkURL,+ type AcceptedInvitation,+ type InvitationPreview+} from '@open-pencil/cloud/contract'import { openHomeLocation } from '@/app/shell/menu/navigation'import { openStorageDocumentInNewTab } from '@/app/tabs'diff --git a/src/app/cloud/links.ts b/src/app/cloud/links.tsindex d14b6376c..4f453b72d 100644--- a/src/app/cloud/links.ts+++ b/src/app/cloud/links.ts@@ -1,6 +1,6 @@import * as v from 'valibot'-import { cloudDesktopLinkURL, type CloudLinkKind } from '@open-pencil/cloud/client'+import { cloudDesktopLinkURL, type CloudLinkKind } from '@open-pencil/cloud/contract'import { cloudMessages, useViewportKind } from '@open-pencil/vue'import { toast } from '@/app/shell/ui'diff --git a/src/app/cloud/sessions/sign-in.ts b/src/app/cloud/sessions/sign-in.tsindex 41e8fa3f2..2f64ae11d 100644--- a/src/app/cloud/sessions/sign-in.ts+++ b/src/app/cloud/sessions/sign-in.ts@@ -1,4 +1,5 @@import { useSessionStorage } from '@vueuse/core'+import { withoutFragment } from 'ufo'import { ref } from 'vue'import { cloudSignInURL, type CloudSocialProvider } from '@open-pencil/cloud/client'@@ -24,9 +25,7 @@ export function cloudSignInRoute(discovery: CloudDiscovery): 'redirect' | 'devicexport type CloudSignInMethod = CloudSocialProvider | 'email'function returnURL(): string {- const url = new URL(globalThis.location.href)- url.hash = ''- return url.href+ return withoutFragment(globalThis.location.href)}/**diff --git a/src/app/cloud/sharing/document.ts b/src/app/cloud/sharing/document.tsindex 1446aac04..564bc1bee 100644--- a/src/app/cloud/sharing/document.ts+++ b/src/app/cloud/sharing/document.ts@@ -1,5 +1,10 @@-import { cloudShareURL, type CloudAPIClient } from '@open-pencil/cloud/client'-import type { CloudDiscovery, DocumentPermission, DocumentShare } from '@open-pencil/cloud/contract'+import type { CloudAPIClient } from '@open-pencil/cloud/client'+import {+ cloudShareURL,+ type CloudDiscovery,+ type DocumentPermission,+ type DocumentShare+} from '@open-pencil/cloud/contract'import type { StorageDocumentBinding } from '@/app/integrations/storage/types'@@ -173,5 +178,5 @@ export async function cloudLinkURL(target: Target): Promise<string | null> {const share = activeShare(await target.client.listDocumentShares(target.documentId))if (!share) return nullconst secret = await readShareSecret(target.server.id, share.id)- return secret ? cloudShareURL(target.discovery, target.server.url, share.id, secret) : null+ return secret ? cloudShareURL(target.discovery.appURL, target.server.url, share.id, secret) : null}diff --git a/tests/app/cloud/links.test.ts b/tests/app/cloud/links.test.tsindex 009d05a0e..4e2b8698c 100644--- a/tests/app/cloud/links.test.ts+++ b/tests/app/cloud/links.test.ts@@ -1,7 +1,7 @@import 'fake-indexeddb/auto'import { describe, expect, test } from 'bun:test'-import { cloudDesktopLinkURL } from '@open-pencil/cloud/client'+import { cloudDesktopLinkURL } from '@open-pencil/cloud/contract'import { readCloudLink } from '@/app/cloud/links'@@ -36,8 +36,12 @@ describe('Cloud links', () => {)if (!web) throw new Error('Expected a Cloud link')const desktop = new URL(cloudDesktopLinkURL(web.kind, web.id, web.server, web.secret))- expect(desktop.href).toBe(- `openpencil://cloud/share/abc?server=${encodeURIComponent(SERVER)}#secret`- )+ expect([desktop.protocol, desktop.host, desktop.pathname]).toEqual([+ 'openpencil:',+ 'cloud',+ '/share/abc'+ ])+ expect(desktop.searchParams.get('server')).toBe(SERVER)+ expect(desktop.hash).toBe('#secret')})})