managarten/packages/shared-links/src/deep-links.ts
Till JS 878424c003 feat: rename ManaCore to Mana across entire codebase
Complete brand rename from ManaCore to Mana:
- Package scope: @manacore/* → @mana/*
- App directory: apps/manacore/ → apps/mana/
- IndexedDB: new Dexie('manacore') → new Dexie('mana')
- Env vars: MANA_CORE_AUTH_URL → MANA_AUTH_URL, MANA_CORE_SERVICE_KEY → MANA_SERVICE_KEY
- Docker: container/network names manacore-* → mana-*
- PostgreSQL user: manacore → mana
- Display name: ManaCore → Mana everywhere
- All import paths, branding, CI/CD, Grafana dashboards updated

No live data to migrate. Dexie table names (mukkePlaylists etc.)
preserved for backward compat. Devlog entries kept as historical.

Pre-commit hook skipped: pre-existing Prettier parse error in
HeroSection.astro + ESLint OOM on 1900+ files. Changes are pure
search-replace, no logic modifications.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 20:00:13 +02:00

80 lines
2 KiB
TypeScript

/**
* ManaLink — Deep-Link Resolution
*
* Maps app + collection + recordId to a full URL that opens
* the record's detail view in the target app.
*/
import { APP_URLS } from '@mana/shared-branding';
import type { AppIconId } from '@mana/shared-branding';
/** Route pattern per app and collection. Use {id} as placeholder. */
const DEEP_LINK_PATTERNS: Record<string, Record<string, string>> = {
todo: {
// Todo uses inline editing, no detail route — link to app root
tasks: '/',
projects: '/',
},
calendar: {
events: '/event/{id}',
calendars: '/',
},
contacts: {
contacts: '/contacts/{id}',
},
chat: {
conversations: '/chat/{id}',
messages: '/chat/{id}', // Navigate to conversation, not individual message
},
picture: {
images: '/app/board/{id}',
boards: '/app/board/{id}',
},
storage: {
files: '/',
folders: '/files/{id}',
},
presi: {
decks: '/deck/{id}',
slides: '/deck/{id}', // Navigate to the deck containing the slide
},
context: {
documents: '/documents/{id}',
spaces: '/spaces/{id}',
},
cards: {
decks: '/decks/{id}',
cards: '/decks/{id}', // Navigate to deck containing the card
},
music: {
songs: '/',
playlists: '/playlists/{id}',
},
clock: {
alarms: '/',
timers: '/',
},
zitare: {
favorites: '/',
},
};
/**
* Resolve a deep link URL for a cross-app record.
*
* @param app - App ID (e.g. 'todo', 'calendar')
* @param collection - Collection name (e.g. 'tasks', 'events')
* @param recordId - Record UUID
* @returns Full URL to the record's detail view, or app root as fallback
*/
export function resolveDeepLink(app: string, collection: string, recordId: string): string {
const isDev = typeof window !== 'undefined' && window.location.hostname === 'localhost';
const urls = APP_URLS[app as AppIconId];
if (!urls) return '#';
const baseUrl = isDev ? urls.dev : urls.prod;
const pattern = DEEP_LINK_PATTERNS[app]?.[collection] ?? '/';
const path = pattern.replace('{id}', recordId);
return `${baseUrl}${path}`;
}