@camstack/addon-admin-ui 1.2.657 → 1.2.659
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/CHANGELOG.md +12 -0
- package/dist/assets/{Addons-Box3Zccu.js → Addons-BAZZzcwC.js} +1 -1
- package/dist/assets/{AdminSectionedPage-CzrpTekp.js → AdminSectionedPage-BgDzN6TR.js} +1 -1
- package/dist/assets/{AiProfiles-D-w5C5-l.js → AiProfiles-BbsG4YRW.js} +1 -1
- package/dist/assets/{BootstrapSettingsForm-5uFD2Kof.js → BootstrapSettingsForm-C6EAxUx0.js} +1 -1
- package/dist/assets/{Build-qZQh3hjA.js → Build-BVBdQwlW.js} +1 -1
- package/dist/assets/{Calendars-DTutQb1E.js → Calendars-BErhWp39.js} +1 -1
- package/dist/assets/{CameraGrids-CUWb60X0.js → CameraGrids-8vI9nXx6.js} +1 -1
- package/dist/assets/{Cluster-BJAuetBc.js → Cluster-BhmI96G8.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-BIhcgdoy.js → CompositionBlockEditor-g2EYFk8V.js} +1 -1
- package/dist/assets/{CompositionEditorPage-BiVpjRJl.js → CompositionEditorPage-BgTBTj8w.js} +1 -1
- package/dist/assets/{Data-BXhy6eL_.js → Data-D0gdf1I0.js} +1 -1
- package/dist/assets/DeviceDetail-D-ryYF0z.js +2 -0
- package/dist/assets/{Devices-B_bfY38s.js → Devices-Bh9pbsi_.js} +1 -1
- package/dist/assets/{EmbedDevicePage-Cla-SVQD.js → EmbedDevicePage-ChsSks8t.js} +1 -1
- package/dist/assets/{History-DD6D7Dcs.js → History-BjyoxKCB.js} +1 -1
- package/dist/assets/{Identity-BeB3iubj.js → Identity-Ci1hV_px.js} +1 -1
- package/dist/assets/{InstancesTable-8uEgcvVT.js → InstancesTable-BGr_CSfQ.js} +1 -1
- package/dist/assets/{IntegrationDetail-BiOcgnb_.js → IntegrationDetail-BXNCJeWN.js} +1 -1
- package/dist/assets/{IntegrationWizard-5b0NkY3q.js → IntegrationWizard-BJ098UD3.js} +1 -1
- package/dist/assets/{Integrations-DDXj6LGa.js → Integrations-D8sQMJsy.js} +1 -1
- package/dist/assets/{Integrations-BYkq5Tnd.js → Integrations-DL0NA8Ig.js} +1 -1
- package/dist/assets/{Library-C4HdgygP.js → Library-BWzsDdK1.js} +1 -1
- package/dist/assets/{Locations-0P70Sc0f.js → Locations-B-x-T8vk.js} +1 -1
- package/dist/assets/{Logs-Cyf77THP.js → Logs-DZqsockY.js} +1 -1
- package/dist/assets/{MyAccess-Bdg6M_F2.js → MyAccess-DWNdgDGD.js} +1 -1
- package/dist/assets/{Network--k6YX0uT.js → Network-BgeNLRSx.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-Dw5WZxWi.js → NodeAddonsSettingsPanel-CafQePC4.js} +1 -1
- package/dist/assets/{Notifications-CfesJVtl.js → Notifications-CVxCT2Fs.js} +1 -1
- package/dist/assets/{Pipeline-Cxfq3bsX.js → Pipeline-DmGFEVEg.js} +1 -1
- package/dist/assets/{Recordings-Bz1UQb_D.js → Recordings-BSvC9s8e.js} +1 -1
- package/dist/assets/{SessionsList-ByWStI3D.js → SessionsList-C1OAywF9.js} +1 -1
- package/dist/assets/{Showroom-BVvEli5J.js → Showroom-vbfLqpBw.js} +1 -1
- package/dist/assets/{StorageLocationsTable-CFaMMEmA.js → StorageLocationsTable-CyB9xlEG.js} +1 -1
- package/dist/assets/{System-BMSl-son.js → System-fVtr7uyF.js} +1 -1
- package/dist/assets/{Templates-BNH1PKWe.js → Templates-BMr1b_YS.js} +1 -1
- package/dist/assets/{Terminal-D-YiG_GF.js → Terminal-BMQq7ebE.js} +1 -1
- package/dist/assets/{TrainingProviders-B05YjzG6.js → TrainingProviders-BVqm0Y4N.js} +1 -1
- package/dist/assets/{create-composition-51F9Gq1x.js → create-composition-B2YbPgss.js} +1 -1
- package/dist/assets/{device-detail-BYVgg4Sb.js → device-detail-CuhDLCgG.js} +1 -1
- package/dist/assets/{device-integration-icon-C2zPAE71.js → device-integration-icon-DouP6fxO.js} +1 -1
- package/dist/assets/{index-DHx7H0Qb.css → index-CoqQ1LfI.css} +1 -1
- package/dist/assets/{index-BV01fYDf.js → index-t4MmHqcc.js} +3 -3
- package/dist/assets/{mf-entry-bootstrap-0-43e13f36.js → mf-entry-bootstrap-0-f044c710.js} +1 -1
- package/dist/assets/{step-inspector-model-fxfNSZXN.js → step-inspector-model-C89WY2Ck.js} +1 -1
- package/dist/assets/{useAdminDeviceRemoval-60EAneS8.js → useAdminDeviceRemoval-DQlQg_rq.js} +1 -1
- package/dist/assets/{useNodeUrlSelection-lmVrEsaf.js → useNodeUrlSelection-BZ6hSQEj.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/server/addon.js +1 -1
- package/package.json +2 -2
- package/dist/assets/DeviceDetail-DdYnzePf.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$t as s,Ct as c,Gn as l,Gr as u,Mr as d,Wa as f,Xi as p,_t as m,ct as h,lt as g,zn as _}from"./player-overlays-DuG5kk5Q.js";import{Zr as v,vs as y}from"./client-pLjIfKNS.js";import{$r as b,Jd as x,Jn as S,Jr as C,Kn as w,Qr as T,Qt as E,Qu as D,Rf as O,Rn as k,Si as A,Vo as j,Xd as M,Xt as ee,Yn as N,Yr as te,Zd as P,Zr as ne,Zt as re,_n as ie,bn as ae,cn as oe,en as se,fn as ce,gn as le,hi as ue,hn as de,ho as fe,in as pe,li as F,ln as me,mn as he,mo as ge,of as I,on as L,pn as _e,qr as ve,rn as ye,si as be,sn as R,tn as xe,un as Se,vi as z,vn as B,yn as Ce,zf as we,zn as Te}from"./src-DOkmPL4F.js";import{t as V}from"./useTranslation-BJr-n0es.js";import{Qr as Ee}from"./index-BV01fYDf.js";import{t as De}from"./AdminPage-Q2-TrrvF.js";i();function H(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function Oe(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:R(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:H(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:R(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:H(t,n)})}return r}function ke(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function U(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:ue(r,`compact`,t,n)}var Ae=[`energy`,`temperatures`,`nodes`,`storage`],je=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),W=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Me=`addon:storage-orchestrator/location-used-percent`;function Ne(e,t){let n=(e,n)=>{let r=t.filter(e);return L((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&je.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&W.includes(e.info.key)&&e.info.scope===``,(e,t)=>W.indexOf(e.info.key)-W.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Me)}}function Pe(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of L(e)){let e=n.get(R(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function G(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var K=`history-page`;function Fe({part:r,window:i}){let{t:a}=V(),o=f(),s=A(),c=z(),l=e=>`${U(e,s,c)} · ${e.metric}`,u=t(()=>[...r.lines,...r.states,...r.energy],[r]),d=se(t(()=>u.map(e=>G(e.ref)),[u]),i,!1),m=e=>d.status===`ok`?d.data.current.get(E(G(e.ref))):void 0,h=e=>{let t=m(e);return t?.ok?t.result:void 0};if(u.length===0)return n(F,{icon:p,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(d.status===`error`)return n(x,{title:a(`history.page.readFailed`,`History could not be read`),message:d.error});let g=d.status===`pending`,_=u.map(e=>({c:e,e:m(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=h(e),r=_e(e.info,n,i.from);return{id:e.id,label:l(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=he(e.info,h(e),i.from,i.to),r=Se(e.info.key,o);return{id:e.id,label:l(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),b=r.energy.map(e=>({c:e,...ce(h(e))})),S=b[0]?.bucketMs??36e5,C=[...new Set(b.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:b.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(x,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${l(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(Ce,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:K,pending:g}),b.length>0&&n(be,{title:a(`history.page.energy`,`Energy`),layers:b.map((e,t)=>({id:e.c.id,label:U(e.c,s,c),colorIndex:t})),buckets:C,bucketMs:S,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:K,pending:g}),y.length>0&&n(ae,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:K,pending:g})]})}function Ie(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Le(e,t){let n=[];for(let r of Ie(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function q(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Re(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+q(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function ze(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var J=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function Y(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function X(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function Z(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:X(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:Y(o,r,i)})]})},sortValue:e=>`${Y(t(e),r,i)} ${X(t(e))}`}}var Be=[`raw`,`5m`,`1h`,`1d`];function Ve(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function He(t,r){return[Z(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(M,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:J(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[J(t.firstTs),` → `,J(t.lastTs)]}),sortValue:e=>e.lastTs},...Be.map(e=>({key:`rows-${e}`,header:Ve(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function Ue(e,t){if(e.ok)return n(M,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:q(e.deleted),points:q(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(M,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function We(e,t){return[Z(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>Ue(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function Ge({open:i,onClose:a,list:o,deviceNames:c,onDelete:u,onRefresh:f,refreshing:p}){let{t:m}=V(),g=h(),[_,v]=r(new Set),[y,x]=r(!1),[w,E]=r([]),D=t(()=>He(c,m),[c,m]),O=t(()=>We(c,m),[c,m]),k=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),A=[..._].filter(e=>k.has(e)).map(Number),j=Re(w.map(e=>e.outcome)),M=async()=>{if(await g({title:m(`history.orphans.confirmTitle`,{count:A.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:m(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:m(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){x(!0);try{let e=await Le(A,u);E(ze(o.series,e)),v(new Set)}finally{x(!1),f()}}};return n(ve,{open:i,onOpenChange:e=>!e&&a(),children:e(te,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(T,{children:n(b,{children:m(`history.orphans.title`,`Series no longer linked to a device`)})}),e(C,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:m(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:m(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(I,{size:`sm`,variant:`outline`,onClick:f,disabled:p,children:[n(l,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.loadAgain`,`Load again`)]})]}),w.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:m(`history.orphans.summary`,{count:j.deleted,refused:j.refused,points:j.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(S,{columns:O,rows:w,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(S,{columns:D,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:N,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:m(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:_,onChange:v,rowLabel:e=>`${X(e)} — ${Y(e,c,m)}`,pageLabel:m(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(ne,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:m(`history.orphans.selected`,{count:A.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(I,{variant:`ghost`,size:`sm`,onClick:a,children:m(`history.orphans.close`,`Close`)}),e(I,{variant:`danger`,size:`sm`,disabled:A.length===0||y,onClick:()=>void M(),children:[y?n(d,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(s,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Ke=5*6e4;function qe({enabled:i}){let{t:a}=V(),[s,c]=r(!1),l=fe({},{enabled:i,staleTime:Ke}),u=j({projection:`slim`},{enabled:i}),d=ge(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(x,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(x,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(I,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(Ge,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var Q=`device`,Je=`node`;function Ye({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=V(),c=A(),l=z(),u=e=>U(e,c,l),d=k(r,{searchText:e=>[ke(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Q:Je},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(Te,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Q?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(S,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:N,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var Xe=new Set([y.Container]),$=5*6e4;function Ze(){let{t:r}=V(),i=O(`device-history`),[a,o]=Ee(),s=t(()=>L(a.getAll(`s`).flatMap(e=>{let t=ye(e);return t===null?[]:[t]})),[a]),l=a.get(`window`),d=ie(l)?l:`7d`,f=de(a.get(`range`)),m=(e,t,n)=>{let r=new URLSearchParams;for(let t of L(e))r.append(`s`,pe(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},v=Qe(i===`present`),y=B(d,Date.now(),f),b=B(d,re(Date.now(),y.to-y.from),f),S=t(()=>Pe(s,v.candidates),[s,v.candidates]),C=t(()=>new Set(s.map(R)),[s]),T=ee(),E=g(),D=h(),k=async()=>{let e=await E({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await T.update(t=>oe(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:d,selection:[...s]}))},A=async(e,t)=>{await D({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await T.update(t=>me(t,e))},j=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(De,{icon:p,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(I,{size:`sm`,variant:`outline`,onClick:()=>void k(),disabled:s.length===0||!T.writable,children:[n(_,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(P,{className:`h-64 w-full`}):i===`unknown`?n(x,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(F,{icon:u,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(qe,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[Ae.map(e=>n(I,{size:`sm`,variant:`outline`,disabled:v.status!==`ok`,onClick:()=>m(Ne(e,v.candidates),d),children:j(e)},e)),T.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(I,{size:`sm`,variant:`secondary`,onClick:()=>m(t.selection,t.window,null),children:t.name}),n(I,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void A(t.id,t.name),disabled:!T.writable,children:n(c,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(w,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:v.status===`error`?n(x,{message:v.error}):n(Ye,{catalog:v.candidates,loading:v.status===`pending`,selected:C,onChange:e=>{let t=s.filter(t=>e.has(R(t))),n=v.candidates.filter(t=>e.has(t.id)&&!C.has(t.id)).map(e=>e.ref);m([...t,...n],d)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(w,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(I,{size:`sm`,variant:`ghost`,onClick:()=>m([],d),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(xe,{value:d,onChange:e=>m(s,e),custom:f,onCustomChange:e=>m(s,`custom`,le(e))}),v.status===`pending`&&s.length>0?n(P,{className:`h-64 w-full`}):n(Fe,{part:S,window:b}),S.missing.length>0&&v.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:S.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Qe(e){let{t:n}=V(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=m().trpcClient,o=j({projection:`slim`},{enabled:e}),{nodes:s}=we(),c=t(()=>(o.data??[]).filter(e=>!Xe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=D({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),p=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>Oe(c.flatMap((e,t)=>{let n=p[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=v(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:g}}export{Ze as HistoryPage};
|
|
1
|
+
import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$t as s,Ct as c,Gn as l,Gr as u,Mr as d,Wa as f,Xi as p,_t as m,ct as h,lt as g,zn as _}from"./player-overlays-DuG5kk5Q.js";import{Zr as v,vs as y}from"./client-pLjIfKNS.js";import{$r as b,Jd as x,Jn as S,Jr as C,Kn as w,Qr as T,Qt as E,Qu as D,Rf as O,Rn as k,Si as A,Vo as j,Xd as M,Xt as ee,Yn as N,Yr as te,Zd as P,Zr as ne,Zt as re,_n as ie,bn as ae,cn as oe,en as se,fn as ce,gn as le,hi as ue,hn as de,ho as fe,in as pe,li as F,ln as me,mn as he,mo as ge,of as I,on as L,pn as _e,qr as ve,rn as ye,si as be,sn as R,tn as xe,un as Se,vi as z,vn as B,yn as Ce,zf as we,zn as Te}from"./src-DOkmPL4F.js";import{t as V}from"./useTranslation-BJr-n0es.js";import{Qr as Ee}from"./index-t4MmHqcc.js";import{t as De}from"./AdminPage-Q2-TrrvF.js";i();function H(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function Oe(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:R(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:H(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:R(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:H(t,n)})}return r}function ke(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function U(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:ue(r,`compact`,t,n)}var Ae=[`energy`,`temperatures`,`nodes`,`storage`],je=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),W=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Me=`addon:storage-orchestrator/location-used-percent`;function Ne(e,t){let n=(e,n)=>{let r=t.filter(e);return L((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&je.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&W.includes(e.info.key)&&e.info.scope===``,(e,t)=>W.indexOf(e.info.key)-W.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Me)}}function Pe(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of L(e)){let e=n.get(R(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function G(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var K=`history-page`;function Fe({part:r,window:i}){let{t:a}=V(),o=f(),s=A(),c=z(),l=e=>`${U(e,s,c)} · ${e.metric}`,u=t(()=>[...r.lines,...r.states,...r.energy],[r]),d=se(t(()=>u.map(e=>G(e.ref)),[u]),i,!1),m=e=>d.status===`ok`?d.data.current.get(E(G(e.ref))):void 0,h=e=>{let t=m(e);return t?.ok?t.result:void 0};if(u.length===0)return n(F,{icon:p,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(d.status===`error`)return n(x,{title:a(`history.page.readFailed`,`History could not be read`),message:d.error});let g=d.status===`pending`,_=u.map(e=>({c:e,e:m(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=h(e),r=_e(e.info,n,i.from);return{id:e.id,label:l(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=he(e.info,h(e),i.from,i.to),r=Se(e.info.key,o);return{id:e.id,label:l(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),b=r.energy.map(e=>({c:e,...ce(h(e))})),S=b[0]?.bucketMs??36e5,C=[...new Set(b.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:b.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(x,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${l(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(Ce,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:K,pending:g}),b.length>0&&n(be,{title:a(`history.page.energy`,`Energy`),layers:b.map((e,t)=>({id:e.c.id,label:U(e.c,s,c),colorIndex:t})),buckets:C,bucketMs:S,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:K,pending:g}),y.length>0&&n(ae,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:K,pending:g})]})}function Ie(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Le(e,t){let n=[];for(let r of Ie(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function q(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Re(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+q(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function ze(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var J=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function Y(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function X(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function Z(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:X(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:Y(o,r,i)})]})},sortValue:e=>`${Y(t(e),r,i)} ${X(t(e))}`}}var Be=[`raw`,`5m`,`1h`,`1d`];function Ve(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function He(t,r){return[Z(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(M,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:J(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[J(t.firstTs),` → `,J(t.lastTs)]}),sortValue:e=>e.lastTs},...Be.map(e=>({key:`rows-${e}`,header:Ve(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function Ue(e,t){if(e.ok)return n(M,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:q(e.deleted),points:q(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(M,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function We(e,t){return[Z(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>Ue(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function Ge({open:i,onClose:a,list:o,deviceNames:c,onDelete:u,onRefresh:f,refreshing:p}){let{t:m}=V(),g=h(),[_,v]=r(new Set),[y,x]=r(!1),[w,E]=r([]),D=t(()=>He(c,m),[c,m]),O=t(()=>We(c,m),[c,m]),k=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),A=[..._].filter(e=>k.has(e)).map(Number),j=Re(w.map(e=>e.outcome)),M=async()=>{if(await g({title:m(`history.orphans.confirmTitle`,{count:A.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:m(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:m(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){x(!0);try{let e=await Le(A,u);E(ze(o.series,e)),v(new Set)}finally{x(!1),f()}}};return n(ve,{open:i,onOpenChange:e=>!e&&a(),children:e(te,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(T,{children:n(b,{children:m(`history.orphans.title`,`Series no longer linked to a device`)})}),e(C,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:m(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:m(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(I,{size:`sm`,variant:`outline`,onClick:f,disabled:p,children:[n(l,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.loadAgain`,`Load again`)]})]}),w.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:m(`history.orphans.summary`,{count:j.deleted,refused:j.refused,points:j.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(S,{columns:O,rows:w,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(S,{columns:D,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:N,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:m(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:_,onChange:v,rowLabel:e=>`${X(e)} — ${Y(e,c,m)}`,pageLabel:m(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(ne,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:m(`history.orphans.selected`,{count:A.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(I,{variant:`ghost`,size:`sm`,onClick:a,children:m(`history.orphans.close`,`Close`)}),e(I,{variant:`danger`,size:`sm`,disabled:A.length===0||y,onClick:()=>void M(),children:[y?n(d,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(s,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Ke=5*6e4;function qe({enabled:i}){let{t:a}=V(),[s,c]=r(!1),l=fe({},{enabled:i,staleTime:Ke}),u=j({projection:`slim`},{enabled:i}),d=ge(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(x,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(x,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(I,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(Ge,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var Q=`device`,Je=`node`;function Ye({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=V(),c=A(),l=z(),u=e=>U(e,c,l),d=k(r,{searchText:e=>[ke(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Q:Je},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(Te,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Q?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(S,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:N,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var Xe=new Set([y.Container]),$=5*6e4;function Ze(){let{t:r}=V(),i=O(`device-history`),[a,o]=Ee(),s=t(()=>L(a.getAll(`s`).flatMap(e=>{let t=ye(e);return t===null?[]:[t]})),[a]),l=a.get(`window`),d=ie(l)?l:`7d`,f=de(a.get(`range`)),m=(e,t,n)=>{let r=new URLSearchParams;for(let t of L(e))r.append(`s`,pe(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},v=Qe(i===`present`),y=B(d,Date.now(),f),b=B(d,re(Date.now(),y.to-y.from),f),S=t(()=>Pe(s,v.candidates),[s,v.candidates]),C=t(()=>new Set(s.map(R)),[s]),T=ee(),E=g(),D=h(),k=async()=>{let e=await E({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await T.update(t=>oe(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:d,selection:[...s]}))},A=async(e,t)=>{await D({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await T.update(t=>me(t,e))},j=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(De,{icon:p,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(I,{size:`sm`,variant:`outline`,onClick:()=>void k(),disabled:s.length===0||!T.writable,children:[n(_,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(P,{className:`h-64 w-full`}):i===`unknown`?n(x,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(F,{icon:u,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(qe,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[Ae.map(e=>n(I,{size:`sm`,variant:`outline`,disabled:v.status!==`ok`,onClick:()=>m(Ne(e,v.candidates),d),children:j(e)},e)),T.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(I,{size:`sm`,variant:`secondary`,onClick:()=>m(t.selection,t.window,null),children:t.name}),n(I,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void A(t.id,t.name),disabled:!T.writable,children:n(c,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(w,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:v.status===`error`?n(x,{message:v.error}):n(Ye,{catalog:v.candidates,loading:v.status===`pending`,selected:C,onChange:e=>{let t=s.filter(t=>e.has(R(t))),n=v.candidates.filter(t=>e.has(t.id)&&!C.has(t.id)).map(e=>e.ref);m([...t,...n],d)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(w,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(I,{size:`sm`,variant:`ghost`,onClick:()=>m([],d),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(xe,{value:d,onChange:e=>m(s,e),custom:f,onCustomChange:e=>m(s,`custom`,le(e))}),v.status===`pending`&&s.length>0?n(P,{className:`h-64 w-full`}):n(Fe,{part:S,window:b}),S.missing.length>0&&v.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:S.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Qe(e){let{t:n}=V(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=m().trpcClient,o=j({projection:`slim`},{enabled:e}),{nodes:s}=we(),c=t(()=>(o.data??[]).filter(e=>!Xe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=D({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),p=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>Oe(c.flatMap((e,t)=>{let n=p[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=v(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:g}}export{Ze as HistoryPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,S as r,V as i,Y as a,a as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$t as u,An as d,Bi as f,Br as p,Bt as m,Ct as h,D as g,Fn as _,Fr as v,Gn as y,Ia as b,Ln as x,Mr as S,On as C,Yt as w,_t as T,bn as E,ct as D,er as ee,hi as O,jn as k,kr as te,li as ne,lt as re,or as ie,ut as ae,xa as oe}from"./player-overlays-DuG5kk5Q.js";import{bs as A,d as se,ys as ce}from"./client-pLjIfKNS.js";import{d as j,n as le,o as ue,p as M,u as N}from"./terminal-BSZfUawf.js";import{t as de}from"./file-up-2YD_M6f_.js";import{t as fe}from"./key-CH4aXNMz.js";import{t as pe}from"./monitor-smartphone-DPI9EQus.js";import{t as me}from"./unlink-D3-IGpS8.js";import{$ as he,$r as P,Bd as ge,Bn as _e,Cc as ve,Dc as ye,Fd as be,Gr as xe,Hd as Se,Id as Ce,Jd as F,Jn as we,Jr as I,Kn as L,Ld as R,Nd as Te,O as Ee,Oc as De,Pd as Oe,Q as ke,Qr as z,Rd as Ae,U as je,Ud as Me,Vd as Ne,Vn as Pe,Vo as Fe,Wd as Ie,Wf as B,Xd as V,Yd as Le,Yn as Re,Yr as H,Zr as ze,bc as Be,br as Ve,df as He,ff as Ue,fr as We,li as Ge,mf as Ke,of as U,ot as W,pf as qe,pr as Je,qn as G,qr as Ye,uf as Xe,ur as Ze,vc as Qe,vr as $e,yr as et,zd as tt}from"./src-DOkmPL4F.js";import{t as K}from"./i18n-EpyjWJGh.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{I as nt,Jr as rt,Kr as it,Q as at,Qr as ot,Xr as st,a as ct,c as lt,i as ut,l as dt,o as ft,qr as pt,s as mt,t as ht,u as gt,x as _t}from"./index-BV01fYDf.js";import{t as vt}from"./AdminSectionedPage-CzrpTekp.js";import{t as yt}from"./AdminPage-Q2-TrrvF.js";import{t as bt}from"./InstancesTable-8uEgcvVT.js";import{C as xt,D as J,E as St,O as Y,S as Ct,T as wt,_ as Tt,a as Et,b as Dt,c as Ot,d as kt,f as At,g as jt,h as Mt,i as Nt,k as Pt,l as Ft,m as It,n as Lt,o as Rt,p as zt,s as Bt,t as Vt,u as Ht,v as Ut,w as Wt,x as Gt,y as Kt}from"./SessionsList-ByWStI3D.js";import{n as qt,t as Jt}from"./BootstrapSettingsForm-5uFD2Kof.js";s();function Yt(){let{t:e}=q(),t=D(),i=B.useUtils(),o=Pt(),{data:s,isLoading:c}=tt(),l=n(()=>s??[],[s]),u=B.useQueries(e=>l.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),d=B.auth.listLoginMethods.useQuery(),[f,p]=a(null),m=Me({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((d.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[d.data]),g=l.flatMap((e,t)=>u[t]?.data??[]),_=g.map(e=>({...Gt(e,o),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>Dt(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return r(J,{notice:Y(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:M,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`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:r(Wt,{rows:_,label:`sign-in links`,isLoading:c||u.some(e=>e.isLoading),loadError:u.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:me,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}s();var Xt={key:`access.nouns.linkedApp`};function Zt(e){if(e.type===`category`){let t=e.target??``;return t===`device`?K.t(`access.linkedAppsSection.allDevices`):K.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Qt(){let{t:e}=q(),t=D(),i=c(),o=Ae(),[s,l]=a(null),d=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),f=Ne({onSuccess:d,onError:e=>l(`Revoke failed: ${e.message}`)}),p=wt(Xt,d),m=n(()=>(o.data??[]).map(e=>Ct(e,e.scopes.map(Zt).join(`, `))),[o.data]),h=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(l(null),f.mutate({id:n.id}))},g=f.isPending?f.variables?.id??null:null;return r(J,{notice:Y(s,p.outcome),onDismissNotice:()=>{l(null),p.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:v,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`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:r(Wt,{rows:m,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:u,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void h(e),busyId:g,disabled:f.isPending||p.busy},bulk:{revoke:p,noun:Xt,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}var $t=5e3;function en(){let{t}=q(),n=B.useUtils(),i=B.auth.cliLoginPending.useQuery(void 0,{refetchInterval:$t}),a=B.auth.cliLoginDeny.useMutation({onSuccess:()=>void n.auth.cliLoginPending.invalidate()}),o=i.data??[];if(o.length===0)return null;let s=Date.now();return e(`div`,{className:`space-y-2 rounded-md border border-border bg-background-elevated p-3`,"data-testid":`pending-terminal-signins`,children:[e(`div`,{className:`flex items-center gap-2 text-xs font-medium text-foreground`,children:[r(le,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`cliLogin.pendingTitle`,`Pending terminal sign-ins`)]}),r(`ul`,{className:`space-y-1`,children:o.map(n=>{let i=ht(n.createdAt,s);return e(`li`,{className:`flex items-center justify-between gap-3 text-xs`,children:[e(`span`,{className:`min-w-0 truncate text-foreground-muted`,children:[n.userAgent??t(`cliLogin.unknownValue`,`Unknown`),` · `,n.ip??t(`cliLogin.unknownValue`,`Unknown`),` · `,i.key===`justNow`?t(`cliLogin.ageNow`,`just now`):i.key===`seconds`?t(`cliLogin.ageSeconds`,`{{count}} s ago`,{count:i.value}):t(`cliLogin.ageMinutes`,`{{count}} min ago`,{count:i.value})]}),r(U,{type:`button`,size:`sm`,variant:`ghost`,disabled:a.isPending,onClick:()=>a.mutate({requestId:n.requestId}),children:t(`cliLogin.notMe`,`Not me`)})]},n.requestId)})}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`cliLogin.pendingHint`,`To approve one, open the approval page and type the code the terminal shows.`)})]})}s();var tn={key:`access.nouns.session`};function nn(){let{t}=q(),i=D(),o=B.useUtils(),s=Pt(),c=B.auth.listSessions.useQuery(),[l,u]=a(null),d=()=>void o.auth.listSessions.invalidate(),f=B.auth.revokeSessions.useMutation({onSuccess:d,onError:e=>u(`Sign out failed: ${e.message}`)}),p=wt(tn,d),m=n(()=>(c.data??[]).map(e=>xt(e,s,{client:e=>Tt(e).label,method:Ut})),[c.data,s]),h=async e=>{await i({title:t(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:t(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:e.ownerName,name:e.name}),confirmLabel:t(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(u(null),f.mutate({id:e.id}))};return e(J,{notice:Y(l,p.outcome),onDismissNotice:()=>{u(null),p.dismiss()},id:`login-sessions`,title:t(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:pe,description:t(`access.loginSessionsSection.everyBrowserAndAppSigned`,`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:[r(en,{}),r(Wt,{rows:m,label:t(`common.sessionsLabel`),isLoading:c.isLoading,loadError:c.isError?c.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:t(`access.loginSessionsSection.signOut`,`Sign out`),icon:ue,isAvailable:e=>e.status===`active`,onRun:e=>void h(e),busyId:f.isPending&&f.variables!==void 0&&`id`in f.variables?f.variables.id:null,disabled:f.isPending||p.busy},bulk:{revoke:p,noun:tn,isSelectable:e=>e.status===`active`}})]})}var rn={"by-id":`helpers.authAuditWording.bulkNoun.credential`,"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function X(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Z(e,t){let n=X(e,`tokenId`);return X(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Q(e){return e.filter(e=>e!==null)}function an(e){let t=X(e,`prefix`);return t===null?null:K.t(`helpers.authAuditWording.prefix`,{prefix:t})}function on(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:K.t(`helpers.authAuditWording.tokenCreated`,{name:Z(n,t)}),details:Q([an(n),typeof e==`number`?K.t(`helpers.authAuditWording.expires`,{at:Kt(e)}):null])}}case`admin-token-used`:{let e=X(n,`path`);return{title:K.t(`helpers.authAuditWording.tokenUsed`,{name:Z(n,t)}),details:Q([an(n),e===null?null:K.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:K.t(`helpers.authAuditWording.tokenMinted`,{name:Z(n,t)}),details:Q([typeof e==`number`?K.t(`helpers.authAuditWording.expires`,{at:Kt(e)}):null])}}case`token-revoked`:return{title:K.t(`helpers.authAuditWording.anyTokenRevoked`,{name:Z(n,t)}),details:[]};case`admin-token-revoked`:return{title:K.t(`helpers.authAuditWording.tokenRevoked`,{name:Z(n,t)}),details:Q([an(n)])};case`credentials-revoked`:{let e=X(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=rn[e],a=i===void 0?`${e}s`:K.t(i);return{title:K.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Q([typeof r==`number`&&r>0?K.t(`helpers.authAuditWording.skipped`,{count:r}):null,X(n,`ids`)===null?null:K.t(`helpers.authAuditWording.ids`,{ids:X(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=X(n,`method`),t=X(n,`factors`);return{title:K.t(`helpers.authAuditWording.secondFactorSkipped`),details:Q([e===null?null:K.t(`helpers.authAuditWording.signedInWith`,{method:Ut(e)}),t===null?null:K.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}s();var sn=100;function cn(){let{user:e}=nt();return e?.isAdmin?r(un,{}):null}function ln(){let{data:e}=tt(),{data:t}=B.auth.listTokens.useQuery(void 0);return n(()=>{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.label);return{userNameById:n,tokenNameById:r}},[e,t])}function un(){let{t}=q(),n=B.auth.listAuthAudit.useQuery({limit:sn}),{userNameById:i,tokenNameById:a}=ln(),o=n.data??[];return e(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[e(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[r(x,{className:`h-3.5 w-3.5 text-foreground-subtle`}),r(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:t(`auth.authAuditSection.latest`,{count:sn})})]}),r(`div`,{className:`p-4`,children:n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):n.isError?e(`div`,{className:`text-[11px] text-danger`,children:[t(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,n.error?.message??t(`auth.authAuditSection.requestFailed`,`Request failed`)]}):o.length===0?e(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[r(`div`,{children:t(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),r(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:t(`auth.authAuditSection.thisTrailRecordsAdminToken`,`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.`)})]}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:o.map(e=>r(dn,{record:e,userName:e.userId===void 0?null:i.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function dn({record:t,userName:n,tokenNameById:i}){let a=on(t,i);return e(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[e(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[r(`span`,{className:`font-medium text-foreground`,children:a.title}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Kt(t.at)})]}),e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&r(`span`,{className:`text-foreground`,children:n}),t.ip!==void 0&&r(`span`,{className:`font-mono`,children:t.ip}),a.details.map(e=>r(`span`,{className:`font-mono`,children:e},e))]})]})}s();function fn(e){let{ids:t,answered:r,legacyGroupParam:i=null,groupFirst:a}=e,[o]=ot(),s=o.get(ft),c=i===null?null:o.get(i),l=o.get(mt),u=n(()=>dt({ids:t,requested:s,answered:r,legacyGroup:c,...a===void 0?{}:{groupFirst:a}}),[t,s,r,c,a]),d=n(()=>(e,t)=>`?${gt(o,e,i,t??null).toString()}`,[o,i]);return{...u,requestedSection:l,hrefFor:d}}s();var $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},pn={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens,[$.shareLinks]:$.tokens};function mn(){return[{id:$.loginSessions,label:K.t(`system.access.loginSessions`,`Login sessions`),icon:pe,render:()=>r(nn,{})},{id:$.linkedApps,label:K.t(`system.access.linkedApps`,`Linked apps`),icon:v,render:()=>r(Qt,{})},{id:$.tokens,label:K.t(`system.access.tokens`,`Tokens`),icon:N,render:({createRequested:e,onCreateConsumed:t})=>r(Mt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.externalIdentities,label:K.t(`system.access.signInLinks`,`Sign-in links`),icon:M,render:()=>r(Yt,{})},{id:$.audit,label:K.t(`system.access.audit`,`Audit`),icon:x,render:()=>r(cn,{})}]}function hn({createRequested:t=!1,onCreateConsumed:i}){let{t:a}=q(),o=n(()=>mn(),[]),s=fn({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=st(),[l]=ot(),u=l.get(`integration`),d=u===null?void 0:pn[u];if(d!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,d),r(rt,{to:`?${e.toString()}`,replace:!0})}let f=o.find(e=>e.id===s.selectedId)??o[0];return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[r(Ze,{appearance:`pills`,value:f?.id??$.loginSessions,onValueChange:e=>{c(`?${gt(l,e,null,null).toString()}`)},children:r(We,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(Je,{value:t.id,"data-testid":`access-kind-${t.id}`,children:[r(t.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),t.label]},t.id))})}),f===void 0?null:r(`div`,{role:`region`,"aria-label":f.label,"data-testid":`access-kind-body`,children:f.render({createRequested:t&&f.id===$.tokens,onCreateConsumed:i??(()=>void 0)})},f.id)]})}function gn(t,n){if(t===$.tokens)return e(U,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[r(N,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),K.t(`system.access.newToken`,`New token`)]})}function _n(){let[e,t]=a(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}function vn(){let{t}=q();return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[r(bt,{functionCap:`login-method`,icon:j,title:t(`system.authentication.connectionsTitle`,`Sign-in connections`),subtitle:t(`system.authentication.connectionsSubtitle`,`Identity providers that sign users in. Each connection has its own id, which cannot be changed later.`),emptyTitle:t(`system.authentication.connectionsEmptyTitle`,`No sign-in connections`),emptyDescription:t(`system.authentication.connectionsEmptyDescription`,`Add a connection to let users sign in through an identity provider.`),addLabel:t(`system.authentication.addConnection`,`Add connection`),install:{capability:`login-method`,label:t(`system.authentication.sectionInstall`,`Add provider`)},typedId:()=>({pattern:at})}),r(bn,{})]})}var yn=qt;function bn(){let{t}=q();return r(L,{headingId:`authentication-policy`,title:t(`system.authentication.policyTitle`,`Sign-in policy`),icon:d,children:e(`div`,{className:g,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:t(`system.authentication.localAlwaysOn`,`Username and password sign-in is always on and cannot be turned off. It is not a connection, so it has no row above.`)}),r(`p`,{className:`text-xs text-foreground-subtle`,children:r(it,{i18nKey:`system.authentication.totpNote`,components:{access:r(pt,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:r(pt,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})}),r(Jt,{sectionIds:[yn],hideSectionChrome:!0,emptyMessage:t(`system.authentication.policyUnavailable`,`Not available — the addon that owns these settings did not answer.`)})]})})}function xn({isPending:t,error:n,what:i,onRetry:a,children:o}){let{t:s}=q();return t?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.queryBody.reading`,{what:i})]}):n===null?o:r(F,{title:s(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:i}),message:n.message.length>0?n.message:s(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:a})}function Sn(){let{t}=q(),n=B.deviceCredentials.getDeviceCaStatus.useQuery({}),i=n.data;return r(J,{id:`device-ca`,title:t(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:d,description:t(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:r(xn,{isPending:n.isPending,error:n.error,what:`the device CA`,onRetry:()=>void n.refetch(),children:i!==void 0&&e(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[e(G,{label:t(`certificates.deviceCaCard.state`,`State`),children:[i.state===`ready`&&r(V,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),i.state===`absent`&&r(V,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),i.state===`unavailable`&&r(V,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),i.state===`ready`&&e(l,{children:[r(G,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:i.subject}),r(G,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:i.fingerprintSha256}),r(G,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:i.validTo})]}),i.state===`unavailable`&&r(G,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:r(`span`,{className:`text-danger`,children:i.reason})})]})})})}s();function Cn(){let{t}=q(),n=B.useUtils(),i=B.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[o,s]=a(null),c=B.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{s(null),n.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>s(`Could not save: ${e.message}`)});return r(xn,{isPending:i.isPending,error:i.error,what:`the enrollment setting`,onRetry:()=>void i.refetch(),children:i.data!==void 0&&e(G,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:r($e,{checked:i.data.selfEnrollment===`allowed`,disabled:c.isPending,"aria-label":t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>c.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:i.data.selfEnrollment===`allowed`?t(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):t(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),o!==null&&r(`span`,{className:`block text-[11px] text-danger`,children:o})]})})}s();function wn(e){let[t,n]=a(()=>Date.now());return i(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}s();var Tn=80,En=208;function Dn({open:t,users:n,onClose:i,onPaired:o}){let{t:s}=q(),c=B.deviceCredentials.startEnrollment.useMutation({onSuccess:o}),[l,u]=a(``),[d,f]=a(``),p=l===``?n[0]?.id??``:l,m=c.data,h=()=>{c.reset(),f(``),i()};return r(he,{open:t,onClose:h,title:s(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:E,width:`md`,testId:`pair-device-dialog`,error:c.isError?c.error.message:null,footer:m===void 0?e(U,{type:`button`,onClick:()=>{let e=d.trim();p===``||e===``||c.mutate({userId:p,deviceName:e})},disabled:c.isPending||p===``||d.trim()===``,children:[c.isPending&&r(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):r(U,{type:`button`,variant:`outline`,onClick:h,children:s(`certificates.pairDeviceDialog.done`,`Done`)}),children:m===void 0?e(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),r(W,{label:s(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:r(ae,{value:p,onChange:e=>u(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})}),r(W,{label:s(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:s(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:r(Ke,{value:d,maxLength:Tn,onChange:e=>f(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):r(On,{enrollUrl:m.enrollUrl,expiresAt:m.expiresAt,hubKnown:m.hubOrigin!==null,onRestart:()=>c.reset()})})}function On({enrollUrl:t,expiresAt:n,hubKnown:i,onRestart:a}){let{t:o}=q(),s=Rt(n,wn(1e3));return r(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:e(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[r(`div`,{className:s.expired?`opacity-30`:void 0,children:r(xe,{value:t,size:En,alt:o(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),e(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),r(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:s.expired?o(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):o(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:s.label})}),e(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[r(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:t}),r(_e,{value:t,srLabel:`Enrollment link`})]}),!i&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[r(w,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:o(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),s.expired&&r(U,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}s();var kn={key:`access.nouns.device`};function An({pairOpen:t,onPairClose:i}){let{t:o}=q(),s=D(),c=re(),l=B.useUtils(),d=B.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),f=tt(),[p,m]=a(null),[h,g]=a(null),_=()=>void l.deviceCredentials.listDeviceCredentials.invalidate(),v=e=>t=>{g(null),m(`${e} failed: ${t.message}`)},y=()=>{g(null),_()},b=B.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:y,onError:v(`Revoke`)}),x=B.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&m(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),y()},onError:v(`Delete`)}),S=B.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:y,onError:v(`Rename`)}),C=St(kn,e=>b.mutateAsync({id:e}),_),w=C.busy||h!==null,T=n(()=>(d.data??[]).map(Lt),[d.data]),ee=async e=>{await s({title:o(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:o(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(m(null),g(e.id),b.mutate({id:e.id}))},O=async e=>{await s({title:o(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:o(`common.delete`,`Delete`),variant:`danger`})&&(m(null),g(e.id),x.mutate({id:e.id}))},k=async e=>{let t=(await c({title:o(`certificates.devicesCard.renameDevice`,`Rename device`),label:o(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:o(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(m(null),g(e.id),S.mutate({id:e.id,deviceName:t}))},te={label:o(`certificates.devicesCard.revoke2`,`Revoke`),icon:oe,isAvailable:Et,onRun:e=>void ee(e),busyId:b.isPending?h:null,disabled:w},ne=[{label:o(`certificates.devicesCard.rename`,`Rename`),icon:ie,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void k(e),busyId:S.isPending?h:null,disabled:w},{label:o(`common.delete`,`Delete`),icon:u,isAvailable:Nt,onRun:e=>void O(e),busyId:x.isPending?h:null,disabled:w}];return e(J,{id:`devices`,title:o(`certificates.devicesCard.devices`,`Devices`),icon:E,description:o(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:Y(p,C.outcome),onDismissNotice:()=>{m(null),C.dismiss()},children:[r(Cn,{}),r(Wt,{rows:T,label:o(`certificates.devicesCard.label`),isLoading:d.isPending,loadError:d.error===null?null:d.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:te,extraActions:ne,bulk:{revoke:C,noun:kn,isSelectable:Et}}),r(Dn,{open:t,users:f.data??[],onClose:i,onPaired:_})]})}var jn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Mn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,Nn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Pn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Mn.exec(t);return e===null?jn.test(t)?K.t(`helpers.pemFile.isCert`):K.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?K.t(`helpers.pemFile.encrypted`):null}return jn.test(t)?e===`certificate`&&Mn.test(t)?K.t(`helpers.pemFile.certHasKey`):null:Mn.test(t)?K.t(`helpers.pemFile.isKey`):K.t(`helpers.pemFile.notCert`)}function Fn(e){return e.text()}s();function In({kind:n,label:i,value:o,onChange:s,rows:c=6}){let{t:l}=q(),u=t(null),[d,f]=a(null),[p,m]=a(null),h=p??Pn(n,o),g=`pem-${n}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await Fn(t);m(null),s(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return e(`div`,{className:`space-y-1`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:i}),e(`div`,{className:`flex min-w-0 items-center gap-2`,children:[d!==null&&r(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:d}),r(et,{ref:u,accept:Nn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(U,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[r(de,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),r(Ve,{id:g,value:o,onChange:e=>{f(null),m(null),s(e.target.value)},rows:c,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&r(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}s();var Ln=30;function Rn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<Ln*864e5}function zn(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Bn(){let{t}=q(),n=c(),i=Qe(void 0,{refetchInterval:15e3}),o=Be({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=ve({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=De({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=ye({onSuccess:()=>{p(!1),h(``),v(``),b(``),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),d=i.data,[f,p]=a(!1),[m,h]=a(``),[_,v]=a(``),[y,b]=a(``),x=()=>{if(!d?.caCertPem)return;let e=new Blob([d.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},S=d?.mode===`uploaded`?`Uploaded`:d?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(L,{headingId:`local-access-certificate`,title:t(`system.localAccess.certificate`,`Certificate`),icon:C,children:e(`div`,{className:`${g} space-y-3`,children:[i.isError&&r(`p`,{className:`text-xs text-danger`,children:t(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),d?.reissueError&&r(F,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:d.reissueError}),d?.restartRequired&&r(F,{variant:`warning`,title:t(`system.localAccess.restartRequired`,`Restart required`),message:t(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),d?.caMissing===!0&&r(F,{variant:`warning`,title:t(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:t(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),d?.caReplacedAt!=null&&Rn(d.caReplacedAt)&&r(F,{variant:`warning`,title:t(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:t(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(d.caReplacedAt).toLocaleString()})}),e(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.mode`,`Mode`)}),r(`dd`,{className:`font-medium`,children:S})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.validTo`,`Valid to`)}),r(`dd`,{className:`font-mono`,children:d?.validTo?new Date(d.validTo).toLocaleString():`—`})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),r(`dd`,{className:`font-mono`,title:d?.leafFingerprintSha256??void 0,children:zn(d?.leafFingerprintSha256??null)})]}),d?.storedUpload!=null&&e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.storedUpload`,`Stored upload`)}),r(`dd`,{className:`font-medium`,children:t(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(d.storedUpload.validTo).toLocaleDateString(),ca:d.storedUpload.hasCa?t(`system.localAccess.storedUploadWithCa`,`with its CA`):t(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.caSha256`,`CA SHA-256`)}),r(`dd`,{className:`font-mono`,title:d?.caFingerprintSha256??void 0,children:d?.mode===`uploaded`&&d.caFingerprintSha256===null?r(`span`,{className:`font-sans text-foreground-subtle`,children:t(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):zn(d?.caFingerprintSha256??null)})]})]}),d&&d.sans.length>0&&r(`div`,{className:`flex flex-wrap gap-1`,children:d.sans.map(e=>r(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),e(`div`,{className:`flex flex-wrap gap-2`,children:[r(Pe,{label:t(`system.localAccess.regenerate`,`Regenerate`),title:t(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:t(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:t(`system.localAccess.regenerate`,`Regenerate`),disabled:d?.mode===`uploaded`||o.isPending,action:()=>o.mutateAsync({})}),r(U,{size:`sm`,variant:`outline`,onClick:()=>p(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),d?.caCertPem&&r(U,{size:`sm`,variant:`outline`,onClick:x,children:t(`system.localAccess.downloadCa`,`Download CA`)}),d?.mode===`uploaded`&&r(Pe,{label:t(`system.localAccess.revertToGenerated`,`Revert to generated`),title:t(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:t(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:t(`system.localAccess.revert`,`Revert`),disabled:s.isPending,action:()=>s.mutateAsync({})}),d?.mode===`generated`&&d.storedUpload!=null&&r(Pe,{label:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:t(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:t(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:l.isPending,action:()=>l.mutateAsync(void 0)})]}),f&&e(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[r(In,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:m,onChange:h}),r(In,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),r(In,{kind:`ca`,label:t(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),r(U,{size:`sm`,disabled:!m.trim()||!_.trim()||Pn(`certificate`,m)!==null||Pn(`privateKey`,_)!==null||Pn(`ca`,y)!==null||u.isPending,onClick:()=>u.mutate({certPem:m,keyPem:_,...y.trim()?{caPem:y}:{}}),children:t(`system.localAccess.saveCertificate`,`Save certificate`)}),u.isError&&r(`p`,{className:`text-xs text-danger`,children:u.error instanceof Error?u.error.message:t(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var Vn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function Hn(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function Un({https:t,mesh:n,now:i}){let{t:a}=q(),o=Qe().data?.caCertPem??``,s=()=>{if(o===``)return;let e=URL.createObjectURL(new Blob([o],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},c=n?.ca,l=c?.state===`ready`?Date.parse(c.validTo):null,u=n?.listener;return e(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[r(G,{label:a(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:e(`span`,{className:`flex flex-wrap items-center gap-2`,children:[Hn(t)??`—`,o!==``&&e(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:[r(O,{className:`h-3 w-3`,"aria-hidden":!0}),a(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),r(G,{label:a(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:c===void 0?`—`:c.state===`ready`?c.fingerprintSha256:r(`span`,{className:`text-danger`,children:a(`certificates.caStrip.unavailable`,{reason:c.reason})})}),c?.state===`ready`&&e(G,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${Vn[Ht(l,i)]}`,children:[`(`,Ot(l,i),`)`]})]}),u!==void 0&&e(G,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&r(V,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&r(V,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:kt(u.since)}),` `,u.reason]})]}),n!==void 0&&!n.registryAvailable&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[r(w,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:a(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function Wn(e,t){let n=new Set;for(let t of e)n.add(t.nodeId);for(let e of t?.nodes??[])n.add(e.nodeId);return[...n].map(n=>{let r=e.find(e=>e.nodeId===n)??null,i=t?.nodes.find(e=>e.nodeId===n)??null;return{nodeId:n,isHub:r?.isHub??n===`hub`,online:r?.online??i?.online??!1,https:r,mesh:i}}).toSorted((e,t)=>Number(t.isHub)-Number(e.isHub)||e.nodeId.localeCompare(t.nodeId))}function Gn(e){return e.isHub?K.t(`helpers.nodesModel.hubReissued`):e.mesh===null?K.t(`helpers.nodesModel.noCertRecorded`):e.online?null:K.t(`helpers.certificateModel.nodeOffline`)}function Kn(e){return e.isHub||e.mesh===null?Gn(e):null}var qn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},Jn={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Yn={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function Xn(e){let t=e.https?.https;return t?.kind===`served`?Bt(t.status.validTo):null}function Zn({ms:t,now:n}){return t===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[r(`div`,{children:kt(t)}),r(`div`,{className:`text-[10px] ${qn[Ht(t,n)]}`,children:Ot(t,n)})]})}function Qn({row:t}){let{t:n}=q(),i=t.https?.https;return i===void 0?r(`span`,{className:`text-foreground-subtle`,children:`—`}):i.kind===`served`?e(`div`,{title:i.status.leafFingerprintSha256??``,children:[r(V,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),r(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Yn[i.status.mode]}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:zt(i.status.leafFingerprintSha256)}),i.status.sans.length>0&&r(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:i.status.sans.join(`, `),children:i.status.sans.join(`, `)})]}):e(`div`,{className:`max-w-[16rem]`,children:[r(V,{variant:i.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:i.kind===`unreadable`?n(`certificates.nodesColumns.unreadable`,`Unreadable`):n(`certificates.nodesColumns.notServed`,`Not served`)}),r(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:i.reason})]})}function $n({row:t}){let{t:n}=q(),i=t.mesh?.current??null;if(i===null)return r(`span`,{className:`text-foreground-subtle`,children:n(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let a=t.mesh?.history.length??0;return e(`div`,{children:[r(`div`,{className:`font-mono text-[11px]`,title:i.serial,children:It(i.serial)}),r(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:i.fingerprintSha256,children:zt(i.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[Jn[i.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function er({row:e}){let{t}=q(),n=e.mesh?.presentingCurrent??null;return n===null?r(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?r(V,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):r(V,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function tr(t){let n=t.icon;return e(U,{type:`button`,variant:`ghost`,size:`sm`,className:t.danger?`text-danger hover:bg-danger/10`:void 0,disabled:t.reason!==null||t.busy,title:t.reason??void 0,"aria-label":t.ariaLabel,onClick:t.onClick,children:[t.spinning?r(S,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):r(n,{className:`h-3 w-3`,"aria-hidden":!0}),t.label]})}function nr({reasons:t}){let{t:n}=q();return e(He,{className:`inline-block`,children:[r(qe,{children:r(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:n(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),r(Ue,{children:r(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:t.map(e=>r(`li`,{children:e},e))})})]})}function rr({row:t,o:n}){let{t:i}=q(),a=t.https===null?`No HTTPS inventory for this node.`:At(t.https).reason,o=Gn(t),s=Kn(t),c=e=>n.running?.nodeId===t.nodeId&&n.running.action===e,l=e=>!t.isHub||e===null,u=[a,o,s].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return e(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[e(`div`,{className:`flex flex-col items-end gap-0.5`,children:[l(a)&&r(tr,{label:i(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:i(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:t.nodeId}),icon:y,reason:a,busy:n.busy,spinning:c(`renew-https`),danger:!1,onClick:()=>n.onRenewHttps(t)}),l(o)&&r(tr,{label:c(`renew-identity`)?i(`certificates.nodesColumns.renewing`,`Renewing…`):i(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:i(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:y,reason:o,busy:n.busy,spinning:c(`renew-identity`),danger:!1,onClick:()=>n.onRenewIdentity(t)}),l(s)&&r(tr,{label:i(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:i(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:oe,reason:s,busy:n.busy,spinning:c(`revoke-identity`),danger:!0,onClick:()=>n.onRevokeIdentity(t)})]}),t.isHub&&u.length>0&&r(nr,{reasons:u}),!t.isHub&&a!==null&&t.https!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${t.nodeId}`,children:a}),!t.isHub&&o!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${t.nodeId}`,children:o})]})}function ir(t){return[{key:`node`,header:K.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.nodeId}),t.nodeId===`hub`&&r(V,{variant:`info`,className:`text-[10px]`,children:K.t(`common.hubWord`)}),!t.online&&r(V,{variant:`default`,className:`text-[10px]`,children:K.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>r(Qn,{row:e})},{key:`https-expires`,header:K.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>Xn(e),render:e=>r(Zn,{ms:Xn(e),now:t.now})},{key:`identity`,header:K.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>r($n,{row:e})},{key:`identity-expires`,header:K.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>r(Zn,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:K.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>r(er,{row:e})},{key:`actions`,header:K.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>r(rr,{row:e,o:t})}]}s();function ar(){let{t}=q(),i=D(),o=B.useUtils(),s=wn(6e4),c=B.certificates.listHttpsCertificates.useQuery(),l=B.certificates.getMeshCertificates.useQuery(),[u,d]=a(null),[f,p]=a(null),[m,h]=a(null),g=()=>{h(null),o.certificates.listHttpsCertificates.invalidate(),o.certificates.getMeshCertificates.invalidate()},v=e=>(t,n)=>{h(null),d(`${n.nodeId}: ${e} - ${t.message}`)},y=B.certificates.renewHttpsOnNode.useMutation({onSuccess:(e,n)=>{p({tone:`success`,message:e.restartRequired?t(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):t(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),g()},onError:v(`renewal failed`)}),b=B.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(Ft(e)),g()},onError:v(`renewal could not start`)}),x=B.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:v(`revoke failed`)}),S=y.isPending||b.isPending||x.isPending,C=(e,t)=>{d(null),p(null),h({nodeId:e,action:t})},w=async e=>{await i({title:t(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:e.nodeId}),message:e.isHub?t(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):t(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:t(`certificates.nodesCard.renew`,`Renew`)})&&(C(e.nodeId,`renew-https`),y.mutate({nodeId:e.nodeId}))},T=e=>{C(e.nodeId,`renew-identity`),b.mutate({nodeId:e.nodeId})},E=async e=>{await i({title:t(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:e.nodeId}),message:t(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:e.nodeId}),confirmLabel:t(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(C(e.nodeId,`revoke-identity`),x.mutate({nodeId:e.nodeId}))},ee=ir({now:s,busy:S,running:m,onRenewHttps:e=>void w(e),onRenewIdentity:T,onRevokeIdentity:e=>void E(e)}),O=n(()=>Wn(c.data??[],l.data),[c.data,l.data]),k=l.data?.registryAvailable??!0;return r(J,{id:`nodes`,title:t(`certificates.nodesCard.nodes`,`Nodes`),icon:_,description:t(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:Y(u,f),onDismissNotice:()=>{d(null),p(null)},children:r(xn,{isPending:c.isPending||l.isPending,error:c.error??l.error,what:`node certificates`,onRetry:()=>{c.refetch(),l.refetch()},children:e(`div`,{className:`space-y-3`,children:[r(Un,{https:c.data??[],mesh:l.data,now:s}),r(we,{columns:ee,rows:O,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Re,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:k?t(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):t(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function or({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[r(An,{pairOpen:t,onPairClose:n}),r(Sn,{}),r(Bn,{}),r(ar,{})]})}function sr({userId:t,username:n,onClose:i}){let{t:a}=q(),o=D(),s=B.useUtils(),c=R({userId:t}),l=B.auth.listLoginMethods.useQuery(),u=Me({onSuccess:()=>void s.userManagement.listExternalIdentities.invalidate()}),d=new Map((l.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=c.data??[],p=async(e,r)=>{await o({title:a(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:a(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:n,label:r}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&u.mutate({userId:t,provider:e.provider,subject:e.subject})};return r(Ye,{open:!0,onOpenChange:e=>!e&&i(),children:e(H,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[r(z,{children:e(P,{className:`flex items-center gap-2`,children:[r(v,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.externalIdentitiesModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),r(I,{className:`space-y-3`,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),a(`common.loading`,`Loading…`)]}):f.length===0?r(`p`,{className:`text-xs text-foreground-subtle`,children:a(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(t=>{let n=d.get(t.provider),i=n??t.provider;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[e(`div`,{className:`flex-1 min-w-0`,children:[e(`div`,{className:`font-medium text-foreground truncate`,children:[i,n===void 0&&r(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:a(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),e(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[t.label??t.subject,` ·`,` `,new Date(t.linkedAt).toLocaleDateString()]})]}),e(U,{variant:`unstyled`,onClick:()=>void p(t,i),disabled:u.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:[r(me,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),r(ze,{children:r(U,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function cr({userId:t,username:n,onClose:i}){let{t:a}=q(),o=c(),s=D(),u=Ce({userId:t}),d=u.data,m=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),g=be({onSuccess:()=>{m(),i()}}),_=u.isLoading?`loading`:d?.enabled?`enrolled`:`not_enrolled`;return r(Ye,{open:!0,onOpenChange:e=>!e&&i(),children:e(H,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(z,{children:e(P,{className:`flex items-center gap-2`,children:[r(E,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.totpModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(I,{className:`space-y-4`,children:[_===`loading`&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),a(`users.totpModal.checkingStatus`,`Checking status…`)]}),_===`not_enrolled`&&e(`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:[r(p,{className:`h-4 w-4 mt-0.5 shrink-0`}),e(`div`,{children:[r(`div`,{className:`font-medium text-foreground`,children:a(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),r(`p`,{className:`mt-0.5`,children:a(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),_===`enrolled`&&d&&e(l,{children:[e(`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:[r(f,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),e(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[r(`div`,{className:`font-medium`,children:a(`users.totpModal.2faIsActive`,`2FA is active`)}),r(`div`,{className:`text-foreground-subtle`,children:a(`common.enrolledOn`,{when:d.confirmedAt?new Date(d.confirmedAt).toLocaleString():`—`})})]})]}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(`users.totpModal.removingHereClearsTheServer`,`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.`)}),e(`div`,{className:`flex justify-end gap-2`,children:[r(U,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)}),e(U,{variant:`unstyled`,onClick:async()=>{await s({title:a(`users.totpModal.remove2fa`,`Remove 2FA`),message:a(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:n}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&g.mutate({userId:t})},disabled:g.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:[g.isPending?r(S,{className:`h-3 w-3 animate-spin`}):r(h,{className:`h-3 w-3`}),a(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}s();function lr({userId:t,username:n,onClose:i}){let{t:o}=q(),{user:s,logout:c}=nt(),l=s?.id===t,u=D(),d=B.useUtils(),f=B.auth.listSessions.useQuery({userId:t}),[p,m]=a(null),h=B.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(l&&`userId`in t){c();return}d.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await u({title:o(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:o(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:n,label:Tt(e.client).label}),confirmLabel:o(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await u({title:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:l?o(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):o(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:n}),confirmLabel:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:t}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return r(Ye,{open:!0,onOpenChange:e=>!e&&i(),children:e(H,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[r(z,{children:e(P,{className:`flex items-center gap-2`,children:[r(pe,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[o(`users.userSessionsModal.activeSessions`,`Active sessions`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[o(`users.userSessionsModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(I,{className:`space-y-3`,children:[p!==null&&r(`div`,{className:`text-[11px] text-danger`,children:p}),r(Vt,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void g(e),revokingId:v})]}),e(ze,{className:`justify-between`,children:[e(U,{variant:`unstyled`,onClick:()=>void _(),disabled:h.isPending||(f.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:[h.isPending&&v===null?r(S,{className:`h-3 w-3 animate-spin`}):r(ue,{className:`h-3 w-3`}),o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),r(U,{onClick:i,variant:`secondary`,children:o(`common.close`,`Close`)})]})]})})}function ur({scopes:t,invalidReason:n}){let{t:i}=q(),a=T(),s=o({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=Fe({projection:`slim`}),l=c?.length??null;if(n!==null)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,"data-testid":`role-preview`,children:[r(k,{className:`h-3 w-3 shrink-0`}),n]});if(s.isLoading)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,"data-testid":`role-preview`,children:[r(S,{className:`h-3 w-3 shrink-0 animate-spin`}),i(`users.rolePreview.resolving`)]});if(s.isError||!s.data)return r(`p`,{className:`text-[11px] text-danger`,"data-testid":`role-preview`,children:i(`users.rolePreview.couldNotResolve`)});let u=s.data.viewableDeviceCount,d=s.data.device.view.all?i(`users.rolePreview.everyDevice`,{count:u}):l===null?i(`users.rolePreview.devicesVisible`,{count:u}):i(`users.rolePreview.devicesVisibleOf`,{count:u,total:l});return e(`p`,{className:`flex items-center gap-1.5 text-[11px] ${u===0?`text-warning`:`text-foreground`}`,"data-testid":`role-preview`,children:[u===0?r(k,{className:`h-3 w-3 shrink-0`}):r(ne,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u===0?i(`users.rolePreview.noDevice`):d]})}function dr(e){let t=se(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:ce,unconfigured:!e.isAdmin};let n=vr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:yr(n.mode,n.pickedIds,t.features),unconfigured:!1}}function fr(e,t){return{...e,role:t}}function pr(e,t){return{...e,mode:t,viewer:yr(t,e.pickedIds,e.viewer.features)}}function mr(e,t){let n=br(t);return{...e,pickedIds:n,viewer:yr(e.mode,n,e.viewer.features)}}function hr(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:yr(e.mode,e.pickedIds,i)}}function gr(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function _r(e){return gr(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function vr(e){if(e.allow===`*`)return{mode:`except`,pickedIds:e.block};let t=new Set(e.block);return{mode:`only`,pickedIds:e.allow.filter(e=>!t.has(e))}}function yr(e,t,n){let r=br(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function br(e){return[...new Set(e)]}s();var xr=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function Sr(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function Cr(e){let t=[];for(let n of e)n.parentDeviceId===null&&t.push({id:n.id,name:n.name,type:String(n.type),...n.location===null?{}:{location:n.location}});return t}function wr({user:t,isSelf:i,onClose:o,onSubmit:s,submitting:c,error:u}){let{t:d}=q(),[f,p]=a(n(()=>dr(t),[t])),m=Fe({projection:`slim`}),h=m.data,g=Sr(m.isError,h),_=n(()=>Cr(h??[]),[h]),v=n(()=>({state:g,devices:g===`answered`?(h??[]).map(e=>({id:e.id,name:e.name})):void 0}),[g,h]),y=gr(f),x=_r(f),C=y===`no-allowed-device`?d(`users.userAccessModal.pickAllowedDevice`):null,w=e=>{p(fr(f,e))},T=[{value:`except`,label:d(`users.userAccessModal.modeExcept`)},{value:`only`,label:d(`users.userAccessModal.modeOnly`)}];return r(Ye,{open:!0,onOpenChange:e=>!e&&o(),children:e(H,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(z,{children:r(P,{children:d(`users.userAccessModal.title`,{name:t.username})})}),e(I,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&r(F,{variant:`warning`,title:d(`users.userAccessModal.noAccessYet`),message:d(`users.userAccessModal.noAccessYetDetail`,{name:t.username})}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:xr,children:d(`users.userAccessModal.role`)}),e(`div`,{role:`radiogroup`,"aria-label":d(`users.userAccessModal.role`),className:`grid gap-1.5 sm:grid-cols-2`,children:[r(Tr,{name:`admin`,checked:f.role===`admin`,label:d(`users.userAccessModal.admin`),description:d(`users.userAccessModal.adminDescription`),onPick:()=>w(`admin`)}),r(Tr,{name:`viewer`,checked:f.role===`viewer`,disabled:i,label:d(`users.userAccessModal.viewer`),description:d(i?`users.userAccessModal.cannotDemoteSelf`:`users.userAccessModal.viewerDescription`),onPick:()=>w(`viewer`)})]})]}),f.role===`viewer`&&e(l,{children:[e(`section`,{className:`space-y-3`,children:[r(`h3`,{className:xr,children:d(`users.userAccessModal.devices`)}),r(je,{label:d(`users.userAccessModal.whichDevices`),value:f.mode,options:T,onChange:e=>p(pr(f,e))}),r(Ee,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(mr(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),r(ur,{scopes:x?.scopes??[],invalidReason:C})]}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:xr,children:d(`users.userAccessModal.features`)}),r(`div`,{className:`space-y-1`,children:A.map(t=>e(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[r(b,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>p(hr(f,t.id,e.target.checked))}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:d(`users.viewerFeatures.${t.id}.label`,t.label)}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:d(`users.viewerFeatures.${t.id}.description`,t.description)})]})]},t.id))})]})]}),u!==null&&r(F,{message:u})]}),e(ze,{children:[r(U,{variant:`outline`,size:`sm`,onClick:o,children:d(`common.cancel`,`Cancel`)}),r(U,{size:`sm`,onClick:()=>x!==null&&s(x),disabled:c||x===null,children:c?r(S,{className:`h-3 w-3 animate-spin`}):d(`users.userAccessModal.saveAccess`)})]})]})})}function Tr({name:t,checked:n,disabled:i=!1,label:a,description:o,onPick:s}){return e(`label`,{className:`flex items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-surface-hover`} ${i?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[r(Le,{name:`user-role`,value:t,checked:n,disabled:i,onChange:s,className:`mt-0.5`}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:a}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:o})]})]})}s();var Er=8;function Dr(){return{username:``,password:``,isAdmin:!1}}function Or(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function kr(e){return e instanceof Error?e.message:K.t(`admin.system.users.genericError`)}function Ar(){let{t}=q(),n=c(),{user:o}=nt(),{state:s,openNew:f,openEdit:p,close:h}=ke(),[g,_]=a(null),[y,x]=a(null),[C,w]=a(!1),{data:T,isLoading:O,isError:k,error:te,refetch:ne}=tt(),ae=D(),oe=re(),A=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),se=Te(),ce=Oe({onSuccess:A}),j=Ie({onSuccess:A}),le=ge({onSuccess:A}),ue=Se(),[M,N]=a(null),[de,me]=a(!1),[P,_e]=a(null),[ve,ye]=a(null),[be,xe]=a(null),[Ce,I]=a(null),L=T??[],R=s.mode===`edit`?L.find(e=>e.id===s.id)??null:null,Ee=()=>{_(null),x(null),w(!1),se.reset(),j.reset(),h()};i(()=>{if(s.mode===`closed`){_(null),x(null),w(!1);return}if(s.mode===`new`){_(e=>e!==null&&e.id===void 0?e:Dr());return}if(R===null){O||h();return}_(e=>e?.id===R.id?e:Or(R))},[s,R,O,h]);let De=s.mode===`new`&&g!==null&&g.id===void 0||s.mode===`edit`&&g!==null&&R!==null;async function z(e){await ae({title:t(`admin.system.users.deleteUser`,`Delete user`),message:t(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:e.username}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&(ce.mutate({id:e.id}),s.mode===`edit`&&s.id===e.id&&Ee())}async function Ae(e){let n=await oe({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:e.username}),label:t(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:t(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:t(`admin.system.users.continue`,`Continue`),validate:e=>e.length<Er?K.t(`admin.system.users.passwordTooShort`,{min:Er}):null});n===null||n.length===0||await ae({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:e.username}),confirmLabel:t(`common.reset`,`Reset`)})&&le.mutate({id:e.id,newPassword:n})}function je(e){_e(null),N(e)}async function Me(e,t){me(!0),_e(null);try{t.isAdmin!==e.isAdmin&&await j.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await ue.mutateAsync({userId:e.id,scopes:[...t.scopes]}),N(null)}catch(e){_e(kr(e))}finally{me(!1),A()}}async function Ne(){if(g!==null){x(null);try{if(g.id===void 0){let e=g.username.trim();if(e===``||g.password.length<Er)return;await se.mutateAsync({username:e,password:g.password,isAdmin:g.isAdmin})}else await j.mutateAsync({id:g.id,isAdmin:g.isAdmin});A(),Ee()}catch(e){x(kr(e))}}}function Pe(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let Fe=se.isPending||j.isPending,B=g!==null&&g.id===void 0&&g.username.trim()!==``&&g.password.length>=Er,V=g!==null&&g.id!==void 0,Le=Fe||(g?.id===void 0?!B:!V),Re=e=>ce.isPending&&ce.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||le.isPending&&le.variables?.id===e.id,H=[{key:`username`,header:t(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>r(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`scopes`,header:t(`admin.system.users.access`,`Access`),sortValue:e=>jr(e),render:n=>r(`span`,{onClick:e=>e.stopPropagation(),children:e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>je(n),disabled:Re(n),title:t(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${n.id}`,children:[r(d,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),r(Mr,{user:n})]})})},{key:`createdAt`,header:t(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>r(`span`,{className:`text-foreground-subtle`,children:Pe(e.createdAt)})},{key:`actions`,header:t(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:n=>{let i=Re(n),a=n.id!==o?.id&&n.totpEnabled;return e(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>p(n.id),disabled:i,title:t(`admin.system.users.editUser`,`Edit user`),children:[r(ie,{className:`h-3 w-3`}),t(`common.edit`,`Edit`)]}),a&&e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ye(n),disabled:i,title:t(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[r(E,{className:`h-3 w-3`}),t(`admin.system.users.remove2fa`,`Remove 2FA`)]}),e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>xe(n),disabled:i,title:t(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[r(v,{className:`h-3 w-3`}),t(`admin.system.users.signInLinks`,`Sign-in links`)]}),e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>I(n),disabled:i,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[r(pe,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void Ae(n),disabled:i,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[r(fe,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void z(n),disabled:i,title:t(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[i?r(S,{className:`h-3 w-3 animate-spin`}):r(u,{className:`h-3 w-3`}),t(`common.delete`,`Delete`)]})]})}}];return e(yt,{embedded:!0,icon:m,title:t(`admin.system.users.users`,`Users`),subtitle:t(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:e(U,{size:`sm`,type:`button`,onClick:()=>{x(null),f()},children:[r(ee,{className:`h-3.5 w-3.5`}),t(`admin.system.users.createUser`,`Create User`)]}),children:[k&&r(F,{title:t(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:kr(te),onRetry:()=>void ne()}),O&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}),!O&&!k&&L.length===0&&r(Ge,{icon:m,title:t(`admin.system.users.noUsersYet`,`No users yet`),description:t(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!O&&!k&&L.length>0&&r(we,{columns:H,rows:L,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>p(e.id)}),r(he,{open:De,onClose:Ee,title:g?.id===void 0?t(`admin.system.users.createUser`,`Create User`):t(`admin.system.users.edit`,`Edit {{value1}}`,{value1:g.username||`user`}),icon:m,error:y,testId:`user-form-dialog`,footer:r(U,{size:`sm`,type:`button`,disabled:Le,onClick:()=>void Ne(),children:Fe?e(l,{children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`admin.system.users.saving`,`Saving…`)]}):g?.id===void 0?t(`admin.system.users.create`,`Create`):t(`common.save`,`Save`)}),children:g!==null&&e(`div`,{className:`space-y-3`,children:[r(W,{label:t(`admin.system.users.username`,`Username`),required:g.id===void 0,children:r(Ke,{value:g.username,onChange:e=>_({...g,username:e.target.value}),placeholder:`john`,autoFocus:g.id===void 0,disabled:g.id!==void 0,"data-testid":`user-form-username`})}),g.id===void 0&&r(W,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(Er)}),children:r(Xe,{value:g.password,onValueChange:e=>_({...g,password:e}),shown:C,onToggleShown:()=>w(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),r(W,{label:t(`admin.system.users.admin`,`Admin`),description:t(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:e(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[r(b,{checked:g.isAdmin,onChange:e=>_({...g,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),r(`span`,{children:t(`admin.system.users.admin`,`Admin`)})]})}),g.id!==void 0&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),ve&&r(cr,{userId:ve.id,username:ve.username,onClose:()=>ye(null)}),be&&r(sr,{userId:be.id,username:be.username,onClose:()=>xe(null)}),Ce&&r(lr,{userId:Ce.id,username:Ce.username,onClose:()=>I(null)}),M&&r(wr,{user:M,isSelf:M.id===o?.id,onClose:()=>N(null),onSubmit:e=>void Me(M,e),submitting:de,error:P})]})}function jr(e){let t=dr(e);return t.role===`admin`?0:t.unconfigured?2:1}function Mr({user:t}){let{t:n}=q(),i=dr(t);if(i.role===`admin`)return r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.admin`)});if(i.unconfigured)return r(`span`,{className:`font-medium text-warning`,children:n(`admin.system.users.noAccess`,`No access`)});let{allow:a,block:o,features:s}=i.viewer,c=a===`*`?n(`users.accessSummary.allDevices`):n(`users.accessSummary.devices`,{count:a.length});return e(`span`,{className:`text-foreground-subtle`,children:[r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.viewer`)}),` ·`,` `,c,o.length>0&&e(l,{children:[` · `,n(`users.accessSummary.blocked`,{count:o.length})]}),s.length>0&&e(l,{children:[` · `,n(`users.accessSummary.features`,{count:s.length})]})]})}s();var Nr={"api-keys":$.tokens,"linked-sessions":$.linkedApps},Pr=`certificates`;function Fr(t){return e(U,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[r(E,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),K.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Ir(){let{t:e}=q(),[t]=ot(),n=_n(),[i,o]=a(!1),s=Nr[t.get(`tab`)??``];if(s!==void 0)return r(rt,{to:lt(`access`,{integration:s}),replace:!0});let c=_t(`/system/identity`,{t:e,isAdmin:!0})??{icon:te,title:e(`system.identity`,`Identity & Access`)},l=t.get(`tab`)??`users`,u=t.get(`integration`),d=l===ct.access.tab?gn(u,n.requestCreate):l===`certificates`?Fr(()=>o(!0)):void 0;return r(vt,{icon:c.icon,title:c.title,defaultSection:`users`,sectionsLabel:`${c.title} sections`,actions:d,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:r(Ar,{})},{id:ct.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:ut.concat([jt.token,jt.scoped,jt.admin]),content:r(hn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Pr,label:e(`systemPage.identity.certificates`,`Certificates`),content:r(or,{pairOpen:i,onPairClose:()=>o(!1)})},{id:ct.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:r(vn,{}),ownedParams:ut}]})}export{Ir as IdentityPage};
|
|
1
|
+
import{C as e,J as t,K as n,S as r,V as i,Y as a,a as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$t as u,An as d,Bi as f,Br as p,Bt as m,Ct as h,D as g,Fn as _,Fr as v,Gn as y,Ia as b,Ln as x,Mr as S,On as C,Yt as w,_t as T,bn as E,ct as D,er as ee,hi as O,jn as k,kr as te,li as ne,lt as re,or as ie,ut as ae,xa as oe}from"./player-overlays-DuG5kk5Q.js";import{bs as A,d as se,ys as ce}from"./client-pLjIfKNS.js";import{d as j,n as le,o as ue,p as M,u as N}from"./terminal-BSZfUawf.js";import{t as de}from"./file-up-2YD_M6f_.js";import{t as fe}from"./key-CH4aXNMz.js";import{t as pe}from"./monitor-smartphone-DPI9EQus.js";import{t as me}from"./unlink-D3-IGpS8.js";import{$ as he,$r as P,Bd as ge,Bn as _e,Cc as ve,Dc as ye,Fd as be,Gr as xe,Hd as Se,Id as Ce,Jd as F,Jn as we,Jr as I,Kn as L,Ld as R,Nd as Te,O as Ee,Oc as De,Pd as Oe,Q as ke,Qr as z,Rd as Ae,U as je,Ud as Me,Vd as Ne,Vn as Pe,Vo as Fe,Wd as Ie,Wf as B,Xd as V,Yd as Le,Yn as Re,Yr as H,Zr as ze,bc as Be,br as Ve,df as He,ff as Ue,fr as We,li as Ge,mf as Ke,of as U,ot as W,pf as qe,pr as Je,qn as G,qr as Ye,uf as Xe,ur as Ze,vc as Qe,vr as $e,yr as et,zd as tt}from"./src-DOkmPL4F.js";import{t as K}from"./i18n-EpyjWJGh.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{I as nt,Jr as rt,Kr as it,Q as at,Qr as ot,Xr as st,a as ct,c as lt,i as ut,l as dt,o as ft,qr as pt,s as mt,t as ht,u as gt,x as _t}from"./index-t4MmHqcc.js";import{t as vt}from"./AdminSectionedPage-BgDzN6TR.js";import{t as yt}from"./AdminPage-Q2-TrrvF.js";import{t as bt}from"./InstancesTable-BGr_CSfQ.js";import{C as xt,D as J,E as St,O as Y,S as Ct,T as wt,_ as Tt,a as Et,b as Dt,c as Ot,d as kt,f as At,g as jt,h as Mt,i as Nt,k as Pt,l as Ft,m as It,n as Lt,o as Rt,p as zt,s as Bt,t as Vt,u as Ht,v as Ut,w as Wt,x as Gt,y as Kt}from"./SessionsList-C1OAywF9.js";import{n as qt,t as Jt}from"./BootstrapSettingsForm-C6EAxUx0.js";s();function Yt(){let{t:e}=q(),t=D(),i=B.useUtils(),o=Pt(),{data:s,isLoading:c}=tt(),l=n(()=>s??[],[s]),u=B.useQueries(e=>l.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),d=B.auth.listLoginMethods.useQuery(),[f,p]=a(null),m=Me({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((d.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[d.data]),g=l.flatMap((e,t)=>u[t]?.data??[]),_=g.map(e=>({...Gt(e,o),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>Dt(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return r(J,{notice:Y(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:M,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`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:r(Wt,{rows:_,label:`sign-in links`,isLoading:c||u.some(e=>e.isLoading),loadError:u.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:me,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}s();var Xt={key:`access.nouns.linkedApp`};function Zt(e){if(e.type===`category`){let t=e.target??``;return t===`device`?K.t(`access.linkedAppsSection.allDevices`):K.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Qt(){let{t:e}=q(),t=D(),i=c(),o=Ae(),[s,l]=a(null),d=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),f=Ne({onSuccess:d,onError:e=>l(`Revoke failed: ${e.message}`)}),p=wt(Xt,d),m=n(()=>(o.data??[]).map(e=>Ct(e,e.scopes.map(Zt).join(`, `))),[o.data]),h=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(l(null),f.mutate({id:n.id}))},g=f.isPending?f.variables?.id??null:null;return r(J,{notice:Y(s,p.outcome),onDismissNotice:()=>{l(null),p.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:v,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`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:r(Wt,{rows:m,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:u,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void h(e),busyId:g,disabled:f.isPending||p.busy},bulk:{revoke:p,noun:Xt,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}var $t=5e3;function en(){let{t}=q(),n=B.useUtils(),i=B.auth.cliLoginPending.useQuery(void 0,{refetchInterval:$t}),a=B.auth.cliLoginDeny.useMutation({onSuccess:()=>void n.auth.cliLoginPending.invalidate()}),o=i.data??[];if(o.length===0)return null;let s=Date.now();return e(`div`,{className:`space-y-2 rounded-md border border-border bg-background-elevated p-3`,"data-testid":`pending-terminal-signins`,children:[e(`div`,{className:`flex items-center gap-2 text-xs font-medium text-foreground`,children:[r(le,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`cliLogin.pendingTitle`,`Pending terminal sign-ins`)]}),r(`ul`,{className:`space-y-1`,children:o.map(n=>{let i=ht(n.createdAt,s);return e(`li`,{className:`flex items-center justify-between gap-3 text-xs`,children:[e(`span`,{className:`min-w-0 truncate text-foreground-muted`,children:[n.userAgent??t(`cliLogin.unknownValue`,`Unknown`),` · `,n.ip??t(`cliLogin.unknownValue`,`Unknown`),` · `,i.key===`justNow`?t(`cliLogin.ageNow`,`just now`):i.key===`seconds`?t(`cliLogin.ageSeconds`,`{{count}} s ago`,{count:i.value}):t(`cliLogin.ageMinutes`,`{{count}} min ago`,{count:i.value})]}),r(U,{type:`button`,size:`sm`,variant:`ghost`,disabled:a.isPending,onClick:()=>a.mutate({requestId:n.requestId}),children:t(`cliLogin.notMe`,`Not me`)})]},n.requestId)})}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`cliLogin.pendingHint`,`To approve one, open the approval page and type the code the terminal shows.`)})]})}s();var tn={key:`access.nouns.session`};function nn(){let{t}=q(),i=D(),o=B.useUtils(),s=Pt(),c=B.auth.listSessions.useQuery(),[l,u]=a(null),d=()=>void o.auth.listSessions.invalidate(),f=B.auth.revokeSessions.useMutation({onSuccess:d,onError:e=>u(`Sign out failed: ${e.message}`)}),p=wt(tn,d),m=n(()=>(c.data??[]).map(e=>xt(e,s,{client:e=>Tt(e).label,method:Ut})),[c.data,s]),h=async e=>{await i({title:t(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:t(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:e.ownerName,name:e.name}),confirmLabel:t(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(u(null),f.mutate({id:e.id}))};return e(J,{notice:Y(l,p.outcome),onDismissNotice:()=>{u(null),p.dismiss()},id:`login-sessions`,title:t(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:pe,description:t(`access.loginSessionsSection.everyBrowserAndAppSigned`,`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:[r(en,{}),r(Wt,{rows:m,label:t(`common.sessionsLabel`),isLoading:c.isLoading,loadError:c.isError?c.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:t(`access.loginSessionsSection.signOut`,`Sign out`),icon:ue,isAvailable:e=>e.status===`active`,onRun:e=>void h(e),busyId:f.isPending&&f.variables!==void 0&&`id`in f.variables?f.variables.id:null,disabled:f.isPending||p.busy},bulk:{revoke:p,noun:tn,isSelectable:e=>e.status===`active`}})]})}var rn={"by-id":`helpers.authAuditWording.bulkNoun.credential`,"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function X(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Z(e,t){let n=X(e,`tokenId`);return X(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Q(e){return e.filter(e=>e!==null)}function an(e){let t=X(e,`prefix`);return t===null?null:K.t(`helpers.authAuditWording.prefix`,{prefix:t})}function on(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:K.t(`helpers.authAuditWording.tokenCreated`,{name:Z(n,t)}),details:Q([an(n),typeof e==`number`?K.t(`helpers.authAuditWording.expires`,{at:Kt(e)}):null])}}case`admin-token-used`:{let e=X(n,`path`);return{title:K.t(`helpers.authAuditWording.tokenUsed`,{name:Z(n,t)}),details:Q([an(n),e===null?null:K.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:K.t(`helpers.authAuditWording.tokenMinted`,{name:Z(n,t)}),details:Q([typeof e==`number`?K.t(`helpers.authAuditWording.expires`,{at:Kt(e)}):null])}}case`token-revoked`:return{title:K.t(`helpers.authAuditWording.anyTokenRevoked`,{name:Z(n,t)}),details:[]};case`admin-token-revoked`:return{title:K.t(`helpers.authAuditWording.tokenRevoked`,{name:Z(n,t)}),details:Q([an(n)])};case`credentials-revoked`:{let e=X(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=rn[e],a=i===void 0?`${e}s`:K.t(i);return{title:K.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Q([typeof r==`number`&&r>0?K.t(`helpers.authAuditWording.skipped`,{count:r}):null,X(n,`ids`)===null?null:K.t(`helpers.authAuditWording.ids`,{ids:X(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=X(n,`method`),t=X(n,`factors`);return{title:K.t(`helpers.authAuditWording.secondFactorSkipped`),details:Q([e===null?null:K.t(`helpers.authAuditWording.signedInWith`,{method:Ut(e)}),t===null?null:K.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}s();var sn=100;function cn(){let{user:e}=nt();return e?.isAdmin?r(un,{}):null}function ln(){let{data:e}=tt(),{data:t}=B.auth.listTokens.useQuery(void 0);return n(()=>{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.label);return{userNameById:n,tokenNameById:r}},[e,t])}function un(){let{t}=q(),n=B.auth.listAuthAudit.useQuery({limit:sn}),{userNameById:i,tokenNameById:a}=ln(),o=n.data??[];return e(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[e(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[r(x,{className:`h-3.5 w-3.5 text-foreground-subtle`}),r(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:t(`auth.authAuditSection.latest`,{count:sn})})]}),r(`div`,{className:`p-4`,children:n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):n.isError?e(`div`,{className:`text-[11px] text-danger`,children:[t(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,n.error?.message??t(`auth.authAuditSection.requestFailed`,`Request failed`)]}):o.length===0?e(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[r(`div`,{children:t(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),r(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:t(`auth.authAuditSection.thisTrailRecordsAdminToken`,`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.`)})]}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:o.map(e=>r(dn,{record:e,userName:e.userId===void 0?null:i.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function dn({record:t,userName:n,tokenNameById:i}){let a=on(t,i);return e(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[e(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[r(`span`,{className:`font-medium text-foreground`,children:a.title}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Kt(t.at)})]}),e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&r(`span`,{className:`text-foreground`,children:n}),t.ip!==void 0&&r(`span`,{className:`font-mono`,children:t.ip}),a.details.map(e=>r(`span`,{className:`font-mono`,children:e},e))]})]})}s();function fn(e){let{ids:t,answered:r,legacyGroupParam:i=null,groupFirst:a}=e,[o]=ot(),s=o.get(ft),c=i===null?null:o.get(i),l=o.get(mt),u=n(()=>dt({ids:t,requested:s,answered:r,legacyGroup:c,...a===void 0?{}:{groupFirst:a}}),[t,s,r,c,a]),d=n(()=>(e,t)=>`?${gt(o,e,i,t??null).toString()}`,[o,i]);return{...u,requestedSection:l,hrefFor:d}}s();var $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},pn={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens,[$.shareLinks]:$.tokens};function mn(){return[{id:$.loginSessions,label:K.t(`system.access.loginSessions`,`Login sessions`),icon:pe,render:()=>r(nn,{})},{id:$.linkedApps,label:K.t(`system.access.linkedApps`,`Linked apps`),icon:v,render:()=>r(Qt,{})},{id:$.tokens,label:K.t(`system.access.tokens`,`Tokens`),icon:N,render:({createRequested:e,onCreateConsumed:t})=>r(Mt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.externalIdentities,label:K.t(`system.access.signInLinks`,`Sign-in links`),icon:M,render:()=>r(Yt,{})},{id:$.audit,label:K.t(`system.access.audit`,`Audit`),icon:x,render:()=>r(cn,{})}]}function hn({createRequested:t=!1,onCreateConsumed:i}){let{t:a}=q(),o=n(()=>mn(),[]),s=fn({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=st(),[l]=ot(),u=l.get(`integration`),d=u===null?void 0:pn[u];if(d!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,d),r(rt,{to:`?${e.toString()}`,replace:!0})}let f=o.find(e=>e.id===s.selectedId)??o[0];return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[r(Ze,{appearance:`pills`,value:f?.id??$.loginSessions,onValueChange:e=>{c(`?${gt(l,e,null,null).toString()}`)},children:r(We,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(Je,{value:t.id,"data-testid":`access-kind-${t.id}`,children:[r(t.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),t.label]},t.id))})}),f===void 0?null:r(`div`,{role:`region`,"aria-label":f.label,"data-testid":`access-kind-body`,children:f.render({createRequested:t&&f.id===$.tokens,onCreateConsumed:i??(()=>void 0)})},f.id)]})}function gn(t,n){if(t===$.tokens)return e(U,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[r(N,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),K.t(`system.access.newToken`,`New token`)]})}function _n(){let[e,t]=a(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}function vn(){let{t}=q();return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[r(bt,{functionCap:`login-method`,icon:j,title:t(`system.authentication.connectionsTitle`,`Sign-in connections`),subtitle:t(`system.authentication.connectionsSubtitle`,`Identity providers that sign users in. Each connection has its own id, which cannot be changed later.`),emptyTitle:t(`system.authentication.connectionsEmptyTitle`,`No sign-in connections`),emptyDescription:t(`system.authentication.connectionsEmptyDescription`,`Add a connection to let users sign in through an identity provider.`),addLabel:t(`system.authentication.addConnection`,`Add connection`),install:{capability:`login-method`,label:t(`system.authentication.sectionInstall`,`Add provider`)},typedId:()=>({pattern:at})}),r(bn,{})]})}var yn=qt;function bn(){let{t}=q();return r(L,{headingId:`authentication-policy`,title:t(`system.authentication.policyTitle`,`Sign-in policy`),icon:d,children:e(`div`,{className:g,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:t(`system.authentication.localAlwaysOn`,`Username and password sign-in is always on and cannot be turned off. It is not a connection, so it has no row above.`)}),r(`p`,{className:`text-xs text-foreground-subtle`,children:r(it,{i18nKey:`system.authentication.totpNote`,components:{access:r(pt,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:r(pt,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})}),r(Jt,{sectionIds:[yn],hideSectionChrome:!0,emptyMessage:t(`system.authentication.policyUnavailable`,`Not available — the addon that owns these settings did not answer.`)})]})})}function xn({isPending:t,error:n,what:i,onRetry:a,children:o}){let{t:s}=q();return t?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.queryBody.reading`,{what:i})]}):n===null?o:r(F,{title:s(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:i}),message:n.message.length>0?n.message:s(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:a})}function Sn(){let{t}=q(),n=B.deviceCredentials.getDeviceCaStatus.useQuery({}),i=n.data;return r(J,{id:`device-ca`,title:t(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:d,description:t(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:r(xn,{isPending:n.isPending,error:n.error,what:`the device CA`,onRetry:()=>void n.refetch(),children:i!==void 0&&e(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[e(G,{label:t(`certificates.deviceCaCard.state`,`State`),children:[i.state===`ready`&&r(V,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),i.state===`absent`&&r(V,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),i.state===`unavailable`&&r(V,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),i.state===`ready`&&e(l,{children:[r(G,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:i.subject}),r(G,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:i.fingerprintSha256}),r(G,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:i.validTo})]}),i.state===`unavailable`&&r(G,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:r(`span`,{className:`text-danger`,children:i.reason})})]})})})}s();function Cn(){let{t}=q(),n=B.useUtils(),i=B.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[o,s]=a(null),c=B.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{s(null),n.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>s(`Could not save: ${e.message}`)});return r(xn,{isPending:i.isPending,error:i.error,what:`the enrollment setting`,onRetry:()=>void i.refetch(),children:i.data!==void 0&&e(G,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:r($e,{checked:i.data.selfEnrollment===`allowed`,disabled:c.isPending,"aria-label":t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>c.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:i.data.selfEnrollment===`allowed`?t(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):t(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),o!==null&&r(`span`,{className:`block text-[11px] text-danger`,children:o})]})})}s();function wn(e){let[t,n]=a(()=>Date.now());return i(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}s();var Tn=80,En=208;function Dn({open:t,users:n,onClose:i,onPaired:o}){let{t:s}=q(),c=B.deviceCredentials.startEnrollment.useMutation({onSuccess:o}),[l,u]=a(``),[d,f]=a(``),p=l===``?n[0]?.id??``:l,m=c.data,h=()=>{c.reset(),f(``),i()};return r(he,{open:t,onClose:h,title:s(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:E,width:`md`,testId:`pair-device-dialog`,error:c.isError?c.error.message:null,footer:m===void 0?e(U,{type:`button`,onClick:()=>{let e=d.trim();p===``||e===``||c.mutate({userId:p,deviceName:e})},disabled:c.isPending||p===``||d.trim()===``,children:[c.isPending&&r(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):r(U,{type:`button`,variant:`outline`,onClick:h,children:s(`certificates.pairDeviceDialog.done`,`Done`)}),children:m===void 0?e(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),r(W,{label:s(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:r(ae,{value:p,onChange:e=>u(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})}),r(W,{label:s(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:s(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:r(Ke,{value:d,maxLength:Tn,onChange:e=>f(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):r(On,{enrollUrl:m.enrollUrl,expiresAt:m.expiresAt,hubKnown:m.hubOrigin!==null,onRestart:()=>c.reset()})})}function On({enrollUrl:t,expiresAt:n,hubKnown:i,onRestart:a}){let{t:o}=q(),s=Rt(n,wn(1e3));return r(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:e(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[r(`div`,{className:s.expired?`opacity-30`:void 0,children:r(xe,{value:t,size:En,alt:o(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),e(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),r(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:s.expired?o(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):o(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:s.label})}),e(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[r(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:t}),r(_e,{value:t,srLabel:`Enrollment link`})]}),!i&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[r(w,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:o(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),s.expired&&r(U,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}s();var kn={key:`access.nouns.device`};function An({pairOpen:t,onPairClose:i}){let{t:o}=q(),s=D(),c=re(),l=B.useUtils(),d=B.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),f=tt(),[p,m]=a(null),[h,g]=a(null),_=()=>void l.deviceCredentials.listDeviceCredentials.invalidate(),v=e=>t=>{g(null),m(`${e} failed: ${t.message}`)},y=()=>{g(null),_()},b=B.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:y,onError:v(`Revoke`)}),x=B.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&m(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),y()},onError:v(`Delete`)}),S=B.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:y,onError:v(`Rename`)}),C=St(kn,e=>b.mutateAsync({id:e}),_),w=C.busy||h!==null,T=n(()=>(d.data??[]).map(Lt),[d.data]),ee=async e=>{await s({title:o(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:o(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(m(null),g(e.id),b.mutate({id:e.id}))},O=async e=>{await s({title:o(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:o(`common.delete`,`Delete`),variant:`danger`})&&(m(null),g(e.id),x.mutate({id:e.id}))},k=async e=>{let t=(await c({title:o(`certificates.devicesCard.renameDevice`,`Rename device`),label:o(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:o(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(m(null),g(e.id),S.mutate({id:e.id,deviceName:t}))},te={label:o(`certificates.devicesCard.revoke2`,`Revoke`),icon:oe,isAvailable:Et,onRun:e=>void ee(e),busyId:b.isPending?h:null,disabled:w},ne=[{label:o(`certificates.devicesCard.rename`,`Rename`),icon:ie,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void k(e),busyId:S.isPending?h:null,disabled:w},{label:o(`common.delete`,`Delete`),icon:u,isAvailable:Nt,onRun:e=>void O(e),busyId:x.isPending?h:null,disabled:w}];return e(J,{id:`devices`,title:o(`certificates.devicesCard.devices`,`Devices`),icon:E,description:o(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:Y(p,C.outcome),onDismissNotice:()=>{m(null),C.dismiss()},children:[r(Cn,{}),r(Wt,{rows:T,label:o(`certificates.devicesCard.label`),isLoading:d.isPending,loadError:d.error===null?null:d.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:te,extraActions:ne,bulk:{revoke:C,noun:kn,isSelectable:Et}}),r(Dn,{open:t,users:f.data??[],onClose:i,onPaired:_})]})}var jn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Mn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,Nn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Pn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Mn.exec(t);return e===null?jn.test(t)?K.t(`helpers.pemFile.isCert`):K.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?K.t(`helpers.pemFile.encrypted`):null}return jn.test(t)?e===`certificate`&&Mn.test(t)?K.t(`helpers.pemFile.certHasKey`):null:Mn.test(t)?K.t(`helpers.pemFile.isKey`):K.t(`helpers.pemFile.notCert`)}function Fn(e){return e.text()}s();function In({kind:n,label:i,value:o,onChange:s,rows:c=6}){let{t:l}=q(),u=t(null),[d,f]=a(null),[p,m]=a(null),h=p??Pn(n,o),g=`pem-${n}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await Fn(t);m(null),s(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return e(`div`,{className:`space-y-1`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:i}),e(`div`,{className:`flex min-w-0 items-center gap-2`,children:[d!==null&&r(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:d}),r(et,{ref:u,accept:Nn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(U,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[r(de,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),r(Ve,{id:g,value:o,onChange:e=>{f(null),m(null),s(e.target.value)},rows:c,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&r(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}s();var Ln=30;function Rn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<Ln*864e5}function zn(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Bn(){let{t}=q(),n=c(),i=Qe(void 0,{refetchInterval:15e3}),o=Be({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=ve({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=De({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=ye({onSuccess:()=>{p(!1),h(``),v(``),b(``),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),d=i.data,[f,p]=a(!1),[m,h]=a(``),[_,v]=a(``),[y,b]=a(``),x=()=>{if(!d?.caCertPem)return;let e=new Blob([d.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},S=d?.mode===`uploaded`?`Uploaded`:d?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(L,{headingId:`local-access-certificate`,title:t(`system.localAccess.certificate`,`Certificate`),icon:C,children:e(`div`,{className:`${g} space-y-3`,children:[i.isError&&r(`p`,{className:`text-xs text-danger`,children:t(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),d?.reissueError&&r(F,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:d.reissueError}),d?.restartRequired&&r(F,{variant:`warning`,title:t(`system.localAccess.restartRequired`,`Restart required`),message:t(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),d?.caMissing===!0&&r(F,{variant:`warning`,title:t(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:t(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),d?.caReplacedAt!=null&&Rn(d.caReplacedAt)&&r(F,{variant:`warning`,title:t(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:t(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(d.caReplacedAt).toLocaleString()})}),e(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.mode`,`Mode`)}),r(`dd`,{className:`font-medium`,children:S})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.validTo`,`Valid to`)}),r(`dd`,{className:`font-mono`,children:d?.validTo?new Date(d.validTo).toLocaleString():`—`})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),r(`dd`,{className:`font-mono`,title:d?.leafFingerprintSha256??void 0,children:zn(d?.leafFingerprintSha256??null)})]}),d?.storedUpload!=null&&e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.storedUpload`,`Stored upload`)}),r(`dd`,{className:`font-medium`,children:t(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(d.storedUpload.validTo).toLocaleDateString(),ca:d.storedUpload.hasCa?t(`system.localAccess.storedUploadWithCa`,`with its CA`):t(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.caSha256`,`CA SHA-256`)}),r(`dd`,{className:`font-mono`,title:d?.caFingerprintSha256??void 0,children:d?.mode===`uploaded`&&d.caFingerprintSha256===null?r(`span`,{className:`font-sans text-foreground-subtle`,children:t(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):zn(d?.caFingerprintSha256??null)})]})]}),d&&d.sans.length>0&&r(`div`,{className:`flex flex-wrap gap-1`,children:d.sans.map(e=>r(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),e(`div`,{className:`flex flex-wrap gap-2`,children:[r(Pe,{label:t(`system.localAccess.regenerate`,`Regenerate`),title:t(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:t(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:t(`system.localAccess.regenerate`,`Regenerate`),disabled:d?.mode===`uploaded`||o.isPending,action:()=>o.mutateAsync({})}),r(U,{size:`sm`,variant:`outline`,onClick:()=>p(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),d?.caCertPem&&r(U,{size:`sm`,variant:`outline`,onClick:x,children:t(`system.localAccess.downloadCa`,`Download CA`)}),d?.mode===`uploaded`&&r(Pe,{label:t(`system.localAccess.revertToGenerated`,`Revert to generated`),title:t(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:t(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:t(`system.localAccess.revert`,`Revert`),disabled:s.isPending,action:()=>s.mutateAsync({})}),d?.mode===`generated`&&d.storedUpload!=null&&r(Pe,{label:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:t(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:t(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:l.isPending,action:()=>l.mutateAsync(void 0)})]}),f&&e(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[r(In,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:m,onChange:h}),r(In,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),r(In,{kind:`ca`,label:t(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),r(U,{size:`sm`,disabled:!m.trim()||!_.trim()||Pn(`certificate`,m)!==null||Pn(`privateKey`,_)!==null||Pn(`ca`,y)!==null||u.isPending,onClick:()=>u.mutate({certPem:m,keyPem:_,...y.trim()?{caPem:y}:{}}),children:t(`system.localAccess.saveCertificate`,`Save certificate`)}),u.isError&&r(`p`,{className:`text-xs text-danger`,children:u.error instanceof Error?u.error.message:t(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var Vn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function Hn(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function Un({https:t,mesh:n,now:i}){let{t:a}=q(),o=Qe().data?.caCertPem??``,s=()=>{if(o===``)return;let e=URL.createObjectURL(new Blob([o],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},c=n?.ca,l=c?.state===`ready`?Date.parse(c.validTo):null,u=n?.listener;return e(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[r(G,{label:a(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:e(`span`,{className:`flex flex-wrap items-center gap-2`,children:[Hn(t)??`—`,o!==``&&e(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:[r(O,{className:`h-3 w-3`,"aria-hidden":!0}),a(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),r(G,{label:a(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:c===void 0?`—`:c.state===`ready`?c.fingerprintSha256:r(`span`,{className:`text-danger`,children:a(`certificates.caStrip.unavailable`,{reason:c.reason})})}),c?.state===`ready`&&e(G,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${Vn[Ht(l,i)]}`,children:[`(`,Ot(l,i),`)`]})]}),u!==void 0&&e(G,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&r(V,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&r(V,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:kt(u.since)}),` `,u.reason]})]}),n!==void 0&&!n.registryAvailable&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[r(w,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:a(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function Wn(e,t){let n=new Set;for(let t of e)n.add(t.nodeId);for(let e of t?.nodes??[])n.add(e.nodeId);return[...n].map(n=>{let r=e.find(e=>e.nodeId===n)??null,i=t?.nodes.find(e=>e.nodeId===n)??null;return{nodeId:n,isHub:r?.isHub??n===`hub`,online:r?.online??i?.online??!1,https:r,mesh:i}}).toSorted((e,t)=>Number(t.isHub)-Number(e.isHub)||e.nodeId.localeCompare(t.nodeId))}function Gn(e){return e.isHub?K.t(`helpers.nodesModel.hubReissued`):e.mesh===null?K.t(`helpers.nodesModel.noCertRecorded`):e.online?null:K.t(`helpers.certificateModel.nodeOffline`)}function Kn(e){return e.isHub||e.mesh===null?Gn(e):null}var qn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},Jn={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Yn={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function Xn(e){let t=e.https?.https;return t?.kind===`served`?Bt(t.status.validTo):null}function Zn({ms:t,now:n}){return t===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[r(`div`,{children:kt(t)}),r(`div`,{className:`text-[10px] ${qn[Ht(t,n)]}`,children:Ot(t,n)})]})}function Qn({row:t}){let{t:n}=q(),i=t.https?.https;return i===void 0?r(`span`,{className:`text-foreground-subtle`,children:`—`}):i.kind===`served`?e(`div`,{title:i.status.leafFingerprintSha256??``,children:[r(V,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),r(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Yn[i.status.mode]}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:zt(i.status.leafFingerprintSha256)}),i.status.sans.length>0&&r(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:i.status.sans.join(`, `),children:i.status.sans.join(`, `)})]}):e(`div`,{className:`max-w-[16rem]`,children:[r(V,{variant:i.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:i.kind===`unreadable`?n(`certificates.nodesColumns.unreadable`,`Unreadable`):n(`certificates.nodesColumns.notServed`,`Not served`)}),r(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:i.reason})]})}function $n({row:t}){let{t:n}=q(),i=t.mesh?.current??null;if(i===null)return r(`span`,{className:`text-foreground-subtle`,children:n(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let a=t.mesh?.history.length??0;return e(`div`,{children:[r(`div`,{className:`font-mono text-[11px]`,title:i.serial,children:It(i.serial)}),r(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:i.fingerprintSha256,children:zt(i.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[Jn[i.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function er({row:e}){let{t}=q(),n=e.mesh?.presentingCurrent??null;return n===null?r(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?r(V,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):r(V,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function tr(t){let n=t.icon;return e(U,{type:`button`,variant:`ghost`,size:`sm`,className:t.danger?`text-danger hover:bg-danger/10`:void 0,disabled:t.reason!==null||t.busy,title:t.reason??void 0,"aria-label":t.ariaLabel,onClick:t.onClick,children:[t.spinning?r(S,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):r(n,{className:`h-3 w-3`,"aria-hidden":!0}),t.label]})}function nr({reasons:t}){let{t:n}=q();return e(He,{className:`inline-block`,children:[r(qe,{children:r(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:n(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),r(Ue,{children:r(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:t.map(e=>r(`li`,{children:e},e))})})]})}function rr({row:t,o:n}){let{t:i}=q(),a=t.https===null?`No HTTPS inventory for this node.`:At(t.https).reason,o=Gn(t),s=Kn(t),c=e=>n.running?.nodeId===t.nodeId&&n.running.action===e,l=e=>!t.isHub||e===null,u=[a,o,s].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return e(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[e(`div`,{className:`flex flex-col items-end gap-0.5`,children:[l(a)&&r(tr,{label:i(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:i(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:t.nodeId}),icon:y,reason:a,busy:n.busy,spinning:c(`renew-https`),danger:!1,onClick:()=>n.onRenewHttps(t)}),l(o)&&r(tr,{label:c(`renew-identity`)?i(`certificates.nodesColumns.renewing`,`Renewing…`):i(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:i(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:y,reason:o,busy:n.busy,spinning:c(`renew-identity`),danger:!1,onClick:()=>n.onRenewIdentity(t)}),l(s)&&r(tr,{label:i(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:i(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:oe,reason:s,busy:n.busy,spinning:c(`revoke-identity`),danger:!0,onClick:()=>n.onRevokeIdentity(t)})]}),t.isHub&&u.length>0&&r(nr,{reasons:u}),!t.isHub&&a!==null&&t.https!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${t.nodeId}`,children:a}),!t.isHub&&o!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${t.nodeId}`,children:o})]})}function ir(t){return[{key:`node`,header:K.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.nodeId}),t.nodeId===`hub`&&r(V,{variant:`info`,className:`text-[10px]`,children:K.t(`common.hubWord`)}),!t.online&&r(V,{variant:`default`,className:`text-[10px]`,children:K.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>r(Qn,{row:e})},{key:`https-expires`,header:K.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>Xn(e),render:e=>r(Zn,{ms:Xn(e),now:t.now})},{key:`identity`,header:K.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>r($n,{row:e})},{key:`identity-expires`,header:K.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>r(Zn,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:K.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>r(er,{row:e})},{key:`actions`,header:K.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>r(rr,{row:e,o:t})}]}s();function ar(){let{t}=q(),i=D(),o=B.useUtils(),s=wn(6e4),c=B.certificates.listHttpsCertificates.useQuery(),l=B.certificates.getMeshCertificates.useQuery(),[u,d]=a(null),[f,p]=a(null),[m,h]=a(null),g=()=>{h(null),o.certificates.listHttpsCertificates.invalidate(),o.certificates.getMeshCertificates.invalidate()},v=e=>(t,n)=>{h(null),d(`${n.nodeId}: ${e} - ${t.message}`)},y=B.certificates.renewHttpsOnNode.useMutation({onSuccess:(e,n)=>{p({tone:`success`,message:e.restartRequired?t(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):t(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),g()},onError:v(`renewal failed`)}),b=B.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(Ft(e)),g()},onError:v(`renewal could not start`)}),x=B.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:v(`revoke failed`)}),S=y.isPending||b.isPending||x.isPending,C=(e,t)=>{d(null),p(null),h({nodeId:e,action:t})},w=async e=>{await i({title:t(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:e.nodeId}),message:e.isHub?t(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):t(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:t(`certificates.nodesCard.renew`,`Renew`)})&&(C(e.nodeId,`renew-https`),y.mutate({nodeId:e.nodeId}))},T=e=>{C(e.nodeId,`renew-identity`),b.mutate({nodeId:e.nodeId})},E=async e=>{await i({title:t(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:e.nodeId}),message:t(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:e.nodeId}),confirmLabel:t(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(C(e.nodeId,`revoke-identity`),x.mutate({nodeId:e.nodeId}))},ee=ir({now:s,busy:S,running:m,onRenewHttps:e=>void w(e),onRenewIdentity:T,onRevokeIdentity:e=>void E(e)}),O=n(()=>Wn(c.data??[],l.data),[c.data,l.data]),k=l.data?.registryAvailable??!0;return r(J,{id:`nodes`,title:t(`certificates.nodesCard.nodes`,`Nodes`),icon:_,description:t(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:Y(u,f),onDismissNotice:()=>{d(null),p(null)},children:r(xn,{isPending:c.isPending||l.isPending,error:c.error??l.error,what:`node certificates`,onRetry:()=>{c.refetch(),l.refetch()},children:e(`div`,{className:`space-y-3`,children:[r(Un,{https:c.data??[],mesh:l.data,now:s}),r(we,{columns:ee,rows:O,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Re,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:k?t(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):t(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function or({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[r(An,{pairOpen:t,onPairClose:n}),r(Sn,{}),r(Bn,{}),r(ar,{})]})}function sr({userId:t,username:n,onClose:i}){let{t:a}=q(),o=D(),s=B.useUtils(),c=R({userId:t}),l=B.auth.listLoginMethods.useQuery(),u=Me({onSuccess:()=>void s.userManagement.listExternalIdentities.invalidate()}),d=new Map((l.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=c.data??[],p=async(e,r)=>{await o({title:a(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:a(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:n,label:r}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&u.mutate({userId:t,provider:e.provider,subject:e.subject})};return r(Ye,{open:!0,onOpenChange:e=>!e&&i(),children:e(H,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[r(z,{children:e(P,{className:`flex items-center gap-2`,children:[r(v,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.externalIdentitiesModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),r(I,{className:`space-y-3`,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),a(`common.loading`,`Loading…`)]}):f.length===0?r(`p`,{className:`text-xs text-foreground-subtle`,children:a(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(t=>{let n=d.get(t.provider),i=n??t.provider;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[e(`div`,{className:`flex-1 min-w-0`,children:[e(`div`,{className:`font-medium text-foreground truncate`,children:[i,n===void 0&&r(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:a(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),e(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[t.label??t.subject,` ·`,` `,new Date(t.linkedAt).toLocaleDateString()]})]}),e(U,{variant:`unstyled`,onClick:()=>void p(t,i),disabled:u.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:[r(me,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),r(ze,{children:r(U,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function cr({userId:t,username:n,onClose:i}){let{t:a}=q(),o=c(),s=D(),u=Ce({userId:t}),d=u.data,m=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),g=be({onSuccess:()=>{m(),i()}}),_=u.isLoading?`loading`:d?.enabled?`enrolled`:`not_enrolled`;return r(Ye,{open:!0,onOpenChange:e=>!e&&i(),children:e(H,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(z,{children:e(P,{className:`flex items-center gap-2`,children:[r(E,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.totpModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(I,{className:`space-y-4`,children:[_===`loading`&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),a(`users.totpModal.checkingStatus`,`Checking status…`)]}),_===`not_enrolled`&&e(`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:[r(p,{className:`h-4 w-4 mt-0.5 shrink-0`}),e(`div`,{children:[r(`div`,{className:`font-medium text-foreground`,children:a(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),r(`p`,{className:`mt-0.5`,children:a(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),_===`enrolled`&&d&&e(l,{children:[e(`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:[r(f,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),e(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[r(`div`,{className:`font-medium`,children:a(`users.totpModal.2faIsActive`,`2FA is active`)}),r(`div`,{className:`text-foreground-subtle`,children:a(`common.enrolledOn`,{when:d.confirmedAt?new Date(d.confirmedAt).toLocaleString():`—`})})]})]}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(`users.totpModal.removingHereClearsTheServer`,`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.`)}),e(`div`,{className:`flex justify-end gap-2`,children:[r(U,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)}),e(U,{variant:`unstyled`,onClick:async()=>{await s({title:a(`users.totpModal.remove2fa`,`Remove 2FA`),message:a(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:n}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&g.mutate({userId:t})},disabled:g.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:[g.isPending?r(S,{className:`h-3 w-3 animate-spin`}):r(h,{className:`h-3 w-3`}),a(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}s();function lr({userId:t,username:n,onClose:i}){let{t:o}=q(),{user:s,logout:c}=nt(),l=s?.id===t,u=D(),d=B.useUtils(),f=B.auth.listSessions.useQuery({userId:t}),[p,m]=a(null),h=B.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(l&&`userId`in t){c();return}d.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await u({title:o(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:o(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:n,label:Tt(e.client).label}),confirmLabel:o(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await u({title:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:l?o(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):o(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:n}),confirmLabel:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:t}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return r(Ye,{open:!0,onOpenChange:e=>!e&&i(),children:e(H,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[r(z,{children:e(P,{className:`flex items-center gap-2`,children:[r(pe,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[o(`users.userSessionsModal.activeSessions`,`Active sessions`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[o(`users.userSessionsModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(I,{className:`space-y-3`,children:[p!==null&&r(`div`,{className:`text-[11px] text-danger`,children:p}),r(Vt,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void g(e),revokingId:v})]}),e(ze,{className:`justify-between`,children:[e(U,{variant:`unstyled`,onClick:()=>void _(),disabled:h.isPending||(f.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:[h.isPending&&v===null?r(S,{className:`h-3 w-3 animate-spin`}):r(ue,{className:`h-3 w-3`}),o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),r(U,{onClick:i,variant:`secondary`,children:o(`common.close`,`Close`)})]})]})})}function ur({scopes:t,invalidReason:n}){let{t:i}=q(),a=T(),s=o({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=Fe({projection:`slim`}),l=c?.length??null;if(n!==null)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,"data-testid":`role-preview`,children:[r(k,{className:`h-3 w-3 shrink-0`}),n]});if(s.isLoading)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,"data-testid":`role-preview`,children:[r(S,{className:`h-3 w-3 shrink-0 animate-spin`}),i(`users.rolePreview.resolving`)]});if(s.isError||!s.data)return r(`p`,{className:`text-[11px] text-danger`,"data-testid":`role-preview`,children:i(`users.rolePreview.couldNotResolve`)});let u=s.data.viewableDeviceCount,d=s.data.device.view.all?i(`users.rolePreview.everyDevice`,{count:u}):l===null?i(`users.rolePreview.devicesVisible`,{count:u}):i(`users.rolePreview.devicesVisibleOf`,{count:u,total:l});return e(`p`,{className:`flex items-center gap-1.5 text-[11px] ${u===0?`text-warning`:`text-foreground`}`,"data-testid":`role-preview`,children:[u===0?r(k,{className:`h-3 w-3 shrink-0`}):r(ne,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u===0?i(`users.rolePreview.noDevice`):d]})}function dr(e){let t=se(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:ce,unconfigured:!e.isAdmin};let n=vr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:yr(n.mode,n.pickedIds,t.features),unconfigured:!1}}function fr(e,t){return{...e,role:t}}function pr(e,t){return{...e,mode:t,viewer:yr(t,e.pickedIds,e.viewer.features)}}function mr(e,t){let n=br(t);return{...e,pickedIds:n,viewer:yr(e.mode,n,e.viewer.features)}}function hr(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:yr(e.mode,e.pickedIds,i)}}function gr(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function _r(e){return gr(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function vr(e){if(e.allow===`*`)return{mode:`except`,pickedIds:e.block};let t=new Set(e.block);return{mode:`only`,pickedIds:e.allow.filter(e=>!t.has(e))}}function yr(e,t,n){let r=br(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function br(e){return[...new Set(e)]}s();var xr=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function Sr(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function Cr(e){let t=[];for(let n of e)n.parentDeviceId===null&&t.push({id:n.id,name:n.name,type:String(n.type),...n.location===null?{}:{location:n.location}});return t}function wr({user:t,isSelf:i,onClose:o,onSubmit:s,submitting:c,error:u}){let{t:d}=q(),[f,p]=a(n(()=>dr(t),[t])),m=Fe({projection:`slim`}),h=m.data,g=Sr(m.isError,h),_=n(()=>Cr(h??[]),[h]),v=n(()=>({state:g,devices:g===`answered`?(h??[]).map(e=>({id:e.id,name:e.name})):void 0}),[g,h]),y=gr(f),x=_r(f),C=y===`no-allowed-device`?d(`users.userAccessModal.pickAllowedDevice`):null,w=e=>{p(fr(f,e))},T=[{value:`except`,label:d(`users.userAccessModal.modeExcept`)},{value:`only`,label:d(`users.userAccessModal.modeOnly`)}];return r(Ye,{open:!0,onOpenChange:e=>!e&&o(),children:e(H,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(z,{children:r(P,{children:d(`users.userAccessModal.title`,{name:t.username})})}),e(I,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&r(F,{variant:`warning`,title:d(`users.userAccessModal.noAccessYet`),message:d(`users.userAccessModal.noAccessYetDetail`,{name:t.username})}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:xr,children:d(`users.userAccessModal.role`)}),e(`div`,{role:`radiogroup`,"aria-label":d(`users.userAccessModal.role`),className:`grid gap-1.5 sm:grid-cols-2`,children:[r(Tr,{name:`admin`,checked:f.role===`admin`,label:d(`users.userAccessModal.admin`),description:d(`users.userAccessModal.adminDescription`),onPick:()=>w(`admin`)}),r(Tr,{name:`viewer`,checked:f.role===`viewer`,disabled:i,label:d(`users.userAccessModal.viewer`),description:d(i?`users.userAccessModal.cannotDemoteSelf`:`users.userAccessModal.viewerDescription`),onPick:()=>w(`viewer`)})]})]}),f.role===`viewer`&&e(l,{children:[e(`section`,{className:`space-y-3`,children:[r(`h3`,{className:xr,children:d(`users.userAccessModal.devices`)}),r(je,{label:d(`users.userAccessModal.whichDevices`),value:f.mode,options:T,onChange:e=>p(pr(f,e))}),r(Ee,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(mr(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),r(ur,{scopes:x?.scopes??[],invalidReason:C})]}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:xr,children:d(`users.userAccessModal.features`)}),r(`div`,{className:`space-y-1`,children:A.map(t=>e(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[r(b,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>p(hr(f,t.id,e.target.checked))}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:d(`users.viewerFeatures.${t.id}.label`,t.label)}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:d(`users.viewerFeatures.${t.id}.description`,t.description)})]})]},t.id))})]})]}),u!==null&&r(F,{message:u})]}),e(ze,{children:[r(U,{variant:`outline`,size:`sm`,onClick:o,children:d(`common.cancel`,`Cancel`)}),r(U,{size:`sm`,onClick:()=>x!==null&&s(x),disabled:c||x===null,children:c?r(S,{className:`h-3 w-3 animate-spin`}):d(`users.userAccessModal.saveAccess`)})]})]})})}function Tr({name:t,checked:n,disabled:i=!1,label:a,description:o,onPick:s}){return e(`label`,{className:`flex items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-surface-hover`} ${i?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[r(Le,{name:`user-role`,value:t,checked:n,disabled:i,onChange:s,className:`mt-0.5`}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:a}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:o})]})]})}s();var Er=8;function Dr(){return{username:``,password:``,isAdmin:!1}}function Or(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function kr(e){return e instanceof Error?e.message:K.t(`admin.system.users.genericError`)}function Ar(){let{t}=q(),n=c(),{user:o}=nt(),{state:s,openNew:f,openEdit:p,close:h}=ke(),[g,_]=a(null),[y,x]=a(null),[C,w]=a(!1),{data:T,isLoading:O,isError:k,error:te,refetch:ne}=tt(),ae=D(),oe=re(),A=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),se=Te(),ce=Oe({onSuccess:A}),j=Ie({onSuccess:A}),le=ge({onSuccess:A}),ue=Se(),[M,N]=a(null),[de,me]=a(!1),[P,_e]=a(null),[ve,ye]=a(null),[be,xe]=a(null),[Ce,I]=a(null),L=T??[],R=s.mode===`edit`?L.find(e=>e.id===s.id)??null:null,Ee=()=>{_(null),x(null),w(!1),se.reset(),j.reset(),h()};i(()=>{if(s.mode===`closed`){_(null),x(null),w(!1);return}if(s.mode===`new`){_(e=>e!==null&&e.id===void 0?e:Dr());return}if(R===null){O||h();return}_(e=>e?.id===R.id?e:Or(R))},[s,R,O,h]);let De=s.mode===`new`&&g!==null&&g.id===void 0||s.mode===`edit`&&g!==null&&R!==null;async function z(e){await ae({title:t(`admin.system.users.deleteUser`,`Delete user`),message:t(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:e.username}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&(ce.mutate({id:e.id}),s.mode===`edit`&&s.id===e.id&&Ee())}async function Ae(e){let n=await oe({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:e.username}),label:t(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:t(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:t(`admin.system.users.continue`,`Continue`),validate:e=>e.length<Er?K.t(`admin.system.users.passwordTooShort`,{min:Er}):null});n===null||n.length===0||await ae({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:e.username}),confirmLabel:t(`common.reset`,`Reset`)})&&le.mutate({id:e.id,newPassword:n})}function je(e){_e(null),N(e)}async function Me(e,t){me(!0),_e(null);try{t.isAdmin!==e.isAdmin&&await j.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await ue.mutateAsync({userId:e.id,scopes:[...t.scopes]}),N(null)}catch(e){_e(kr(e))}finally{me(!1),A()}}async function Ne(){if(g!==null){x(null);try{if(g.id===void 0){let e=g.username.trim();if(e===``||g.password.length<Er)return;await se.mutateAsync({username:e,password:g.password,isAdmin:g.isAdmin})}else await j.mutateAsync({id:g.id,isAdmin:g.isAdmin});A(),Ee()}catch(e){x(kr(e))}}}function Pe(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let Fe=se.isPending||j.isPending,B=g!==null&&g.id===void 0&&g.username.trim()!==``&&g.password.length>=Er,V=g!==null&&g.id!==void 0,Le=Fe||(g?.id===void 0?!B:!V),Re=e=>ce.isPending&&ce.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||le.isPending&&le.variables?.id===e.id,H=[{key:`username`,header:t(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>r(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`scopes`,header:t(`admin.system.users.access`,`Access`),sortValue:e=>jr(e),render:n=>r(`span`,{onClick:e=>e.stopPropagation(),children:e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>je(n),disabled:Re(n),title:t(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${n.id}`,children:[r(d,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),r(Mr,{user:n})]})})},{key:`createdAt`,header:t(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>r(`span`,{className:`text-foreground-subtle`,children:Pe(e.createdAt)})},{key:`actions`,header:t(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:n=>{let i=Re(n),a=n.id!==o?.id&&n.totpEnabled;return e(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>p(n.id),disabled:i,title:t(`admin.system.users.editUser`,`Edit user`),children:[r(ie,{className:`h-3 w-3`}),t(`common.edit`,`Edit`)]}),a&&e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ye(n),disabled:i,title:t(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[r(E,{className:`h-3 w-3`}),t(`admin.system.users.remove2fa`,`Remove 2FA`)]}),e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>xe(n),disabled:i,title:t(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[r(v,{className:`h-3 w-3`}),t(`admin.system.users.signInLinks`,`Sign-in links`)]}),e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>I(n),disabled:i,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[r(pe,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void Ae(n),disabled:i,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[r(fe,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void z(n),disabled:i,title:t(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[i?r(S,{className:`h-3 w-3 animate-spin`}):r(u,{className:`h-3 w-3`}),t(`common.delete`,`Delete`)]})]})}}];return e(yt,{embedded:!0,icon:m,title:t(`admin.system.users.users`,`Users`),subtitle:t(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:e(U,{size:`sm`,type:`button`,onClick:()=>{x(null),f()},children:[r(ee,{className:`h-3.5 w-3.5`}),t(`admin.system.users.createUser`,`Create User`)]}),children:[k&&r(F,{title:t(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:kr(te),onRetry:()=>void ne()}),O&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}),!O&&!k&&L.length===0&&r(Ge,{icon:m,title:t(`admin.system.users.noUsersYet`,`No users yet`),description:t(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!O&&!k&&L.length>0&&r(we,{columns:H,rows:L,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>p(e.id)}),r(he,{open:De,onClose:Ee,title:g?.id===void 0?t(`admin.system.users.createUser`,`Create User`):t(`admin.system.users.edit`,`Edit {{value1}}`,{value1:g.username||`user`}),icon:m,error:y,testId:`user-form-dialog`,footer:r(U,{size:`sm`,type:`button`,disabled:Le,onClick:()=>void Ne(),children:Fe?e(l,{children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`admin.system.users.saving`,`Saving…`)]}):g?.id===void 0?t(`admin.system.users.create`,`Create`):t(`common.save`,`Save`)}),children:g!==null&&e(`div`,{className:`space-y-3`,children:[r(W,{label:t(`admin.system.users.username`,`Username`),required:g.id===void 0,children:r(Ke,{value:g.username,onChange:e=>_({...g,username:e.target.value}),placeholder:`john`,autoFocus:g.id===void 0,disabled:g.id!==void 0,"data-testid":`user-form-username`})}),g.id===void 0&&r(W,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(Er)}),children:r(Xe,{value:g.password,onValueChange:e=>_({...g,password:e}),shown:C,onToggleShown:()=>w(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),r(W,{label:t(`admin.system.users.admin`,`Admin`),description:t(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:e(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[r(b,{checked:g.isAdmin,onChange:e=>_({...g,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),r(`span`,{children:t(`admin.system.users.admin`,`Admin`)})]})}),g.id!==void 0&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),ve&&r(cr,{userId:ve.id,username:ve.username,onClose:()=>ye(null)}),be&&r(sr,{userId:be.id,username:be.username,onClose:()=>xe(null)}),Ce&&r(lr,{userId:Ce.id,username:Ce.username,onClose:()=>I(null)}),M&&r(wr,{user:M,isSelf:M.id===o?.id,onClose:()=>N(null),onSubmit:e=>void Me(M,e),submitting:de,error:P})]})}function jr(e){let t=dr(e);return t.role===`admin`?0:t.unconfigured?2:1}function Mr({user:t}){let{t:n}=q(),i=dr(t);if(i.role===`admin`)return r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.admin`)});if(i.unconfigured)return r(`span`,{className:`font-medium text-warning`,children:n(`admin.system.users.noAccess`,`No access`)});let{allow:a,block:o,features:s}=i.viewer,c=a===`*`?n(`users.accessSummary.allDevices`):n(`users.accessSummary.devices`,{count:a.length});return e(`span`,{className:`text-foreground-subtle`,children:[r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.viewer`)}),` ·`,` `,c,o.length>0&&e(l,{children:[` · `,n(`users.accessSummary.blocked`,{count:o.length})]}),s.length>0&&e(l,{children:[` · `,n(`users.accessSummary.features`,{count:s.length})]})]})}s();var Nr={"api-keys":$.tokens,"linked-sessions":$.linkedApps},Pr=`certificates`;function Fr(t){return e(U,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[r(E,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),K.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Ir(){let{t:e}=q(),[t]=ot(),n=_n(),[i,o]=a(!1),s=Nr[t.get(`tab`)??``];if(s!==void 0)return r(rt,{to:lt(`access`,{integration:s}),replace:!0});let c=_t(`/system/identity`,{t:e,isAdmin:!0})??{icon:te,title:e(`system.identity`,`Identity & Access`)},l=t.get(`tab`)??`users`,u=t.get(`integration`),d=l===ct.access.tab?gn(u,n.requestCreate):l===`certificates`?Fr(()=>o(!0)):void 0;return r(vt,{icon:c.icon,title:c.title,defaultSection:`users`,sectionsLabel:`${c.title} sections`,actions:d,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:r(Ar,{})},{id:ct.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:ut.concat([jt.token,jt.scoped,jt.admin]),content:r(hn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Pr,label:e(`systemPage.identity.certificates`,`Certificates`),content:r(or,{pairOpen:i,onPairClose:()=>o(!1)})},{id:ct.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:r(vn,{}),ownedParams:ut}]})}export{Ir as IdentityPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,k as c,o 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-CEyXHAdg.js";import{$t as f,Fr as ee,Gn as p,Ln as m,Mr as h,O as te,V as ne,_t as re,ct as ie,er as ae,fa as g,or as oe,tr as se}from"./player-overlays-DuG5kk5Q.js";import{Tr as _}from"./client-pLjIfKNS.js";import{t as ce}from"./link-2-off-DmsjRAt7.js";import{$r as v,Dn as y,En as b,Jd as le,Jn as ue,Jr as de,Kn as fe,Pi as pe,Q as me,Qr as x,Us as S,Vn as C,Xd as w,Yr as T,ga as E,hf as D,li as he,nt as ge,of as O,qr as k,ua as A,vr as j}from"./src-DOkmPL4F.js";import{t as M}from"./useTranslation-BJr-n0es.js";import{$ as _e,Br as ve,G as N,Vr as ye,X as P,Y as F,Z as be,at as I,ct as xe,et as Se,it as Ce,lt as we,ot as L,qr as R,r as z,rt as Te,st as Ee,tt as B,ut as De}from"./index-BV01fYDf.js";import{t as Oe}from"./IntegrationWizard-5b0NkY3q.js";import{t as ke}from"./NodeAddonsSettingsPanel-Dw5WZxWi.js";s();function Ae({addonId:t,label:n}){return e(`span`,{className:`inline-flex items-center gap-1.5 text-foreground-muted`,children:[i(V,{addonId:t}),n]})}function V({addonId:e}){let t=N(e),[n,r]=o(!1);return!t||n?null:i(`img`,{src:t,alt:``,className:`h-4 w-4 shrink-0 rounded`,onError:()=>r(!0)})}var je=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],H=`text-[10px]`;function U(){let e=l();return A({onSuccess:()=>{for(let t of je)e.invalidateQueries({queryKey:t})}})}function W({addonId:e,displayName:t,message:n}){let{t:r}=M(),a=ie(),o=U();return i(D,{icon:o.isPending?h:p,variant:`ghost`,size:`sm`,"aria-label":r(`integrationHub.addonControls.restartNamed`,`Restart {{name}}`,{name:t}),disabled:o.isPending,onClick:()=>void a({title:r(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),message:n,confirmLabel:r(`integrationHub.addonControls.restart`,`Restart`),variant:`danger`}).then(t=>t?o.mutateAsync({addonId:e}):void 0)})}function Me({addonId:e,displayName:t,iconOnly:n=!1,description:r}){let{t:a}=M(),o=U(),s=r??a(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`);return n?i(W,{addonId:e,displayName:t,message:s}):i(C,{label:a(`integrationHub.addonControls.restart`,`Restart`),icon:p,size:`sm`,title:a(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),description:s,confirmLabel:a(`integrationHub.addonControls.restart`,`Restart`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:o.isPending,action:()=>o.mutateAsync({addonId:e})})}s();var Ne=600,G=c(null);function K({id:n,title:r,icon:a,actions:o,framed:s=!1,children:c}){let{t:l}=M(),f=d(G),p=t(null),m=`integration-section-${n}`;q(p,f,n);let h=e(u,{children:[f===null?null:i(R,{to:f.sectionHref(n),"aria-label":l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),title:l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title: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:i(ee,{className:`h-3 w-3`,"aria-hidden":!0})}),o]});return s?i(`div`,{ref:p,className:`scroll-mt-4`,children:i(fe,{headingId:m,title:r,icon:a,actions:h,children:c})}):e(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[e(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[a!==void 0&&i(a,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),i(`h2`,{id:m,className:`${ne} min-w-0 flex-1`,children:r}),h]}),c]})}function q(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;a(()=>{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()},Ne);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}s();var J=`max-h-72`,Y=[{kind:`logs`,labelKey:`common.logs`,icon:m},{kind:`events`,labelKey:`common.events`,icon:g}];function Pe({addonId:t,switcher:n}){let{t:r}=M(),[a,s]=o(`logs`);return e(K,{id:z,title:r(`integrationHub.addonIntegrationBody.activity`,`Activity`),framed:!0,actions:i(`div`,{className:`flex flex-wrap items-center gap-2`,children:i(`div`,{role:`group`,"aria-label":r(`integrationHub.addonIntegrationBody.activityStream`,`Activity stream`),className:`flex items-center gap-1`,children:Y.map(({kind:t,labelKey:n,icon:o})=>e(O,{variant:`unstyled`,type:`button`,"aria-pressed":a===t,onClick:()=>s(t),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${a===t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[i(o,{className:`h-3 w-3`,"aria-hidden":!0}),r(n)]},t))})}),children:[n!==void 0&&i(`div`,{className:`px-3 pt-2`,children:n}),a===`logs`?i(y,{addonId:t,maxHeight:J,showFilters:!1}):i(b,{addonId:t,category:`addon.*`,maxHeight:J})]})}function X({addonId:t,title:n=`Settings`,subtitle:r,fieldScope:a,onClose:o}){return i(k,{open:!0,onOpenChange:e=>!e&&o(),children:e(T,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-3xl`,children:[e(x,{children:[i(v,{children:n}),r&&i(`p`,{className:`text-xs text-foreground-subtle`,children:r})]}),i(de,{children:i(ke,{nodeId:null,addonIds:[t],level:`global`,...a===void 0?{}:{fieldScope:a}})})]})})}function Z({addonId:e,title:t,onClose:n}){return i(X,{addonId:e,title:t,fieldScope:`cluster`,onClose:n})}s();var Q={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function $({addonId:e,fallback:t,tileClassName:n,size:r=`md`}){let[a,s]=o(!1),c=N(e),l=Q[r];return i(`div`,{className:`${l.tile} flex items-center justify-center shrink-0 ${n}`,children:a||!c?i(t,{className:l.fallback,"aria-hidden":!0}):i(`img`,{src:c,alt:``,className:`${l.img} bg-white ring-1 ring-black/5`,onError:()=>s(!0)})})}var Fe={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function Ie(e,t){switch(t){case`ok`:return e(`instances.health.ok`,`Healthy`);case`error`:return e(`instances.health.error`,`Error`);case`off`:return e(`instances.health.off`,`Off`);case`unknown`:return e(`instances.health.unknown`,`Unknown`)}}function Le({pills:t,selected:n,onSelect:r,fallbackIcon:a,install:o}){let{t:s}=M(),c=t.length>1;return!c&&o===void 0?null:i(`div`,{className:`px-3 pt-2`,children:e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c&&i(`div`,{role:`group`,"aria-label":s(`instances.filterByProvider`,`Filter by provider`),className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:t.map(t=>e(O,{variant:`unstyled`,type:`button`,"aria-pressed":n===t.addonId,"data-testid":`instance-pill-${t.addonId}`,onClick:()=>r(n===t.addonId?null:t.addonId),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 ${n===t.addonId?`border-primary bg-primary/10 text-primary font-medium`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[i($,{addonId:t.addonId,fallback:a,tileClassName:``,size:`sm`}),i(`span`,{className:`truncate`,children:t.name}),i(`span`,{className:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:t.count}),i(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Fe[t.health]}`,"aria-hidden":!0}),i(`span`,{className:`sr-only`,children:Ie(s,t.health)})]},t.addonId))}),o!==void 0&&e(R,{to:_(o.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:[i(ae,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),i(`span`,{className:`truncate`,children:o.label})]})]})})}function Re(e){let t=S({onSuccess:e.onSuccess,onError:t=>e.onError?.(t.message)});return{mutate:e=>t.mutate({...e}),isPending:t.isPending}}s();function ze({row:t,pinning:n,onChanged:r}){let{t:a}=M(),s=l(),[c,u]=o(null),d=Re({onSuccess:()=>{u(null),s.invalidateQueries({queryKey:[P]}),r?.()},onError:u}),f=t.notRunning===void 0?null:a(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:t.providerName});return e(`span`,{className:`flex flex-col items-end gap-1`,title:f??void 0,children:[i(j,{checked:t.enabled,disabled:d.isPending||f!==null,"aria-label":a(`providerInstances.enable`,`Enable {{name}}`,{name:t.name}),"data-testid":`instance-switch-${t.id}`,onCheckedChange:e=>{u(null),d.mutate({addonId:t.addonId,id:t.id,enabled:e})}}),f!==null&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:f}),n>0&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`providerInstances.pinnedBy`,{count:n})}),c!==null&&i(`span`,{className:`text-[11px] text-danger`,role:`alert`,children:a(`providerInstances.switchFailed`,`Could not change {{name}}: {{message}}`,{name:t.name,message:c})})]})}s();var Be=`instance`;function Ve(e){let t=[e.status?.detail,e.lastCheckedAt===void 0?void 0:new Date(e.lastCheckedAt).toLocaleString()].filter(e=>e!==void 0&&e.length>0);return t.length>0?t.join(` · `):void 0}function He({row:t}){let{t:n}=M();return t.enabled?e(`span`,{className:`flex flex-wrap items-center gap-1`,children:[i(w,{variant:t.configured?`success`:`default`,children:t.configured?n(`providerInstances.configured`,`Configured`):n(`providerInstances.notConfigured`,`Not configured`)}),t.status!==void 0&&i(w,{variant:t.status.state===`error`?`danger`:t.status.state===`ok`?`success`:`default`,title:Ve(t),children:L(t.status)})]}):i(`span`,{className:`flex flex-wrap items-center gap-1`,children:i(w,{variant:`default`,children:n(`providerInstances.off`,`Off`)})})}function Ue({row:e,functionCap:t}){let{t:n}=M(),r=l(),a=E({onSuccess:()=>void r.invalidateQueries()});return i(j,{checked:e.isActive,disabled:a.isPending,"aria-label":n(`providerInstances.enable`,`Enable {{name}}`,{name:e.providerName}),onCheckedChange:n=>a.mutate({capName:t,addonId:e.addonId,enabled:n})})}function We({functionCap:t,icon:a,title:s,subtitle:c,emptyTitle:d,emptyDescription:p,addLabel:m,install:ne,extraColumns:g,lead:_,rowActions:v,fixedRowActions:y,canDelete:b,pageActions:de,typedId:x,rowFilter:S}){let{t:C}=M(),T=re(),E=l(),k=ie(),A=be(t),j=me({editKey:Be,newKey:`${Be}-new`}),[N,F]=o(null),[I,L]=o(null),R=pe({functionCap:`notification-output`}),z=r(e=>Ee(R.data??[],e).length,[R.data]),[Te,ke]=o(null),[V,je]=o(null),H=n(()=>_e(A.holders),[A.holders]),U=n(()=>Ce(A.functionProviders,A.rows,A.displayNames),[A.functionProviders,A.rows,A.displayNames]),W=U.some(e=>e.addonId===V)?V:null,Ne=n(()=>{let e=Se(A.rows,W);return S===void 0?e:e.filter(S)},[A.rows,W,S]),G=r(e=>A.displayNames.get(e)??e,[A.displayNames]),K=r(async e=>{F(e.key),L(null);try{let t=await T.trpcClient.integrationInstances.testInstance.mutate({addonId:e.addonId,id:e.id,values:{}});L({name:e.name,verdict:De(t)})}catch(t){let n=t instanceof Error?t.message:String(t);L({name:e.name,verdict:{status:`inconclusive`,error:n}})}finally{F(null)}},[T]),q=r(async e=>{let t=Ee(R.data??[],e.id),n=t.length>0?` ${C(`providerInstances.deletePinned`,`These notification targets use it and will stop delivering: {{names}}.`,{names:t.join(`, `)})}`:``;if(await k({title:C(`providerInstances.deleteTitle`,`Delete {{name}}?`,{name:e.name}),message:`${C(`providerInstances.deleteMessage`,`The record and its stored credentials are removed.`)}${n}`,confirmLabel:C(`common.delete`,`Delete`),variant:`danger`}))try{await T.trpcClient.integrationInstances.deleteInstance.mutate({addonId:e.addonId,id:e.id}),await E.invalidateQueries({queryKey:[P]})}catch(t){xe({title:C(`providerInstances.deleteFailed`,`Could not delete`),message:`${e.name}: ${t instanceof Error?t.message:String(t)}`,severity:`critical`})}},[k,E,T,C,R.data]),J=n(()=>A.rows.some(e=>e.kind===`instance`&&e.kindLabel!==void 0),[A.rows]),Y=r((e,t)=>{e!==void 0&&ye(ve(e,t),()=>{E.invalidateQueries({queryKey:[P]})})},[E]),Pe=n(()=>[{key:`name`,nowrap:!1,header:C(`providerInstances.colName`,`Name`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex flex-col`,children:[i(`span`,{className:`font-medium ${t.kind===`instance`&&!t.enabled?`text-foreground-muted`:`text-foreground`}`,children:t.name}),t.kind===`fixed`&&t.description.length>0&&i(`span`,{className:`line-clamp-2 text-[11px] text-foreground-subtle`,title:t.description,children:t.description})]})},{key:`provider`,header:C(`providerInstances.colProvider`,`Provider`),sortValue:e=>e.providerName,render:e=>i(`span`,{className:`text-foreground-muted`,children:e.providerName})},...J?[{key:`kind`,header:C(`providerInstances.colKind`,`Kind`),sortValue:e=>e.kind===`instance`?e.kindLabel??``:``,render:e=>e.kind===`instance`&&e.kindLabel!==void 0&&e.kindLabel.length>0?i(Ae,{addonId:e.addonId,label:e.kindLabel}):i(`span`,{className:`text-foreground-muted`})}]:[],{key:`state`,header:C(`instances.colStatus`,`Status`),notSortableReason:C(`providerInstances.stateNotSortable`,`A row carries a badge, not a value to order by.`),render:e=>e.kind===`instance`?i(He,{row:e}):i(w,{variant:e.isActive?`success`:`default`,children:e.isActive?C(`instances.active`,`Active`):C(`providerInstances.off`,`Off`)})},{key:`on`,header:C(`providerInstances.colOn`,`On`),notSortableReason:C(`providerInstances.onNotSortable`,`A switch is not a value to order by.`),render:e=>e.kind===`fixed`?i(Ue,{row:e,functionCap:t}):i(ze,{row:e,pinning:z(e.id)})},...g??[],{key:`actions`,align:`right`,notSortableReason:C(`providerInstances.actionsNotSortable`,`Row actions are not values.`),render:t=>e(`span`,{className:`inline-flex items-center gap-1`,children:[t.kind===`instance`&&t.connectPath!==void 0&&i(D,{icon:ee,variant:`ghost`,size:`sm`,"aria-label":C(`providerInstances.connectRow`,`Connect {{name}}`,{name:t.name}),onClick:()=>Y(t.connectPath,t.id)}),t.kind===`instance`&&t.disconnectPath!==void 0&&i(D,{icon:ce,variant:`ghost`,size:`sm`,"aria-label":C(`providerInstances.disconnectRow`,`Disconnect {{name}}`,{name:t.name}),onClick:()=>Y(t.disconnectPath,t.id)}),t.kind===`instance`&&t.canTest&&i(D,{icon:N===t.key?h:se,variant:`ghost`,size:`sm`,"aria-label":C(`providerInstances.testRow`,`Test {{name}}`,{name:t.name}),disabled:N!==null,onClick:()=>void K(t)}),t.kind===`instance`&&v?.(t),t.kind===`fixed`&&y?.(t),i(D,{icon:oe,variant:`ghost`,size:`sm`,"aria-label":C(`providerInstances.editRow`,`Edit {{name}}`,{name:t.name}),onClick:()=>j.openEdit(B(t.addonId,t.kind===`instance`?t.id:void 0))}),i(Me,{iconOnly:!0,addonId:t.addonId,displayName:t.providerName,description:C(`providerInstances.restartConfirm`,`Restarts the addon on the hub. If it shares a runner group, every addon in that group restarts with it.`)}),t.kind===`instance`&&(b?.(t)??!0)&&i(D,{icon:f,variant:`ghost`,size:`sm`,"aria-label":C(`providerInstances.deleteRow`,`Delete {{name}}`,{name:t.name}),onClick:()=>void q(t)})]})}],[g,j,t,z,v,y,b,q,Y,K,J,C,N]),X;X=A.state===`error`?i(`div`,{className:`p-3`,children:i(le,{title:C(`providerInstances.loadFailed`,`Could not load the list`),message:A.error??``,onRetry:A.refetch})}):A.state===`pending`?e(`div`,{className:`flex items-center gap-2 p-3 text-xs text-foreground-subtle`,children:[i(h,{className:`h-3 w-3 animate-spin`}),C(`providerInstances.loading`,`Loading…`)]}):A.rows.length===0?i(he,{icon:a,title:d,description:p}):i(ue,{columns:Pe,rows:Ne,rowKey:e=>e.key,bordered:!1,emptyMessage:C(`instances.noneForProvider`,`This provider has no instance yet.`)});let Z=A.holders.filter(e=>!H.includes(e)).map(e=>G(e.addonId)),Q=H.length>0?void 0:Z.length>0?C(`instances.addBlocked`,`{{names}}: only one instance is allowed and it already exists.`,{names:Z.join(`, `)}):C(`instances.addNone`,`No provider here can hold instances.`),$=e(u,{children:[c!==void 0&&i(`p`,{className:`px-3 pt-2 text-xs text-foreground-muted`,children:c}),A.state===`ready`&&Q!==void 0&&i(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-subtle`,children:Q}),A.state===`ready`&&e(u,{children:[e(ge,{children:[de?.(A.rows.filter(e=>e.kind===`instance`)),e(O,{size:`sm`,variant:`primary`,disabled:Q!==void 0,title:Q,onClick:()=>{let e=H.find(e=>e.addonId===W)??(H.length===1?H[0]:void 0);e===void 0?j.openNew():j.openEdit(B(e.addonId,null))},children:[i(ae,{className:`h-3.5 w-3.5`}),m]})]}),i(Le,{pills:U,selected:W,onSelect:je,fallbackIcon:a,...ne===void 0?{}:{install:ne}})]}),X,A.state===`ready`&&A.rows.length>0&&i(Ge,{rows:A.rows,selected:Te,onSelect:ke}),I!==null&&e(`div`,{className:`space-y-1 p-3`,children:[i(`p`,{className:`text-[11px] font-medium text-foreground`,children:I.name}),i(we,{verdict:I.verdict})]}),A.state===`ready`&&j.state.mode===`new`&&i(Oe,{open:!0,onClose:j.close,pickFrom:{title:m,providers:H.map(e=>({addonId:e.addonId,name:G(e.addonId),description:A.descriptions.get(e.addonId)??``})),onPick:e=>j.openEdit(B(e,null))}}),A.state===`ready`&&j.state.mode===`edit`&&i(Ke,{refValue:j.state.id,data:A,nameOf:G,onClose:j.close,onOpen:(e,t)=>j.openEdit(B(e,t)),..._===void 0?{}:{lead:_},...x===void 0?{}:{typedId:x}},j.state.id)]});return s===void 0?i(`section`,{"aria-label":m,className:te,children:$}):i(fe,{headingId:`provider-instances-${t}`,title:s,icon:a,children:$})}function Ge({rows:e,selected:t,onSelect:r}){let{t:a}=M(),o=n(()=>I(e),[e]),s=o[0];if(s===void 0)return null;let c=o.find(e=>e.addonId===t)??s;return i(`div`,{className:`p-3`,children:i(Pe,{addonId:c.addonId,switcher:o.length>1?i(`div`,{role:`group`,"aria-label":a(`providerInstances.activityProvider`,`Activity of`),className:`flex flex-wrap items-center gap-1`,children:o.map(e=>i(O,{variant:`unstyled`,type:`button`,"aria-pressed":e.addonId===c.addonId,onClick:()=>r(e.addonId),className:`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${e.addonId===c.addonId?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.name},e.addonId))}):void 0})})}function Ke({refValue:e,data:t,nameOf:n,onClose:r,onOpen:a,lead:o,typedId:s}){let c=Te(e);if(c.kind===`fixed`)return i(Z,{addonId:c.addonId,title:n(c.addonId),onClose:r});let l=t.holders.find(e=>e.addonId===c.addonId);if(l===void 0)return null;let u=c.kind===`instance`?l.instances.find(e=>e.id===c.id)??null:null;if(c.kind===`instance`&&u===null)return null;let d=t.rows.find(e=>e.kind===`instance`&&e.addonId===c.addonId&&e.id===u?.id);return i(qe,{addonId:c.addonId,...o!==void 0&&d!==void 0?{lead:o(d)}:{},providerName:n(c.addonId),description:l.description,instance:u,onClose:r,onOpen:a,...s===void 0?{}:{typedId:s}})}function qe(e){let{onOpen:n,onClose:r,onSaved:a,...o}=e,s=t(null),c=e.instance===null;return i(F,{...o,onSaved:e=>{c&&(s.current=e),a?.(e)},onClose:()=>{s.current===null?r():n(e.addonId,s.current)}})}export{$ as n,H as r,We as t};
|
|
1
|
+
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,k as c,o 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-CEyXHAdg.js";import{$t as f,Fr as ee,Gn as p,Ln as m,Mr as h,O as te,V as ne,_t as re,ct as ie,er as ae,fa as g,or as oe,tr as se}from"./player-overlays-DuG5kk5Q.js";import{Tr as _}from"./client-pLjIfKNS.js";import{t as ce}from"./link-2-off-DmsjRAt7.js";import{$r as v,Dn as y,En as b,Jd as le,Jn as ue,Jr as de,Kn as fe,Pi as pe,Q as me,Qr as x,Us as S,Vn as C,Xd as w,Yr as T,ga as E,hf as D,li as he,nt as ge,of as O,qr as k,ua as A,vr as j}from"./src-DOkmPL4F.js";import{t as M}from"./useTranslation-BJr-n0es.js";import{$ as _e,Br as ve,G as N,Vr as ye,X as P,Y as F,Z as be,at as I,ct as xe,et as Se,it as Ce,lt as we,ot as L,qr as R,r as z,rt as Te,st as Ee,tt as B,ut as De}from"./index-t4MmHqcc.js";import{t as Oe}from"./IntegrationWizard-BJ098UD3.js";import{t as ke}from"./NodeAddonsSettingsPanel-CafQePC4.js";s();function Ae({addonId:t,label:n}){return e(`span`,{className:`inline-flex items-center gap-1.5 text-foreground-muted`,children:[i(V,{addonId:t}),n]})}function V({addonId:e}){let t=N(e),[n,r]=o(!1);return!t||n?null:i(`img`,{src:t,alt:``,className:`h-4 w-4 shrink-0 rounded`,onError:()=>r(!0)})}var je=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],H=`text-[10px]`;function U(){let e=l();return A({onSuccess:()=>{for(let t of je)e.invalidateQueries({queryKey:t})}})}function W({addonId:e,displayName:t,message:n}){let{t:r}=M(),a=ie(),o=U();return i(D,{icon:o.isPending?h:p,variant:`ghost`,size:`sm`,"aria-label":r(`integrationHub.addonControls.restartNamed`,`Restart {{name}}`,{name:t}),disabled:o.isPending,onClick:()=>void a({title:r(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),message:n,confirmLabel:r(`integrationHub.addonControls.restart`,`Restart`),variant:`danger`}).then(t=>t?o.mutateAsync({addonId:e}):void 0)})}function Me({addonId:e,displayName:t,iconOnly:n=!1,description:r}){let{t:a}=M(),o=U(),s=r??a(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`);return n?i(W,{addonId:e,displayName:t,message:s}):i(C,{label:a(`integrationHub.addonControls.restart`,`Restart`),icon:p,size:`sm`,title:a(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),description:s,confirmLabel:a(`integrationHub.addonControls.restart`,`Restart`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:o.isPending,action:()=>o.mutateAsync({addonId:e})})}s();var Ne=600,G=c(null);function K({id:n,title:r,icon:a,actions:o,framed:s=!1,children:c}){let{t:l}=M(),f=d(G),p=t(null),m=`integration-section-${n}`;q(p,f,n);let h=e(u,{children:[f===null?null:i(R,{to:f.sectionHref(n),"aria-label":l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),title:l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title: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:i(ee,{className:`h-3 w-3`,"aria-hidden":!0})}),o]});return s?i(`div`,{ref:p,className:`scroll-mt-4`,children:i(fe,{headingId:m,title:r,icon:a,actions:h,children:c})}):e(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[e(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[a!==void 0&&i(a,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),i(`h2`,{id:m,className:`${ne} min-w-0 flex-1`,children:r}),h]}),c]})}function q(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;a(()=>{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()},Ne);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}s();var J=`max-h-72`,Y=[{kind:`logs`,labelKey:`common.logs`,icon:m},{kind:`events`,labelKey:`common.events`,icon:g}];function Pe({addonId:t,switcher:n}){let{t:r}=M(),[a,s]=o(`logs`);return e(K,{id:z,title:r(`integrationHub.addonIntegrationBody.activity`,`Activity`),framed:!0,actions:i(`div`,{className:`flex flex-wrap items-center gap-2`,children:i(`div`,{role:`group`,"aria-label":r(`integrationHub.addonIntegrationBody.activityStream`,`Activity stream`),className:`flex items-center gap-1`,children:Y.map(({kind:t,labelKey:n,icon:o})=>e(O,{variant:`unstyled`,type:`button`,"aria-pressed":a===t,onClick:()=>s(t),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${a===t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[i(o,{className:`h-3 w-3`,"aria-hidden":!0}),r(n)]},t))})}),children:[n!==void 0&&i(`div`,{className:`px-3 pt-2`,children:n}),a===`logs`?i(y,{addonId:t,maxHeight:J,showFilters:!1}):i(b,{addonId:t,category:`addon.*`,maxHeight:J})]})}function X({addonId:t,title:n=`Settings`,subtitle:r,fieldScope:a,onClose:o}){return i(k,{open:!0,onOpenChange:e=>!e&&o(),children:e(T,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-3xl`,children:[e(x,{children:[i(v,{children:n}),r&&i(`p`,{className:`text-xs text-foreground-subtle`,children:r})]}),i(de,{children:i(ke,{nodeId:null,addonIds:[t],level:`global`,...a===void 0?{}:{fieldScope:a}})})]})})}function Z({addonId:e,title:t,onClose:n}){return i(X,{addonId:e,title:t,fieldScope:`cluster`,onClose:n})}s();var Q={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function $({addonId:e,fallback:t,tileClassName:n,size:r=`md`}){let[a,s]=o(!1),c=N(e),l=Q[r];return i(`div`,{className:`${l.tile} flex items-center justify-center shrink-0 ${n}`,children:a||!c?i(t,{className:l.fallback,"aria-hidden":!0}):i(`img`,{src:c,alt:``,className:`${l.img} bg-white ring-1 ring-black/5`,onError:()=>s(!0)})})}var Fe={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function Ie(e,t){switch(t){case`ok`:return e(`instances.health.ok`,`Healthy`);case`error`:return e(`instances.health.error`,`Error`);case`off`:return e(`instances.health.off`,`Off`);case`unknown`:return e(`instances.health.unknown`,`Unknown`)}}function Le({pills:t,selected:n,onSelect:r,fallbackIcon:a,install:o}){let{t:s}=M(),c=t.length>1;return!c&&o===void 0?null:i(`div`,{className:`px-3 pt-2`,children:e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c&&i(`div`,{role:`group`,"aria-label":s(`instances.filterByProvider`,`Filter by provider`),className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:t.map(t=>e(O,{variant:`unstyled`,type:`button`,"aria-pressed":n===t.addonId,"data-testid":`instance-pill-${t.addonId}`,onClick:()=>r(n===t.addonId?null:t.addonId),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 ${n===t.addonId?`border-primary bg-primary/10 text-primary font-medium`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[i($,{addonId:t.addonId,fallback:a,tileClassName:``,size:`sm`}),i(`span`,{className:`truncate`,children:t.name}),i(`span`,{className:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:t.count}),i(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Fe[t.health]}`,"aria-hidden":!0}),i(`span`,{className:`sr-only`,children:Ie(s,t.health)})]},t.addonId))}),o!==void 0&&e(R,{to:_(o.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:[i(ae,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),i(`span`,{className:`truncate`,children:o.label})]})]})})}function Re(e){let t=S({onSuccess:e.onSuccess,onError:t=>e.onError?.(t.message)});return{mutate:e=>t.mutate({...e}),isPending:t.isPending}}s();function ze({row:t,pinning:n,onChanged:r}){let{t:a}=M(),s=l(),[c,u]=o(null),d=Re({onSuccess:()=>{u(null),s.invalidateQueries({queryKey:[P]}),r?.()},onError:u}),f=t.notRunning===void 0?null:a(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:t.providerName});return e(`span`,{className:`flex flex-col items-end gap-1`,title:f??void 0,children:[i(j,{checked:t.enabled,disabled:d.isPending||f!==null,"aria-label":a(`providerInstances.enable`,`Enable {{name}}`,{name:t.name}),"data-testid":`instance-switch-${t.id}`,onCheckedChange:e=>{u(null),d.mutate({addonId:t.addonId,id:t.id,enabled:e})}}),f!==null&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:f}),n>0&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`providerInstances.pinnedBy`,{count:n})}),c!==null&&i(`span`,{className:`text-[11px] text-danger`,role:`alert`,children:a(`providerInstances.switchFailed`,`Could not change {{name}}: {{message}}`,{name:t.name,message:c})})]})}s();var Be=`instance`;function Ve(e){let t=[e.status?.detail,e.lastCheckedAt===void 0?void 0:new Date(e.lastCheckedAt).toLocaleString()].filter(e=>e!==void 0&&e.length>0);return t.length>0?t.join(` · `):void 0}function He({row:t}){let{t:n}=M();return t.enabled?e(`span`,{className:`flex flex-wrap items-center gap-1`,children:[i(w,{variant:t.configured?`success`:`default`,children:t.configured?n(`providerInstances.configured`,`Configured`):n(`providerInstances.notConfigured`,`Not configured`)}),t.status!==void 0&&i(w,{variant:t.status.state===`error`?`danger`:t.status.state===`ok`?`success`:`default`,title:Ve(t),children:L(t.status)})]}):i(`span`,{className:`flex flex-wrap items-center gap-1`,children:i(w,{variant:`default`,children:n(`providerInstances.off`,`Off`)})})}function Ue({row:e,functionCap:t}){let{t:n}=M(),r=l(),a=E({onSuccess:()=>void r.invalidateQueries()});return i(j,{checked:e.isActive,disabled:a.isPending,"aria-label":n(`providerInstances.enable`,`Enable {{name}}`,{name:e.providerName}),onCheckedChange:n=>a.mutate({capName:t,addonId:e.addonId,enabled:n})})}function We({functionCap:t,icon:a,title:s,subtitle:c,emptyTitle:d,emptyDescription:p,addLabel:m,install:ne,extraColumns:g,lead:_,rowActions:v,fixedRowActions:y,canDelete:b,pageActions:de,typedId:x,rowFilter:S}){let{t:C}=M(),T=re(),E=l(),k=ie(),A=be(t),j=me({editKey:Be,newKey:`${Be}-new`}),[N,F]=o(null),[I,L]=o(null),R=pe({functionCap:`notification-output`}),z=r(e=>Ee(R.data??[],e).length,[R.data]),[Te,ke]=o(null),[V,je]=o(null),H=n(()=>_e(A.holders),[A.holders]),U=n(()=>Ce(A.functionProviders,A.rows,A.displayNames),[A.functionProviders,A.rows,A.displayNames]),W=U.some(e=>e.addonId===V)?V:null,Ne=n(()=>{let e=Se(A.rows,W);return S===void 0?e:e.filter(S)},[A.rows,W,S]),G=r(e=>A.displayNames.get(e)??e,[A.displayNames]),K=r(async e=>{F(e.key),L(null);try{let t=await T.trpcClient.integrationInstances.testInstance.mutate({addonId:e.addonId,id:e.id,values:{}});L({name:e.name,verdict:De(t)})}catch(t){let n=t instanceof Error?t.message:String(t);L({name:e.name,verdict:{status:`inconclusive`,error:n}})}finally{F(null)}},[T]),q=r(async e=>{let t=Ee(R.data??[],e.id),n=t.length>0?` ${C(`providerInstances.deletePinned`,`These notification targets use it and will stop delivering: {{names}}.`,{names:t.join(`, `)})}`:``;if(await k({title:C(`providerInstances.deleteTitle`,`Delete {{name}}?`,{name:e.name}),message:`${C(`providerInstances.deleteMessage`,`The record and its stored credentials are removed.`)}${n}`,confirmLabel:C(`common.delete`,`Delete`),variant:`danger`}))try{await T.trpcClient.integrationInstances.deleteInstance.mutate({addonId:e.addonId,id:e.id}),await E.invalidateQueries({queryKey:[P]})}catch(t){xe({title:C(`providerInstances.deleteFailed`,`Could not delete`),message:`${e.name}: ${t instanceof Error?t.message:String(t)}`,severity:`critical`})}},[k,E,T,C,R.data]),J=n(()=>A.rows.some(e=>e.kind===`instance`&&e.kindLabel!==void 0),[A.rows]),Y=r((e,t)=>{e!==void 0&&ye(ve(e,t),()=>{E.invalidateQueries({queryKey:[P]})})},[E]),Pe=n(()=>[{key:`name`,nowrap:!1,header:C(`providerInstances.colName`,`Name`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex flex-col`,children:[i(`span`,{className:`font-medium ${t.kind===`instance`&&!t.enabled?`text-foreground-muted`:`text-foreground`}`,children:t.name}),t.kind===`fixed`&&t.description.length>0&&i(`span`,{className:`line-clamp-2 text-[11px] text-foreground-subtle`,title:t.description,children:t.description})]})},{key:`provider`,header:C(`providerInstances.colProvider`,`Provider`),sortValue:e=>e.providerName,render:e=>i(`span`,{className:`text-foreground-muted`,children:e.providerName})},...J?[{key:`kind`,header:C(`providerInstances.colKind`,`Kind`),sortValue:e=>e.kind===`instance`?e.kindLabel??``:``,render:e=>e.kind===`instance`&&e.kindLabel!==void 0&&e.kindLabel.length>0?i(Ae,{addonId:e.addonId,label:e.kindLabel}):i(`span`,{className:`text-foreground-muted`})}]:[],{key:`state`,header:C(`instances.colStatus`,`Status`),notSortableReason:C(`providerInstances.stateNotSortable`,`A row carries a badge, not a value to order by.`),render:e=>e.kind===`instance`?i(He,{row:e}):i(w,{variant:e.isActive?`success`:`default`,children:e.isActive?C(`instances.active`,`Active`):C(`providerInstances.off`,`Off`)})},{key:`on`,header:C(`providerInstances.colOn`,`On`),notSortableReason:C(`providerInstances.onNotSortable`,`A switch is not a value to order by.`),render:e=>e.kind===`fixed`?i(Ue,{row:e,functionCap:t}):i(ze,{row:e,pinning:z(e.id)})},...g??[],{key:`actions`,align:`right`,notSortableReason:C(`providerInstances.actionsNotSortable`,`Row actions are not values.`),render:t=>e(`span`,{className:`inline-flex items-center gap-1`,children:[t.kind===`instance`&&t.connectPath!==void 0&&i(D,{icon:ee,variant:`ghost`,size:`sm`,"aria-label":C(`providerInstances.connectRow`,`Connect {{name}}`,{name:t.name}),onClick:()=>Y(t.connectPath,t.id)}),t.kind===`instance`&&t.disconnectPath!==void 0&&i(D,{icon:ce,variant:`ghost`,size:`sm`,"aria-label":C(`providerInstances.disconnectRow`,`Disconnect {{name}}`,{name:t.name}),onClick:()=>Y(t.disconnectPath,t.id)}),t.kind===`instance`&&t.canTest&&i(D,{icon:N===t.key?h:se,variant:`ghost`,size:`sm`,"aria-label":C(`providerInstances.testRow`,`Test {{name}}`,{name:t.name}),disabled:N!==null,onClick:()=>void K(t)}),t.kind===`instance`&&v?.(t),t.kind===`fixed`&&y?.(t),i(D,{icon:oe,variant:`ghost`,size:`sm`,"aria-label":C(`providerInstances.editRow`,`Edit {{name}}`,{name:t.name}),onClick:()=>j.openEdit(B(t.addonId,t.kind===`instance`?t.id:void 0))}),i(Me,{iconOnly:!0,addonId:t.addonId,displayName:t.providerName,description:C(`providerInstances.restartConfirm`,`Restarts the addon on the hub. If it shares a runner group, every addon in that group restarts with it.`)}),t.kind===`instance`&&(b?.(t)??!0)&&i(D,{icon:f,variant:`ghost`,size:`sm`,"aria-label":C(`providerInstances.deleteRow`,`Delete {{name}}`,{name:t.name}),onClick:()=>void q(t)})]})}],[g,j,t,z,v,y,b,q,Y,K,J,C,N]),X;X=A.state===`error`?i(`div`,{className:`p-3`,children:i(le,{title:C(`providerInstances.loadFailed`,`Could not load the list`),message:A.error??``,onRetry:A.refetch})}):A.state===`pending`?e(`div`,{className:`flex items-center gap-2 p-3 text-xs text-foreground-subtle`,children:[i(h,{className:`h-3 w-3 animate-spin`}),C(`providerInstances.loading`,`Loading…`)]}):A.rows.length===0?i(he,{icon:a,title:d,description:p}):i(ue,{columns:Pe,rows:Ne,rowKey:e=>e.key,bordered:!1,emptyMessage:C(`instances.noneForProvider`,`This provider has no instance yet.`)});let Z=A.holders.filter(e=>!H.includes(e)).map(e=>G(e.addonId)),Q=H.length>0?void 0:Z.length>0?C(`instances.addBlocked`,`{{names}}: only one instance is allowed and it already exists.`,{names:Z.join(`, `)}):C(`instances.addNone`,`No provider here can hold instances.`),$=e(u,{children:[c!==void 0&&i(`p`,{className:`px-3 pt-2 text-xs text-foreground-muted`,children:c}),A.state===`ready`&&Q!==void 0&&i(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-subtle`,children:Q}),A.state===`ready`&&e(u,{children:[e(ge,{children:[de?.(A.rows.filter(e=>e.kind===`instance`)),e(O,{size:`sm`,variant:`primary`,disabled:Q!==void 0,title:Q,onClick:()=>{let e=H.find(e=>e.addonId===W)??(H.length===1?H[0]:void 0);e===void 0?j.openNew():j.openEdit(B(e.addonId,null))},children:[i(ae,{className:`h-3.5 w-3.5`}),m]})]}),i(Le,{pills:U,selected:W,onSelect:je,fallbackIcon:a,...ne===void 0?{}:{install:ne}})]}),X,A.state===`ready`&&A.rows.length>0&&i(Ge,{rows:A.rows,selected:Te,onSelect:ke}),I!==null&&e(`div`,{className:`space-y-1 p-3`,children:[i(`p`,{className:`text-[11px] font-medium text-foreground`,children:I.name}),i(we,{verdict:I.verdict})]}),A.state===`ready`&&j.state.mode===`new`&&i(Oe,{open:!0,onClose:j.close,pickFrom:{title:m,providers:H.map(e=>({addonId:e.addonId,name:G(e.addonId),description:A.descriptions.get(e.addonId)??``})),onPick:e=>j.openEdit(B(e,null))}}),A.state===`ready`&&j.state.mode===`edit`&&i(Ke,{refValue:j.state.id,data:A,nameOf:G,onClose:j.close,onOpen:(e,t)=>j.openEdit(B(e,t)),..._===void 0?{}:{lead:_},...x===void 0?{}:{typedId:x}},j.state.id)]});return s===void 0?i(`section`,{"aria-label":m,className:te,children:$}):i(fe,{headingId:`provider-instances-${t}`,title:s,icon:a,children:$})}function Ge({rows:e,selected:t,onSelect:r}){let{t:a}=M(),o=n(()=>I(e),[e]),s=o[0];if(s===void 0)return null;let c=o.find(e=>e.addonId===t)??s;return i(`div`,{className:`p-3`,children:i(Pe,{addonId:c.addonId,switcher:o.length>1?i(`div`,{role:`group`,"aria-label":a(`providerInstances.activityProvider`,`Activity of`),className:`flex flex-wrap items-center gap-1`,children:o.map(e=>i(O,{variant:`unstyled`,type:`button`,"aria-pressed":e.addonId===c.addonId,onClick:()=>r(e.addonId),className:`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${e.addonId===c.addonId?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.name},e.addonId))}):void 0})})}function Ke({refValue:e,data:t,nameOf:n,onClose:r,onOpen:a,lead:o,typedId:s}){let c=Te(e);if(c.kind===`fixed`)return i(Z,{addonId:c.addonId,title:n(c.addonId),onClose:r});let l=t.holders.find(e=>e.addonId===c.addonId);if(l===void 0)return null;let u=c.kind===`instance`?l.instances.find(e=>e.id===c.id)??null:null;if(c.kind===`instance`&&u===null)return null;let d=t.rows.find(e=>e.kind===`instance`&&e.addonId===c.addonId&&e.id===u?.id);return i(qe,{addonId:c.addonId,...o!==void 0&&d!==void 0?{lead:o(d)}:{},providerName:n(c.addonId),description:l.description,instance:u,onClose:r,onOpen:a,...s===void 0?{}:{typedId:s}})}function qe(e){let{onOpen:n,onClose:r,onSaved:a,...o}=e,s=t(null),c=e.instance===null;return i(F,{...o,onSaved:e=>{c&&(s.current=e),a?.(e)},onClose:()=>{s.current===null?r():n(e.addonId,s.current)}})}export{$ as n,H as r,We as t};
|