@bodhiapp/bodhi-js-react-core 0.0.39 → 0.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bodhi-react-core.cjs.js +2 -2
- package/dist/bodhi-react-core.esm.js +360 -363
- package/dist/index.d.ts +1 -0
- package/dist/url.d.ts +1 -0
- package/package.json +6 -6
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`,JSON.stringify(n,null,2)),g.current?.updateState(y()),{setupState:n}},[T.MSG.MODAL_LNA_CONNECT]:async t=>{const n=t.payload.serverUrl;console.log("[SetupModalProcessor] LNA connect:",n);const o=await e.testDirectConnectivity(n);if(o.server.status!=="not-connected"){const v=o.server.status;if(v==="ready"||v==="setup"||v==="resource_admin"){h.setDirectStatus("granted"),e.getConnectionMode()===null&&await e.setConnectionMode("direct");const L=await S();return f.current=L,g.current?.updateState(y()),{success:!0}}}const C=await S();return f.current=C,g.current?.updateState(y()),{success:!1}},[T.MSG.MODAL_LNA_SKIP]:async()=>{h.setDirectStatus("skipped");const t=await S();return f.current=t,g.current?.updateState(y()),{success:!0}},[T.MSG.MODAL_CLOSE]:()=>{p()},[T.MSG.MODAL_COMPLETE]:()=>{p()},[T.MSG.MODAL_CONFIRM_SERVER_INSTALL]:t=>(h.setServerInstallConfirmed(t.payload.confirmed),g.current?.updateState(y()),{success:!0}),[T.MSG.MODAL_SELECT_CONNECTION]:async t=>{const o=t.payload.connection==="lna"?"direct":"extension";return await e.setConnectionMode(o),g.current?.updateState(y()),{success:!0}}}),[_,e,h,S,y,I,p]);return r.useEffect(()=>(g.current=new s.OnboardingModal({modalHtmlPath:a,handlers:c}),()=>{g.current?.destroy(),g.current=null}),[a,c]),r.useEffect(()=>{k&&g.current?(g.current.showLoading(),S(!0).then(t=>{f.current=t,g.current?.updateState(t),E?.()}).catch(t=>{console.error("[SetupModalProcessor] buildSetupState failed:",t)})):!k&&g.current&&g.current.destroy()},[k,S,E]),null}const se="http://localhost:1135",q={MODAL_READY:"modal:ready",MODAL_PROBE:"modal:probe",MODAL_COMPLETE:"modal:complete",MODAL_CLOSE:"modal:close"},ae=130,ce=143;function oe(e=navigator.userAgent){const a=e.toLowerCase(),p=a.match(/edg\/(\d+)/);if(p){const d=parseInt(p[1],10);return{name:"edge",version:d,supported:d>=ce}}const E=a.match(/chrome\/(\d+)/);if(E&&!a.includes("edg/")){const d=parseInt(E[1],10);return{name:"chrome",version:d,supported:d>=ae}}const w=a.match(/firefox\/(\d+)/);if(w)return{name:"firefox",version:parseInt(w[1],10),supported:!1};const l=a.match(/version\/(\d+).*safari/);return l&&!a.includes("chrome/")?{name:"safari",version:parseInt(l[1],10),supported:!1}:{name:"unknown",version:0,supported:!1}}function ie({client:e,modalHtmlPath:a,hideSetup:p,onSetupReady:E,setupState:w,basePath:l="/",logLevel:d="warn",autoProbe:k=!0,defaultHost:_}){const g=w!=="ready",h=r.useMemo(()=>new s.Logger("SetupModalV2Processor",d),[d]),f=r.useRef(null),m=r.useRef(null),x=r.useMemo(()=>new s.BodhiClientUserPrefsManager(s.createStoragePrefixWithNamespace(l,"bodhijs:")),[l]),O=r.useMemo(()=>`${s.createStoragePrefixWithNamespace(l,"bodhijs:")}setup-v2.connection`,[l]),I=r.useCallback(()=>{try{const c=localStorage.getItem(O);if(!c)return null;const t=JSON.parse(c);return typeof t?.serverUrl=="string"?t:null}catch{return null}},[O]),M=r.useCallback(c=>{try{localStorage.setItem(O,JSON.stringify({serverUrl:c,lastProbedAt:Date.now()}))}catch{}},[O]),A=r.useCallback(async c=>{const t=oe(),n=await e.testDirectConnectivity(c),o=n.server.status;return o==="ready"?(M(c),x.setDirectStatus("granted"),e.getConnectionMode()===null&&await e.setConnectionMode("direct"),{serverUrl:c,browser:t,probeStatus:"connected",serverStatus:"ready"}):o==="setup"||o==="resource_admin"?{serverUrl:c,browser:t,probeStatus:"not-ready",serverStatus:o}:o==="error"?{serverUrl:c,browser:t,probeStatus:"error",serverStatus:"error",error:n.server.error?{code:"server-error",message:n.server.error.message}:void 0}:{serverUrl:c,browser:t,probeStatus:"network-error",serverStatus:"unreachable",error:n.server.error?{code:"network-error",message:n.server.error.message}:void 0}},[e,x,M]),S=r.useCallback(async()=>{const t=I()?.serverUrl??_??se;return A(t)},[A,I,_]),y=r.useMemo(()=>({[q.MODAL_READY]:async()=>{if(m.current)return{setupState:m.current};const c=await S();return m.current=c,{setupState:c}},[q.MODAL_PROBE]:async c=>{const t=await A(c.payload.serverUrl);return m.current=t,f.current?.updateState(t),{setupState:t}},[q.MODAL_COMPLETE]:()=>{p()},[q.MODAL_CLOSE]:()=>{p()}}),[S,A,p]);return r.useEffect(()=>(f.current=new s.OnboardingModalV2({modalHtmlPath:a,handlers:y}),()=>{f.current?.destroy(),f.current=null}),[a,y]),r.useEffect(()=>{k&&S().then(c=>{m.current=c,h.info("Auto-probe complete:",c.probeStatus)}).catch(c=>{h.error("Auto-probe failed:",c)})},[k,S,h]),r.useEffect(()=>{let c=!1;return g&&f.current?(f.current.showLoading(),m.current?(f.current.updateState(m.current),E?.()):S().then(t=>{c||(m.current=t,f.current?.updateState(t),E?.())}).catch(t=>{c||h.error("buildInitialState failed:",t)})):!g&&f.current&&f.current.destroy(),()=>{c=!0}},[g,S,E,h]),null}const J={status:"not-initialized",mode:null,extensionId:null,url:null,server:s.BACKEND_SERVER_NOT_CONNECTED,error:null},X={status:"initializing",mode:null,extensionId:null,url:null,server:s.BACKEND_SERVER_NOT_CONNECTED,error:null};function Y(e){return e.status==="not-initialized"}function H(e){return e.status==="initializing"}function Z(e){return e.status!=="not-initialized"&&e.status!=="initializing"}function V(e){return e.status==="ready"}function $(e){return V(e)&&e.server.status==="ready"}function Q(e){return s.isExtensionState(e)?{status:e.extension==="not-initialized"?"initializing":e.extension==="not-found"?"extension-not-found":"ready",mode:"extension",extensionId:e.extensionId,url:null,server:e.server,error:e.server.error}:{status:e.url===null||e.server.status==="not-reachable"||e.server.status==="not-connected"?"direct-not-connected":"ready",mode:"direct",extensionId:null,url:e.url,server:e.server,error:e.server.error}}const ue={isNotInitialized:Y,isInitializing:H,isInitialized:Z,isReady:V,isOverallReady:$},G=r.createContext(null);G.displayName="BodhiContext";function le({children:e,client:a,modalHtmlPath:p,handleCallback:E=!0,callbackPath:w,basePath:l="/",logLevel:d="warn",setupModal:k="setup-modal-v2",autoProbe:_=!0,defaultHost:g}){const h=l==="/"?"":l.replace(/\/$/,""),f=w??`${h}/callback`,m=r.useMemo(()=>new s.Logger("BodhiProvider",d),[d]),x=r.useRef(!1),O=r.useRef(!1),I=r.useRef(!1),[M,A]=r.useState(J),[S,y]=r.useState(s.INITIAL_AUTH_STATE),[c,t]=r.useState(!1),[n,o]=r.useState("ready"),C=r.useCallback((i,u)=>{O.current=!0,y({status:"error",user:null,accessToken:null,error:{code:i,message:u},refreshToken:null,expiresAt:null,isTokenRefresh:!1}),t(!1)},[]),v=r.useCallback(()=>{O.current=!1},[]);r.useEffect(()=>{const i=u=>{switch(u.type){case"client-state":A(Q(u.state));break;case"auth-state":O.current||(y(u.state),t(!1));break}};return a.setStateCallback(i),()=>{a.setStateCallback(s.NOOP_STATE_CALLBACK)}},[a]);const L=r.useCallback(async()=>{o("loading")},[]),N=r.useCallback(()=>{o("ready")},[]),P=r.useCallback(()=>{o("loaded")},[]),j=r.useCallback(async i=>{A(X);try{await a.init(i||{})}catch(u){m.error("Init failed:",u)}},[a,m]);r.useEffect(()=>{if(I.current)return;I.current=!0,(async()=>{if(await j(),!E)return;const u=new URL(window.location.href);if(u.pathname!==f||x.current||!s.isWebUIClient(a))return;if(u.searchParams.get("bodhi_flow")==="access_request"){const R=u.searchParams.get("id");if(!R){m.warn("Access request callback marker present but no id parameter"),window.history.replaceState({},"",l);return}x.current=!0,t(!0);try{await a.handleAccessRequestCallback(R)}catch(D){m.error("Access request callback failed:",D);const te=D instanceof s.BodhiError?D:null;C(te?.code??"access_request_callback_failed",D instanceof Error?D.message:"Access request callback failed"),window.history.replaceState({},"",l)}return}const z=u.searchParams.get("code"),K=u.searchParams.get("state");if(!(!z||!K)){x.current=!0,t(!0);try{await a.handleOAuthCallback(z,K),window.history.replaceState({},"",l)}catch(R){m.error("OAuth callback failed:",R);const D=R instanceof s.BodhiError?R:null;C(D?.code??"oauth_callback_failed",R instanceof Error?R.message:"OAuth callback failed"),window.history.replaceState({},"",l)}}})()},[j,a,E,f,l]);const F=r.useCallback(async i=>{v(),t(!0);try{const u=i?{...i.userRole&&{userRole:i.userRole},...i.requested&&{requested:i.requested},...i.flowType&&{flowType:i.flowType},...i.redirectUrl&&{redirectUrl:i.redirectUrl},...i.onProgress&&{onProgress:i.onProgress},...i.pollIntervalMs&&{pollIntervalMs:i.pollIntervalMs},...i.pollTimeoutMs&&{pollTimeoutMs:i.pollTimeoutMs}}:void 0,U=u&&Object.keys(u).length>0?u:void 0;await a.login(U)}catch(u){const U=u instanceof s.BodhiError?u:null,z={status:"error",user:null,accessToken:null,error:{message:u instanceof Error?u.message:"Login failed",code:U?.code??"login_failed"},refreshToken:null,expiresAt:null,isTokenRefresh:!1};return y(z),t(!1),z}},[a,v]),W=r.useCallback(async()=>{v();try{await a.logout()}catch(i){C("logout_failed",i instanceof Error?i.message:"Logout failed")}},[a,C,v]),ee=r.useMemo(()=>{const i=M.status==="ready",u=M.server.status==="ready";return{client:a,clientState:M,auth:S,isAuthLoading:c,login:F,logout:W,showSetup:L,hideSetup:N,setupState:n,isAuthenticated:S.status==="authenticated",canLogin:i&&!c,isReady:i,isServerReady:u,isOverallReady:i&&u,isInitializing:M.status==="initializing",isExtension:M.mode==="extension",isDirect:M.mode==="direct"}},[a,M,S,c,n,F,W,L,N]);return B.jsxs(G.Provider,{value:ee,children:[k==="setup-modal"?B.jsx(ne,{client:a,modalHtmlPath:p,hideSetup:N,onSetupReady:P,setupState:n,basePath:l,logLevel:d,autoProbe:_}):B.jsx(ie,{client:a,modalHtmlPath:p,hideSetup:N,onSetupReady:P,setupState:n,basePath:l,logLevel:d,autoProbe:_,defaultHost:g}),e]})}function de(){const e=r.useContext(G);if(!e)throw new Error("useBodhi must be used within BodhiProvider");return e}const fe=e=>b.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 479.995 479.995",width:"480px",height:"480px",...e},b.createElement("path",{fill:"#ffa4b8",d:"M239.998,374.56l-0.01-0.01c0-0.01,0.01-0.01,0.01-0.02c-4.64-8.78-65.7-144.8-212.22-85.2 c-14.36,5.85-19.78,23.45-11.19,36.36c11.11,16.69,22.86,30.01,34.91,40.53c-27.85,7.89-45.6,33.8-43.3,61.55 c0.96,11.6,13.29,18.52,23.71,13.35c33.99-16.84,60.03-2.51,80.35,2.14c56.68,12.99,113.71,4.53,125.52-46.29 c0.52-2.22,0.95-4.51,1.28-6.89c0.01-0.04,0.01-0.08,0.02-0.12c0.066-0.492,0.126-0.978,0.181-1.458 c0.455-3.631,0.712-7.438,0.739-11.452c-0.02-1.44-0.02-2.01,0-2.25v-0.09c0-0.02,0-0.04,0.01-0.05c0-0.02,0.01-0.03,0.02-0.06 c0-0.01,0.01-0.01,0.01-0.02C240.018,374.569,240.008,374.56,239.998,374.56z"}),b.createElement("path",{fill:"#ffa4b8",d:"M471.798,427.769c-0.96,11.6-13.29,18.52-23.71,13.35c-33.99-16.84-60.03-2.51-80.35,2.14 c-63.41,14.53-127.25,2.22-127.74-66.21c0.033-2.642-0.044-2.302,0.04-2.47c-0.02-0.01-0.03-0.02-0.04-0.02l0.01-0.01 c0-0.01-0.01-0.01-0.01-0.02c4.64-8.78,65.7-144.8,212.22-85.2c14.36,5.85,19.78,23.45,11.19,36.36 c-11.11,16.69-22.86,30.01-34.91,40.53C456.348,374.109,474.098,400.019,471.798,427.769z"}),b.createElement("path",{fill:"#befa91",d:"M428.498,366.219c27.85,7.89,45.6,33.8,43.3,61.55c-0.96,11.6-13.29,18.52-23.71,13.35 c-33.99-16.84-60.03-2.51-80.35,2.14c-63.41,14.53-127.928,2.222-127.74-66.21c0.007-2.683-0.02-2.351,0.04-2.47 C248.598,379.129,345.858,438.329,428.498,366.219z"}),b.createElement("path",{fill:"#befa91",d:"M51.498,366.219c82.76,72.22,180.18,12.74,188.5,8.34c0.01,0,0.02,0.01,0.04,0.02 c-0.058,0.116-0.047-0.169-0.04,2.47c0.188,68.432-64.33,80.74-127.74,66.21c-20.32-4.65-46.36-18.98-80.35-2.14 c-10.42,5.17-22.75-1.75-23.71-13.35C5.898,400.019,23.648,374.109,51.498,366.219z"}),b.createElement("path",{fill:"#ffbfcb",d:"M235.228,365.299c-32.29-36.09-89.98-73-179.74-36.49c-1.979,0.805-3.787,1.834-5.413,3.042 c-10.569,7.856-25.473,5.765-32.82-5.164c-0.223-0.331-0.445-0.664-0.667-0.997c-8.59-12.91-3.17-30.51,11.19-36.36 C155.168,237.509,217.948,333.56,235.228,365.299z"}),b.createElement("path",{fill:"#ffa4b8",d:"M239.998,374.549c-12.85-2.2-214.54-23.33-193.03-240.71c1.49-14.99,15.86-25.15,30.48-21.55 c108.49,26.72,149.07,91.39,162.55,149.92C252.768,317.699,241.178,367.679,239.998,374.549z"}),b.createElement("path",{fill:"#ffbfcb",d:"M193.698,174.638c11.866,12.406-3.013,31.792-18.056,23.52 c-21.875-12.028-50.044-10.573-70.207,3.701c-24.832,17.579-59.398-0.365-60.013-30.784c-0.237-11.724,0.248-24.123,1.545-37.237 c1.49-14.99,15.86-25.15,30.48-21.55C131.23,125.537,168.324,148.11,193.698,174.638z"}),b.createElement("path",{fill:"#ffa4b8",d:"M221.538,39.599c9.78-11.13,27.15-11.12,36.93,0.01c157.02,178.77-7.48,323.95-18.47,334.94 C229.988,364.549,63.948,218.989,221.538,39.599z"}),b.createElement("path",{fill:"#ffbfcb",d:"M261.523,43.131c9.452,11.033,8.166,27.623-2.74,37.221c-0.784,0.69-1.535,1.439-2.245,2.247 c-35.942,40.915-55.05,80.07-63.012,116.258c-5.176,23.523-39.936,19.717-39.551-4.366c0.741-46.282,18.411-98.941,67.563-154.892 c9.78-11.13,27.15-11.12,36.93,0.01C259.5,40.785,260.518,41.959,261.523,43.131z"}),b.createElement("path",{fill:"#ffa4b8",d:"M239.998,374.549c-1.18-6.87-12.77-56.85,0-112.34c13.48-58.53,54.06-123.2,162.55-149.92 c14.62-3.6,28.99,6.56,30.48,21.55C454.538,351.219,252.848,372.349,239.998,374.549z"}),b.createElement("path",{fill:"#ff8ca5",d:"M239.998,374.549c-3.115-0.536-17.362-2.183-36.835-7.483c-3.181-0.866-6.028-2.682-8.145-5.209 c-49.098-58.608-75.675-130.75-61.047-205.793c2.165-11.107,14.881-16.444,24.408-10.337c0.756,0.485,1.506,0.972,2.249,1.462 C126.798,274.139,232.088,366.649,239.998,374.549z"}),b.createElement("path",{fill:"#ff8ca5",d:"M281.608,365.729c-21.9,6.37-38.24,8.25-41.61,8.82c8.67-8.67,112.98-100.94,79.35-227.34v-0.01 c0.742-0.489,1.49-0.975,2.244-1.459c9.551-6.123,22.265-0.733,24.422,10.406C369.565,277.734,281.608,363.204,281.608,365.729z"}),b.createElement("path",{fill:"#ff8ca5",d:"M417.451,302.932c-32.211,44.193-80.706,72.823-134.571,87.345c-3.396,0.916-6.999,0.754-10.3-0.463 c-20.772-7.664-31.911-15.254-32.583-15.254c0.826-0.825,112.667-9.463,166.4-98.31C419.37,278.279,424.743,292.927,417.451,302.932 z"}),b.createElement("path",{fill:"#ff8ca5",d:"M62.565,302.932c32.211,44.193,80.705,72.823,134.571,87.345c3.396,0.916,6.999,0.754,10.3-0.463 c20.772-7.664,31.911-15.254,32.583-15.254c-0.828-0.828-112.665-9.458-166.4-98.31C60.646,278.279,55.273,292.927,62.565,302.932z"}),b.createElement("path",{fill:"#9ceb63",d:"M433.464,393.091c-52.749,39.415-118.979,42.09-182.861,13.657 c-4.441-1.977-7.606-6.011-8.633-10.763c-1.552-7.18-1.884-14.238-1.973-21.326c0.172-0.345,9.566,5.934,26.76,12.89 c36.31,14.71,102.75,30.15,161.74-21.33C440.977,369.752,443.403,385.664,433.464,393.091z"}),b.createElement("path",{fill:"#9ceb63",d:"M240.038,374.579c0,0.01-0.01,0.01-0.01,0.02s-0.01,0.03-0.01,0.05c0,0,0,0,0,0.01 c-0.01,0.03-0.01,0.06-0.02,0.1v0.04c-0.13,1.3,0.09,7.59-0.92,15.16c-0.01,0.04-0.01,0.08-0.02,0.12 c-0.26,1.91-0.59,3.91-1.03,5.92c-0.07,0.33-0.15,0.65-0.25,0.97c-1.23,4.33-4.28,7.95-8.41,9.79 c-63.06,28.05-129.47,26.21-182.79-13.63c-9.94-7.43-7.63-23.36,4.92-26.91c13.1,11.46,28.11,20.79,44.16,26.79 c19.78,7.48,34.99,8.98,53.83,8.68c34.33-0.55,60.1-11.03,90.51-27.13C240.008,374.56,240.018,374.569,240.038,374.579z"}),b.createElement("path",{d:"M443.143,363.426c9.579-9.648,18.604-20.804,26.926-33.305c11.399-17.132,4.201-40.447-14.837-48.202 c-12.321-5.012-24.515-8.844-36.391-11.454c17.945-34.197,27.974-78.94,22.188-137.413c-1.925-19.503-20.802-33.354-40.394-28.53 c-17.952,4.421-34.806,10.063-50.093,16.768c-4.046,1.775-5.888,6.494-4.113,10.54c1.774,4.046,6.493,5.887,10.54,4.113 c14.45-6.338,30.429-11.682,47.492-15.885c9.885-2.435,19.599,4.434,20.607,14.573c9.088,90.121-21.147,164.341-99.823,205.213 c-3.921,2.037-5.448,6.866-3.411,10.787c2.043,3.933,6.879,5.442,10.787,3.411c27.191-14.125,56.267-35.849,77.701-68.994 c12.564,2.375,25.617,6.296,38.878,11.69c9.68,3.943,13.334,15.824,7.549,24.518c-10.205,15.33-21.482,28.43-33.516,38.936 c-49.396,43.107-111.979,41.39-169.834,12.419c56.638-56.971,92.247-132.34,77.074-212.524 c-8.101-42.81-30.305-85.119-65.997-125.754c-12.964-14.759-36.003-14.748-48.946-0.016 c-28.645,32.607-48.657,66.371-59.602,100.512c-21.999-13.018-47.7-23.197-76.569-30.307c-19.338-4.763-38.383,8.699-40.354,28.53 C26.197,262.501,90.89,324.677,147.416,354.042c3.92,2.036,8.75,0.51,10.787-3.411c2.037-3.921,0.51-8.75-3.411-10.787 c-52.141-27.086-111.791-84.677-99.863-205.213c1.007-10.132,10.713-17.01,20.606-14.574c31.115,7.663,58.223,19.013,80.571,33.735 c4.863,3.204,10.891,0.586,12.257-4.539c9.392-35.245,29.306-70.362,59.188-104.378c6.581-7.492,18.316-7.487,24.904,0.014 c128.735,146.565,37.449,269.122-12.476,318.519c-30.274-29.828-76.759-87.727-78.002-162.831 c-0.073-4.417-3.698-7.933-8.131-7.867c-4.417,0.073-7.939,3.714-7.867,8.131c1.382,83.483,54.096,146.516,85.999,177.099 c-0.353,20.737-7.099,36.575-20.104,47.086c-20.129,16.267-55.786,20.072-97.831,10.438c-19.181-4.396-48.632-19.874-85.688-1.511 c-5.361,2.657-11.689-0.859-12.186-6.844c-1.888-22.74,12.042-43.926,33.548-51.893c13.4,11.096,27.797,19.551,43.11,25.275 c20.238,7.653,36.036,9.525,56.788,9.196c15.85-0.254,30.814-2.572,45.747-7.085c4.229-1.278,6.622-5.743,5.343-9.972 c-1.278-4.229-5.744-6.622-9.972-5.344c-13.494,4.078-27.027,6.173-41.373,6.403c-17.347,0.275-31.911-0.993-50.901-8.174 c-31.69-11.847-56.387-35.98-75.211-64.258c-5.791-8.704-2.122-20.58,7.548-24.52c4.092-1.667,6.058-6.335,4.391-10.427 c-1.667-4.092-6.334-6.058-10.427-4.391c-19.062,7.765-26.214,31.095-14.832,48.202c8.365,12.566,17.352,23.674,26.917,33.31 C12.89,375.664-2.037,401.187,0.226,428.434c1.427,17.192,19.743,27.533,35.235,19.857c30.84-15.283,54.311-1.971,75.01,2.771 c36.708,8.411,82.166,10.086,111.461-13.59c14.777-11.943,23.305-28.715,25.489-49.937 c61.607,30.736,128.694,32.482,182.835-12.326c21.516,7.959,35.456,29.153,33.567,51.902c-0.493,5.939-6.786,9.519-12.186,6.844 c-30.339-15.034-55.535-7.379-73.932-1.791c-31.306,9.51-74.736,14.144-102.884-2.498c-3.803-2.248-8.709-0.989-10.958,2.815 c-2.249,3.803-0.989,8.709,2.815,10.958c29.214,17.272,69.817,15.19,102.844,7.622c20.72-4.747,44.177-18.05,75.01-2.771 c15.523,7.691,33.811-2.693,35.235-19.856C482.032,401.183,467.102,375.655,443.143,363.426z"})),pe={sm:32,md:48,lg:64};function ge({size:e="md",variant:a="light",className:p="",style:E={}}){const w=pe[e],l={display:"inline-block",cursor:"pointer",transition:"all 250ms ease",borderRadius:"50%",...a==="dark"&&{backgroundColor:"rgba(255, 255, 255, 0.05)",padding:"8px"},...E};return B.jsx("a",{href:"https://getbodhi.app",target:"_blank",rel:"noopener noreferrer",title:"Powered by Bodhi","aria-label":"Powered by Bodhi - Visit getbodhi.app",className:p,style:l,onMouseEnter:d=>{d.currentTarget.style.transform="scale(1.1)",d.currentTarget.style.boxShadow="0 0 20px rgba(255, 164, 184, 0.6)"},onMouseLeave:d=>{d.currentTarget.style.transform="scale(1)",d.currentTarget.style.boxShadow="none"},children:B.jsx(fe,{width:w,height:w,style:{display:"block"}})})}const he="production";Object.defineProperty(exports,"BodhiApiError",{enumerable:!0,get:()=>s.BodhiApiError});Object.defineProperty(exports,"BodhiError",{enumerable:!0,get:()=>s.BodhiError});Object.defineProperty(exports,"InMemoryStorage",{enumerable:!0,get:()=>s.InMemoryStorage});Object.defineProperty(exports,"LoginOptionsBuilder",{enumerable:!0,get:()=>s.LoginOptionsBuilder});Object.defineProperty(exports,"createApiError",{enumerable:!0,get:()=>s.createApiError});Object.defineProperty(exports,"createOperationError",{enumerable:!0,get:()=>s.createOperationError});Object.defineProperty(exports,"isAuthError",{enumerable:!0,get:()=>s.isAuthError});Object.defineProperty(exports,"isAuthLoading",{enumerable:!0,get:()=>s.isAuthLoading});Object.defineProperty(exports,"isAuthenticated",{enumerable:!0,get:()=>s.isAuthenticated});Object.defineProperty(exports,"isClientReady",{enumerable:!0,get:()=>s.isClientReady});Object.defineProperty(exports,"isDirectState",{enumerable:!0,get:()=>s.isDirectState});Object.defineProperty(exports,"isExtensionState",{enumerable:!0,get:()=>s.isExtensionState});Object.defineProperty(exports,"isWebUIClient",{enumerable:!0,get:()=>s.isWebUIClient});Object.defineProperty(exports,"unwrapResponse",{enumerable:!0,get:()=>s.unwrapResponse});exports.BodhiBadge=ge;exports.BodhiProvider=le;exports.BodhiReactContext=G;exports.ClientCtxState=ue;exports.INITIALIZING_CLIENT_CONTEXT_STATE=X;exports.INITIAL_CLIENT_CONTEXT_STATE=J;exports.REACT_CORE_BUILD_MODE=he;exports.clientStateToContextState=Q;exports.isClientCtxInitialized=Z;exports.isClientCtxInitializing=H;exports.isClientCtxNotInitialized=Y;exports.isClientCtxReady=V;exports.isOverallReady=$;exports.useBodhi=de;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),s=require("@bodhiapp/bodhi-js-core"),r=require("react"),L=require("@bodhiapp/setup-modal-types");function ne(e){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const S in e)if(S!=="default"){const C=Object.getOwnPropertyDescriptor(e,S);Object.defineProperty(a,S,C.get?C:{enumerable:!0,get:()=>e[S]})}}return a.default=e,Object.freeze(a)}const h=ne(r);function B(e){return e.replace(/\/+$/,"")}function se({client:e,modalHtmlPath:a,hideSetup:S,onSetupReady:C,setupState:w,basePath:p="/",logLevel:l="warn"}){const R=w!=="ready",_=r.useMemo(()=>new s.Logger("SetupModalProcessor",l),[l]),d=r.useRef(null),m=r.useMemo(()=>new s.BodhiClientUserPrefsManager(s.createStoragePrefixWithNamespace(p,"bodhijs:")),[p]),f=r.useRef(null),y=r.useCallback(t=>t==="direct"?"lna":t==="extension"?"extension":null,[]),A=r.useCallback(t=>t.extension==="ready"?{status:"ready",version:"unknown",id:t.extensionId}:t.extension==="not-found"?{status:"not-installed",error:{message:"Extension not found",code:"ext-not-installed"}}:{status:"unreachable",error:{message:"Client not initialized",code:"ext-connection-failed"}},[]),O=r.useCallback(t=>{if(t.server.status==="pending-extension-ready")return{status:"pending-extension-ready",error:{message:"Extension not ready",code:"server-pending-ext-ready"}};const n=t.server;switch(n.status){case"ready":return{status:"ready",version:n.version||"unknown"};case"setup":return{status:"setup",version:n.version||"unknown",error:{message:n.error?.message||"Setup required",code:"server-in-setup-status"}};case"resource_admin":return{status:"resource_admin",version:n.version||"unknown",error:{message:n.error?.message||"Resource admin required",code:"server-in-admin-status"}};case"error":return{status:"error",error:{message:n.error?.message||"Unknown error",code:"server-unexpected-error"}};case"not-reachable":return{status:"unreachable",error:{message:n.error?.message||"Server not reachable",code:"server-conn-refused"}};default:return{status:"unreachable",error:{message:"Unknown server status",code:"server-unexpected-error"}}}},[]),x=r.useCallback(t=>{if(t.server.status==="not-connected")return{status:"pending-lna-ready"};const n=t.server;switch(n.status){case"ready":return{status:"ready",version:n.version||"unknown"};case"setup":return{status:"setup",version:n.version||"unknown"};case"resource_admin":return{status:"resource_admin",version:n.version||"unknown"};case"error":case"not-reachable":return{status:"error",error:{message:n.error?.message||"Connection error"}};default:return{status:"error",error:{message:"Unknown server status"}}}},[]),T=r.useCallback((t,n)=>{if(t.server.status!=="pending-extension-ready"){const o=t.server.status;if(o==="ready"||o==="setup"||o==="resource_admin")return!0}if(n.server.status!=="not-connected"){const o=n.server.status;if(o==="ready"||o==="setup"||o==="resource_admin")return!0}return!1},[]),M=r.useCallback((t,n,o)=>{if(n==="skipped")return{status:"skipped",serverUrl:o};if(t.server.status!=="not-connected"){const u=t.server;return u.status==="ready"||u.status==="setup"||u.status==="resource_admin"?{status:"granted",serverUrl:o}:{status:"unreachable",serverUrl:o,error:{message:u.error?.message||"Server unreachable",code:"lna-unreachable"}}}return n==="granted"?{status:"granted",serverUrl:o}:{status:"prompt",serverUrl:o}},[]),b=r.useCallback(async(t=!1)=>{const n=s.detectBrowser().type,o=s.detectOS().type;let u=await e.getExtensionState();(u.extension==="not-initialized"||t)&&(u=await e.testExtensionConnectivity());let E=await e.getDirectState();const I=m.getDirectStatus();I==="granted"&&(E.server.status==="not-connected"||t)&&(E=await e.testDirectConnectivity());const N=s.getServerUrl(E)||"http://localhost:1135",j=M(E,I,N);return e.getConnectionMode()===null&&(s.isDirectServerReady(E)?await e.setConnectionMode("direct"):s.isExtensionServerReady(u)&&await e.setConnectionMode("extension")),m.isServerInstallConfirmed()||T(u,E)&&m.setServerInstallConfirmed(!0),{extension:A(u),server:O(u),lna:j,lnaServer:x(E),env:{browser:n,os:o},browsers:s.BROWSER_CONFIGS,os:s.OS_CONFIGS,userConfirmations:{serverInstall:m.isServerInstallConfirmed()},selectedConnection:y(e.getConnectionMode())}},[e,m,A,O,x,y,M,T]),v=r.useCallback(()=>{if(!f.current)throw new Error("Cannot get state: currentStateRef is null");return{...f.current,userConfirmations:{serverInstall:m.isServerInstallConfirmed()},selectedConnection:y(e.getConnectionMode())}},[m,e,y]),c=r.useMemo(()=>({[L.MSG.MODAL_READY]:async()=>(_.info("MODAL_READY: returning current state or default"),f.current?{setupState:v()}:{setupState:L.DEFAULT_SETUP_STATE}),[L.MSG.MODAL_REFRESH]:async()=>{_.info("MODAL_REFRESH: refreshing state");const t=await b(!0);f.current=t;const n=v();return _.info(`MODAL_REFRESH: state refreshed
|
|
2
|
+
`,JSON.stringify(n,null,2)),d.current?.updateState(v()),{setupState:n}},[L.MSG.MODAL_LNA_CONNECT]:async t=>{const n=B(t.payload.serverUrl);console.log("[SetupModalProcessor] LNA connect:",n);const o=await e.testDirectConnectivity(n);if(o.server.status!=="not-connected"){const E=o.server.status;if(E==="ready"||E==="setup"||E==="resource_admin"){m.setDirectStatus("granted"),e.getConnectionMode()===null&&await e.setConnectionMode("direct");const I=await b();return f.current=I,d.current?.updateState(v()),{success:!0}}}const u=await b();return f.current=u,d.current?.updateState(v()),{success:!1}},[L.MSG.MODAL_LNA_SKIP]:async()=>{m.setDirectStatus("skipped");const t=await b();return f.current=t,d.current?.updateState(v()),{success:!0}},[L.MSG.MODAL_CLOSE]:()=>{S()},[L.MSG.MODAL_COMPLETE]:()=>{S()},[L.MSG.MODAL_CONFIRM_SERVER_INSTALL]:t=>(m.setServerInstallConfirmed(t.payload.confirmed),d.current?.updateState(v()),{success:!0}),[L.MSG.MODAL_SELECT_CONNECTION]:async t=>{const o=t.payload.connection==="lna"?"direct":"extension";return await e.setConnectionMode(o),d.current?.updateState(v()),{success:!0}}}),[_,e,m,b,v,x,S]);return r.useEffect(()=>(d.current=new s.OnboardingModal({modalHtmlPath:a,handlers:c}),()=>{d.current?.destroy(),d.current=null}),[a,c]),r.useEffect(()=>{R&&d.current?(d.current.showLoading(),b(!0).then(t=>{f.current=t,d.current?.updateState(t),C?.()}).catch(t=>{console.error("[SetupModalProcessor] buildSetupState failed:",t)})):!R&&d.current&&d.current.destroy()},[R,b,C]),null}const ae="http://localhost:1135",U={MODAL_READY:"modal:ready",MODAL_PROBE:"modal:probe",MODAL_COMPLETE:"modal:complete",MODAL_CLOSE:"modal:close"},oe=130,ce=143;function ie(e=navigator.userAgent){const a=e.toLowerCase(),S=a.match(/edg\/(\d+)/);if(S){const l=parseInt(S[1],10);return{name:"edge",version:l,supported:l>=ce}}const C=a.match(/chrome\/(\d+)/);if(C&&!a.includes("edg/")){const l=parseInt(C[1],10);return{name:"chrome",version:l,supported:l>=oe}}const w=a.match(/firefox\/(\d+)/);if(w)return{name:"firefox",version:parseInt(w[1],10),supported:!1};const p=a.match(/version\/(\d+).*safari/);return p&&!a.includes("chrome/")?{name:"safari",version:parseInt(p[1],10),supported:!1}:{name:"unknown",version:0,supported:!1}}function ue({client:e,modalHtmlPath:a,hideSetup:S,onSetupReady:C,setupState:w,basePath:p="/",logLevel:l="warn",autoProbe:R=!0,defaultHost:_}){const d=w!=="ready",m=r.useMemo(()=>new s.Logger("SetupModalV2Processor",l),[l]),f=r.useRef(null),y=r.useRef(null),A=r.useMemo(()=>new s.BodhiClientUserPrefsManager(s.createStoragePrefixWithNamespace(p,"bodhijs:")),[p]),O=r.useMemo(()=>`${s.createStoragePrefixWithNamespace(p,"bodhijs:")}setup-v2.connection`,[p]),x=r.useCallback(()=>{try{const c=localStorage.getItem(O);if(!c)return null;const t=JSON.parse(c);return typeof t?.serverUrl=="string"?t:null}catch{return null}},[O]),T=r.useCallback(c=>{try{localStorage.setItem(O,JSON.stringify({serverUrl:B(c),lastProbedAt:Date.now()}))}catch{}},[O]),M=r.useCallback(async c=>{const t=B(c),n=ie(),o=await e.testDirectConnectivity(t),u=o.server.status;return u==="ready"?(T(t),A.setDirectStatus("granted"),e.getConnectionMode()===null&&await e.setConnectionMode("direct"),{serverUrl:t,browser:n,probeStatus:"connected",serverStatus:"ready"}):u==="setup"||u==="resource_admin"?{serverUrl:t,browser:n,probeStatus:"not-ready",serverStatus:u}:u==="error"?{serverUrl:t,browser:n,probeStatus:"error",serverStatus:"error",error:o.server.error?{code:"server-error",message:o.server.error.message}:void 0}:{serverUrl:t,browser:n,probeStatus:"network-error",serverStatus:"unreachable",error:o.server.error?{code:"network-error",message:o.server.error.message}:void 0}},[e,A,T]),b=r.useCallback(async()=>{const t=x()?.serverUrl??_??ae;return M(t)},[M,x,_]),v=r.useMemo(()=>({[U.MODAL_READY]:async()=>{if(y.current)return{setupState:y.current};const c=await b();return y.current=c,{setupState:c}},[U.MODAL_PROBE]:async c=>{const t=await M(c.payload.serverUrl);return y.current=t,f.current?.updateState(t),{setupState:t}},[U.MODAL_COMPLETE]:()=>{S()},[U.MODAL_CLOSE]:()=>{S()}}),[b,M,S]);return r.useEffect(()=>(f.current=new s.OnboardingModalV2({modalHtmlPath:a,handlers:v}),()=>{f.current?.destroy(),f.current=null}),[a,v]),r.useEffect(()=>{R&&b().then(c=>{y.current=c,m.info("Auto-probe complete:",c.probeStatus)}).catch(c=>{m.error("Auto-probe failed:",c)})},[R,b,m]),r.useEffect(()=>{let c=!1;return d&&f.current?(f.current.showLoading(),y.current?(f.current.updateState(y.current),C?.()):b().then(t=>{c||(y.current=t,f.current?.updateState(t),C?.())}).catch(t=>{c||m.error("buildInitialState failed:",t)})):!d&&f.current&&f.current.destroy(),()=>{c=!0}},[d,b,C,m]),null}const X={status:"not-initialized",mode:null,extensionId:null,url:null,server:s.BACKEND_SERVER_NOT_CONNECTED,error:null},Y={status:"initializing",mode:null,extensionId:null,url:null,server:s.BACKEND_SERVER_NOT_CONNECTED,error:null};function $(e){return e.status==="not-initialized"}function H(e){return e.status==="initializing"}function Z(e){return e.status!=="not-initialized"&&e.status!=="initializing"}function q(e){return e.status==="ready"}function Q(e){return q(e)&&e.server.status==="ready"}function ee(e){return s.isExtensionState(e)?{status:e.extension==="not-initialized"?"initializing":e.extension==="not-found"?"extension-not-found":"ready",mode:"extension",extensionId:e.extensionId,url:null,server:e.server,error:e.server.error}:{status:e.url===null||e.server.status==="not-reachable"||e.server.status==="not-connected"?"direct-not-connected":"ready",mode:"direct",extensionId:null,url:e.url,server:e.server,error:e.server.error}}const le={isNotInitialized:$,isInitializing:H,isInitialized:Z,isReady:q,isOverallReady:Q},G=r.createContext(null);G.displayName="BodhiContext";function de({children:e,client:a,modalHtmlPath:S,handleCallback:C=!0,callbackPath:w,basePath:p="/",logLevel:l="warn",setupModal:R="setup-modal-v2",autoProbe:_=!0,defaultHost:d}){const m=p==="/"?"":p.replace(/\/$/,""),f=w??`${m}/callback`,y=r.useMemo(()=>d?B(d):void 0,[d]),A=r.useMemo(()=>new s.Logger("BodhiProvider",l),[l]),O=r.useRef(!1),x=r.useRef(!1),T=r.useRef(!1),[M,b]=r.useState(X),[v,c]=r.useState(s.INITIAL_AUTH_STATE),[t,n]=r.useState(!1),[o,u]=r.useState("ready"),E=r.useCallback((g,i)=>{x.current=!0,c({status:"error",user:null,accessToken:null,error:{code:g,message:i},refreshToken:null,expiresAt:null,isTokenRefresh:!1}),n(!1)},[]),I=r.useCallback(()=>{x.current=!1},[]);r.useEffect(()=>{const g=i=>{switch(i.type){case"client-state":b(ee(i.state));break;case"auth-state":x.current||(c(i.state),n(!1));break}};return a.setStateCallback(g),()=>{a.setStateCallback(s.NOOP_STATE_CALLBACK)}},[a]);const V=r.useCallback(async()=>{u("loading")},[]),N=r.useCallback(()=>{u("ready")},[]),j=r.useCallback(()=>{u("loaded")},[]),F=r.useCallback(async g=>{b(Y);try{await a.init(g||{})}catch(i){A.error("Init failed:",i)}},[a,A]);r.useEffect(()=>{if(T.current)return;T.current=!0,(async()=>{if(await F(),!C)return;const i=new URL(window.location.href);if(i.pathname!==f||O.current||!s.isWebUIClient(a))return;const k=i.searchParams.get("error");if(k){O.current=!0;const D=i.searchParams.get("error_source")==="bodhi"&&k==="access_denied";E(D?"access_request_denied":k,i.searchParams.get("error_description")??k),window.history.replaceState({},"",p);return}const z=i.searchParams.get("code"),J=i.searchParams.get("state");if(!(!z||!J)){O.current=!0,n(!0);try{await a.handleOAuthCallback(z,J),window.history.replaceState({},"",p)}catch(D){A.error("OAuth callback failed:",D);const re=D instanceof s.BodhiError?D:null;E(re?.code??"oauth_callback_failed",D instanceof Error?D.message:"OAuth callback failed"),window.history.replaceState({},"",p)}}})()},[F,a,C,f,p]);const W=r.useCallback(async g=>{I(),n(!0);try{const i=g?{...g.userRole&&{userRole:g.userRole},...g.requested&&{requested:g.requested},...g.onProgress&&{onProgress:g.onProgress}}:void 0,k=i&&Object.keys(i).length>0?i:void 0;await a.login(k)}catch(i){const k=i instanceof s.BodhiError?i:null,z={status:"error",user:null,accessToken:null,error:{message:i instanceof Error?i.message:"Login failed",code:k?.code??"login_failed"},refreshToken:null,expiresAt:null,isTokenRefresh:!1};return c(z),n(!1),z}},[a,I]),K=r.useCallback(async()=>{I();try{await a.logout()}catch(g){E("logout_failed",g instanceof Error?g.message:"Logout failed")}},[a,E,I]),te=r.useMemo(()=>{const g=M.status==="ready",i=M.server.status==="ready";return{client:a,clientState:M,auth:v,isAuthLoading:t,login:W,logout:K,showSetup:V,hideSetup:N,setupState:o,isAuthenticated:v.status==="authenticated",canLogin:g&&!t,isReady:g,isServerReady:i,isOverallReady:g&&i,isInitializing:M.status==="initializing",isExtension:M.mode==="extension",isDirect:M.mode==="direct"}},[a,M,v,t,o,W,K,V,N]);return P.jsxs(G.Provider,{value:te,children:[R==="setup-modal"?P.jsx(se,{client:a,modalHtmlPath:S,hideSetup:N,onSetupReady:j,setupState:o,basePath:p,logLevel:l,autoProbe:_}):P.jsx(ue,{client:a,modalHtmlPath:S,hideSetup:N,onSetupReady:j,setupState:o,basePath:p,logLevel:l,autoProbe:_,defaultHost:y}),e]})}function fe(){const e=r.useContext(G);if(!e)throw new Error("useBodhi must be used within BodhiProvider");return e}const pe=e=>h.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 479.995 479.995",width:"480px",height:"480px",...e},h.createElement("path",{fill:"#ffa4b8",d:"M239.998,374.56l-0.01-0.01c0-0.01,0.01-0.01,0.01-0.02c-4.64-8.78-65.7-144.8-212.22-85.2 c-14.36,5.85-19.78,23.45-11.19,36.36c11.11,16.69,22.86,30.01,34.91,40.53c-27.85,7.89-45.6,33.8-43.3,61.55 c0.96,11.6,13.29,18.52,23.71,13.35c33.99-16.84,60.03-2.51,80.35,2.14c56.68,12.99,113.71,4.53,125.52-46.29 c0.52-2.22,0.95-4.51,1.28-6.89c0.01-0.04,0.01-0.08,0.02-0.12c0.066-0.492,0.126-0.978,0.181-1.458 c0.455-3.631,0.712-7.438,0.739-11.452c-0.02-1.44-0.02-2.01,0-2.25v-0.09c0-0.02,0-0.04,0.01-0.05c0-0.02,0.01-0.03,0.02-0.06 c0-0.01,0.01-0.01,0.01-0.02C240.018,374.569,240.008,374.56,239.998,374.56z"}),h.createElement("path",{fill:"#ffa4b8",d:"M471.798,427.769c-0.96,11.6-13.29,18.52-23.71,13.35c-33.99-16.84-60.03-2.51-80.35,2.14 c-63.41,14.53-127.25,2.22-127.74-66.21c0.033-2.642-0.044-2.302,0.04-2.47c-0.02-0.01-0.03-0.02-0.04-0.02l0.01-0.01 c0-0.01-0.01-0.01-0.01-0.02c4.64-8.78,65.7-144.8,212.22-85.2c14.36,5.85,19.78,23.45,11.19,36.36 c-11.11,16.69-22.86,30.01-34.91,40.53C456.348,374.109,474.098,400.019,471.798,427.769z"}),h.createElement("path",{fill:"#befa91",d:"M428.498,366.219c27.85,7.89,45.6,33.8,43.3,61.55c-0.96,11.6-13.29,18.52-23.71,13.35 c-33.99-16.84-60.03-2.51-80.35,2.14c-63.41,14.53-127.928,2.222-127.74-66.21c0.007-2.683-0.02-2.351,0.04-2.47 C248.598,379.129,345.858,438.329,428.498,366.219z"}),h.createElement("path",{fill:"#befa91",d:"M51.498,366.219c82.76,72.22,180.18,12.74,188.5,8.34c0.01,0,0.02,0.01,0.04,0.02 c-0.058,0.116-0.047-0.169-0.04,2.47c0.188,68.432-64.33,80.74-127.74,66.21c-20.32-4.65-46.36-18.98-80.35-2.14 c-10.42,5.17-22.75-1.75-23.71-13.35C5.898,400.019,23.648,374.109,51.498,366.219z"}),h.createElement("path",{fill:"#ffbfcb",d:"M235.228,365.299c-32.29-36.09-89.98-73-179.74-36.49c-1.979,0.805-3.787,1.834-5.413,3.042 c-10.569,7.856-25.473,5.765-32.82-5.164c-0.223-0.331-0.445-0.664-0.667-0.997c-8.59-12.91-3.17-30.51,11.19-36.36 C155.168,237.509,217.948,333.56,235.228,365.299z"}),h.createElement("path",{fill:"#ffa4b8",d:"M239.998,374.549c-12.85-2.2-214.54-23.33-193.03-240.71c1.49-14.99,15.86-25.15,30.48-21.55 c108.49,26.72,149.07,91.39,162.55,149.92C252.768,317.699,241.178,367.679,239.998,374.549z"}),h.createElement("path",{fill:"#ffbfcb",d:"M193.698,174.638c11.866,12.406-3.013,31.792-18.056,23.52 c-21.875-12.028-50.044-10.573-70.207,3.701c-24.832,17.579-59.398-0.365-60.013-30.784c-0.237-11.724,0.248-24.123,1.545-37.237 c1.49-14.99,15.86-25.15,30.48-21.55C131.23,125.537,168.324,148.11,193.698,174.638z"}),h.createElement("path",{fill:"#ffa4b8",d:"M221.538,39.599c9.78-11.13,27.15-11.12,36.93,0.01c157.02,178.77-7.48,323.95-18.47,334.94 C229.988,364.549,63.948,218.989,221.538,39.599z"}),h.createElement("path",{fill:"#ffbfcb",d:"M261.523,43.131c9.452,11.033,8.166,27.623-2.74,37.221c-0.784,0.69-1.535,1.439-2.245,2.247 c-35.942,40.915-55.05,80.07-63.012,116.258c-5.176,23.523-39.936,19.717-39.551-4.366c0.741-46.282,18.411-98.941,67.563-154.892 c9.78-11.13,27.15-11.12,36.93,0.01C259.5,40.785,260.518,41.959,261.523,43.131z"}),h.createElement("path",{fill:"#ffa4b8",d:"M239.998,374.549c-1.18-6.87-12.77-56.85,0-112.34c13.48-58.53,54.06-123.2,162.55-149.92 c14.62-3.6,28.99,6.56,30.48,21.55C454.538,351.219,252.848,372.349,239.998,374.549z"}),h.createElement("path",{fill:"#ff8ca5",d:"M239.998,374.549c-3.115-0.536-17.362-2.183-36.835-7.483c-3.181-0.866-6.028-2.682-8.145-5.209 c-49.098-58.608-75.675-130.75-61.047-205.793c2.165-11.107,14.881-16.444,24.408-10.337c0.756,0.485,1.506,0.972,2.249,1.462 C126.798,274.139,232.088,366.649,239.998,374.549z"}),h.createElement("path",{fill:"#ff8ca5",d:"M281.608,365.729c-21.9,6.37-38.24,8.25-41.61,8.82c8.67-8.67,112.98-100.94,79.35-227.34v-0.01 c0.742-0.489,1.49-0.975,2.244-1.459c9.551-6.123,22.265-0.733,24.422,10.406C369.565,277.734,281.608,363.204,281.608,365.729z"}),h.createElement("path",{fill:"#ff8ca5",d:"M417.451,302.932c-32.211,44.193-80.706,72.823-134.571,87.345c-3.396,0.916-6.999,0.754-10.3-0.463 c-20.772-7.664-31.911-15.254-32.583-15.254c0.826-0.825,112.667-9.463,166.4-98.31C419.37,278.279,424.743,292.927,417.451,302.932 z"}),h.createElement("path",{fill:"#ff8ca5",d:"M62.565,302.932c32.211,44.193,80.705,72.823,134.571,87.345c3.396,0.916,6.999,0.754,10.3-0.463 c20.772-7.664,31.911-15.254,32.583-15.254c-0.828-0.828-112.665-9.458-166.4-98.31C60.646,278.279,55.273,292.927,62.565,302.932z"}),h.createElement("path",{fill:"#9ceb63",d:"M433.464,393.091c-52.749,39.415-118.979,42.09-182.861,13.657 c-4.441-1.977-7.606-6.011-8.633-10.763c-1.552-7.18-1.884-14.238-1.973-21.326c0.172-0.345,9.566,5.934,26.76,12.89 c36.31,14.71,102.75,30.15,161.74-21.33C440.977,369.752,443.403,385.664,433.464,393.091z"}),h.createElement("path",{fill:"#9ceb63",d:"M240.038,374.579c0,0.01-0.01,0.01-0.01,0.02s-0.01,0.03-0.01,0.05c0,0,0,0,0,0.01 c-0.01,0.03-0.01,0.06-0.02,0.1v0.04c-0.13,1.3,0.09,7.59-0.92,15.16c-0.01,0.04-0.01,0.08-0.02,0.12 c-0.26,1.91-0.59,3.91-1.03,5.92c-0.07,0.33-0.15,0.65-0.25,0.97c-1.23,4.33-4.28,7.95-8.41,9.79 c-63.06,28.05-129.47,26.21-182.79-13.63c-9.94-7.43-7.63-23.36,4.92-26.91c13.1,11.46,28.11,20.79,44.16,26.79 c19.78,7.48,34.99,8.98,53.83,8.68c34.33-0.55,60.1-11.03,90.51-27.13C240.008,374.56,240.018,374.569,240.038,374.579z"}),h.createElement("path",{d:"M443.143,363.426c9.579-9.648,18.604-20.804,26.926-33.305c11.399-17.132,4.201-40.447-14.837-48.202 c-12.321-5.012-24.515-8.844-36.391-11.454c17.945-34.197,27.974-78.94,22.188-137.413c-1.925-19.503-20.802-33.354-40.394-28.53 c-17.952,4.421-34.806,10.063-50.093,16.768c-4.046,1.775-5.888,6.494-4.113,10.54c1.774,4.046,6.493,5.887,10.54,4.113 c14.45-6.338,30.429-11.682,47.492-15.885c9.885-2.435,19.599,4.434,20.607,14.573c9.088,90.121-21.147,164.341-99.823,205.213 c-3.921,2.037-5.448,6.866-3.411,10.787c2.043,3.933,6.879,5.442,10.787,3.411c27.191-14.125,56.267-35.849,77.701-68.994 c12.564,2.375,25.617,6.296,38.878,11.69c9.68,3.943,13.334,15.824,7.549,24.518c-10.205,15.33-21.482,28.43-33.516,38.936 c-49.396,43.107-111.979,41.39-169.834,12.419c56.638-56.971,92.247-132.34,77.074-212.524 c-8.101-42.81-30.305-85.119-65.997-125.754c-12.964-14.759-36.003-14.748-48.946-0.016 c-28.645,32.607-48.657,66.371-59.602,100.512c-21.999-13.018-47.7-23.197-76.569-30.307c-19.338-4.763-38.383,8.699-40.354,28.53 C26.197,262.501,90.89,324.677,147.416,354.042c3.92,2.036,8.75,0.51,10.787-3.411c2.037-3.921,0.51-8.75-3.411-10.787 c-52.141-27.086-111.791-84.677-99.863-205.213c1.007-10.132,10.713-17.01,20.606-14.574c31.115,7.663,58.223,19.013,80.571,33.735 c4.863,3.204,10.891,0.586,12.257-4.539c9.392-35.245,29.306-70.362,59.188-104.378c6.581-7.492,18.316-7.487,24.904,0.014 c128.735,146.565,37.449,269.122-12.476,318.519c-30.274-29.828-76.759-87.727-78.002-162.831 c-0.073-4.417-3.698-7.933-8.131-7.867c-4.417,0.073-7.939,3.714-7.867,8.131c1.382,83.483,54.096,146.516,85.999,177.099 c-0.353,20.737-7.099,36.575-20.104,47.086c-20.129,16.267-55.786,20.072-97.831,10.438c-19.181-4.396-48.632-19.874-85.688-1.511 c-5.361,2.657-11.689-0.859-12.186-6.844c-1.888-22.74,12.042-43.926,33.548-51.893c13.4,11.096,27.797,19.551,43.11,25.275 c20.238,7.653,36.036,9.525,56.788,9.196c15.85-0.254,30.814-2.572,45.747-7.085c4.229-1.278,6.622-5.743,5.343-9.972 c-1.278-4.229-5.744-6.622-9.972-5.344c-13.494,4.078-27.027,6.173-41.373,6.403c-17.347,0.275-31.911-0.993-50.901-8.174 c-31.69-11.847-56.387-35.98-75.211-64.258c-5.791-8.704-2.122-20.58,7.548-24.52c4.092-1.667,6.058-6.335,4.391-10.427 c-1.667-4.092-6.334-6.058-10.427-4.391c-19.062,7.765-26.214,31.095-14.832,48.202c8.365,12.566,17.352,23.674,26.917,33.31 C12.89,375.664-2.037,401.187,0.226,428.434c1.427,17.192,19.743,27.533,35.235,19.857c30.84-15.283,54.311-1.971,75.01,2.771 c36.708,8.411,82.166,10.086,111.461-13.59c14.777-11.943,23.305-28.715,25.489-49.937 c61.607,30.736,128.694,32.482,182.835-12.326c21.516,7.959,35.456,29.153,33.567,51.902c-0.493,5.939-6.786,9.519-12.186,6.844 c-30.339-15.034-55.535-7.379-73.932-1.791c-31.306,9.51-74.736,14.144-102.884-2.498c-3.803-2.248-8.709-0.989-10.958,2.815 c-2.249,3.803-0.989,8.709,2.815,10.958c29.214,17.272,69.817,15.19,102.844,7.622c20.72-4.747,44.177-18.05,75.01-2.771 c15.523,7.691,33.811-2.693,35.235-19.856C482.032,401.183,467.102,375.655,443.143,363.426z"})),ge={sm:32,md:48,lg:64};function Se({size:e="md",variant:a="light",className:S="",style:C={}}){const w=ge[e],p={display:"inline-block",cursor:"pointer",transition:"all 250ms ease",borderRadius:"50%",...a==="dark"&&{backgroundColor:"rgba(255, 255, 255, 0.05)",padding:"8px"},...C};return P.jsx("a",{href:"https://getbodhi.app",target:"_blank",rel:"noopener noreferrer",title:"Powered by Bodhi","aria-label":"Powered by Bodhi - Visit getbodhi.app",className:S,style:p,onMouseEnter:l=>{l.currentTarget.style.transform="scale(1.1)",l.currentTarget.style.boxShadow="0 0 20px rgba(255, 164, 184, 0.6)"},onMouseLeave:l=>{l.currentTarget.style.transform="scale(1)",l.currentTarget.style.boxShadow="none"},children:P.jsx(pe,{width:w,height:w,style:{display:"block"}})})}const me="production";Object.defineProperty(exports,"BodhiApiError",{enumerable:!0,get:()=>s.BodhiApiError});Object.defineProperty(exports,"BodhiError",{enumerable:!0,get:()=>s.BodhiError});Object.defineProperty(exports,"InMemoryStorage",{enumerable:!0,get:()=>s.InMemoryStorage});Object.defineProperty(exports,"LoginOptionsBuilder",{enumerable:!0,get:()=>s.LoginOptionsBuilder});Object.defineProperty(exports,"createApiError",{enumerable:!0,get:()=>s.createApiError});Object.defineProperty(exports,"createOperationError",{enumerable:!0,get:()=>s.createOperationError});Object.defineProperty(exports,"isAuthError",{enumerable:!0,get:()=>s.isAuthError});Object.defineProperty(exports,"isAuthLoading",{enumerable:!0,get:()=>s.isAuthLoading});Object.defineProperty(exports,"isAuthenticated",{enumerable:!0,get:()=>s.isAuthenticated});Object.defineProperty(exports,"isClientReady",{enumerable:!0,get:()=>s.isClientReady});Object.defineProperty(exports,"isDirectState",{enumerable:!0,get:()=>s.isDirectState});Object.defineProperty(exports,"isExtensionState",{enumerable:!0,get:()=>s.isExtensionState});Object.defineProperty(exports,"isWebUIClient",{enumerable:!0,get:()=>s.isWebUIClient});Object.defineProperty(exports,"unwrapResponse",{enumerable:!0,get:()=>s.unwrapResponse});exports.BodhiBadge=Se;exports.BodhiProvider=de;exports.BodhiReactContext=G;exports.ClientCtxState=le;exports.INITIALIZING_CLIENT_CONTEXT_STATE=Y;exports.INITIAL_CLIENT_CONTEXT_STATE=X;exports.REACT_CORE_BUILD_MODE=me;exports.clientStateToContextState=ee;exports.isClientCtxInitialized=Z;exports.isClientCtxInitializing=H;exports.isClientCtxNotInitialized=$;exports.isClientCtxReady=q;exports.isOverallReady=Q;exports.normalizeServerUrl=B;exports.useBodhi=fe;
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { Logger as
|
|
3
|
-
import { BodhiApiError as
|
|
4
|
-
import * as
|
|
5
|
-
import { useMemo as
|
|
6
|
-
import { MSG as
|
|
7
|
-
function
|
|
1
|
+
import { jsxs as se, jsx as j } from "react/jsx-runtime";
|
|
2
|
+
import { Logger as K, BodhiClientUserPrefsManager as Q, createStoragePrefixWithNamespace as W, detectBrowser as oe, detectOS as ce, getServerUrl as ae, isDirectServerReady as ie, isExtensionServerReady as ue, OS_CONFIGS as le, BROWSER_CONFIGS as de, OnboardingModal as fe, OnboardingModalV2 as pe, BACKEND_SERVER_NOT_CONNECTED as ee, isExtensionState as he, INITIAL_AUTH_STATE as me, NOOP_STATE_CALLBACK as ge, isWebUIClient as Se, BodhiError as Z } from "@bodhiapp/bodhi-js-core";
|
|
3
|
+
import { BodhiApiError as Ye, BodhiError as $e, InMemoryStorage as He, LoginOptionsBuilder as Je, createApiError as Xe, createOperationError as Ze, isAuthError as Qe, isAuthLoading as er, isAuthenticated as rr, isClientReady as tr, isDirectState as nr, isExtensionState as sr, isWebUIClient as or, unwrapResponse as cr } from "@bodhiapp/bodhi-js-core";
|
|
4
|
+
import * as m from "react";
|
|
5
|
+
import { useMemo as x, useRef as z, useCallback as p, useEffect as N, createContext as ve, useState as V, useContext as Ce } from "react";
|
|
6
|
+
import { MSG as T, DEFAULT_SETUP_STATE as Ee } from "@bodhiapp/setup-modal-types";
|
|
7
|
+
function q(r) {
|
|
8
|
+
return r.replace(/\/+$/, "");
|
|
9
|
+
}
|
|
10
|
+
function ye({
|
|
8
11
|
client: r,
|
|
9
12
|
modalHtmlPath: n,
|
|
10
|
-
hideSetup:
|
|
11
|
-
onSetupReady:
|
|
12
|
-
setupState:
|
|
13
|
-
basePath:
|
|
14
|
-
logLevel:
|
|
13
|
+
hideSetup: C,
|
|
14
|
+
onSetupReady: w,
|
|
15
|
+
setupState: M,
|
|
16
|
+
basePath: d = "/",
|
|
17
|
+
logLevel: i = "warn"
|
|
15
18
|
}) {
|
|
16
|
-
const
|
|
17
|
-
() => new
|
|
18
|
-
[
|
|
19
|
-
), l = z(null),
|
|
19
|
+
const I = M !== "ready", _ = x(() => new K("SetupModalProcessor", i), [i]), u = z(null), h = x(
|
|
20
|
+
() => new Q(W(d, "bodhijs:")),
|
|
21
|
+
[d]
|
|
22
|
+
), l = z(null), E = p(
|
|
20
23
|
(e) => e === "direct" ? "lna" : e === "extension" ? "extension" : null,
|
|
21
24
|
[]
|
|
22
|
-
),
|
|
25
|
+
), O = p((e) => e.extension === "ready" ? {
|
|
23
26
|
status: "ready",
|
|
24
27
|
version: "unknown",
|
|
25
28
|
// TODO: have ExtensionState also get extension version
|
|
@@ -30,7 +33,7 @@ function Ee({
|
|
|
30
33
|
} : {
|
|
31
34
|
status: "unreachable",
|
|
32
35
|
error: { message: "Client not initialized", code: "ext-connection-failed" }
|
|
33
|
-
}, []),
|
|
36
|
+
}, []), b = p((e) => {
|
|
34
37
|
if (e.server.status === "pending-extension-ready")
|
|
35
38
|
return {
|
|
36
39
|
status: "pending-extension-ready",
|
|
@@ -83,7 +86,7 @@ function Ee({
|
|
|
83
86
|
}
|
|
84
87
|
};
|
|
85
88
|
}
|
|
86
|
-
}, []),
|
|
89
|
+
}, []), A = p((e) => {
|
|
87
90
|
if (e.server.status === "not-connected")
|
|
88
91
|
return { status: "pending-lna-ready" };
|
|
89
92
|
const t = e.server;
|
|
@@ -106,290 +109,293 @@ function Ee({
|
|
|
106
109
|
error: { message: "Unknown server status" }
|
|
107
110
|
};
|
|
108
111
|
}
|
|
109
|
-
}, []),
|
|
112
|
+
}, []), R = p(
|
|
110
113
|
(e, t) => {
|
|
111
114
|
if (e.server.status !== "pending-extension-ready") {
|
|
112
|
-
const
|
|
113
|
-
if (
|
|
115
|
+
const s = e.server.status;
|
|
116
|
+
if (s === "ready" || s === "setup" || s === "resource_admin")
|
|
114
117
|
return !0;
|
|
115
118
|
}
|
|
116
119
|
if (t.server.status !== "not-connected") {
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
120
|
+
const s = t.server.status;
|
|
121
|
+
if (s === "ready" || s === "setup" || s === "resource_admin")
|
|
119
122
|
return !0;
|
|
120
123
|
}
|
|
121
124
|
return !1;
|
|
122
125
|
},
|
|
123
126
|
[]
|
|
124
|
-
),
|
|
125
|
-
(e, t,
|
|
127
|
+
), y = p(
|
|
128
|
+
(e, t, s) => {
|
|
126
129
|
if (t === "skipped")
|
|
127
|
-
return { status: "skipped", serverUrl:
|
|
130
|
+
return { status: "skipped", serverUrl: s };
|
|
128
131
|
if (e.server.status !== "not-connected") {
|
|
129
|
-
const
|
|
130
|
-
return
|
|
132
|
+
const a = e.server;
|
|
133
|
+
return a.status === "ready" || a.status === "setup" || a.status === "resource_admin" ? { status: "granted", serverUrl: s } : {
|
|
131
134
|
status: "unreachable",
|
|
132
|
-
serverUrl:
|
|
135
|
+
serverUrl: s,
|
|
133
136
|
error: {
|
|
134
|
-
message:
|
|
137
|
+
message: a.error?.message || "Server unreachable",
|
|
135
138
|
code: "lna-unreachable"
|
|
136
139
|
}
|
|
137
140
|
};
|
|
138
141
|
}
|
|
139
|
-
return t === "granted" ? { status: "granted", serverUrl:
|
|
142
|
+
return t === "granted" ? { status: "granted", serverUrl: s } : { status: "prompt", serverUrl: s };
|
|
140
143
|
},
|
|
141
144
|
[]
|
|
142
|
-
),
|
|
145
|
+
), g = p(
|
|
143
146
|
async (e = !1) => {
|
|
144
|
-
const t =
|
|
145
|
-
let
|
|
146
|
-
(
|
|
147
|
-
let
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
return r.getConnectionMode() === null && (
|
|
152
|
-
extension:
|
|
153
|
-
server:
|
|
154
|
-
lna:
|
|
155
|
-
lnaServer:
|
|
156
|
-
env: { browser: t, os:
|
|
157
|
-
browsers:
|
|
158
|
-
os:
|
|
159
|
-
userConfirmations: { serverInstall:
|
|
160
|
-
selectedConnection:
|
|
147
|
+
const t = oe().type, s = ce().type;
|
|
148
|
+
let a = await r.getExtensionState();
|
|
149
|
+
(a.extension === "not-initialized" || e) && (a = await r.testExtensionConnectivity());
|
|
150
|
+
let v = await r.getDirectState();
|
|
151
|
+
const L = h.getDirectStatus();
|
|
152
|
+
L === "granted" && (v.server.status === "not-connected" || e) && (v = await r.testDirectConnectivity());
|
|
153
|
+
const B = ae(v) || "http://localhost:1135", P = y(v, L, B);
|
|
154
|
+
return r.getConnectionMode() === null && (ie(v) ? await r.setConnectionMode("direct") : ue(a) && await r.setConnectionMode("extension")), h.isServerInstallConfirmed() || R(a, v) && h.setServerInstallConfirmed(!0), {
|
|
155
|
+
extension: O(a),
|
|
156
|
+
server: b(a),
|
|
157
|
+
lna: P,
|
|
158
|
+
lnaServer: A(v),
|
|
159
|
+
env: { browser: t, os: s },
|
|
160
|
+
browsers: de,
|
|
161
|
+
os: le,
|
|
162
|
+
userConfirmations: { serverInstall: h.isServerInstallConfirmed() },
|
|
163
|
+
selectedConnection: E(r.getConnectionMode())
|
|
161
164
|
};
|
|
162
165
|
},
|
|
163
166
|
[
|
|
164
167
|
r,
|
|
165
|
-
p,
|
|
166
|
-
x,
|
|
167
|
-
M,
|
|
168
|
-
O,
|
|
169
168
|
h,
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
O,
|
|
170
|
+
b,
|
|
171
|
+
A,
|
|
172
|
+
E,
|
|
173
|
+
y,
|
|
174
|
+
R
|
|
172
175
|
]
|
|
173
|
-
),
|
|
176
|
+
), S = p(() => {
|
|
174
177
|
if (!l.current)
|
|
175
178
|
throw new Error("Cannot get state: currentStateRef is null");
|
|
176
179
|
return {
|
|
177
180
|
...l.current,
|
|
178
181
|
// Override userConfirmations from storage (in case updated outside buildSetupState)
|
|
179
182
|
userConfirmations: {
|
|
180
|
-
serverInstall:
|
|
183
|
+
serverInstall: h.isServerInstallConfirmed()
|
|
181
184
|
},
|
|
182
185
|
// Override selectedConnection from client (in case changed via handler)
|
|
183
|
-
selectedConnection:
|
|
186
|
+
selectedConnection: E(r.getConnectionMode())
|
|
184
187
|
};
|
|
185
|
-
}, [
|
|
188
|
+
}, [h, r, E]), o = x(
|
|
186
189
|
() => ({
|
|
187
|
-
[
|
|
188
|
-
[
|
|
189
|
-
|
|
190
|
-
const e = await
|
|
190
|
+
[T.MODAL_READY]: async () => (_.info("MODAL_READY: returning current state or default"), l.current ? { setupState: S() } : { setupState: Ee }),
|
|
191
|
+
[T.MODAL_REFRESH]: async () => {
|
|
192
|
+
_.info("MODAL_REFRESH: refreshing state");
|
|
193
|
+
const e = await g(!0);
|
|
191
194
|
l.current = e;
|
|
192
|
-
const t =
|
|
193
|
-
return
|
|
194
|
-
`, JSON.stringify(t, null, 2)),
|
|
195
|
+
const t = S();
|
|
196
|
+
return _.info(`MODAL_REFRESH: state refreshed
|
|
197
|
+
`, JSON.stringify(t, null, 2)), u.current?.updateState(S()), { setupState: t };
|
|
195
198
|
},
|
|
196
|
-
[
|
|
197
|
-
const t = e.payload.serverUrl;
|
|
199
|
+
[T.MODAL_LNA_CONNECT]: async (e) => {
|
|
200
|
+
const t = q(e.payload.serverUrl);
|
|
198
201
|
console.log("[SetupModalProcessor] LNA connect:", t);
|
|
199
|
-
const
|
|
200
|
-
if (
|
|
201
|
-
const
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
return l.current =
|
|
202
|
+
const s = await r.testDirectConnectivity(t);
|
|
203
|
+
if (s.server.status !== "not-connected") {
|
|
204
|
+
const v = s.server.status;
|
|
205
|
+
if (v === "ready" || v === "setup" || v === "resource_admin") {
|
|
206
|
+
h.setDirectStatus("granted"), r.getConnectionMode() === null && await r.setConnectionMode("direct");
|
|
207
|
+
const L = await g();
|
|
208
|
+
return l.current = L, u.current?.updateState(S()), { success: !0 };
|
|
206
209
|
}
|
|
207
210
|
}
|
|
208
|
-
const
|
|
209
|
-
return l.current =
|
|
211
|
+
const a = await g();
|
|
212
|
+
return l.current = a, u.current?.updateState(S()), { success: !1 };
|
|
210
213
|
},
|
|
211
|
-
[
|
|
212
|
-
|
|
213
|
-
const e = await
|
|
214
|
-
return l.current = e,
|
|
214
|
+
[T.MODAL_LNA_SKIP]: async () => {
|
|
215
|
+
h.setDirectStatus("skipped");
|
|
216
|
+
const e = await g();
|
|
217
|
+
return l.current = e, u.current?.updateState(S()), { success: !0 };
|
|
215
218
|
},
|
|
216
|
-
[
|
|
217
|
-
|
|
219
|
+
[T.MODAL_CLOSE]: () => {
|
|
220
|
+
C();
|
|
218
221
|
},
|
|
219
|
-
[
|
|
220
|
-
|
|
222
|
+
[T.MODAL_COMPLETE]: () => {
|
|
223
|
+
C();
|
|
221
224
|
},
|
|
222
|
-
[
|
|
223
|
-
[
|
|
224
|
-
const
|
|
225
|
-
return await r.setConnectionMode(
|
|
225
|
+
[T.MODAL_CONFIRM_SERVER_INSTALL]: (e) => (h.setServerInstallConfirmed(e.payload.confirmed), u.current?.updateState(S()), { success: !0 }),
|
|
226
|
+
[T.MODAL_SELECT_CONNECTION]: async (e) => {
|
|
227
|
+
const s = e.payload.connection === "lna" ? "direct" : "extension";
|
|
228
|
+
return await r.setConnectionMode(s), u.current?.updateState(S()), { success: !0 };
|
|
226
229
|
}
|
|
227
230
|
}),
|
|
228
|
-
[
|
|
231
|
+
[_, r, h, g, S, A, C]
|
|
229
232
|
);
|
|
230
|
-
return N(() => (
|
|
231
|
-
|
|
232
|
-
}), [n,
|
|
233
|
-
|
|
234
|
-
l.current = e,
|
|
233
|
+
return N(() => (u.current = new fe({ modalHtmlPath: n, handlers: o }), () => {
|
|
234
|
+
u.current?.destroy(), u.current = null;
|
|
235
|
+
}), [n, o]), N(() => {
|
|
236
|
+
I && u.current ? (u.current.showLoading(), g(!0).then((e) => {
|
|
237
|
+
l.current = e, u.current?.updateState(e), w?.();
|
|
235
238
|
}).catch((e) => {
|
|
236
239
|
console.error("[SetupModalProcessor] buildSetupState failed:", e);
|
|
237
|
-
})) : !
|
|
238
|
-
}, [
|
|
240
|
+
})) : !I && u.current && u.current.destroy();
|
|
241
|
+
}, [I, g, w]), null;
|
|
239
242
|
}
|
|
240
|
-
const
|
|
243
|
+
const we = "http://localhost:1135", F = {
|
|
241
244
|
MODAL_READY: "modal:ready",
|
|
242
245
|
MODAL_PROBE: "modal:probe",
|
|
243
246
|
MODAL_COMPLETE: "modal:complete",
|
|
244
247
|
MODAL_CLOSE: "modal:close"
|
|
245
|
-
},
|
|
246
|
-
function
|
|
247
|
-
const n = r.toLowerCase(),
|
|
248
|
-
if (
|
|
249
|
-
const
|
|
250
|
-
return { name: "edge", version:
|
|
248
|
+
}, Me = 130, be = 143;
|
|
249
|
+
function _e(r = navigator.userAgent) {
|
|
250
|
+
const n = r.toLowerCase(), C = n.match(/edg\/(\d+)/);
|
|
251
|
+
if (C) {
|
|
252
|
+
const i = parseInt(C[1], 10);
|
|
253
|
+
return { name: "edge", version: i, supported: i >= be };
|
|
251
254
|
}
|
|
252
|
-
const
|
|
253
|
-
if (
|
|
254
|
-
const
|
|
255
|
-
return { name: "chrome", version:
|
|
255
|
+
const w = n.match(/chrome\/(\d+)/);
|
|
256
|
+
if (w && !n.includes("edg/")) {
|
|
257
|
+
const i = parseInt(w[1], 10);
|
|
258
|
+
return { name: "chrome", version: i, supported: i >= Me };
|
|
256
259
|
}
|
|
257
|
-
const
|
|
258
|
-
if (
|
|
259
|
-
return { name: "firefox", version: parseInt(
|
|
260
|
-
const
|
|
261
|
-
return
|
|
260
|
+
const M = n.match(/firefox\/(\d+)/);
|
|
261
|
+
if (M)
|
|
262
|
+
return { name: "firefox", version: parseInt(M[1], 10), supported: !1 };
|
|
263
|
+
const d = n.match(/version\/(\d+).*safari/);
|
|
264
|
+
return d && !n.includes("chrome/") ? { name: "safari", version: parseInt(d[1], 10), supported: !1 } : { name: "unknown", version: 0, supported: !1 };
|
|
262
265
|
}
|
|
263
266
|
function Ae({
|
|
264
267
|
client: r,
|
|
265
268
|
modalHtmlPath: n,
|
|
266
|
-
hideSetup:
|
|
267
|
-
onSetupReady:
|
|
268
|
-
setupState:
|
|
269
|
-
basePath:
|
|
270
|
-
logLevel:
|
|
271
|
-
autoProbe:
|
|
272
|
-
defaultHost:
|
|
269
|
+
hideSetup: C,
|
|
270
|
+
onSetupReady: w,
|
|
271
|
+
setupState: M,
|
|
272
|
+
basePath: d = "/",
|
|
273
|
+
logLevel: i = "warn",
|
|
274
|
+
autoProbe: I = !0,
|
|
275
|
+
defaultHost: _
|
|
273
276
|
}) {
|
|
274
|
-
const
|
|
275
|
-
() => new
|
|
276
|
-
[
|
|
277
|
-
),
|
|
278
|
-
() => `${
|
|
279
|
-
[
|
|
280
|
-
),
|
|
277
|
+
const u = M !== "ready", h = x(() => new K("SetupModalV2Processor", i), [i]), l = z(null), E = z(null), O = x(
|
|
278
|
+
() => new Q(W(d, "bodhijs:")),
|
|
279
|
+
[d]
|
|
280
|
+
), b = x(
|
|
281
|
+
() => `${W(d, "bodhijs:")}setup-v2.connection`,
|
|
282
|
+
[d]
|
|
283
|
+
), A = p(() => {
|
|
281
284
|
try {
|
|
282
|
-
const
|
|
283
|
-
if (!
|
|
284
|
-
const e = JSON.parse(
|
|
285
|
+
const o = localStorage.getItem(b);
|
|
286
|
+
if (!o) return null;
|
|
287
|
+
const e = JSON.parse(o);
|
|
285
288
|
return typeof e?.serverUrl == "string" ? e : null;
|
|
286
289
|
} catch {
|
|
287
290
|
return null;
|
|
288
291
|
}
|
|
289
|
-
}, [
|
|
290
|
-
(
|
|
292
|
+
}, [b]), R = p(
|
|
293
|
+
(o) => {
|
|
291
294
|
try {
|
|
292
295
|
localStorage.setItem(
|
|
293
|
-
|
|
294
|
-
JSON.stringify({
|
|
296
|
+
b,
|
|
297
|
+
JSON.stringify({
|
|
298
|
+
serverUrl: q(o),
|
|
299
|
+
lastProbedAt: Date.now()
|
|
300
|
+
})
|
|
295
301
|
);
|
|
296
302
|
} catch {
|
|
297
303
|
}
|
|
298
304
|
},
|
|
299
|
-
[
|
|
300
|
-
),
|
|
301
|
-
async (
|
|
302
|
-
const e =
|
|
303
|
-
return
|
|
304
|
-
serverUrl:
|
|
305
|
-
browser:
|
|
305
|
+
[b]
|
|
306
|
+
), y = p(
|
|
307
|
+
async (o) => {
|
|
308
|
+
const e = q(o), t = _e(), s = await r.testDirectConnectivity(e), a = s.server.status;
|
|
309
|
+
return a === "ready" ? (R(e), O.setDirectStatus("granted"), r.getConnectionMode() === null && await r.setConnectionMode("direct"), { serverUrl: e, browser: t, probeStatus: "connected", serverStatus: "ready" }) : a === "setup" || a === "resource_admin" ? { serverUrl: e, browser: t, probeStatus: "not-ready", serverStatus: a } : a === "error" ? {
|
|
310
|
+
serverUrl: e,
|
|
311
|
+
browser: t,
|
|
306
312
|
probeStatus: "error",
|
|
307
313
|
serverStatus: "error",
|
|
308
|
-
error:
|
|
314
|
+
error: s.server.error ? { code: "server-error", message: s.server.error.message } : void 0
|
|
309
315
|
} : {
|
|
310
|
-
serverUrl:
|
|
311
|
-
browser:
|
|
316
|
+
serverUrl: e,
|
|
317
|
+
browser: t,
|
|
312
318
|
probeStatus: "network-error",
|
|
313
319
|
serverStatus: "unreachable",
|
|
314
|
-
error:
|
|
320
|
+
error: s.server.error ? { code: "network-error", message: s.server.error.message } : void 0
|
|
315
321
|
};
|
|
316
322
|
},
|
|
317
|
-
[r,
|
|
318
|
-
),
|
|
319
|
-
const e =
|
|
320
|
-
return
|
|
321
|
-
}, [
|
|
323
|
+
[r, O, R]
|
|
324
|
+
), g = p(async () => {
|
|
325
|
+
const e = A()?.serverUrl ?? _ ?? we;
|
|
326
|
+
return y(e);
|
|
327
|
+
}, [y, A, _]), S = x(
|
|
322
328
|
() => ({
|
|
323
|
-
[
|
|
324
|
-
if (
|
|
325
|
-
return { setupState:
|
|
326
|
-
const
|
|
327
|
-
return
|
|
329
|
+
[F.MODAL_READY]: async () => {
|
|
330
|
+
if (E.current)
|
|
331
|
+
return { setupState: E.current };
|
|
332
|
+
const o = await g();
|
|
333
|
+
return E.current = o, { setupState: o };
|
|
328
334
|
},
|
|
329
|
-
[
|
|
330
|
-
const e = await
|
|
331
|
-
return
|
|
335
|
+
[F.MODAL_PROBE]: async (o) => {
|
|
336
|
+
const e = await y(o.payload.serverUrl);
|
|
337
|
+
return E.current = e, l.current?.updateState(e), { setupState: e };
|
|
332
338
|
},
|
|
333
|
-
[
|
|
334
|
-
|
|
339
|
+
[F.MODAL_COMPLETE]: () => {
|
|
340
|
+
C();
|
|
335
341
|
},
|
|
336
|
-
[
|
|
337
|
-
|
|
342
|
+
[F.MODAL_CLOSE]: () => {
|
|
343
|
+
C();
|
|
338
344
|
}
|
|
339
345
|
}),
|
|
340
|
-
[
|
|
346
|
+
[g, y, C]
|
|
341
347
|
);
|
|
342
|
-
return N(() => (l.current = new
|
|
348
|
+
return N(() => (l.current = new pe({ modalHtmlPath: n, handlers: S }), () => {
|
|
343
349
|
l.current?.destroy(), l.current = null;
|
|
344
|
-
}), [n,
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}).catch((
|
|
348
|
-
|
|
350
|
+
}), [n, S]), N(() => {
|
|
351
|
+
I && g().then((o) => {
|
|
352
|
+
E.current = o, h.info("Auto-probe complete:", o.probeStatus);
|
|
353
|
+
}).catch((o) => {
|
|
354
|
+
h.error("Auto-probe failed:", o);
|
|
349
355
|
});
|
|
350
|
-
}, [
|
|
351
|
-
let
|
|
352
|
-
return
|
|
353
|
-
|
|
356
|
+
}, [I, g, h]), N(() => {
|
|
357
|
+
let o = !1;
|
|
358
|
+
return u && l.current ? (l.current.showLoading(), E.current ? (l.current.updateState(E.current), w?.()) : g().then((e) => {
|
|
359
|
+
o || (E.current = e, l.current?.updateState(e), w?.());
|
|
354
360
|
}).catch((e) => {
|
|
355
|
-
|
|
356
|
-
})) : !
|
|
357
|
-
|
|
361
|
+
o || h.error("buildInitialState failed:", e);
|
|
362
|
+
})) : !u && l.current && l.current.destroy(), () => {
|
|
363
|
+
o = !0;
|
|
358
364
|
};
|
|
359
|
-
}, [
|
|
365
|
+
}, [u, g, w, h]), null;
|
|
360
366
|
}
|
|
361
|
-
const
|
|
367
|
+
const xe = {
|
|
362
368
|
status: "not-initialized",
|
|
363
369
|
mode: null,
|
|
364
370
|
extensionId: null,
|
|
365
371
|
url: null,
|
|
366
|
-
server:
|
|
372
|
+
server: ee,
|
|
367
373
|
error: null
|
|
368
|
-
},
|
|
374
|
+
}, Oe = {
|
|
369
375
|
status: "initializing",
|
|
370
376
|
mode: null,
|
|
371
377
|
extensionId: null,
|
|
372
378
|
url: null,
|
|
373
|
-
server:
|
|
379
|
+
server: ee,
|
|
374
380
|
error: null
|
|
375
381
|
};
|
|
376
|
-
function
|
|
382
|
+
function Le(r) {
|
|
377
383
|
return r.status === "not-initialized";
|
|
378
384
|
}
|
|
379
385
|
function Ie(r) {
|
|
380
386
|
return r.status === "initializing";
|
|
381
387
|
}
|
|
382
|
-
function
|
|
388
|
+
function Re(r) {
|
|
383
389
|
return r.status !== "not-initialized" && r.status !== "initializing";
|
|
384
390
|
}
|
|
385
|
-
function
|
|
391
|
+
function re(r) {
|
|
386
392
|
return r.status === "ready";
|
|
387
393
|
}
|
|
388
|
-
function
|
|
389
|
-
return
|
|
394
|
+
function De(r) {
|
|
395
|
+
return re(r) && r.server.status === "ready";
|
|
390
396
|
}
|
|
391
|
-
function
|
|
392
|
-
return
|
|
397
|
+
function Te(r) {
|
|
398
|
+
return he(r) ? {
|
|
393
399
|
status: r.extension === "not-initialized" ? "initializing" : r.extension === "not-found" ? "extension-not-found" : "ready",
|
|
394
400
|
mode: "extension",
|
|
395
401
|
extensionId: r.extensionId,
|
|
@@ -405,221 +411,211 @@ function Re(r) {
|
|
|
405
411
|
error: r.server.error
|
|
406
412
|
};
|
|
407
413
|
}
|
|
408
|
-
const
|
|
409
|
-
isNotInitialized:
|
|
414
|
+
const Ve = {
|
|
415
|
+
isNotInitialized: Le,
|
|
410
416
|
isInitializing: Ie,
|
|
411
|
-
isInitialized:
|
|
412
|
-
isReady:
|
|
413
|
-
isOverallReady:
|
|
414
|
-
},
|
|
415
|
-
|
|
416
|
-
function
|
|
417
|
+
isInitialized: Re,
|
|
418
|
+
isReady: re,
|
|
419
|
+
isOverallReady: De
|
|
420
|
+
}, Y = ve(null);
|
|
421
|
+
Y.displayName = "BodhiContext";
|
|
422
|
+
function Fe({
|
|
417
423
|
children: r,
|
|
418
424
|
client: n,
|
|
419
|
-
modalHtmlPath:
|
|
420
|
-
handleCallback:
|
|
421
|
-
callbackPath:
|
|
422
|
-
basePath:
|
|
423
|
-
logLevel:
|
|
424
|
-
setupModal:
|
|
425
|
-
autoProbe:
|
|
426
|
-
defaultHost:
|
|
425
|
+
modalHtmlPath: C,
|
|
426
|
+
handleCallback: w = !0,
|
|
427
|
+
callbackPath: M,
|
|
428
|
+
basePath: d = "/",
|
|
429
|
+
logLevel: i = "warn",
|
|
430
|
+
setupModal: I = "setup-modal-v2",
|
|
431
|
+
autoProbe: _ = !0,
|
|
432
|
+
defaultHost: u
|
|
427
433
|
}) {
|
|
428
|
-
const
|
|
429
|
-
|
|
434
|
+
const h = d === "/" ? "" : d.replace(/\/$/, ""), l = M ?? `${h}/callback`, E = x(
|
|
435
|
+
() => u ? q(u) : void 0,
|
|
436
|
+
[u]
|
|
437
|
+
), O = x(() => new K("BodhiProvider", i), [i]), b = z(!1), A = z(!1), R = z(!1), [y, g] = V(xe), [S, o] = V(me), [e, t] = V(!1), [s, a] = V("ready"), v = p((f, c) => {
|
|
438
|
+
A.current = !0, o({
|
|
430
439
|
status: "error",
|
|
431
440
|
user: null,
|
|
432
441
|
accessToken: null,
|
|
433
|
-
error: { code:
|
|
442
|
+
error: { code: f, message: c },
|
|
434
443
|
refreshToken: null,
|
|
435
444
|
expiresAt: null,
|
|
436
445
|
isTokenRefresh: !1
|
|
437
|
-
}),
|
|
438
|
-
}, []),
|
|
439
|
-
|
|
446
|
+
}), t(!1);
|
|
447
|
+
}, []), L = p(() => {
|
|
448
|
+
A.current = !1;
|
|
440
449
|
}, []);
|
|
441
450
|
N(() => {
|
|
442
|
-
const
|
|
443
|
-
switch (
|
|
451
|
+
const f = (c) => {
|
|
452
|
+
switch (c.type) {
|
|
444
453
|
case "client-state":
|
|
445
|
-
|
|
454
|
+
g(Te(c.state));
|
|
446
455
|
break;
|
|
447
456
|
case "auth-state":
|
|
448
|
-
|
|
457
|
+
A.current || (o(c.state), t(!1));
|
|
449
458
|
break;
|
|
450
459
|
}
|
|
451
460
|
};
|
|
452
|
-
return n.setStateCallback(
|
|
453
|
-
n.setStateCallback(
|
|
461
|
+
return n.setStateCallback(f), () => {
|
|
462
|
+
n.setStateCallback(ge);
|
|
454
463
|
};
|
|
455
464
|
}, [n]);
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
}, []), B =
|
|
459
|
-
|
|
460
|
-
}, []),
|
|
461
|
-
|
|
462
|
-
}, []),
|
|
463
|
-
async (
|
|
464
|
-
|
|
465
|
+
const G = p(async () => {
|
|
466
|
+
a("loading");
|
|
467
|
+
}, []), B = p(() => {
|
|
468
|
+
a("ready");
|
|
469
|
+
}, []), P = p(() => {
|
|
470
|
+
a("loaded");
|
|
471
|
+
}, []), $ = p(
|
|
472
|
+
async (f) => {
|
|
473
|
+
g(Oe);
|
|
465
474
|
try {
|
|
466
|
-
await n.init(
|
|
467
|
-
} catch (
|
|
468
|
-
|
|
475
|
+
await n.init(f || {});
|
|
476
|
+
} catch (c) {
|
|
477
|
+
O.error("Init failed:", c);
|
|
469
478
|
}
|
|
470
479
|
},
|
|
471
|
-
[n,
|
|
480
|
+
[n, O]
|
|
472
481
|
);
|
|
473
482
|
N(() => {
|
|
474
|
-
if (
|
|
475
|
-
|
|
476
|
-
if (await
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
await n.handleAccessRequestCallback(T);
|
|
488
|
-
} catch (D) {
|
|
489
|
-
h.error("Access request callback failed:", D);
|
|
490
|
-
const te = D instanceof W ? D : null;
|
|
491
|
-
g(
|
|
492
|
-
te?.code ?? "access_request_callback_failed",
|
|
493
|
-
D instanceof Error ? D.message : "Access request callback failed"
|
|
494
|
-
), window.history.replaceState({}, "", i);
|
|
495
|
-
}
|
|
483
|
+
if (R.current) return;
|
|
484
|
+
R.current = !0, (async () => {
|
|
485
|
+
if (await $(), !w) return;
|
|
486
|
+
const c = new URL(window.location.href);
|
|
487
|
+
if (c.pathname !== l || b.current || !Se(n)) return;
|
|
488
|
+
const D = c.searchParams.get("error");
|
|
489
|
+
if (D) {
|
|
490
|
+
b.current = !0;
|
|
491
|
+
const k = c.searchParams.get("error_source") === "bodhi" && D === "access_denied";
|
|
492
|
+
v(
|
|
493
|
+
k ? "access_request_denied" : D,
|
|
494
|
+
c.searchParams.get("error_description") ?? D
|
|
495
|
+
), window.history.replaceState({}, "", d);
|
|
496
496
|
return;
|
|
497
497
|
}
|
|
498
|
-
const
|
|
499
|
-
if (!(!
|
|
500
|
-
|
|
498
|
+
const U = c.searchParams.get("code"), X = c.searchParams.get("state");
|
|
499
|
+
if (!(!U || !X)) {
|
|
500
|
+
b.current = !0, t(!0);
|
|
501
501
|
try {
|
|
502
|
-
await n.handleOAuthCallback(
|
|
503
|
-
} catch (
|
|
504
|
-
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
), window.history.replaceState({}, "",
|
|
502
|
+
await n.handleOAuthCallback(U, X), window.history.replaceState({}, "", d);
|
|
503
|
+
} catch (k) {
|
|
504
|
+
O.error("OAuth callback failed:", k);
|
|
505
|
+
const ne = k instanceof Z ? k : null;
|
|
506
|
+
v(
|
|
507
|
+
ne?.code ?? "oauth_callback_failed",
|
|
508
|
+
k instanceof Error ? k.message : "OAuth callback failed"
|
|
509
|
+
), window.history.replaceState({}, "", d);
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
512
|
})();
|
|
513
|
-
}, [
|
|
514
|
-
const
|
|
515
|
-
async (
|
|
516
|
-
|
|
513
|
+
}, [$, n, w, l, d]);
|
|
514
|
+
const H = p(
|
|
515
|
+
async (f) => {
|
|
516
|
+
L(), t(!0);
|
|
517
517
|
try {
|
|
518
|
-
const
|
|
519
|
-
...
|
|
520
|
-
...
|
|
521
|
-
...
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
} : void 0, V = o && Object.keys(o).length > 0 ? o : void 0;
|
|
527
|
-
await n.login(V);
|
|
528
|
-
} catch (o) {
|
|
529
|
-
const V = o instanceof W ? o : null, P = {
|
|
518
|
+
const c = f ? {
|
|
519
|
+
...f.userRole && { userRole: f.userRole },
|
|
520
|
+
...f.requested && { requested: f.requested },
|
|
521
|
+
...f.onProgress && { onProgress: f.onProgress }
|
|
522
|
+
} : void 0, D = c && Object.keys(c).length > 0 ? c : void 0;
|
|
523
|
+
await n.login(D);
|
|
524
|
+
} catch (c) {
|
|
525
|
+
const D = c instanceof Z ? c : null, U = {
|
|
530
526
|
status: "error",
|
|
531
527
|
user: null,
|
|
532
528
|
accessToken: null,
|
|
533
529
|
error: {
|
|
534
|
-
message:
|
|
535
|
-
code:
|
|
530
|
+
message: c instanceof Error ? c.message : "Login failed",
|
|
531
|
+
code: D?.code ?? "login_failed"
|
|
536
532
|
},
|
|
537
533
|
refreshToken: null,
|
|
538
534
|
expiresAt: null,
|
|
539
535
|
isTokenRefresh: !1
|
|
540
536
|
};
|
|
541
|
-
return
|
|
537
|
+
return o(U), t(!1), U;
|
|
542
538
|
}
|
|
543
539
|
},
|
|
544
|
-
[n,
|
|
545
|
-
),
|
|
546
|
-
|
|
540
|
+
[n, L]
|
|
541
|
+
), J = p(async () => {
|
|
542
|
+
L();
|
|
547
543
|
try {
|
|
548
544
|
await n.logout();
|
|
549
|
-
} catch (
|
|
550
|
-
|
|
545
|
+
} catch (f) {
|
|
546
|
+
v("logout_failed", f instanceof Error ? f.message : "Logout failed");
|
|
551
547
|
}
|
|
552
|
-
}, [n,
|
|
553
|
-
const
|
|
548
|
+
}, [n, v, L]), te = x(() => {
|
|
549
|
+
const f = y.status === "ready", c = y.server.status === "ready";
|
|
554
550
|
return {
|
|
555
551
|
client: n,
|
|
556
|
-
clientState:
|
|
557
|
-
auth:
|
|
558
|
-
isAuthLoading:
|
|
559
|
-
login:
|
|
560
|
-
logout:
|
|
561
|
-
showSetup:
|
|
552
|
+
clientState: y,
|
|
553
|
+
auth: S,
|
|
554
|
+
isAuthLoading: e,
|
|
555
|
+
login: H,
|
|
556
|
+
logout: J,
|
|
557
|
+
showSetup: G,
|
|
562
558
|
hideSetup: B,
|
|
563
|
-
setupState:
|
|
559
|
+
setupState: s,
|
|
564
560
|
// Computed auth properties
|
|
565
|
-
isAuthenticated:
|
|
566
|
-
canLogin:
|
|
561
|
+
isAuthenticated: S.status === "authenticated",
|
|
562
|
+
canLogin: f && !e,
|
|
567
563
|
// Computed connection properties
|
|
568
|
-
isReady:
|
|
569
|
-
isServerReady:
|
|
570
|
-
isOverallReady:
|
|
571
|
-
isInitializing:
|
|
572
|
-
isExtension:
|
|
573
|
-
isDirect:
|
|
564
|
+
isReady: f,
|
|
565
|
+
isServerReady: c,
|
|
566
|
+
isOverallReady: f && c,
|
|
567
|
+
isInitializing: y.status === "initializing",
|
|
568
|
+
isExtension: y.mode === "extension",
|
|
569
|
+
isDirect: y.mode === "direct"
|
|
574
570
|
};
|
|
575
|
-
}, [n,
|
|
576
|
-
return /* @__PURE__ */
|
|
577
|
-
|
|
578
|
-
|
|
571
|
+
}, [n, y, S, e, s, H, J, G, B]);
|
|
572
|
+
return /* @__PURE__ */ se(Y.Provider, { value: te, children: [
|
|
573
|
+
I === "setup-modal" ? /* @__PURE__ */ j(
|
|
574
|
+
ye,
|
|
579
575
|
{
|
|
580
576
|
client: n,
|
|
581
|
-
modalHtmlPath:
|
|
577
|
+
modalHtmlPath: C,
|
|
582
578
|
hideSetup: B,
|
|
583
|
-
onSetupReady:
|
|
584
|
-
setupState:
|
|
585
|
-
basePath:
|
|
586
|
-
logLevel:
|
|
587
|
-
autoProbe:
|
|
579
|
+
onSetupReady: P,
|
|
580
|
+
setupState: s,
|
|
581
|
+
basePath: d,
|
|
582
|
+
logLevel: i,
|
|
583
|
+
autoProbe: _
|
|
588
584
|
}
|
|
589
|
-
) : /* @__PURE__ */
|
|
585
|
+
) : /* @__PURE__ */ j(
|
|
590
586
|
Ae,
|
|
591
587
|
{
|
|
592
588
|
client: n,
|
|
593
|
-
modalHtmlPath:
|
|
589
|
+
modalHtmlPath: C,
|
|
594
590
|
hideSetup: B,
|
|
595
|
-
onSetupReady:
|
|
596
|
-
setupState:
|
|
597
|
-
basePath:
|
|
598
|
-
logLevel:
|
|
599
|
-
autoProbe:
|
|
600
|
-
defaultHost:
|
|
591
|
+
onSetupReady: P,
|
|
592
|
+
setupState: s,
|
|
593
|
+
basePath: d,
|
|
594
|
+
logLevel: i,
|
|
595
|
+
autoProbe: _,
|
|
596
|
+
defaultHost: E
|
|
601
597
|
}
|
|
602
598
|
),
|
|
603
599
|
r
|
|
604
600
|
] });
|
|
605
601
|
}
|
|
606
|
-
function
|
|
607
|
-
const r =
|
|
602
|
+
function je() {
|
|
603
|
+
const r = Ce(Y);
|
|
608
604
|
if (!r) throw new Error("useBodhi must be used within BodhiProvider");
|
|
609
605
|
return r;
|
|
610
606
|
}
|
|
611
|
-
const ke = (r) => /* @__PURE__ */
|
|
607
|
+
const ke = (r) => /* @__PURE__ */ m.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 479.995 479.995", width: "480px", height: "480px", ...r }, /* @__PURE__ */ m.createElement("path", { fill: "#ffa4b8", d: "M239.998,374.56l-0.01-0.01c0-0.01,0.01-0.01,0.01-0.02c-4.64-8.78-65.7-144.8-212.22-85.2 c-14.36,5.85-19.78,23.45-11.19,36.36c11.11,16.69,22.86,30.01,34.91,40.53c-27.85,7.89-45.6,33.8-43.3,61.55 c0.96,11.6,13.29,18.52,23.71,13.35c33.99-16.84,60.03-2.51,80.35,2.14c56.68,12.99,113.71,4.53,125.52-46.29 c0.52-2.22,0.95-4.51,1.28-6.89c0.01-0.04,0.01-0.08,0.02-0.12c0.066-0.492,0.126-0.978,0.181-1.458 c0.455-3.631,0.712-7.438,0.739-11.452c-0.02-1.44-0.02-2.01,0-2.25v-0.09c0-0.02,0-0.04,0.01-0.05c0-0.02,0.01-0.03,0.02-0.06 c0-0.01,0.01-0.01,0.01-0.02C240.018,374.569,240.008,374.56,239.998,374.56z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ffa4b8", d: "M471.798,427.769c-0.96,11.6-13.29,18.52-23.71,13.35c-33.99-16.84-60.03-2.51-80.35,2.14 c-63.41,14.53-127.25,2.22-127.74-66.21c0.033-2.642-0.044-2.302,0.04-2.47c-0.02-0.01-0.03-0.02-0.04-0.02l0.01-0.01 c0-0.01-0.01-0.01-0.01-0.02c4.64-8.78,65.7-144.8,212.22-85.2c14.36,5.85,19.78,23.45,11.19,36.36 c-11.11,16.69-22.86,30.01-34.91,40.53C456.348,374.109,474.098,400.019,471.798,427.769z" }), /* @__PURE__ */ m.createElement("path", { fill: "#befa91", d: "M428.498,366.219c27.85,7.89,45.6,33.8,43.3,61.55c-0.96,11.6-13.29,18.52-23.71,13.35 c-33.99-16.84-60.03-2.51-80.35,2.14c-63.41,14.53-127.928,2.222-127.74-66.21c0.007-2.683-0.02-2.351,0.04-2.47 C248.598,379.129,345.858,438.329,428.498,366.219z" }), /* @__PURE__ */ m.createElement("path", { fill: "#befa91", d: "M51.498,366.219c82.76,72.22,180.18,12.74,188.5,8.34c0.01,0,0.02,0.01,0.04,0.02 c-0.058,0.116-0.047-0.169-0.04,2.47c0.188,68.432-64.33,80.74-127.74,66.21c-20.32-4.65-46.36-18.98-80.35-2.14 c-10.42,5.17-22.75-1.75-23.71-13.35C5.898,400.019,23.648,374.109,51.498,366.219z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ffbfcb", d: "M235.228,365.299c-32.29-36.09-89.98-73-179.74-36.49c-1.979,0.805-3.787,1.834-5.413,3.042 c-10.569,7.856-25.473,5.765-32.82-5.164c-0.223-0.331-0.445-0.664-0.667-0.997c-8.59-12.91-3.17-30.51,11.19-36.36 C155.168,237.509,217.948,333.56,235.228,365.299z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ffa4b8", d: "M239.998,374.549c-12.85-2.2-214.54-23.33-193.03-240.71c1.49-14.99,15.86-25.15,30.48-21.55 c108.49,26.72,149.07,91.39,162.55,149.92C252.768,317.699,241.178,367.679,239.998,374.549z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ffbfcb", d: "M193.698,174.638c11.866,12.406-3.013,31.792-18.056,23.52 c-21.875-12.028-50.044-10.573-70.207,3.701c-24.832,17.579-59.398-0.365-60.013-30.784c-0.237-11.724,0.248-24.123,1.545-37.237 c1.49-14.99,15.86-25.15,30.48-21.55C131.23,125.537,168.324,148.11,193.698,174.638z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ffa4b8", d: "M221.538,39.599c9.78-11.13,27.15-11.12,36.93,0.01c157.02,178.77-7.48,323.95-18.47,334.94 C229.988,364.549,63.948,218.989,221.538,39.599z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ffbfcb", d: "M261.523,43.131c9.452,11.033,8.166,27.623-2.74,37.221c-0.784,0.69-1.535,1.439-2.245,2.247 c-35.942,40.915-55.05,80.07-63.012,116.258c-5.176,23.523-39.936,19.717-39.551-4.366c0.741-46.282,18.411-98.941,67.563-154.892 c9.78-11.13,27.15-11.12,36.93,0.01C259.5,40.785,260.518,41.959,261.523,43.131z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ffa4b8", d: "M239.998,374.549c-1.18-6.87-12.77-56.85,0-112.34c13.48-58.53,54.06-123.2,162.55-149.92 c14.62-3.6,28.99,6.56,30.48,21.55C454.538,351.219,252.848,372.349,239.998,374.549z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ff8ca5", d: "M239.998,374.549c-3.115-0.536-17.362-2.183-36.835-7.483c-3.181-0.866-6.028-2.682-8.145-5.209 c-49.098-58.608-75.675-130.75-61.047-205.793c2.165-11.107,14.881-16.444,24.408-10.337c0.756,0.485,1.506,0.972,2.249,1.462 C126.798,274.139,232.088,366.649,239.998,374.549z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ff8ca5", d: "M281.608,365.729c-21.9,6.37-38.24,8.25-41.61,8.82c8.67-8.67,112.98-100.94,79.35-227.34v-0.01 c0.742-0.489,1.49-0.975,2.244-1.459c9.551-6.123,22.265-0.733,24.422,10.406C369.565,277.734,281.608,363.204,281.608,365.729z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ff8ca5", d: "M417.451,302.932c-32.211,44.193-80.706,72.823-134.571,87.345c-3.396,0.916-6.999,0.754-10.3-0.463 c-20.772-7.664-31.911-15.254-32.583-15.254c0.826-0.825,112.667-9.463,166.4-98.31C419.37,278.279,424.743,292.927,417.451,302.932 z" }), /* @__PURE__ */ m.createElement("path", { fill: "#ff8ca5", d: "M62.565,302.932c32.211,44.193,80.705,72.823,134.571,87.345c3.396,0.916,6.999,0.754,10.3-0.463 c20.772-7.664,31.911-15.254,32.583-15.254c-0.828-0.828-112.665-9.458-166.4-98.31C60.646,278.279,55.273,292.927,62.565,302.932z" }), /* @__PURE__ */ m.createElement("path", { fill: "#9ceb63", d: "M433.464,393.091c-52.749,39.415-118.979,42.09-182.861,13.657 c-4.441-1.977-7.606-6.011-8.633-10.763c-1.552-7.18-1.884-14.238-1.973-21.326c0.172-0.345,9.566,5.934,26.76,12.89 c36.31,14.71,102.75,30.15,161.74-21.33C440.977,369.752,443.403,385.664,433.464,393.091z" }), /* @__PURE__ */ m.createElement("path", { fill: "#9ceb63", d: "M240.038,374.579c0,0.01-0.01,0.01-0.01,0.02s-0.01,0.03-0.01,0.05c0,0,0,0,0,0.01 c-0.01,0.03-0.01,0.06-0.02,0.1v0.04c-0.13,1.3,0.09,7.59-0.92,15.16c-0.01,0.04-0.01,0.08-0.02,0.12 c-0.26,1.91-0.59,3.91-1.03,5.92c-0.07,0.33-0.15,0.65-0.25,0.97c-1.23,4.33-4.28,7.95-8.41,9.79 c-63.06,28.05-129.47,26.21-182.79-13.63c-9.94-7.43-7.63-23.36,4.92-26.91c13.1,11.46,28.11,20.79,44.16,26.79 c19.78,7.48,34.99,8.98,53.83,8.68c34.33-0.55,60.1-11.03,90.51-27.13C240.008,374.56,240.018,374.569,240.038,374.579z" }), /* @__PURE__ */ m.createElement("path", { d: "M443.143,363.426c9.579-9.648,18.604-20.804,26.926-33.305c11.399-17.132,4.201-40.447-14.837-48.202 c-12.321-5.012-24.515-8.844-36.391-11.454c17.945-34.197,27.974-78.94,22.188-137.413c-1.925-19.503-20.802-33.354-40.394-28.53 c-17.952,4.421-34.806,10.063-50.093,16.768c-4.046,1.775-5.888,6.494-4.113,10.54c1.774,4.046,6.493,5.887,10.54,4.113 c14.45-6.338,30.429-11.682,47.492-15.885c9.885-2.435,19.599,4.434,20.607,14.573c9.088,90.121-21.147,164.341-99.823,205.213 c-3.921,2.037-5.448,6.866-3.411,10.787c2.043,3.933,6.879,5.442,10.787,3.411c27.191-14.125,56.267-35.849,77.701-68.994 c12.564,2.375,25.617,6.296,38.878,11.69c9.68,3.943,13.334,15.824,7.549,24.518c-10.205,15.33-21.482,28.43-33.516,38.936 c-49.396,43.107-111.979,41.39-169.834,12.419c56.638-56.971,92.247-132.34,77.074-212.524 c-8.101-42.81-30.305-85.119-65.997-125.754c-12.964-14.759-36.003-14.748-48.946-0.016 c-28.645,32.607-48.657,66.371-59.602,100.512c-21.999-13.018-47.7-23.197-76.569-30.307c-19.338-4.763-38.383,8.699-40.354,28.53 C26.197,262.501,90.89,324.677,147.416,354.042c3.92,2.036,8.75,0.51,10.787-3.411c2.037-3.921,0.51-8.75-3.411-10.787 c-52.141-27.086-111.791-84.677-99.863-205.213c1.007-10.132,10.713-17.01,20.606-14.574c31.115,7.663,58.223,19.013,80.571,33.735 c4.863,3.204,10.891,0.586,12.257-4.539c9.392-35.245,29.306-70.362,59.188-104.378c6.581-7.492,18.316-7.487,24.904,0.014 c128.735,146.565,37.449,269.122-12.476,318.519c-30.274-29.828-76.759-87.727-78.002-162.831 c-0.073-4.417-3.698-7.933-8.131-7.867c-4.417,0.073-7.939,3.714-7.867,8.131c1.382,83.483,54.096,146.516,85.999,177.099 c-0.353,20.737-7.099,36.575-20.104,47.086c-20.129,16.267-55.786,20.072-97.831,10.438c-19.181-4.396-48.632-19.874-85.688-1.511 c-5.361,2.657-11.689-0.859-12.186-6.844c-1.888-22.74,12.042-43.926,33.548-51.893c13.4,11.096,27.797,19.551,43.11,25.275 c20.238,7.653,36.036,9.525,56.788,9.196c15.85-0.254,30.814-2.572,45.747-7.085c4.229-1.278,6.622-5.743,5.343-9.972 c-1.278-4.229-5.744-6.622-9.972-5.344c-13.494,4.078-27.027,6.173-41.373,6.403c-17.347,0.275-31.911-0.993-50.901-8.174 c-31.69-11.847-56.387-35.98-75.211-64.258c-5.791-8.704-2.122-20.58,7.548-24.52c4.092-1.667,6.058-6.335,4.391-10.427 c-1.667-4.092-6.334-6.058-10.427-4.391c-19.062,7.765-26.214,31.095-14.832,48.202c8.365,12.566,17.352,23.674,26.917,33.31 C12.89,375.664-2.037,401.187,0.226,428.434c1.427,17.192,19.743,27.533,35.235,19.857c30.84-15.283,54.311-1.971,75.01,2.771 c36.708,8.411,82.166,10.086,111.461-13.59c14.777-11.943,23.305-28.715,25.489-49.937 c61.607,30.736,128.694,32.482,182.835-12.326c21.516,7.959,35.456,29.153,33.567,51.902c-0.493,5.939-6.786,9.519-12.186,6.844 c-30.339-15.034-55.535-7.379-73.932-1.791c-31.306,9.51-74.736,14.144-102.884-2.498c-3.803-2.248-8.709-0.989-10.958,2.815 c-2.249,3.803-0.989,8.709,2.815,10.958c29.214,17.272,69.817,15.19,102.844,7.622c20.72-4.747,44.177-18.05,75.01-2.771 c15.523,7.691,33.811-2.693,35.235-19.856C482.032,401.183,467.102,375.655,443.143,363.426z" })), ze = {
|
|
612
608
|
sm: 32,
|
|
613
609
|
md: 48,
|
|
614
610
|
lg: 64
|
|
615
611
|
};
|
|
616
|
-
function
|
|
612
|
+
function qe({
|
|
617
613
|
size: r = "md",
|
|
618
614
|
variant: n = "light",
|
|
619
|
-
className:
|
|
620
|
-
style:
|
|
615
|
+
className: C = "",
|
|
616
|
+
style: w = {}
|
|
621
617
|
}) {
|
|
622
|
-
const
|
|
618
|
+
const M = ze[r], d = {
|
|
623
619
|
display: "inline-block",
|
|
624
620
|
cursor: "pointer",
|
|
625
621
|
transition: "all 250ms ease",
|
|
@@ -628,9 +624,9 @@ function Fe({
|
|
|
628
624
|
backgroundColor: "rgba(255, 255, 255, 0.05)",
|
|
629
625
|
padding: "8px"
|
|
630
626
|
},
|
|
631
|
-
...
|
|
627
|
+
...w
|
|
632
628
|
};
|
|
633
|
-
return /* @__PURE__ */
|
|
629
|
+
return /* @__PURE__ */ j(
|
|
634
630
|
"a",
|
|
635
631
|
{
|
|
636
632
|
href: "https://getbodhi.app",
|
|
@@ -638,46 +634,47 @@ function Fe({
|
|
|
638
634
|
rel: "noopener noreferrer",
|
|
639
635
|
title: "Powered by Bodhi",
|
|
640
636
|
"aria-label": "Powered by Bodhi - Visit getbodhi.app",
|
|
641
|
-
className:
|
|
642
|
-
style:
|
|
643
|
-
onMouseEnter: (
|
|
644
|
-
|
|
637
|
+
className: C,
|
|
638
|
+
style: d,
|
|
639
|
+
onMouseEnter: (i) => {
|
|
640
|
+
i.currentTarget.style.transform = "scale(1.1)", i.currentTarget.style.boxShadow = "0 0 20px rgba(255, 164, 184, 0.6)";
|
|
645
641
|
},
|
|
646
|
-
onMouseLeave: (
|
|
647
|
-
|
|
642
|
+
onMouseLeave: (i) => {
|
|
643
|
+
i.currentTarget.style.transform = "scale(1)", i.currentTarget.style.boxShadow = "none";
|
|
648
644
|
},
|
|
649
|
-
children: /* @__PURE__ */
|
|
645
|
+
children: /* @__PURE__ */ j(ke, { width: M, height: M, style: { display: "block" } })
|
|
650
646
|
}
|
|
651
647
|
);
|
|
652
648
|
}
|
|
653
|
-
const
|
|
649
|
+
const Ge = "production";
|
|
654
650
|
export {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
651
|
+
Ye as BodhiApiError,
|
|
652
|
+
qe as BodhiBadge,
|
|
653
|
+
$e as BodhiError,
|
|
654
|
+
Fe as BodhiProvider,
|
|
655
|
+
Y as BodhiReactContext,
|
|
656
|
+
Ve as ClientCtxState,
|
|
657
|
+
Oe as INITIALIZING_CLIENT_CONTEXT_STATE,
|
|
658
|
+
xe as INITIAL_CLIENT_CONTEXT_STATE,
|
|
663
659
|
He as InMemoryStorage,
|
|
664
660
|
Je as LoginOptionsBuilder,
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
661
|
+
Ge as REACT_CORE_BUILD_MODE,
|
|
662
|
+
Te as clientStateToContextState,
|
|
663
|
+
Xe as createApiError,
|
|
664
|
+
Ze as createOperationError,
|
|
665
|
+
Qe as isAuthError,
|
|
666
|
+
er as isAuthLoading,
|
|
667
|
+
rr as isAuthenticated,
|
|
668
|
+
Re as isClientCtxInitialized,
|
|
673
669
|
Ie as isClientCtxInitializing,
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
670
|
+
Le as isClientCtxNotInitialized,
|
|
671
|
+
re as isClientCtxReady,
|
|
672
|
+
tr as isClientReady,
|
|
673
|
+
nr as isDirectState,
|
|
674
|
+
sr as isExtensionState,
|
|
675
|
+
De as isOverallReady,
|
|
676
|
+
or as isWebUIClient,
|
|
677
|
+
q as normalizeServerUrl,
|
|
681
678
|
cr as unwrapResponse,
|
|
682
|
-
|
|
679
|
+
je as useBodhi
|
|
683
680
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -20,4 +20,5 @@ export { isAuthError, isAuthLoading, isAuthenticated, isClientReady, } from '@bo
|
|
|
20
20
|
export type { ApiResponse } from '@bodhiapp/bodhi-browser-types';
|
|
21
21
|
export type { McpFetchLike, McpTransportConfig } from '@bodhiapp/bodhi-js-core';
|
|
22
22
|
export type { StreamTextResult } from '@bodhiapp/bodhi-js-core';
|
|
23
|
+
export { normalizeServerUrl } from './url';
|
|
23
24
|
export { BUILD_MODE as REACT_CORE_BUILD_MODE } from './build-info';
|
package/dist/url.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeServerUrl(url: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bodhiapp/bodhi-js-react-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40",
|
|
4
4
|
"description": "Core React bindings for Bodhi Browser SDK (dependency injection)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/bodhi-react-core.cjs.js",
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"typecheck": "tsc --noEmit"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@bodhiapp/bodhi-browser-types": "0.0.
|
|
61
|
-
"@bodhiapp/setup-modal-types": "0.0.
|
|
62
|
-
"@bodhiapp/setup-modal-v2-types": "0.0.
|
|
63
|
-
"@bodhiapp/bodhi-js-core": "0.0.
|
|
64
|
-
"@bodhiapp/ts-client": "0.1.
|
|
60
|
+
"@bodhiapp/bodhi-browser-types": "0.0.40",
|
|
61
|
+
"@bodhiapp/setup-modal-types": "0.0.40",
|
|
62
|
+
"@bodhiapp/setup-modal-v2-types": "0.0.40",
|
|
63
|
+
"@bodhiapp/bodhi-js-core": "0.0.40",
|
|
64
|
+
"@bodhiapp/ts-client": "0.1.35"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"react": "^18.3.0 || ^19.0.0"
|