{"version":3,"file":"AppSessionDetection.DWyBkqTN.mjs","names":["useState","__legacyOverrideHOC_DataObserverContext","_jsx"],"sources":["https:/framerusercontent.com/modules/zPinAEfmJ2pnptTMAyrg/rb8baXDUkh3qtJAuKvv4/AppSessionDetection.js"],"sourcesContent":["\"use client\";import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useState}from\"react\";/**\n * Framer Code Overrides for conditional button display based on app session.\n *\n * STRUCTURE IN FRAMER:\n *\n * Frame\n *   ├─ GuestButtons (override: ShowForGuests)\n *   └─ ExistingButtons (override: ShowForSignedInUsers)\n */const AUTH_CONFIG={allowedHostnames:[\"brivvy.io\",\"www.brivvy.io\"],cacheTtlMs:5*60*1e3,debugMode:false,disableSessionCheckOnHomePage:true,guestDestinationUrl:\"/\",homepagePaths:[\"/\"],isCacheEnabled:false,localStorageTimestampKey:\"app_session_cache_timestamp\",localStorageValueKey:\"app_session_cache_value\",requestTimeoutMs:4e3,sessionEndpointUrl:\"https://app.brivvy.io/api/session\",signedInDestinationUrl:\"https://app.brivvy.io\"};const KNOWN_CRAWLER_USER_AGENT_REGEX=/bot|crawler|spider|slurp|bingpreview|mediapartners-google|facebookexternalhit|whatsapp|telegrambot|linkedinbot|twitterbot|applebot|duckduckbot|yandex|baiduspider|semrushbot|gptbot|chatgpt-user|oai-searchbot|anthropic-ai|claudebot|claude-web|perplexitybot|perplexity-user|youbot/i;let cachedIsAuthenticated=null;let cachedAtTimestamp=0;let inFlightRequest=null;export function AlwaysHide(){return{style:{display:\"none\"}};}export function AlwaysShow(){return{style:{display:\"flex\"}};}export function RefreshSessionButtonVisibility(){clearAuthenticationCache();window.dispatchEvent(new Event(\"authStatusChanged\"));if(AUTH_CONFIG.debugMode){console.log(\"[Auth Override] Auth status update triggered\");}}export function SetLogoLinkDestinationBySession(){const{isAuthenticated}=useAuthenticationStatus();const destinationUrl=isAuthenticated?AUTH_CONFIG.signedInDestinationUrl:AUTH_CONFIG.guestDestinationUrl;return{href:destinationUrl,link:destinationUrl,style:{display:\"flex\"}};}export function ShowForGuests(){const{hasResolved,isAuthenticated}=useAuthenticationStatus();if(!hasResolved){return{style:{display:\"none\"}};}return{style:{display:isAuthenticated?\"none\":\"flex\"}};}export function ShowForSignedInUsers(){const{hasResolved,isAuthenticated}=useAuthenticationStatus();if(!hasResolved){return{style:{display:\"none\"}};}return{style:{display:isAuthenticated?\"flex\":\"none\"}};}function clearAuthenticationCache(){cachedIsAuthenticated=null;cachedAtTimestamp=0;clearStoredAuthenticationStatus();}function clearStoredAuthenticationStatus(){if(!AUTH_CONFIG.isCacheEnabled){return;}try{window.localStorage.removeItem(AUTH_CONFIG.localStorageValueKey);window.localStorage.removeItem(AUTH_CONFIG.localStorageTimestampKey);}catch{// Intentionally ignore storage errors.\n}}async function fetchAuthenticationStatusFromApi(){const abortController=new AbortController;const timeoutId=window.setTimeout(()=>{abortController.abort();},AUTH_CONFIG.requestTimeoutMs);try{const response=await fetch(AUTH_CONFIG.sessionEndpointUrl,{credentials:\"include\",method:\"GET\",signal:abortController.signal});if(!response.ok){return false;}const payload=await response.json();return Boolean(payload?.active);}catch(error){if(AUTH_CONFIG.debugMode){console.error(\"[Auth Override] Session check failed:\",error);}return false;}finally{window.clearTimeout(timeoutId);}}/**\n * Reuses one pending network request.\n * If multiple overrides mount together, they all await the same Promise.\n */async function getAuthenticationStatus(forceRefresh=false){if(false&&shouldSkipSessionCheckOnHomePage()){if(AUTH_CONFIG.debugMode){console.log(\"[Auth Override] Session check skipped on homepage\");}return false;}if(!isSessionCheckAllowedForCurrentHost()){if(AUTH_CONFIG.debugMode){console.log(\"[Auth Override] Session check skipped for unsupported hostname\");}setCachedAuthenticationStatus(false);return false;}if(isKnownCrawlerUserAgent()){if(AUTH_CONFIG.debugMode){console.log(\"[Auth Override] Crawler detected, skipping API call\");}setCachedAuthenticationStatus(false);return false;}if(AUTH_CONFIG.isCacheEnabled&&!forceRefresh&&getIsCacheFresh()&&cachedIsAuthenticated!==null){return cachedIsAuthenticated;}if(AUTH_CONFIG.isCacheEnabled&&!forceRefresh){hydrateCacheFromLocalStorage();if(getIsCacheFresh()&&cachedIsAuthenticated!==null){return cachedIsAuthenticated;}}if(inFlightRequest){return inFlightRequest;}inFlightRequest=fetchAuthenticationStatusFromApi().then(isAuthenticated=>{setCachedAuthenticationStatus(isAuthenticated);return isAuthenticated;}).finally(()=>{inFlightRequest=null;});return inFlightRequest;}function getIsCacheFresh(){if(cachedIsAuthenticated===null){return false;}return Date.now()-cachedAtTimestamp<=AUTH_CONFIG.cacheTtlMs;}function hydrateCacheFromLocalStorage(){if(!AUTH_CONFIG.isCacheEnabled){return;}try{const storedAuthenticationValue=window.localStorage.getItem(AUTH_CONFIG.localStorageValueKey);const storedTimestampValue=window.localStorage.getItem(AUTH_CONFIG.localStorageTimestampKey);if(!storedAuthenticationValue||!storedTimestampValue){return;}const parsedTimestamp=Number(storedTimestampValue);if(!parsedTimestamp||Number.isNaN(parsedTimestamp)){return;}const isStoredAuthenticationTrue=storedAuthenticationValue===\"1\";const isStoredAuthenticationFalse=storedAuthenticationValue===\"0\";if(!isStoredAuthenticationTrue&&!isStoredAuthenticationFalse){return;}cachedIsAuthenticated=isStoredAuthenticationTrue;cachedAtTimestamp=parsedTimestamp;}catch{// Intentionally ignore storage errors.\n}}function isKnownCrawlerUserAgent(){const userAgent=navigator.userAgent||\"\";return KNOWN_CRAWLER_USER_AGENT_REGEX.test(userAgent);}function isSessionCheckAllowedForCurrentHost(){const{hostname}=window.location;const allowedHostnames=AUTH_CONFIG.allowedHostnames;return allowedHostnames.includes(hostname);}function setCachedAuthenticationStatus(isAuthenticated){cachedIsAuthenticated=isAuthenticated;cachedAtTimestamp=Date.now();if(!AUTH_CONFIG.isCacheEnabled){return;}setStoredAuthenticationStatus(isAuthenticated,cachedAtTimestamp);}function setStoredAuthenticationStatus(isAuthenticated,timestamp){if(!AUTH_CONFIG.isCacheEnabled){return;}try{window.localStorage.setItem(AUTH_CONFIG.localStorageValueKey,isAuthenticated?\"1\":\"0\");window.localStorage.setItem(AUTH_CONFIG.localStorageTimestampKey,String(timestamp));}catch{// Intentionally ignore storage errors.\n}}function shouldSkipSessionCheckOnHomePage(){if(!AUTH_CONFIG.disableSessionCheckOnHomePage){return false;}const{pathname}=window.location;const homepagePaths=AUTH_CONFIG.homepagePaths;return homepagePaths.includes(pathname);}function useAuthenticationStatus(){const[isAuthenticated,setIsAuthenticated]=useState(false);const[hasResolved,setHasResolved]=useState(false);useEffect(()=>{let isSubscribed=true;const resolveAuthentication=async(forceRefresh=false)=>{const resolvedAuthentication=await getAuthenticationStatus(forceRefresh);if(!isSubscribed){return;}setIsAuthenticated(resolvedAuthentication);setHasResolved(true);if(AUTH_CONFIG.debugMode){console.log(`[Auth Override] Resolved auth: ${resolvedAuthentication?\"Existing User\":\"Guest User\"}`);}};resolveAuthentication();const handleAuthStatusChanged=()=>{clearAuthenticationCache();resolveAuthentication(true);};const handleVisibilityChange=()=>{if(document.visibilityState===\"visible\"){resolveAuthentication();}};window.addEventListener(\"authStatusChanged\",handleAuthStatusChanged);document.addEventListener(\"visibilitychange\",handleVisibilityChange);return()=>{isSubscribed=false;window.removeEventListener(\"authStatusChanged\",handleAuthStatusChanged);document.removeEventListener(\"visibilitychange\",handleVisibilityChange);};},[]);return{hasResolved,isAuthenticated};}if(typeof window!==\"undefined\"){window.refreshSessionButtonVisibility=RefreshSessionButtonVisibility;}import{useContext as __legacyOverrideHOC_useContext}from\"react\";import{DataObserverContext as __legacyOverrideHOC_DataObserverContext}from\"framer\";export function withAlwaysHide(C){return props=>{__legacyOverrideHOC_useContext(__legacyOverrideHOC_DataObserverContext);return _jsx(C,{...props,...AlwaysHide(props)});};}withAlwaysHide.displayName=\"AlwaysHide\";export function withAlwaysShow(C){return props=>{__legacyOverrideHOC_useContext(__legacyOverrideHOC_DataObserverContext);return _jsx(C,{...props,...AlwaysShow(props)});};}withAlwaysShow.displayName=\"AlwaysShow\";export function withSetLogoLinkDestinationBySession(C){return props=>{__legacyOverrideHOC_useContext(__legacyOverrideHOC_DataObserverContext);return _jsx(C,{...props,...SetLogoLinkDestinationBySession(props)});};}withSetLogoLinkDestinationBySession.displayName=\"SetLogoLinkDestinationBySession\";export function withShowForGuests(C){return props=>{__legacyOverrideHOC_useContext(__legacyOverrideHOC_DataObserverContext);return _jsx(C,{...props,...ShowForGuests(props)});};}withShowForGuests.displayName=\"ShowForGuests\";export function withShowForSignedInUsers(C){return props=>{__legacyOverrideHOC_useContext(__legacyOverrideHOC_DataObserverContext);return _jsx(C,{...props,...ShowForSignedInUsers(props)});};}withShowForSignedInUsers.displayName=\"ShowForSignedInUsers\";\nexport const __FramerMetadata__ = {\"exports\":{\"withSetLogoLinkDestinationBySession\":{\"type\":\"reactHoc\",\"name\":\"withSetLogoLinkDestinationBySession\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"AlwaysHide\":{\"type\":\"override\",\"name\":\"AlwaysHide\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withShowForGuests\":{\"type\":\"reactHoc\",\"name\":\"withShowForGuests\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"AlwaysShow\":{\"type\":\"override\",\"name\":\"AlwaysShow\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAlwaysShow\":{\"type\":\"reactHoc\",\"name\":\"withAlwaysShow\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"RefreshSessionButtonVisibility\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"SetLogoLinkDestinationBySession\":{\"type\":\"override\",\"name\":\"SetLogoLinkDestinationBySession\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"ShowForGuests\":{\"type\":\"override\",\"name\":\"ShowForGuests\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"ShowForSignedInUsers\":{\"type\":\"override\",\"name\":\"ShowForSignedInUsers\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAlwaysHide\":{\"type\":\"reactHoc\",\"name\":\"withAlwaysHide\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withShowForSignedInUsers\":{\"type\":\"reactHoc\",\"name\":\"withShowForSignedInUsers\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AppSessionDetection.map"],"mappings":"uMAQ6zB,SAAgB,GAAY,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,OAAO,CAAC,CAAE,SAAgB,GAAY,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,OAAO,CAAC,CAAE,SAAgB,GAAgC,CAAC,GAA0B,CAAC,EAAO,cAAc,IAAI,MAAM,oBAAoB,CAAC,CAAI,EAAY,WAAW,QAAQ,IAAI,+CAA+C,CAAG,SAAgB,GAAiC,CAAC,GAAK,CAAC,mBAAiB,GAAyB,CAAO,EAAe,EAAgB,EAAY,uBAAuB,EAAY,oBAAoB,MAAM,CAAC,KAAK,EAAe,KAAK,EAAe,MAAM,CAAC,QAAQ,OAAO,CAAC,CAAE,SAAgB,GAAe,CAAC,GAAK,CAAC,cAAY,mBAAiB,GAAyB,CAAkD,OAA7C,EAAmD,CAAC,MAAM,CAAC,QAAQ,EAAgB,OAAO,OAAO,CAAC,CAA/E,CAAC,MAAM,CAAC,QAAQ,OAAO,CAAC,CAAyD,SAAgB,GAAsB,CAAC,GAAK,CAAC,cAAY,mBAAiB,GAAyB,CAAkD,OAA7C,EAAmD,CAAC,MAAM,CAAC,QAAQ,EAAgB,OAAO,OAAO,CAAC,CAA/E,CAAC,MAAM,CAAC,QAAQ,OAAO,CAAC,CAAyD,SAAS,GAA0B,CAAC,EAAsB,KAAK,EAAkB,EAAE,GAAiC,CAAE,SAAS,GAAiC,CAAK,KAAY,eAAwB,GAAG,CAAC,EAAO,aAAa,WAAW,EAAY,qBAAqB,CAAC,EAAO,aAAa,WAAW,EAAY,yBAAyB,MAAO,GAC3oE,eAAe,GAAkC,CAAC,IAAM,EAAgB,IAAI,gBAAsB,EAAU,EAAO,eAAe,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