{"version":3,"sources":["../../../src/components/features/mux-origins.ts"],"names":[],"mappings":";;;AA4BO,IAAM,iBAAA,GAAoB;AAG1B,IAAM,gBAAA,GAAmB;AAqBzB,SAAS,eAAA,CAAgB,GAAA,EAAa,aAAA,GAAkC,MAAA,EAAgB;AAC7F,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAI,IAAI,GAAG,CAAA;AAAA,EACtB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,IAAI,MAAA,CAAO,MAAA,KAAW,iBAAA,EAAmB,OAAO,GAAA;AAChD,EAAA,IAAI,CAAC,MAAA,CAAO,QAAA,CAAS,QAAA,CAAS,OAAO,GAAG,OAAO,GAAA;AAC/C,EAAA,IAAI,MAAA,CAAO,YAAA,CAAa,GAAA,CAAI,OAAO,GAAG,OAAO,GAAA;AAC7C,EAAA,MAAA,CAAO,YAAA,CAAa,GAAA,CAAI,gBAAA,EAAkB,aAAa,CAAA;AACvD,EAAA,OAAO,OAAO,QAAA,EAAS;AACzB","file":"mux-origins.cjs","sourcesContent":["/**\n * Mux CDN origins + playback-URL helpers — single source of truth, server-safe.\n *\n * Lives in its own NON-`'use client'` module so server-side hub\n * modules (webhook handlers, URL builders, hostname comparisons in\n * `lib/config/mux-config.ts`) can import these without\n * tripping Next.js's client-reference poisoning. Re-exported from\n * `use-video-warmup.ts` for backward-compat with client-side callers.\n *\n * The Mux-HLS detection in `toMuxPreviewUrl` intentionally overlaps the\n * hub's `lib/config/mux-config.ts` `isMuxHlsUrl` — same documented\n * cross-repo duplication umbrella as the origin constants (the hub's\n * server code cannot depend on this package's client-marked siblings).\n *\n * Bug history (2026-05-29): when these constants lived in\n * `use-video-warmup.ts` (which is `'use client'`), the hub's\n * server-side `new URL(MUX_STREAM_ORIGIN).hostname` evaluation crashed\n * at Vercel build with `TypeError: Invalid URL` — Next.js had\n * replaced the constant with a client-function stub that throws\n * \"Attempted to call ... from the server\" when stringified. Splitting\n * the constants into this module restores the server-safe path.\n *\n * These hostnames are part of Mux's public API contract and are\n * stable. A future change to the Mux CDN architecture (extremely\n * unlikely) would be a single-line edit here.\n */\n\n/** HLS playback (`/{playback_id}.m3u8` + segments + per-asset MP4 renditions). */\nexport const MUX_STREAM_ORIGIN = 'https://stream.mux.com'\n\n/** Server-generated thumbnails (`/{playback_id}/thumbnail.jpg`). */\nexport const MUX_IMAGE_ORIGIN = 'https://image.mux.com'\n\n/** Valid values for Mux's `max_resolution` playback modifier (720p is the floor). */\nexport type MuxMaxResolution = '720p' | '1080p' | '1440p' | '2160p'\n\n/**\n * Cap the renditions offered by a public Mux HLS manifest for small\n * preview players (e.g. the ~234px video-bite hover cards) by appending\n * Mux's `max_resolution` playback modifier.\n *\n * Why a URL param and not a player prop: MuxPlayer's `maxResolution`\n * prop only applies when playing via `playbackId` — our SSOT passes\n * `src` URLs. And on Safari (native HLS, no hls.js) manifest-level\n * filtering is the ONLY rendition cap; hls.js's `capLevelToPlayerSize`\n * doesn't exist there.\n *\n * Pass-through (returns `url` unchanged) for: non-Mux hosts (Supabase\n * MP4s, YouTube), non-`.m3u8` paths (MP4 renditions), signed URLs\n * (`?token=` — Mux forbids loose modifiers alongside a token; they must\n * live in the JWT), and unparseable strings.\n */\nexport function toMuxPreviewUrl(url: string, maxResolution: MuxMaxResolution = '720p'): string {\n  let parsed: URL\n  try {\n    parsed = new URL(url)\n  } catch {\n    return url\n  }\n  if (parsed.origin !== MUX_STREAM_ORIGIN) return url\n  if (!parsed.pathname.endsWith('.m3u8')) return url\n  if (parsed.searchParams.has('token')) return url\n  parsed.searchParams.set('max_resolution', maxResolution)\n  return parsed.toString()\n}\n"]}