(rawUrl: string)
| 33 | } |
| 34 | |
| 35 | export function parseOpenNoteDeepLink(rawUrl: string): OpenNoteDeepLinkRequest | null { |
| 36 | const trimmed = rawUrl.trim() |
| 37 | if (!trimmed) return null |
| 38 | |
| 39 | let parsed: URL |
| 40 | try { |
| 41 | parsed = new URL(trimmed) |
| 42 | } catch { |
| 43 | return null |
| 44 | } |
| 45 | |
| 46 | if (parsed.protocol !== `${ZENNOTES_DEEP_LINK_SCHEME}:`) return null |
| 47 | |
| 48 | const action = deepLinkAction(parsed) |
| 49 | const target = OPEN_NOTE_ACTION_TARGETS[action] |
| 50 | if (!target) return null |
| 51 | |
| 52 | const notePath = normalizeDeepLinkNotePath(parsed.searchParams.get('path')) |
| 53 | return notePath ? { target, path: notePath } : null |
| 54 | } |
| 55 | |
| 56 | export function normalizeDeepLinkNotePath(rawPath: string | null | undefined): string | null { |
| 57 | const trimmed = rawPath?.trim() |
no test coverage detected