Files
beenvoice-app/lib/shortcuts.ts
T
soconnorandCursor 6762a9bff3 Move production to beenvoice.app with migrated accounts, refreshed auth and timer UX, and expanded invoice flows.
Official URL migration preserves sessions, shortcuts prefs, and last clock-in client; auth screens match web with legal links; time clock and invoice editor/send flows are updated for the new domain and UI patterns.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 03:40:48 -04:00

67 lines
1.9 KiB
TypeScript

import * as Linking from "expo-linking";
export type ShortcutAction = "clock-in" | "clock-out" | "open-timer";
export type ParsedShortcut = {
action: ShortcutAction;
title: string;
clientId: string;
};
function queryParam(value: string | string[] | undefined): string {
if (Array.isArray(value)) return value[0] ?? "";
return value ?? "";
}
function normalizeShortcutPath(hostname: string | null, path: string | null): string | null {
const host = (hostname ?? "").replace(/^\/+|\/+$/g, "");
const segment = (path ?? "").replace(/^\/+|\/+$/g, "");
if (host === "shortcuts" && segment) {
return segment;
}
const combined = [host, segment].filter(Boolean).join("/");
const match = combined.match(/(?:^|\/)shortcuts\/(clock-in|clock-out)$/);
if (match?.[1]) return match[1];
if (combined === "clock-in" || combined === "clock-out") {
return combined;
}
return null;
}
/** Parse `beenvoice://shortcuts/clock-in` and related URLs from Shortcuts / Siri. */
export function parseShortcutUrl(url: string | null | undefined): ParsedShortcut | null {
if (!url) return null;
const parsed = Linking.parse(url);
if (parsed.scheme !== "beenvoice") return null;
const path = (parsed.path ?? "").replace(/^\/+/, "");
const host = parsed.hostname ?? "";
if (path === "timer" || host === "timer") {
return { action: "open-timer", title: "", clientId: "" };
}
const shortcutAction = normalizeShortcutPath(host, path);
if (shortcutAction === "clock-in" || shortcutAction === "clock-out") {
return {
action: shortcutAction,
title: queryParam(parsed.queryParams?.title),
clientId: queryParam(parsed.queryParams?.clientId),
};
}
return null;
}
export const SHORTCUT_URLS = {
timer: "beenvoice://timer",
openTimer: "beenvoice://timer",
clockIn: "beenvoice://shortcuts/clock-in",
clockOut: "beenvoice://shortcuts/clock-out",
} as const;