@camstack/addon-admin-ui 1.2.419 → 1.2.421
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/assets/{AddonAssetIcon-DYHQRlSp.js → AddonAssetIcon-BcUAeUFA.js} +1 -1
- package/dist/assets/{Addons-BOwupZ--.js → Addons-CMFKnFy_.js} +1 -1
- package/dist/assets/{AdminPage-BJe_yale.js → AdminPage-Pnx0mTsE.js} +1 -1
- package/dist/assets/{AdminSectionedPage-B_hL5DCA.js → AdminSectionedPage-Cwqk3VSC.js} +1 -1
- package/dist/assets/{AiProfiles-CVBWkEG0.js → AiProfiles-Cm-uW0cp.js} +1 -1
- package/dist/assets/{BrokerForm-D05-0PUD.js → BrokerForm-C29qpKHz.js} +1 -1
- package/dist/assets/{Build-DtTy0bzq.js → Build-jtQNSTVm.js} +1 -1
- package/dist/assets/{Calendars-Deib6Qp0.js → Calendars-DXVrSwsu.js} +1 -1
- package/dist/assets/{Cluster-TBUaIduv.js → Cluster-Dt4QC5gH.js} +1 -1
- package/dist/assets/{ClusterStepModel-CZN1ClvK.js → ClusterStepModel-nVqIETDq.js} +1 -1
- package/dist/assets/{CompositionEditor-Bfh1J2V0.js → CompositionEditor-CWfZxpvY.js} +1 -1
- package/dist/assets/{CompositionEditorPage-CqED2zZk.js → CompositionEditorPage-D2_5GID5.js} +1 -1
- package/dist/assets/{Data-CZKbDGBO.js → Data-PX9MYiMq.js} +1 -1
- package/dist/assets/{DeviceDetail-Dgfq4lG_.js → DeviceDetail-CvBViCpU.js} +1 -1
- package/dist/assets/{DeviceDoActionFields-DEoK4prj.js → DeviceDoActionFields-Vpw3Hlks.js} +1 -1
- package/dist/assets/{Devices-RAq86zJ-.js → Devices-NE3Jk6_G.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-HOvkjWNq.js → EmbedPlayerPage-o6tk8CLI.js} +1 -1
- package/dist/assets/{Identity-R4cnVy8H.js → Identity-DvZevqOL.js} +1 -1
- package/dist/assets/{IntegrationDetail-Q7o9YBAV.js → IntegrationDetail-pyZVXw9L.js} +1 -1
- package/dist/assets/{IntegrationHub-C14W-rYf.js → IntegrationHub-C--iFSMN.js} +1 -1
- package/dist/assets/{Integrations-BMw2OC2B.js → Integrations-B8URUnQX.js} +1 -1
- package/dist/assets/{Integrations-DbpbkIdW.js → Integrations-Cadxh0XR.js} +1 -1
- package/dist/assets/{Library-CwstIFCY.js → Library-DHn4yJN3.js} +1 -1
- package/dist/assets/{Locations-BgeLtFoo.js → Locations-CMXm68gm.js} +1 -1
- package/dist/assets/{Logs-ChtgfGqs.js → Logs-Bg5PD7yc.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CYuxuRh9.js → MotionZonesSettings-BAPe5lDr.js} +1 -1
- package/dist/assets/{MyAccess-DOROy27P.js → MyAccess-BvJqlxVR.js} +1 -1
- package/dist/assets/{Network-uM8Np7Ru.js → Network-Cq6PVeH5.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BrxuUwuY.js → NodeAddonsSettingsPanel-BK1RxciP.js} +1 -1
- package/dist/assets/{Notifications-DcnKiD3U.js → Notifications-Cwp9_it6.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BCMpHkjW.js → PrivacyMaskSettings-3MxMW9V1.js} +1 -1
- package/dist/assets/{Recordings-3-biF9OR.js → Recordings-ZhXXvJqY.js} +1 -1
- package/dist/assets/{ScanNetworkModal-DrptEMCC.js → ScanNetworkModal-_RdncTUH.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DlBI6DSc.js → SceneMonitorEditor-BTWYSCY4.js} +1 -1
- package/dist/assets/{SessionsList-CVEeQSUC.js → SessionsList-Dm6Me6Pk.js} +1 -1
- package/dist/assets/{Showroom-DmjsAM0j.js → Showroom-B6NjRCzE.js} +1 -1
- package/dist/assets/{System-g4XNE748.js → System-Q5wNMpYV.js} +1 -1
- package/dist/assets/{Terminal-DXot0903.js → Terminal-Bq2YkQer.js} +1 -1
- package/dist/assets/{Viewer-lkq8wIyw.js → Viewer-CA-_IKP2.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Bv_TLJRm.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DxkHv0jA.js} +1 -1
- package/dist/assets/{addon-icons-context-WQbdCczg.js → addon-icons-context-BcFthDce.js} +1 -1
- package/dist/assets/{archive-Bg_8z17t.js → archive-4K83r_1n.js} +1 -1
- package/dist/assets/{authed-media-B_Om8tL5.js → authed-media-B1N-Y_02.js} +1 -1
- package/dist/assets/{bell-off-BSOzEnNI.js → bell-off-BHt33UBf.js} +1 -1
- package/dist/assets/{boxes-Cq1rDwGo.js → boxes-BZgI7Qpt.js} +1 -1
- package/dist/assets/circle-slash-Blsoe4DV.js +1 -0
- package/dist/assets/client-CKGZv6zJ.js +358 -0
- package/dist/assets/{cloud-upload-D8aUm-st.js → cloud-upload-5ZRXO4G8.js} +1 -1
- package/dist/assets/crop-gRMkMnnt.js +1 -0
- package/dist/assets/{device-integration-icon-DSO1DJ6e.js → device-integration-icon-CgVkQy_G.js} +1 -1
- package/dist/assets/device-picker-model-C-bu65w9.js +1 -0
- package/dist/assets/dist-B51fr1vo.js +358 -0
- package/dist/assets/{dist-HP5i1qN3.js → dist-DtKcnSMJ.js} +1 -1
- package/dist/assets/{eraser-B4B4p4fp.js → eraser-Bgk8Dzm-.js} +1 -1
- package/dist/assets/{file-up-Ctnhm8uf.js → file-up-BDHV-8n7.js} +1 -1
- package/dist/assets/{hard-drive-download-DlkRlnTH.js → hard-drive-download-Cf7DR1zn.js} +1 -1
- package/dist/assets/{history-BLTh8Bem.js → history-BThcfo0X.js} +1 -1
- package/dist/assets/{hostInit-C-6yLsNX.js → hostInit-CU4FJ_9p.js} +1 -1
- package/dist/assets/{icons-DDZqoEZd.js → icons-hV-aAVBh.js} +1 -1
- package/dist/assets/{index-69_96GM2.js → index-AsTGrKva.js} +3 -3
- package/dist/assets/{key-xWSt8lR6.js → key-DKkIyX9P.js} +1 -1
- package/dist/assets/{key-round-C354dYrM.js → key-round-Dzvj04Ko.js} +1 -1
- package/dist/assets/{layers-Cw-gn0EU.js → layers-D6sO1vTO.js} +1 -1
- package/dist/assets/{list-ordered-DrDcQSlp.js → list-ordered-B8fDKjS-.js} +1 -1
- package/dist/assets/{location-owned-usage-C7tqRQmA.js → location-owned-usage-C7aYDcAR.js} +1 -1
- package/dist/assets/{log-in-OFkq8c7s.js → log-in-lHSUE2pa.js} +1 -1
- package/dist/assets/{memory-stick-B-4j6O2U.js → memory-stick-CttSJTx_.js} +1 -1
- package/dist/assets/{message-square-plus-cj0zDTGN.js → message-square-plus-CwcMKafs.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-119a86b4.js → mf-entry-bootstrap-0-c3f6e5ea.js} +2 -2
- package/dist/assets/{mic-off-CoyheUut.js → mic-off-Ip3w_Vtm.js} +1 -1
- package/dist/assets/{monitor-off-bZft5R2I.js → monitor-off-BZ83JVg4.js} +1 -1
- package/dist/assets/{monitor-smartphone-Hh8u9J69.js → monitor-smartphone-yIys4K1P.js} +1 -1
- package/dist/assets/mount-C-bu65w9.js +1 -0
- package/dist/assets/{notification-schedule-field-C9I2pgA_.js → notification-schedule-field-Dy4ByDYy.js} +1 -1
- package/dist/assets/{octagon-alert-BKn8JSN8.js → octagon-alert-B71ohghx.js} +1 -1
- package/dist/assets/{player-overlays-CdH-hgko.js → player-overlays-C20AJTgs.js} +1 -1
- package/dist/assets/{recycle-nDZ6TdhC.js → recycle-DhAxCder.js} +1 -1
- package/dist/assets/remoteEntry-9Elsv3BT.js +1 -0
- package/dist/assets/{scan-eye-DxnXj5B2.js → scan-eye-BbXV25vz.js} +1 -1
- package/dist/assets/{scissors-DbzjEHrL.js → scissors-WSGBgAVG.js} +1 -1
- package/dist/assets/{search-x-1g2n1cX3.js → search-x-CaqrjMNZ.js} +1 -1
- package/dist/assets/{send-DGe8QjVE.js → send-B-4ijiWE.js} +1 -1
- package/dist/assets/{settings-2-DJEPu36p.js → settings-2-BjwKRpE2.js} +1 -1
- package/dist/assets/{speaker-CS6yvVj7.js → speaker-__2EFvIp.js} +1 -1
- package/dist/assets/{src-BHgtK1NY.js → src-CIIJy_o8.js} +3 -3
- package/dist/assets/{timer-reset-BrMDnQ7I.js → timer-reset-CkaW1pT6.js} +1 -1
- package/dist/assets/{ungroup-BK7RJCny.js → ungroup-CqbpWLek.js} +1 -1
- package/dist/assets/{unlink-Ap2CYOyG.js → unlink-2_Gor_ZF.js} +1 -1
- package/dist/assets/{usb-69pet2vu.js → usb-Dbv88fxf.js} +1 -1
- package/dist/assets/{use-scenes-feed-AwInEa_e.js → use-scenes-feed-DxSvhMQ5.js} +1 -1
- package/dist/assets/{use-stationary-objects-CMs4zOau.js → use-stationary-objects-BllXyUsy.js} +1 -1
- package/dist/assets/useEventInvalidation-C-bu65w9.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BWsnYLI4.js → useNodeUrlSelection-DNAtiVHu.js} +1 -1
- package/dist/assets/user-round-tDoKxf4s.js +1 -0
- package/dist/assets/{user-x-D-5EhF7R.js → user-x-D3HnF7fF.js} +1 -1
- package/dist/assets/{video-BBl7guKu.js → video-Bkjg9omB.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-RNj3c6kK.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-LWvJP_B9.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +4 -3
- package/package.json +1 -1
- package/dist/assets/circle-slash-Cb-mJVlY.js +0 -1
- package/dist/assets/client-o5tMDxAT.js +0 -358
- package/dist/assets/crop-B1gR4lpF.js +0 -1
- package/dist/assets/device-picker-model-bsYvItQb.js +0 -1
- package/dist/assets/dist-DYqbaqnY.js +0 -358
- package/dist/assets/mount-bsYvItQb.js +0 -1
- package/dist/assets/remoteEntry-CXWWpr9N.js +0 -1
- package/dist/assets/useEventInvalidation-bsYvItQb.js +0 -1
- package/dist/assets/user-round-DDhN6bhd.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Ir as f,It as p,On as m,Pn as h,Qt as g,Tt as _,_i as v,ar as y,cn as b,cr as x,dt as S,fi as C,fn as w,nr as T,on as E,ot as D,pr as O,sn as k,yi as A}from"./player-overlays-CdH-hgko.js";import{n as j,r as M,t as N}from"./key-xWSt8lR6.js";import{c as P,o as F,u as I}from"./video-BBl7guKu.js";import{t as L}from"./history-BLTh8Bem.js";import{t as R}from"./key-round-C354dYrM.js";import{t as z}from"./monitor-smartphone-Hh8u9J69.js";import{t as B}from"./unlink-Ap2CYOyG.js";import{a as V,bi as H,i as ee,o as te,s as U,vi as ne,yi as re}from"./client-o5tMDxAT.js";import{Al as ie,An as W,Bl as ae,Bn as G,Dl as oe,Dn as K,Dr as se,El as ce,En as q,Er as le,Fl as ue,Ft as de,G as fe,Gl as pe,Ht as me,Il as he,Kl as ge,L as _e,Ll as ve,Ln as ye,Ml as be,N as xe,Nl as Se,Ol as Ce,P as we,Pl as Te,Qn as Ee,Rl as De,Rn as Oe,Tl as ke,Tn as Ae,X as je,Xl as Me,Z as Ne,Zn as J,ar as Pe,bn as Fe,en as Ie,gu as Y,jl as Le,jn as Re,kl as ze,kn as Be,ma as Ve,nn as He,on as Ue,rn as We,z as Ge,zl as Ke,zn as qe}from"./src-BHgtK1NY.js";import{t as Je}from"./useTranslation-Bc5yH9V9.js";import{C as Ye,J as Xe,Q as Ze,R as X,X as Qe,Y as $e,c as et,h as tt,p as nt,s as rt}from"./index-69_96GM2.js";import{t as it}from"./AdminSectionedPage-B_hL5DCA.js";import{t as at}from"./AdminPage-BJe_yale.js";import{_ as ot,a as st,b as ct,c as lt,d as ut,f as dt,g as ft,h as pt,i as mt,l as ht,m as gt,n as _t,o as vt,p as yt,s as bt,t as xt,u as St,v as Ct,x as wt,y as Tt}from"./SessionsList-CVEeQSUC.js";import{i as Et,n as Dt,r as Ot,t as kt}from"./IntegrationHub-C14W-rYf.js";import{n as At,t as jt}from"./addon-display-names-BkwMrExv.js";n();function Mt(){let e=J(),t=Y.useUtils(),n=wt(),{data:r,isLoading:a}=Se(),o=i(()=>r??[],[r]),s=Y.useQueries(e=>o.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),l=Y.auth.listLoginMethods.useQuery(),[d,f]=c(null),p=Ke({onSuccess:()=>void t.userManagement.listExternalIdentities.invalidate(),onError:e=>f(`Remove failed: ${e.message}`)}),m=i(()=>new Map((l.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[l.data]),h=o.flatMap((e,t)=>s[t]?.data??[]),g=h.map(e=>({...dt(e,n),kind:m.get(e.provider)??e.provider})),_=async t=>{let n=h.find(e=>ut(e)===t.id);n!==void 0&&await e({title:`Remove sign-in link`,message:`"${t.ownerName}" will no longer be able to sign in with this ${t.kind} account.`,confirmLabel:`Remove`,variant:`danger`})&&(f(null),p.mutate({userId:n.userId,provider:n.provider,subject:n.subject}))};return u(Tt,{notice:ct(d),onDismissNotice:()=>{f(null)},id:`external-identities`,title:`Sign-in links`,icon:I,description:`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`,children:u(ft,{rows:g,label:`sign-in links`,isLoading:a||s.some(e=>e.isLoading),loadError:s.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:`Remove`,icon:B,isAvailable:()=>!0,onRun:e=>void _(e),busyId:null,disabled:p.isPending}})})}n();function Nt(){let e=J(),t=s(),n=wt(),r=ie(),[a,o]=c(null),l=ue({onSuccess:()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),onError:e=>o(`Revoke failed: ${e.message}`)}),d=i(()=>(r.data??[]).map(e=>St(e,n)),[r.data,n]),f=async t=>{await e({title:`Revoke "${t.name}"?`,message:`Any client using this key loses access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(o(null),l.mutate({id:t.id}))};return u(Tt,{notice:ct(a),onDismissNotice:()=>{o(null)},id:`legacy-api-keys`,title:`Legacy API keys`,icon:L,description:`Keys from before scoped tokens. Nothing creates them any more; revoke them and issue a scoped token instead.`,children:u(ft,{rows:d,label:`legacy API keys`,isLoading:r.isLoading,loadError:r.isError?r.error?.message??`Request failed`:null,emptyText:`No legacy API keys.`,action:{label:`Revoke`,icon:p,isAvailable:()=>!0,onRun:e=>void f(e),busyId:l.isPending?l.variables?.id??null:null,disabled:l.isPending}})})}n();var Pt={one:`linked app`,many:`linked apps`};function Ft(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function It(){let e=J(),t=s(),n=be(),[r,a]=c(null),o=()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),l=he({onSuccess:o,onError:e=>a(`Revoke failed: ${e.message}`)}),d=ot(`oauth-session`,Pt,o),f=i(()=>(n.data??[]).map(e=>yt(e,e.scopes.map(Ft).join(`, `))),[n.data]),m=async t=>{await e({title:`Revoke the "${t.name}" link?`,message:`${t.name} loses access for ${t.ownerName} on its next call. Linking it again needs the account-link flow from the start.`,confirmLabel:`Revoke`,variant:`danger`})&&(a(null),l.mutate({id:t.id}))},h=l.isPending?l.variables?.id??null:null;return u(Tt,{notice:ct(r,d.outcome),onDismissNotice:()=>{a(null),d.dismiss()},id:`linked-apps`,title:`Linked apps`,icon:x,description:`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`,children:u(ft,{rows:f,label:`linked apps`,isLoading:n.isLoading,loadError:n.isError?n.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:`Revoke`,icon:p,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:l.isPending||d.busy},bulk:{revoke:d,noun:Pt,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:`Select revoked`,match:e=>e.status===`revoked`}]}})})}n();var Lt={one:`session`,many:`sessions`};function Rt(){let e=J(),t=Y.useUtils(),n=wt(),r=Y.auth.listSessions.useQuery(),[a,o]=c(null),s=()=>void t.auth.listSessions.invalidate(),l=Y.auth.revokeSessions.useMutation({onSuccess:s,onError:e=>o(`Sign out failed: ${e.message}`)}),d=ot(`login-session`,Lt,s),f=i(()=>(r.data??[]).map(e=>gt(e,n,{client:e=>st(e).label,method:vt})),[r.data,n]),p=async t=>{await e({title:`Sign out this session`,message:`${t.ownerName} on ${t.name} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(o(null),l.mutate({id:t.id}))};return u(Tt,{notice:ct(a,d.outcome),onDismissNotice:()=>{o(null),d.dismiss()},id:`login-sessions`,title:`Login sessions`,icon:z,description:`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`,children:u(ft,{rows:f,label:`sessions`,isLoading:r.isLoading,loadError:r.isError?r.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:`Sign out`,icon:F,isAvailable:e=>e.status===`active`,onRun:e=>void p(e),busyId:l.isPending&&l.variables!==void 0&&`id`in l.variables?l.variables.id:null,disabled:l.isPending||d.busy},bulk:{revoke:d,noun:Lt,isSelectable:e=>e.status===`active`}})})}function zt({token:e,label:t,onClose:n}){return u(Ae,{open:!0,onOpenChange:e=>!e&&n(),children:r(K,{width:`md`,scroll:`body`,children:[u(W,{children:u(Re,{children:`Token: ${t}`})}),r(q,{className:`space-y-3`,children:[u(`div`,{className:`rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),u(`div`,{className:`select-all break-all rounded-md border border-border bg-background p-2 font-mono text-[11px] text-foreground`,children:e})]}),r(Be,{children:[u(de,{value:e,label:`Copy`,srLabel:`token`}),u(G,{type:`button`,variant:`primary`,size:`sm`,onClick:n,children:`Done`})]})]})})}var Bt={token:`newToken`,scoped:`newScoped`,admin:`newAdmin`};n();var Vt=7,Ht=90,Ut=80;function Wt(e){let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=Ht?t:null}function Gt({open:e,users:t,onClose:n,onSubmitScoped:i,onSubmitAdmin:a,submitting:s,formError:l,awaitingProof:f}){let{user:p}=X(),m=p?.isAdmin===!0,h=m?null:p?.scopes??[],[g,_]=c(!1),[v,b]=c(t[0]?.id??``),[x,S]=c(``),[C,w]=c([{type:`capability`,target:``,access:[`view`,`create`]}]),[T,D]=c(``),[O,A]=c(String(Vt));d(()=>{e||(_(!1),b(t[0]?.id??``),S(``),w([{type:`capability`,target:``,access:[`view`,`create`]}]),D(``),A(String(Vt)))},[e,t]);let j=x.trim(),M=we(C),N=Wt(O),P=!g&&v!==``&&j.length>0&&C.length>0&&M===null&&!s,F=g&&m&&j.length>0&&j.length<=Ut&&N!==null&&!s&&!f;return u(Ge,{open:e,onClose:n,title:g?`Create admin token`:`Create token`,icon:g?k:R,error:l,width:`md`,testId:`create-token-dialog`,footer:r(G,{type:`button`,variant:g?`danger`:`primary`,size:`sm`,onClick:()=>{if(g){if(!F||N===null)return;a({name:j,expiresInDays:N});return}if(!P)return;let e=parseInt(T,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;i({userId:v,name:j,scopes:C,...t===void 0?{}:{expiresAt:t}})},disabled:g?!F:!P,children:[s||f?u(y,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):u(g?k:E,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),g?`Create admin token`:`Issue token`]}),children:r(`div`,{className:`space-y-3`,children:[m?r(`label`,{className:`flex items-start gap-2 text-sm text-foreground`,children:[u(`input`,{type:`checkbox`,className:`mt-0.5`,checked:g,onChange:e=>_(e.target.checked),"data-testid":`token-as-admin`}),r(`span`,{children:[u(`span`,{className:`font-medium`,children:`Administrator`}),u(`span`,{className:`block text-[11px] text-foreground-subtle`,children:`Off = scoped to a surface. On = full admin for scripts (audited, max 90 days).`})]})]}):null,g?u(`div`,{className:`space-y-1 rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] leading-relaxed text-foreground`,"data-testid":`admin-token-warning`,children:r(`p`,{children:[`An admin token acts as a `,u(`strong`,{children:`full administrator`}),`. Anyone holding it can do anything an admin can. Creating one asks you to confirm it is you.`]})}):null,g?null:r(`div`,{className:`space-y-1`,children:[u(Ue,{htmlFor:`token-user`,children:`On behalf of user`}),u(pe,{id:`token-user`,value:v,onChange:e=>b(e.target.value),options:t.map(e=>({value:e.id,label:e.username}))})]}),u(fe,{label:`Name`,required:!0,children:u(Me,{id:`token-name`,value:x,maxLength:Ut,onChange:e=>S(e.target.value),placeholder:g?`nightly-backup`:`cloudflare-tunnel-route`,autoFocus:!0})}),g?r(`div`,{className:`space-y-1`,children:[u(Ue,{htmlFor:`token-admin-days`,children:`Expires in (days)`}),u(Me,{id:`token-admin-days`,type:`number`,min:1,max:Ht,value:O,onChange:e=>A(e.target.value),state:N===null?`error`:`default`}),N===null?r(`p`,{className:`text-[11px] text-danger`,children:[`Expiry must be a whole number of days, 1 to `,Ht,`.`]}):r(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Whole number of days, 1 to `,Ht,`.`]})]}):r(o,{children:[r(`div`,{className:`space-y-1`,children:[u(Ue,{children:`Scopes`}),u(xe,{value:C,onChange:w,clampToParent:h}),M&&u(`p`,{className:`text-[10px] text-danger`,children:M}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`})]}),r(`div`,{className:`space-y-1`,children:[u(Ue,{htmlFor:`token-scoped-days`,children:`Expires in (days)`}),u(Me,{id:`token-scoped-days`,type:`number`,min:1,value:T,onChange:e=>D(e.target.value),placeholder:`30`}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Leave blank for non-expiring.`})]})]})]})})}n();var Kt={one:`token`,many:`tokens`};function qt(e){return e.type===`device`?`device:[${Ne(e.selector)}]`:`${e.type}:${e.target??``}`}function Jt({createRequested:e=!1,onCreateConsumed:t}){let{user:n}=X(),a=J(),o=s(),l=Y.useUtils(),f=wt(),{data:m,isLoading:h}=Se(),g=i(()=>m??[],[m]),_=Y.useQueries(e=>g.map(t=>e.userManagement.listScopedTokens({userId:t.id}))),v=Y.auth.listAdminTokens.useQuery(void 0,{enabled:n?.isAdmin===!0}),{requestProof:y,dialog:b}=mt(`Creating an admin token`),{state:x,openNew:S,close:C}=_e({newKey:Bt.token}),[w,T]=c(null),[E,D]=c(null),[O,k]=c(!1),[A,j]=c(null),[M,N]=c(null);d(()=>{e&&(S(),t?.())},[e,S,t]);let P=()=>{o.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),l.auth.listAdminTokens.invalidate(),l.auth.listAuthAudit.invalidate()},F=ke({onSuccess:({token:e,record:t})=>{P(),C(),D(null),j({token:e,label:t.name})},onError:e=>{T(`Create failed: ${e.message}`),D(`Create failed: ${e.message}`)}}),I=Y.auth.createAdminToken.useMutation({onSuccess:({token:e,record:t})=>{P(),C(),D(null),k(!1),j({token:e,label:t.name})},onError:e=>{T(`Create failed: ${e.message}`),D(`Create failed: ${e.message}`),k(!1)}}),L=ve({onSuccess:()=>{N(null),P()},onError:e=>{N(null),T(`Revoke failed: ${e.message}`)}}),z=Y.auth.revokeAdminToken.useMutation({onSuccess:()=>{N(null),P()},onError:e=>{N(null),T(`Revoke failed: ${e.message}`)}}),B=Ct(Kt,P),V=Date.now(),H=g.flatMap((e,t)=>(_[t]?.data??[]).map(t=>pt(t,e.id,f,t.scopes.map(qt).join(`, `),V))),ee=n?.isAdmin===!0?(v.data??[]).map(e=>ht(e,f,V)):[],te=[...H,...ee],U=_.find(e=>e.isError)?.error?.message??(v.isError?v.error?.message??`Request failed`:null),ne=async e=>{let t=e.kind===lt;await a({title:`Revoke "${e.name}"?`,message:t?`Every script using it loses access immediately. This cannot be undone.`:`${e.ownerName}'s scoped token stops working on its next use. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(T(null),N(e.id),t?z.mutate({id:e.id}):L.mutate({id:e.id}))},re=F.isPending||I.isPending;return r(`div`,{"data-testid":`tokens`,children:[b,u(Tt,{notice:ct(w,B.outcome),onDismissNotice:()=>{T(null),B.dismiss()},id:`tokens`,title:`Tokens`,icon:R,description:`Scoped tokens for a narrow surface, and admin tokens for full-administrator scripts. Revoking one stops it on its next use.`,children:u(ft,{rows:te,label:`tokens`,isLoading:h||_.some(e=>e.isLoading)||n?.isAdmin===!0&&v.isLoading,loadError:U,emptyText:`No tokens.`,action:{label:`Revoke`,icon:p,isAvailable:e=>e.status===`active`,onRun:e=>void ne(e),busyId:M,disabled:B.busy||M!==null},bulk:{revoke:B,noun:Kt,isSelectable:e=>e.status===`active`}})}),u(Gt,{open:x.mode===`new`,users:g.map(e=>({id:e.id,username:e.username})),onClose:()=>{C(),D(null),k(!1)},submitting:re,formError:E,awaitingProof:O,onSubmitScoped:e=>F.mutate({userId:e.userId,name:e.name,scopes:e.scopes,expiresAt:e.expiresAt}),onSubmitAdmin:e=>{(async()=>{T(null),D(null),k(!0);let t=await y();k(!1),t!==null&&I.mutate({...e,reauthToken:t})})()}}),A&&u(zt,{token:A.token,label:A.label,onClose:()=>j(null)})]})}var Yt={"share-link":`share links`,"admin-token":`admin tokens`,"login-session":`login sessions`};function Z(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Xt(e,t){let n=Z(e,`tokenId`);return Z(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Zt(e){return e.filter(e=>e!==null)}function Qt(e){let t=Z(e,`prefix`);return t===null?null:`Prefix ${t}…`}function $t(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:`Admin token "${Xt(n,t)}" created`,details:Zt([Qt(n),typeof e==`number`?`Expires ${bt(e)}`:null])}}case`admin-token-used`:{let e=Z(n,`path`);return{title:`Admin token "${Xt(n,t)}" used`,details:Zt([Qt(n),e===null?null:`Call ${e}`])}}case`admin-token-revoked`:return{title:`Admin token "${Xt(n,t)}" revoked`,details:Zt([Qt(n)])};case`credentials-revoked`:{let e=Z(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=Yt[e]??`${e}s`;return{title:`${typeof t==`number`?String(t):`?`} ${i} revoked in bulk`,details:Zt([typeof r==`number`&&r>0?`${String(r)} skipped`:null,Z(n,`ids`)===null?null:`Ids ${Z(n,`ids`)??``}`])}}case`second-factor-skipped`:{let e=Z(n,`method`),t=Z(n,`factors`);return{title:`Second factor skipped on a trusted network`,details:Zt([e===null?null:`Signed in with ${vt(e)}`,t===null?null:`Skipped: ${t.split(`,`).join(`, `)}`])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}n();var en=100;function tn(){let{user:e}=X();return e?.isAdmin?u(rn,{}):null}function nn(){let{data:e}=Se(),{data:t}=Y.auth.listAdminTokens.useQuery();return i(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.name);return{userNameById:n,tokenNameById:r}},[e,t])}function rn(){let e=Y.auth.listAuthAudit.useQuery({limit:en}),{userNameById:t,tokenNameById:n}=nn(),i=e.data??[];return r(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(w,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Authentication audit`}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[`Latest `,en,`, newest first`]})]}),u(`div`,{className:`p-4`,children:e.isLoading?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading audit trail…`]}):e.isError?r(`div`,{className:`text-[11px] text-danger`,children:[`Could not load the audit trail: `,e.error?.message??`Request failed`]}):i.length===0?r(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[u(`div`,{children:`No authentication events recorded yet.`}),u(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`})]}):u(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:i.map(e=>u(an,{record:e,userName:e.userId===void 0?null:t.get(e.userId)??e.userId,tokenNameById:n},e.id))})})]})}function an({record:e,userName:t,tokenNameById:n}){let i=$t(e,n);return r(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[r(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[u(`span`,{className:`font-medium text-foreground`,children:i.title}),u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:bt(e.at)})]}),r(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[t!==null&&u(`span`,{className:`text-foreground`,children:t}),e.ip!==void 0&&u(`span`,{className:`font-mono`,children:e.ip}),i.details.map(e=>u(`span`,{className:`font-mono`,children:e},e))]})]})}n();var Q={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,legacyApiKeys:`legacy-api-keys`,externalIdentities:`external-identities`,audit:`auth-audit`},on={[Q.scopedTokens]:Q.tokens,[Q.adminTokens]:Q.tokens};function sn(e){return[{id:Q.loginSessions,label:`Login sessions`,icon:z,render:()=>u(Rt,{})},{id:Q.linkedApps,label:`Linked apps`,icon:x,render:()=>u(It,{})},{id:Q.tokens,label:`Tokens`,icon:R,render:({createRequested:e,onCreateConsumed:t})=>u(Jt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:Q.shareLinks,label:`Share links`,icon:b,render:()=>u(_t,{})},...e?[{id:Q.legacyApiKeys,label:`Legacy API keys`,icon:L,render:()=>u(Nt,{})}]:[],{id:Q.externalIdentities,label:`Sign-in links`,icon:I,render:()=>u(Mt,{})},{id:Q.audit,label:`Audit`,icon:w,render:()=>u(tn,{})}]}function cn({createRequested:e=!1,onCreateConsumed:t}){let n=ie(),a=(n.data??[]).length>0,o=i(()=>sn(a),[a]),s=Et({ids:i(()=>o.map(e=>e.id),[o]),answered:!n.isLoading}),c=Qe(),[l]=Ze(),d=l.get(`integration`),f=d===null?void 0:on[d];if(f!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,f),u($e,{to:`?${e.toString()}`,replace:!0})}let p=o.find(e=>e.id===s.selectedId)??o[0],m=p?.id??Q.loginSessions;return n.isLoading?u(`div`,{className:`text-sm text-foreground-subtle`,"data-testid":`access-page`,children:`Loading…`}):r(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[u(Ie,{appearance:`pills`,value:m,onValueChange:e=>{c(`?${tt(l,e,null,null).toString()}`)},children:u(He,{"aria-label":`Credential kinds`,children:o.map(e=>r(We,{value:e.id,"data-testid":`access-kind-${e.id}`,children:[u(e.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),e.label]},e.id))})}),p===void 0?null:u(`div`,{role:`region`,"aria-label":p.label,"data-testid":`access-kind-body`,children:p.render({createRequested:e&&p.id===Q.tokens,onCreateConsumed:t??(()=>void 0)})},p.id)]})}function ln(e,t){if(e===Q.tokens)return r(G,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:t,children:[u(R,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`New token`]})}function un(){let[e,t]=c(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}n();var dn=[`oidcConnections`,`listConnections`],fn=[`oidcConnections`,`connectionFormSchema`],pn={displayName:`OpenID Connect`,icon:`shield-check`,issuerUrl:``,clientId:``,clientSecret:``,redirectUri:``,scopes:`openid profile email`,usernameClaim:`preferred_username`},mn=/^[a-z0-9][a-z0-9-]{0,63}$/;function hn(e){return e instanceof Error?e.message:String(e)}function gn(e,t){if(t)return typeof e==`string`&&e.length>0?e:void 0;if(re(e))return ne;if(typeof e==`string`&&e.length>0)return e;H(e)}function _n(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function vn({addonId:n}){let f=D(),h=s(),g=J(),_=_e({editKey:`oidcEdit`,newKey:`oidcNew`}),[v,y]=c(!1),[b,x]=c(null),[S,C]=c(``),[w,T]=c({...pn}),O=t(null),k=a({queryKey:[...dn,n],queryFn:async()=>f.trpcClient.oidcConnections.listConnections.query({})}),A=a({queryKey:fn,queryFn:async()=>f.trpcClient.oidcConnections.connectionFormSchema.query({})}),j=k.data??[],M=_n(A.data)?A.data:void 0,N=_.state,P=N.mode===`edit`?j.find(e=>e.id===N.id)??null:null;d(()=>{if(_.state.mode===`edit`&&P!==null){let e=`edit:${P.id}`;if(O.current===e)return;O.current=e,x(null),C(P.id),T(P.formValues===void 0?{...pn}:{...P.formValues});return}if(_.state.mode===`new`){if(O.current===`new`)return;O.current=`new`,x(null),C(``),T({...pn})}},[P,_.state]);let F=e(async()=>{await h.invalidateQueries({queryKey:dn})},[h]),I=l({mutationFn:async e=>f.trpcClient.oidcConnections.deleteConnection.mutate({id:e}),onSuccess:async()=>F()}),L=e(async e=>{await g({title:`Delete OIDC connection?`,message:`Remove “${e.displayName}” (${e.id}). The login button and IdP credentials for this id are dropped.`,confirmLabel:`Delete`,cancelLabel:`Cancel`,variant:`danger`})&&(await I.mutateAsync(e.id),_.state.mode===`edit`&&_.state.id===e.id&&(_.close(),O.current=null))},[g,I,_]),R=e(async()=>{let e=w.displayName,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){x(`Display name is required.`);return}let n=_.state.mode===`new`,r=n?S.trim():P?.id??``;if(n&&!mn.test(r)){x(`Instance id must be a lowercase slug (e.g. authentik, google).`);return}if(r===``){x(`That connection is no longer available.`);return}let i=gn(w.clientSecret,n),a=w.icon,o=w.issuerUrl,s=w.clientId,c=w.redirectUri,l=w.scopes,u=w.usernameClaim,d=u===`email`||u===`sub`?u:`preferred_username`;y(!0),x(null);try{n&&await f.trpcClient.oidcConnections.createConnection.mutate({id:r,displayName:t}),await f.trpcClient.oidcConnections.updateConnection.mutate({id:r,displayName:t,icon:typeof a==`string`?a:`shield-check`,issuerUrl:typeof o==`string`?o:``,clientId:typeof s==`string`?s:``,...i===void 0?{}:{clientSecret:i},redirectUri:typeof c==`string`?c:``,scopes:typeof l==`string`?l:`openid profile email`,usernameClaim:d}),await F(),_.close(),O.current=null}catch(e){x(hn(e))}finally{y(!1)}},[S,P?.id,_,w,F,f]),z=i(()=>[{key:`id`,header:`Id`,sortValue:e=>e.id,render:e=>u(`span`,{className:`font-mono text-xs text-foreground`,children:e.id})},{key:`name`,header:`Name`,sortValue:e=>e.displayName,render:e=>u(`span`,{className:`truncate font-medium text-foreground`,children:e.displayName})},{key:`issuer`,header:`Issuer`,sortValue:e=>e.issuerUrl,render:e=>u(`span`,{className:`truncate text-xs text-foreground-muted`,children:e.issuerUrl===``?`—`:e.issuerUrl})},{key:`status`,header:`Status`,notSortableReason:`Badge`,render:e=>u(Pe,{variant:e.configured?`success`:`warning`,children:e.configured?`Configured`:`Not configured`})},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>r(`div`,{className:`flex justify-end gap-1`,children:[u(G,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),_.openEdit(e.id)},children:`Edit`}),u(G,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":`Delete ${e.displayName}`,title:`Delete`,onClick:t=>{t.stopPropagation(),L(e)},children:u(p,{className:`h-3.5 w-3.5 text-danger`})})]})}],[_,L]),B=_.state.mode===`new`,V=B||P!==null,H=B?`new`:P===null?`closed`:`edit:${P.id}:${P.configured?`cfg`:`empty`}`;return r(`div`,{className:`flex min-h-0 flex-col gap-3`,"data-testid":`oidc-settings-connections`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[r(`p`,{className:`text-sm text-foreground-muted`,children:[`Each row is one IdP. Redirect URI:`,` `,u(`span`,{className:`font-mono text-xs`,children:`/addon/${n}/<id>/callback`})]}),r(G,{type:`button`,size:`sm`,"data-testid":`oidc-connections-add`,onClick:()=>_.openNew(),children:[u(m,{className:`h-3.5 w-3.5`}),`Add connection`]})]}),k.isError?u(`p`,{className:`text-sm text-danger`,children:`Could not load connections.`}):null,k.isPending?u(qe,{className:`h-32 w-full`}):u(me,{columns:z,rows:j,rowKey:e=>e.id,pageSize:25,mobileMode:`scroll`,emptyMessage:`No OIDC connections yet. Add one to register an IdP.`,onRowClick:e=>_.openEdit(e.id),defaultSort:{columnKey:`name`,dir:`asc`}}),u(Ge,{open:V,onClose:()=>{_.close(),x(null),O.current=null},title:B?`Add OIDC connection`:`Edit ${P?.displayName??`connection`}`,icon:E,width:`xl`,testId:`oidc-connection-editor`,error:b,footer:u(G,{type:`button`,size:`sm`,disabled:v||B&&S.trim()===``,onClick:()=>void R(),children:v?`Saving…`:`Save`}),children:V?r(o,{children:[B?r(`div`,{children:[u(Ue,{htmlFor:`oidc-connection-id`,children:`Instance id`}),u(Me,{id:`oidc-connection-id`,value:S,onChange:e=>C(e.target.value),placeholder:`authentik`,autoComplete:`off`}),u(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:`URL slug — appears in /addon/${n}/<id>/callback. Stable; renaming is not supported after save.`})]}):r(`p`,{className:`text-sm text-foreground-muted`,children:[`Instance id: `,u(`span`,{className:`font-mono`,children:P?.id})]}),M===void 0?u(`p`,{className:`text-sm text-foreground-muted`,children:`Loading form…`}):u(Fe,{schema:M,values:w,onChange:T,bare:!0},H)]}):null})]})}n();var yn=3e4,bn=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],xn={title:`Authentication`,subtitle:`Login providers (local password, OIDC, SAML) and second-factor providers (passkeys / WebAuthn). They run in parallel — enable or disable each independently; disabling one only removes that method, local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Sn(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:j,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`Scoped tokens, admin tokens and sessions are managed from Identity → Tokens & sessions.`],setupSteps:[`A fresh hub has one account, admin / changeme — the first sign-in asks for a new password. Add users from Users → New user.`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:P,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Choose a stable instance id (slug). Set the IdP redirect URI to `https://<this-hub>/addon/auth-oidc/<id>/callback`.",`In Settings below, Add connection — enter the id, issuer, and credentials; Save.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:P,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:g,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:g,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:E,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Cn(){let e=se({capName:bn[0].capName},{refetchInterval:yn}),t=se({capName:bn[1].capName},{refetchInterval:yn}),n=le(void 0,{refetchInterval:yn}),r=i(()=>jt(n.data??[]),[n.data]),a=i(()=>{let n=[],i=[e.data??[],t.data??[]];for(let[e,t]of bn.entries())for(let a of i[e]??[])n.push({addonId:a.addonId,displayName:r.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,r]),o=[{id:`authentication`,label:`Authentication providers`,install:{capability:bn[0].capName,label:xn.installLabel},entries:a.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:E,...At(e.isActive),render:()=>u(Dt,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:u(Pe,{variant:`info`,className:Ot,children:e.stageBadge}),settingsContent:e.addonId.startsWith(`auth-oidc`)?u(vn,{addonId:e.addonId}):void 0,panels:[{id:`about`,title:`About`,icon:Sn(e.addonId).icon,content:u(wn,{addonId:e.addonId})}]})}))}];return u(kt,{embedded:!0,icon:E,title:xn.title,subtitle:xn.subtitle,groups:o,isLoading:e.isLoading||t.isLoading,emptyTitle:xn.emptyTitle,emptyDescription:xn.emptyDescription})}function wn({addonId:e}){let t=Sn(e),n=t.icon;return r(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[r(`div`,{className:`flex items-start gap-2.5`,children:[u(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),u(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),u(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>u(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&r(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[u(M,{className:`h-3 w-3`}),`Setup steps`]}),u(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>u(`li`,{children:e},t))})]}),e===`local-auth`&&r(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[u(O,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),r(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,u(Xe,{to:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,u(Xe,{to:`/system/identity?tab=users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Tn({userId:e,username:t,onClose:n}){let i=J(),a=Y.useUtils(),o=Le({userId:e}),s=Y.auth.listLoginMethods.useQuery(),c=Ke({onSuccess:()=>void a.userManagement.listExternalIdentities.invalidate()}),l=new Map((s.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),d=o.data??[],f=async(n,r)=>{await i({title:`Remove sign-in link`,message:`"${t}" will no longer be able to sign in with this ${r} account.`,confirmLabel:`Remove`,variant:`danger`})&&c.mutate({userId:e,provider:n.provider,subject:n.subject})};return u(Ae,{open:!0,onOpenChange:e=>!e&&n(),children:r(K,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[u(W,{children:r(Re,{className:`flex items-center gap-2`,children:[u(x,{className:`h-4 w-4 text-primary`}),r(`span`,{children:[`Linked sign-in accounts`,r(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,u(`span`,{className:`font-mono`,children:t})]})]})]})}),u(q,{className:`space-y-3`,children:o.isLoading?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}):d.length===0?u(`p`,{className:`text-xs text-foreground-subtle`,children:`No linked accounts. Only the user can link one, from their own profile page.`}):u(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:d.map(e=>{let t=l.get(e.provider),n=t??e.provider;return r(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[r(`div`,{className:`flex-1 min-w-0`,children:[r(`div`,{className:`font-medium text-foreground truncate`,children:[n,t===void 0&&u(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:`provider unavailable`})]}),r(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),r(`button`,{onClick:()=>void f(e,n),disabled:c.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u(B,{className:`h-3 w-3`}),`Remove`]})]},`${e.provider}|${e.subject}`)})})}),u(Be,{children:u(G,{onClick:n,variant:`secondary`,children:`Close`})})]})})}function En({userId:e,username:t,onClose:n}){let i=s(),a=J(),c=ze({userId:e}),l=c.data,d=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=Ce({onSuccess:()=>{d(),n()}}),p=c.isLoading?`loading`:l?.enabled?`enrolled`:`not_enrolled`;return u(Ae,{open:!0,onOpenChange:e=>!e&&n(),children:r(K,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[u(W,{children:r(Re,{className:`flex items-center gap-2`,children:[u(g,{className:`h-4 w-4 text-primary`}),r(`span`,{children:[`Two-factor authentication`,r(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,u(`span`,{className:`font-mono`,children:t})]})]})]})}),r(q,{className:`space-y-4`,children:[p===`loading`&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(y,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&r(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[u(O,{className:`h-4 w-4 mt-0.5 shrink-0`}),r(`div`,{children:[u(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),u(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&l&&r(o,{children:[r(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[u(C,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),r(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[u(`div`,{className:`font-medium`,children:`2FA is active`}),r(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,l.confirmedAt?new Date(l.confirmedAt).toLocaleString():`—`]})]})]}),u(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),r(`div`,{className:`flex justify-end gap-2`,children:[u(G,{onClick:n,variant:`secondary`,children:`Close`}),r(`button`,{onClick:async()=>{await a({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&f.mutate({userId:e})},disabled:f.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[f.isPending?u(y,{className:`h-3 w-3 animate-spin`}):u(S,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}n();function Dn({userId:e,username:t,onClose:n}){let{user:i,logout:a}=X(),o=i?.id===e,s=J(),l=Y.useUtils(),d=Y.auth.listSessions.useQuery({userId:e}),[f,p]=c(null),m=Y.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(o&&`userId`in t){a();return}l.auth.listSessions.invalidate()},onError:e=>p(`Sign out failed: ${e.message}`)}),h=async e=>{await s({title:`Sign out this session`,message:`"${t}" on ${st(e.client).label} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(p(null),m.mutate({id:e.id}))},g=async()=>{await s({title:`Sign out everywhere`,message:o?`Every session of your own account ends, this browser included: you will be signed out here too.`:`Every session of "${t}" ends at once; each device has to sign in again.`,confirmLabel:`Sign out everywhere`,variant:`danger`})&&(p(null),m.mutate({userId:e}))},_=m.isPending&&m.variables!==void 0&&`id`in m.variables?m.variables.id:null;return u(Ae,{open:!0,onOpenChange:e=>!e&&n(),children:r(K,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[u(W,{children:r(Re,{className:`flex items-center gap-2`,children:[u(z,{className:`h-4 w-4 text-primary`}),r(`span`,{children:[`Active sessions`,r(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,u(`span`,{className:`font-mono`,children:t})]})]})]})}),r(q,{className:`space-y-3`,children:[f!==null&&u(`div`,{className:`text-[11px] text-danger`,children:f}),u(xt,{sessions:d.data??[],isLoading:d.isLoading,loadError:d.isError?d.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void h(e),revokingId:_})]}),r(Be,{className:`justify-between`,children:[r(`button`,{onClick:()=>void g(),disabled:m.isPending||(d.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[m.isPending&&_===null?u(y,{className:`h-3 w-3 animate-spin`}):u(F,{className:`h-3 w-3`}),`Sign out everywhere`]}),u(G,{onClick:n,variant:`secondary`,children:`Close`})]})]})})}function On({icon:e,label:t,count:n,all:i,total:a}){return r(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[u(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:t}),u(`span`,{className:n===0?`text-foreground-subtle`:`font-medium text-foreground`,children:n===0?`none`:i?`all ${a}`:`${n} of ${a}`})]})}function kn({scopes:e,isAdmin:t,invalidReason:n}){let i=D(),s=a({queryKey:[`auth`,`previewScope`,e,t],enabled:n===null,queryFn:()=>i.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:t})}),{data:c}=Ve({projection:`slim`}),l=c?.length??0;if(n!==null)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:r(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[u(k,{className:`h-3 w-3 shrink-0`}),n]})});if(s.isLoading)return r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[u(y,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(s.isError||!s.data)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let d=s.data;return u(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:d.isAdmin?r(`p`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):r(o,{children:[u(On,{icon:f,label:`Devices they can see`,count:d.device.view.deviceCount,all:d.device.view.all,total:l}),u(On,{icon:h,label:`Devices they can operate`,count:d.device.create.deviceCount,all:d.device.create.all,total:l}),u(On,{icon:p,label:`Devices they can delete`,count:d.device.delete.deviceCount,all:d.device.delete.all,total:l}),r(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,d.system.length===0?`none`:d.system.join(`, `),d.capabilities.length>0&&r(o,{children:[` · Extra capabilities: `,d.capabilities.map(e=>e.name).join(`, `)]}),d.addons.length>0&&r(o,{children:[` · Addons: `,d.addons.map(e=>e.name).join(`, `)]})]}),d.device.view.deviceCount===0&&u(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}n();function An(e){let t=te(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function jn(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:V({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Mn({user:e,onClose:t,onSubmit:n,submitting:a,callerScopes:s}){let l=i(()=>An(e.scopes??[]),[e.scopes]),[d,f]=c(l),[p,m]=c(l.mode===`advanced`),h=i(()=>jn(d),[d]),g=!e.isAdmin&&d.mode===`role`&&d.roleId===null,_=i(()=>e.isAdmin?null:d.mode===`role`&&d.roleId===null?`Pick what this user can do to see the result.`:we(h),[e.isAdmin,d.mode,d.roleId,h]),b=e=>f({...d,...e});return u(Ae,{open:!0,onOpenChange:e=>!e&&t(),children:r(K,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(W,{children:[r(Re,{children:[`Access — `,e.username]}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),r(q,{className:`space-y-4`,children:[g&&r(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[u(k,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),r(`p`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:`No access.`}),` `,r(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),r(`section`,{className:`space-y-2`,children:[u(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),u(`div`,{className:`space-y-1.5`,children:ee.map(e=>{let t=d.mode===`role`&&d.roleId===e.id;return r(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${t?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[u(`input`,{type:`radio`,name:`access-role`,checked:t,onChange:()=>b({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),r(`span`,{className:`min-w-0`,children:[u(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),u(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),r(`button`,{type:`button`,onClick:()=>{if(!p){f({...d,mode:`advanced`,advancedScopes:h}),m(!0);return}m(!1),f(An(d.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[u(p?A:v,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),p&&r(`div`,{className:`rounded-lg border border-border p-2`,children:[u(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),u(xe,{value:d.advancedScopes,onChange:e=>b({mode:`advanced`,advancedScopes:e}),clampToParent:s,emptyHint:r(o,{children:[`No grants.`,` `,u(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),d.mode===`role`&&r(`section`,{className:`space-y-2`,children:[u(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),u(je,{value:d.selector,onChange:e=>b({selector:e}),includeLinked:d.includeLinked,onIncludeLinkedChange:e=>b({includeLinked:e}),clampToDeviceIds:null})]}),r(`section`,{className:`space-y-2`,children:[u(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:d.mode===`role`?`3 · Result`:`2 · Result`}),u(kn,{scopes:h,isAdmin:e.isAdmin,invalidReason:_})]})]}),r(Be,{children:[u(G,{variant:`outline`,size:`sm`,onClick:t,children:`Cancel`}),u(G,{size:`sm`,onClick:()=>n([...h]),disabled:a||_!==null,children:a?u(y,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}n();var $=8;function Nn(){return{username:``,password:``,isAdmin:!1}}function Pn(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function Fn(e){return e instanceof Error?e.message:`Something went wrong`}function In(){let e=s(),{user:t}=X(),{state:n,openNew:i,openEdit:a,close:l}=_e(),[f,v]=c(null),[b,S]=c(null),[C,w]=c(!1),{data:T,isLoading:D,isError:O,error:k,refetch:A}=Se(),j=J(),M=Ee(),P=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),F=ce(),I=oe({onSuccess:P}),L=ae({onSuccess:P}),R=Te({onSuccess:P}),B=De({onSuccess:()=>{P(),H(null)}}),[V,H]=c(null),[ee,te]=c(null),[U,ne]=c(null),[re,ie]=c(null),W=T??[],K=n.mode===`edit`?W.find(e=>e.id===n.id)??null:null,se=()=>{v(null),S(null),w(!1),F.reset(),L.reset(),l()};d(()=>{if(n.mode===`closed`){v(null),S(null),w(!1);return}if(n.mode===`new`){v(e=>e!==null&&e.id===void 0?e:Nn());return}if(K===null){D||l();return}v(e=>e?.id===K.id?e:Pn(K))},[n,K,D,l]);let q=n.mode===`new`&&f!==null&&f.id===void 0||n.mode===`edit`&&f!==null&&K!==null;async function le(e){await j({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&(I.mutate({id:e.id}),n.mode===`edit`&&n.id===e.id&&se())}async function ue(e){let t=await M({title:`Reset password`,message:`Set a new password for "${e.username}".`,label:`New password`,inputType:`password`,placeholder:`At least 8 characters`,confirmLabel:`Continue`,validate:e=>e.length<$?`Password must be at least ${String($)} characters.`:null});t===null||t.length===0||await j({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&R.mutate({id:e.id,newPassword:t})}function de(e,t){t!==e.isAdmin&&L.mutate({id:e.id,isAdmin:t})}async function pe(){if(f!==null){S(null);try{if(f.id===void 0){let e=f.username.trim();if(e===``||f.password.length<$)return;await F.mutateAsync({username:e,password:f.password,isAdmin:f.isAdmin})}else await L.mutateAsync({id:f.id,isAdmin:f.isAdmin});P(),se()}catch(e){S(Fn(e))}}}function he(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let ve=F.isPending||L.isPending,be=f!==null&&f.id===void 0&&f.username.trim()!==``&&f.password.length>=$,xe=f!==null&&f.id!==void 0,Ce=ve||(f?.id===void 0?!be:!xe),we=e=>I.isPending&&I.variables?.id===e.id||L.isPending&&L.variables?.id===e.id||R.isPending&&R.variables?.id===e.id;return r(at,{embedded:!0,icon:_,title:`Users`,subtitle:`Hub accounts, admin flag, access scopes, sessions and sign-in links.`,actions:r(G,{size:`sm`,type:`button`,onClick:()=>{S(null),i()},children:[u(m,{className:`h-3.5 w-3.5`}),`Create User`]}),children:[O&&u(ye,{title:`Could not load users`,message:Fn(k),onRetry:()=>void A()}),D&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}),!D&&!O&&W.length===0&&u(Oe,{icon:_,title:`No users yet`,description:`Create a user to grant hub access.`}),!D&&!O&&W.length>0&&u(me,{columns:[{key:`username`,header:`Username`,sortValue:e=>e.username,render:e=>u(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`isAdmin`,header:`Admin`,nowrap:!0,sortValue:e=>+!!e.isAdmin,render:e=>u(`span`,{onClick:e=>e.stopPropagation(),children:r(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[u(`input`,{type:`checkbox`,checked:e.isAdmin,onChange:t=>de(e,t.target.checked),disabled:we(e),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),u(`span`,{className:e.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:e.isAdmin?`Admin`:`Regular`})]})})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?u(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):u(`span`,{onClick:e=>e.stopPropagation(),children:r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>H(e),title:`Configure access`,children:[u(E,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u(Ln,{scopes:e.scopes??[]})]})})},{key:`createdAt`,header:`Created`,nowrap:!0,sortValue:e=>e.createdAt,render:e=>u(`span`,{className:`text-foreground-subtle`,children:he(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:e=>{let n=we(e),i=e.id!==t?.id&&e.totpEnabled;return r(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>a(e.id),disabled:n,title:`Edit user`,children:[u(h,{className:`h-3 w-3`}),`Edit`]}),i&&r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>te(e),disabled:n,title:`Remove two-factor authentication`,children:[u(g,{className:`h-3 w-3`}),`Remove 2FA`]}),r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ne(e),disabled:n,title:`Linked sign-in accounts`,children:[u(x,{className:`h-3 w-3`}),`Sign-in links`]}),r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ie(e),disabled:n,title:`Active sessions`,children:[u(z,{className:`h-3 w-3`}),`Sessions`]}),r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void ue(e),disabled:n,title:`Reset password`,children:[u(N,{className:`h-3 w-3`}),`Reset password`]}),r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void le(e),disabled:n,title:`Delete user`,className:`text-danger hover:bg-danger/10`,children:[n?u(y,{className:`h-3 w-3 animate-spin`}):u(p,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:W,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,mobileMode:`scroll`,onRowClick:e=>a(e.id)}),u(Ge,{open:q,onClose:se,title:f?.id===void 0?`Create User`:`Edit ${f.username||`user`}`,icon:_,error:b,testId:`user-form-dialog`,footer:u(G,{size:`sm`,type:`button`,disabled:Ce,onClick:()=>void pe(),children:ve?r(o,{children:[u(y,{className:`h-3.5 w-3.5 animate-spin`}),`Saving…`]}):f?.id===void 0?`Create`:`Save`}),children:f!==null&&r(`div`,{className:`space-y-3`,children:[u(fe,{label:`Username`,required:f.id===void 0,children:u(Me,{value:f.username,onChange:e=>v({...f,username:e.target.value}),placeholder:`john`,autoFocus:f.id===void 0,disabled:f.id!==void 0,"data-testid":`user-form-username`})}),f.id===void 0&&u(fe,{label:`Password`,required:!0,description:`At least ${String($)} characters.`,children:u(ge,{value:f.password,onValueChange:e=>v({...f,password:e}),shown:C,onToggleShown:()=>w(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),u(fe,{label:`Admin`,description:`Unrestricted access to every capability and device.`,children:r(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[u(`input`,{type:`checkbox`,checked:f.isAdmin,onChange:e=>v({...f,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),u(`span`,{children:`Admin`})]})}),f.id!==void 0&&u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`})]})}),ee&&u(En,{userId:ee.id,username:ee.username,onClose:()=>te(null)}),U&&u(Tn,{userId:U.id,username:U.username,onClose:()=>ne(null)}),re&&u(Dn,{userId:re.id,username:re.username,onClose:()=>ie(null)}),V&&u(Rn,{user:V,onClose:()=>H(null),onSubmit:e=>B.mutate({userId:V.id,scopes:e}),submitting:B.isPending})]})}function Ln({scopes:e}){if(e.length===0)return u(`span`,{className:`font-medium text-warning`,children:`No access`});let t=te(e);return t===null?r(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):r(`span`,{className:`text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:U(t.roleId).label}),` ·`,` `,Ne(t.selector)]})}function Rn(e){let{user:t}=X(),n=t?.isAdmin===!0;return u(Mn,{...e,callerScopes:n?null:t?.scopes??[]})}var zn={"api-keys":Q.tokens,"linked-sessions":Q.linkedApps};function Bn(){let{t:e}=Je(),[t]=Ze(),n=un(),r=zn[t.get(`tab`)??``];if(r!==void 0)return u($e,{to:nt(`access`,{integration:r}),replace:!0});let i=Ye(`/system/identity`,{t:e,isAdmin:!0})??{icon:T,title:e(`system.identity`,`Identity & Access`)},a=t.get(`tab`)??`users`,o=t.get(`integration`),s=a===et.access.tab?ln(o,n.requestCreate):void 0;return u(it,{icon:i.icon,title:i.title,defaultSection:`users`,sectionsLabel:`${i.title} sections`,actions:s,sections:[{id:`users`,label:`Users`,content:u(In,{})},{id:et.access.tab,label:`Tokens & sessions`,content:u(cn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate}),ownedParams:rt.concat([Bt.token,Bt.scoped,Bt.admin])},{id:et.authentication.tab,label:`Authentication`,content:u(Cn,{}),ownedParams:rt}]})}export{Bn as IdentityPage};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Ir as f,It as p,On as m,Pn as h,Qt as g,Tt as _,_i as v,ar as y,cn as b,cr as x,dt as S,fi as C,fn as w,nr as T,on as E,ot as D,pr as O,sn as k,yi as A}from"./player-overlays-C20AJTgs.js";import{n as j,r as M,t as N}from"./key-DKkIyX9P.js";import{c as P,o as F,u as I}from"./video-Bkjg9omB.js";import{t as L}from"./history-BThcfo0X.js";import{t as R}from"./key-round-Dzvj04Ko.js";import{t as z}from"./monitor-smartphone-yIys4K1P.js";import{t as B}from"./unlink-2_Gor_ZF.js";import{a as V,bi as H,i as ee,o as te,s as U,vi as ne,yi as re}from"./client-CKGZv6zJ.js";import{Al as ie,An as W,Bl as ae,Bn as G,Dl as oe,Dn as K,Dr as se,El as ce,En as q,Er as le,Fl as ue,Ft as de,G as fe,Gl as pe,Ht as me,Il as he,Kl as ge,L as _e,Ll as ve,Ln as ye,Ml as be,N as xe,Nl as Se,Ol as Ce,P as we,Pl as Te,Qn as Ee,Rl as De,Rn as Oe,Tl as ke,Tn as Ae,X as je,Xl as Me,Z as Ne,Zn as J,ar as Pe,bn as Fe,en as Ie,gu as Y,jl as Le,jn as Re,kl as ze,kn as Be,ma as Ve,nn as He,on as Ue,rn as We,z as Ge,zl as Ke,zn as qe}from"./src-CIIJy_o8.js";import{t as Je}from"./useTranslation-Bc5yH9V9.js";import{C as Ye,J as Xe,Q as Ze,R as X,X as Qe,Y as $e,c as et,h as tt,p as nt,s as rt}from"./index-AsTGrKva.js";import{t as it}from"./AdminSectionedPage-Cwqk3VSC.js";import{t as at}from"./AdminPage-Pnx0mTsE.js";import{_ as ot,a as st,b as ct,c as lt,d as ut,f as dt,g as ft,h as pt,i as mt,l as ht,m as gt,n as _t,o as vt,p as yt,s as bt,t as xt,u as St,v as Ct,x as wt,y as Tt}from"./SessionsList-Dm6Me6Pk.js";import{i as Et,n as Dt,r as Ot,t as kt}from"./IntegrationHub-C--iFSMN.js";import{n as At,t as jt}from"./addon-display-names-BkwMrExv.js";n();function Mt(){let e=J(),t=Y.useUtils(),n=wt(),{data:r,isLoading:a}=Se(),o=i(()=>r??[],[r]),s=Y.useQueries(e=>o.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),l=Y.auth.listLoginMethods.useQuery(),[d,f]=c(null),p=Ke({onSuccess:()=>void t.userManagement.listExternalIdentities.invalidate(),onError:e=>f(`Remove failed: ${e.message}`)}),m=i(()=>new Map((l.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[l.data]),h=o.flatMap((e,t)=>s[t]?.data??[]),g=h.map(e=>({...dt(e,n),kind:m.get(e.provider)??e.provider})),_=async t=>{let n=h.find(e=>ut(e)===t.id);n!==void 0&&await e({title:`Remove sign-in link`,message:`"${t.ownerName}" will no longer be able to sign in with this ${t.kind} account.`,confirmLabel:`Remove`,variant:`danger`})&&(f(null),p.mutate({userId:n.userId,provider:n.provider,subject:n.subject}))};return u(Tt,{notice:ct(d),onDismissNotice:()=>{f(null)},id:`external-identities`,title:`Sign-in links`,icon:I,description:`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`,children:u(ft,{rows:g,label:`sign-in links`,isLoading:a||s.some(e=>e.isLoading),loadError:s.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:`Remove`,icon:B,isAvailable:()=>!0,onRun:e=>void _(e),busyId:null,disabled:p.isPending}})})}n();function Nt(){let e=J(),t=s(),n=wt(),r=ie(),[a,o]=c(null),l=ue({onSuccess:()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),onError:e=>o(`Revoke failed: ${e.message}`)}),d=i(()=>(r.data??[]).map(e=>St(e,n)),[r.data,n]),f=async t=>{await e({title:`Revoke "${t.name}"?`,message:`Any client using this key loses access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(o(null),l.mutate({id:t.id}))};return u(Tt,{notice:ct(a),onDismissNotice:()=>{o(null)},id:`legacy-api-keys`,title:`Legacy API keys`,icon:L,description:`Keys from before scoped tokens. Nothing creates them any more; revoke them and issue a scoped token instead.`,children:u(ft,{rows:d,label:`legacy API keys`,isLoading:r.isLoading,loadError:r.isError?r.error?.message??`Request failed`:null,emptyText:`No legacy API keys.`,action:{label:`Revoke`,icon:p,isAvailable:()=>!0,onRun:e=>void f(e),busyId:l.isPending?l.variables?.id??null:null,disabled:l.isPending}})})}n();var Pt={one:`linked app`,many:`linked apps`};function Ft(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function It(){let e=J(),t=s(),n=be(),[r,a]=c(null),o=()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),l=he({onSuccess:o,onError:e=>a(`Revoke failed: ${e.message}`)}),d=ot(`oauth-session`,Pt,o),f=i(()=>(n.data??[]).map(e=>yt(e,e.scopes.map(Ft).join(`, `))),[n.data]),m=async t=>{await e({title:`Revoke the "${t.name}" link?`,message:`${t.name} loses access for ${t.ownerName} on its next call. Linking it again needs the account-link flow from the start.`,confirmLabel:`Revoke`,variant:`danger`})&&(a(null),l.mutate({id:t.id}))},h=l.isPending?l.variables?.id??null:null;return u(Tt,{notice:ct(r,d.outcome),onDismissNotice:()=>{a(null),d.dismiss()},id:`linked-apps`,title:`Linked apps`,icon:x,description:`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`,children:u(ft,{rows:f,label:`linked apps`,isLoading:n.isLoading,loadError:n.isError?n.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:`Revoke`,icon:p,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:l.isPending||d.busy},bulk:{revoke:d,noun:Pt,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:`Select revoked`,match:e=>e.status===`revoked`}]}})})}n();var Lt={one:`session`,many:`sessions`};function Rt(){let e=J(),t=Y.useUtils(),n=wt(),r=Y.auth.listSessions.useQuery(),[a,o]=c(null),s=()=>void t.auth.listSessions.invalidate(),l=Y.auth.revokeSessions.useMutation({onSuccess:s,onError:e=>o(`Sign out failed: ${e.message}`)}),d=ot(`login-session`,Lt,s),f=i(()=>(r.data??[]).map(e=>gt(e,n,{client:e=>st(e).label,method:vt})),[r.data,n]),p=async t=>{await e({title:`Sign out this session`,message:`${t.ownerName} on ${t.name} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(o(null),l.mutate({id:t.id}))};return u(Tt,{notice:ct(a,d.outcome),onDismissNotice:()=>{o(null),d.dismiss()},id:`login-sessions`,title:`Login sessions`,icon:z,description:`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`,children:u(ft,{rows:f,label:`sessions`,isLoading:r.isLoading,loadError:r.isError?r.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:`Sign out`,icon:F,isAvailable:e=>e.status===`active`,onRun:e=>void p(e),busyId:l.isPending&&l.variables!==void 0&&`id`in l.variables?l.variables.id:null,disabled:l.isPending||d.busy},bulk:{revoke:d,noun:Lt,isSelectable:e=>e.status===`active`}})})}function zt({token:e,label:t,onClose:n}){return u(Ae,{open:!0,onOpenChange:e=>!e&&n(),children:r(K,{width:`md`,scroll:`body`,children:[u(W,{children:u(Re,{children:`Token: ${t}`})}),r(q,{className:`space-y-3`,children:[u(`div`,{className:`rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),u(`div`,{className:`select-all break-all rounded-md border border-border bg-background p-2 font-mono text-[11px] text-foreground`,children:e})]}),r(Be,{children:[u(de,{value:e,label:`Copy`,srLabel:`token`}),u(G,{type:`button`,variant:`primary`,size:`sm`,onClick:n,children:`Done`})]})]})})}var Bt={token:`newToken`,scoped:`newScoped`,admin:`newAdmin`};n();var Vt=7,Ht=90,Ut=80;function Wt(e){let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=Ht?t:null}function Gt({open:e,users:t,onClose:n,onSubmitScoped:i,onSubmitAdmin:a,submitting:s,formError:l,awaitingProof:f}){let{user:p}=X(),m=p?.isAdmin===!0,h=m?null:p?.scopes??[],[g,_]=c(!1),[v,b]=c(t[0]?.id??``),[x,S]=c(``),[C,w]=c([{type:`capability`,target:``,access:[`view`,`create`]}]),[T,D]=c(``),[O,A]=c(String(Vt));d(()=>{e||(_(!1),b(t[0]?.id??``),S(``),w([{type:`capability`,target:``,access:[`view`,`create`]}]),D(``),A(String(Vt)))},[e,t]);let j=x.trim(),M=we(C),N=Wt(O),P=!g&&v!==``&&j.length>0&&C.length>0&&M===null&&!s,F=g&&m&&j.length>0&&j.length<=Ut&&N!==null&&!s&&!f;return u(Ge,{open:e,onClose:n,title:g?`Create admin token`:`Create token`,icon:g?k:R,error:l,width:`md`,testId:`create-token-dialog`,footer:r(G,{type:`button`,variant:g?`danger`:`primary`,size:`sm`,onClick:()=>{if(g){if(!F||N===null)return;a({name:j,expiresInDays:N});return}if(!P)return;let e=parseInt(T,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;i({userId:v,name:j,scopes:C,...t===void 0?{}:{expiresAt:t}})},disabled:g?!F:!P,children:[s||f?u(y,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):u(g?k:E,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),g?`Create admin token`:`Issue token`]}),children:r(`div`,{className:`space-y-3`,children:[m?r(`label`,{className:`flex items-start gap-2 text-sm text-foreground`,children:[u(`input`,{type:`checkbox`,className:`mt-0.5`,checked:g,onChange:e=>_(e.target.checked),"data-testid":`token-as-admin`}),r(`span`,{children:[u(`span`,{className:`font-medium`,children:`Administrator`}),u(`span`,{className:`block text-[11px] text-foreground-subtle`,children:`Off = scoped to a surface. On = full admin for scripts (audited, max 90 days).`})]})]}):null,g?u(`div`,{className:`space-y-1 rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] leading-relaxed text-foreground`,"data-testid":`admin-token-warning`,children:r(`p`,{children:[`An admin token acts as a `,u(`strong`,{children:`full administrator`}),`. Anyone holding it can do anything an admin can. Creating one asks you to confirm it is you.`]})}):null,g?null:r(`div`,{className:`space-y-1`,children:[u(Ue,{htmlFor:`token-user`,children:`On behalf of user`}),u(pe,{id:`token-user`,value:v,onChange:e=>b(e.target.value),options:t.map(e=>({value:e.id,label:e.username}))})]}),u(fe,{label:`Name`,required:!0,children:u(Me,{id:`token-name`,value:x,maxLength:Ut,onChange:e=>S(e.target.value),placeholder:g?`nightly-backup`:`cloudflare-tunnel-route`,autoFocus:!0})}),g?r(`div`,{className:`space-y-1`,children:[u(Ue,{htmlFor:`token-admin-days`,children:`Expires in (days)`}),u(Me,{id:`token-admin-days`,type:`number`,min:1,max:Ht,value:O,onChange:e=>A(e.target.value),state:N===null?`error`:`default`}),N===null?r(`p`,{className:`text-[11px] text-danger`,children:[`Expiry must be a whole number of days, 1 to `,Ht,`.`]}):r(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Whole number of days, 1 to `,Ht,`.`]})]}):r(o,{children:[r(`div`,{className:`space-y-1`,children:[u(Ue,{children:`Scopes`}),u(xe,{value:C,onChange:w,clampToParent:h}),M&&u(`p`,{className:`text-[10px] text-danger`,children:M}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`})]}),r(`div`,{className:`space-y-1`,children:[u(Ue,{htmlFor:`token-scoped-days`,children:`Expires in (days)`}),u(Me,{id:`token-scoped-days`,type:`number`,min:1,value:T,onChange:e=>D(e.target.value),placeholder:`30`}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Leave blank for non-expiring.`})]})]})]})})}n();var Kt={one:`token`,many:`tokens`};function qt(e){return e.type===`device`?`device:[${Ne(e.selector)}]`:`${e.type}:${e.target??``}`}function Jt({createRequested:e=!1,onCreateConsumed:t}){let{user:n}=X(),a=J(),o=s(),l=Y.useUtils(),f=wt(),{data:m,isLoading:h}=Se(),g=i(()=>m??[],[m]),_=Y.useQueries(e=>g.map(t=>e.userManagement.listScopedTokens({userId:t.id}))),v=Y.auth.listAdminTokens.useQuery(void 0,{enabled:n?.isAdmin===!0}),{requestProof:y,dialog:b}=mt(`Creating an admin token`),{state:x,openNew:S,close:C}=_e({newKey:Bt.token}),[w,T]=c(null),[E,D]=c(null),[O,k]=c(!1),[A,j]=c(null),[M,N]=c(null);d(()=>{e&&(S(),t?.())},[e,S,t]);let P=()=>{o.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),l.auth.listAdminTokens.invalidate(),l.auth.listAuthAudit.invalidate()},F=ke({onSuccess:({token:e,record:t})=>{P(),C(),D(null),j({token:e,label:t.name})},onError:e=>{T(`Create failed: ${e.message}`),D(`Create failed: ${e.message}`)}}),I=Y.auth.createAdminToken.useMutation({onSuccess:({token:e,record:t})=>{P(),C(),D(null),k(!1),j({token:e,label:t.name})},onError:e=>{T(`Create failed: ${e.message}`),D(`Create failed: ${e.message}`),k(!1)}}),L=ve({onSuccess:()=>{N(null),P()},onError:e=>{N(null),T(`Revoke failed: ${e.message}`)}}),z=Y.auth.revokeAdminToken.useMutation({onSuccess:()=>{N(null),P()},onError:e=>{N(null),T(`Revoke failed: ${e.message}`)}}),B=Ct(Kt,P),V=Date.now(),H=g.flatMap((e,t)=>(_[t]?.data??[]).map(t=>pt(t,e.id,f,t.scopes.map(qt).join(`, `),V))),ee=n?.isAdmin===!0?(v.data??[]).map(e=>ht(e,f,V)):[],te=[...H,...ee],U=_.find(e=>e.isError)?.error?.message??(v.isError?v.error?.message??`Request failed`:null),ne=async e=>{let t=e.kind===lt;await a({title:`Revoke "${e.name}"?`,message:t?`Every script using it loses access immediately. This cannot be undone.`:`${e.ownerName}'s scoped token stops working on its next use. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(T(null),N(e.id),t?z.mutate({id:e.id}):L.mutate({id:e.id}))},re=F.isPending||I.isPending;return r(`div`,{"data-testid":`tokens`,children:[b,u(Tt,{notice:ct(w,B.outcome),onDismissNotice:()=>{T(null),B.dismiss()},id:`tokens`,title:`Tokens`,icon:R,description:`Scoped tokens for a narrow surface, and admin tokens for full-administrator scripts. Revoking one stops it on its next use.`,children:u(ft,{rows:te,label:`tokens`,isLoading:h||_.some(e=>e.isLoading)||n?.isAdmin===!0&&v.isLoading,loadError:U,emptyText:`No tokens.`,action:{label:`Revoke`,icon:p,isAvailable:e=>e.status===`active`,onRun:e=>void ne(e),busyId:M,disabled:B.busy||M!==null},bulk:{revoke:B,noun:Kt,isSelectable:e=>e.status===`active`}})}),u(Gt,{open:x.mode===`new`,users:g.map(e=>({id:e.id,username:e.username})),onClose:()=>{C(),D(null),k(!1)},submitting:re,formError:E,awaitingProof:O,onSubmitScoped:e=>F.mutate({userId:e.userId,name:e.name,scopes:e.scopes,expiresAt:e.expiresAt}),onSubmitAdmin:e=>{(async()=>{T(null),D(null),k(!0);let t=await y();k(!1),t!==null&&I.mutate({...e,reauthToken:t})})()}}),A&&u(zt,{token:A.token,label:A.label,onClose:()=>j(null)})]})}var Yt={"share-link":`share links`,"admin-token":`admin tokens`,"login-session":`login sessions`};function Z(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Xt(e,t){let n=Z(e,`tokenId`);return Z(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Zt(e){return e.filter(e=>e!==null)}function Qt(e){let t=Z(e,`prefix`);return t===null?null:`Prefix ${t}…`}function $t(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:`Admin token "${Xt(n,t)}" created`,details:Zt([Qt(n),typeof e==`number`?`Expires ${bt(e)}`:null])}}case`admin-token-used`:{let e=Z(n,`path`);return{title:`Admin token "${Xt(n,t)}" used`,details:Zt([Qt(n),e===null?null:`Call ${e}`])}}case`admin-token-revoked`:return{title:`Admin token "${Xt(n,t)}" revoked`,details:Zt([Qt(n)])};case`credentials-revoked`:{let e=Z(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=Yt[e]??`${e}s`;return{title:`${typeof t==`number`?String(t):`?`} ${i} revoked in bulk`,details:Zt([typeof r==`number`&&r>0?`${String(r)} skipped`:null,Z(n,`ids`)===null?null:`Ids ${Z(n,`ids`)??``}`])}}case`second-factor-skipped`:{let e=Z(n,`method`),t=Z(n,`factors`);return{title:`Second factor skipped on a trusted network`,details:Zt([e===null?null:`Signed in with ${vt(e)}`,t===null?null:`Skipped: ${t.split(`,`).join(`, `)}`])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}n();var en=100;function tn(){let{user:e}=X();return e?.isAdmin?u(rn,{}):null}function nn(){let{data:e}=Se(),{data:t}=Y.auth.listAdminTokens.useQuery();return i(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.name);return{userNameById:n,tokenNameById:r}},[e,t])}function rn(){let e=Y.auth.listAuthAudit.useQuery({limit:en}),{userNameById:t,tokenNameById:n}=nn(),i=e.data??[];return r(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(w,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Authentication audit`}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[`Latest `,en,`, newest first`]})]}),u(`div`,{className:`p-4`,children:e.isLoading?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading audit trail…`]}):e.isError?r(`div`,{className:`text-[11px] text-danger`,children:[`Could not load the audit trail: `,e.error?.message??`Request failed`]}):i.length===0?r(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[u(`div`,{children:`No authentication events recorded yet.`}),u(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`})]}):u(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:i.map(e=>u(an,{record:e,userName:e.userId===void 0?null:t.get(e.userId)??e.userId,tokenNameById:n},e.id))})})]})}function an({record:e,userName:t,tokenNameById:n}){let i=$t(e,n);return r(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[r(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[u(`span`,{className:`font-medium text-foreground`,children:i.title}),u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:bt(e.at)})]}),r(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[t!==null&&u(`span`,{className:`text-foreground`,children:t}),e.ip!==void 0&&u(`span`,{className:`font-mono`,children:e.ip}),i.details.map(e=>u(`span`,{className:`font-mono`,children:e},e))]})]})}n();var Q={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,legacyApiKeys:`legacy-api-keys`,externalIdentities:`external-identities`,audit:`auth-audit`},on={[Q.scopedTokens]:Q.tokens,[Q.adminTokens]:Q.tokens};function sn(e){return[{id:Q.loginSessions,label:`Login sessions`,icon:z,render:()=>u(Rt,{})},{id:Q.linkedApps,label:`Linked apps`,icon:x,render:()=>u(It,{})},{id:Q.tokens,label:`Tokens`,icon:R,render:({createRequested:e,onCreateConsumed:t})=>u(Jt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:Q.shareLinks,label:`Share links`,icon:b,render:()=>u(_t,{})},...e?[{id:Q.legacyApiKeys,label:`Legacy API keys`,icon:L,render:()=>u(Nt,{})}]:[],{id:Q.externalIdentities,label:`Sign-in links`,icon:I,render:()=>u(Mt,{})},{id:Q.audit,label:`Audit`,icon:w,render:()=>u(tn,{})}]}function cn({createRequested:e=!1,onCreateConsumed:t}){let n=ie(),a=(n.data??[]).length>0,o=i(()=>sn(a),[a]),s=Et({ids:i(()=>o.map(e=>e.id),[o]),answered:!n.isLoading}),c=Qe(),[l]=Ze(),d=l.get(`integration`),f=d===null?void 0:on[d];if(f!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,f),u($e,{to:`?${e.toString()}`,replace:!0})}let p=o.find(e=>e.id===s.selectedId)??o[0],m=p?.id??Q.loginSessions;return n.isLoading?u(`div`,{className:`text-sm text-foreground-subtle`,"data-testid":`access-page`,children:`Loading…`}):r(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[u(Ie,{appearance:`pills`,value:m,onValueChange:e=>{c(`?${tt(l,e,null,null).toString()}`)},children:u(He,{"aria-label":`Credential kinds`,children:o.map(e=>r(We,{value:e.id,"data-testid":`access-kind-${e.id}`,children:[u(e.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),e.label]},e.id))})}),p===void 0?null:u(`div`,{role:`region`,"aria-label":p.label,"data-testid":`access-kind-body`,children:p.render({createRequested:e&&p.id===Q.tokens,onCreateConsumed:t??(()=>void 0)})},p.id)]})}function ln(e,t){if(e===Q.tokens)return r(G,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:t,children:[u(R,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`New token`]})}function un(){let[e,t]=c(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}n();var dn=[`oidcConnections`,`listConnections`],fn=[`oidcConnections`,`connectionFormSchema`],pn={displayName:`OpenID Connect`,icon:`shield-check`,issuerUrl:``,clientId:``,clientSecret:``,redirectUri:``,scopes:`openid profile email`,usernameClaim:`preferred_username`},mn=/^[a-z0-9][a-z0-9-]{0,63}$/;function hn(e){return e instanceof Error?e.message:String(e)}function gn(e,t){if(t)return typeof e==`string`&&e.length>0?e:void 0;if(re(e))return ne;if(typeof e==`string`&&e.length>0)return e;H(e)}function _n(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function vn({addonId:n}){let f=D(),h=s(),g=J(),_=_e({editKey:`oidcEdit`,newKey:`oidcNew`}),[v,y]=c(!1),[b,x]=c(null),[S,C]=c(``),[w,T]=c({...pn}),O=t(null),k=a({queryKey:[...dn,n],queryFn:async()=>f.trpcClient.oidcConnections.listConnections.query({})}),A=a({queryKey:fn,queryFn:async()=>f.trpcClient.oidcConnections.connectionFormSchema.query({})}),j=k.data??[],M=_n(A.data)?A.data:void 0,N=_.state,P=N.mode===`edit`?j.find(e=>e.id===N.id)??null:null;d(()=>{if(_.state.mode===`edit`&&P!==null){let e=`edit:${P.id}`;if(O.current===e)return;O.current=e,x(null),C(P.id),T(P.formValues===void 0?{...pn}:{...P.formValues});return}if(_.state.mode===`new`){if(O.current===`new`)return;O.current=`new`,x(null),C(``),T({...pn})}},[P,_.state]);let F=e(async()=>{await h.invalidateQueries({queryKey:dn})},[h]),I=l({mutationFn:async e=>f.trpcClient.oidcConnections.deleteConnection.mutate({id:e}),onSuccess:async()=>F()}),L=e(async e=>{await g({title:`Delete OIDC connection?`,message:`Remove “${e.displayName}” (${e.id}). The login button and IdP credentials for this id are dropped.`,confirmLabel:`Delete`,cancelLabel:`Cancel`,variant:`danger`})&&(await I.mutateAsync(e.id),_.state.mode===`edit`&&_.state.id===e.id&&(_.close(),O.current=null))},[g,I,_]),R=e(async()=>{let e=w.displayName,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){x(`Display name is required.`);return}let n=_.state.mode===`new`,r=n?S.trim():P?.id??``;if(n&&!mn.test(r)){x(`Instance id must be a lowercase slug (e.g. authentik, google).`);return}if(r===``){x(`That connection is no longer available.`);return}let i=gn(w.clientSecret,n),a=w.icon,o=w.issuerUrl,s=w.clientId,c=w.redirectUri,l=w.scopes,u=w.usernameClaim,d=u===`email`||u===`sub`?u:`preferred_username`;y(!0),x(null);try{n&&await f.trpcClient.oidcConnections.createConnection.mutate({id:r,displayName:t}),await f.trpcClient.oidcConnections.updateConnection.mutate({id:r,displayName:t,icon:typeof a==`string`?a:`shield-check`,issuerUrl:typeof o==`string`?o:``,clientId:typeof s==`string`?s:``,...i===void 0?{}:{clientSecret:i},redirectUri:typeof c==`string`?c:``,scopes:typeof l==`string`?l:`openid profile email`,usernameClaim:d}),await F(),_.close(),O.current=null}catch(e){x(hn(e))}finally{y(!1)}},[S,P?.id,_,w,F,f]),z=i(()=>[{key:`id`,header:`Id`,sortValue:e=>e.id,render:e=>u(`span`,{className:`font-mono text-xs text-foreground`,children:e.id})},{key:`name`,header:`Name`,sortValue:e=>e.displayName,render:e=>u(`span`,{className:`truncate font-medium text-foreground`,children:e.displayName})},{key:`issuer`,header:`Issuer`,sortValue:e=>e.issuerUrl,render:e=>u(`span`,{className:`truncate text-xs text-foreground-muted`,children:e.issuerUrl===``?`—`:e.issuerUrl})},{key:`status`,header:`Status`,notSortableReason:`Badge`,render:e=>u(Pe,{variant:e.configured?`success`:`warning`,children:e.configured?`Configured`:`Not configured`})},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>r(`div`,{className:`flex justify-end gap-1`,children:[u(G,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),_.openEdit(e.id)},children:`Edit`}),u(G,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":`Delete ${e.displayName}`,title:`Delete`,onClick:t=>{t.stopPropagation(),L(e)},children:u(p,{className:`h-3.5 w-3.5 text-danger`})})]})}],[_,L]),B=_.state.mode===`new`,V=B||P!==null,H=B?`new`:P===null?`closed`:`edit:${P.id}:${P.configured?`cfg`:`empty`}`;return r(`div`,{className:`flex min-h-0 flex-col gap-3`,"data-testid":`oidc-settings-connections`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[r(`p`,{className:`text-sm text-foreground-muted`,children:[`Each row is one IdP. Redirect URI:`,` `,u(`span`,{className:`font-mono text-xs`,children:`/addon/${n}/<id>/callback`})]}),r(G,{type:`button`,size:`sm`,"data-testid":`oidc-connections-add`,onClick:()=>_.openNew(),children:[u(m,{className:`h-3.5 w-3.5`}),`Add connection`]})]}),k.isError?u(`p`,{className:`text-sm text-danger`,children:`Could not load connections.`}):null,k.isPending?u(qe,{className:`h-32 w-full`}):u(me,{columns:z,rows:j,rowKey:e=>e.id,pageSize:25,mobileMode:`scroll`,emptyMessage:`No OIDC connections yet. Add one to register an IdP.`,onRowClick:e=>_.openEdit(e.id),defaultSort:{columnKey:`name`,dir:`asc`}}),u(Ge,{open:V,onClose:()=>{_.close(),x(null),O.current=null},title:B?`Add OIDC connection`:`Edit ${P?.displayName??`connection`}`,icon:E,width:`xl`,testId:`oidc-connection-editor`,error:b,footer:u(G,{type:`button`,size:`sm`,disabled:v||B&&S.trim()===``,onClick:()=>void R(),children:v?`Saving…`:`Save`}),children:V?r(o,{children:[B?r(`div`,{children:[u(Ue,{htmlFor:`oidc-connection-id`,children:`Instance id`}),u(Me,{id:`oidc-connection-id`,value:S,onChange:e=>C(e.target.value),placeholder:`authentik`,autoComplete:`off`}),u(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:`URL slug — appears in /addon/${n}/<id>/callback. Stable; renaming is not supported after save.`})]}):r(`p`,{className:`text-sm text-foreground-muted`,children:[`Instance id: `,u(`span`,{className:`font-mono`,children:P?.id})]}),M===void 0?u(`p`,{className:`text-sm text-foreground-muted`,children:`Loading form…`}):u(Fe,{schema:M,values:w,onChange:T,bare:!0},H)]}):null})]})}n();var yn=3e4,bn=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],xn={title:`Authentication`,subtitle:`Login providers (local password, OIDC, SAML) and second-factor providers (passkeys / WebAuthn). They run in parallel — enable or disable each independently; disabling one only removes that method, local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Sn(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:j,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`Scoped tokens, admin tokens and sessions are managed from Identity → Tokens & sessions.`],setupSteps:[`A fresh hub has one account, admin / changeme — the first sign-in asks for a new password. Add users from Users → New user.`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:P,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Choose a stable instance id (slug). Set the IdP redirect URI to `https://<this-hub>/addon/auth-oidc/<id>/callback`.",`In Settings below, Add connection — enter the id, issuer, and credentials; Save.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:P,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:g,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:g,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:E,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Cn(){let e=se({capName:bn[0].capName},{refetchInterval:yn}),t=se({capName:bn[1].capName},{refetchInterval:yn}),n=le(void 0,{refetchInterval:yn}),r=i(()=>jt(n.data??[]),[n.data]),a=i(()=>{let n=[],i=[e.data??[],t.data??[]];for(let[e,t]of bn.entries())for(let a of i[e]??[])n.push({addonId:a.addonId,displayName:r.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,r]),o=[{id:`authentication`,label:`Authentication providers`,install:{capability:bn[0].capName,label:xn.installLabel},entries:a.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:E,...At(e.isActive),render:()=>u(Dt,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:u(Pe,{variant:`info`,className:Ot,children:e.stageBadge}),settingsContent:e.addonId.startsWith(`auth-oidc`)?u(vn,{addonId:e.addonId}):void 0,panels:[{id:`about`,title:`About`,icon:Sn(e.addonId).icon,content:u(wn,{addonId:e.addonId})}]})}))}];return u(kt,{embedded:!0,icon:E,title:xn.title,subtitle:xn.subtitle,groups:o,isLoading:e.isLoading||t.isLoading,emptyTitle:xn.emptyTitle,emptyDescription:xn.emptyDescription})}function wn({addonId:e}){let t=Sn(e),n=t.icon;return r(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[r(`div`,{className:`flex items-start gap-2.5`,children:[u(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),u(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),u(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>u(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&r(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[u(M,{className:`h-3 w-3`}),`Setup steps`]}),u(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>u(`li`,{children:e},t))})]}),e===`local-auth`&&r(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[u(O,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),r(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,u(Xe,{to:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,u(Xe,{to:`/system/identity?tab=users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Tn({userId:e,username:t,onClose:n}){let i=J(),a=Y.useUtils(),o=Le({userId:e}),s=Y.auth.listLoginMethods.useQuery(),c=Ke({onSuccess:()=>void a.userManagement.listExternalIdentities.invalidate()}),l=new Map((s.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),d=o.data??[],f=async(n,r)=>{await i({title:`Remove sign-in link`,message:`"${t}" will no longer be able to sign in with this ${r} account.`,confirmLabel:`Remove`,variant:`danger`})&&c.mutate({userId:e,provider:n.provider,subject:n.subject})};return u(Ae,{open:!0,onOpenChange:e=>!e&&n(),children:r(K,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[u(W,{children:r(Re,{className:`flex items-center gap-2`,children:[u(x,{className:`h-4 w-4 text-primary`}),r(`span`,{children:[`Linked sign-in accounts`,r(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,u(`span`,{className:`font-mono`,children:t})]})]})]})}),u(q,{className:`space-y-3`,children:o.isLoading?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}):d.length===0?u(`p`,{className:`text-xs text-foreground-subtle`,children:`No linked accounts. Only the user can link one, from their own profile page.`}):u(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:d.map(e=>{let t=l.get(e.provider),n=t??e.provider;return r(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[r(`div`,{className:`flex-1 min-w-0`,children:[r(`div`,{className:`font-medium text-foreground truncate`,children:[n,t===void 0&&u(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:`provider unavailable`})]}),r(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),r(`button`,{onClick:()=>void f(e,n),disabled:c.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u(B,{className:`h-3 w-3`}),`Remove`]})]},`${e.provider}|${e.subject}`)})})}),u(Be,{children:u(G,{onClick:n,variant:`secondary`,children:`Close`})})]})})}function En({userId:e,username:t,onClose:n}){let i=s(),a=J(),c=ze({userId:e}),l=c.data,d=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=Ce({onSuccess:()=>{d(),n()}}),p=c.isLoading?`loading`:l?.enabled?`enrolled`:`not_enrolled`;return u(Ae,{open:!0,onOpenChange:e=>!e&&n(),children:r(K,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[u(W,{children:r(Re,{className:`flex items-center gap-2`,children:[u(g,{className:`h-4 w-4 text-primary`}),r(`span`,{children:[`Two-factor authentication`,r(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,u(`span`,{className:`font-mono`,children:t})]})]})]})}),r(q,{className:`space-y-4`,children:[p===`loading`&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(y,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&r(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[u(O,{className:`h-4 w-4 mt-0.5 shrink-0`}),r(`div`,{children:[u(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),u(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&l&&r(o,{children:[r(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[u(C,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),r(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[u(`div`,{className:`font-medium`,children:`2FA is active`}),r(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,l.confirmedAt?new Date(l.confirmedAt).toLocaleString():`—`]})]})]}),u(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),r(`div`,{className:`flex justify-end gap-2`,children:[u(G,{onClick:n,variant:`secondary`,children:`Close`}),r(`button`,{onClick:async()=>{await a({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&f.mutate({userId:e})},disabled:f.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[f.isPending?u(y,{className:`h-3 w-3 animate-spin`}):u(S,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}n();function Dn({userId:e,username:t,onClose:n}){let{user:i,logout:a}=X(),o=i?.id===e,s=J(),l=Y.useUtils(),d=Y.auth.listSessions.useQuery({userId:e}),[f,p]=c(null),m=Y.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(o&&`userId`in t){a();return}l.auth.listSessions.invalidate()},onError:e=>p(`Sign out failed: ${e.message}`)}),h=async e=>{await s({title:`Sign out this session`,message:`"${t}" on ${st(e.client).label} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(p(null),m.mutate({id:e.id}))},g=async()=>{await s({title:`Sign out everywhere`,message:o?`Every session of your own account ends, this browser included: you will be signed out here too.`:`Every session of "${t}" ends at once; each device has to sign in again.`,confirmLabel:`Sign out everywhere`,variant:`danger`})&&(p(null),m.mutate({userId:e}))},_=m.isPending&&m.variables!==void 0&&`id`in m.variables?m.variables.id:null;return u(Ae,{open:!0,onOpenChange:e=>!e&&n(),children:r(K,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[u(W,{children:r(Re,{className:`flex items-center gap-2`,children:[u(z,{className:`h-4 w-4 text-primary`}),r(`span`,{children:[`Active sessions`,r(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,u(`span`,{className:`font-mono`,children:t})]})]})]})}),r(q,{className:`space-y-3`,children:[f!==null&&u(`div`,{className:`text-[11px] text-danger`,children:f}),u(xt,{sessions:d.data??[],isLoading:d.isLoading,loadError:d.isError?d.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void h(e),revokingId:_})]}),r(Be,{className:`justify-between`,children:[r(`button`,{onClick:()=>void g(),disabled:m.isPending||(d.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[m.isPending&&_===null?u(y,{className:`h-3 w-3 animate-spin`}):u(F,{className:`h-3 w-3`}),`Sign out everywhere`]}),u(G,{onClick:n,variant:`secondary`,children:`Close`})]})]})})}function On({icon:e,label:t,count:n,all:i,total:a}){return r(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[u(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:t}),u(`span`,{className:n===0?`text-foreground-subtle`:`font-medium text-foreground`,children:n===0?`none`:i?`all ${a}`:`${n} of ${a}`})]})}function kn({scopes:e,isAdmin:t,invalidReason:n}){let i=D(),s=a({queryKey:[`auth`,`previewScope`,e,t],enabled:n===null,queryFn:()=>i.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:t})}),{data:c}=Ve({projection:`slim`}),l=c?.length??0;if(n!==null)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:r(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[u(k,{className:`h-3 w-3 shrink-0`}),n]})});if(s.isLoading)return r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[u(y,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(s.isError||!s.data)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let d=s.data;return u(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:d.isAdmin?r(`p`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):r(o,{children:[u(On,{icon:f,label:`Devices they can see`,count:d.device.view.deviceCount,all:d.device.view.all,total:l}),u(On,{icon:h,label:`Devices they can operate`,count:d.device.create.deviceCount,all:d.device.create.all,total:l}),u(On,{icon:p,label:`Devices they can delete`,count:d.device.delete.deviceCount,all:d.device.delete.all,total:l}),r(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,d.system.length===0?`none`:d.system.join(`, `),d.capabilities.length>0&&r(o,{children:[` · Extra capabilities: `,d.capabilities.map(e=>e.name).join(`, `)]}),d.addons.length>0&&r(o,{children:[` · Addons: `,d.addons.map(e=>e.name).join(`, `)]})]}),d.device.view.deviceCount===0&&u(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}n();function An(e){let t=te(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function jn(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:V({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Mn({user:e,onClose:t,onSubmit:n,submitting:a,callerScopes:s}){let l=i(()=>An(e.scopes??[]),[e.scopes]),[d,f]=c(l),[p,m]=c(l.mode===`advanced`),h=i(()=>jn(d),[d]),g=!e.isAdmin&&d.mode===`role`&&d.roleId===null,_=i(()=>e.isAdmin?null:d.mode===`role`&&d.roleId===null?`Pick what this user can do to see the result.`:we(h),[e.isAdmin,d.mode,d.roleId,h]),b=e=>f({...d,...e});return u(Ae,{open:!0,onOpenChange:e=>!e&&t(),children:r(K,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(W,{children:[r(Re,{children:[`Access — `,e.username]}),u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),r(q,{className:`space-y-4`,children:[g&&r(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[u(k,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),r(`p`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:`No access.`}),` `,r(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),r(`section`,{className:`space-y-2`,children:[u(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),u(`div`,{className:`space-y-1.5`,children:ee.map(e=>{let t=d.mode===`role`&&d.roleId===e.id;return r(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${t?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[u(`input`,{type:`radio`,name:`access-role`,checked:t,onChange:()=>b({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),r(`span`,{className:`min-w-0`,children:[u(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),u(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),r(`button`,{type:`button`,onClick:()=>{if(!p){f({...d,mode:`advanced`,advancedScopes:h}),m(!0);return}m(!1),f(An(d.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[u(p?A:v,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),p&&r(`div`,{className:`rounded-lg border border-border p-2`,children:[u(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),u(xe,{value:d.advancedScopes,onChange:e=>b({mode:`advanced`,advancedScopes:e}),clampToParent:s,emptyHint:r(o,{children:[`No grants.`,` `,u(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),d.mode===`role`&&r(`section`,{className:`space-y-2`,children:[u(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),u(je,{value:d.selector,onChange:e=>b({selector:e}),includeLinked:d.includeLinked,onIncludeLinkedChange:e=>b({includeLinked:e}),clampToDeviceIds:null})]}),r(`section`,{className:`space-y-2`,children:[u(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:d.mode===`role`?`3 · Result`:`2 · Result`}),u(kn,{scopes:h,isAdmin:e.isAdmin,invalidReason:_})]})]}),r(Be,{children:[u(G,{variant:`outline`,size:`sm`,onClick:t,children:`Cancel`}),u(G,{size:`sm`,onClick:()=>n([...h]),disabled:a||_!==null,children:a?u(y,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}n();var $=8;function Nn(){return{username:``,password:``,isAdmin:!1}}function Pn(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function Fn(e){return e instanceof Error?e.message:`Something went wrong`}function In(){let e=s(),{user:t}=X(),{state:n,openNew:i,openEdit:a,close:l}=_e(),[f,v]=c(null),[b,S]=c(null),[C,w]=c(!1),{data:T,isLoading:D,isError:O,error:k,refetch:A}=Se(),j=J(),M=Ee(),P=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),F=ce(),I=oe({onSuccess:P}),L=ae({onSuccess:P}),R=Te({onSuccess:P}),B=De({onSuccess:()=>{P(),H(null)}}),[V,H]=c(null),[ee,te]=c(null),[U,ne]=c(null),[re,ie]=c(null),W=T??[],K=n.mode===`edit`?W.find(e=>e.id===n.id)??null:null,se=()=>{v(null),S(null),w(!1),F.reset(),L.reset(),l()};d(()=>{if(n.mode===`closed`){v(null),S(null),w(!1);return}if(n.mode===`new`){v(e=>e!==null&&e.id===void 0?e:Nn());return}if(K===null){D||l();return}v(e=>e?.id===K.id?e:Pn(K))},[n,K,D,l]);let q=n.mode===`new`&&f!==null&&f.id===void 0||n.mode===`edit`&&f!==null&&K!==null;async function le(e){await j({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&(I.mutate({id:e.id}),n.mode===`edit`&&n.id===e.id&&se())}async function ue(e){let t=await M({title:`Reset password`,message:`Set a new password for "${e.username}".`,label:`New password`,inputType:`password`,placeholder:`At least 8 characters`,confirmLabel:`Continue`,validate:e=>e.length<$?`Password must be at least ${String($)} characters.`:null});t===null||t.length===0||await j({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&R.mutate({id:e.id,newPassword:t})}function de(e,t){t!==e.isAdmin&&L.mutate({id:e.id,isAdmin:t})}async function pe(){if(f!==null){S(null);try{if(f.id===void 0){let e=f.username.trim();if(e===``||f.password.length<$)return;await F.mutateAsync({username:e,password:f.password,isAdmin:f.isAdmin})}else await L.mutateAsync({id:f.id,isAdmin:f.isAdmin});P(),se()}catch(e){S(Fn(e))}}}function he(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let ve=F.isPending||L.isPending,be=f!==null&&f.id===void 0&&f.username.trim()!==``&&f.password.length>=$,xe=f!==null&&f.id!==void 0,Ce=ve||(f?.id===void 0?!be:!xe),we=e=>I.isPending&&I.variables?.id===e.id||L.isPending&&L.variables?.id===e.id||R.isPending&&R.variables?.id===e.id;return r(at,{embedded:!0,icon:_,title:`Users`,subtitle:`Hub accounts, admin flag, access scopes, sessions and sign-in links.`,actions:r(G,{size:`sm`,type:`button`,onClick:()=>{S(null),i()},children:[u(m,{className:`h-3.5 w-3.5`}),`Create User`]}),children:[O&&u(ye,{title:`Could not load users`,message:Fn(k),onRetry:()=>void A()}),D&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}),!D&&!O&&W.length===0&&u(Oe,{icon:_,title:`No users yet`,description:`Create a user to grant hub access.`}),!D&&!O&&W.length>0&&u(me,{columns:[{key:`username`,header:`Username`,sortValue:e=>e.username,render:e=>u(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`isAdmin`,header:`Admin`,nowrap:!0,sortValue:e=>+!!e.isAdmin,render:e=>u(`span`,{onClick:e=>e.stopPropagation(),children:r(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[u(`input`,{type:`checkbox`,checked:e.isAdmin,onChange:t=>de(e,t.target.checked),disabled:we(e),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),u(`span`,{className:e.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:e.isAdmin?`Admin`:`Regular`})]})})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?u(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):u(`span`,{onClick:e=>e.stopPropagation(),children:r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>H(e),title:`Configure access`,children:[u(E,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u(Ln,{scopes:e.scopes??[]})]})})},{key:`createdAt`,header:`Created`,nowrap:!0,sortValue:e=>e.createdAt,render:e=>u(`span`,{className:`text-foreground-subtle`,children:he(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:e=>{let n=we(e),i=e.id!==t?.id&&e.totpEnabled;return r(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>a(e.id),disabled:n,title:`Edit user`,children:[u(h,{className:`h-3 w-3`}),`Edit`]}),i&&r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>te(e),disabled:n,title:`Remove two-factor authentication`,children:[u(g,{className:`h-3 w-3`}),`Remove 2FA`]}),r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ne(e),disabled:n,title:`Linked sign-in accounts`,children:[u(x,{className:`h-3 w-3`}),`Sign-in links`]}),r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ie(e),disabled:n,title:`Active sessions`,children:[u(z,{className:`h-3 w-3`}),`Sessions`]}),r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void ue(e),disabled:n,title:`Reset password`,children:[u(N,{className:`h-3 w-3`}),`Reset password`]}),r(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void le(e),disabled:n,title:`Delete user`,className:`text-danger hover:bg-danger/10`,children:[n?u(y,{className:`h-3 w-3 animate-spin`}):u(p,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:W,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,mobileMode:`scroll`,onRowClick:e=>a(e.id)}),u(Ge,{open:q,onClose:se,title:f?.id===void 0?`Create User`:`Edit ${f.username||`user`}`,icon:_,error:b,testId:`user-form-dialog`,footer:u(G,{size:`sm`,type:`button`,disabled:Ce,onClick:()=>void pe(),children:ve?r(o,{children:[u(y,{className:`h-3.5 w-3.5 animate-spin`}),`Saving…`]}):f?.id===void 0?`Create`:`Save`}),children:f!==null&&r(`div`,{className:`space-y-3`,children:[u(fe,{label:`Username`,required:f.id===void 0,children:u(Me,{value:f.username,onChange:e=>v({...f,username:e.target.value}),placeholder:`john`,autoFocus:f.id===void 0,disabled:f.id!==void 0,"data-testid":`user-form-username`})}),f.id===void 0&&u(fe,{label:`Password`,required:!0,description:`At least ${String($)} characters.`,children:u(ge,{value:f.password,onValueChange:e=>v({...f,password:e}),shown:C,onToggleShown:()=>w(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),u(fe,{label:`Admin`,description:`Unrestricted access to every capability and device.`,children:r(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[u(`input`,{type:`checkbox`,checked:f.isAdmin,onChange:e=>v({...f,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),u(`span`,{children:`Admin`})]})}),f.id!==void 0&&u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`})]})}),ee&&u(En,{userId:ee.id,username:ee.username,onClose:()=>te(null)}),U&&u(Tn,{userId:U.id,username:U.username,onClose:()=>ne(null)}),re&&u(Dn,{userId:re.id,username:re.username,onClose:()=>ie(null)}),V&&u(Rn,{user:V,onClose:()=>H(null),onSubmit:e=>B.mutate({userId:V.id,scopes:e}),submitting:B.isPending})]})}function Ln({scopes:e}){if(e.length===0)return u(`span`,{className:`font-medium text-warning`,children:`No access`});let t=te(e);return t===null?r(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):r(`span`,{className:`text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:U(t.roleId).label}),` ·`,` `,Ne(t.selector)]})}function Rn(e){let{user:t}=X(),n=t?.isAdmin===!0;return u(Mn,{...e,callerScopes:n?null:t?.scopes??[]})}var zn={"api-keys":Q.tokens,"linked-sessions":Q.linkedApps};function Bn(){let{t:e}=Je(),[t]=Ze(),n=un(),r=zn[t.get(`tab`)??``];if(r!==void 0)return u($e,{to:nt(`access`,{integration:r}),replace:!0});let i=Ye(`/system/identity`,{t:e,isAdmin:!0})??{icon:T,title:e(`system.identity`,`Identity & Access`)},a=t.get(`tab`)??`users`,o=t.get(`integration`),s=a===et.access.tab?ln(o,n.requestCreate):void 0;return u(it,{icon:i.icon,title:i.title,defaultSection:`users`,sectionsLabel:`${i.title} sections`,actions:s,sections:[{id:`users`,label:`Users`,content:u(In,{})},{id:et.access.tab,label:`Tokens & sessions`,content:u(cn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate}),ownedParams:rt.concat([Bt.token,Bt.scoped,Bt.admin])},{id:et.authentication.tab,label:`Authentication`,content:u(Cn,{}),ownedParams:rt}]})}export{Bn as IdentityPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Ir as l,It as u,Lr as d,Nt as f,On as p,Sn as m,_i as h,_n as g,ai as _,ar as v,bi as y,di as b,dt as x,fn as S,ht as C,ln as w,ot as ee,qi as T,yi as E,yn as D}from"./player-overlays-CdH-hgko.js";import{t as O}from"./search-x-1g2n1cX3.js";import{Ar as k}from"./client-o5tMDxAT.js";import{$i as A,An as j,Ba as M,Ca as N,Dn as P,En as F,It as I,Ji as te,Kt as ne,Mr as L,Tn as R,Tt as z,Xi as B,Yi as V,Zi as H,aa as U,ao as W,co as re,do as G,ea as K,et as ie,hr as ae,in as oe,io as se,jn as ce,la as q,lo as le,ma as ue,mr as de,oa as fe,oo as pe,qi as J,rt as Y,so as me,su as he,ta as ge,tt as _e,uu as ve,xa as ye,yn as X}from"./src-BHgtK1NY.js";import{t as be}from"./useTranslation-Bc5yH9V9.js";import{n as xe}from"./addon-icons-context-WQbdCczg.js";import{I as Se,Q as Ce,X as we,Z as Te}from"./index-69_96GM2.js";import{t as Ee}from"./NodeAddonsSettingsPanel-BrxuUwuY.js";import{t as De}from"./device-integration-icon-DSO1DJ6e.js";import{n as Oe,r as ke,t as Ae}from"./ScanNetworkModal-DrptEMCC.js";n();function je(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...je(n.fields));return t}function Me(t,n,r){let[a,s]=o(`idle`),[c,l]=o({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...je(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;s(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[r,u,n]),clearProbeResult:f}}n();function Z(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function Ne(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Pe(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Pe(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Fe(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Ie({open:t,integrationId:n,addonId:l,onClose:u}){let{t:d}=be(),p=a(),[m,h]=o({}),[g,_]=o(!1),[y,b]=o(null),[w,ee]=o(Fe),T=ye({addonId:l},{enabled:t}),D=T.data?.deviceType??null,O=q({addonId:l,type:D??k.Camera},{enabled:t&&T.isSuccess&&D!==null}),A=O.data??null;c(()=>{t&&(h(A?Pe(A.sections.flatMap(e=>e.fields)):{}),ee(Fe()),_(!1),b(null))},[t,n,A]);let j=i(()=>({...m,_probeRequestId:w}),[m,w]),N=K({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),P=M(),F=e(async(e,t)=>{_(!0);let n=await P.mutateAsync({addonId:l,type:D??k.Camera,key:e,value:t,formValues:j});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ne(e[i])&&!Ne(a)&&(r[i]=a,t=!0);return t?r:e}),n},[P,l,j,D]),{testAllStatus:I,hasProbeFields:te,probeResults:ne,handleTestAll:L,clearProbeResult:R}=Me(A??{sections:[]},m,F);async function B(e){b(null);try{await N.mutateAsync({addonId:l,type:D??k.Camera,config:m,integrationId:n}),e?h(A?Pe(A.sections.flatMap(e=>e.fields)):{}):u()}catch(e){b(e instanceof Error?e.message:String(e))}}if(!t)return null;let V=Z((A?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ne(m[e])),H=V.length===0,U=T.isLoading||D!==null&&O.isLoading,W=T.isError||T.isSuccess&&D===null||O.isError||O.isSuccess&&A===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),s(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:s(x,{className:`h-4 w-4`})})]}),s(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:U?s(`div`,{className:`flex items-center justify-center py-8`,children:s(v,{className:`h-5 w-5 animate-spin text-primary`})}):W?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(f,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,s(`span`,{className:`font-mono`,children:l}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):s(Se,{schema:A,values:m,onChange:h,onTestField:F,probeResults:ne,onClearProbe:R})}),!W&&!U&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[s(S,{className:`h-3.5 w-3.5`}),`Test logs`,s(`span`,{className:`font-mono text-[9px] opacity-60`,children:w.slice(0,14)})]}),s(E,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&s(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:s(z,{addonId:l,requestId:w,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!W&&!U&&(y||V.length>0)&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(f,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:y||`Required: ${V.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!W&&te&&r(`button`,{type:`button`,onClick:L,disabled:I===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[I===`testing`?s(v,{className:`h-3.5 w-3.5 animate-spin`}):s(C,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>B(!0),disabled:W||!H||N.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),s(`button`,{onClick:()=>B(!1),disabled:W||!H||N.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:N.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Le=1500;function Re({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=be(),o=J(),c=(B({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Le:!1}).data??[]).find(e=>e.jobId===n);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&i();let p=[`${u}/${c.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&p.push(`${c.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&p.push(`${c.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&p.push(`${c.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=p.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?s(v,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?s(f,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?s(_,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):s(b,{className:`h-3.5 w-3.5 text-primary shrink-0`}),s(`p`,{className:`text-[11px] text-foreground`,children:m}),l&&s(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),s(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:s(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Q(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var $=`devices`,ze={id:$,label:`Devices`,isDefault:!0},Be=2e4,Ve=100;function He({addonId:n,integrationId:i,onClose:l}){let{t:u}=be(),d=a(),[p,m]=o(new Set),[h,_]=o(new Set),[b,S]=o(new Map),[C,w]=o(null),{data:ee}=pe(),T=(ee??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[E,D]=o(!0),O=te({addonId:n,integrationId:i}).data?.filters,k=O&&O.length>0?O:[ze],[j,M]=o(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===$)?$:k[0].id)),N=j!==$,P=H(),F=V({addonId:n,integrationId:i,page:1,pageSize:Be,filter:j}),I=F.refetch,ne=P.mutate,L=e(()=>{ne({addonId:n,integrationId:i},{onSettled:()=>{I()}})},[ne,n,i,I]),R=t(null);c(()=>{let e=`${n}::${i}`;R.current===e||F.isLoading||(R.current=e,(F.data?.candidates.length??0)===0&&L())},[n,i,F.isLoading,F.data,L]);let z=P.isPending,B=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,U=typeof P.data?.lastError==`string`&&P.data.lastError.length>0?P.data.lastError:null,W=F.data?.candidates??[],re=F.isError?F.error instanceof Error?F.error.message:String(F.error):null,G=A(),[K,ae]=o(null),oe=e(e=>{e.alreadyAdopted||m(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),se=e(e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ce=e((e,t)=>{S(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),q=e(e=>{let t={};for(let n of e){let e=b.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[b]),le=e(async()=>{w(null);let e=[...p];if(e.length!==0)try{let t=q(e),{jobId:r}=await G.mutateAsync({addonId:n,integrationId:i,filter:j,childNativeIds:e,...t?{perCandidate:t}:{},...T?{importLocations:E}:{}});ae(r),m(new Set),S(new Map)}catch(e){w(e instanceof Error?e.message:String(e))}},[p,q,G,n,i,j,T,E]),ue=t(null),de=e(()=>{K===null||ue.current===K||(ue.current=K,I(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[K,I,d]),fe=e(e=>{M(e),m(new Set),_(new Set),S(new Map),w(null)},[]),J=p.size,Y=K!==null&&J===0&&!G.isPending;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),s(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:u(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[T&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[s(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),s(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:s(x,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(B??re??U)&&W.length===0&&s(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(f,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),s(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:B??re??U})]})]})}),k.length>1&&s(Ue,{filters:k,activeFilter:j,onSelect:fe}),s(`div`,{className:`flex-1 min-h-0`,children:s(ie,{mode:`generic`,items:W,pageSize:Ve,getKey:e=>e.childNativeId,getSearchText:Q,getFilterType:e=>e.type,filterOptions:he(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:F.isLoading||z&&W.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(B??re??U)&&W.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:L,disabled:z,title:u(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[s(g,{className:`h-3.5 w-3.5 ${z?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>s(We,{candidate:e,expandable:!N,expanded:h.has(e.childNativeId),onToggleExpand:()=>se(e.childNativeId),adoptedLabel:u(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:u(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=ve(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[s(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>s(`div`,{className:`flex items-center justify-end`,children:s(`button`,{onClick:()=>oe(e),disabled:e.alreadyAdopted,"aria-label":p.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${p.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:p.has(e.childNativeId)&&s(y,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!N&&h.has(e.childNativeId),renderExpanded:N?void 0:e=>s(Ge,{candidate:e,hiddenChildIds:b.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ce(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:p.has(e.childNativeId)?`bg-primary/5`:``})})]}),C&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(f,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:C})]})}),K!==null&&s(Re,{addonId:n,integrationId:i,jobId:K,onFinished:de}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[s(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:u(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:Y?l:le,disabled:!Y&&(J===0||G.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[G.isPending&&s(v,{className:`h-3.5 w-3.5 animate-spin`}),Y?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!Y&&J>0?` (${J})`:``]})]})]})]})]})}function Ue({filters:e,activeFilter:t,onSelect:n}){return s(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return s(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function We({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[s(n?E:h,{className:`h-3.5 w-3.5`}),o]}):s(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),s(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&s(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Ge({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:s(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[s(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&s(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),s(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:s(i?d:l,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Ke(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Ke(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function qe(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Ke(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Je(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ye({integrationId:e,addonId:t,name:n,kind:o,mode:c,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=be(),m=a(),{data:h,isLoading:g}=me({id:e},{enabled:c===`account`||c===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:y,isLoading:b}=de({addonId:t,nodeId:`hub`},{enabled:c===`account`}),x=i(()=>y?Je(y):null,[y]),S=le(),C=(t,n)=>{S.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return s(R,{open:!0,onOpenChange:e=>!e&&f(),children:r(P,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(j,{children:r(ce,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]})}),s(F,{children:c===`broker`?l?r(`div`,{className:`space-y-3`,children:[s(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,s(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),S.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(v,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):s(ke,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),S.isError&&s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):c===`account`?g||b?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(v,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):s(Oe,{addonId:t,configSchema:x,canTest:u,initialName:n,initialConfig:qe(x,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):s(X,{trpc:d,addonId:t,nodeId:`hub`,title:n})})]})})}function Xe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Ze(){let{t}=be(),{integrationId:n}=Te(),l=a(),d=we(),[f,h]=Ce(),g=ee(),[_,y]=o(!1),[b,x]=o(!1),[C,E]=o(!1),[k,A]=o(!1),{data:M,isLoading:te}=W({id:n??``},{enabled:!!n}),{data:B}=de({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId}),{data:V,isSuccess:H}=pe(),K=i(()=>{let e=M?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[V,M?.addonId,H]),{data:q}=U({}),le=i(()=>(q?.providers??[]).some(e=>e.addonId===M?.addonId),[q,M?.addonId]),J=K!==null,me=M?.info?.fixed===!0,he=J?K===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ve=i(()=>{let e=M?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.brokerKind??null},[V,M?.addonId,H]),ye=i(()=>{let e=M?.addonId;return!e||!H?!1:(V??[]).find(t=>t.addonId===e)?.canTest===!0},[V,M?.addonId,H]),X=i(()=>{let e=M?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.mode??null},[V,M?.addonId,H]);c(()=>{f.get(`add`)===`1`&&J&&(y(!0),h(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,J,h]);let xe=B!=null&&Array.isArray(B.sections)&&B.sections.some(e=>e.fields.length>0),{data:Se}=ae({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId&&X!==`account`}),Oe=X!==null&&X!==`account`&&Xe(Se),ke=i(()=>M?.addonId?[M.addonId]:[],[M?.addonId]),{data:je}=ue({projection:`slim`},{refetchInterval:3e4}),Me=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=G({onMutate:async e=>{await l.cancelQueries({queryKey:Me});let t=l.getQueryData(Me);return t!=null&&l.setQueryData(Me,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&l.setQueryData(Me,r.previous)},onSettled:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=se({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Pe=L({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=N({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=ge({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=fe({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=i(()=>je??[],[je]),$=i(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),ze=e(e=>$.get(e)??null,[$]),{data:Be}=re(void 0),Ve=i(()=>_e(Be),[Be]),Ue=e(e=>d(`/devices/${String(e)}`),[d]),We=i(()=>{let e=M?.id;return e?Q.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Q,M?.id,Ve]),Ge=i(()=>Be===void 0?null:Y(We).length,[Be,We])??`…`;return te?r(`div`,{className:`p-4`,children:[s(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),s(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):M?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[s(ne,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:M.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[s(Qe,{addonId:M.addonId}),r(`div`,{className:`min-w-0`,children:[s(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:M.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[M.addonId,` · `,Ge,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[le&&r(`button`,{onClick:()=>x(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[s(m,{className:`h-3.5 w-3.5`}),`Scan network`]}),!me&&r(`button`,{onClick:()=>y(!0),disabled:!J,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:he,children:[s(p,{className:`h-3.5 w-3.5`}),he]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${M.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[s(oe,{checked:M.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":M.enabled?`Disable integration`:`Enable integration`}),s(`span`,{className:`text-[11px] font-medium ${M.enabled?`text-success`:`text-foreground-subtle`}`,children:M.enabled?`Enabled`:`Disabled`}),Z.isPending&&s(v,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),X!==`standalone`&&(xe||K===`device-adoption`)&&r(`button`,{onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[s(w,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>A(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[s(S,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),s(I,{label:`Restart`,icon:D,title:`Restart "${M.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ge} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:M.addonId})}),!me&&n&&s(I,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:u,title:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:M.name,count:Ge}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({id:n})})]})]}),Oe&&s(Ee,{nodeId:null,addonIds:ke,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),s(ie,{context:`integration-detail`,devices:Q,trpc:g.trpcClient,integrationOf:Ve,forceIntegrationId:M.id,urlScope:`root`,lsKey:`integration-detail:${M.addonId}`,resolveIntegrationIcon:De,resolveParent:ze,onNavigate:Ue,batchActions:{remove:Fe.mutate,disable:Le.mutate,enable:Re.mutate},...me?{}:{onDeleteDevice:e=>Fe.mutate({deviceId:e.id})}}),_&&n&&K===`device-adoption`&&s(He,{addonId:M.addonId,integrationId:n,onClose:()=>y(!1)}),_&&n&&K===`device-provider`&&s(Ie,{open:_,integrationId:n,addonId:M.addonId,onClose:()=>y(!1)}),b&&M&&s(Ae,{open:b,scope:{addonId:M.addonId,label:M.name},onClose:()=>x(!1)}),C&&n&&K!==null&&X!==null&&s(Ye,{integrationId:n,addonId:M.addonId,name:M.name,kind:K,mode:X,brokerKind:ve,canTest:ye,trpc:g.trpcClient,onClose:()=>E(!1)}),k&&s(R,{open:!0,onOpenChange:e=>!e&&A(!1),children:r(P,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[s(j,{className:`mb-0`,children:r(ce,{className:`flex items-center gap-2 min-w-0`,children:[s(S,{className:`h-4 w-4 text-primary shrink-0`}),s(`span`,{className:`truncate`,children:M.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[M.addonId,n?` · ${n}`:``]})]})}),s(F,{className:`min-h-0 overflow-hidden p-0`,children:s(z,{addonId:M.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[s(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:s(O,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),s(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[s(T,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Qe({addonId:e}){let t=xe(e),[n,r]=o(!1);return!t||n?null:s(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{Ze as IntegrationDetailPage};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Ir as l,It as u,Lr as d,Nt as f,On as p,Sn as m,_i as h,_n as g,ai as _,ar as v,bi as y,di as b,dt as x,fn as S,ht as C,ln as w,ot as ee,qi as T,yi as E,yn as D}from"./player-overlays-C20AJTgs.js";import{t as O}from"./search-x-CaqrjMNZ.js";import{Ar as k}from"./client-CKGZv6zJ.js";import{$i as A,An as j,Ba as M,Ca as N,Dn as P,En as F,It as I,Ji as te,Kt as ne,Mr as L,Tn as R,Tt as z,Xi as B,Yi as V,Zi as H,aa as U,ao as W,co as re,do as G,ea as K,et as ie,hr as ae,in as oe,io as se,jn as ce,la as q,lo as le,ma as ue,mr as de,oa as fe,oo as pe,qi as J,rt as Y,so as me,su as he,ta as ge,tt as _e,uu as ve,xa as ye,yn as X}from"./src-CIIJy_o8.js";import{t as be}from"./useTranslation-Bc5yH9V9.js";import{n as xe}from"./addon-icons-context-BcFthDce.js";import{I as Se,Q as Ce,X as we,Z as Te}from"./index-AsTGrKva.js";import{t as Ee}from"./NodeAddonsSettingsPanel-BK1RxciP.js";import{t as De}from"./device-integration-icon-CgVkQy_G.js";import{n as Oe,r as ke,t as Ae}from"./ScanNetworkModal-_RdncTUH.js";n();function je(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...je(n.fields));return t}function Me(t,n,r){let[a,s]=o(`idle`),[c,l]=o({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...je(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;s(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[r,u,n]),clearProbeResult:f}}n();function Z(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function Ne(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Pe(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Pe(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Fe(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Ie({open:t,integrationId:n,addonId:l,onClose:u}){let{t:d}=be(),p=a(),[m,h]=o({}),[g,_]=o(!1),[y,b]=o(null),[w,ee]=o(Fe),T=ye({addonId:l},{enabled:t}),D=T.data?.deviceType??null,O=q({addonId:l,type:D??k.Camera},{enabled:t&&T.isSuccess&&D!==null}),A=O.data??null;c(()=>{t&&(h(A?Pe(A.sections.flatMap(e=>e.fields)):{}),ee(Fe()),_(!1),b(null))},[t,n,A]);let j=i(()=>({...m,_probeRequestId:w}),[m,w]),N=K({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),P=M(),F=e(async(e,t)=>{_(!0);let n=await P.mutateAsync({addonId:l,type:D??k.Camera,key:e,value:t,formValues:j});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ne(e[i])&&!Ne(a)&&(r[i]=a,t=!0);return t?r:e}),n},[P,l,j,D]),{testAllStatus:I,hasProbeFields:te,probeResults:ne,handleTestAll:L,clearProbeResult:R}=Me(A??{sections:[]},m,F);async function B(e){b(null);try{await N.mutateAsync({addonId:l,type:D??k.Camera,config:m,integrationId:n}),e?h(A?Pe(A.sections.flatMap(e=>e.fields)):{}):u()}catch(e){b(e instanceof Error?e.message:String(e))}}if(!t)return null;let V=Z((A?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ne(m[e])),H=V.length===0,U=T.isLoading||D!==null&&O.isLoading,W=T.isError||T.isSuccess&&D===null||O.isError||O.isSuccess&&A===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),s(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:s(x,{className:`h-4 w-4`})})]}),s(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:U?s(`div`,{className:`flex items-center justify-center py-8`,children:s(v,{className:`h-5 w-5 animate-spin text-primary`})}):W?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(f,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,s(`span`,{className:`font-mono`,children:l}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):s(Se,{schema:A,values:m,onChange:h,onTestField:F,probeResults:ne,onClearProbe:R})}),!W&&!U&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[s(S,{className:`h-3.5 w-3.5`}),`Test logs`,s(`span`,{className:`font-mono text-[9px] opacity-60`,children:w.slice(0,14)})]}),s(E,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&s(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:s(z,{addonId:l,requestId:w,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!W&&!U&&(y||V.length>0)&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(f,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:y||`Required: ${V.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!W&&te&&r(`button`,{type:`button`,onClick:L,disabled:I===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[I===`testing`?s(v,{className:`h-3.5 w-3.5 animate-spin`}):s(C,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>B(!0),disabled:W||!H||N.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),s(`button`,{onClick:()=>B(!1),disabled:W||!H||N.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:N.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Le=1500;function Re({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=be(),o=J(),c=(B({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Le:!1}).data??[]).find(e=>e.jobId===n);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&i();let p=[`${u}/${c.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&p.push(`${c.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&p.push(`${c.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&p.push(`${c.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=p.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?s(v,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?s(f,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?s(_,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):s(b,{className:`h-3.5 w-3.5 text-primary shrink-0`}),s(`p`,{className:`text-[11px] text-foreground`,children:m}),l&&s(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),s(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:s(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Q(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var $=`devices`,ze={id:$,label:`Devices`,isDefault:!0},Be=2e4,Ve=100;function He({addonId:n,integrationId:i,onClose:l}){let{t:u}=be(),d=a(),[p,m]=o(new Set),[h,_]=o(new Set),[b,S]=o(new Map),[C,w]=o(null),{data:ee}=pe(),T=(ee??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[E,D]=o(!0),O=te({addonId:n,integrationId:i}).data?.filters,k=O&&O.length>0?O:[ze],[j,M]=o(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===$)?$:k[0].id)),N=j!==$,P=H(),F=V({addonId:n,integrationId:i,page:1,pageSize:Be,filter:j}),I=F.refetch,ne=P.mutate,L=e(()=>{ne({addonId:n,integrationId:i},{onSettled:()=>{I()}})},[ne,n,i,I]),R=t(null);c(()=>{let e=`${n}::${i}`;R.current===e||F.isLoading||(R.current=e,(F.data?.candidates.length??0)===0&&L())},[n,i,F.isLoading,F.data,L]);let z=P.isPending,B=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,U=typeof P.data?.lastError==`string`&&P.data.lastError.length>0?P.data.lastError:null,W=F.data?.candidates??[],re=F.isError?F.error instanceof Error?F.error.message:String(F.error):null,G=A(),[K,ae]=o(null),oe=e(e=>{e.alreadyAdopted||m(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),se=e(e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ce=e((e,t)=>{S(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),q=e(e=>{let t={};for(let n of e){let e=b.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[b]),le=e(async()=>{w(null);let e=[...p];if(e.length!==0)try{let t=q(e),{jobId:r}=await G.mutateAsync({addonId:n,integrationId:i,filter:j,childNativeIds:e,...t?{perCandidate:t}:{},...T?{importLocations:E}:{}});ae(r),m(new Set),S(new Map)}catch(e){w(e instanceof Error?e.message:String(e))}},[p,q,G,n,i,j,T,E]),ue=t(null),de=e(()=>{K===null||ue.current===K||(ue.current=K,I(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[K,I,d]),fe=e(e=>{M(e),m(new Set),_(new Set),S(new Map),w(null)},[]),J=p.size,Y=K!==null&&J===0&&!G.isPending;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),s(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:u(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[T&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[s(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),s(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:s(x,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(B??re??U)&&W.length===0&&s(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(f,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),s(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:B??re??U})]})]})}),k.length>1&&s(Ue,{filters:k,activeFilter:j,onSelect:fe}),s(`div`,{className:`flex-1 min-h-0`,children:s(ie,{mode:`generic`,items:W,pageSize:Ve,getKey:e=>e.childNativeId,getSearchText:Q,getFilterType:e=>e.type,filterOptions:he(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:F.isLoading||z&&W.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(B??re??U)&&W.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:L,disabled:z,title:u(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[s(g,{className:`h-3.5 w-3.5 ${z?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>s(We,{candidate:e,expandable:!N,expanded:h.has(e.childNativeId),onToggleExpand:()=>se(e.childNativeId),adoptedLabel:u(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:u(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=ve(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[s(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>s(`div`,{className:`flex items-center justify-end`,children:s(`button`,{onClick:()=>oe(e),disabled:e.alreadyAdopted,"aria-label":p.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${p.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:p.has(e.childNativeId)&&s(y,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!N&&h.has(e.childNativeId),renderExpanded:N?void 0:e=>s(Ge,{candidate:e,hiddenChildIds:b.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ce(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:p.has(e.childNativeId)?`bg-primary/5`:``})})]}),C&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(f,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:C})]})}),K!==null&&s(Re,{addonId:n,integrationId:i,jobId:K,onFinished:de}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[s(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:u(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:Y?l:le,disabled:!Y&&(J===0||G.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[G.isPending&&s(v,{className:`h-3.5 w-3.5 animate-spin`}),Y?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!Y&&J>0?` (${J})`:``]})]})]})]})]})}function Ue({filters:e,activeFilter:t,onSelect:n}){return s(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return s(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function We({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[s(n?E:h,{className:`h-3.5 w-3.5`}),o]}):s(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),s(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&s(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Ge({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:s(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[s(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&s(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),s(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:s(i?d:l,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Ke(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Ke(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function qe(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Ke(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Je(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ye({integrationId:e,addonId:t,name:n,kind:o,mode:c,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=be(),m=a(),{data:h,isLoading:g}=me({id:e},{enabled:c===`account`||c===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:y,isLoading:b}=de({addonId:t,nodeId:`hub`},{enabled:c===`account`}),x=i(()=>y?Je(y):null,[y]),S=le(),C=(t,n)=>{S.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return s(R,{open:!0,onOpenChange:e=>!e&&f(),children:r(P,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(j,{children:r(ce,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]})}),s(F,{children:c===`broker`?l?r(`div`,{className:`space-y-3`,children:[s(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,s(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),S.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(v,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):s(ke,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),S.isError&&s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):c===`account`?g||b?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(v,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):s(Oe,{addonId:t,configSchema:x,canTest:u,initialName:n,initialConfig:qe(x,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):s(X,{trpc:d,addonId:t,nodeId:`hub`,title:n})})]})})}function Xe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Ze(){let{t}=be(),{integrationId:n}=Te(),l=a(),d=we(),[f,h]=Ce(),g=ee(),[_,y]=o(!1),[b,x]=o(!1),[C,E]=o(!1),[k,A]=o(!1),{data:M,isLoading:te}=W({id:n??``},{enabled:!!n}),{data:B}=de({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId}),{data:V,isSuccess:H}=pe(),K=i(()=>{let e=M?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[V,M?.addonId,H]),{data:q}=U({}),le=i(()=>(q?.providers??[]).some(e=>e.addonId===M?.addonId),[q,M?.addonId]),J=K!==null,me=M?.info?.fixed===!0,he=J?K===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ve=i(()=>{let e=M?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.brokerKind??null},[V,M?.addonId,H]),ye=i(()=>{let e=M?.addonId;return!e||!H?!1:(V??[]).find(t=>t.addonId===e)?.canTest===!0},[V,M?.addonId,H]),X=i(()=>{let e=M?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.mode??null},[V,M?.addonId,H]);c(()=>{f.get(`add`)===`1`&&J&&(y(!0),h(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,J,h]);let xe=B!=null&&Array.isArray(B.sections)&&B.sections.some(e=>e.fields.length>0),{data:Se}=ae({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId&&X!==`account`}),Oe=X!==null&&X!==`account`&&Xe(Se),ke=i(()=>M?.addonId?[M.addonId]:[],[M?.addonId]),{data:je}=ue({projection:`slim`},{refetchInterval:3e4}),Me=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=G({onMutate:async e=>{await l.cancelQueries({queryKey:Me});let t=l.getQueryData(Me);return t!=null&&l.setQueryData(Me,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&l.setQueryData(Me,r.previous)},onSettled:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=se({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Pe=L({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=N({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=ge({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=fe({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=i(()=>je??[],[je]),$=i(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),ze=e(e=>$.get(e)??null,[$]),{data:Be}=re(void 0),Ve=i(()=>_e(Be),[Be]),Ue=e(e=>d(`/devices/${String(e)}`),[d]),We=i(()=>{let e=M?.id;return e?Q.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Q,M?.id,Ve]),Ge=i(()=>Be===void 0?null:Y(We).length,[Be,We])??`…`;return te?r(`div`,{className:`p-4`,children:[s(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),s(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):M?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[s(ne,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:M.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[s(Qe,{addonId:M.addonId}),r(`div`,{className:`min-w-0`,children:[s(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:M.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[M.addonId,` · `,Ge,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[le&&r(`button`,{onClick:()=>x(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[s(m,{className:`h-3.5 w-3.5`}),`Scan network`]}),!me&&r(`button`,{onClick:()=>y(!0),disabled:!J,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:he,children:[s(p,{className:`h-3.5 w-3.5`}),he]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${M.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[s(oe,{checked:M.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":M.enabled?`Disable integration`:`Enable integration`}),s(`span`,{className:`text-[11px] font-medium ${M.enabled?`text-success`:`text-foreground-subtle`}`,children:M.enabled?`Enabled`:`Disabled`}),Z.isPending&&s(v,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),X!==`standalone`&&(xe||K===`device-adoption`)&&r(`button`,{onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[s(w,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>A(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[s(S,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),s(I,{label:`Restart`,icon:D,title:`Restart "${M.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ge} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:M.addonId})}),!me&&n&&s(I,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:u,title:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:M.name,count:Ge}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({id:n})})]})]}),Oe&&s(Ee,{nodeId:null,addonIds:ke,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),s(ie,{context:`integration-detail`,devices:Q,trpc:g.trpcClient,integrationOf:Ve,forceIntegrationId:M.id,urlScope:`root`,lsKey:`integration-detail:${M.addonId}`,resolveIntegrationIcon:De,resolveParent:ze,onNavigate:Ue,batchActions:{remove:Fe.mutate,disable:Le.mutate,enable:Re.mutate},...me?{}:{onDeleteDevice:e=>Fe.mutate({deviceId:e.id})}}),_&&n&&K===`device-adoption`&&s(He,{addonId:M.addonId,integrationId:n,onClose:()=>y(!1)}),_&&n&&K===`device-provider`&&s(Ie,{open:_,integrationId:n,addonId:M.addonId,onClose:()=>y(!1)}),b&&M&&s(Ae,{open:b,scope:{addonId:M.addonId,label:M.name},onClose:()=>x(!1)}),C&&n&&K!==null&&X!==null&&s(Ye,{integrationId:n,addonId:M.addonId,name:M.name,kind:K,mode:X,brokerKind:ve,canTest:ye,trpc:g.trpcClient,onClose:()=>E(!1)}),k&&s(R,{open:!0,onOpenChange:e=>!e&&A(!1),children:r(P,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[s(j,{className:`mb-0`,children:r(ce,{className:`flex items-center gap-2 min-w-0`,children:[s(S,{className:`h-4 w-4 text-primary shrink-0`}),s(`span`,{className:`truncate`,children:M.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[M.addonId,n?` · ${n}`:``]})]})}),s(F,{className:`min-h-0 overflow-hidden p-0`,children:s(z,{addonId:M.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[s(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:s(O,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),s(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[s(T,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Qe({addonId:e}){let t=xe(e),[n,r]=o(!1);return!t||n?null:s(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{Ze as IntegrationDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e,K as t,L as n,Q as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Jt as d,Nt as f,On as p,Pi as m,V as h,ar as g,cr as _,fn as v,kn as y,yn as b}from"./player-overlays-
|
|
1
|
+
import{D as e,K as t,L as n,Q as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Jt as d,Nt as f,On as p,Pi as m,V as h,ar as g,cr as _,fn as v,kn as y,yn as b}from"./player-overlays-C20AJTgs.js";import{t as x}from"./settings-2-BjwKRpE2.js";import{Bn as S,It as C,Ln as ee,Mr as w,Pn as T,Rn as E,Rr as D,Tt as O,Vt as k,ar as te,wt as ne}from"./src-CIIJy_o8.js";import{J as A,Q as j,d as M,f as N,h as P,l as F,m as I,o as L,u as R}from"./index-AsTGrKva.js";import{t as z}from"./AdminPage-Pnx0mTsE.js";import{t as B}from"./NodeAddonsSettingsPanel-BK1RxciP.js";import{t as V}from"./AddonAssetIcon-BcUAeUFA.js";r();function H(e){let{ids:t,answered:n,legacyGroupParam:r=null,groupFirst:i}=e,[o]=j(),s=o.get(F),c=r===null?null:o.get(r),l=o.get(R),u=a(()=>I({ids:t,requested:s,answered:n,legacyGroup:c,...i===void 0?{}:{groupFirst:i}}),[t,s,n,c,i]),d=a(()=>(e,t)=>`?${P(o,e,r,t??null).toString()}`,[o,r]);return{...u,requestedSection:l,hrefFor:d}}var U=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],W=`text-[10px]`;function G({isActive:e}){return l(te,{variant:e?`success`:`default`,className:W,children:e?`Enabled`:`Disabled`})}function K({capName:e,addonId:t,isActive:n}){let r=s(),a=D({onSuccess:()=>{for(let e of U)r.invalidateQueries({queryKey:e})}}),o=a.isPending;return i(S,{size:`sm`,variant:n?`secondary`:`primary`,disabled:o,onClick:()=>a.mutate({capName:e,addonId:t,enabled:!n}),children:[o?l(g,{className:`h-3 w-3 animate-spin`}):l(n?d:y,{className:`h-3 w-3`}),n?`Disable`:`Enable`]})}function re({addonId:e,displayName:t}){let n=s(),r=w({onSuccess:()=>{for(let e of U)n.invalidateQueries({queryKey:e})}});return l(C,{label:`Restart`,icon:b,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:r.isPending,action:()=>r.mutateAsync({addonId:e})})}r();var q=600,J=e(null);function Y({id:e,title:r,icon:a,actions:s,framed:c=!1,children:u}){let d=n(J),f=t(null),p=`integration-section-${e}`;X(f,d,e);let m=i(o,{children:[d===null?null:l(A,{to:d.sectionHref(e),"aria-label":`Link to ${r}`,title:`Link to ${r}`,className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:l(_,{className:`h-3 w-3`,"aria-hidden":!0})}),s]});return c?l(`div`,{ref:f,className:`scroll-mt-4`,children:l(k,{headingId:p,title:r,icon:a,actions:m,children:u})}):i(`section`,{ref:f,"aria-labelledby":p,className:`scroll-mt-4 space-y-2`,children:[i(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[a!==void 0&&l(a,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),l(`h2`,{id:p,className:`${h} min-w-0 flex-1`,children:r}),m]}),u]})}function X(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;u(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},q);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}r();var Z=`max-h-72`;function ie({addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o,error:s=null,lead:c,panels:u=[],settingsContent:d}){let f=u.filter(e=>e.placement!==`end`),p=u.filter(e=>e.placement===`end`);return i(`div`,{className:`flex flex-col gap-4`,children:[l(ae,{addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o}),s!==null&&l(ee,{message:s}),c,l(Q,{panels:f}),l(Y,{id:M,title:`Settings`,icon:x,children:d===void 0?l(B,{nodeId:`hub`,addonIds:[e],level:`global`,capability:n}):d}),l($,{addonId:e}),l(Q,{panels:p})]})}function Q({panels:e}){return l(o,{children:e.map(e=>l(Y,{id:e.id,title:e.title,icon:e.icon,children:e.content},e.id))})}function ae({addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o}){return i(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-surface px-2 py-1.5 sm:px-3`,"data-testid":`integration-status-strip`,children:[i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[l(G,{isActive:r}),a,l(`span`,{className:`break-all font-mono text-[11px] text-foreground-subtle`,children:e})]}),i(`div`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[o,l(K,{capName:n,addonId:e,isActive:r}),l(re,{addonId:e,displayName:t})]})]})}var oe=[{kind:`logs`,label:`Logs`,icon:v},{kind:`events`,label:`Events`,icon:m}];function $({addonId:e}){let[t,n]=c(`logs`);return l(Y,{id:L,title:`Activity`,framed:!0,actions:l(`div`,{role:`group`,"aria-label":`Activity stream`,className:`flex items-center gap-1`,children:oe.map(({kind:e,label:r,icon:a})=>i(`button`,{type:`button`,"aria-pressed":t===e,onClick:()=>n(e),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t===e?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[l(a,{className:`h-3 w-3`,"aria-hidden":!0}),r]},e))}),children:t===`logs`?l(O,{addonId:e,maxHeight:Z,showFilters:!1}):l(ne,{addonId:e,category:`addon.*`,maxHeight:Z})})}var se=`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,ce=`border-primary bg-primary/10 text-primary font-medium`,le=`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,ue={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function de({label:e,groups:t,selectedId:n,hrefFor:r}){let a=t.length>1;return l(`nav`,{"aria-label":e,className:a?`flex flex-col gap-2 sm:grid sm:grid-cols-[max-content_minmax(0,1fr)] sm:items-start sm:gap-x-3`:`flex flex-col`,children:t.map(e=>i(`div`,{role:`group`,"aria-label":e.label,className:a?`flex min-w-0 flex-col gap-1 sm:col-span-2 sm:grid sm:grid-cols-subgrid sm:items-start`:`min-w-0`,children:[a&&l(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle sm:pt-2`,children:e.label}),i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[e.entries.map(e=>l(fe,{entry:e,current:e.id===n,href:r(e.id)},e.id)),e.install&&i(A,{to:N(e.install.capability),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[l(p,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),l(`span`,{className:`truncate`,children:e.install.label})]})]})]},e.id))})}function fe({entry:e,current:t,href:n}){let r=e.state===`ok`;return i(A,{to:n,"aria-current":t?`true`:void 0,className:`${se} ${t?ce:le}`,"data-testid":`integration-pill-${e.id}`,children:[l(V,{addonId:e.id,fallback:e.fallbackIcon,tileClassName:``,size:`sm`}),l(`span`,{className:`truncate`,children:e.name}),e.showState!==!1&&l(pe,{entry:e,quiet:r})]})}function pe({entry:e,quiet:t}){return i(o,{children:[l(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${ue[e.state]}`,"aria-hidden":!0}),l(`span`,{className:t?`sr-only`:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:e.stateLabel})]})}r();function me({icon:e,title:t,subtitle:n,groups:r,isLoading:s,emptyTitle:c,emptyDescription:u,legacyGroupParam:d,trailing:f,embedded:p=!1}){let m=a(()=>r.flatMap(e=>e.entries),[r]),h=a(()=>m.map(e=>e.id),[m]),g=a(()=>{let e={};for(let t of r){let n=t.entries[0];n!==void 0&&(e[t.id]=n.id)}return e},[r]),_=H({ids:h,answered:!s,legacyGroupParam:d??null,groupFirst:g}),v=m.find(e=>e.id===_.selectedId)??null,y=a(()=>v===null?null:{integrationId:v.id,requestedSection:_.requestedSection,sectionHref:e=>_.hrefFor(v.id,e)},[v,_]),b=s?null:l(de,{label:`${t} integrations`,groups:r,selectedId:_.selectedId,hrefFor:e=>_.hrefFor(e)}),x=s?l(T,{children:l(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):i(o,{children:[_.staleId!==null&&l(ge,{staleId:_.staleId,shownName:v?.name??null}),v!==null&&y!==null?l(J.Provider,{value:y,children:l(`div`,{role:`region`,"aria-label":v.name,"data-testid":`integration-body`,children:v.render()},v.id)}):l(he,{groups:r,title:c,description:u}),f]});return p?i(`div`,{className:`space-y-3`,"data-testid":`integration-hub-embedded`,children:[b,x]}):l(z,{icon:e,title:t,subtitle:n,nav:b,children:x})}function he({groups:e,title:t,description:n}){let r=e.find(e=>e.install!==void 0)?.install;return l(T,{children:l(E,{title:t,description:n,action:r?l(A,{to:N(r.capability),children:i(S,{variant:`primary`,size:`sm`,children:[l(p,{className:`mr-1 h-3.5 w-3.5`}),r.label]})}):void 0})})}function ge({staleId:e,shownName:t}){return i(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[l(f,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),i(`span`,{children:[`This link named `,l(`span`,{className:`font-mono text-foreground`,children:e}),`, which is not installed here.`,t!==null&&i(o,{children:[` `,`Showing `,l(`span`,{className:`font-medium text-foreground`,children:t}),` instead.`]})]})]})}export{H as i,ie as n,W as r,me as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Dn as l,On as u,Sn as d,_i as f,ar as p,bi as m,dn as h,dt as g,ln as _,ot as v,wi as y,yi as b,yn as x}from"./player-overlays-CdH-hgko.js";import{Ki as ee,M as S,Xl as C,co as te,et as w,iu as T,ma as E,mr as D,oo as O,r as k,ra as A,ro as j,rt as ne,tt as M}from"./src-BHgtK1NY.js";import{t as N}from"./useTranslation-Bc5yH9V9.js";import{K as P,Q as re,X as F}from"./index-69_96GM2.js";import{t as I}from"./AdminPage-BJe_yale.js";import"./useEventInvalidation-bsYvItQb.js";import{t as L}from"./device-integration-icon-DSO1DJ6e.js";import{n as R,r as z,t as ie}from"./ScanNetworkModal-DrptEMCC.js";t();function B(e=!0){c(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}t();function V(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function ae({providerId:e,onImport:t,onSkip:r}){let{t:i}=N(),[a,l]=o(new Set),u=A(),d=u.data,f=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function p(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||p(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(m,{className:`h-3 w-3 text-primary-foreground`})}),s(y,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}t();function H({onSelect:e,onClose:t,pendingAddonId:i=null}){let{t:a}=N(),c=F(),[l,u]=o(``),{data:d,isLoading:m}=O(),g=r(()=>{let e=d??[],t=l.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[d,l]);if(m)return s(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>s(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let v=i!==null;return n(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[n(`div`,{className:`relative`,children:[s(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),s(C,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:a(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":a(`integrations.searchProviders`,`Search integrations…`)})]}),s(`div`,{className:`grid grid-cols-2 gap-2`,children:g.map(r=>{let o=r.instanceMode===`unique`&&r.existingInstances.length>0,l=i===r.addonId,u=v;return n(`button`,{type:`button`,disabled:u,"data-testid":`provider-pick-${r.addonId}`,onClick:()=>{if(!u)if(o){let e=r.existingInstances[0].id;t(),c(`/integrations/${e}`)}else e(r.addonId,r.instanceMode,r.discoveryMode,r.name,r.kind,r.brokerKind,r.mode,r.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[r.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:s(`img`,{src:r.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:s(`span`,{className:`text-sm`,style:{color:r.color},children:`◉`})}),s(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:r.name}),r.description?s(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:r.description}):null,l?s(p,{className:`h-4 w-4 animate-spin text-primary`}):o?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(_,{className:`h-3 w-3`}),a(`integrations.manage`)]}):s(f,{className:`h-3.5 w-3.5 text-foreground-subtle`,"aria-hidden":!0})]},r.addonId)})}),g.length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(d??[]).length===0?a(`integrations.noProviders`):a(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}t();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var oe=2e4;function se({open:e,onClose:t}){let{t:l}=N(),u=F(),d=a(),[f,m]=o(`picker`),[h,_]=o(null),[v,y]=o(null),[b,x]=o(`manual`),[S,C]=o(null),[te,w]=o(``),[T,E]=o(null),[O,k]=o(null),[ne,M]=o(!1),{data:P}=D({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),re=r(()=>P?U(P):null,[P]),I=j({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),L=A(),ie=L.data;c(()=>{f!==`discovery`||!v||!h||L.isPending||L.data||L.mutate({addonId:h})},[f,v,h,L]);let se=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function W(e,t,n,r,i,a,o,s){if(!I.isPending){if(_(e),M(s),x(n),w(r),k(null),o===`broker`){if(!a){k(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),m(`broker`);return}if(o===`account`){m(`config`);return}ce(e,r)}}async function ce(e,n){try{let r=await I.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function le(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),b===`auto`||b===`both`?m(`discovery`):q(t.id)}catch{}}async function G(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:te,settings:{brokerId:e}});E(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=ie?.find(e=>e.stableId===t);e&&await se.mutateAsync({addonId:h,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??v??h;t(),J(),n&&u(`/integrations/${n}`)}function J(){m(`picker`),_(null),y(null),x(`manual`),C(null),w(``),E(null),k(null),M(!1)}function Y(){t(),J()}B(e);let X=I.isPending,Z=V(X,oe);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?h:null,$=I.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(g,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[O&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:O}),s(H,{onSelect:W,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&s(R,{addonId:h,configSchema:re??null,canTest:ne,onSave:le,onBack:()=>m(`picker`)}),f===`broker`&&S&&s(z,{kind:S,onResolved:e=>{G(e)},onBack:()=>m(`picker`)}),f===`discovery`&&v&&s(ae,{providerId:v,onImport:K,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(p,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function W({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?b:f,{className:`h-3.5 w-3.5`})}),s(P,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(W,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(S,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var G=`expand`;function K(){let{t}=N(),a=F(),c=v(),[f]=re(),[p,m]=o(!1),h=e(()=>m(!0),[]),g=e(()=>m(!1),[]),[_,y]=o(!1),b=e(()=>y(!0),[]),ee=e(()=>y(!1),[]);k([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),k([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:S,isLoading:C,refetch:D}=te(void 0),{data:O,isLoading:A,refetch:j}=E({projection:`slim`}),P=r(()=>O??[],[O]),R=r(()=>S??[],[S]),z=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),B=r(()=>M(S),[S]),V=r(()=>{let e=new Map;for(let t of ne(P)){let n=B(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,B]),ae=r(()=>R.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:V.get(e.id)??0})),[R,V]),H=f.get(G),U=e(e=>{let t=new URLSearchParams(window.location.search);t.get(G)===e?t.delete(G):t.set(G,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),oe=e(e=>a(`/integrations/${e.id}`),[a]),W=e(e=>z.get(e)??null,[z]),K=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(w,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:B,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:L,resolveParent:W,onNavigate:K}),[P,c.trpcClient,B,W,K]),J=e(e=>H===e.addonId,[H]),Y=r(()=>ce({isExpanded:J,onToggleExpand:U}),[J,U]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{D(),j()},[D,j]),Q=C||A,$=R.length>0;return n(I,{icon:l,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(x,{className:T(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:b,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(d,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:h,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(u,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(w,{mode:`generic`,items:ae,getKey:Z,getSearchText:X,columns:Y,onRowClick:oe,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(se,{open:p,onClose:g}),s(ie,{open:_,onClose:ee})]})}export{K as IntegrationsPage};
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Dn as l,On as u,Sn as d,_i as f,ar as p,bi as m,dn as h,dt as g,ln as _,ot as v,wi as y,yi as b,yn as x}from"./player-overlays-C20AJTgs.js";import{Ki as ee,M as S,Xl as C,co as te,et as w,iu as T,ma as E,mr as D,oo as O,r as k,ra as A,ro as j,rt as ne,tt as M}from"./src-CIIJy_o8.js";import{t as N}from"./useTranslation-Bc5yH9V9.js";import{K as P,Q as re,X as F}from"./index-AsTGrKva.js";import{t as I}from"./AdminPage-Pnx0mTsE.js";import"./useEventInvalidation-C-bu65w9.js";import{t as L}from"./device-integration-icon-CgVkQy_G.js";import{n as R,r as z,t as ie}from"./ScanNetworkModal-_RdncTUH.js";t();function B(e=!0){c(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}t();function V(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function ae({providerId:e,onImport:t,onSkip:r}){let{t:i}=N(),[a,l]=o(new Set),u=A(),d=u.data,f=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function p(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||p(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(m,{className:`h-3 w-3 text-primary-foreground`})}),s(y,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}t();function H({onSelect:e,onClose:t,pendingAddonId:i=null}){let{t:a}=N(),c=F(),[l,u]=o(``),{data:d,isLoading:m}=O(),g=r(()=>{let e=d??[],t=l.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[d,l]);if(m)return s(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>s(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let v=i!==null;return n(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[n(`div`,{className:`relative`,children:[s(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),s(C,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:a(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":a(`integrations.searchProviders`,`Search integrations…`)})]}),s(`div`,{className:`grid grid-cols-2 gap-2`,children:g.map(r=>{let o=r.instanceMode===`unique`&&r.existingInstances.length>0,l=i===r.addonId,u=v;return n(`button`,{type:`button`,disabled:u,"data-testid":`provider-pick-${r.addonId}`,onClick:()=>{if(!u)if(o){let e=r.existingInstances[0].id;t(),c(`/integrations/${e}`)}else e(r.addonId,r.instanceMode,r.discoveryMode,r.name,r.kind,r.brokerKind,r.mode,r.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[r.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:s(`img`,{src:r.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:s(`span`,{className:`text-sm`,style:{color:r.color},children:`◉`})}),s(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:r.name}),r.description?s(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:r.description}):null,l?s(p,{className:`h-4 w-4 animate-spin text-primary`}):o?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(_,{className:`h-3 w-3`}),a(`integrations.manage`)]}):s(f,{className:`h-3.5 w-3.5 text-foreground-subtle`,"aria-hidden":!0})]},r.addonId)})}),g.length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(d??[]).length===0?a(`integrations.noProviders`):a(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}t();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var oe=2e4;function se({open:e,onClose:t}){let{t:l}=N(),u=F(),d=a(),[f,m]=o(`picker`),[h,_]=o(null),[v,y]=o(null),[b,x]=o(`manual`),[S,C]=o(null),[te,w]=o(``),[T,E]=o(null),[O,k]=o(null),[ne,M]=o(!1),{data:P}=D({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),re=r(()=>P?U(P):null,[P]),I=j({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),L=A(),ie=L.data;c(()=>{f!==`discovery`||!v||!h||L.isPending||L.data||L.mutate({addonId:h})},[f,v,h,L]);let se=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function W(e,t,n,r,i,a,o,s){if(!I.isPending){if(_(e),M(s),x(n),w(r),k(null),o===`broker`){if(!a){k(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),m(`broker`);return}if(o===`account`){m(`config`);return}ce(e,r)}}async function ce(e,n){try{let r=await I.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function le(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),b===`auto`||b===`both`?m(`discovery`):q(t.id)}catch{}}async function G(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:te,settings:{brokerId:e}});E(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=ie?.find(e=>e.stableId===t);e&&await se.mutateAsync({addonId:h,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??v??h;t(),J(),n&&u(`/integrations/${n}`)}function J(){m(`picker`),_(null),y(null),x(`manual`),C(null),w(``),E(null),k(null),M(!1)}function Y(){t(),J()}B(e);let X=I.isPending,Z=V(X,oe);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?h:null,$=I.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(g,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[O&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:O}),s(H,{onSelect:W,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&s(R,{addonId:h,configSchema:re??null,canTest:ne,onSave:le,onBack:()=>m(`picker`)}),f===`broker`&&S&&s(z,{kind:S,onResolved:e=>{G(e)},onBack:()=>m(`picker`)}),f===`discovery`&&v&&s(ae,{providerId:v,onImport:K,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(p,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function W({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?b:f,{className:`h-3.5 w-3.5`})}),s(P,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(W,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(S,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var G=`expand`;function K(){let{t}=N(),a=F(),c=v(),[f]=re(),[p,m]=o(!1),h=e(()=>m(!0),[]),g=e(()=>m(!1),[]),[_,y]=o(!1),b=e(()=>y(!0),[]),ee=e(()=>y(!1),[]);k([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),k([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:S,isLoading:C,refetch:D}=te(void 0),{data:O,isLoading:A,refetch:j}=E({projection:`slim`}),P=r(()=>O??[],[O]),R=r(()=>S??[],[S]),z=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),B=r(()=>M(S),[S]),V=r(()=>{let e=new Map;for(let t of ne(P)){let n=B(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,B]),ae=r(()=>R.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:V.get(e.id)??0})),[R,V]),H=f.get(G),U=e(e=>{let t=new URLSearchParams(window.location.search);t.get(G)===e?t.delete(G):t.set(G,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),oe=e(e=>a(`/integrations/${e.id}`),[a]),W=e(e=>z.get(e)??null,[z]),K=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(w,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:B,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:L,resolveParent:W,onNavigate:K}),[P,c.trpcClient,B,W,K]),J=e(e=>H===e.addonId,[H]),Y=r(()=>ce({isExpanded:J,onToggleExpand:U}),[J,U]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{D(),j()},[D,j]),Q=C||A,$=R.length>0;return n(I,{icon:l,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(x,{className:T(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:b,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(d,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:h,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(u,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(w,{mode:`generic`,items:ae,getKey:Z,getSearchText:X,columns:Y,onRowClick:oe,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(se,{open:p,onClose:g}),s(ie,{open:_,onClose:ee})]})}export{K as IntegrationsPage};
|