// Copyright: (c) 2026 TWWIM UG. All rights reserved. (www.twwim.com) import { AuthOrigin, Channel } from '@archer/domain'; /** * Resolves which storefront/surface the dashboard is rendering for. Single * source of truth for UI shape across CP web, WP plugin embed, and Shopify * deep-linked sessions. Reuses the @archer/domain Channel enum so backend and * client speak the same vocabulary. * * Resolution priority (intentional): * 1. WP build flag wins — the plugin ships its own bundle, every session * inside wp-admin is WORDPRESS regardless of who's signed in. * 2. SHOPIFY auth origin — applies only inside the cp.twwim.ai web bundle * when a Shopify-installed merchant deep-links in via /auth/shopify. * 3. WEBSITE — the default; pure web TWWIM users. * * Channel.JTL is reserved for the future native JTL Shop plugin build target. */ export interface ResolveChannelInput { /** import.meta.env.VITE_WP_EMBED === 'true' — baked at WP plugin build. */ isWpEmbedBuild: boolean; /** AuthenticatedUser.authOrigin from the JWT (undefined before login). */ authOrigin: AuthOrigin | undefined; } export function resolveChannel(input: ResolveChannelInput): Channel { if (input.isWpEmbedBuild) return Channel.WORDPRESS; if (input.authOrigin === AuthOrigin.SHOPIFY) return Channel.SHOPIFY; return Channel.WEBSITE; }