{"version":3,"file":"AppSessionDetection.BwPeTnSB.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,MAAM,CAAC,CAAE,CAAC,SAAgB,GAAY,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,MAAM,CAAC,CAAE,CAAC,SAAgB,GAAgC,CAAC,EAAyB,EAAE,EAAO,cAAc,IAAI,MAAM,mBAAmB,CAAC,EAAK,EAAY,WAAW,QAAQ,IAAI,8CAA8C,CAAG,CAAC,SAAgB,GAAiC,CAAC,GAAK,CAAC,mBAAiB,EAAwB,EAAQ,EAAe,EAAgB,EAAY,uBAAuB,EAAY,oBAAoB,MAAM,CAAC,KAAK,EAAe,KAAK,EAAe,MAAM,CAAC,QAAQ,MAAM,CAAC,CAAE,CAAC,SAAgB,GAAe,CAAC,GAAK,CAAC,cAAY,mBAAiB,EAAwB,EAAmD,OAA7C,EAAmD,CAAC,MAAM,CAAC,QAAQ,EAAgB,OAAO,MAAM,CAAC,EAA9E,CAAC,MAAM,CAAC,QAAQ,MAAM,CAAC,CAAyD,CAAC,SAAgB,GAAsB,CAAC,GAAK,CAAC,cAAY,mBAAiB,EAAwB,EAAmD,OAA7C,EAAmD,CAAC,MAAM,CAAC,QAAQ,EAAgB,OAAO,MAAM,CAAC,EAA9E,CAAC,MAAM,CAAC,QAAQ,MAAM,CAAC,CAAyD,CAAC,SAAS,GAA0B,CAAC,EAAsB,KAAK,EAAkB,EAAE,EAAgC,CAAE,CAAC,SAAS,GAAiC,CAAK,KAAY,eAAwB,GAAG,CAAC,EAAO,aAAa,WAAW,EAAY,oBAAoB,EAAE,EAAO,aAAa,WAAW,EAAY,wBAAwB,CAAE,MAAM,CAC7oE,CAAC,CAAC,eAA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