{"version":3,"file":"Sub.68aEdbFC.mjs","names":["useState","createClient"],"sources":["https:/framerusercontent.com/modules/uj67dn4jsFE4vF1BFoT1/lizab81R7bLwzm2aFrHl/Sub.js"],"sourcesContent":["// Sub.tsx - Framer Code Override for Stripe Subscription Integration\n// Copy this entire file contents into Framer: Assets Panel > Code > + > Code Override\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useState,useEffect}from\"react\";import{createClient}from\"https://esm.sh/@supabase/supabase-js@2\";// ============================================\n// CONFIGURATION\n// ============================================\nconst SUPABASE_URL=\"https://hbegqpgwdrpgrqhdoeyj.supabase.co\";const SUPABASE_ANON_KEY=\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImhiZWdxcGd3ZHJwZ3JxaGRvZXlqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTUwOTAxOTAsImV4cCI6MjA3MDY2NjE5MH0.mXxF8GvvJwX4SgtenqQYdV4408f-Uwb1dj8-afSuM8g\";// API URL for backend calls\nconst API_URL=\"https://resonance-api.lavendaire.com\";// ============================================\n// SUPABASE CLIENT\n// ============================================\nconst supabase=createClient(SUPABASE_URL,SUPABASE_ANON_KEY,{auth:{autoRefreshToken:true,persistSession:true,detectSessionInUrl:true}});// ============================================\n// HELPER FUNCTIONS\n// ============================================\n/**\n * Get current Supabase auth session\n */async function getSession(){const{data:{session},error}=await supabase.auth.getSession();return{session,error};}/**\n * Create Stripe checkout session via API\n * @param planType - 'monthly' or 'yearly'\n * @returns Checkout URL or null if error\n */async function createStripeCheckout(planType){try{const{session,error:sessionError}=await getSession();if(sessionError||!session?.access_token){console.error(\"[Stripe] No valid session:\",sessionError);return null;}const response=await fetch(`${API_URL}/api/stripe/checkout`,{method:\"POST\",headers:{Authorization:`Bearer ${session.access_token}`,\"Content-Type\":\"application/json\"},body:JSON.stringify({planType})});if(!response.ok){const errorData=await response.json().catch(()=>({}));// Handle specific error cases\nif(response.status===401){// Not authenticated - should redirect to create-account\nconsole.log(\"[Stripe] User not authenticated\");return null;}if(response.status===409){// Already has active subscription\nalert(\"You already have an active subscription\");return null;}if(response.status===400){// Validation error\nalert(errorData.message||\"Invalid request. Please try again.\");return null;}// Generic error\nalert(\"Something went wrong. Please try again.\");console.error(\"[Stripe] API error:\",response.status,errorData);return null;}const data=await response.json();return data.checkoutUrl;}catch(error){console.error(\"[Stripe] Checkout error:\",error);alert(\"Something went wrong. Please try again.\");return null;}}/**\n * Create Stripe customer portal session via API\n * @returns Portal URL or null if error\n */async function createStripePortalSession(){try{const{session,error:sessionError}=await getSession();if(sessionError||!session?.access_token){console.error(\"[Stripe] No valid session for portal:\",sessionError);return null;}const response=await fetch(`${API_URL}/api/stripe/portal-session`,{method:\"POST\",headers:{Authorization:`Bearer ${session.access_token}`,\"Content-Type\":\"application/json\"},body:JSON.stringify({returnUrl:`${window.location.origin}/account`})});if(!response.ok){const errorData=await response.json().catch(()=>({}));if(response.status===401){console.log(\"[Stripe] User not authenticated for portal session\");return null;}if(response.status===400){alert(errorData.message||\"Unable to open billing portal. Please try again.\");return null;}alert(\"Something went wrong. Please try again.\");console.error(\"[Stripe] Portal API error:\",response.status,errorData);return null;}const data=await response.json();return data.portalUrl;}catch(error){console.error(\"[Stripe] Portal session error:\",error);alert(\"Something went wrong. Please try again.\");return null;}}// Prevent double submission\nlet isSubmitting=false;// ============================================\n// STRIPE BUTTON OVERRIDES\n// ============================================\n/**\n * Yearly Plan Trial Button Override\n * Apply to \"Start your free trial\" button for yearly plan\n *\n * Flow:\n * - If authenticated: Create Stripe checkout and redirect\n * - If not authenticated: Store intent and redirect to /create-account\n */export function withStripeYearlyTrial(Component){return props=>{const handleClick=async e=>{// Safely prevent default - Framer's onTap may not pass event\ntry{if(e?.preventDefault)e.preventDefault();if(e?.stopPropagation)e.stopPropagation();}catch{}if(isSubmitting)return false;isSubmitting=true;try{// Check if user is authenticated\nconst{session}=await getSession();if(!session?.access_token){// Not authenticated - store intent and redirect to create account\nconsole.log(\"[Stripe] Not authenticated, redirecting to create-account\");sessionStorage.setItem(\"stripe_intent\",\"yearly\");window.location.href=\"/create-account\";return false;}// Authenticated - create checkout session\nconst checkoutUrl=await createStripeCheckout(\"yearly\");if(checkoutUrl){window.location.href=checkoutUrl;}}finally{isSubmitting=false;}return false;};// Remove href to prevent native link navigation bypassing our handler\nreturn /*#__PURE__*/_jsx(Component,{...props,href:undefined,onClick:handleClick,onTap:handleClick});};}/**\n * Monthly Plan Trial Button Override\n * Apply to \"Start your free trial\" button for monthly plan\n *\n * Flow:\n * - If authenticated: Create Stripe checkout and redirect\n * - If not authenticated: Store intent and redirect to /create-account\n */export function withStripeMonthlyTrial(Component){return props=>{const handleClick=async e=>{// Safely prevent default - Framer's onTap may not pass event\ntry{if(e?.preventDefault)e.preventDefault();if(e?.stopPropagation)e.stopPropagation();}catch{}if(isSubmitting)return false;isSubmitting=true;try{// Check if user is authenticated\nconst{session}=await getSession();if(!session?.access_token){// Not authenticated - store intent and redirect to create account\nconsole.log(\"[Stripe] Not authenticated, redirecting to create-account\");sessionStorage.setItem(\"stripe_intent\",\"monthly\");window.location.href=\"/create-account\";return false;}// Authenticated - create checkout session\nconst checkoutUrl=await createStripeCheckout(\"monthly\");if(checkoutUrl){window.location.href=checkoutUrl;}}finally{isSubmitting=false;}return false;};// Remove href to prevent native link navigation bypassing our handler\nreturn /*#__PURE__*/_jsx(Component,{...props,href:undefined,onClick:handleClick,onTap:handleClick});};}/**\n * Post-Auth Stripe Redirect Override\n * Apply to the /create-account page frame\n *\n * After user creates account or logs in via OAuth:\n * - Checks for stripe_intent in sessionStorage\n * - If found, automatically creates checkout session and redirects to Stripe\n */export function withStripePostAuthRedirect(Component){return props=>{const[isRedirecting,setIsRedirecting]=useState(false);useEffect(()=>{const handlePostAuthRedirect=async()=>{// Check for stripe intent\nconst stripeIntent=sessionStorage.getItem(\"stripe_intent\");if(!stripeIntent){return;// No Stripe intent, normal flow\n}// Check if user is now authenticated\nconst{session}=await getSession();if(!session?.access_token){return;// Not authenticated yet, wait for auth\n}// User is authenticated and has stripe intent\nconsole.log(\"[Stripe] Post-auth redirect detected, plan:\",stripeIntent);setIsRedirecting(true);// Clear the intent\nsessionStorage.removeItem(\"stripe_intent\");// Create checkout session\nconst checkoutUrl=await createStripeCheckout(stripeIntent);if(checkoutUrl){window.location.href=checkoutUrl;}else{// Checkout failed, redirect to pricing page\nsetIsRedirecting(false);window.location.href=\"/pricing-plan\";}};// Listen for auth state changes\nconst{data:{subscription}}=supabase.auth.onAuthStateChange((event,session)=>{if(event===\"SIGNED_IN\"&&session){// Small delay to ensure session is fully established\nsetTimeout(handlePostAuthRedirect,500);}});// Also check immediately in case session already exists\nhandlePostAuthRedirect();return()=>subscription.unsubscribe();},[]);// Show loading state while redirecting to Stripe\nif(isRedirecting){return /*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",flexDirection:\"column\",alignItems:\"center\",justifyContent:\"center\",minHeight:\"100vh\",gap:\"16px\"},children:/*#__PURE__*/_jsx(\"div\",{children:\"Redirecting to checkout...\"})});}return /*#__PURE__*/_jsx(Component,{...props});};}/**\n * OAuth Callback Handler with Stripe Support\n * Apply to your main page frame (extends withAuthCallback from Auth.tsx)\n *\n * Handles OAuth callback AND checks for stripe_intent after successful auth\n */export function withAuthCallbackAndStripe(Component){return props=>{useEffect(()=>{const hash=window.location.hash;if(hash&&hash.includes(\"access_token\")){const params=new URLSearchParams(hash.substring(1));const accessToken=params.get(\"access_token\");const refreshToken=params.get(\"refresh_token\");if(accessToken&&refreshToken){supabase.auth.setSession({access_token:accessToken,refresh_token:refreshToken}).then(async({error})=>{if(error){console.error(\"Session error:\",error);alert(\"Login failed: \"+error.message);return;}// Check for stripe intent first (highest priority)\nconst stripeIntent=sessionStorage.getItem(\"stripe_intent\");if(stripeIntent){console.log(\"[Stripe] OAuth callback with stripe intent:\",stripeIntent);sessionStorage.removeItem(\"stripe_intent\");const checkoutUrl=await createStripeCheckout(stripeIntent);if(checkoutUrl){window.location.href=checkoutUrl;return;}// Fallback to pricing page if checkout fails\nwindow.location.href=\"/pricing-plan\";return;}// Check auth intent from sessionStorage (beta trial flow)\nconst authIntent=sessionStorage.getItem(\"auth_intent\");sessionStorage.removeItem(\"auth_intent\");if(authIntent===\"trial\"){// Beta trial flow\nwindow.location.href=\"/trial-active\";}else{// Regular login flow\nwindow.location.href=\"/account\";}});}}},[]);return /*#__PURE__*/_jsx(Component,{...props});};}/**\n * Manage Subscription Button Override\n * Apply to \"Manage Subscription\" button on /account page\n */export function withManageSubscription(Component){return props=>{const handleClick=async e=>{try{if(e?.preventDefault)e.preventDefault();if(e?.stopPropagation)e.stopPropagation();}catch{}if(isSubmitting)return false;isSubmitting=true;try{const portalUrl=await createStripePortalSession();if(portalUrl){window.location.href=portalUrl;}}finally{isSubmitting=false;}return false;};return /*#__PURE__*/_jsx(Component,{...props,href:undefined,onClick:handleClick,onTap:handleClick});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withStripeMonthlyTrial\":{\"type\":\"reactHoc\",\"name\":\"withStripeMonthlyTrial\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withStripeYearlyTrial\":{\"type\":\"reactHoc\",\"name\":\"withStripeYearlyTrial\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAuthCallbackAndStripe\":{\"type\":\"reactHoc\",\"name\":\"withAuthCallbackAndStripe\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withStripePostAuthRedirect\":{\"type\":\"reactHoc\",\"name\":\"withStripePostAuthRedirect\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withManageSubscription\":{\"type\":\"reactHoc\",\"name\":\"withManageSubscription\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Sub.map"],"mappings":"+LAcG,eAAe,GAAY,CAAC,GAAK,CAAC,KAAK,CAAC,WAAS,SAAO,MAAM,EAAS,KAAK,YAAY,CAAC,MAAM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