PageSourceSearch

https://app.adeptads.ai/_nuxt/BBQP3RnX.js

js adeptads.ai collected 2026-10-05 11:48:03 UTC 24,695 bytes, 1 lines download raw bytes

1import{Gn as e,Jt as t,_i as n,qi as r}from"./CLLDXjUq.js";import{n as i}from"./n8l2siWw.js";import{t as a}from"./BpYqazCA.js";import{a as o,c as s,i as c,r as l,s as u}from"./DbYnbX_9.js";import{t as d}from"./BRiNof1Z.js";import{l as f}from"./CblxND2n.js";import{t as p}from"./jsH7tE7Q.js";function m(e){return s(e)&&typeof e.error_code==`string`&&typeof e.detail==`string`}function h(e){return m(e)&&(e.error_code===`TOKEN_REVOKED`||e.error_code===`REFRESH_TOKEN_REVOKED`)}function g(e){return m(e)&&[`JWT_INVALID_SIGNATURE`,`JWT_KEY_ROTATION`,`JWT_ALGORITHM_MISMATCH`].includes(e.error_code)}function _(e){return m(e)&&[`provider_error`,`token_exchange_failed`,`user_info_failed`,`token_refresh_failed`,`invalid_state`,`configuration_error`].includes(e.error_code)}function v(e){if(!e)return null;let t=u(e,`data`)||u(e,`response`,`_data`)||e;return m(t)?t:null}function y(e,t,n){return{error_code:e,detail:n||b(e,t),provider:t}}function b(e,t){switch(e){case`provider_error`:return`Authentication failed with ${t}. Please try again.`;case`token_exchange_failed`:return`Failed to complete authentication with ${t}. Please try again.`;case`user_info_failed`:return`Failed to retrieve user information from ${t}. Please try again.`;case`token_refresh_failed`:return`Failed to refresh authentication with ${t}. Please log in again.`;case`invalid_state`:return`Invalid authentication state. Please try again.`;case`configuration_error`:return`OAuth provider ${t} is not properly configured.`;default:return`OAuth authentication failed with ${t}.`}}function x(e){if(h(e))return e.detail||`Your session has been revoked. Please log in again.`;if(g(e))return e.error_code===`JWT_ALGORITHM_MISMATCH`?`Authentication protocol mismatch. Please try logging in again.`:e.detail||`Security validation failed. Please log in again.`;if(_(e)){let t=e.provider?` with ${e.provider}`:``;switch(e.error_code){case`provider_error`:return e.detail||`Authentication failed${t}. Please try again.`;case`token_exchange_failed`:return e.detail||`Failed to complete authentication${t}. Please try again.`;case`user_info_failed`:return e.detail||`Failed to retrieve user information${t}. Please try again.`;case`token_refresh_failed`:return e.detail||`Failed to refresh authentication${t}. Please log in again.`;case`invalid_state`:return e.detail||`Invalid authentication state. Please try again.`;case`configuration_error`:return e.detail||`OAuth provider${t} is not properly configured.`;default:return e.detail||`OAuth authentication failed${t}.`}}return m(e)?e.detail:`An authentication error occurred`}var S=`::`;function C(e,t,n){return[e,t,n].join(S)}var ee=i(`bidding-options-cache`,()=>{let e=r({});function t(t){return t&&e.value[t]||null}function n(t,n){e.value={...e.value,[t]:n}}function i(t){if(!t||!e.value[t])return;let{[t]:n,...r}=e.value;e.value=r}function a(t,n){let r=`${t}${S}${n}${S}`,i={},a=!1;for(let[t,n]of Object.entries(e.value)){if(t.startsWith(r)){a=!0;continue}i[t]=n}a&&(e.value=i)}function o(){e.value={}}return{getEntry:t,setEntry:n,invalidateEntry:i,invalidateByAccount:a,reset:o}}),w=`domain:refresh`,T=`account:changed`;function te(){let e=f(w);function t(t,n,r){e.emit({type:T,sessionKey:r,platform:t,accountId:n})}return{bus:e,publishAccountChanged:t}}function ne(e,t,n=Date.now()){if(!e)return!1;let r=typeof t==`number`&&t>0?t:0;if(r<=0)return!1;let i=new Date(e).getTime();if(!Number.isFinite(i))return!1;let a=n-i;return a>=0&&a<=r}function E(e,t){return!e||!(t!=null&&t.effective_account)||!t.selection?`none`:`${e}:${t.auth_id}:${t.credential_version}:${t.selection.account_id}:${t.selection.access_root_id}:${t.selection_revision}`}var D=[{id:`google_ads`,name:`Google Ads`,slug:`google-ads`,icon:`i-simple-icons-google`,available:!0},{id:`meta_ads`,name:`Meta Ads`,slug:`meta-ads`,icon:`i-simple-icons-meta`,available:!1},{id:`bing_ads`,name:`Microsoft Ads`,slug:`microsoft-ads`,icon:`i-simple-icons-microsoft`,available:!1}],re=i(`platform`,()=>{let i=r({}),a=r({}),o=r({}),s=r({}),c=r(0),l=r(null),u=r(null),f=r(!1),p=r(!1),m=r(null),h=r(null),g=r({}),_=Number(t().public.conversionStatusTtlMs)||6e5,v=0,y=e(()=>D.map(e=>{var t,n;return{...e,connected:((t=i.value[e.id])==null?void 0:t.has_token)||!1,is_token_valid:((n=i.value[e.id])==null?void 0:n.is_token_valid)||!1,accounts:Object.values(a.value[e.id]||{})}})),b=e(()=>y.value.filter(e=>e.available)),x=e(()=>y.value.find(e=>e.id===l.value)||null),S=e(()=>l.value&&i.value[l.value]||null),C=e(()=>{var e;return((e=S.value)==null?void 0:e.effective_account)||null}),w=C,T=e(()=>E(l.value,S.value)),re=e(()=>l.value&&a.value[l.value]||{}),O=e(()=>l.value?s.value[l.value]:null),k=e(()=>{var e;return!!m.value||!!((e=O.value)!=null&&e.checking)}),A=e(()=>{var e;return((e=O.value)==null?void 0:e.error)||h.value}),{publishAccountChanged:j}=te();n(T,e=>{var t;j(l.value,((t=w.value)==null?void 0:t.id)||null,e)},{flush:`sync`});function M(e){let t=i.value[e];return`${c.value}:${e}:${t==null?void 0:t.auth_id}:${t==null?void 0:t.credential_version}:${t==null?void 0:t.selection_revision}`}function ie(e,t){let n=i.value[e];return`${c.value}:${e}:${n==null?void 0:n.auth_id}:${n==null?void 0:n.credential_version}:${t.access_root_id||`roots`}:${t.manager_id||``}`}function ae(e,t=!1){let n=`${c.value}:${++v}`;return s.value[e]={id:n,identity:M(e),checking:t,error:null},n}function oe(e,t,n){let r=s.value[e];if((r==null?void 0:r.id)!==t)return!1;let i=r.identity===M(e);return s.value[e]={...r,checking:!1,error:i?n:null},i}function se(){return m.value=`${c.value}:${++v}`,h.value=null,m.value}function ce(e,t=null){return m.value===e&&(m.value=null,h.value=t,p.value=!0,!0)}function le(e,t,n=!1){let r=e.platform_type,l=i.value[r],u=s.value[r],d=t===(u==null?void 0:u.id);return!d&&!(n&&t.split(`:`)[0]===String(c.value)&&(l==null?void 0:l.auth_id)===e.auth_id&&(l==null?void 0:l.credential_version)===e.credential_version&&l.selection_revision<e.selection_revision)||(u&&(s.value[r]={...u,checking:!d&&u.checking,error:null}),(l==null?void 0:l.auth_id)===e.auth_id&&(l.credential_version>e.credential_version||l.credential_version===e.credential_version&&l.selection_revision>e.selection_revision))?!1:(((l==null?void 0:l.auth_id)!==e.auth_id||(l==null?void 0:l.credential_version)!==e.credential_version)&&(a.value[r]={},o.value={},g.value={}),P(r,e.access_path),p.value=!0,i.value[r]=e,!0)}function N(e,t,n,r){return ie(e,t)===n&&(o.value[n]=r,P(e,r.accounts),!0)}function P(e,t){a.value[e]={...a.value[e],...Object.fromEntries(t.map(e=>[e.id,e]))}}function F(e){let t=y.value.find(t=>
1t.id===e);if(!(t!=null&&t.available))throw Error(`Platform ${e} is not available`);return t}function I(e){e&&F(e),f.value=!1,l.value=e}function L(){f.value=!0,h.value=null,m.value=null,l.value=null,p.value=!0}function R(e){u.value=e}let z=e=>`${T.value}:${e}`;function B(e){return e&&g.value[z(e)]||null}function V(e){var t;return((t=B(e))==null?void 0:t.status)||null}function ue(e,t){var n;let r=(n=B(e))==null?void 0:n.lastChecked;return r?ne(r,t&&t>0?t:_):!1}let de=e=>{let t=V(e);return!!(t!=null&&t.enabled&&t.has_primary_actions)},H=e=>{var t;return(((t=V(e))==null||(t=t.counts)==null?void 0:t.has_value)||0)>0};function U(e,t){g.value[z(e)]={status:t,lastChecked:new Date().toISOString()},d.debug(`💾 [platform-session] Saved conversion status`,{externalId:e,sessionKey:T.value})}function W(){c.value++,i.value={},o.value={},a.value={},s.value={},l.value=null,f.value=!1,p.value=!1,m.value=null,h.value=null,g.value={},ee().reset()}return{platforms:y,sessions:i,scopes:o,generation:c,currentPlatform:l,lastUsedPlatform:u,choosingPlatform:f,initialized:p,isCheckingSession:k,sessionError:A,getAvailablePlatforms:b,getCurrentPlatform:x,getSession:S,getCurrentAccount:C,getEffectiveAccount:w,getSessionKey:T,getAccountsById:re,sessionIdentity:M,scopeKey:ie,beginSessionRequest:ae,failSessionRequest:oe,beginInitialization:se,finishInitialization:ce,applySession:le,applyScope:N,validatePlatform:F,setCurrentPlatform:I,requestPlatformChoice:L,setLastUsedPlatform:R,getConversionStatusEntry:B,getConversionStatus:V,isConversionStatusFresh:ue,hasConversions:de,hasValueConversions:H,setConversionStatus:U,resetState:W}},{persist:{pick:[`currentPlatform`,`lastUsedPlatform`]}}),O=i(`campaignAutopilot`,()=>{let e=r({}),t=r({}),n=r(!1),i=r(!1),a=r(null),o=r(new Set),s=r(!1),c=r(null),l=r(null);function u(t,n){d.debug(`💾 Setting autopilot settings for campaign ${t}:`,n),e.value[t]=n}function f(t){if(!(t in e.value))return;d.debug(`🗑️ Clearing autopilot settings for campaign ${t}`);let{[t]:n,...r}=e.value;e.value=r}function p(e,n){t.value[e]=n}function m(e){n.value=e}function h(e){a.value=e}function g(e){i.value=e}function _(e){o.value.add(e)}function v(){o.value.clear()}function y(){e.value={},t.value={},o.value.clear(),n.value=!1,i.value=!1,a.value=null}function b(){y(),s.value=!1,c.value=null,l.value=null}function x(e,t){c.value=e,l.value=t||null,s.value=!0}function S(){s.value=!1,c.value=null,l.value=null}function C(e){return o.value.has(e)}return{settings:e,activityLog:t,isLoading:n,isRunOnceLoading:i,error:a,showUpgradeModal:s,upgradeModalReason:c,upgradeModalCampaignId:l,setSettings:u,clearSettings:f,setActivityLog:p,setLoading:m,setError:h,setRunOnceLoading:g,addFetchedCampaign:_,clearFetchedCampaigns:v,clearCachedState:y,clearAll:b,openUpgradeModal:x,closeUpgradeModal:S,hasFetchedCampaign:C}}),k=18e5;function A(e,t,n){return n?`user:${e}:flow:${t}:campaign:${n}`:`user:${e}:flow:${t}`}var j=i(`autopilotIntent`,()=>{let e=r({});function t(e,t){let{[e]:n,...r}=t;return r}function n(e){return e?Date.now()-e.createdAt>k:!1}function i(){let r={...e.value},i=!1;for(let[e,a]of Object.entries(r))a&&n(a)&&(d.info(`🗑️ Clearing expired autopilot intent`,{scopeKey:e,campaignId:a.campaignId}),r=t(e,r),i=!0);i&&(e.value=r)}function a(t){var n;let r=A(t.userId,t.flow,t.campaignId);e.value={...e.value,[r]:{campaignId:t.campaignId,flow:t.flow,createdAt:(n=t.createdAt)==null?Date.now():n,scopeKey:r}}}function o(t,n,r){if(i(),r){var a;return(a=e.value[A(t,n,r)])==null?null:a}let o=`user:${t}:flow:${n}:campaign:`,s=Object.values(e.value).filter(e=>e.scopeKey.startsWith(o));if(s.length<=1){var c;return(c=s[0])==null?null:c}return d.warn(`⚠️ Ambiguous autopilot intent lookup without campaign id`,{userId:t,flow:n,matches:s.map(e=>e.campaignId)}),null}function s(n,r,a){if(i(),!n)return;if(r){if(a){let i=A(n,r,a);if(!(i in e.value))return;e.value=t(i,e.value);return}let i={...e.value},o=!1,s=`user:${n}:flow:${r}:`;for(let e of Object.keys(i))e.startsWith(s)&&(i=t(e,i),o=!0);o&&(e.value=i);return}let o={...e.value},s=!1;for(let e of Object.keys(o))e.startsWith(`user:${n}:`)&&(o=t(e,o),s=!0);s&&(e.value=o)}function c(n){i();let r={...e.value},a=!1;for(let e of Object.keys(r))n&&e.startsWith(`user:${n}:`)||(r=t(e,r),a=!0);a&&(e.value=r)}return{clearIntent:s,clearMismatchedUserScope:c,getIntent:o,setIntent:a}},{persist:{pick:[`intents`]}}
1),M=3e4,ie=15e3,ae=1e3,oe=3e4,se=5e3,ce=`Invalid response from user profile API`,le=`Authenticated session is waiting for initial profile bootstrap`,N=i(`auth`,()=>{let t=r(null),n=r(null),i=r(null),s=r(null),u=r(!1),f=r(null),g=r(!1),_=r(null),y=r(null),b=r(null),S=r(null),C=a(),ee=e(()=>t.value),w=e(()=>n.value),T=e(()=>g.value),te=e(()=>_.value),ne=e(()=>b.value),E=e(()=>!s.value||Date.now()>=s.value-12e4),D=e(()=>g.value&&!E.value),k=f,A=0,N=0,P=0,F=null,I=null,L=!1;function R(e){return typeof e==`object`&&!!e}function z(e){return!!(e!=null&&e.id&&e!=null&&e.email)}function B(){A+=1}function V(){P+=1}function ue(){N+=1,B(),V(),F=null,I=null,L=!1}function de(){return z(t.value)&&F!==null&&Date.now()-F<M}function H(e){return R(e)?e:null}function U(e){var t;let n=H(e);return(n==null?void 0:n.statusCode)||(n==null||(t=n.response)==null?void 0:t.status)||(n==null?void 0:n.status)||null}function W(e){var t,n;let r=H(e),i=(r==null?void 0:r.data)||(r==null||(t=r.response)==null?void 0:t._data)||(r==null||(n=r.response)==null?void 0:n.data)||null;return R(i)?i:null}function G(e){return e?typeof e.detail==`string`?e.detail:R(e.detail)&&typeof e.detail.message==`string`?e.detail.message:null:null}function K(e){return e&&typeof e.message==`string`?e.message:null}function q(e){if(e instanceof Error)return e.message;let t=H(e);return typeof(t==null?void 0:t.message)==`string`?t.message:null}function fe(e){return o(e)}function pe(e){return e instanceof Error&&e.message===ce}function me(e,t){return t!==null&&(t===408||t===429||t>=500&&t<600)||t===null&&!pe(e)}function he(e,t,n){let r=fe(e),i=r===null?ae*2**t:Math.max(r*1e3,ae);return Math.min(i,n)}function ge(e){return new Promise(t=>setTimeout(t,e))}function J(){return!n.value||!i.value||!g.value?{status:`auth_invalid`}:{status:`unavailable`,user:null}}function _e(){return z(t.value)&&n.value&&i.value&&g.value?{status:`ok`,user:t.value,source:`cache`}:{status:`unavailable`,user:t.value}}function ve(e,t,n){return e===N?t===A?n===P?null:`user_state`:`credentials`:`session`}function ye(e){ue(),n.value=e.access_token,i.value=e.refresh_token,s.value=new Date(e.expires_at).getTime(),g.value=!0,t.value=null}function be(e){b.value=e,S.value=Date.now()}function Y(){b.value=null,S.value=null}function xe(){return S.value===null?null:S.value+oe}function Se(e){return e?e-Date.now():null}function Ce(){let e=Se(xe());return e!==null&&e<=0}function we(){let e=xe(),t=Se(e);return{deadlineAtMs:e==null?void 0:e,timeoutMs:t===null?se:Math.max(1,Math.min(se,t))}}function Te(){return d.warn(`⚠️ [AuthStore] Pending auth bootstrap exceeded max duration, clearing session`),Q(),{status:`expired`}}function Ee(e){t.value=e,F=Date.now(),V(),Y(),p().clearMismatchedUserScope(e.id),j().clearMismatchedUserScope(e.id)}function De(){ue(),n.value=null,i.value=null,s.value=null,g.value=!1,t.value=null,Y(),X=null,Z=null}async function Oe(e,t){X=null,Z=null,ye(e),be(t);let n=await $(!0,we());if(n.status===`auth_invalid`)throw Q(),Error(`Failed to bootstrap authenticated session after ${t}`);return n.status===`unavailable`?z(n.user)?(d.warn(`⚠️ [AuthStore] Session bootstrapped after ${t} without fresh profile sync`),Y(),{status:`authenticated`,user:n.user}):(d.warn(`⚠️ [AuthStore] Keeping ${t} session pending while profile bootstrap is unavailable`),{status:`bootstrap_pending`,source:t}):(d.info(`✅ [AuthStore] Session bootstrapped after ${t}`),Y(),{status:`authenticated`,user:n.user})}async function ke(e,t,n){u.value=!0,f.value=null,k.retryAfter=void 0,k.isRateLimit=void 0;try{let r=await C.login(e,t,n);if(!r||!r.access_token||!r.refresh_token||!r.expires_at)throw Error(`Invalid response from login API`);return await Oe(r,`login`)}catch(e){let t=U(e),n=W(e),r=G(n);if(t===429){let t=fe(e)||60;f.value=`Too many login attempts. Please try again in ${t} seconds.`,k.retryAfter=t,k.isRateLimit=!0}else t===401?f.value=`Invalid email or password`:t===422?f.value=`Invalid email format or missing required fields`:r?f.value=r:K(n)?f.value=`Authentication failed`:(q(e),f.value=`Login failed`);let i=v(e);throw d.error(`❌ Login error:`,{error_code:i==null?void 0:i.error_code,message:(i==null?void 0:i.detail)||q(e)}),g.value=!1,e}finally{u.value=!1}}function Ae(){var e;let n=((e=t.value)==null?void 0:e.id)||null;Re(),n&&p().clearUserIntent(n),re().resetState(),window.location.href=`/auth/login`}async function je(e,t,n,r,i,a,o){u.value=!0,f.value=null,k.retryAfter=void 0,k.isRateLimit=void 0;try{d.info(`▶️ [AuthStore] Registration request started`,{traceId:o});let s=await C.register({email:t,password:n,full_name:e,company_name:``,is_agency:!1,selected_tier:i,selected_billing_cycle:a,captcha_token:r},o);if(!s||!s.access_token||!s.refresh_token||!s.expires_at)throw Error(`Invalid response from registration API`);let c=await Oe(s,`register`);return d.info(`✅ [AuthStore] Registration request completed`,{traceId:o}),c}catch(e){let t=U(e),n=l(e),r=W(e),i=G(r);throw t===422?f.value=`Invalid registration data. Please check your inputs.`:n===`EMAIL_ALREADY_REGISTERED`||t===409?f.value=`Email already exists`:i?f.value=i:K(r)?f.value=`Authentication failed`:q(e)?f.value=`Login failed`:f.value=`Registration failed`,d.error(`❌ Registration error:`,{traceId:o,error_code:n,message:c(e,q(e)||`Registration failed`)}),e}finally{u.value=!1}}let X=null,Z=null;async function Me(e={}){if(X)return X;X=Ne(e);try{return await X}finally{X=null}}async function Ne(e={}
1){if(!n.value||!i.value)return Q(),{status:`auth_invalid`};if(E.value)try{if(!await Fe(e))return!n.value||!i.value||!g.value?(Q(),{status:`auth_invalid`}):(d.warn(`⚠️ [AuthStore] Auth check could not refresh the access token; marking session unavailable`),{status:`unavailable`,user:t.value})}catch(e){let r=v(e);return d.error(`Error refreshing access token in checkAuth:`,{error_code:r==null?void 0:r.error_code,message:(r==null?void 0:r.detail)||(e==null?void 0:e.message)}),!n.value||!i.value||!g.value?(Q(),{status:`auth_invalid`}):{status:`unavailable`,user:t.value}}return g.value=!0,await $(!0,e)}function Q(){De(),O().clearAll(),j().clearMismatchedUserScope()}async function Pe(e={}){if(!i.value)return!1;let t=i.value;try{let r=await C.refreshToken(t,{timeout:e.timeoutMs});return!r||!r.access_token||!r.refresh_token||!r.expires_at?(d.error(`Invalid response from token refresh API`),!1):i.value===t?(B(),n.value=r.access_token,i.value=r.refresh_token,s.value=new Date(r.expires_at).getTime(),d.info(`✅ Token refreshed successfully`),!0):(d.warn(`⚠️ [AuthStore] Ignoring stale token refresh response`),!!(n.value&&i.value&&g.value))}catch(e){if(i.value&&i.value!==t)return d.warn(`⚠️ [AuthStore] Ignoring stale token refresh failure`),!!(n.value&&i.value&&g.value);let r=U(e),a=W(e),o=G(a),s=`Failed to refresh access token`;r===401?(h(a)?(s=x(a),d.warn(`⚠️ [Auth] Refresh token revoked`,{error_code:a.error_code,revoked_at:a.revoked_at})):m(a)?s=x(a):o!=null&&o.includes(`revoked`)?(s=`Refresh token revoked`,d.warn(`⚠️ [Auth] Refresh token revoked, logging out`)):s=o||`Invalid refresh token`,d.warn(`⚠️ [Auth] Refresh rejected with 401, clearing auth state`),Q()):o?s=o:K(a)?s=`Token validation failed`:q(e)&&(s=`Authentication failed`);let c=v(e);return d.error(`❌ Token refresh error:`,{error_code:c==null?void 0:c.error_code,message:(c==null?void 0:c.detail)||s}),!1}}async function Fe(e={}){if(Z)return d.debug(`⏳ [AuthStore] Awaiting ongoing token refresh`),await Z;d.debug(`▶️ [AuthStore] Starting token refresh`),Z=Pe(e);try{return await Z}finally{Z=null,d.debug(`🔄 [AuthStore] Token refresh process completed`)}}async function Ie(e=!1,r={}){let a=e&&z(t.value);d.info(a?`🔍 Background profile refresh`:`Fetching user profile from API`),a||(u.value=!0);try{for(;n.value&&i.value;){let e=N,a=A,s=P,c=0,l=0;for(;;)try{var o;let i=Se(r.deadlineAtMs);if(i!==null&&i<=0)return d.warn(`⚠️ [AuthStore] ${le}`),{status:`unavailable`,user:t.value};let c=i===null?r.timeoutMs:Math.max(1,Math.min((o=r.timeoutMs)==null?i:o,i)),l=await C.getUserProfile({timeout:c});if(!l||!l.id||!l.email)throw Error(ce);let u=ve(e,a,s);if(u===`session`)return d.warn(`⚠️ [AuthStore] Ignoring stale user profile response after session change`),J();if(u===`credentials`){d.info(`🔄 [AuthStore] Restarting user profile fetch after token refresh`);break}if(u===`user_state`)return d.info(`🔄 [AuthStore] Reusing newer local user state instead of stale profile response`),_e();if(d.info(`✅ User profile fetched successfully:`,l),Ee(l),!L||!n.value)return{status:`ok`,user:l,source:`network`};d.debug(`🔄 [AuthStore] Running queued user profile refetch`),L=!1;break}catch(o){let u=ve(e,a,s);if(u===`session`)return d.warn(`⚠️ [AuthStore] Ignoring stale user profile failure after session change`),J();if(u===`credentials`){d.info(`🔄 [AuthStore] Restarting user profile fetch after token refresh failure`);break}if(u===`user_state`)return d.info(`🔄 [AuthStore] Reusing newer local user state after stale profile failure`),_e();let f=U(o),p=W(o),m=G(p),h=`Failed to fetch user profile`;if(f===401||f===403){h=`Authentication required`,d.warn(`⚠️ [Auth] Unauthorized profile fetch, resetting auth state`),Q();let e=v(o);return d.error(`❌ Error fetching user profile:`,{error_code:e==null?void 0:e.error_code,message:(e==null?void 0:e.detail)||h}),{status:`auth_invalid`}}let g=Se(r.deadlineAtMs),_=Math.min(ie-l,g==null?1/0:g);if(me(o,f)&&_>0){let t=he(o,c,_);if(d.warn(`⚠️ [AuthStore] Retrying user profile fetch after transient failure`,{attempt:c+1,delayMs:t,totalRetryDelayMs:l+t}),c+=1,l+=t,await ge(t),!n.value||!i.value)return d.warn(`⚠️ [AuthStore] Stopping user profile retry after auth state changed`),J();let r=ve(e,a,s);if(r===`session`)return d.warn(`⚠️ [AuthStore] Stopping user profile retry after session changed`),J();if(r===`credentials`){d.info(`🔄 [AuthStore] Restarting user profile fetch after token refresh during backoff`);break}if(r===`user_state`)return d.info(`🔄 [AuthStore] Reusing newer local user state after profile backoff`),_e();continue}m?h=m:K(p)?h=`Token validation failed`:q(o)&&(h=`Authentication failed`);let y=v(o);return d.error(`❌ Error fetching user profile:`,{error_code:y==null?void 0:y.error_code,message:(y==null?void 0:y.detail)||h}),{status:`unavailable`,user:t.value}}}return{status:`unavailable`,user:t.value}}finally{a||(u.value=!1)}}async function $(e=!1,r={}
1){if(!n.value||!i.value)return{status:`auth_invalid`};if(!e&&de()){d.info(`🔍 [AuthStore] Reusing fresh cached user profile`);let e=t.value;return z(e)?{status:`ok`,user:e,source:`cache`}:{status:`unavailable`,user:null}}if(I){e?(L=!0,d.debug(`⏳ [AuthStore] Queued user profile refetch after in-flight request`)):d.debug(`⏳ [AuthStore] Awaiting ongoing user profile fetch`);let t=await I;return e&&L&&!I&&n.value?(d.debug(`🔄 [AuthStore] Starting queued user profile refetch after settled request`),L=!1,await $(!0,r)):t}d.debug(`▶️ [AuthStore] Starting user profile sync`,{forceRefresh:e}),I=Ie(e,r);try{return await I}finally{I=null}}async function Le(e=!1){let t=await $(e);return t.status===`ok`?t.user:t.status===`unavailable`&&t.user?(d.warn(`⚠️ [AuthStore] Fresh user sync unavailable; reusing cached profile`),t.user):t.status===`unavailable`?(d.warn(`⚠️ [AuthStore] Fresh user profile required but unavailable`),null):(d.warn(`⚠️ [AuthStore] Fresh user profile required but auth is invalid`),null)}function Re(){d.info(`Resetting auth store state`),Q(),u.value=!1,f.value=null,k.retryAfter=void 0,k.isRateLimit=void 0,y.value=null}function ze(e,t=`credits`){y.value={message:e,type:t}}function Be(){y.value=null}function Ve(e){var n;(n=t.value)!=null&&n.subscription&&(V(),d.debug(`💾 [AuthStore] Patching subscription state`,e),t.value={...t.value,subscription:{...t.value.subscription,...e}})}function He(e){t.value&&e&&(V(),d.debug(`💾 [AuthStore] Applying authoritative subscription snapshot`,{status:e.status,tier:e.tier,pendingPriceId:e.pending_price_id}),t.value={...t.value,subscription:{...e}})}async function Ue(){if(z(t.value)&&D.value)return{status:`authenticated`,user:t.value,source:`cache`};if(b.value&&n.value&&i.value&&g.value)return Ce()?(Te(),{status:`guest`}):{status:`bootstrap_pending`,source:b.value};let e=await Me();return e.status===`auth_invalid`?{status:`guest`}:e.status===`unavailable`?{status:`unavailable`,user:e.user}:{status:`authenticated`,user:e.user,source:e.source}}async function We(){if(!n.value||!i.value||!g.value)return Q(),{status:`auth_invalid`};if(Ce())return Te();if(z(t.value)&&D.value)return Y(),{status:`authenticated`,user:t.value};let e=await Me(we());return e.status===`auth_invalid`?(Y(),{status:`auth_invalid`}):e.status===`unavailable`&&z(e.user)?(Y(),{status:`authenticated`,user:e.user}):e.status===`unavailable`?Ce()?Te():(d.warn(`⚠️ [AuthStore] ${le}`),{status:`bootstrap_pending`}):(Y(),{status:`authenticated`,user:e.user})}return{user:t,accessToken:n,refreshToken:i,accessTokenExpiry:s,loading:u,error:f,isAuthenticated:g,redirectPath:_,subscriptionWarning:y,getUser:ee,getToken:w,getIsAuthenticated:T,getRedirectPath:te,getPendingBootstrapSource:ne,isTokenExpired:E,isSessionValid:D,login:ke,logout:Ae,register:je,resolveRouteSession:Ue,syncCurrentUser:$,refreshAccessToken:Fe,ensureFreshUser:Le,bootstrapAuthenticatedSession:Oe,completePendingBootstrapSession:We,resetState:Re,setSubscriptionWarning:ze,clearSubscriptionWarning:Be,patchSubscription:Ve,setSubscriptionSnapshot:He}},{persist:{pick:[`accessToken`,`refreshToken`,`accessTokenExpiry`,`isAuthenticated`,`redirectPath`]}});export{te as a,ee as c,m as d,g as f,v as h,re as i,y as l,h as m,j as n,T as o,_ as p,O as r,C as s,N as t,x as u};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.