@camstack/addon-admin-ui 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddLocationWizard-ty_4uW1H.js → AddLocationWizard-D6tk8U-w.js} +1 -1
- package/dist/assets/{AddonCollectionPage-CIvGYL8Z.js → AddonCollectionPage-CPQWZfC0.js} +1 -1
- package/dist/assets/Addons-BIu0hjHd.js +1 -0
- package/dist/assets/{AdminTabs-7T1CldHN.js → AdminTabs-Ddi8-SQJ.js} +1 -1
- package/dist/assets/{BrokerForm-DzjaLHmG.js → BrokerForm-Jzl9BAMO.js} +1 -1
- package/dist/assets/{BrokerStep-B3pEVZ2L.js → BrokerStep-vbWWE4ss.js} +1 -1
- package/dist/assets/{Capabilities-D2qn1TDV.js → Capabilities-GrzalIOH.js} +1 -1
- package/dist/assets/{CapabilityBadges-BWnECBvl.js → CapabilityBadges-BN0gXK4w.js} +1 -1
- package/dist/assets/{Cluster-BVUZdAyW.js → Cluster-zuSKpmeo.js} +2 -2
- package/dist/assets/{Dashboard-HorCsmCt.js → Dashboard-Dl3BUDju.js} +1 -1
- package/dist/assets/{Data-hispFwBv.js → Data-DJn-KYZI.js} +1 -1
- package/dist/assets/{DetectionIntelligence-BtnTELA6.js → DetectionIntelligence-BhQAT1WX.js} +1 -1
- package/dist/assets/DeviceDetail-C16YaYd6.js +2 -0
- package/dist/assets/{Devices-XIivtEYO.js → Devices-D_zVs1PC.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CIF0Ft1g.js → EmbedPlayerPage-BjQGYATU.js} +1 -1
- package/dist/assets/{FormBuilder-DVLWBVys.js → FormBuilder-BXQEmfaE.js} +1 -1
- package/dist/assets/{Identity-8krGNqDO.js → Identity-ZvlfZz_A.js} +1 -1
- package/dist/assets/IntegrationDetail-Bnpn2hQ2.js +1 -0
- package/dist/assets/{Integrations-CxuWXvnl.js → Integrations-Bv07bA7c.js} +1 -1
- package/dist/assets/{Integrations-CxFwUmeX.js → Integrations-CsaOfFWR.js} +1 -1
- package/dist/assets/{Logs-DYrcsFh9.js → Logs-DBoE5z_U.js} +1 -1
- package/dist/assets/{MyAccess-C-zxwxTM.js → MyAccess-Bp5Cp_C6.js} +1 -1
- package/dist/assets/Network-Dyg7yTc_.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-B4ru8rzf.js → NodeAddonsSettingsPanel-9HVgS_gw.js} +1 -1
- package/dist/assets/Pipeline-DzZm2XqD.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-Cut8tYhS.js → PrivacyMaskSettings-Cl0lj_PR.js} +1 -1
- package/dist/assets/{ProviderIcon-BpqSF3Hu.js → ProviderIcon-DWSMqwcl.js} +1 -1
- package/dist/assets/{Settings-CriiXyFu.js → Settings-ayyuAbCz.js} +1 -1
- package/dist/assets/{Showroom-KHowYChm.js → Showroom-CQ1h4YKK.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cus-LW9c.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CS4OeMKk.js} +1 -1
- package/dist/assets/{bell-C1jXqDWz.js → bell-C9HUnDGC.js} +1 -1
- package/dist/assets/circle-check-big-BDdzTa9p.js +1 -0
- package/dist/assets/{copy-tH10joFB.js → copy-BtC330Ic.js} +1 -1
- package/dist/assets/{download-DyMeaCfZ.js → download-CEQQi2pw.js} +1 -1
- package/dist/assets/{hostInit-8PN225l2.js → hostInit-Y3VsYAf_.js} +1 -1
- package/dist/assets/index-DuroU2aU.js +4 -0
- package/dist/assets/{key-round-eCBxaKT6.js → key-round-C1aQCNHE.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-137d5c5b.js → mf-entry-bootstrap-0-3e98f17f.js} +2 -2
- package/dist/assets/{pencil-xW8n5CLs.js → pencil-Dw6owGVy.js} +1 -1
- package/dist/assets/plus-CbaF5MYw.js +1 -0
- package/dist/assets/{radio-CWnAI4na.js → radio-CyBw1Cvj.js} +1 -1
- package/dist/assets/{refresh-cw-BKhUNMXQ.js → refresh-cw-CPqFoliO.js} +1 -1
- package/dist/assets/remoteEntry-BXtCFyvA.js +1 -0
- package/dist/assets/{rotate-ccw-BXu8SIv5.js → rotate-ccw-BJL6I3ju.js} +1 -1
- package/dist/assets/rotate-cw-DZGWB7EU.js +1 -0
- package/dist/assets/search-cFwrysqG.js +1 -0
- package/dist/assets/{server-X3K4ldX4.js → server-BgZ85UtO.js} +1 -1
- package/dist/assets/{sparkles-ChgPFrhX.js → sparkles-Dj3mm_rJ.js} +1 -1
- package/dist/assets/square-D-dTwz52.js +1 -0
- package/dist/assets/{square-check-big-Bzz95oCZ.js → square-check-big-CMEqldHV.js} +1 -1
- package/dist/assets/{src-C5tvi19O.js → src-CqVYgpnN.js} +4 -4
- package/dist/assets/{upload-BeG8PyHB.js → upload-tyMJOOSL.js} +1 -1
- package/dist/assets/useDevice-DTk9eLX5.js +1 -0
- package/dist/assets/{useEventInvalidation-Cf9VIpDW.js → useEventInvalidation-CqPABxEF.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BLisQvKo.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B1bVOGqv.js} +2 -2
- package/dist/assets/{wifi-DYJHTrlD.js → wifi-Do23YMj8.js} +1 -1
- package/dist/assets/{zap-DLiiHws-.js → zap-CZ68wiP1.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/sw.js +1 -1
- package/dist/workbox-14d7584c.js +1 -0
- package/package.json +1 -1
- package/dist/assets/Addons-CWtFT6QM.js +0 -1
- package/dist/assets/DeviceDetail-OXTiYiO9.js +0 -2
- package/dist/assets/IntegrationDetail-Dyg4wlgs.js +0 -1
- package/dist/assets/Network-D5ppyqPS.js +0 -1
- package/dist/assets/Pipeline-CS6lN8Ww.js +0 -1
- package/dist/assets/circle-check-big-is5GRKO9.js +0 -1
- package/dist/assets/index-CAfPe666.js +0 -4
- package/dist/assets/plus-DVpT3Ja2.js +0 -1
- package/dist/assets/remoteEntry-BOZn_K50.js +0 -1
- package/dist/assets/rotate-cw-BO4D9G2F.js +0 -1
- package/dist/assets/search-DyWYI0Yj.js +0 -1
- package/dist/assets/square-Faey8y7b.js +0 -1
- package/dist/assets/useDevice-B7VwJa4X.js +0 -1
- package/dist/workbox-9c191d2f.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Ci as e,Di as t,Ei as n,Ni as r,Si as i,Ti as a,_i as o,at as s,bi as c,c as l,fa as u,gi as d,hi as f,mi as p,pi as m,qi as h,s as g,st as _,vi as v,wi as y,xi as b,yi as x}from"./src-C5tvi19O.js";import{G as S,U as C,X as w,b as T,o as E,x as D,y as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{t as k}from"./circle-check-big-is5GRKO9.js";import{t as A}from"./copy-tH10joFB.js";import{t as j}from"./key-round-eCBxaKT6.js";import{t as M}from"./AddonCollectionPage-CIvGYL8Z.js";import{t as ee}from"./plus-DVpT3Ja2.js";import{B as N,C as P,F,d as I,i as L,l as R,r as z,s as B,w as V,x as H}from"./index-CAfPe666.js";import{t as U}from"./AdminPage-CN6ZMhf0.js";import{t as W}from"./AdminTabs-7T1CldHN.js";var G=N(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=N(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),te=N(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=N(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),J=N(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);w();function ne({userId:e,username:t,onClose:n}){let i=E(),a=r(),s=o({userId:e}),c=s.data,l=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=d({onSuccess:()=>{l(),n()}}),p=s.isLoading?`loading`:c?.enabled?`enrolled`:`not_enrolled`;return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[D(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[D(`div`,{className:`flex items-center gap-2`,children:[T(R,{className:`h-4 w-4 text-primary`}),D(`div`,{children:[T(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),D(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,T(`span`,{className:`font-mono`,children:t})]})]})]}),T(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`p-4 space-y-4`,children:[p===`loading`&&D(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[T(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&D(`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:[T(P,{className:`h-4 w-4 mt-0.5 shrink-0`}),D(`div`,{children:[T(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),T(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&c&&D(O,{children:[D(`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:[T(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),D(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[T(`div`,{className:`font-medium`,children:`2FA is active`}),D(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,c.confirmedAt?new Date(c.confirmedAt).toLocaleString():`—`]})]})]}),T(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),D(`div`,{className:`flex justify-end gap-2`,children:[T(u,{onClick:n,variant:`secondary`,children:`Close`}),D(`button`,{onClick:async()=>{await a({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&f.mutate({userId:e})},disabled:f.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[f.isPending?T(H,{className:`h-3 w-3 animate-spin`}):T(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function Y(){let e=E(),{user:a}=z(),[o,s]=S(!1),[c,l]=S(``),[u,d]=S(``),[m,g]=S(!1),[_,v]=S(null),{data:y,isLoading:x,isError:C}=b(),w=r(),O=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=p({onSuccess:()=>{O(),s(!1),l(``),d(``),g(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),A=f({onSuccess:O}),j=t({onSuccess:O}),M=i({onSuccess:O}),N=n({onSuccess:()=>{O(),F(null)}}),[P,F]=S(null),[V,W]=S(null),G=y??[];async function K(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function q(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function J(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function Y(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return D(U,{children:[T(`div`,{className:`flex items-center justify-end`,children:D(`button`,{onClick:()=>s(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[T(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),o&&D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-center justify-between`,children:[T(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),T(`button`,{onClick:()=>s(!1),className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`grid grid-cols-3 gap-3`,children:[D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),T(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),T(`input`,{type:`password`,value:u,onChange:e=>d(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),D(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:m,onChange:e=>g(e.target.checked),className:`rounded border-border focus:ring-primary`}),T(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),_&&T(`p`,{className:`text-[10px] text-danger`,children:_}),D(`div`,{className:`flex justify-end gap-2`,children:[T(`button`,{onClick:()=>s(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>k.mutate({username:c,password:u,isAdmin:m}),disabled:k.isPending||!c||!u,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),x&&T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),C&&T(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!C&&G.length===0&&T(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return T(h,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>D(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>J(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),T(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return T(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return D(`button`,{onClick:()=>F(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[T(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>T(`span`,{className:`text-foreground-subtle`,children:Y(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let n=e(t);return D(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==a?.id&&t.totpEnabled&&D(`button`,{onClick:()=>W(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[T(R,{className:`h-3 w-3`}),`Remove 2FA`]}),D(`button`,{onClick:()=>q(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[T(te,{className:`h-3 w-3`}),`Reset password`]}),D(`button`,{onClick:()=>K(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&T(ne,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&T(re,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function re(e){let{user:t}=z(),n=t?.isAdmin===!0;return T(ie,{...e,callerScopes:n?null:t?.scopes??[]})}function ie({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=S(C(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=l(a);return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:D(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[D(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[D(`div`,{children:[D(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),T(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`px-4 py-4`,children:[T(g,{value:a,onChange:o,clampToParent:i,emptyHint:D(O,{children:[`No scopes granted.`,` `,T(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&T(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),D(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?T(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}w();var ae=`bg-primary/10 text-primary`,oe=`bg-foreground-subtle/10 text-foreground-subtle`;function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function se(e){return e?e===`*`?`*`:e.join(`, `):``}function ce(){let t=E(),n=r(),{data:i,isLoading:o}=v(),{data:s}=b(),c=C(()=>i??[],[i]),l=C(()=>s??[],[s]),u=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),d=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[f,p]=S(!1),[h,g]=S(null),_=e({onSuccess:u}),y=m({onSuccess:({token:e,record:t})=>{d(),p(!1),g({token:e,label:t.name})}}),x=a({onSuccess:d}),w=async(e,t)=>{await n({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&_.mutate({id:e})},O=async(e,t)=>{await n({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})};return D(U,{children:[D(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[T(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),D(`button`,{onClick:()=>p(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:l.length===0,title:l.length===0?`Create a user first`:`Issue a scoped token`,children:[T(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),D(Z,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&T(ue,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>T(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{O(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),c.length>0&&T(Z,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:T(de,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.map(e=>{let t=!!e.isAdmin,n=_.isPending&&_.variables?.id===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ae:oe}`,children:t?`admin`:`regular`})}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:se(e.allowedProviders)||`all`}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>{w(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),o&&T(le,{}),f&&T(pe,{users:l.map(e=>({id:e.id,username:e.username})),onClose:()=>p(!1),onSubmit:e=>y.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:y.isPending}),h&&T(me,{token:h.token,label:h.label,onClose:()=>g(null)})]})}function Z({title:e,subtitle:t,children:n}){return D(`div`,{className:`space-y-2`,children:[D(`div`,{className:`flex items-baseline justify-between`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&T(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function le(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ue({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function de({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=c({userId:e}),s=a??[];return o||s.length===0?null:D(`div`,{className:`space-y-1.5`,children:[T(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),T(de,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.expiresAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function pe({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=S(e[0]?.id??``),[c,u]=S(``),[d,f]=S([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,m]=S(``),h=l(d),_=o!==``&&c.trim().length>0&&d.length>0&&h===null&&!r;return D(he,{title:`Create scoped token`,onClose:t,children:[D(`div`,{className:`space-y-3`,children:[T(Q,{label:`On behalf of user`,children:T(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>T(`option`,{value:e.id,children:e.username},e.id))})}),T(Q,{label:`Name`,children:T(`input`,{value:c,onChange:e=>u(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),D(Q,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[T(g,{value:d,onChange:f,clampToParent:a}),h&&T(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),T(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:T(`input`,{type:`number`,min:1,value:p,onChange:e=>m(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),D(ge,{children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),D(`button`,{onClick:()=>{let e=parseInt(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:d,expiresAt:t})},disabled:!_,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?T(H,{className:`h-3.5 w-3.5 animate-spin`}):T(I,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function me({token:e,label:t,onClose:n}){let[r,i]=S(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return D(he,{title:`Token: ${t}`,onClose:n,children:[D(`div`,{className:`space-y-3`,children:[T(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),T(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),D(ge,{children:[D(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?T(F,{className:`h-3.5 w-3.5 text-primary`}):T(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),T(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function he({title:e,onClose:t,children:n}){return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[D(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),T(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return T(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Q({label:e,hint:t,children:n}){return D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&T(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}w();function $(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function _e(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function ve(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function be({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function xe(){let e=E(),t=r(),{data:n,isLoading:i}=x(),a=C(()=>n??[],[n]),o=y({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),s=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&o.mutate({id:e})};return D(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[i&&T(ve,{}),!i&&a.length===0&&T(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!i&&a.length>0&&T(be,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:a.map(e=>{let t=e.revokedAt!==null,n=(o.isPending?o.variables?.id:void 0)===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>T(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border`,children:t?D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):T(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&D(`button`,{onClick:()=>{s(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}w();var Se=3e4;function Ce(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function we(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:K,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:V,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:V,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:R,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:R,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Te(){let e=_({capName:`auth-provider`},{refetchInterval:Se}),t=s(void 0,{refetchInterval:Se}),n=C(()=>Ce(t.data??[]),[t.data]);return T(M,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:I,itemIcon:I,capability:`auth-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,renderExpandedPanel:e=>T(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-start gap-2.5`,children:[T(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),T(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),T(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>T(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&D(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[D(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[T(G,{className:`h-3 w-3`}),`Setup steps`]}),T(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>T(`li`,{children:e},t))})]}),e===`local-auth`&&D(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[T(P,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),D(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,T(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function De(){return T(`div`,{className:`flex flex-col p-4`,children:T(W,{tabs:[{id:`users`,label:`Users`,icon:J,content:T(Y,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:T(ce,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:T(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:T(Te,{})}]})})}export{De as IdentityPage};
|
|
1
|
+
import{Ci as e,Di as t,Ei as n,Ji as r,Oi as i,Pi as a,Si as o,Ti as s,_i as c,at as l,bi as u,c as d,gi as f,hi as p,mi as m,pa as h,s as g,st as _,vi as v,wi as y,xi as b,yi as x}from"./src-CqVYgpnN.js";import{G as S,U as C,X as w,b as T,o as E,x as D,y as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{t as k}from"./circle-check-big-BDdzTa9p.js";import{t as A}from"./copy-BtC330Ic.js";import{t as j}from"./key-round-C1aQCNHE.js";import{t as M}from"./AddonCollectionPage-CPQWZfC0.js";import{t as ee}from"./plus-CbaF5MYw.js";import{B as N,C as P,F,d as I,i as L,l as R,r as z,s as B,w as V,x as H}from"./index-DuroU2aU.js";import{t as U}from"./AdminPage-CN6ZMhf0.js";import{t as W}from"./AdminTabs-Ddi8-SQJ.js";var G=N(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=N(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),te=N(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=N(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),J=N(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);w();function ne({userId:e,username:t,onClose:n}){let r=E(),i=a(),o=v({userId:e}),s=o.data,l=()=>r.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),u=c({onSuccess:()=>{l(),n()}}),d=o.isLoading?`loading`:s?.enabled?`enrolled`:`not_enrolled`;return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[D(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[D(`div`,{className:`flex items-center gap-2`,children:[T(R,{className:`h-4 w-4 text-primary`}),D(`div`,{children:[T(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),D(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,T(`span`,{className:`font-mono`,children:t})]})]})]}),T(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`p-4 space-y-4`,children:[d===`loading`&&D(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[T(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),d===`not_enrolled`&&D(`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:[T(P,{className:`h-4 w-4 mt-0.5 shrink-0`}),D(`div`,{children:[T(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),T(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),d===`enrolled`&&s&&D(O,{children:[D(`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:[T(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),D(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[T(`div`,{className:`font-medium`,children:`2FA is active`}),D(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,s.confirmedAt?new Date(s.confirmedAt).toLocaleString():`—`]})]})]}),T(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),D(`div`,{className:`flex justify-end gap-2`,children:[T(h,{onClick:n,variant:`secondary`,children:`Close`}),D(`button`,{onClick:async()=>{await i({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&u.mutate({userId:e})},disabled:u.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:[u.isPending?T(H,{className:`h-3 w-3 animate-spin`}):T(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function Y(){let n=E(),{user:s}=z(),[c,l]=S(!1),[u,d]=S(``),[m,h]=S(``),[g,_]=S(!1),[v,y]=S(null),{data:b,isLoading:x,isError:C}=o(),w=a(),O=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=p({onSuccess:()=>{O(),l(!1),d(``),h(``),_(!1),y(null)},onError:e=>{y(e instanceof Error?e.message:`Failed to create user`)}}),A=f({onSuccess:O}),j=i({onSuccess:O}),M=e({onSuccess:O}),N=t({onSuccess:()=>{O(),F(null)}}),[P,F]=S(null),[V,W]=S(null),G=b??[];async function K(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function q(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function J(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function Y(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return D(U,{children:[T(`div`,{className:`flex items-center justify-end`,children:D(`button`,{onClick:()=>l(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[T(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),c&&D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-center justify-between`,children:[T(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),T(`button`,{onClick:()=>l(!1),className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`grid grid-cols-3 gap-3`,children:[D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),T(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),T(`input`,{type:`password`,value:m,onChange:e=>h(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),D(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`rounded border-border focus:ring-primary`}),T(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),v&&T(`p`,{className:`text-[10px] text-danger`,children:v}),D(`div`,{className:`flex justify-end gap-2`,children:[T(`button`,{onClick:()=>l(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>k.mutate({username:u,password:m,isAdmin:g}),disabled:k.isPending||!u||!m,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),x&&T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),C&&T(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!C&&G.length===0&&T(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return T(r,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>D(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>J(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),T(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return T(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return D(`button`,{onClick:()=>F(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[T(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>T(`span`,{className:`text-foreground-subtle`,children:Y(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let n=e(t);return D(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==s?.id&&t.totpEnabled&&D(`button`,{onClick:()=>W(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[T(R,{className:`h-3 w-3`}),`Remove 2FA`]}),D(`button`,{onClick:()=>q(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[T(te,{className:`h-3 w-3`}),`Reset password`]}),D(`button`,{onClick:()=>K(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&T(ne,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&T(re,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function re(e){let{user:t}=z(),n=t?.isAdmin===!0;return T(ie,{...e,callerScopes:n?null:t?.scopes??[]})}function ie({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=S(C(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=d(a);return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:D(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[D(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[D(`div`,{children:[D(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),T(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`px-4 py-4`,children:[T(g,{value:a,onChange:o,clampToParent:i,emptyHint:D(O,{children:[`No scopes granted.`,` `,T(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&T(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),D(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?T(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}w();var ae=`bg-primary/10 text-primary`,oe=`bg-foreground-subtle/10 text-foreground-subtle`;function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function se(e){return e?e===`*`?`*`:e.join(`, `):``}function ce(){let e=E(),t=a(),{data:r,isLoading:i}=x(),{data:s}=o(),c=C(()=>r??[],[r]),l=C(()=>s??[],[s]),u=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),d=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[f,p]=S(!1),[h,g]=S(null),_=y({onSuccess:u}),v=m({onSuccess:({token:e,record:t})=>{d(),p(!1),g({token:e,label:t.name})}}),b=n({onSuccess:d}),w=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&_.mutate({id:e})},O=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&b.mutate({id:e})};return D(U,{children:[D(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[T(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),D(`button`,{onClick:()=>p(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:l.length===0,title:l.length===0?`Create a user first`:`Issue a scoped token`,children:[T(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),D(Z,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&T(ue,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>T(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{O(e,t)},revokePending:b.isPending,revokeId:b.variables?.id},e.id))]}),c.length>0&&T(Z,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:T(de,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.map(e=>{let t=!!e.isAdmin,n=_.isPending&&_.variables?.id===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ae:oe}`,children:t?`admin`:`regular`})}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:se(e.allowedProviders)||`all`}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>{w(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),i&&T(le,{}),f&&T(pe,{users:l.map(e=>({id:e.id,username:e.username})),onClose:()=>p(!1),onSubmit:e=>v.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:v.isPending}),h&&T(me,{token:h.token,label:h.label,onClose:()=>g(null)})]})}function Z({title:e,subtitle:t,children:n}){return D(`div`,{className:`space-y-2`,children:[D(`div`,{className:`flex items-baseline justify-between`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&T(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function le(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ue({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function de({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=b({userId:e}),s=a??[];return o||s.length===0?null:D(`div`,{className:`space-y-1.5`,children:[T(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),T(de,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.expiresAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function pe({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=S(e[0]?.id??``),[c,l]=S(``),[u,f]=S([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,m]=S(``),h=d(u),_=o!==``&&c.trim().length>0&&u.length>0&&h===null&&!r;return D(he,{title:`Create scoped token`,onClose:t,children:[D(`div`,{className:`space-y-3`,children:[T(Q,{label:`On behalf of user`,children:T(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>T(`option`,{value:e.id,children:e.username},e.id))})}),T(Q,{label:`Name`,children:T(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),D(Q,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[T(g,{value:u,onChange:f,clampToParent:a}),h&&T(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),T(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:T(`input`,{type:`number`,min:1,value:p,onChange:e=>m(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),D(ge,{children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),D(`button`,{onClick:()=>{let e=parseInt(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!_,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?T(H,{className:`h-3.5 w-3.5 animate-spin`}):T(I,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function me({token:e,label:t,onClose:n}){let[r,i]=S(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return D(he,{title:`Token: ${t}`,onClose:n,children:[D(`div`,{className:`space-y-3`,children:[T(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),T(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),D(ge,{children:[D(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?T(F,{className:`h-3.5 w-3.5 text-primary`}):T(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),T(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function he({title:e,onClose:t,children:n}){return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[D(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),T(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return T(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Q({label:e,hint:t,children:n}){return D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&T(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}w();function $(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function _e(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function ve(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function be({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function xe(){let e=E(),t=a(),{data:n,isLoading:r}=u(),i=C(()=>n??[],[n]),o=s({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),c=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&o.mutate({id:e})};return D(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&T(ve,{}),!r&&i.length===0&&T(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&T(be,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:i.map(e=>{let t=e.revokedAt!==null,n=(o.isPending?o.variables?.id:void 0)===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>T(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border`,children:t?D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):T(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&D(`button`,{onClick:()=>{c(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}w();var Se=3e4;function Ce(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function we(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:K,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:V,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:V,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:R,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:R,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Te(){let e=_({capName:`auth-provider`},{refetchInterval:Se}),t=l(void 0,{refetchInterval:Se}),n=C(()=>Ce(t.data??[]),[t.data]);return T(M,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:I,itemIcon:I,capability:`auth-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,renderExpandedPanel:e=>T(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-start gap-2.5`,children:[T(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),T(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),T(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>T(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&D(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[D(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[T(G,{className:`h-3 w-3`}),`Setup steps`]}),T(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>T(`li`,{children:e},t))})]}),e===`local-auth`&&D(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[T(P,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),D(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,T(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function De(){return T(`div`,{className:`flex flex-col p-4`,children:T(W,{tabs:[{id:`users`,label:`Users`,icon:J,content:T(Y,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:T(ce,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:T(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:T(Te,{})}]})})}export{De as IdentityPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Bn as e,Cn as t,Hn as n,J as r,Jt as i,Kn as a,Mi as o,R as s,Rn as c,Wn as l,Yi as u,d,dt as f,en as p,g as m,gn as h,in as g,ji as _,la as v,ln as y,nn as b,on as x,pn as ee,rn as S,tn as C,x as w,z as T,zn as te}from"./src-CqVYgpnN.js";import{F as E,G as D,R as O,U as k,W as A,X as j,b as M,o as N,x as P,y as F}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as I}from"./player-overlays-DzZKARlk.js";import{b as L}from"./src-CrhOk7JL.js";import{t as R}from"./ProviderIcon-DWSMqwcl.js";import{t as z}from"./plus-CbaF5MYw.js";import{t as B}from"./refresh-cw-CPqFoliO.js";import{t as V}from"./rotate-cw-DZGWB7EU.js";import{t as H}from"./wifi-Do23YMj8.js";import{B as U,E as W,F as ne,H as re,M as ie,P as G,R as ae,T as K,U as oe,f as se,i as ce,o as q,p as le,s as ue,t as de,x as J}from"./index-DuroU2aU.js";import{t as Y}from"./FormBuilder-BXQEmfaE.js";import{t as X}from"./BrokerStep-vbWWE4ss.js";var fe=U(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);j();function Z(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function pe(e,t,n){let[r,i]=D(`idle`),[a,o]=D({}),s=k(()=>{let t=[];for(let n of e.sections)t.push(...Z(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=E(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:E(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}j();function me(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...me(n.fields));return t}function he(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function ge(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){ge(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Q(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function _e({open:e,integrationId:n,addonId:r,onClose:i}){let{t:a}=de(),o=N(),[s,c]=D({}),[l,u]=D(!1),[d,f]=D(null),[p,h]=D(Q),g=y({addonId:r,type:L.Camera},{enabled:e}),_=g.data??null;O(()=>{e&&(c(_?ge(_.sections.flatMap(e=>e.fields)):{}),h(Q()),u(!1),f(null))},[e,n,_]);let v=k(()=>({...s,_probeRequestId:p}),[s,p]),b=S({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),x=t(),ee=E(async(e,t)=>{u(!0);let n=await x.mutateAsync({addonId:r,type:L.Camera,key:e,value:t,formValues:v});return n.status===`ok`&&n.suggestedValues&&c(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))he(e[i])&&!he(a)&&(r[i]=a,t=!0);return t?r:e}),n},[x,r,v]),{testAllStatus:C,hasProbeFields:w,probeResults:T,handleTestAll:te,clearProbeResult:A}=pe(_??{sections:[]},s,ee);async function j(e){f(null);try{await b.mutateAsync({addonId:r,type:L.Camera,config:s,integrationId:n}),e?c(_?ge(_.sections.flatMap(e=>e.fields)):{}):i()}catch(e){f(e instanceof Error?e.message:String(e))}}if(!e)return null;let F=me((_?.sections??[]).flatMap(e=>e.fields)).filter(e=>he(s[e])),I=F.length===0,R=!g.isLoading&&(g.isError||_===null);return P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[M(`div`,{className:`absolute inset-0 bg-black/60`,onClick:i}),P(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[P(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground`,children:a(`integrations.addDevice`)}),M(`button`,{onClick:i,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:M(ce,{className:`h-4 w-4`})})]}),M(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:g.isLoading?M(`div`,{className:`flex items-center justify-center py-8`,children:M(J,{className:`h-5 w-5 animate-spin text-primary`})}):R?P(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[M(q,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),P(`div`,{className:`space-y-1`,children:[M(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),P(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,M(`span`,{className:`font-mono`,children:r}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):M(Y,{schema:_,values:s,onChange:c,onTestField:ee,probeResults:T,onClearProbe:A})}),!R&&!g.isLoading&&P(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[P(`button`,{type:`button`,onClick:()=>u(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[P(`span`,{className:`flex items-center gap-2`,children:[M(le,{className:`h-3.5 w-3.5`}),`Test logs`,M(`span`,{className:`font-mono text-[9px] opacity-60`,children:p.slice(0,14)})]}),M(G,{className:`h-3.5 w-3.5 transition-transform ${l?`rotate-180`:``}`})]}),l&&M(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:M(m,{addonId:r,requestId:p,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!R&&!g.isLoading&&(d||F.length>0)&&M(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:P(`div`,{className:`flex items-start gap-2`,children:[M(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),M(`p`,{className:`text-[11px] text-destructive`,children:d||`Required: ${F.join(`, `)}`})]})}),P(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[P(`div`,{className:`flex items-center gap-2`,children:[M(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.cancel`)}),!R&&w&&P(`button`,{type:`button`,onClick:te,disabled:C===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[C===`testing`?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(H,{className:`h-3.5 w-3.5`}),`Test All`]})]}),P(`div`,{className:`flex items-center gap-2`,children:[M(`button`,{onClick:()=>j(!0),disabled:R||!I||b.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:a(`integrations.saveAndNew`)}),M(`button`,{onClick:()=>j(!1),disabled:R||!I||b.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:b.isPending?a(`integrations.saving`):a(`integrations.save`)})]})]})]})]})}function ve(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}j();var $=`devices`,ye={id:$,label:`Devices`,isDefault:!0},be=2e4,xe=100;function Se({addonId:t,integrationId:n,onClose:r}){let{t:a}=de(),[c,l]=D(new Set),[u,d]=D(new Set),[f,m]=D(new Map),[h,g]=D(null),{data:v}=e(),y=(v??[]).find(e=>e.addonId===t)?.supportsLocationImport??!1,[x,ee]=D(!0),S=i({integrationId:n}).data?.filters,w=S&&S.length>0?S:[ye],[T,te]=D(w.find(e=>e.isDefault)?.id??(w.some(e=>e.id===$)?$:w[0].id)),k=T!==$,j=b(),N=C({addonId:t,integrationId:n,page:1,pageSize:be,filter:T}),F=N.refetch,I=j.mutate,L=E(()=>{I({addonId:t,integrationId:n},{onSettled:()=>{F()}})},[I,t,n,F]),R=A(null);O(()=>{let e=`${t}::${n}`;R.current===e||N.isLoading||(R.current=e,(N.data?.candidates.length??0)===0&&L())},[t,n,N.isLoading,N.data,L]);let z=j.isPending,B=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,H=N.data?.candidates??[],U=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,W=p(),re=E(e=>{e.alreadyAdopted||l(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ie=E(e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),G=E((e,t)=>{m(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),ae=E(e=>{let t={};for(let n of e){let e=f.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[f]),K=E(async()=>{g(null);let e=[...c];if(e.length!==0)try{let i=ae(e);await W.mutateAsync({addonId:t,integrationId:n,filter:T,childNativeIds:e,...i?{perCandidate:i}:{},...y?{importLocations:x}:{}}),l(new Set),m(new Map),await F(),r()}catch(e){g(e instanceof Error?e.message:String(e))}},[c,ae,W,t,n,T,F,y,x]),oe=E(e=>{te(e),l(new Set),d(new Set),m(new Map),g(null)},[]),se=c.size;return P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[M(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),P(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[P(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[P(`div`,{className:`min-w-0`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground`,children:a(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),M(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:a(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),P(`div`,{className:`flex items-center gap-3 shrink-0`,children:[y&&P(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[M(`input`,{type:`checkbox`,checked:x,onChange:e=>ee(e.target.checked),className:`accent-primary`}),a(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),M(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:M(ce,{className:`h-4 w-4`})})]})]}),P(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(B??U)&&H.length===0&&M(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:P(`div`,{className:`flex items-start gap-2`,children:[M(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`div`,{className:`min-w-0`,children:[M(`p`,{className:`text-xs font-medium text-destructive`,children:a(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),M(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:B??U})]})]})}),w.length>1&&M(Ce,{filters:w,activeFilter:T,onSelect:oe}),M(`div`,{className:`flex-1 min-h-0`,children:M(s,{mode:`generic`,items:H,pageSize:xe,getKey:e=>e.childNativeId,getSearchText:ve,getFilterType:e=>e.type,filterOptions:_(),filterLabel:a(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:N.isLoading||z&&H.length===0,searchPlaceholder:a(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(B??U)&&H.length===0?``:a(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:P(`button`,{type:`button`,onClick:L,disabled:z,title:a(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[M(V,{className:`h-3.5 w-3.5 ${z?`animate-spin`:``}`}),a(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:a(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>M(we,{candidate:e,expandable:!k,expanded:u.has(e.childNativeId),onToggleExpand:()=>ie(e.childNativeId),adoptedLabel:a(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:a(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=o(e.type),n=t.icon;return P(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[M(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>M(`div`,{className:`flex items-center justify-end`,children:M(`button`,{onClick:()=>re(e),disabled:e.alreadyAdopted,"aria-label":c.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${c.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:c.has(e.childNativeId)&&M(ne,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!k&&u.has(e.childNativeId),renderExpanded:k?void 0:e=>M(Te,{candidate:e,hiddenChildIds:f.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>G(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:c.has(e.childNativeId)?`bg-primary/5`:``})})]}),h&&M(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:P(`div`,{className:`flex items-start gap-2`,children:[M(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),M(`p`,{className:`text-[11px] text-destructive`,children:h})]})}),P(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[M(`div`,{}),P(`div`,{className:`flex items-center gap-2`,children:[M(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.cancel`,{defaultValue:`Cancel`})}),P(`button`,{onClick:K,disabled:se===0||W.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[W.isPending&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),a(`integrations.addSelected`,{defaultValue:`Add selected`}),se>0?` (${se})`:``]})]})]})]})]})}function Ce({filters:e,activeFilter:t,onSelect:n}){return M(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return M(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function we({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return P(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?P(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[M(n?G:ie,{className:`h-3.5 w-3.5`}),a]}):M(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),M(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&M(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function Te({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:M(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return P(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[M(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&M(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),M(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:M(r?W:K,{className:`h-3 w-3`})})]},e.childNativeId)})})}j();function Ee({integrationId:e,addonId:t,name:r,kind:i,brokerKind:a,trpc:o,onClose:s}){let{t:c}=de(),u=N(),d=i===`device-adoption`,{data:f}=n({id:e},{enabled:d}),p=k(()=>{let e=f?.brokerId;return typeof e==`string`?e:null},[f]),m=l();return M(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:s,children:P(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[P(`div`,{className:`mb-3 flex items-center justify-between`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]}),M(`button`,{onClick:s,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":c(`common.close`,{defaultValue:`Close`}),children:M(ce,{className:`h-4 w-4`})})]}),d?a?P(`div`,{className:`space-y-3`,children:[M(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),p&&P(`p`,{className:`text-[11px] text-foreground`,children:[c(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,M(`span`,{className:`font-mono text-foreground-subtle`,children:p})]}),m.isPending?P(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[M(J,{className:`h-3 w-3 animate-spin`}),c(`integrations.saving`,{defaultValue:`Saving…`})]}):M(X,{kind:a,onResolved:t=>{m.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{u.invalidateQueries(),s()}})},onBack:s}),m.isError&&M(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):M(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):M(w,{trpc:o,addonId:t,nodeId:`hub`,title:r})]})})}j();function De(){let{t}=de(),{integrationId:n}=oe(),i=N(),o=re(),l=I(),[p,_]=D(!1),[y,b]=D(!1),[S,C]=D(!1),[w,O]=D(!1),{data:A,isLoading:j}=te({id:n??``},{enabled:!!n}),{data:L}=r({addonId:A?.addonId??``,nodeId:`hub`},{enabled:!!A?.addonId}),{data:V,isSuccess:H}=e(),U=k(()=>{let e=A?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[V,A?.addonId,H]),W=U!==null,ne=W?U===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ie=k(()=>{let e=A?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.brokerKind??null},[V,A?.addonId,H]),G=L!=null&&Array.isArray(L.sections)&&L.sections.some(e=>e.fields.length>0),{data:K}=ee({},{refetchInterval:5e3}),Y=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],X=a({onMutate:async e=>{await i.cancelQueries({queryKey:Y});let t=i.getQueryData(Y);return t!=null&&i.setQueryData(Y,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&i.setQueryData(Y,r.previous)},onSettled:()=>{i.invalidateQueries({queryKey:[[`integrations`]]}),i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=c({onSuccess:()=>{i.invalidateQueries({queryKey:[[`integrations`]]}),i.invalidateQueries({queryKey:[[`deviceManager`]]}),C(!1),o(`/integrations`)}}),pe=f({onSuccess:()=>{i.invalidateQueries({queryKey:[[`integrations`]]}),i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),me=h({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),he=g({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ge=x({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=k(()=>K??[],[K]),ve=k(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),$=E(e=>ve.get(e)??null,[ve]),ye=E(e=>M(R,{type:e,size:`sm`}),[]),be=E(e=>o(`/devices/${String(e)}`),[o]),xe=k(()=>{let e=A?.addonId;return e?Q.filter(t=>t.addonId===e):[]},[Q,A?.addonId]),Ce=k(()=>T(xe).length,[xe]);return j?P(`div`,{className:`p-4`,children:[M(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),M(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):A?P(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[M(u,{items:[{label:`Integrations`,onClick:()=>o(`/integrations`)},{label:A.name}]}),P(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[P(`div`,{className:`flex items-center gap-3 min-w-0`,children:[M(`img`,{src:`/api/addon-assets/${A.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),P(`div`,{className:`min-w-0`,children:[M(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:A.name}),P(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[A.addonId,` · `,Ce,` `,t(`integrations.devices`)]})]})]}),P(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[P(`button`,{onClick:()=>_(!0),disabled:!W,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:ne,children:[M(z,{className:`h-3.5 w-3.5`}),ne]}),P(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${X.isPending?`opacity-60`:``} ${A.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[M(v,{checked:A.enabled,onCheckedChange:e=>X.mutate({id:n,enabled:e}),disabled:X.isPending,"aria-label":A.enabled?`Disable integration`:`Enable integration`}),M(`span`,{className:`text-[11px] font-medium ${A.enabled?`text-success`:`text-foreground-subtle`}`,children:A.enabled?`Enabled`:`Disabled`}),X.isPending&&M(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),(G||U===`device-adoption`)&&P(`button`,{onClick:()=>b(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[M(se,{className:`h-3 w-3`}),t(`integrations.config`)]}),P(`button`,{onClick:()=>O(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[M(le,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),M(d,{label:`Restart`,icon:B,title:`Restart "${A.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ce} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:pe.isPending,action:()=>pe.mutateAsync({addonId:A.addonId})}),P(`button`,{onClick:()=>C(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[M(ue,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),M(s,{context:`integration-detail`,devices:Q,trpc:l.trpcClient,defaultView:`cards`,forceAddon:A.addonId,urlScope:`root`,lsKey:`integration-detail:${A.addonId}`,resolveIntegrationIcon:ye,resolveParent:$,onNavigate:be,batchActions:{remove:me.mutate,disable:he.mutate,enable:ge.mutate},onDeleteDevice:e=>me.mutate({deviceId:e.id})}),p&&n&&U===`device-adoption`&&M(Se,{addonId:A.addonId,integrationId:n,onClose:()=>_(!1)}),p&&n&&U===`device-provider`&&M(_e,{open:p,integrationId:n,addonId:A.addonId,onClose:()=>_(!1)}),y&&n&&U!==null&&M(Ee,{integrationId:n,addonId:A.addonId,name:A.name,kind:U,brokerKind:ie,trpc:l.trpcClient,onClose:()=>b(!1)}),w&&M(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>O(!1),children:P(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[P(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[P(`div`,{className:`flex items-center gap-2 min-w-0`,children:[M(le,{className:`h-4 w-4 text-primary shrink-0`}),M(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:A.name}),P(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[A.addonId,n?` · ${n}`:``]})]}),M(`button`,{onClick:()=>O(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:M(ce,{className:`h-4 w-4`})})]}),M(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:M(m,{addonId:A.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),S&&M(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&C(!1),children:P(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[P(`div`,{className:`flex items-start gap-3`,children:[M(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:M(q,{className:`h-4 w-4 text-danger`})}),P(`div`,{className:`min-w-0`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),M(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:A.name,count:Ce})})]})]}),Z.error&&M(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Z.error instanceof Error?Z.error.message:String(Z.error)}),P(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[M(`button`,{onClick:()=>C(!1),disabled:Z.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),M(`button`,{onClick:()=>Z.mutate({id:n}),disabled:Z.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Z.isPending?P(F,{children:[M(J,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):P(F,{children:[M(ue,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):P(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[M(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:M(fe,{className:`h-6 w-6 text-foreground-subtle`})}),P(`div`,{className:`space-y-1 max-w-sm`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),M(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),P(`button`,{onClick:()=>o(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[M(ae,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{De as IntegrationDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Bt as e,Ht as t,It as n,Lt as r,Ni as i,Ut as a,Vt as o,Wt as s,Zt as c,at as l,v as u,zt as d}from"./src-C5tvi19O.js";import{G as f,U as p,X as m,b as h,o as g,x as _,y as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as y}from"./player-overlays-DzZKARlk.js";import{c as b,n as x,u as S}from"./src-CrhOk7JL.js";import{t as C}from"./pencil-xW8n5CLs.js";import{t as w}from"./AddonCollectionPage-CIvGYL8Z.js";import{t as T}from"./plus-DVpT3Ja2.js";import{t as E}from"./radio-CWnAI4na.js";import{t as ee}from"./wifi-DYJHTrlD.js";import{B as D,H as O,g as k,i as A,s as j,x as M}from"./index-CAfPe666.js";import{t as N}from"./AdminPage-CN6ZMhf0.js";import{t as P}from"./BrokerForm-DzjaLHmG.js";import{t as F}from"./AdminTabs-7T1CldHN.js";var I=D(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),L=D(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]);m();var R={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function z(e){return R[e]??e}function B(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var V={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function te({status:e}){return h(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${V[e]}`,children:e})}function H(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function U({title:e,subtitle:t,onClose:n,children:r}){return h(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:_(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[_(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[_(`div`,{className:`space-y-0.5`,children:[h(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&h(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),h(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:h(A,{className:`h-4 w-4`})})]}),h(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto`,children:r})]})})}function W({kinds:e,onClose:t,onDone:r}){let i=g(),a=e=>`${e.addonId??``}::${e.kind}`,[o,s]=f(e[0]?a(e[0]):``),[c,l]=f(``),u=e.find(e=>a(e)===o)??e[0],d=u?.kind??``,p=u?.addonId,m=n({onSuccess:()=>{i.invalidateQueries({queryKey:[[`broker`,`list`]]}),r()}}),v=e=>{!d||c.trim().length===0||m.mutate({kind:d,name:c.trim(),settings:e,...p===void 0?{}:{addonId:p}})};return h(U,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:m.isPending?()=>{}:t,children:_(`div`,{className:`space-y-3`,children:[_(`div`,{className:`space-y-1`,children:[h(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),h(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>h(`option`,{value:a(e),children:e.label},a(e)))})]}),_(`div`,{className:`space-y-1`,children:[h(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),h(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),m.isError&&h(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:m.error instanceof Error?m.error.message:String(m.error)}),d&&h(P,{kind:d,...p===void 0?{}:{addonId:p},onSubmit:v,onCancel:t,submitLabel:m.isPending?`Adding…`:`Add broker`,disabled:m.isPending}),c.trim().length===0&&h(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`})]})})}function G({broker:e,onClose:t,onDone:n}){let i=g(),o=r({id:e.id,addonId:e.addonId}),s=a({onSuccess:()=>{i.invalidateQueries({queryKey:[[`broker`,`list`]]}),i.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),n()}}),c=p(()=>{let e=o.data;return e&&typeof e==`object`?{...e}:{}},[o.data]);return h(U,{title:`Edit ${e.name}`,subtitle:`${z(e.kind)} · ${e.id}`,onClose:s.isPending?()=>{}:t,children:o.isLoading?_(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[h(M,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):o.isError?_(`div`,{className:`space-y-3`,children:[_(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,o.error instanceof Error?o.error.message:`Unknown error`]}),h(`div`,{className:`flex justify-end`,children:h(`button`,{type:`button`,onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):_(`div`,{className:`space-y-3`,children:[s.isError&&h(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:s.error instanceof Error?s.error.message:String(s.error)}),h(P,{kind:e.kind,addonId:e.addonId,initialValues:c,onSubmit:t=>{s.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:s.isPending?`Saving…`:`Save`,disabled:s.isPending})]})})}function K({broker:e,onEdit:n}){let r=g(),a=i(),[o,c]=f(null),l=s({onSuccess:e=>c(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>c({ok:!1,error:e instanceof Error?e.message:String(e)})}),u=t({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),d=async()=>{await a({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&u.mutate({id:e.id,addonId:e.addonId})};return _(`tr`,{className:`border-b border-border last:border-0`,children:[h(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),h(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:z(e.kind)}),_(`td`,{className:`px-3 py-2`,children:[h(te,{status:e.status}),o&&h(`span`,{className:`ml-2 text-[10px] ${o.ok?`text-success`:`text-danger`}`,children:o.ok?`OK`:o.error??`failed`})]}),h(`td`,{className:`px-3 py-2`,children:_(`div`,{className:`flex items-center justify-end gap-1.5`,children:[_(`button`,{type:`button`,onClick:()=>l.mutate({id:e.id,addonId:e.addonId}),disabled:l.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[l.isPending?h(M,{className:`h-3 w-3 animate-spin`}):h(ee,{className:`h-3 w-3`}),`Test`]}),_(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[h(C,{className:`h-3 w-3`}),` Edit`]}),_(`button`,{type:`button`,onClick:()=>{d()},disabled:u.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u.isPending?h(M,{className:`h-3 w-3 animate-spin`}):h(j,{className:`h-3 w-3`}),`Delete`]})]})})]})}function q(){let t=e({}),n=o(),r=p(()=>H(t.data),[t.data]),[i,a]=f(!1),[s,c]=f(null),l=p(()=>{let e=new Map;for(let t of B(n.data))for(let n of t.kinds)e.set(`${t.addonId}::${n.kind}`,{addonId:t.addonId,kind:n.kind,label:n.label});for(let t of r)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:z(t.kind)});return[...e.values()]},[r,n.data]);return _(`div`,{className:`space-y-3`,children:[h(`div`,{className:`flex items-center justify-end`,children:_(`button`,{type:`button`,onClick:()=>a(!0),disabled:l.length===0,title:l.length===0?`No broker providers available`:void 0,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[h(T,{className:`h-3.5 w-3.5`}),` Add broker`]})}),h(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:_(`table`,{className:`w-full border-collapse`,children:[h(`thead`,{children:_(`tr`,{className:`border-b border-border bg-background/50`,children:[h(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),h(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),h(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),h(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),_(`tbody`,{children:[t.isLoading&&h(`tr`,{children:_(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[h(M,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),t.isError&&h(`tr`,{children:_(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,t.error instanceof Error?t.error.message:`Unknown error`]})}),!t.isLoading&&!t.isError&&r.length===0&&h(`tr`,{children:h(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),r.map(e=>h(K,{broker:e,onEdit:c},e.id))]})]})}),i&&h(W,{kinds:l,onClose:()=>a(!1),onDone:()=>a(!1)}),s&&h(G,{broker:s,onClose:()=>c(null),onDone:()=>c(null)})]})}var J=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:L,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:I,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:E,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function Y(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function X(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=Y(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function Z(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function Q(e){for(let[t,n]of Object.entries(x))if(n===e)return t;return null}function ne(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return h(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function re({addonId:e}){let{data:t,isLoading:n}=d({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=S.safeParse(t);if(!r.success)return null;let i=r.data;return h($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ie({addonId:e}){let{data:t,isLoading:n}=c({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=b.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return h($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function ae({kind:e,addonId:t}){return e===`broker`?h(re,{addonId:t}):e===`device-export`?h(ie,{addonId:t}):null}function oe({descriptor:e,rows:t,isLoading:n}){let r=Q(e.kind),i=e.kind===`device-export`,a=y(),o=O();return h(w,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:r??e.kind,installButtonLabel:e.addLabel,items:t,isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:t=>{let n=ne(t.processState);return _(v,{children:[h($,{label:n.label,className:n.className}),h(ae,{kind:e.kind,addonId:t.addonId})]})},renderExpandedPanel:i?e=>h(u,{addonId:e.addonId,trpc:a.trpcClient,onOpenDevice:e=>o(`/devices/${e}`)}):void 0,showChrome:!0})}function se(){let e=l(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(X).filter(e=>e!==null);return h(N,{icon:k,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:h(F,{tabs:J.map(n=>{let r=Object.entries(x).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?h(q,{}):h(oe,{descriptor:n,rows:Z(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{se as IntegrationsPage};
|
|
1
|
+
import{Bt as e,Gt as t,Ht as n,Lt as r,Pi as i,Qt as a,Rt as o,Ut as s,Vt as c,Wt as l,at as u,v as d}from"./src-CqVYgpnN.js";import{G as f,U as p,X as m,b as h,o as g,x as _,y as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as y}from"./player-overlays-DzZKARlk.js";import{c as b,n as x,u as S}from"./src-CrhOk7JL.js";import{t as C}from"./pencil-Dw6owGVy.js";import{t as w}from"./AddonCollectionPage-CPQWZfC0.js";import{t as T}from"./plus-CbaF5MYw.js";import{t as E}from"./radio-CyBw1Cvj.js";import{t as ee}from"./wifi-Do23YMj8.js";import{B as D,H as O,g as k,i as A,s as j,x as M}from"./index-DuroU2aU.js";import{t as N}from"./AdminPage-CN6ZMhf0.js";import{t as P}from"./BrokerForm-Jzl9BAMO.js";import{t as F}from"./AdminTabs-Ddi8-SQJ.js";var I=D(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),L=D(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]);m();var R={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function z(e){return R[e]??e}function B(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var V={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function te({status:e}){return h(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${V[e]}`,children:e})}function H(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function U({title:e,subtitle:t,onClose:n,children:r}){return h(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:_(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[_(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[_(`div`,{className:`space-y-0.5`,children:[h(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&h(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),h(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:h(A,{className:`h-4 w-4`})})]}),h(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto`,children:r})]})})}function W({kinds:e,onClose:t,onDone:n}){let i=g(),a=e=>`${e.addonId??``}::${e.kind}`,[o,s]=f(e[0]?a(e[0]):``),[c,l]=f(``),u=e.find(e=>a(e)===o)??e[0],d=u?.kind??``,p=u?.addonId,m=r({onSuccess:()=>{i.invalidateQueries({queryKey:[[`broker`,`list`]]}),n()}}),v=e=>{!d||c.trim().length===0||m.mutate({kind:d,name:c.trim(),settings:e,...p===void 0?{}:{addonId:p}})};return h(U,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:m.isPending?()=>{}:t,children:_(`div`,{className:`space-y-3`,children:[_(`div`,{className:`space-y-1`,children:[h(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),h(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>h(`option`,{value:a(e),children:e.label},a(e)))})]}),_(`div`,{className:`space-y-1`,children:[h(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),h(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),m.isError&&h(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:m.error instanceof Error?m.error.message:String(m.error)}),d&&h(P,{kind:d,...p===void 0?{}:{addonId:p},onSubmit:v,onCancel:t,submitLabel:m.isPending?`Adding…`:`Add broker`,disabled:m.isPending}),c.trim().length===0&&h(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`})]})})}function G({broker:e,onClose:t,onDone:n}){let r=g(),i=o({id:e.id,addonId:e.addonId}),a=l({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]}),r.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),n()}}),s=p(()=>{let e=i.data;return e&&typeof e==`object`?{...e}:{}},[i.data]);return h(U,{title:`Edit ${e.name}`,subtitle:`${z(e.kind)} · ${e.id}`,onClose:a.isPending?()=>{}:t,children:i.isLoading?_(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[h(M,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):i.isError?_(`div`,{className:`space-y-3`,children:[_(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,i.error instanceof Error?i.error.message:`Unknown error`]}),h(`div`,{className:`flex justify-end`,children:h(`button`,{type:`button`,onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):_(`div`,{className:`space-y-3`,children:[a.isError&&h(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:a.error instanceof Error?a.error.message:String(a.error)}),h(P,{kind:e.kind,addonId:e.addonId,initialValues:s,onSubmit:t=>{a.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:a.isPending?`Saving…`:`Save`,disabled:a.isPending})]})})}function K({broker:e,onEdit:n}){let r=g(),a=i(),[o,c]=f(null),l=t({onSuccess:e=>c(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>c({ok:!1,error:e instanceof Error?e.message:String(e)})}),u=s({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),d=async()=>{await a({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&u.mutate({id:e.id,addonId:e.addonId})};return _(`tr`,{className:`border-b border-border last:border-0`,children:[h(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),h(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:z(e.kind)}),_(`td`,{className:`px-3 py-2`,children:[h(te,{status:e.status}),o&&h(`span`,{className:`ml-2 text-[10px] ${o.ok?`text-success`:`text-danger`}`,children:o.ok?`OK`:o.error??`failed`})]}),h(`td`,{className:`px-3 py-2`,children:_(`div`,{className:`flex items-center justify-end gap-1.5`,children:[_(`button`,{type:`button`,onClick:()=>l.mutate({id:e.id,addonId:e.addonId}),disabled:l.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[l.isPending?h(M,{className:`h-3 w-3 animate-spin`}):h(ee,{className:`h-3 w-3`}),`Test`]}),_(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[h(C,{className:`h-3 w-3`}),` Edit`]}),_(`button`,{type:`button`,onClick:()=>{d()},disabled:u.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u.isPending?h(M,{className:`h-3 w-3 animate-spin`}):h(j,{className:`h-3 w-3`}),`Delete`]})]})})]})}function q(){let e=c({}),t=n(),r=p(()=>H(e.data),[e.data]),[i,a]=f(!1),[o,s]=f(null),l=p(()=>{let e=new Map;for(let n of B(t.data))for(let t of n.kinds)e.set(`${n.addonId}::${t.kind}`,{addonId:n.addonId,kind:t.kind,label:t.label});for(let t of r)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:z(t.kind)});return[...e.values()]},[r,t.data]);return _(`div`,{className:`space-y-3`,children:[h(`div`,{className:`flex items-center justify-end`,children:_(`button`,{type:`button`,onClick:()=>a(!0),disabled:l.length===0,title:l.length===0?`No broker providers available`:void 0,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[h(T,{className:`h-3.5 w-3.5`}),` Add broker`]})}),h(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:_(`table`,{className:`w-full border-collapse`,children:[h(`thead`,{children:_(`tr`,{className:`border-b border-border bg-background/50`,children:[h(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),h(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),h(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),h(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),_(`tbody`,{children:[e.isLoading&&h(`tr`,{children:_(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[h(M,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&h(`tr`,{children:_(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&r.length===0&&h(`tr`,{children:h(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),r.map(e=>h(K,{broker:e,onEdit:s},e.id))]})]})}),i&&h(W,{kinds:l,onClose:()=>a(!1),onDone:()=>a(!1)}),o&&h(G,{broker:o,onClose:()=>s(null),onDone:()=>s(null)})]})}var J=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:L,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:I,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:E,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function Y(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function X(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=Y(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function Z(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function Q(e){for(let[t,n]of Object.entries(x))if(n===e)return t;return null}function ne(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return h(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function re({addonId:t}){let{data:n,isLoading:r}=e({addonId:t},{refetchInterval:1e4,retry:!1});if(r||!n)return null;let i=S.safeParse(n);if(!i.success)return null;let a=i.data;return h($,{label:`${a.brokerCount} broker${a.brokerCount===1?``:`s`}${a.connectedCount>0?` • ${a.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ie({addonId:e}){let{data:t,isLoading:n}=a({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=b.safeParse(t);if(!r.success)return null;let i=r.data,o=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return h($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:o})}function ae({kind:e,addonId:t}){return e===`broker`?h(re,{addonId:t}):e===`device-export`?h(ie,{addonId:t}):null}function oe({descriptor:e,rows:t,isLoading:n}){let r=Q(e.kind),i=e.kind===`device-export`,a=y(),o=O();return h(w,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:r??e.kind,installButtonLabel:e.addLabel,items:t,isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:t=>{let n=ne(t.processState);return _(v,{children:[h($,{label:n.label,className:n.className}),h(ae,{kind:e.kind,addonId:t.addonId})]})},renderExpandedPanel:i?e=>h(d,{addonId:e.addonId,trpc:a.trpcClient,onOpenDevice:e=>o(`/devices/${e}`)}):void 0,showChrome:!0})}function se(){let e=u(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(X).filter(e=>e!==null);return h(N,{icon:k,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:h(F,{tabs:J.map(n=>{let r=Object.entries(x).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?h(q,{}):h(oe,{descriptor:n,rows:Z(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{se as IntegrationsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Hn as e,In as t,J as n,Qt as r,R as i,Wn as a,fn as o,in as s,ya as c,z as l,zn as u}from"./src-C5tvi19O.js";import{F as d,G as f,R as p,U as m,X as h,b as g,o as _,x as v,y}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as b}from"./player-overlays-DzZKARlk.js";import{t as x}from"./ProviderIcon-BpqSF3Hu.js";import{t as S}from"./plus-DVpT3Ja2.js";import{t as C}from"./refresh-cw-BKhUNMXQ.js";import{F as w,H as T,I as E,M as D,P as O,W as k,f as A,g as j,i as M,t as N,x as P}from"./index-CAfPe666.js";import{t as F}from"./AdminPage-CN6ZMhf0.js";import{t as I}from"./StatusBadge-CkYubfRG.js";import{t as L}from"./FormBuilder-DVLWBVys.js";import{t as R}from"./useEventInvalidation-Cf9VIpDW.js";import{t as z}from"./BrokerStep-B3pEVZ2L.js";h();function B({onSelect:e,onClose:t,pendingAddonId:n=null}){let{t:r}=N(),i=T(),{data:a,isLoading:o}=u();if(o)return g(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>g(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let s=n!==null;return v(`div`,{className:`space-y-2`,children:[(a??[]).map(a=>{let o=a.instanceMode===`unique`&&a.existingInstances.length>0,c=n===a.addonId,l=s;return v(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=a.existingInstances[0].id;t(),i(`/integrations/${e}`)}else e(a.addonId,a.instanceMode,a.discoveryMode,a.name,a.kind,a.brokerKind)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[a.iconUrl?g(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:g(`img`,{src:a.iconUrl,alt:``,className:`h-5 w-5`})}):g(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:g(`span`,{className:`text-sm`,style:{color:a.color},children:`◉`})}),v(`div`,{className:`flex-1 min-w-0`,children:[g(`p`,{className:`text-xs font-semibold text-foreground`,children:a.name}),a.description&&g(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:a.description})]}),c?g(P,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?v(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[g(A,{className:`h-3 w-3`}),r(`integrations.manage`)]}):g(D,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},a.addonId)}),(a??[]).length===0&&g(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:r(`integrations.noProviders`)})]})}function V({addonId:e,configSchema:t,onSave:n,onBack:r}){let{t:i}=N(),[o,s]=f(``),[c,l]=f({}),[u,d]=f(null),p=a({onSuccess:e=>d(e),onError:e=>d({success:!1,error:String(e)})});return v(`div`,{className:`space-y-4`,children:[v(`div`,{children:[g(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:i(`integrations.integrationName`)}),g(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:i(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&g(L,{schema:t,values:c,onChange:l}),u&&g(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${u.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:u.success?i(`integrations.connectionSuccess`):`${i(`integrations.errorPrefix`)} ${u.error}`}),v(`div`,{className:`flex items-center justify-between pt-2`,children:[g(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.back`)}),v(`div`,{className:`flex items-center gap-2`,children:[g(`button`,{onClick:()=>p.mutate({addonId:e,settings:c}),disabled:p.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:p.isPending?i(`integrations.testing`):i(`integrations.testConnection`)}),g(`button`,{onClick:()=>n({name:o,config:c}),disabled:!o.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:i(`integrations.forward`)})]})]})]})}h();function H({providerId:e,onImport:t,onSkip:n}){let{t:r}=N(),[i,a]=f(new Set),o=s(),c=o.data,l=o.isPending||!o.data&&!o.isError;p(()=>{e&&(o.isPending||o.data||o.mutate({addonId:e}))},[e,o]);function u(e){a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(l)return v(`div`,{className:`flex flex-col items-center py-12`,children:[g(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),g(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=c??[];return v(`div`,{className:`space-y-4`,children:[g(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&g(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=i.has(t);return v(`button`,{onClick:()=>u(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[g(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&g(w,{className:`h-3 w-3 text-primary-foreground`})}),g(E,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),g(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),v(`div`,{className:`flex items-center justify-between pt-2`,children:[g(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&v(`button`,{onClick:()=>t(Array.from(i)),disabled:i.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,i.size,`)`]})]})]})}h();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}function W({open:e,onClose:i}){let{t:a}=N(),o=T(),c=_(),[l,u]=f(`picker`),[d,h]=f(null),[b,x]=f(null),[S,C]=f(`manual`),[w,E]=f(null),[D,O]=f(``),[k,A]=f(null),[j,F]=f(null),{data:I}=n({addonId:d??``,nodeId:`hub`},{enabled:d!=null}),L=m(()=>I?U(I):null,[I]),R=t({onSuccess:()=>c.invalidateQueries({queryKey:[[`integrations`]]})}),W=s(),G=W.data;p(()=>{l!==`discovery`||!b||!d||W.isPending||W.data||W.mutate({addonId:d})},[l,b,d,W]);let ee=r({onSuccess:()=>c.invalidateQueries({queryKey:[[`deviceManager`]]})});async function te(e,t,n,r,a,s){if(!R.isPending){if(h(e),C(n),O(r),F(null),a===`device-adoption`){if(!s){F(`Addon '${e}' declares device-adoption but no brokerKind in its manifest`);return}E(s),u(`broker`);return}if(t===`unique`){try{let t=await R.mutateAsync({addonId:e,name:r,settings:{}});i(),Y(),o(`/integrations/${t.id}`)}catch{}return}u(`config`)}}async function K(e){if(d)try{let t=await R.mutateAsync({addonId:d,name:e.name,settings:e.config});x(t.id),S===`auto`||S===`both`?u(`discovery`):J(t.id)}catch{}}async function q(e){if(d)try{let t=await R.mutateAsync({addonId:d,name:D,settings:{brokerId:e}});A(t.id),x(t.id),J(t.id)}catch{}}async function ne(e){if(d){for(let t of e){let e=G?.find(e=>e.stableId===t);e&&await ee.mutateAsync({addonId:d,candidate:e,...k===null?{}:{integrationId:k}})}J()}}function J(e){let t=e??b??d;i(),Y(),t&&o(`/integrations/${t}`)}function Y(){u(`picker`),h(null),x(null),C(`manual`),E(null),O(``),A(null),F(null)}function X(){i(),Y()}if(!e)return null;let re={picker:a(`integrations.newIntegration`),config:a(`integrations.configureIntegration`),discovery:a(`integrations.importDevices`),broker:a(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Z=R.isPending,Q=Z?d:null,$=R.error;return v(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[g(`div`,{className:`absolute inset-0 bg-black/60`,onClick:Z?void 0:X}),v(`div`,{className:`relative z-10 w-full max-w-lg max-h-[85vh] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[v(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[g(`h2`,{className:`text-sm font-semibold text-foreground`,children:re[l]}),g(`button`,{onClick:X,disabled:Z,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:g(M,{className:`h-4 w-4`})})]}),v(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto`,children:[$&&!Z&&g(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),l===`picker`&&v(y,{children:[j&&g(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:j}),g(B,{onSelect:te,onClose:X,pendingAddonId:Q})]}),l===`config`&&d&&g(V,{addonId:d,configSchema:L??null,onSave:K,onBack:()=>u(`picker`)}),l===`broker`&&w&&g(z,{kind:w,onResolved:e=>{q(e)},onBack:()=>u(`picker`)}),l===`discovery`&&b&&g(H,{providerId:b,onImport:ne,onSkip:J})]}),Z&&v(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm`,children:[g(P,{className:`h-6 w-6 animate-spin text-primary`}),g(`p`,{className:`text-xs font-medium text-foreground`,children:a(`integrations.creating`,{defaultValue:`Creating integration…`})}),g(`p`,{className:`text-[10px] text-foreground-subtle`,children:a(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})})]})]})]})}function G({integration:e,expanded:t,onToggleExpand:n}){return v(`div`,{className:`flex items-center gap-2.5`,children:[g(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:g(t?O:D,{className:`h-3.5 w-3.5`})}),g(x,{type:e.addonId,size:`sm`}),v(`div`,{className:`flex min-w-0 flex-col`,children:[g(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),g(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ee(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>g(G,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>g(I,{status:e.status})}]}h();function te(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var K=`expand`;function q(){let{t}=N(),n=T(),r=b(),[a]=k(),[s,u]=f(!1),p=d(()=>u(!0),[]),h=d(()=>u(!1),[]);R([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),R([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:_,isLoading:w,refetch:E}=e(void 0),{data:D,isLoading:O,refetch:A}=o({}),M=m(()=>D??[],[D]),P=m(()=>_??[],[_]),I=m(()=>{let e=new Map;for(let t of M)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[M]),L=m(()=>{let e=new Map;for(let t of l(M)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[M]),z=m(()=>P.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:te(e),deviceCount:L.get(e.addonId)??0})),[P,L]),B=a.get(K),V=d(e=>{let t=new URLSearchParams(window.location.search);t.get(K)===e?t.delete(K):t.set(K,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),H=d(e=>n(`/integrations/${e.id}`),[n]),U=d(e=>I.get(e)??null,[I]),G=d(e=>g(x,{type:e,size:`sm`}),[]),q=d(e=>n(`/devices/${String(e)}`),[n]),ne=d(e=>g(i,{context:`integration-detail`,devices:M,trpc:r.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:G,resolveParent:U,onNavigate:q}),[M,r.trpcClient,G,U,q]),J=d(e=>B===e.addonId,[B]),Y=m(()=>ee({isExpanded:J,onToggleExpand:V}),[J,V]),X=d(e=>`${e.name} ${e.addonId}`,[]),re=d(e=>e.addonId,[]),Z=d(()=>{E(),A()},[E,A]),Q=w||O,$=P.length>0;return v(F,{icon:j,title:t(`nav.integrations`,`Integrations`),actions:v(y,{children:[g(`button`,{onClick:Z,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:g(C,{className:c(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),v(`button`,{onClick:p,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[g(S,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&g(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>g(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&v(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[g(`p`,{className:`text-sm`,children:`No integrations configured.`}),g(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&g(i,{mode:`generic`,items:z,getKey:re,getSearchText:X,columns:Y,onRowClick:H,isExpanded:J,renderExpanded:ne,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),g(W,{open:s,onClose:h})]})}export{q as IntegrationsPage};
|
|
1
|
+
import{$t as e,Bn as t,Gn as n,J as r,Ln as i,R as a,Un as o,an as s,ba as c,pn as l,z as u}from"./src-CqVYgpnN.js";import{F as d,G as f,R as p,U as m,X as h,b as g,o as _,x as v,y}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as b}from"./player-overlays-DzZKARlk.js";import{t as x}from"./ProviderIcon-DWSMqwcl.js";import{t as S}from"./plus-CbaF5MYw.js";import{t as C}from"./refresh-cw-CPqFoliO.js";import{F as w,H as T,I as E,M as D,P as O,W as k,f as A,g as j,i as M,t as N,x as P}from"./index-DuroU2aU.js";import{t as F}from"./AdminPage-CN6ZMhf0.js";import{t as I}from"./StatusBadge-CkYubfRG.js";import{t as L}from"./FormBuilder-BXQEmfaE.js";import{t as R}from"./useEventInvalidation-CqPABxEF.js";import{t as z}from"./BrokerStep-vbWWE4ss.js";h();function B({onSelect:e,onClose:n,pendingAddonId:r=null}){let{t:i}=N(),a=T(),{data:o,isLoading:s}=t();if(s)return g(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>g(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let c=r!==null;return v(`div`,{className:`space-y-2`,children:[(o??[]).map(t=>{let o=t.instanceMode===`unique`&&t.existingInstances.length>0,s=r===t.addonId,l=c;return v(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=t.existingInstances[0].id;n(),a(`/integrations/${e}`)}else e(t.addonId,t.instanceMode,t.discoveryMode,t.name,t.kind,t.brokerKind)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[t.iconUrl?g(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${t.color}15`},children:g(`img`,{src:t.iconUrl,alt:``,className:`h-5 w-5`})}):g(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${t.color}15`},children:g(`span`,{className:`text-sm`,style:{color:t.color},children:`◉`})}),v(`div`,{className:`flex-1 min-w-0`,children:[g(`p`,{className:`text-xs font-semibold text-foreground`,children:t.name}),t.description&&g(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:t.description})]}),s?g(P,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?v(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[g(A,{className:`h-3 w-3`}),i(`integrations.manage`)]}):g(D,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},t.addonId)}),(o??[]).length===0&&g(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}function V({addonId:e,configSchema:t,onSave:r,onBack:i}){let{t:a}=N(),[o,s]=f(``),[c,l]=f({}),[u,d]=f(null),p=n({onSuccess:e=>d(e),onError:e=>d({success:!1,error:String(e)})});return v(`div`,{className:`space-y-4`,children:[v(`div`,{children:[g(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:a(`integrations.integrationName`)}),g(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&g(L,{schema:t,values:c,onChange:l}),u&&g(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${u.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:u.success?a(`integrations.connectionSuccess`):`${a(`integrations.errorPrefix`)} ${u.error}`}),v(`div`,{className:`flex items-center justify-between pt-2`,children:[g(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.back`)}),v(`div`,{className:`flex items-center gap-2`,children:[g(`button`,{onClick:()=>p.mutate({addonId:e,settings:c}),disabled:p.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:p.isPending?a(`integrations.testing`):a(`integrations.testConnection`)}),g(`button`,{onClick:()=>r({name:o,config:c}),disabled:!o.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:a(`integrations.forward`)})]})]})]})}h();function H({providerId:e,onImport:t,onSkip:n}){let{t:r}=N(),[i,a]=f(new Set),o=s(),c=o.data,l=o.isPending||!o.data&&!o.isError;p(()=>{e&&(o.isPending||o.data||o.mutate({addonId:e}))},[e,o]);function u(e){a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(l)return v(`div`,{className:`flex flex-col items-center py-12`,children:[g(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),g(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=c??[];return v(`div`,{className:`space-y-4`,children:[g(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&g(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=i.has(t);return v(`button`,{onClick:()=>u(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[g(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&g(w,{className:`h-3 w-3 text-primary-foreground`})}),g(E,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),g(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),v(`div`,{className:`flex items-center justify-between pt-2`,children:[g(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&v(`button`,{onClick:()=>t(Array.from(i)),disabled:i.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,i.size,`)`]})]})]})}h();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}function W({open:t,onClose:n}){let{t:a}=N(),o=T(),c=_(),[l,u]=f(`picker`),[d,h]=f(null),[b,x]=f(null),[S,C]=f(`manual`),[w,E]=f(null),[D,O]=f(``),[k,A]=f(null),[j,F]=f(null),{data:I}=r({addonId:d??``,nodeId:`hub`},{enabled:d!=null}),L=m(()=>I?U(I):null,[I]),R=i({onSuccess:()=>c.invalidateQueries({queryKey:[[`integrations`]]})}),W=s(),G=W.data;p(()=>{l!==`discovery`||!b||!d||W.isPending||W.data||W.mutate({addonId:d})},[l,b,d,W]);let ee=e({onSuccess:()=>c.invalidateQueries({queryKey:[[`deviceManager`]]})});async function te(e,t,r,i,a,s){if(!R.isPending){if(h(e),C(r),O(i),F(null),a===`device-adoption`){if(!s){F(`Addon '${e}' declares device-adoption but no brokerKind in its manifest`);return}E(s),u(`broker`);return}if(t===`unique`){try{let t=await R.mutateAsync({addonId:e,name:i,settings:{}});n(),Y(),o(`/integrations/${t.id}`)}catch{}return}u(`config`)}}async function K(e){if(d)try{let t=await R.mutateAsync({addonId:d,name:e.name,settings:e.config});x(t.id),S===`auto`||S===`both`?u(`discovery`):J(t.id)}catch{}}async function q(e){if(d)try{let t=await R.mutateAsync({addonId:d,name:D,settings:{brokerId:e}});A(t.id),x(t.id),J(t.id)}catch{}}async function ne(e){if(d){for(let t of e){let e=G?.find(e=>e.stableId===t);e&&await ee.mutateAsync({addonId:d,candidate:e,...k===null?{}:{integrationId:k}})}J()}}function J(e){let t=e??b??d;n(),Y(),t&&o(`/integrations/${t}`)}function Y(){u(`picker`),h(null),x(null),C(`manual`),E(null),O(``),A(null),F(null)}function X(){n(),Y()}if(!t)return null;let re={picker:a(`integrations.newIntegration`),config:a(`integrations.configureIntegration`),discovery:a(`integrations.importDevices`),broker:a(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Z=R.isPending,Q=Z?d:null,$=R.error;return v(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[g(`div`,{className:`absolute inset-0 bg-black/60`,onClick:Z?void 0:X}),v(`div`,{className:`relative z-10 w-full max-w-lg max-h-[85vh] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[v(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[g(`h2`,{className:`text-sm font-semibold text-foreground`,children:re[l]}),g(`button`,{onClick:X,disabled:Z,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:g(M,{className:`h-4 w-4`})})]}),v(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto`,children:[$&&!Z&&g(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),l===`picker`&&v(y,{children:[j&&g(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:j}),g(B,{onSelect:te,onClose:X,pendingAddonId:Q})]}),l===`config`&&d&&g(V,{addonId:d,configSchema:L??null,onSave:K,onBack:()=>u(`picker`)}),l===`broker`&&w&&g(z,{kind:w,onResolved:e=>{q(e)},onBack:()=>u(`picker`)}),l===`discovery`&&b&&g(H,{providerId:b,onImport:ne,onSkip:J})]}),Z&&v(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm`,children:[g(P,{className:`h-6 w-6 animate-spin text-primary`}),g(`p`,{className:`text-xs font-medium text-foreground`,children:a(`integrations.creating`,{defaultValue:`Creating integration…`})}),g(`p`,{className:`text-[10px] text-foreground-subtle`,children:a(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})})]})]})]})}function G({integration:e,expanded:t,onToggleExpand:n}){return v(`div`,{className:`flex items-center gap-2.5`,children:[g(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:g(t?O:D,{className:`h-3.5 w-3.5`})}),g(x,{type:e.addonId,size:`sm`}),v(`div`,{className:`flex min-w-0 flex-col`,children:[g(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),g(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ee(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>g(G,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>g(I,{status:e.status})}]}h();function te(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var K=`expand`;function q(){let{t:e}=N(),t=T(),n=b(),[r]=k(),[i,s]=f(!1),p=d(()=>s(!0),[]),h=d(()=>s(!1),[]);R([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),R([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:_,isLoading:w,refetch:E}=o(void 0),{data:D,isLoading:O,refetch:A}=l({}),M=m(()=>D??[],[D]),P=m(()=>_??[],[_]),I=m(()=>{let e=new Map;for(let t of M)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[M]),L=m(()=>{let e=new Map;for(let t of u(M)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[M]),z=m(()=>P.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:te(e),deviceCount:L.get(e.addonId)??0})),[P,L]),B=r.get(K),V=d(e=>{let t=new URLSearchParams(window.location.search);t.get(K)===e?t.delete(K):t.set(K,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),H=d(e=>t(`/integrations/${e.id}`),[t]),U=d(e=>I.get(e)??null,[I]),G=d(e=>g(x,{type:e,size:`sm`}),[]),q=d(e=>t(`/devices/${String(e)}`),[t]),ne=d(e=>g(a,{context:`integration-detail`,devices:M,trpc:n.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:G,resolveParent:U,onNavigate:q}),[M,n.trpcClient,G,U,q]),J=d(e=>B===e.addonId,[B]),Y=m(()=>ee({isExpanded:J,onToggleExpand:V}),[J,V]),X=d(e=>`${e.name} ${e.addonId}`,[]),re=d(e=>e.addonId,[]),Z=d(()=>{E(),A()},[E,A]),Q=w||O,$=P.length>0;return v(F,{icon:j,title:e(`nav.integrations`,`Integrations`),actions:v(y,{children:[g(`button`,{onClick:Z,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:g(C,{className:c(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),v(`button`,{onClick:p,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[g(S,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&g(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>g(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&v(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[g(`p`,{className:`text-sm`,children:`No integrations configured.`}),g(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&g(a,{mode:`generic`,items:z,getKey:re,getSearchText:X,columns:Y,onRowClick:H,isExpanded:J,renderExpanded:ne,searchPlaceholder:e(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:e(`integrations.empty`,{defaultValue:`No integrations found.`})}),g(W,{open:i,onClose:h})]})}export{q as IntegrationsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as e}from"./src-
|
|
1
|
+
import{g as e}from"./src-CqVYgpnN.js";import{b as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{t as n}from"./AdminPage-CN6ZMhf0.js";function r(){return t(n,{children:t(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:t(e,{limit:500,maxHeight:`max-h-[calc(100vh-250px)]`,showScope:!0,showFilters:!0})})})}export{r as LogsPage};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/browser-BHo8W_uH.js","assets/rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-zJ_50EbN.js";import"./src-C5tvi19O.js";import{G as n,R as r,U as i,X as a,a as o,b as s,t as c,x as l,y as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as d}from"./player-overlays-DzZKARlk.js";import{t as f}from"./circle-check-big-is5GRKO9.js";import{t as p}from"./copy-tH10joFB.js";import{t as m}from"./key-round-eCBxaKT6.js";import{t as h}from"./pencil-xW8n5CLs.js";import{C as g,T as _,b as v,j as y,l as b,r as x,s as S,x as C,y as w}from"./index-CAfPe666.js";import{t as T}from"./AdminPage-CN6ZMhf0.js";a();function E({value:i,size:a=192}){let[o,c]=n(null),[u,d]=n(null);if(r(()=>{let n=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(n)return;let t=e.create;if(typeof t!=`function`){d(`qrcode.create() unavailable in installed version`);return}try{let e=t(i,{errorCorrectionLevel:`M`});n||c(e)}catch(e){n||d(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1])).catch(()=>{n||d(`qrcode library not installed`)}),()=>{n=!0}},[i]),u)return s(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:a,height:a},children:`QR rendering unavailable — use the secret below.`});if(!o)return s(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:a,height:a},children:`Generating…`});let f=o.modules.size,p=a/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)o.modules.data[e*f+t]&&m.push(s(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return l(`svg`,{width:a,height:a,viewBox:`0 0 ${a} ${a}`,className:`text-black`,children:[s(`rect`,{x:0,y:0,width:a,height:a,fill:`white`}),m]})}a();var D={view:{icon:_,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:h,cls:`bg-primary/15 text-primary`},delete:{icon:S,cls:`bg-danger/15 text-danger`}};function O(){let{user:e,logout:t}=x();if(!e)return s(T,{children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,r=e.scopes??[];return l(T,{children:[l(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[s(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),l(`div`,{className:`flex-1 min-w-0`,children:[s(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),l(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,l(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&l(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[s(g,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),l(`div`,{children:[s(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),s(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),s(k,{}),s(j,{username:e.username}),r.length>0&&l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[l(`div`,{className:`px-4 py-2 border-b border-border`,children:[s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),l(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[s(`div`,{children:`Type`}),s(`div`,{children:`Target`}),s(`div`,{children:`Access`})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map((e,t)=>l(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[s(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),s(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?e.targets.join(`, `):e.target}),s(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:r,cls:i}=D[t];return l(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?i:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[s(r,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[s(w,{className:`h-3 w-3`}),`Sign out`]})})]})}function k(){let e=d(),[t,r]=n(``),[i,a]=n(``),[o,u]=n(``),[p,h]=n(null),g=c({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{h({kind:`success`,msg:`Password updated.`}),r(``),a(``),u(``)},onError:e=>{h({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),_=i.length>0&&o.length>0&&i!==o,b=i.length>0&&i.length<8,x=t.length>=1&&i.length>=8&&i===o;return l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[l(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[s(m,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),l(`div`,{className:`p-4 space-y-3`,children:[s(A,{label:`Current password`,value:t,onChange:r,autoComplete:`current-password`}),s(A,{label:`New password`,value:i,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),s(A,{label:`Confirm new password`,value:o,onChange:u,autoComplete:`new-password`}),(_||b)&&s(`div`,{className:`text-[11px] text-danger`,children:_?`Passwords do not match.`:`New password must be at least 8 characters.`}),p&&l(`div`,{className:`text-[11px] flex items-center gap-1 ${p.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[p.kind===`success`?s(f,{className:`h-3 w-3`}):s(y,{className:`h-3 w-3`}),p.msg]}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:()=>{h(null),g.mutate({currentPassword:t,newPassword:i})},disabled:!x||g.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[g.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(v,{className:`h-3 w-3`}),`Update password`]})})]})]})}function A({label:e,value:t,onChange:n,autoComplete:r,hint:i}){return l(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),s(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),i&&s(`div`,{className:`text-[10px] text-foreground-subtle`,children:i})]})}function j({username:e}){let t=d(),a=o({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),m=a.data,[h,g]=n(null),[_,v]=n(``),[x,S]=n(null),[w,T]=n(!1),D=c({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{g({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),S(null)},onError:e=>S(e instanceof Error?e.message:`Setup failed`)}),O=c({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{g(null),v(``),S(null),a.refetch()},onError:e=>S(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),k=c({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{S(null),a.refetch()},onError:e=>S(e instanceof Error?e.message:`Disable failed`)});r(()=>{if(!w)return;let e=setTimeout(()=>T(!1),1500);return()=>clearTimeout(e)},[w]);let A=i(()=>a.isLoading?`loading`:h?`setup_in_progress`:m?.enabled?`enrolled`:`not_enrolled`,[a.isLoading,m?.enabled,h]);return l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[l(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[s(b,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),l(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&l(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(C,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&l(u,{children:[s(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:()=>{S(null),D.mutate()},disabled:D.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[D.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(b,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&h&&l(u,{children:[l(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,s(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),l(`div`,{className:`flex flex-col items-center gap-3`,children:[s(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:s(E,{value:h.otpauthUrl,size:180})}),l(`div`,{className:`w-full`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),l(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[s(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:h.secret}),l(`button`,{onClick:()=>{h&&navigator.clipboard.writeText(h.secret).then(()=>T(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[w?s(f,{className:`h-3 w-3 text-emerald-500`}):s(p,{className:`h-3 w-3`}),w?`Copied`:`Copy`]})]})]})]}),l(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),s(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:_,onChange:e=>v(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),x&&l(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[s(y,{className:`h-3 w-3`}),x]}),l(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>{g(null),S(null),v(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),l(`button`,{onClick:()=>{S(null),O.mutate({code:_})},disabled:O.isPending||_.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[O.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(f,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&m&&l(u,{children:[l(`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:[s(f,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),l(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),l(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,m.confirmedAt?new Date(m.confirmedAt).toLocaleString():`—`]})]})]}),x&&l(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[s(y,{className:`h-3 w-3`}),x]}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:()=>{S(null),k.mutate()},disabled:k.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:[k.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(b,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}export{O as MyAccessPage};
|
|
2
|
+
import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-zJ_50EbN.js";import"./src-CqVYgpnN.js";import{G as n,R as r,U as i,X as a,a as o,b as s,t as c,x as l,y as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as d}from"./player-overlays-DzZKARlk.js";import{t as f}from"./circle-check-big-BDdzTa9p.js";import{t as p}from"./copy-BtC330Ic.js";import{t as m}from"./key-round-C1aQCNHE.js";import{t as h}from"./pencil-Dw6owGVy.js";import{C as g,T as _,b as v,j as y,l as b,r as x,s as S,x as C,y as w}from"./index-DuroU2aU.js";import{t as T}from"./AdminPage-CN6ZMhf0.js";a();function E({value:i,size:a=192}){let[o,c]=n(null),[u,d]=n(null);if(r(()=>{let n=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(n)return;let t=e.create;if(typeof t!=`function`){d(`qrcode.create() unavailable in installed version`);return}try{let e=t(i,{errorCorrectionLevel:`M`});n||c(e)}catch(e){n||d(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1])).catch(()=>{n||d(`qrcode library not installed`)}),()=>{n=!0}},[i]),u)return s(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:a,height:a},children:`QR rendering unavailable — use the secret below.`});if(!o)return s(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:a,height:a},children:`Generating…`});let f=o.modules.size,p=a/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)o.modules.data[e*f+t]&&m.push(s(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return l(`svg`,{width:a,height:a,viewBox:`0 0 ${a} ${a}`,className:`text-black`,children:[s(`rect`,{x:0,y:0,width:a,height:a,fill:`white`}),m]})}a();var D={view:{icon:_,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:h,cls:`bg-primary/15 text-primary`},delete:{icon:S,cls:`bg-danger/15 text-danger`}};function O(){let{user:e,logout:t}=x();if(!e)return s(T,{children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,r=e.scopes??[];return l(T,{children:[l(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[s(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),l(`div`,{className:`flex-1 min-w-0`,children:[s(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),l(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,l(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&l(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[s(g,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),l(`div`,{children:[s(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),s(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),s(k,{}),s(j,{username:e.username}),r.length>0&&l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[l(`div`,{className:`px-4 py-2 border-b border-border`,children:[s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),l(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[s(`div`,{children:`Type`}),s(`div`,{children:`Target`}),s(`div`,{children:`Access`})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map((e,t)=>l(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[s(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),s(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?e.targets.join(`, `):e.target}),s(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:r,cls:i}=D[t];return l(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?i:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[s(r,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[s(w,{className:`h-3 w-3`}),`Sign out`]})})]})}function k(){let e=d(),[t,r]=n(``),[i,a]=n(``),[o,u]=n(``),[p,h]=n(null),g=c({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{h({kind:`success`,msg:`Password updated.`}),r(``),a(``),u(``)},onError:e=>{h({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),_=i.length>0&&o.length>0&&i!==o,b=i.length>0&&i.length<8,x=t.length>=1&&i.length>=8&&i===o;return l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[l(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[s(m,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),l(`div`,{className:`p-4 space-y-3`,children:[s(A,{label:`Current password`,value:t,onChange:r,autoComplete:`current-password`}),s(A,{label:`New password`,value:i,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),s(A,{label:`Confirm new password`,value:o,onChange:u,autoComplete:`new-password`}),(_||b)&&s(`div`,{className:`text-[11px] text-danger`,children:_?`Passwords do not match.`:`New password must be at least 8 characters.`}),p&&l(`div`,{className:`text-[11px] flex items-center gap-1 ${p.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[p.kind===`success`?s(f,{className:`h-3 w-3`}):s(y,{className:`h-3 w-3`}),p.msg]}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:()=>{h(null),g.mutate({currentPassword:t,newPassword:i})},disabled:!x||g.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[g.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(v,{className:`h-3 w-3`}),`Update password`]})})]})]})}function A({label:e,value:t,onChange:n,autoComplete:r,hint:i}){return l(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),s(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),i&&s(`div`,{className:`text-[10px] text-foreground-subtle`,children:i})]})}function j({username:e}){let t=d(),a=o({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),m=a.data,[h,g]=n(null),[_,v]=n(``),[x,S]=n(null),[w,T]=n(!1),D=c({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{g({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),S(null)},onError:e=>S(e instanceof Error?e.message:`Setup failed`)}),O=c({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{g(null),v(``),S(null),a.refetch()},onError:e=>S(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),k=c({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{S(null),a.refetch()},onError:e=>S(e instanceof Error?e.message:`Disable failed`)});r(()=>{if(!w)return;let e=setTimeout(()=>T(!1),1500);return()=>clearTimeout(e)},[w]);let A=i(()=>a.isLoading?`loading`:h?`setup_in_progress`:m?.enabled?`enrolled`:`not_enrolled`,[a.isLoading,m?.enabled,h]);return l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[l(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[s(b,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),l(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&l(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(C,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&l(u,{children:[s(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:()=>{S(null),D.mutate()},disabled:D.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[D.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(b,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&h&&l(u,{children:[l(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,s(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),l(`div`,{className:`flex flex-col items-center gap-3`,children:[s(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:s(E,{value:h.otpauthUrl,size:180})}),l(`div`,{className:`w-full`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),l(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[s(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:h.secret}),l(`button`,{onClick:()=>{h&&navigator.clipboard.writeText(h.secret).then(()=>T(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[w?s(f,{className:`h-3 w-3 text-emerald-500`}):s(p,{className:`h-3 w-3`}),w?`Copied`:`Copy`]})]})]})]}),l(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),s(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:_,onChange:e=>v(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),x&&l(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[s(y,{className:`h-3 w-3`}),x]}),l(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>{g(null),S(null),v(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),l(`button`,{onClick:()=>{S(null),O.mutate({code:_})},disabled:O.isPending||_.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[O.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(f,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&m&&l(u,{children:[l(`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:[s(f,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),l(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),l(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,m.confirmedAt?new Date(m.confirmedAt).toLocaleString():`—`]})]})]}),x&&l(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[s(y,{className:`h-3 w-3`}),x]}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:()=>{S(null),k.mutate()},disabled:k.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:[k.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(b,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}export{O as MyAccessPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$n as e,Fi as t,Ji as n,Qn as r,Xn as i,Zn as a,ar as o,at as s,cr as c,da as l,er as u,fa as d,ir as f,lr as p,nr as m,pa as h,pi as g,rr as _,st as v,tr as y,ur as b}from"./src-CqVYgpnN.js";import{F as x,G as S,R as ee,U as C,X as w,b as T,o as E,x as D,y as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as k}from"./player-overlays-DzZKARlk.js";import{a as A,s as j}from"./src-CrhOk7JL.js";import{n as M,t as te}from"./rotate-ccw-BJL6I3ju.js";import{t as N}from"./copy-BtC330Ic.js";import{n as ne,t as P}from"./AddonCollectionPage-CPQWZfC0.js";import{t as re}from"./refresh-cw-CPqFoliO.js";import{t as F}from"./server-BgZ85UtO.js";import{t as ie}from"./sparkles-Dj3mm_rJ.js";import{t as ae}from"./square-D-dTwz52.js";import{t as oe}from"./wifi-Do23YMj8.js";import{B as I,D as L,F as se,_ as R,b as ce,i as le,o as z,w as B,x as V,y as ue}from"./index-DuroU2aU.js";import{t as H}from"./AdminPage-CN6ZMhf0.js";import{t as U}from"./AdminTabs-Ddi8-SQJ.js";var de=I(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),fe=I(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),W=I(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);w();var G=5e3,pe={connected:!1,endpoint:null};function me(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function he(){let e=E(),t=v({capName:`network-access`},{refetchInterval:G}),n=s(void 0,{refetchInterval:G}),r=C(()=>me(n.data??[]),[n.data]),i=C(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[a,o]=S(null),[c,l]=S({}),u=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),o(null),l(e=>{let t=n?.addonId;if(t===void 0||!(t in e))return e;let r={...e};return delete r[t],r})},d=(e,t)=>{o(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);l(e=>({...e,[n]:r}))},f=p({onSuccess:u,onError:d}),m=b({onSuccess:u,onError:d});return T(P,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:B,itemIcon:B,capability:`network-access`,installButtonLabel:`Add tunnel`,items:i,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>T(ge,{addonId:e.addonId}),itemError:e=>c[e.addonId]??null,renderPrimaryAction:e=>T(_e,{addonId:e.addonId,busyId:a,onStart:e=>{o(e),f.mutate({addonId:e})},onStop:e=>{o(e),m.mutate({addonId:e})}})})}function K(e){let{data:t}=c({addonId:e},{refetchInterval:G,retry:!1}),n=t?j.safeParse(t):null;return n?.success?n.data:pe}function ge({addonId:e}){let t=K(e);return D(O,{children:[T(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&D(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[T(L,{className:`h-3 w-3`}),t.endpoint.url]})]})}function _e({addonId:e,busyId:t,onStart:n,onStop:r}){let i=K(e),a=t===e;return i.connected?D(h,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?T(V,{className:`h-3 w-3 animate-spin`}):T(ae,{className:`h-3 w-3`}),`Stop`]}):D(h,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?T(V,{className:`h-3 w-3 animate-spin`}):T(ne,{className:`h-3 w-3`}),`Start`]})}w();var q=3e4;function ve(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function ye(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function be(){let e=v({capName:`turn-provider`},{refetchInterval:q}),t=s(void 0,{refetchInterval:q}),n=g(),r=n.data??[],i=C(()=>ve(t.data??[]),[t.data]);return T(P,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:R,itemIcon:R,capability:`turn-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,i]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>T(xe,{addonId:e.addonId,enabled:e.isActive}),trailing:D(l,{children:[D(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[D(`div`,{children:[T(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),T(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),T(h,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),T(`div`,{className:`p-4`,children:r.length===0?T(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):T(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return D(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&D(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&D(`span`,{children:[T(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,T(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&D(`span`,{children:[T(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,T(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),T(`ul`,{className:`divide-y divide-border`,children:n.map(e=>T(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function xe({addonId:e,enabled:t}){let n=g({addonId:e},{enabled:t,retry:!1}),r=C(()=>ye(n.data??[]),[n.data]);return!t||r.length===0?null:D(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[D(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),T(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>T(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}w();var Se={lan:R,wifi:oe,docker:M,vpn:ce,loopback:F,other:F},Ce={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},we=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Te(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=C(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=C(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return we.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?T(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):T(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>D(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[D(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[T(Se[t]??F,{className:`h-3.5 w-3.5 text-foreground-subtle`}),T(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Ce[t]??t}),D(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),T(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return D(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[T(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&T(se,{className:`h-3 w-3`})}),D(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[D(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[T(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),T(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&T(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&T(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&D(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[T(z,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),D(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}w();var J={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function Ee(){let t=E(),n=k(),o=r(void 0,{refetchInterval:3e4}),s=i(void 0),c=u({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),d=e({onSuccess:e=>{g(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),f=C(()=>o.data?.interfaces??[],[o.data]),p=a({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[m,g]=S([]),[_,v]=S(!1);ee(()=>{!_&&s.data&&(g(s.data.addresses),v(!0))},[s.data,_]);let y=s.data?.addresses??[],b=C(()=>{if(m.length!==y.length)return!0;let e=[...m].toSorted(),t=[...y].toSorted();return e.some((e,n)=>e!==t[n])},[m,y]),x=()=>{c.mutate({addresses:[...m]})},w=()=>{g(y)},O=()=>{g([])},A=()=>{o.refetch(),p.refetch(),s.refetch()},j=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},M=p.data?.endpoints??[];return D(H,{children:[D(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[T(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),D(`div`,{className:`flex items-center gap-2 shrink-0`,children:[D(h,{size:`sm`,variant:`secondary`,onClick:A,disabled:o.isLoading,children:[T(re,{className:`h-3 w-3 ${o.isLoading?`animate-spin`:``}`}),`Refresh`]}),T(h,{size:`sm`,variant:`secondary`,onClick:j,children:`Probe race`})]})]}),D(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[D(l,{children:[D(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[D(`div`,{children:[T(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),T(`div`,{className:`text-xs text-foreground-subtle`,children:m.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${m.length} pinned`})]}),D(`div`,{className:`flex items-center gap-1`,children:[D(h,{size:`sm`,variant:`secondary`,onClick:()=>d.mutate(void 0),disabled:d.isPending||c.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[T(ie,{className:`h-3 w-3`}),d.isPending?`Detecting…`:`Best match`]}),D(h,{size:`sm`,variant:`secondary`,onClick:O,disabled:m.length===0||c.isPending,children:[T(te,{className:`h-3 w-3`}),`Clear`]}),b&&T(h,{size:`sm`,variant:`secondary`,onClick:w,disabled:c.isPending,children:`Discard`}),D(h,{size:`sm`,variant:`primary`,onClick:x,disabled:!b||c.isPending,children:[T(fe,{className:`h-3 w-3`}),c.isPending?`Saving…`:`Save`]})]})]}),T(`div`,{className:`p-4`,children:T(Te,{mode:`multiple`,interfaces:f,value:m,onChange:g,disabled:c.isPending,emptyMessage:o.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),D(l,{children:[D(`div`,{className:`px-4 py-3 border-b border-border`,children:[T(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),T(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),T(`div`,{className:`p-4`,children:M.length===0?T(`div`,{className:`text-xs text-foreground-subtle italic`,children:p.isLoading?`Loading…`:`No endpoints available.`}):T(`ul`,{className:`space-y-1 text-xs`,children:M.map(e=>D(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[T(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),T(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&T(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&D(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[T(z,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),T(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),D(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}w();var De={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,Oe=3e4,ke={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Ae(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function je(){let e=v({capName:`mesh-network`},{refetchInterval:Y}),t=s(void 0,{refetchInterval:Y}),n=C(()=>Ae(t.data??[]),[t.data]);return T(P,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:M,itemIcon:R,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>T(Z,{addonId:e.addonId}),renderPrimaryAction:e=>T(Me,{addonId:e.addonId}),renderExpandedPanel:e=>T(Ne,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=y({addonId:e},{refetchInterval:Y,retry:!1}),r=t?A.safeParse(t):null;return{status:r?.success?r.data:ke,isLoading:n}}function Z({addonId:e}){let{status:t}=X(e);return D(O,{children:[T(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Me({addonId:e}){let t=E(),[n,r]=S(!1),[i,a]=S(null),s=k(),{status:c}=X(e),l=x(()=>{t.invalidateQueries({queryKey:[[`meshNetwork`]]})},[t]),u=o(),d=m({onSuccess:l}),p=f({onSuccess:l}),g=x(async()=>{r(!0);let t={cancelled:!1};a(t);try{let n=await u.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Re(2e3),!t.cancelled);){let t=await s.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?A.safeParse(t):null;if(n?.success&&n.data.joined){l();break}if(Date.now()-r>6e5)break}}finally{r(!1),a(null)}},[e,l,u,s]),_=x(()=>{i&&(i.cancelled=!0),r(!1),a(null)},[i]);return T(O,{children:c.joined?D(O,{children:[D(h,{size:`sm`,variant:`secondary`,disabled:d.isPending,onClick:()=>d.mutate({addonId:e}),children:[d.isPending?T(V,{className:`h-3 w-3 animate-spin`}):T(ue,{className:`h-3 w-3`}),`Disconnect`]}),D(h,{size:`sm`,variant:`ghost`,disabled:p.isPending,onClick:()=>p.mutate({addonId:e}),children:[p.isPending?T(V,{className:`h-3 w-3 animate-spin`}):T(W,{className:`h-3 w-3`}),`Log out`]})]}):n?D(h,{size:`sm`,variant:`ghost`,onClick:_,children:[T(le,{className:`h-3 w-3 mr-1`}),` Cancel`]}):D(O,{children:[D(h,{size:`sm`,variant:`primary`,onClick:()=>void g(),children:[T(de,{className:`h-3 w-3`}),`Connect`]}),D(h,{size:`sm`,variant:`ghost`,disabled:p.isPending,onClick:()=>p.mutate({addonId:e}),children:[p.isPending?T(V,{className:`h-3 w-3 animate-spin`}):T(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Ne({addonId:e}){let{status:n}=X(e),r=_({addonId:e},{refetchInterval:Oe,retry:!1});return D(`div`,{className:`rounded-lg border border-border bg-surface`,children:[D(`div`,{className:`p-4 space-y-4`,children:[n.error&&T(t,{message:n.error}),T(Pe,{status:n}),n.endpoints.length>0&&D(`div`,{className:`space-y-1.5`,children:[T(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),n.endpoints.map(e=>D(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${De[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?T(B,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),D(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[T(L,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),T(`div`,{className:`border-t border-border`,children:T(Ie,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function Pe({status:e}){return T(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Fe(e.keyExpiry):`—`}].map(e=>D(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[T(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),T(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Fe(e){let t=e-Date.now();if(t<0)return`Expired ${$(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Ie({peers:e,loading:t}){let r=C(()=>e.map(e=>({...e,_id:e.id})),[e]),i=x(e=>{e&&navigator.clipboard?.writeText(e)},[]),a=C(()=>[{key:`hostname`,header:`Hostname`,render:e=>D(`div`,{className:`flex flex-col`,children:[D(`div`,{className:`flex items-center gap-1.5`,children:[T(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&T(d,{variant:`info`,children:`self`}),e.exitNodeOption&&T(d,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&T(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?D(`div`,{className:`flex items-center gap-1`,children:[T(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),T(`button`,{onClick:()=>i(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:T(N,{className:`h-3 w-3 text-foreground-subtle`})})]}):T(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?D(`div`,{className:`flex items-center gap-1`,children:[T(`span`,{className:`font-mono text-xs`,children:t}),T(`button`,{onClick:()=>i(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:T(N,{className:`h-3 w-3 text-foreground-subtle`})})]}):T(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>D(`div`,{className:`flex items-center gap-1.5`,children:[T(d,{variant:Le(e.connection),children:e.connection}),e.relay&&T(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?T(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):T(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>D(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>T(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[i]);return t&&e.length===0?D(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[T(V,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?T(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):T(`div`,{className:`p-4`,children:T(n,{columns:a,rows:r,rowKey:e=>e._id,minWidthPx:820})})}function Le(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function $(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Re(e){return new Promise(t=>setTimeout(t,e))}function ze(){return T(`div`,{className:`flex flex-col p-4`,children:T(U,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:F,content:T(Ee,{})},{id:`remote-access`,label:`Remote Access`,icon:B,content:T(he,{})},{id:`mesh`,label:`Mesh Networks`,icon:M,content:T(je,{})},{id:`turn`,label:`TURN Servers`,icon:R,content:T(be,{})}]})})}export{ze as NetworkPage};
|
package/dist/assets/{NodeAddonsSettingsPanel-B4ru8rzf.js → NodeAddonsSettingsPanel-9HVgS_gw.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Et as e,Or as t,X as n,Y as r,at as i,qt as a}from"./src-CqVYgpnN.js";import{F as o,G as s,O as c,R as l,U as u,V as d,W as f,X as p,b as m,i as h,o as g,t as _,x as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as y}from"./player-overlays-DzZKARlk.js";import{E as b}from"./src-CrhOk7JL.js";import{n as ee,r as x,t as te}from"./SchemaTabBar-ByWwzBUZ.js";import{t as S}from"./FormBuilder-BXQEmfaE.js";p();var C=c(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:a,disabled:s},c){let p=x({schema:t,serverValues:n,onImmediateSave:o(t=>r(e,t),[e,r]),onDeferredSave:o(()=>{},[])});d(c,()=>({flush:()=>{let e={};for(let t of p.pendingKeys)e[t]=p.values[t];return p.handleDiscard(p.pendingKeys),e},discard:()=>p.resetAll()}),[p]);let h=p.pendingKeys,g=h.join(`|`),_=u(()=>h.map(e=>`${e}=${JSON.stringify(p.values[e])}`).join(`,`),[h,p.values]),v=f(i);l(()=>{v.current=i},[i]),l(()=>{let t={};for(let e of h)t[e]=p.values[e];v.current({addonId:e,pendingKeys:h,pendingValues:t})},[e,g,_]);let y=u(()=>{if(a)return(t,n,r)=>a(e,t,n,r)},[e,a]);return m(S,{schema:t,values:p.values,onChange:p.handleChange,disabled:s,onAction:y})});p();function w(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>w(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function T(e,t){return{...e,fields:e.fields.map(e=>w(e,t))}}function ne(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>T(e,t))},values:t}}function E({nodeId:c,addonIds:l,level:d,deviceId:p,capability:x,sectionIds:S,sectionTab:C,extraTabs:w,title:T,description:E}){let D=g(),O=y().trpcClient,k=n(),A=r(),j=t(),M=a(),N=e(),P=!!(w&&w.length>0),[F,ie]=s(null);if(d===`device`&&!p)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let I=c??`hub`,L=h({queries:l.map(e=>({queryKey:[[`addonSettings`,d===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:I,deviceId:p??null,cap:x??null}],queryFn:async()=>d===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:I,...x?{cap:x}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:p,nodeId:I})}}))}),R=L.some(e=>e.isLoading),z=L.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),B=u(()=>{let e=new Set;for(let t of L){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[z+`::`+L.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),V=u(()=>new Map((w??[]).map(e=>[e.id,e])),[w]),H=u(()=>{if(!P)return[];let e=[...new Set([...B,...(w??[]).map(e=>e.id)])],t=e=>{let t=V.get(e);if(t?.order!==void 0)return t.order;let n=b[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[P,B,w,V]),ae=u(()=>{let e=new Map;for(let t of B){let n=b[t];e.set(t,n?.label??t.charAt(0).toUpperCase()+t.slice(1))}for(let t of w??[])e.set(t.id,t.label);return e},[B,w]),U=P?F&&H.includes(F)?F:H[0]??null:null,W=U!==null&&V.has(U),G=P?U&&!W?U:void 0:C,{data:K}=i(void 0),oe=u(()=>{let e=new Map;for(let t of K??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[K]),q=u(()=>{let e=S?new Set(S):null,t=[];for(let n of L){if(!n.data||n.data.result===null)continue;let{schema:r,values:i}=ne(n.data.result),a=r.sections.filter(t=>e?e.has(t.id):!0);if(a.length===0)continue;let o={...n.data.result,sections:n.data.result.sections.filter(t=>e?e.has(t.id):!0)},s={...r,sections:a};t.push({addonId:n.data.addonId,schemaWithValues:o,schema:s,serverValues:i})}return t},[z,S]),[J,se]=s(new Map),ce=o(e=>{se(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=f(new Map),le=o(e=>t=>{t?Y.current.set(e,t):Y.current.delete(e)},[]),X=o(async(e,t)=>{d===`global`?await k.mutateAsync({addonId:e,nodeId:I,patch:t}):await A.mutateAsync({addonId:e,deviceId:p,nodeId:I,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,I,d,p,D]),ue=o(async(e,t,n,r)=>{let i=I;try{switch(t){case`reprobe-engine`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-hwaccel`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await N.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,N,I,D,O]),de=o((e,t)=>{X(e,t)},[X]),Z=_({mutationFn:async()=>{let e=[];for(let t of q){let n=J.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(d===`global`?await k.mutateAsync({addonId:e,nodeId:I,patch:t}):await A.mutateAsync({addonId:e,deviceId:p,nodeId:I,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)Y.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),fe=o(()=>{for(let e of Y.current.values())e.discard()},[]),pe=u(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),me=u(()=>{let e=new Map;for(let t of q){let n=J.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[q,J]);if(R)return m(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=U&&W?V.get(U):void 0;if(!P&&q.length===0)return v(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,l.length>0?`[${l.join(`, `)}]`:`the current selection`,` `,`expose `,d,`-level settings on this node.`]});let $=Z.isPending;return v(`div`,{className:`space-y-4`,children:[(T||E)&&v(`div`,{className:`border-b border-border pb-2`,children:[T&&m(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&m(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),P&&m(te,{tabs:H.map(e=>({id:e,label:ae.get(e)??e})),activeId:U,onChange:ie,pendingByTab:me}),Z.isError&&v(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Z.error?.message??Z.error)]}),Q?Q.content:(()=>{let e=G?q.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===G).length,0):0,t=G!==null&&e<=1,n=q.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>G?(e.tab??`general`)===G:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i});return n.length===0?m(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):m(re,{entries:n,paneStates:J,displayNames:oe,disabled:$,setPaneRef:le,onPaneStateChange:ce,onImmediateSave:de,onAction:ue,inline:P||!!C})})(),!R&&m(ee,{pendingCount:pe,onSave:()=>Z.mutate(),onDiscard:fe,saving:$})]})}function re({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:c,inline:d}){let f=u(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[p,h]=s(f[0]?.addonId??``);l(()=>{f.length!==0&&(f.find(e=>e.addonId===p)||h(f[0].addonId))},[f,p]);let g=f.find(e=>e.addonId===p)??f[0];if(!g)return null;let _=u(()=>c?(e,t,n,r)=>c(e,t,n,r):void 0,[c]),y=e=>m(C,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:_,disabled:r},e.addonId);return f.length===1||d?m(`div`,{className:`flex flex-col gap-4`,children:f.map(y)}):v(`div`,{className:`flex flex-col gap-3`,children:[m(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:f.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===g.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return v(`button`,{type:`button`,onClick:()=>h(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&m(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),m(`div`,{className:`space-y-2`,children:f.map(e=>m(`div`,{style:e.addonId===g.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{E as t};
|