1import{f as N,j as x}from"/build/_shared/chunk-2GK2INE7.js";import{a as I,d as E,g as D,h as A,j as T,k as R}from"/build/_shared/chunk-RPR7NXHN.js";import{b as U,ha as v,t as _}from"/build/_shared/chunk-ZQZP2RIC.js";import{A as W,u as b}from"/build/_shared/chunk-ZSEETMYI.js";import{a as m}from"/build/_shared/chunk-JHYR5QDS.js";import{O as h}from"/build/_shared/chunk-FES3B5QL.js";import{a as P}from"/build/_shared/chunk-G3QUQOKW.js";import{e as C}from"/build/_shared/chunk-O3BUCIVF.js";var $=e=>Array.from(e).filter(t=>{let o=t.charCodeAt(0);return o>31&&o!==127}).join("");function O(e,t="/"){if(typeof window=="undefined"||!e)return t;let o=$(e).trim();if(!o||!o.startsWith("/")||o.startsWith("//")||o.startsWith("/\\"))return t;try{let r=new URL(o,window.location.origin);if(r.origin!==window.location.origin)return t;let s=`${r.pathname}${r.search}${r.hash}`;return s.startsWith("//")?t:s}catch{return t}}W();var a=C(P()),J="auth/popup-closed-by-user",j="auth/popup-blocked",z="auth/unauthorized-domain",H=(e,t)=>{let o=e instanceof I&&e.code===z||e instanceof TypeError;console.error(o?`[OIDC] ${window.location.hostname} is not an authorized domain of Firebase project "${t.app.options.projectId}". Add it in Firebase console > Authentication > Settings > Authorized domains.`:"[OIDC] Firebase redirect sign-in error",e)},he=async({authOIDCMode:e,authOIDCProviderId:t,event:o,flags:{authOIDCIgnoreAccUpdateNullStore:r,authOIDCTriggerFullAccountUpdate:s},forcePromptMode:l,overrideRedirectUrl:u,setShowPageWideLoader:n})=>{n(!0);let d=e==="popup",p=R(),f=V(t,l);if(ie(u),!d){n(!1);try{await A(p,f,T)}catch(i){H(i,p),y("Error during sign in.")}return{}}let c=window.setTimeout;try{q(c);let i=await D(p,f,T);return await X(i,{authOIDCIgnoreAccUpdateNullStore:r,authOIDCTriggerFullAccountUpdate:s}),{signupSuccess:!0}}catch(i){i instanceof I?i.code===J?console.log("Popup closed by user",i):i.code===j?(console.warn("OIDC Popup blocked",i),oe("Popup blocked by browser, click again.","Try enabling popups in your browser settings.")):(y("Error during sign in."),console.error(`FirebaseError at OIDC response [${i.code}]`,i)):(console.error("Firebase OIDC popup error",i),y("Error during sign in."))}finally{window.setTimeout=c,n(!1)}},B=e=>{try{return b(e).decodedPayload}catch(t){return console.error("Error decoding token",t),null}},X=async(e,t)=>{var l,u;let o=e._tokenResponse.idToken,r=e._tokenResponse.refreshToken,s=e._tokenResponse.isNewUser;if(s&&console.log("Signup new user"),o&&r){te();let n=G(e._tokenResponse.rawUserInfo),d=n==null?void 0:n.iss,p=await Z(d),{authorization_endpoint:f,end_session_endpoint:c}=p||{},i=Y(f),g=B(o),w=g==null?void 0:g.selectedStore;!w&&(n!=null&&n.store_id)&&(w=n==null?void 0:n.store_id);let L={oauthIdToken:e._tokenResponse.oauthIdToken,logoutURL:c,sessionToken:(u=(l=e.user)==null?void 0:l.stsTokenManager)==null?void 0:u.accessToken,accountProfileUrl:i},M=e.user.phoneNumber||(n==null?void 0:n.phone_number)||"";await Q({idToken:o,refreshToken:r,accountData:{givenName:e._tokenResponse.firstName||"",surName:e._tokenResponse.lastName||"",phone:M,email:(g==null?void 0:g.email)||"",selectedStore:w},providerDetails:L,flags:t,isNewUser:s})}else console.error("Invalid user data")},K=()=>{var e;try{let t=JSON.parse(localStorage.getItem("user-data")||"{}");return(e=t==null?void 0:t.selectedStore)!=null?e:null}catch{return console.log("Error parsing user data. No anonymous store selected"),null}},V=(e="oidc.ping",t)=>{let o=new E(e);return o.addScope("openid"),o.addScope("profile"),o.setCustomParameters({oidcPolicyId:"placeHolderId",policyId:"placeHolderId",prompt:t||"login"}),o},G=e=>{try{return JSON.parse(e)}catch(t){return console.error("Error parsing rawUserInfo",t),{}}},Y=e=>{try{if(!e)return"";let t=new URL(e);return`${t.origin}/${t.pathname.split("/")[1]}/account-profile`}catch(t){return console.error(`Error constructing external account profile URL from ${e} auth url`,t),""}},Z=async e=>{try{let t=`${e}/.well-known/openid-configuration`;return await(await fetch(t)).json()}catch(t){return console.error(`Error retrieving well-known config for issuer: ${e}`,t),{}}},q=e=>{window.setTimeout=function(t,o,...r){return o===8e3&&(o=2e3),e(t,o,...r)}},Q=async({accountData:e,flags:{authOIDCIgnoreAccUpdateNullStore:t,authOIDCTriggerFullAccountUpdate:o},idToken:r,isNewUser:s,providerDetails:l,refreshToken:u})=>{var f;let n={...e},d=new FormData,p=o==="TRUE";try{if(t!=="TRUE"&&!(e!=null&&e.selectedStore)&&!p){let c=K()||"";if(c){d.set("idToken",r),d.set("refreshToken",u),d.set("selectedStore",c);let i=await F({formData:d,idToken:r});n.selectedStore=(f=i==null?void 0:i.attributes)==null?void 0:f.selectedStore}}if(p){d.set("idToken",r),d.set("refreshToken",u),Object.entries(e).forEach(([i,g])=>{g!==void 0&&d.set(i,g)});let c=await F({formData:d,idToken:r});n=(c==null?void 0:c.attributes)||e}}catch(c){console.error("Error updating account attributes on OIDC sign in",c),n={...e}}(!n.givenName||!n.surName)&&console.warn("Missing attributes.givenName or attributes.surName from oidc response."),ee({idToken:r,refreshToken:u,accountAttributes:n,providerDetails:l}),await N()},F=async({formData:e,idToken:t})=>{let o=["refreshToken","idToken"],r={attributes:Object.fromEntries(Array.from(e.keys()).map(s=>[s,e.get(s)]).filter(([s,l])=>!o.includes(s)&&l!==void 0&&l!==null&&l!==""))};return await x({updateData:r,idToken:t,ignoreFieldErrors:["phone"],isRetry:!1})},ee=({accountAttributes:e,idToken:t,providerDetails:o,refreshToken:r})=>{let s=JSON.parse(localStorage.getItem("user-data")||"{}");localStorage.setItem("user-data",JSON.stringify({...s,isLoggedIn:!0,isAnonUser:!1,token:t,refreshToken:r,...e,providerDetails:o}))},te=()=>{m.hide("signin-success");let e=".",t;m.show({icon:(0,a.jsx)(_,{size:"1rem"}),message:(0,a.jsxs)(h,{fs:"16px",fw:500,"aria-live":"polite",children:["Signing in",(0,a.jsx)("span",{id:"signinInDots",children:e})]}),autoClose:5e3,id:"signin-success",onClose:()=>{localStorage.setItem("storageNotification","Signed in"),t&&clearInterval(t)}}),t=setInterval(()=>{e==="..."?e=".":e===".."?e="...":e==="."?e="..":e=".";let r=document.getElementById("signinInDots");r&&(r.innerHTML=e)},333)},y=e=>{m.hide("signin-signup-failure"),m.show({icon:(0,a.jsx)(v,{role:"presentation",size:"1rem"}),message:(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(h,{fs:"16px",fw:500,"aria-live":"polite",children:e})}),autoClose:5e3,id:"signin-signup-failure",title:"Error:",color:"red"})},oe=(e,t)=>{m.hide("signin-signup-warning"),m.show({icon:(0,a.jsx)(U,{role:"presentation",size:"1rem"}),message:(0,a.jsx)(a.Fragment,{children:(0,a.jsxs)(h,{fs:"16px",fw:500,"aria-live":"polite",children:[e,t?(0,a.jsx)("div",{children:t}):null]})}),autoClose:5e3,id:"signin-signup-warning",title:"Warning:",color:"yellow"})},re=5e3,k=50,we=()=>new Promise(e=>{let t=0,o=()=>{window.FirebaseAuthReady?e(!0):t<re?(t+=k,setTimeout(o,k)):(console.error("Firebase auth failed to initialize within 5s"),e(!1))};o()}),ne=10,ie=e=>{(e||typeof window!="undefined")&&(localStorage.setItem("redirectToAfterOIDC",e||window.location.href),localStorage.setItem("redirectToAfterOIDCTimestamp",Date.now().toString()))},S=()=>{localStorage.removeItem("redirectToAfterOIDC"),localStorage.removeItem("redirectToAfterOIDCTimestamp")},Ie=()=>{try{let e=typeof window!="undefined"?localStorage.getItem("redirectToAfterOIDC"):null,t=typeof window!="undefined"?localStorage.getItem("redirectToAfterOIDCTimestamp"):null,o=t&&Date.now()-parseInt(t)<ne*60*1e3;if(e&&o){let r=new URL(e,window.location.origin);if(r.pathname==="/login"){let s=r.searchParams.get("redirectTo");window.location.replace(O(s,"/"))}else{let{hash:s,pathname:l,search:u}=r,n=r.origin===window.location.origin?`${l}${u}${s}`:null;window.location.href=O(n,"/")}S()}else console.log("Expired redirect timestamp, redirecting to home page",e,o),S(),window.location.replace("/")}catch(e){console.error("Error redirecting to previous page after OIDC",e),S(),window.location.replace("/")}};export{O as a,H as b,he as c,X as d,te as e,we as f,Ie as g};
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.