function h(l){const c=l.shellOrigin,t=l.capabilities.user?.config??{},d=typeof t.id=="string"&&t.id!==""?t.id:null,f=t.owner===!0,g=t.canEdit===!0,v=t.profile===!0,_=t.email===!0;let w=0;const s=new Map;addEventListener("message",e=>{if(e.source!==parent||e.origin!==c)return;const r=e.data;if(!r||r.__frame_cap_r!==!0)return;const i=typeof r.id=="string"?r.id:null;if(!i)return;const n=s.get(i);n&&(s.delete(i),clearTimeout(n.timer),r.error?n.reject(r.error):n.resolve(r.result))});const u=e=>new Promise((r,i)=>{const n="u"+ ++w,P=setTimeout(()=>{s.delete(n),r(null)},2e4);s.set(n,{resolve:r,reject:i,timer:P}),parent.postMessage({__frame_cap:!0,cap:"user",id:n,method:e,args:[]},c)});let E=null;const p=()=>E??=v?u("profile").then(e=>{const r=e;return{name:typeof r?.name=="string"?r.name:null,avatarUrl:typeof r?.avatarUrl=="string"?r.avatarUrl:null}}):Promise.resolve({name:null,avatarUrl:null});let O=null;const U=()=>O??=_?u("email").then(e=>typeof e=="string"?e:null):Promise.resolve(null),a=l.pipe("user"),o=e=>()=>e().catch(()=>null),m=e=>()=>e().catch(()=>!1);l.mount("user",{id:o(a.wrap("id",()=>Promise.resolve(d))),isOwner:m(a.wrap("isOwner",()=>Promise.resolve(f))),canEdit:m(a.wrap("canEdit",()=>Promise.resolve(g))),name:o(a.wrap("name",()=>p().then(e=>e.name))),avatarUrl:o(a.wrap("avatarUrl",()=>p().then(e=>e.avatarUrl))),email:o(a.wrap("email",()=>U()))})}export{h as install};
