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AA,GACpB;AACF","file":"app-icons.cjs","sourcesContent":["// ---------------------------------------------------------------------------\n// App icons — favicons and platform icons resolved from the Brand API at\n// RUNTIME, never hand-dropped as static files in an app repo (Global Rules →\n// \"App Icons — Favicons & Browser Icons\").\n//\n// `GET https://specs.politogyvrm.com/api/icons/<app>` returns the FULLY\n// RESOLVED variant grid: the server already walks the fallback chain (exact\n// variant → same-platform color/square → color fallback → the app's base\n// favicon → the global platform icon → the VRM Core logo), and marks each entry\n// `fallback: true` when it is inherited rather than app-specific. So an app that\n// has never uploaded its own icon still gets the platform favicon (Brand\n// `assets.favicon`) from the API, with no per-app defaulting logic.\n//\n// The shell itself carries NO icon image and never substitutes one Brand asset\n// for another (Brand guideline \"Logo standard: use the uploaded Brand assets\n// as-is\"). If the API cannot be reached, or returns no browser-tab icon, this\n// returns SPECS_FAVICON_URL: Specs' public redirect to Brand `assets.favicon`,\n// which the BROWSER resolves. In production Cloudflare's bot check challenges\n// the server-side fetch below, so this is the usual path there. The link is in\n// the server HTML, so the browser never falls back to /favicon.ico.\n//\n// Server-safe: no React, no client deps. Next apps call this from\n// `generateMetadata()` so the icon updates when Brand changes, without a\n// redeploy of the app.\n// ---------------------------------------------------------------------------\n\nexport const SPECS_ICONS_BASE = 'https://specs.politogyvrm.com/api/icons'\n\n/** Public 302 to Brand `assets.favicon` (`?kind=apple` → `assets.appleIcon`). */\nexport const SPECS_FAVICON_URL = 'https://specs.politogyvrm.com/api/favicon'\n\n/**\n * @deprecated No longer used and will be removed. It was a hardcoded copy of an\n * old `assets.logoSquare` upload, used as a stand-in favicon — a bundled copy\n * of one Brand asset substituted for another, which the Brand forbids.\n */\nexport const VRM_FALLBACK_ICON =\n  'https://lzhzqtzwlwdffxhjjrba.supabase.co/storage/v1/object/public/brand-assets/logo-square/logo-square-mrspraen.png'\n\nexport type PolitogyIconVariant = { url: string; fallback?: boolean }\n\nexport type PolitogyIconsResponse = {\n  app: string\n  version?: number\n  updatedAt?: string\n  icons: Record<string, PolitogyIconVariant>\n}\n\n/** Next.js `metadata.icons` shape (a subset — url/rel entries). */\nexport type PolitogyMetadataIcons = {\n  /** Falls back to SPECS_FAVICON_URL when the Brand API supplied no browser-tab icon. */\n  icon: { url: string }[]\n  shortcut?: { url: string }[]\n  apple?: { url: string }[]\n}\n\nfunction pick(\n  icons: Record<string, PolitogyIconVariant> | undefined,\n  ...keys: string[]\n): string | null {\n  if (!icons) return null\n  for (const key of keys) {\n    const hit = icons[key]?.url\n    if (hit) return hit\n  }\n  return null\n}\n\n/**\n * Fetch the resolved icon set for an app and shape it for Next `metadata`.\n *\n * Cached for 60s with revalidation, matching the tokens contract — a Brand edit\n * shows up promptly without defeating caching. Never throws: on any failure it\n * returns the SPECS_FAVICON_URL redirect, so an app can call this unguarded in metadata.\n */\nexport async function politogyAppIcons(\n  app: string,\n  init?: { baseUrl?: string; revalidateSeconds?: number; fetchImpl?: typeof globalThis.fetch },\n): Promise<PolitogyMetadataIcons> {\n  const base = init?.baseUrl ?? SPECS_ICONS_BASE\n  const revalidate = init?.revalidateSeconds ?? 60\n  const doFetch = init?.fetchImpl ?? globalThis.fetch\n  try {\n    const res = await doFetch(`${base}/${encodeURIComponent(app)}`, {\n      // `next.revalidate` is ignored by non-Next fetch implementations.\n      next: { revalidate },\n    } as RequestInit)\n    if (!res.ok) throw new Error(`icons ${app}: ${res.status}`)\n    const data = (await res.json()) as PolitogyIconsResponse\n    return toMetadataIcons(data)\n  } catch {\n    return toMetadataIcons(null)\n  }\n}\n\n/**\n * Cache-buster: stamp the Brand revision onto an icon URL as `?v=<version>`\n * (falling back to the `updatedAt` timestamp). The stored filenames are already\n * content-hashed, but favicons are cached so aggressively by browsers that a new\n * Brand publish can still show stale; a version-keyed URL forces every publish to\n * be treated as a distinct resource. No-op for an unknown rev.\n */\nfunction withVersion(url: string, data: PolitogyIconsResponse | null): string {\n  const rev =\n    typeof data?.version === 'number'\n      ? String(data.version)\n      : data?.updatedAt\n        ? String(Date.parse(data.updatedAt) || '').replace(/\\D/g, '')\n        : ''\n  if (!rev) return url\n  return `${url}${url.includes('?') ? '&' : '?'}v=${rev}`\n}\n\n/** Pure shaping step — exported for tests and for callers with their own fetch. */\nexport function toMetadataIcons(data: PolitogyIconsResponse | null): PolitogyMetadataIcons {\n  const icons = data?.icons\n  // The API has already resolved the chain down to Brand `assets.favicon`\n  // (and `assets.appleIcon` for iOS). Nothing is substituted here.\n  const favicon = pick(icons, 'favicon-color-square', 'favicon-color-round')\n  const apple =\n    pick(icons, 'ios-color-square', 'ios-color-round', 'favicon-color-square') ?? favicon\n  if (!favicon) {\n    // No resolved icon (API unreachable, or nothing set): let the browser\n    // follow Specs' redirect to the Brand favicon. Never a bundled image.\n    return {\n      icon: [{ url: SPECS_FAVICON_URL }],\n      shortcut: [{ url: SPECS_FAVICON_URL }],\n      apple: [{ url: `${SPECS_FAVICON_URL}?kind=apple` }],\n    }\n  }\n  const entry = (url: string | null) => (url ? [{ url: withVersion(url, data) }] : [])\n  return {\n    icon: entry(favicon),\n    shortcut: entry(favicon),\n    apple: entry(apple),\n  }\n}\n"]}