@camstack/addon-admin-ui 1.2.87 → 1.2.89
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-ClWHdX1D.js → AddLocationWizard-CYxP8ICv.js} +1 -1
- package/dist/assets/{AddonCollectionPage-CCm-n_-k.js → AddonCollectionPage-Czx0Rf1Y.js} +1 -1
- package/dist/assets/Addons-X9onTcjm.js +1 -0
- package/dist/assets/{AdminTabs-Ya-WafVI.js → AdminTabs-BFe9RXxD.js} +1 -1
- package/dist/assets/{AiProfiles-G8ohU36w.js → AiProfiles-DS7dcd3T.js} +1 -1
- package/dist/assets/{BrokerForm-Cja9Cp03.js → BrokerForm-RC8ZQms1.js} +1 -1
- package/dist/assets/{Build-BUwpX-xq.js → Build-DYatQ35G.js} +3 -3
- package/dist/assets/{Capabilities-CzxtAA9j.js → Capabilities-CdAjZZ5u.js} +1 -1
- package/dist/assets/CapabilityBadges-mGyqruK0.js +1 -0
- package/dist/assets/{Cluster-C3WY-Tom.js → Cluster-CIp91ynz.js} +1 -1
- package/dist/assets/{Data-DP4AzN8W.js → Data-CmrUXYoi.js} +1 -1
- package/dist/assets/{DetectionIntelligence-Dm0ZECMd.js → DetectionIntelligence-D80ddmLz.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-aUgWgamW.js → DeviceAggregateSection-CmXH0Z_0.js} +1 -1
- package/dist/assets/DeviceDetail-CY4j2jrm.js +2 -0
- package/dist/assets/{Devices-BVC0zPbb.js → Devices-C8E4qBqs.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-BwM49mOX.js → EmbedPlayerPage-nLTLNYPt.js} +1 -1
- package/dist/assets/Events-vfLnBqsv.js +1 -0
- package/dist/assets/{FormBuilder-CgtfU1VA.js → FormBuilder-CgXBJs1A.js} +1 -1
- package/dist/assets/{Identity-C2TOQEJq.js → Identity-C-6ig3ru.js} +1 -1
- package/dist/assets/{IntegrationDetail-3MgmsFlC.js → IntegrationDetail-CRrZPmmb.js} +1 -1
- package/dist/assets/{Integrations-AQCeGcvO.js → Integrations-CXvB3xLb.js} +1 -1
- package/dist/assets/{Integrations-CE6i7W5X.js → Integrations-CnscVQeA.js} +1 -1
- package/dist/assets/{Logs-C1e0vFcW.js → Logs-Ptalp9Ap.js} +1 -1
- package/dist/assets/{MotionZonesSettings-AZZ7Vac3.js → MotionZonesSettings-GG2onGsd.js} +1 -1
- package/dist/assets/{MyAccess-oAGUI1mc.js → MyAccess-C9X6mSCC.js} +1 -1
- package/dist/assets/Network-DdfJzcEJ.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-B1Cyvbcv.js → NodeAddonsSettingsPanel-BYXH3-BP.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CkoeBXMD.js → NodeInferenceDevices-CJBU3t4h.js} +1 -1
- package/dist/assets/Notifications-DVfJp0YC.js +1 -0
- package/dist/assets/Pipeline-YNTCsnOx.js +1 -0
- package/dist/assets/{Plates-TsHHlZDi.js → Plates-DzZx4BPp.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BxIYztmC.js → PrivacyMaskSettings-DlD5nHl0.js} +1 -1
- package/dist/assets/{ProviderIcon-BBJFc8mr.js → ProviderIcon-DaauzRy3.js} +1 -1
- package/dist/assets/Recordings-i9RDqe2o.js +1 -0
- package/dist/assets/{ScanNetworkModal-BQIyP8Qh.js → ScanNetworkModal-DwKJwpIs.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-ZOTjS5Og.js → SceneMonitorEditor-H2Z_9riR.js} +1 -1
- package/dist/assets/{Scenes-DDemjEwK.js → Scenes-DiJCcvjG.js} +1 -1
- package/dist/assets/{Settings-BJydhDaq.js → Settings-Clokst-N.js} +1 -1
- package/dist/assets/{Showroom-Di_0Md3V.js → Showroom-1ViARhyC.js} +1 -1
- package/dist/assets/{Terminal-CIo6IaUC.js → Terminal-mLwOsOgP.js} +5 -3
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C91lgIiF.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BTd_JgZ5.js} +1 -1
- package/dist/assets/{bell-ring-0co0yj8J.js → bell-ring-BPrVhIE4.js} +1 -1
- package/dist/assets/{boxes-CKu64rZy.js → boxes-89UouT8T.js} +1 -1
- package/dist/assets/{build-cluster-graph-BWmowgwv.js → build-cluster-graph-Cbb1I-jq.js} +1 -1
- package/dist/assets/circle-check-big-D9ynSOrO.js +1 -0
- package/dist/assets/{circle-x-_qOKhKMV.js → circle-x-Bsgek5uU.js} +1 -1
- package/dist/assets/clock-BvQlDL5a.js +1 -0
- package/dist/assets/{copy-CE9Wp04n.js → copy-BtDJ2xWI.js} +1 -1
- package/dist/assets/{debounced-invalidate-CfnWx62K.js → debounced-invalidate-CfMppTLk.js} +1 -1
- package/dist/assets/{dist-CcR-lswN.js → dist-BJIJtrLw.js} +1 -1
- package/dist/assets/dist-BVCWYzWk.js +349 -0
- package/dist/assets/{download-mZ1OYsqe.js → download-DrTCm0Zn.js} +1 -1
- package/dist/assets/{face-bbox-Y-X13UcQ.js → face-bbox-bnTYLJ2C.js} +1 -1
- package/dist/assets/{hard-drive-D6z2TCCh.js → hard-drive-D6wUZdNf.js} +1 -1
- package/dist/assets/{hostInit-Dr0x9nND.js → hostInit-ZAX9mo8c.js} +1 -1
- package/dist/assets/index-D7fwM52p.js +4 -0
- package/dist/assets/{key-round-CegkgxO2.js → key-round-PssF2mH1.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-e3818a6f.js → mf-entry-bootstrap-0-12df8905.js} +2 -2
- package/dist/assets/{pencil-CCyVFYXA.js → pencil-DDE9Ut_f.js} +1 -1
- package/dist/assets/play-VJTjxs_g.js +1 -0
- package/dist/assets/{player-overlays-BCuyatPp.js → player-overlays-DsK1iDkv.js} +1 -1
- package/dist/assets/plus-CKJhtG9S.js +1 -0
- package/dist/assets/power-DIX0P9O_.js +1 -0
- package/dist/assets/{radio-DvHOeyw2.js → radio-Cgg_wmnh.js} +1 -1
- package/dist/assets/{refresh-cw-CvqUZLg2.js → refresh-cw-B06QF6BP.js} +1 -1
- package/dist/assets/remoteEntry-GRBshePF.js +1 -0
- package/dist/assets/rotate-ccw-CHuGPAms.js +1 -0
- package/dist/assets/rotate-cw-B7IVurj2.js +1 -0
- package/dist/assets/search-B9qXKjRG.js +1 -0
- package/dist/assets/{send-DRex-kWD.js → send-CCB7-Bua.js} +1 -1
- package/dist/assets/{server-DSkdRu09.js → server-qRR4BT4Q.js} +1 -1
- package/dist/assets/shield-Dhep2Fkd.js +1 -0
- package/dist/assets/square-CfRn6ZFd.js +1 -0
- package/dist/assets/{square-check-big-BbcMGYFH.js → square-check-big-CKJTPtsS.js} +1 -1
- package/dist/assets/src-DY4vbC0g.js +349 -0
- package/dist/assets/src-DnZ6ZcH0.js +67 -0
- package/dist/assets/{star-BT_oUHvU.js → star-Cfry0hZj.js} +1 -1
- package/dist/assets/{undo-2-D7QQycip.js → undo-2-CP7k5Csp.js} +1 -1
- package/dist/assets/{upload-D5h4xcC3.js → upload-DKCLx4MR.js} +1 -1
- package/dist/assets/{use-scenes-feed-DcfGN5ks.js → use-scenes-feed-Cf4dSlYi.js} +1 -1
- package/dist/assets/useEventInvalidation-CINdEbPJ.js +1 -0
- package/dist/assets/{video--sYC3ys-.js → video-LCt0QHTC.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DBBIBnMR.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D-HrWJSs.js} +2 -2
- package/dist/assets/{wifi-Wacew_4h.js → wifi-BHTVIRt4.js} +1 -1
- package/dist/assets/{zap-CrjJ004P.js → zap-BXQ1pVxK.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +137 -10
- package/package.json +1 -1
- package/dist/assets/Addons-CNQu3idA.js +0 -1
- package/dist/assets/CapabilityBadges-BVAXgYuj.js +0 -1
- package/dist/assets/DeviceDetail-BoKKas-k.js +0 -2
- package/dist/assets/Events-X4Lovw2K.js +0 -1
- package/dist/assets/Network-BLaNQAjB.js +0 -1
- package/dist/assets/Notifications-D2ro0AxS.js +0 -1
- package/dist/assets/Pipeline-BvxT4V4g.js +0 -1
- package/dist/assets/Recordings-CYIFqOWF.js +0 -1
- package/dist/assets/circle-check-big-BPF9MiQz.js +0 -1
- package/dist/assets/clock-DoS4fxPG.js +0 -1
- package/dist/assets/dist-D6EYui_h.js +0 -349
- package/dist/assets/index-CoX6Kh_l.js +0 -4
- package/dist/assets/play-DCoy3WUZ.js +0 -1
- package/dist/assets/plus-D-xjJ9wd.js +0 -1
- package/dist/assets/power-ChfUL_0y.js +0 -1
- package/dist/assets/remoteEntry-C4Nbi34r.js +0 -1
- package/dist/assets/rotate-ccw-CwngHzIQ.js +0 -1
- package/dist/assets/rotate-cw-pPP0LEo9.js +0 -1
- package/dist/assets/search-Cvti5PjG.js +0 -1
- package/dist/assets/square-B3jj9vzX.js +0 -1
- package/dist/assets/src-BmCjCFGO.js +0 -67
- package/dist/assets/src-D8hsVOc6.js +0 -349
- package/dist/assets/useEventInvalidation-DCo7fWEj.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as c}from"./player-overlays-BCuyatPp.js";import{Br as l,Cs as u,Dn as d,Ds as f,En as p,Es as m,Lt as h,S as g,Ss as _,Ts as v,_s as y,bs as b,et as x,f as S,gs as C,hs as w,ln as T,ms as ee,p as E,ps as D,vs as O,ws as k,x as A,xs as te,ys as j}from"./src-BmCjCFGO.js";import{c as M,d as N,l as P,u as F}from"./src-D8hsVOc6.js";import{t as I}from"./circle-check-big-BPF9MiQz.js";import{t as L}from"./copy-CE9Wp04n.js";import{t as ne}from"./key-round-CegkgxO2.js";import{t as re}from"./pencil-CCyVFYXA.js";import{t as ie}from"./plus-D-xjJ9wd.js";import{C as R,E as z,I as ae,K as B,R as oe,f as V,i as H,k as se,r as U,s as W,u as G,w as ce,z as le}from"./index-CoX6Kh_l.js";import{t as K}from"./AdminPage-CCD07UMs.js";import{t as ue}from"./AdminTabs-Ya-WafVI.js";import{t as de}from"./AddonCollectionPage-CCm-n_-k.js";import{t as fe}from"./addon-display-names-DvSEQty-.js";var pe=B(`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`}]]),me=B(`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`}]]),he=B(`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`}]]),ge=B(`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`}]]),_e=B(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),ve=B(`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`}]]);e();function ye({userId:e,username:n,onClose:r}){let o=a(),c=T(),l=y({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=C({onSuccess:()=>{d(),r()}}),p=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(G,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(H,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[p===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(R,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&t(`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:[s(ce,{className:`h-4 w-4 mt-0.5 shrink-0`}),t(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),s(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&u&&t(i,{children:[t(`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(I,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),t(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),t(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),s(`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.`}),t(`div`,{className:`flex justify-end gap-2`,children:[s(h,{onClick:r,variant:`secondary`,children:`Close`}),t(`button`,{onClick:async()=>{await c({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? 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?s(R,{className:`h-3 w-3 animate-spin`}):s(H,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function q({icon:e,label:n,count:r,all:i,total:a}){return t(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[s(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:n}),s(`span`,{className:r===0?`text-foreground-subtle`:`font-medium text-foreground`,children:r===0?`none`:i?`all ${a}`:`${r} of ${a}`})]})}function be({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),u=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:d}=l({}),f=d?.length??0;if(a!==null)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:t(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[s(_e,{className:`h-3 w-3 shrink-0`}),a]})});if(u.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(R,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(u.isError||!u.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let p=u.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:p.isAdmin?t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):t(i,{children:[s(q,{icon:se,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(q,{icon:re,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(q,{icon:W,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:f}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,p.system.length===0?`none`:p.system.join(`, `),p.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,p.capabilities.map(e=>e.name).join(`, `)]}),p.addons.length>0&&t(i,{children:[` · Addons: `,p.addons.map(e=>e.name).join(`, `)]})]}),p.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function xe(e){let t=F(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function Se(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:P({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Ce({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:l}){let u=n(()=>xe(e.scopes??[]),[e.scopes]),[d,f]=o(u),[p,m]=o(u.mode===`advanced`),h=n(()=>Se(d),[d]),g=!e.isAdmin&&d.mode===`role`&&d.roleId===null,_=n(()=>e.isAdmin?null:d.mode===`role`&&d.roleId===null?`Pick what this user can do to see the result.`:E(h),[e.isAdmin,d.mode,d.roleId,h]),v=e=>f({...d,...e});return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 pt-[calc(1rem+env(safe-area-inset-top))] pb-[calc(1rem+env(safe-area-inset-bottom))]`,children:t(`div`,{className:`flex max-h-full w-full max-w-2xl flex-col rounded-lg border border-border bg-surface shadow-xl`,children:[t(`div`,{className:`flex shrink-0 items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Access — `,e.username]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),s(`button`,{onClick:r,className:`shrink-0 text-foreground-subtle hover:text-foreground`,title:`Close`,children:s(H,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[g&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(_e,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`No access.`}),` `,t(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),s(`div`,{className:`space-y-1.5`,children:M.map(e=>{let n=d.mode===`role`&&d.roleId===e.id;return t(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[s(`input`,{type:`radio`,name:`access-role`,checked:n,onChange:()=>v({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),t(`span`,{className:`min-w-0`,children:[s(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),s(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),t(`button`,{type:`button`,onClick:()=>{if(!p){f({...d,mode:`advanced`,advancedScopes:h}),m(!0);return}m(!1),f(xe(d.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[s(p?oe:ae,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),p&&t(`div`,{className:`rounded-lg border border-border p-2`,children:[s(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),s(S,{value:d.advancedScopes,onChange:e=>v({mode:`advanced`,advancedScopes:e}),clampToParent:l,emptyHint:t(i,{children:[`No grants.`,` `,s(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),d.mode===`role`&&t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),s(A,{value:d.selector,onChange:e=>v({selector:e}),includeLinked:d.includeLinked,onIncludeLinkedChange:e=>v({includeLinked:e}),clampToDeviceIds:null})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:d.mode===`role`?`3 · Result`:`2 · Result`}),s(be,{scopes:h,isAdmin:e.isAdmin,invalidReason:_})]})]}),t(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:r,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>a([...h]),disabled:c||_!==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:c?s(R,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();function we(){let e=a(),{user:n}=U(),[r,i]=o(!1),[c,l]=o(``),[u,d]=o(``),[p,h]=o(!1),[g,v]=o(null),{data:y,isLoading:b,isError:S}=te(),C=T(),E=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),D=ee({onSuccess:()=>{E(),i(!1),l(``),d(``),h(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),O=w({onSuccess:E}),k=f({onSuccess:E}),A=_({onSuccess:E}),j=m({onSuccess:()=>{E(),N(null)}}),[M,N]=o(null),[P,F]=o(null),I=y??[];async function L(e){await C({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`})&&O.mutate({id:e.id})}async function ne(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 C({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&A.mutate({id:e.id,newPassword:t})}}function re(e,t){t!==e.isAdmin&&k.mutate({id:e.id,isAdmin:t})}function z(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(K,{children:[s(`div`,{className:`flex items-center justify-end`,children:t(`button`,{onClick:()=>i(!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:[s(ie,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:[s(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),s(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:s(H,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`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`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`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`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`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:[s(`input`,{type:`checkbox`,checked:p,onChange:e=>h(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),g&&s(`p`,{className:`text-[10px] text-danger`,children:g}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>D.mutate({username:c,password:u,isAdmin:p}),disabled:D.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:D.isPending?`Creating...`:`Create`})]})]}),b&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),S&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!b&&!S&&I.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>O.isPending&&O.variables?.id===e.id||k.isPending&&k.variables?.id===e.id||A.isPending&&A.variables?.id===e.id;return s(x,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:n=>t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:n.isAdmin,onChange:e=>re(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>N(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(V,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Te,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:z(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>F(r),disabled:i,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:[s(G,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>ne(r),disabled:i,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:[s(he,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>L(r),disabled:i,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:[i?s(R,{className:`h-3 w-3 animate-spin`}):s(W,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:I,rowKey:e=>e.id,minWidthPx:560})})(),P&&s(ye,{userId:P.id,username:P.username,onClose:()=>F(null)}),M&&s(Ee,{user:M,onClose:()=>N(null),onSubmit:e=>j.mutate({userId:M.id,scopes:e}),submitting:j.isPending})]})}function Te({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=F(e);return n===null?t(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):t(`span`,{className:`text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:N(n.roleId).label}),` ·`,` `,g(n.selector)]})}function Ee(e){let{user:t}=U(),n=t?.isAdmin===!0;return s(Ce,{...e,callerScopes:n?null:t?.scopes??[]})}e();var De=`bg-primary/10 text-primary`,Oe=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ke(e){return e?e===`*`?`*`:e.join(`, `):``}function Ae(){let e=a(),r=T(),{data:i,isLoading:c}=O(),{data:l}=te(),d=n(()=>i??[],[i]),f=n(()=>l??[],[l]),p=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[h,g]=o(!1),[_,y]=o(null),b=u({onSuccess:p}),x=D({onSuccess:({token:e,record:t})=>{m(),g(!1),y({token:e,label:t.name})}}),S=v({onSuccess:m}),C=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&b.mutate({id:e})},w=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&S.mutate({id:e})};return t(K,{children:[t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`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.`}),t(`button`,{onClick:()=>g(!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:f.length===0,title:f.length===0?`Create a user first`:`Issue a scoped token`,children:[s(V,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(je,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[f.length===0&&s(Ne,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),f.map(e=>s(Fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{w(e,t)},revokePending:S.isPending,revokeId:S.variables?.id},e.id))]}),d.length>0&&s(je,{title:`Legacy API keys`,subtitle:`${d.length} pre-existing — revoke only`,children:s(Pe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:d.map(e=>{let n=!!e.isAdmin,r=b.isPending&&b.variables?.id===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${n?De:Oe}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ke(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{C(e.id,e.label)},disabled:r,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:[r?s(R,{className:`h-3 w-3 animate-spin`}):s(W,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Me,{}),h&&s(Ie,{users:f.map(e=>({id:e.id,username:e.username})),onClose:()=>g(!1),onSubmit:e=>x.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:x.isPending}),_&&s(Le,{token:_.token,label:_.label,onClose:()=>y(null)})]})}function je({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Me(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ne({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Pe({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`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))})}),s(`tbody`,{children:n})]})})}function Fe({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=b({userId:e}),l=o??[];return c||l.length===0?null:t(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),s(Pe,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:l.map(e=>{let n=i&&a===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,n)=>t(`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`?`[${g(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>r(e.id,e.name),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`,children:[n?s(R,{className:`h-3 w-3 animate-spin`}):s(W,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Ie({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=U(),c=a?.isAdmin===!0?null:a?.scopes??[],[l,u]=o(e[0]?.id??``),[d,f]=o(``),[p,m]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[h,g]=o(``),_=E(p),v=l!==``&&d.trim().length>0&&p.length>0&&_===null&&!i;return t(Re,{title:`Create scoped token`,onClose:n,children:[t(`div`,{className:`space-y-3`,children:[s(Y,{label:`On behalf of user`,children:s(`select`,{value:l,onChange:e=>u(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=>s(`option`,{value:e.id,children:e.username},e.id))})}),s(Y,{label:`Name`,children:s(`input`,{value:d,onChange:e=>f(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`})}),t(Y,{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:[s(S,{value:p,onChange:m,clampToParent:c}),_&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:_})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:h,onChange:e=>g(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`})})]}),t(ze,{children:[s(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`button`,{onClick:()=>{let e=parseInt(h,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!v,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:[i?s(R,{className:`h-3.5 w-3.5 animate-spin`}):s(V,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function Le({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(Re,{title:`Token: ${n}`,onClose:r,children:[t(`div`,{className:`space-y-3`,children:[s(`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.`}),s(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),t(ze,{children:[t(`button`,{onClick:()=>{c()},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:[i?s(le,{className:`h-3.5 w-3.5 text-primary`}):s(L,{className:`h-3.5 w-3.5`}),i?`Copied`:`Copy`]}),s(`button`,{onClick:r,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function Re({title:e,onClose:n,children:r}){return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),s(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:s(H,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function ze({children:e}){return s(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:n,children:r}){return t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),r,n&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:n})]})}e();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function Be(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 s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function He({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Ue({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`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))})}),s(`tbody`,{children:n})]})})}function We(){let e=a(),r=T(),{data:i,isLoading:o}=j(),c=n(()=>i??[],[i]),l=k({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),u=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&l.mutate({id:e})};return t(K,{icon:ge,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[o&&s(Ve,{}),!o&&c.length===0&&s(He,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ue,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:c.map(e=>{let n=e.revokedAt!==null,r=(l.isPending?l.variables?.id:void 0)===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>s(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:Be(e)},t))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border`,children:n?t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):s(`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`})}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!n&&t(`button`,{onClick:()=>{u(e.id,e.integrationId)},disabled:r,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:[r?s(R,{className:`h-3 w-3 animate-spin`}):s(W,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}e();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ge(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:me,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`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:z,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:z,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:G,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:G,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:V,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Ke(){let e=d({capName:Q[0].capName},{refetchInterval:Z}),t=d({capName:Q[1].capName},{refetchInterval:Z}),r=p(void 0,{refetchInterval:Z}),i=n(()=>fe(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of r[e]??[])n.push({addonId:a.addonId,displayName:i.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,i]);return s(de,{title:$.title,subtitle:$.subtitle,pageIcon:V,itemIcon:V,capability:Q[0].capName,installButtonLabel:$.installLabel,items:a,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:s(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>s(qe,{addonId:e.addonId})})}function qe({addonId:e}){let n=Ge(e),r=n.icon;return t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-start gap-2.5`,children:[s(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),s(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),s(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>s(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[t(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[s(pe,{className:`h-3 w-3`}),`Setup steps`]}),s(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>s(`li`,{children:e},t))})]}),e===`local-auth`&&t(`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:[s(ce,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,s(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Je(){return s(`div`,{className:`flex flex-col p-4`,children:s(ue,{tabs:[{id:`users`,label:`Users`,icon:ve,content:s(we,{})},{id:`api-keys`,label:`Tokens`,icon:ne,content:s(Ae,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:ge,content:s(We,{})},{id:`authentication`,label:`Authentication`,icon:V,content:s(Ke,{})}]})})}export{Je as IdentityPage};
|
|
1
|
+
import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as c}from"./player-overlays-DsK1iDkv.js";import{As as l,Br as u,Cs as d,Dn as f,Ds as p,En as m,Es as h,Lt as g,Ms as _,Os as v,S as y,Ss as b,Ts as x,bs as S,et as C,f as w,js as T,ks as E,ln as D,p as O,vs as k,ws as A,x as j,xs as M,ys as ee}from"./src-DnZ6ZcH0.js";import{c as N,d as P,l as F,u as I}from"./src-DY4vbC0g.js";import{t as L}from"./circle-check-big-D9ynSOrO.js";import{t as te}from"./copy-BtDJ2xWI.js";import{t as ne}from"./key-round-PssF2mH1.js";import{t as re}from"./pencil-DDE9Ut_f.js";import{t as ie}from"./plus-CKJhtG9S.js";import{C as R,E as z,I as ae,K as B,R as oe,f as V,i as H,k as se,r as U,s as W,u as G,w as ce,z as le}from"./index-D7fwM52p.js";import{t as K}from"./AdminPage-CCD07UMs.js";import{t as ue}from"./AdminTabs-BFe9RXxD.js";import{t as de}from"./AddonCollectionPage-Czx0Rf1Y.js";import{t as fe}from"./addon-display-names-DvSEQty-.js";var pe=B(`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`}]]),me=B(`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`}]]),he=B(`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`}]]),ge=B(`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`}]]),_e=B(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),ve=B(`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`}]]);e();function ye({userId:e,username:n,onClose:r}){let o=a(),c=D(),l=b({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=M({onSuccess:()=>{d(),r()}}),p=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(G,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(H,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[p===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(R,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&t(`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:[s(ce,{className:`h-4 w-4 mt-0.5 shrink-0`}),t(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),s(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&u&&t(i,{children:[t(`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(L,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),t(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),t(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),s(`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.`}),t(`div`,{className:`flex justify-end gap-2`,children:[s(g,{onClick:r,variant:`secondary`,children:`Close`}),t(`button`,{onClick:async()=>{await c({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? 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?s(R,{className:`h-3 w-3 animate-spin`}):s(H,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function q({icon:e,label:n,count:r,all:i,total:a}){return t(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[s(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:n}),s(`span`,{className:r===0?`text-foreground-subtle`:`font-medium text-foreground`,children:r===0?`none`:i?`all ${a}`:`${r} of ${a}`})]})}function be({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:d}=u({}),f=d?.length??0;if(a!==null)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:t(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[s(_e,{className:`h-3 w-3 shrink-0`}),a]})});if(l.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(R,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let p=l.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:p.isAdmin?t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):t(i,{children:[s(q,{icon:se,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(q,{icon:re,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(q,{icon:W,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:f}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,p.system.length===0?`none`:p.system.join(`, `),p.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,p.capabilities.map(e=>e.name).join(`, `)]}),p.addons.length>0&&t(i,{children:[` · Addons: `,p.addons.map(e=>e.name).join(`, `)]})]}),p.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function xe(e){let t=I(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function Se(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:F({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Ce({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:l}){let u=n(()=>xe(e.scopes??[]),[e.scopes]),[d,f]=o(u),[p,m]=o(u.mode===`advanced`),h=n(()=>Se(d),[d]),g=!e.isAdmin&&d.mode===`role`&&d.roleId===null,_=n(()=>e.isAdmin?null:d.mode===`role`&&d.roleId===null?`Pick what this user can do to see the result.`:O(h),[e.isAdmin,d.mode,d.roleId,h]),v=e=>f({...d,...e});return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 pt-[calc(1rem+env(safe-area-inset-top))] pb-[calc(1rem+env(safe-area-inset-bottom))]`,children:t(`div`,{className:`flex max-h-full w-full max-w-2xl flex-col rounded-lg border border-border bg-surface shadow-xl`,children:[t(`div`,{className:`flex shrink-0 items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Access — `,e.username]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),s(`button`,{onClick:r,className:`shrink-0 text-foreground-subtle hover:text-foreground`,title:`Close`,children:s(H,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[g&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(_e,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`No access.`}),` `,t(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),s(`div`,{className:`space-y-1.5`,children:N.map(e=>{let n=d.mode===`role`&&d.roleId===e.id;return t(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[s(`input`,{type:`radio`,name:`access-role`,checked:n,onChange:()=>v({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),t(`span`,{className:`min-w-0`,children:[s(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),s(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),t(`button`,{type:`button`,onClick:()=>{if(!p){f({...d,mode:`advanced`,advancedScopes:h}),m(!0);return}m(!1),f(xe(d.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[s(p?oe:ae,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),p&&t(`div`,{className:`rounded-lg border border-border p-2`,children:[s(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),s(w,{value:d.advancedScopes,onChange:e=>v({mode:`advanced`,advancedScopes:e}),clampToParent:l,emptyHint:t(i,{children:[`No grants.`,` `,s(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),d.mode===`role`&&t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),s(j,{value:d.selector,onChange:e=>v({selector:e}),includeLinked:d.includeLinked,onIncludeLinkedChange:e=>v({includeLinked:e}),clampToDeviceIds:null})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:d.mode===`role`?`3 · Result`:`2 · Result`}),s(be,{scopes:h,isAdmin:e.isAdmin,invalidReason:_})]})]}),t(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:r,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>a([...h]),disabled:c||_!==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:c?s(R,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();function we(){let e=a(),{user:n}=U(),[r,i]=o(!1),[c,l]=o(``),[u,d]=o(``),[f,m]=o(!1),[g,v]=o(null),{data:y,isLoading:b,isError:x}=h(),w=D(),E=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),O=ee({onSuccess:()=>{E(),i(!1),l(``),d(``),m(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),k=S({onSuccess:E}),A=_({onSuccess:E}),j=p({onSuccess:E}),M=T({onSuccess:()=>{E(),P(null)}}),[N,P]=o(null),[F,I]=o(null),L=y??[];async function te(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`})&&k.mutate({id:e.id})}async function ne(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`})&&j.mutate({id:e.id,newPassword:t})}}function re(e,t){t!==e.isAdmin&&A.mutate({id:e.id,isAdmin:t})}function z(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(K,{children:[s(`div`,{className:`flex items-center justify-end`,children:t(`button`,{onClick:()=>i(!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:[s(ie,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:[s(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),s(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:s(H,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`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`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`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`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`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:[s(`input`,{type:`checkbox`,checked:f,onChange:e=>m(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),g&&s(`p`,{className:`text-[10px] text-danger`,children:g}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>O.mutate({username:c,password:u,isAdmin:f}),disabled:O.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:O.isPending?`Creating...`:`Create`})]})]}),b&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),x&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!b&&!x&&L.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>k.isPending&&k.variables?.id===e.id||A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id;return s(C,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:n=>t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:n.isAdmin,onChange:e=>re(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>P(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(V,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Te,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:z(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>I(r),disabled:i,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:[s(G,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>ne(r),disabled:i,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:[s(he,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>te(r),disabled:i,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:[i?s(R,{className:`h-3 w-3 animate-spin`}):s(W,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:L,rowKey:e=>e.id,minWidthPx:560})})(),F&&s(ye,{userId:F.id,username:F.username,onClose:()=>I(null)}),N&&s(Ee,{user:N,onClose:()=>P(null),onSubmit:e=>M.mutate({userId:N.id,scopes:e}),submitting:M.isPending})]})}function Te({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=I(e);return n===null?t(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):t(`span`,{className:`text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:P(n.roleId).label}),` ·`,` `,y(n.selector)]})}function Ee(e){let{user:t}=U(),n=t?.isAdmin===!0;return s(Ce,{...e,callerScopes:n?null:t?.scopes??[]})}e();var De=`bg-primary/10 text-primary`,Oe=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ke(e){return e?e===`*`?`*`:e.join(`, `):``}function Ae(){let e=a(),r=D(),{data:i,isLoading:c}=d(),{data:u}=h(),f=n(()=>i??[],[i]),p=n(()=>u??[],[u]),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),g=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[_,y]=o(!1),[b,x]=o(null),S=v({onSuccess:m}),C=k({onSuccess:({token:e,record:t})=>{g(),y(!1),x({token:e,label:t.name})}}),w=l({onSuccess:g}),T=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&S.mutate({id:e})},E=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&w.mutate({id:e})};return t(K,{children:[t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`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.`}),t(`button`,{onClick:()=>y(!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:p.length===0,title:p.length===0?`Create a user first`:`Issue a scoped token`,children:[s(V,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(je,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[p.length===0&&s(Ne,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),p.map(e=>s(Fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{E(e,t)},revokePending:w.isPending,revokeId:w.variables?.id},e.id))]}),f.length>0&&s(je,{title:`Legacy API keys`,subtitle:`${f.length} pre-existing — revoke only`,children:s(Pe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:f.map(e=>{let n=!!e.isAdmin,r=S.isPending&&S.variables?.id===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${n?De:Oe}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ke(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{T(e.id,e.label)},disabled:r,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:[r?s(R,{className:`h-3 w-3 animate-spin`}):s(W,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Me,{}),_&&s(Ie,{users:p.map(e=>({id:e.id,username:e.username})),onClose:()=>y(!1),onSubmit:e=>C.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:C.isPending}),b&&s(Le,{token:b.token,label:b.label,onClose:()=>x(null)})]})}function je({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Me(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ne({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Pe({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`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))})}),s(`tbody`,{children:n})]})})}function Fe({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=x({userId:e}),l=o??[];return c||l.length===0?null:t(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),s(Pe,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:l.map(e=>{let n=i&&a===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,n)=>t(`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`?`[${y(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>r(e.id,e.name),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`,children:[n?s(R,{className:`h-3 w-3 animate-spin`}):s(W,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Ie({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=U(),c=a?.isAdmin===!0?null:a?.scopes??[],[l,u]=o(e[0]?.id??``),[d,f]=o(``),[p,m]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[h,g]=o(``),_=O(p),v=l!==``&&d.trim().length>0&&p.length>0&&_===null&&!i;return t(Re,{title:`Create scoped token`,onClose:n,children:[t(`div`,{className:`space-y-3`,children:[s(Y,{label:`On behalf of user`,children:s(`select`,{value:l,onChange:e=>u(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=>s(`option`,{value:e.id,children:e.username},e.id))})}),s(Y,{label:`Name`,children:s(`input`,{value:d,onChange:e=>f(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`})}),t(Y,{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:[s(w,{value:p,onChange:m,clampToParent:c}),_&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:_})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:h,onChange:e=>g(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`})})]}),t(ze,{children:[s(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`button`,{onClick:()=>{let e=parseInt(h,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!v,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:[i?s(R,{className:`h-3.5 w-3.5 animate-spin`}):s(V,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function Le({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(Re,{title:`Token: ${n}`,onClose:r,children:[t(`div`,{className:`space-y-3`,children:[s(`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.`}),s(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),t(ze,{children:[t(`button`,{onClick:()=>{c()},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:[i?s(le,{className:`h-3.5 w-3.5 text-primary`}):s(te,{className:`h-3.5 w-3.5`}),i?`Copied`:`Copy`]}),s(`button`,{onClick:r,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function Re({title:e,onClose:n,children:r}){return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),s(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:s(H,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function ze({children:e}){return s(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:n,children:r}){return t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),r,n&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:n})]})}e();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function Be(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 s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function He({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Ue({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`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))})}),s(`tbody`,{children:n})]})})}function We(){let e=a(),r=D(),{data:i,isLoading:o}=A(),c=n(()=>i??[],[i]),l=E({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),u=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&l.mutate({id:e})};return t(K,{icon:ge,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[o&&s(Ve,{}),!o&&c.length===0&&s(He,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ue,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:c.map(e=>{let n=e.revokedAt!==null,r=(l.isPending?l.variables?.id:void 0)===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>s(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:Be(e)},t))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border`,children:n?t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):s(`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`})}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!n&&t(`button`,{onClick:()=>{u(e.id,e.integrationId)},disabled:r,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:[r?s(R,{className:`h-3 w-3 animate-spin`}):s(W,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}e();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ge(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:me,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`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:z,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:z,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:G,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:G,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:V,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Ke(){let e=f({capName:Q[0].capName},{refetchInterval:Z}),t=f({capName:Q[1].capName},{refetchInterval:Z}),r=m(void 0,{refetchInterval:Z}),i=n(()=>fe(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of r[e]??[])n.push({addonId:a.addonId,displayName:i.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,i]);return s(de,{title:$.title,subtitle:$.subtitle,pageIcon:V,itemIcon:V,capability:Q[0].capName,installButtonLabel:$.installLabel,items:a,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:s(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>s(qe,{addonId:e.addonId})})}function qe({addonId:e}){let n=Ge(e),r=n.icon;return t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-start gap-2.5`,children:[s(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),s(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),s(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>s(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[t(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[s(pe,{className:`h-3 w-3`}),`Setup steps`]}),s(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>s(`li`,{children:e},t))})]}),e===`local-auth`&&t(`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:[s(ce,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,s(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Je(){return s(`div`,{className:`flex flex-col p-4`,children:s(ue,{tabs:[{id:`users`,label:`Users`,icon:ve,content:s(we,{})},{id:`api-keys`,label:`Tokens`,icon:ne,content:s(Ae,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:ge,content:s(We,{})},{id:`authentication`,label:`Authentication`,icon:V,content:s(Ke,{})}]})})}export{Je as IdentityPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u}from"./player-overlays-BCuyatPp.js";import{$r as d,Br as f,Ci as p,Cr as m,Dr as h,Er as g,F as _,Fr as v,Gr as y,J as b,Mr as x,N as S,Sr as C,T as ee,Tr as w,Ur as T,Wt as E,_i as D,at as O,br as k,gi as A,gn as j,hi as M,jn as N,jr as P,jt as te,nt as ne,w as re,xi as F,xr as I,yi as L,yr as R}from"./src-BmCjCFGO.js";import{pt as z}from"./src-D8hsVOc6.js";import{t as B}from"./ProviderIcon-BBJFc8mr.js";import{t as ie}from"./circle-x-_qOKhKMV.js";import{t as V}from"./FormBuilder-CgtfU1VA.js";import{t as H}from"./plus-D-xjJ9wd.js";import{i as ae,n as U,r as W,t as oe}from"./ScanNetworkModal-BQIyP8Qh.js";import{t as se}from"./refresh-cw-CvqUZLg2.js";import{t as G}from"./rotate-cw-pPP0LEo9.js";import{t as ce}from"./wifi-Wacew_4h.js";import{A as le,C as K,I as q,J as ue,K as J,P as de,R as fe,W as pe,X as me,Y as he,i as ge,k as _e,m as ve,o as Y,p as ye,s as be,t as xe,z as Se}from"./index-CoX6Kh_l.js";var Ce=J(`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`}]]);n();function we(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...we(n.fields));return t}function Te(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...we(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;o(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function X(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(...X(n.fields));return t}function Z(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Q(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Q(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Ee(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function De({open:t,integrationId:n,addonId:a,onClose:u}){let{t:f}=xe(),p=o(),[m,h]=s({}),[_,y]=s(!1),[x,S]=s(null),[C,ee]=s(Ee),w=T({addonId:a},{enabled:t}),E=w.data?.deviceType??null,D=v({addonId:a,type:E??z.Camera},{enabled:t&&w.isSuccess&&E!==null}),O=D.data??null;l(()=>{t&&(h(O?Q(O.sections.flatMap(e=>e.fields)):{}),ee(Ee()),y(!1),S(null))},[t,n,O]);let k=i(()=>({...m,_probeRequestId:C}),[m,C]),A=g({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=d(),M=e(async(e,t)=>{y(!0);let n=await j.mutateAsync({addonId:a,type:E??z.Camera,key:e,value:t,formValues:k});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Z(e[i])&&!Z(a)&&(r[i]=a,t=!0);return t?r:e}),n},[j,a,k,E]),{testAllStatus:N,hasProbeFields:P,probeResults:te,handleTestAll:ne,clearProbeResult:re}=Te(O??{sections:[]},m,M);async function F(e){S(null);try{await A.mutateAsync({addonId:a,type:E??z.Camera,config:m,integrationId:n}),e?h(O?Q(O.sections.flatMap(e=>e.fields)):{}):u()}catch(e){S(e instanceof Error?e.message:String(e))}}if(!t)return null;let I=X((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>Z(m[e])),L=I.length===0,R=w.isLoading||E!==null&&D.isLoading,B=w.isError||w.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(ge,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?c(`div`,{className:`flex items-center justify-center py-8`,children:c(K,{className:`h-5 w-5 animate-spin text-primary`})}):B?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(Y,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(V,{schema:O,values:m,onChange:h,onTestField:M,probeResults:te,onClearProbe:re})}),!B&&!R&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>y(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[c(ve,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),c(fe,{className:`h-3.5 w-3.5 transition-transform ${_?`rotate-180`:``}`})]}),_&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(b,{addonId:a,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!B&&!R&&(x||I.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:x||`Required: ${I.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!B&&P&&r(`button`,{type:`button`,onClick:ne,disabled:N===`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:[N===`testing`?c(K,{className:`h-3.5 w-3.5 animate-spin`}):c(ce,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>F(!0),disabled:B||!L||A.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:f(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>F(!1),disabled:B||!L||A.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:A.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Oe=1500;function ke({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=xe(),o=R(),s=(C({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Oe:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?c(K,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(Y,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(ie,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(de,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Ae(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var $=`devices`,je={id:$,label:`Devices`,isDefault:!0},Me=2e4,Ne=100;function Pe({addonId:n,integrationId:i,onClose:a}){let{t:o}=xe(),[u,d]=s(new Set),[f,p]=s(new Set),[h,g]=s(new Map),[v,y]=s(null),{data:b}=D(),x=(b??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[C,ee]=s(!0),T=k({addonId:n,integrationId:i}).data?.filters,E=T&&T.length>0?T:[je],[O,A]=s(E.find(e=>e.isDefault)?.id??(E.some(e=>e.id===$)?$:E[0].id)),j=O!==$,M=m(),N=I({addonId:n,integrationId:i,page:1,pageSize:Me,filter:O}),P=N.refetch,te=M.mutate,ne=e(()=>{te({addonId:n,integrationId:i},{onSettled:()=>{P()}})},[te,n,i,P]),F=t(null);l(()=>{let e=`${n}::${i}`;F.current===e||N.isLoading||(F.current=e,(N.data?.candidates.length??0)===0&&ne())},[n,i,N.isLoading,N.data,ne]);let L=M.isPending,R=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,z=typeof M.data?.lastError==`string`&&M.data.lastError.length>0?M.data.lastError:null,B=N.data?.candidates??[],ie=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,V=w(),[H,ae]=s(null),U=e(e=>{e.alreadyAdopted||d(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),W=e(e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),oe=e((e,t)=>{g(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})},[]),se=e(e=>{let t={};for(let n of e){let e=h.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[h]),ce=e(async()=>{y(null);let e=[...u];if(e.length!==0)try{let t=se(e),{jobId:r}=await V.mutateAsync({addonId:n,integrationId:i,filter:O,childNativeIds:e,...t?{perCandidate:t}:{},...x?{importLocations:C}:{}});ae(r),d(new Set),g(new Map)}catch(e){y(e instanceof Error?e.message:String(e))}},[u,se,V,n,i,O,x,C]),le=t(null),q=e(()=>{H===null||le.current===H||(le.current=H,P())},[H,P]),ue=e(e=>{A(e),d(new Set),p(new Set),g(new Map),y(null)},[]),J=u.size;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:o(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:o(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[x&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:C,onChange:e=>ee(e.target.checked),className:`accent-primary`}),o(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(ge,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(R??ie??z)&&B.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:o(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:R??ie??z})]})]})}),E.length>1&&c(Fe,{filters:E,activeFilter:O,onSelect:ue}),c(`div`,{className:`flex-1 min-h-0`,children:c(re,{mode:`generic`,items:B,pageSize:Ne,getKey:e=>e.childNativeId,getSearchText:Ae,getFilterType:e=>e.type,filterOptions:S(),filterLabel:o(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:N.isLoading||L&&B.length===0,searchPlaceholder:o(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??ie??z)&&B.length===0?``:o(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:ne,disabled:L,title:o(`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:[c(G,{className:`h-3.5 w-3.5 ${L?`animate-spin`:``}`}),o(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:o(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ie,{candidate:e,expandable:!j,expanded:f.has(e.childNativeId),onToggleExpand:()=>W(e.childNativeId),adoptedLabel:o(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:o(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=_(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(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=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>U(e),disabled:e.alreadyAdopted,"aria-label":u.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${u.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:u.has(e.childNativeId)&&c(Se,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!j&&f.has(e.childNativeId),renderExpanded:j?void 0:e=>c(Le,{candidate:e,hiddenChildIds:h.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>oe(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:u.has(e.childNativeId)?`bg-primary/5`:``})})]}),v&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:v})]})}),H!==null&&c(ke,{addonId:n,integrationId:i,jobId:H,onFinished:q}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:ce,disabled:J===0||V.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:[V.isPending&&c(K,{className:`h-3.5 w-3.5 animate-spin`}),o(`integrations.addSelected`,{defaultValue:`Add selected`}),J>0?` (${J})`:``]})]})]})]})]})}function Fe({filters:e,activeFilter:t,onSelect:n}){return c(`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 c(`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 Ie({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[c(n?fe:q,{className:`h-3.5 w-3.5`}),o]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Le({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:c(i?le:_e,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Re(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Re(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function ze(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Re(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Be(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ve({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=xe(),m=o(),{data:h,isLoading:g}=L({id:e},{enabled:s===`account`||s===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=j({addonId:t,nodeId:`hub`},{enabled:s===`account`}),b=i(()=>v?Be(v):null,[v]),x=F(),S=t=>{x.mutate({id:e,settings:t},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:f,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:f,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":p(`common.close`,{defaultValue:`Close`}),children:c(ge,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),x.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(K,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(W,{kind:l,onResolved:e=>{S({brokerId:e})},onBack:f}),x.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||y?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(K,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(U,{addonId:t,configSchema:b,canTest:u,initialName:n,initialConfig:ze(b,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>S(e),onBack:f}):c(E,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}n();function He(){let{t}=xe(),{integrationId:n}=he(),d=o(),m=ue(),[g,_]=me(),v=u(),[S,C]=s(!1),[w,T]=s(!1),[E,k]=s(!1),[F,I]=s(!1),[L,R]=s(!1),{data:z,isLoading:ie}=A({id:n??``},{enabled:!!n}),{data:V}=j({addonId:z?.addonId??``,nodeId:`hub`},{enabled:!!z?.addonId}),{data:U,isSuccess:W}=D(),G=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,z?.addonId,W]),{data:ce}=P({}),le=i(()=>(ce?.providers??[]).some(e=>e.addonId===z?.addonId),[ce,z?.addonId]),q=G!==null,J=z?.info?.fixed===!0,de=q?G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),fe=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,z?.addonId,W]),_e=i(()=>{let e=z?.addonId;return!e||!W?!1:(U??[]).find(t=>t.addonId===e)?.canTest===!0},[U,z?.addonId,W]),Se=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,z?.addonId,W]);l(()=>{g.get(`add`)===`1`&&q&&(C(!0),_(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[g,q,_]);let we=V!=null&&Array.isArray(V.sections)&&V.sections.some(e=>e.fields.length>0),{data:Te}=f({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=p({onMutate:async e=>{await d.cancelQueries({queryKey:X});let t=d.getQueryData(X);return t!=null&&d.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(X,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=M({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),I(!1),m(`/integrations`)}}),Ee=N({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=y({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=h({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=x({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Te??[],[Te]),je=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Me=e(e=>je.get(e)??null,[je]),Ne=e(e=>c(B,{type:e,size:`sm`}),[]),Fe=e(e=>m(`/devices/${String(e)}`),[m]),Ie=i(()=>{let e=z?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,z?.addonId]),Le=i(()=>ee(Ie).length,[Ie]);return ie?r(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):z?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(O,{items:[{label:`Integrations`,onClick:()=>m(`/integrations`)},{label:z.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(`img`,{src:`/api/addon-assets/${z.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:z.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[z.addonId,` · `,Le,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[le&&r(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[c(ae,{className:`h-3.5 w-3.5`}),`Scan network`]}),!J&&r(`button`,{onClick:()=>C(!0),disabled:!q,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:de,children:[c(H,{className:`h-3.5 w-3.5`}),de]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${z.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(te,{checked:z.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":z.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${z.enabled?`text-success`:`text-foreground-subtle`}`,children:z.enabled?`Enabled`:`Disabled`}),Z.isPending&&c(K,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(we||G===`device-adoption`)&&r(`button`,{onClick:()=>k(!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:[c(ye,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>R(!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:[c(ve,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(ne,{label:`Restart`,icon:se,title:`Restart "${z.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Le} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ee.isPending,action:()=>Ee.mutateAsync({addonId:z.addonId})}),!J&&r(`button`,{onClick:()=>I(!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:[c(be,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),c(re,{context:`integration-detail`,devices:$,trpc:v.trpcClient,defaultView:`cards`,forceAddon:z.addonId,urlScope:`root`,lsKey:`integration-detail:${z.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Fe,batchActions:{remove:Oe.mutate,disable:ke.mutate,enable:Ae.mutate},...J?{}:{onDeleteDevice:e=>Oe.mutate({deviceId:e.id})}}),S&&n&&G===`device-adoption`&&c(Pe,{addonId:z.addonId,integrationId:n,onClose:()=>C(!1)}),S&&n&&G===`device-provider`&&c(De,{open:S,integrationId:n,addonId:z.addonId,onClose:()=>C(!1)}),w&&z&&c(oe,{open:w,scope:{addonId:z.addonId,label:z.name},onClose:()=>T(!1)}),E&&n&&G!==null&&Se!==null&&c(Ve,{integrationId:n,addonId:z.addonId,name:z.name,kind:G,mode:Se,brokerKind:fe,canTest:_e,trpc:v.trpcClient,onClose:()=>k(!1)}),L&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>R(!1),children:r(`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:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(ve,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:z.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[z.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>R(!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:c(ge,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(b,{addonId:z.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),F&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&I(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(Y,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`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:z.name,count:Le})})]})]}),Q.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>I(!1),disabled:Q.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`})}),c(`button`,{onClick:()=>Q.mutate({id:n}),disabled:Q.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:Q.isPending?r(a,{children:[c(K,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(be,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(Ce,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>m(`/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:[c(pe,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{He as IntegrationDetailPage};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u}from"./player-overlays-DsK1iDkv.js";import{$r as d,Br as f,Ci as p,Cr as m,Dr as h,Er as g,F as _,Fr as v,Gr as y,J as b,Mr as x,N as S,Sr as C,T as ee,Tr as w,Ur as T,Wt as E,_i as D,at as O,br as k,gi as A,gn as j,hi as M,jn as N,jr as P,jt as te,nt as ne,w as re,xi as F,xr as I,yi as L,yr as R}from"./src-DnZ6ZcH0.js";import{mt as z}from"./src-DY4vbC0g.js";import{t as B}from"./ProviderIcon-DaauzRy3.js";import{t as ie}from"./circle-x-Bsgek5uU.js";import{t as V}from"./FormBuilder-CgXBJs1A.js";import{t as H}from"./plus-CKJhtG9S.js";import{i as ae,n as U,r as W,t as oe}from"./ScanNetworkModal-DwKJwpIs.js";import{t as se}from"./refresh-cw-B06QF6BP.js";import{t as G}from"./rotate-cw-B7IVurj2.js";import{t as ce}from"./wifi-BHTVIRt4.js";import{A as le,C as K,I as q,J as ue,K as J,P as de,R as fe,W as pe,X as me,Y as he,i as ge,k as _e,m as ve,o as Y,p as ye,s as be,t as xe,z as Se}from"./index-D7fwM52p.js";var Ce=J(`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`}]]);n();function we(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...we(n.fields));return t}function Te(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...we(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;o(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function X(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(...X(n.fields));return t}function Z(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Q(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Q(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Ee(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function De({open:t,integrationId:n,addonId:a,onClose:u}){let{t:f}=xe(),p=o(),[m,h]=s({}),[_,y]=s(!1),[x,S]=s(null),[C,ee]=s(Ee),w=T({addonId:a},{enabled:t}),E=w.data?.deviceType??null,D=v({addonId:a,type:E??z.Camera},{enabled:t&&w.isSuccess&&E!==null}),O=D.data??null;l(()=>{t&&(h(O?Q(O.sections.flatMap(e=>e.fields)):{}),ee(Ee()),y(!1),S(null))},[t,n,O]);let k=i(()=>({...m,_probeRequestId:C}),[m,C]),A=g({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=d(),M=e(async(e,t)=>{y(!0);let n=await j.mutateAsync({addonId:a,type:E??z.Camera,key:e,value:t,formValues:k});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Z(e[i])&&!Z(a)&&(r[i]=a,t=!0);return t?r:e}),n},[j,a,k,E]),{testAllStatus:N,hasProbeFields:P,probeResults:te,handleTestAll:ne,clearProbeResult:re}=Te(O??{sections:[]},m,M);async function F(e){S(null);try{await A.mutateAsync({addonId:a,type:E??z.Camera,config:m,integrationId:n}),e?h(O?Q(O.sections.flatMap(e=>e.fields)):{}):u()}catch(e){S(e instanceof Error?e.message:String(e))}}if(!t)return null;let I=X((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>Z(m[e])),L=I.length===0,R=w.isLoading||E!==null&&D.isLoading,B=w.isError||w.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(ge,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?c(`div`,{className:`flex items-center justify-center py-8`,children:c(K,{className:`h-5 w-5 animate-spin text-primary`})}):B?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(Y,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(V,{schema:O,values:m,onChange:h,onTestField:M,probeResults:te,onClearProbe:re})}),!B&&!R&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>y(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[c(ve,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),c(fe,{className:`h-3.5 w-3.5 transition-transform ${_?`rotate-180`:``}`})]}),_&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(b,{addonId:a,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!B&&!R&&(x||I.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:x||`Required: ${I.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!B&&P&&r(`button`,{type:`button`,onClick:ne,disabled:N===`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:[N===`testing`?c(K,{className:`h-3.5 w-3.5 animate-spin`}):c(ce,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>F(!0),disabled:B||!L||A.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:f(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>F(!1),disabled:B||!L||A.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:A.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Oe=1500;function ke({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=xe(),o=R(),s=(C({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Oe:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?c(K,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(Y,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(ie,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(de,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Ae(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var $=`devices`,je={id:$,label:`Devices`,isDefault:!0},Me=2e4,Ne=100;function Pe({addonId:n,integrationId:i,onClose:a}){let{t:o}=xe(),[u,d]=s(new Set),[f,p]=s(new Set),[h,g]=s(new Map),[v,y]=s(null),{data:b}=D(),x=(b??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[C,ee]=s(!0),T=k({addonId:n,integrationId:i}).data?.filters,E=T&&T.length>0?T:[je],[O,A]=s(E.find(e=>e.isDefault)?.id??(E.some(e=>e.id===$)?$:E[0].id)),j=O!==$,M=m(),N=I({addonId:n,integrationId:i,page:1,pageSize:Me,filter:O}),P=N.refetch,te=M.mutate,ne=e(()=>{te({addonId:n,integrationId:i},{onSettled:()=>{P()}})},[te,n,i,P]),F=t(null);l(()=>{let e=`${n}::${i}`;F.current===e||N.isLoading||(F.current=e,(N.data?.candidates.length??0)===0&&ne())},[n,i,N.isLoading,N.data,ne]);let L=M.isPending,R=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,z=typeof M.data?.lastError==`string`&&M.data.lastError.length>0?M.data.lastError:null,B=N.data?.candidates??[],ie=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,V=w(),[H,ae]=s(null),U=e(e=>{e.alreadyAdopted||d(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),W=e(e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),oe=e((e,t)=>{g(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})},[]),se=e(e=>{let t={};for(let n of e){let e=h.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[h]),ce=e(async()=>{y(null);let e=[...u];if(e.length!==0)try{let t=se(e),{jobId:r}=await V.mutateAsync({addonId:n,integrationId:i,filter:O,childNativeIds:e,...t?{perCandidate:t}:{},...x?{importLocations:C}:{}});ae(r),d(new Set),g(new Map)}catch(e){y(e instanceof Error?e.message:String(e))}},[u,se,V,n,i,O,x,C]),le=t(null),q=e(()=>{H===null||le.current===H||(le.current=H,P())},[H,P]),ue=e(e=>{A(e),d(new Set),p(new Set),g(new Map),y(null)},[]),J=u.size;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:o(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:o(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[x&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:C,onChange:e=>ee(e.target.checked),className:`accent-primary`}),o(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(ge,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(R??ie??z)&&B.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:o(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:R??ie??z})]})]})}),E.length>1&&c(Fe,{filters:E,activeFilter:O,onSelect:ue}),c(`div`,{className:`flex-1 min-h-0`,children:c(re,{mode:`generic`,items:B,pageSize:Ne,getKey:e=>e.childNativeId,getSearchText:Ae,getFilterType:e=>e.type,filterOptions:S(),filterLabel:o(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:N.isLoading||L&&B.length===0,searchPlaceholder:o(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??ie??z)&&B.length===0?``:o(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:ne,disabled:L,title:o(`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:[c(G,{className:`h-3.5 w-3.5 ${L?`animate-spin`:``}`}),o(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:o(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ie,{candidate:e,expandable:!j,expanded:f.has(e.childNativeId),onToggleExpand:()=>W(e.childNativeId),adoptedLabel:o(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:o(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=_(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(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=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>U(e),disabled:e.alreadyAdopted,"aria-label":u.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${u.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:u.has(e.childNativeId)&&c(Se,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!j&&f.has(e.childNativeId),renderExpanded:j?void 0:e=>c(Le,{candidate:e,hiddenChildIds:h.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>oe(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:u.has(e.childNativeId)?`bg-primary/5`:``})})]}),v&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(Y,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:v})]})}),H!==null&&c(ke,{addonId:n,integrationId:i,jobId:H,onFinished:q}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:ce,disabled:J===0||V.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:[V.isPending&&c(K,{className:`h-3.5 w-3.5 animate-spin`}),o(`integrations.addSelected`,{defaultValue:`Add selected`}),J>0?` (${J})`:``]})]})]})]})]})}function Fe({filters:e,activeFilter:t,onSelect:n}){return c(`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 c(`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 Ie({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[c(n?fe:q,{className:`h-3.5 w-3.5`}),o]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Le({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:c(i?le:_e,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Re(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Re(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function ze(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Re(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Be(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ve({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=xe(),m=o(),{data:h,isLoading:g}=L({id:e},{enabled:s===`account`||s===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=j({addonId:t,nodeId:`hub`},{enabled:s===`account`}),b=i(()=>v?Be(v):null,[v]),x=F(),S=t=>{x.mutate({id:e,settings:t},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:f,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:f,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":p(`common.close`,{defaultValue:`Close`}),children:c(ge,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),x.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(K,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(W,{kind:l,onResolved:e=>{S({brokerId:e})},onBack:f}),x.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||y?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(K,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(U,{addonId:t,configSchema:b,canTest:u,initialName:n,initialConfig:ze(b,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>S(e),onBack:f}):c(E,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}n();function He(){let{t}=xe(),{integrationId:n}=he(),d=o(),m=ue(),[g,_]=me(),v=u(),[S,C]=s(!1),[w,T]=s(!1),[E,k]=s(!1),[F,I]=s(!1),[L,R]=s(!1),{data:z,isLoading:ie}=A({id:n??``},{enabled:!!n}),{data:V}=j({addonId:z?.addonId??``,nodeId:`hub`},{enabled:!!z?.addonId}),{data:U,isSuccess:W}=D(),G=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,z?.addonId,W]),{data:ce}=P({}),le=i(()=>(ce?.providers??[]).some(e=>e.addonId===z?.addonId),[ce,z?.addonId]),q=G!==null,J=z?.info?.fixed===!0,de=q?G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),fe=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,z?.addonId,W]),_e=i(()=>{let e=z?.addonId;return!e||!W?!1:(U??[]).find(t=>t.addonId===e)?.canTest===!0},[U,z?.addonId,W]),Se=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,z?.addonId,W]);l(()=>{g.get(`add`)===`1`&&q&&(C(!0),_(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[g,q,_]);let we=V!=null&&Array.isArray(V.sections)&&V.sections.some(e=>e.fields.length>0),{data:Te}=f({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=p({onMutate:async e=>{await d.cancelQueries({queryKey:X});let t=d.getQueryData(X);return t!=null&&d.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(X,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=M({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),I(!1),m(`/integrations`)}}),Ee=N({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=y({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=h({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=x({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Te??[],[Te]),je=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Me=e(e=>je.get(e)??null,[je]),Ne=e(e=>c(B,{type:e,size:`sm`}),[]),Fe=e(e=>m(`/devices/${String(e)}`),[m]),Ie=i(()=>{let e=z?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,z?.addonId]),Le=i(()=>ee(Ie).length,[Ie]);return ie?r(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):z?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(O,{items:[{label:`Integrations`,onClick:()=>m(`/integrations`)},{label:z.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(`img`,{src:`/api/addon-assets/${z.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:z.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[z.addonId,` · `,Le,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[le&&r(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[c(ae,{className:`h-3.5 w-3.5`}),`Scan network`]}),!J&&r(`button`,{onClick:()=>C(!0),disabled:!q,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:de,children:[c(H,{className:`h-3.5 w-3.5`}),de]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${z.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(te,{checked:z.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":z.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${z.enabled?`text-success`:`text-foreground-subtle`}`,children:z.enabled?`Enabled`:`Disabled`}),Z.isPending&&c(K,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(we||G===`device-adoption`)&&r(`button`,{onClick:()=>k(!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:[c(ye,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>R(!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:[c(ve,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(ne,{label:`Restart`,icon:se,title:`Restart "${z.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Le} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ee.isPending,action:()=>Ee.mutateAsync({addonId:z.addonId})}),!J&&r(`button`,{onClick:()=>I(!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:[c(be,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),c(re,{context:`integration-detail`,devices:$,trpc:v.trpcClient,defaultView:`cards`,forceAddon:z.addonId,urlScope:`root`,lsKey:`integration-detail:${z.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Fe,batchActions:{remove:Oe.mutate,disable:ke.mutate,enable:Ae.mutate},...J?{}:{onDeleteDevice:e=>Oe.mutate({deviceId:e.id})}}),S&&n&&G===`device-adoption`&&c(Pe,{addonId:z.addonId,integrationId:n,onClose:()=>C(!1)}),S&&n&&G===`device-provider`&&c(De,{open:S,integrationId:n,addonId:z.addonId,onClose:()=>C(!1)}),w&&z&&c(oe,{open:w,scope:{addonId:z.addonId,label:z.name},onClose:()=>T(!1)}),E&&n&&G!==null&&Se!==null&&c(Ve,{integrationId:n,addonId:z.addonId,name:z.name,kind:G,mode:Se,brokerKind:fe,canTest:_e,trpc:v.trpcClient,onClose:()=>k(!1)}),L&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>R(!1),children:r(`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:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(ve,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:z.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[z.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>R(!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:c(ge,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(b,{addonId:z.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),F&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&I(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(Y,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`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:z.name,count:Le})})]})]}),Q.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>I(!1),disabled:Q.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`})}),c(`button`,{onClick:()=>Q.mutate({id:n}),disabled:Q.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:Q.isPending?r(a,{children:[c(K,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(be,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(Ce,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>m(`/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:[c(pe,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{He as IntegrationDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-BCuyatPp.js";import{Br as u,T as d,_i as f,bi as p,en as m,gn as ee,i as h,kr as g,mi as te,vr as ne,w as _}from"./src-BmCjCFGO.js";import{t as v}from"./ProviderIcon-BBJFc8mr.js";import{t as y}from"./plus-D-xjJ9wd.js";import{i as b,n as re,r as x,t as S}from"./ScanNetworkModal-BQIyP8Qh.js";import{t as C}from"./refresh-cw-CvqUZLg2.js";import{C as ie,I as w,J as T,R as E,V as D,X as O,i as k,p as A,t as j,v as M,z as N}from"./index-CoX6Kh_l.js";import{t as ae}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-DCo7fWEj.js";import{t as P}from"./StatusBadge-CeptlsPG.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";t();function I(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function L({providerId:e,onImport:t,onSkip:r}){let{t:i}=j(),[a,l]=o(new Set),u=g(),d=u.data,f=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function p(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let m=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:m.length>0?i(`integrations.foundDevices`,{count:m.length}):i(`integrations.noDevicesFound`)}),m.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:m.map(e=>{let t=e.stableId,r=e.suggestedName??t,i=a.has(t);return n(`button`,{onClick:()=>p(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${i?`border-primary bg-primary`:`border-border`}`,children:i&&s(N,{className:`h-3 w-3 text-primary-foreground`})}),s(D,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),m.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function R({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=j(),a=T(),{data:o,isLoading:c}=f();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},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:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(ie,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(A,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(w,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var z=2e4;function se({open:e,onClose:t}){let{t:l}=j(),u=T(),d=a(),[f,p]=o(`picker`),[m,h]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[S,C]=o(null),[w,E]=o(``),[D,O]=o(null),[A,M]=o(null),[N,ae]=o(!1),{data:P}=ee({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),se=r(()=>P?oe(P):null,[P]),B=te({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=g(),ce=V.data;c(()=>{f!==`discovery`||!_||!m||V.isPending||V.data||V.mutate({addonId:m})},[f,_,m,V]);let H=ne({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function U(e,t,n,r,i,a,o,s){if(!B.isPending){if(h(e),ae(s),b(n),E(r),M(null),o===`broker`){if(!a){M(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),p(`broker`);return}if(o===`account`){p(`config`);return}W(e,r)}}async function W(e,n){try{let r=await B.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function G(e){if(m)try{let t=await B.mutateAsync({addonId:m,name:e.name,settings:e.config});v(t.id),y===`auto`||y===`both`?p(`discovery`):q(t.id)}catch{}}async function K(e){if(m)try{let t=await B.mutateAsync({addonId:m,name:w,settings:{brokerId:e}});O(t.id),v(t.id),q(t.id)}catch{}}async function le(e){if(m){for(let t of e){let e=ce?.find(e=>e.stableId===t);e&&await H.mutateAsync({addonId:m,candidate:e,...D===null?{}:{integrationId:D}})}q()}}function q(e){let n=e??_??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),h(null),v(null),b(`manual`),C(null),E(``),O(null),M(null),ae(!1)}function Y(){t(),J()}F(e);let X=B.isPending,Z=I(X,z);if(!e)return null;let Q={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},ue=X?m:null,$=B.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:Q[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(k,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[A&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),s(R,{onSelect:U,onClose:Y,pendingAddonId:ue})]}),f===`config`&&m&&s(re,{addonId:m,configSchema:se??null,canTest:N,onSave:G,onBack:()=>p(`picker`)}),f===`broker`&&S&&s(x,{kind:S,onResolved:e=>{K(e)},onBack:()=>p(`picker`)}),f===`discovery`&&_&&s(L,{providerId:_,onImport:le,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(ie,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function B({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?E:w,{className:`h-3.5 w-3.5`})}),s(v,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function V(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(B,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(P,{status:e.status})}]}t();function ce(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var H=`expand`;function U(){let{t}=j(),a=T(),c=l(),[f]=O(),[ee,g]=o(!1),te=e(()=>g(!0),[]),ne=e(()=>g(!1),[]),[re,x]=o(!1),ie=e(()=>x(!0),[]),w=e(()=>x(!1),[]);h([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),h([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:E,isLoading:D,refetch:k}=p(void 0),{data:A,isLoading:N,refetch:P}=u({}),F=r(()=>A??[],[A]),I=r(()=>E??[],[E]),L=r(()=>{let e=new Map;for(let t of F)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[F]),R=r(()=>{let e=new Map;for(let t of d(F)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[F]),oe=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ce(e),deviceCount:R.get(e.addonId)??0})),[I,R]),z=f.get(H),B=e(e=>{let t=new URLSearchParams(window.location.search);t.get(H)===e?t.delete(H):t.set(H,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`))},[]),U=e(e=>a(`/integrations/${e.id}`),[a]),W=e(e=>L.get(e)??null,[L]),G=e(e=>s(v,{type:e,size:`sm`}),[]),K=e(e=>a(`/devices/${String(e)}`),[a]),le=e(e=>s(_,{context:`integration-detail`,devices:F,trpc:c.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:G,resolveParent:W,onNavigate:K}),[F,c.trpcClient,G,W,K]),q=e(e=>z===e.addonId,[z]),J=r(()=>V({isExpanded:q,onToggleExpand:B}),[q,B]),Y=e(e=>`${e.name} ${e.addonId}`,[]),X=e(e=>e.addonId,[]),Z=e(()=>{k(),P()},[k,P]),Q=D||N,ue=I.length>0;return n(ae,{icon:M,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`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:s(C,{className:m(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:ie,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(b,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:te,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(y,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!ue&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&ue&&s(_,{mode:`generic`,items:oe,getKey:X,getSearchText:Y,columns:J,onRowClick:U,isExpanded:q,renderExpanded:le,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(se,{open:ee,onClose:ne}),s(S,{open:re,onClose:w})]})}export{U as IntegrationsPage};
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-DsK1iDkv.js";import{Br as u,T as d,_i as f,bi as p,en as m,gn as ee,i as h,kr as g,mi as te,vr as ne,w as _}from"./src-DnZ6ZcH0.js";import{t as v}from"./ProviderIcon-DaauzRy3.js";import{t as y}from"./plus-CKJhtG9S.js";import{i as b,n as re,r as x,t as S}from"./ScanNetworkModal-DwKJwpIs.js";import{t as C}from"./refresh-cw-B06QF6BP.js";import{C as ie,I as w,J as T,R as E,V as D,X as O,i as k,p as A,t as j,v as M,z as N}from"./index-D7fwM52p.js";import{t as ae}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-CINdEbPJ.js";import{t as P}from"./StatusBadge-CeptlsPG.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";t();function I(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function L({providerId:e,onImport:t,onSkip:r}){let{t:i}=j(),[a,l]=o(new Set),u=g(),d=u.data,f=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function p(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let m=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:m.length>0?i(`integrations.foundDevices`,{count:m.length}):i(`integrations.noDevicesFound`)}),m.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:m.map(e=>{let t=e.stableId,r=e.suggestedName??t,i=a.has(t);return n(`button`,{onClick:()=>p(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${i?`border-primary bg-primary`:`border-border`}`,children:i&&s(N,{className:`h-3 w-3 text-primary-foreground`})}),s(D,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),m.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function R({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=j(),a=T(),{data:o,isLoading:c}=f();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},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:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(ie,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(A,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(w,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var z=2e4;function se({open:e,onClose:t}){let{t:l}=j(),u=T(),d=a(),[f,p]=o(`picker`),[m,h]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[S,C]=o(null),[w,E]=o(``),[D,O]=o(null),[A,M]=o(null),[N,ae]=o(!1),{data:P}=ee({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),se=r(()=>P?oe(P):null,[P]),B=te({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=g(),ce=V.data;c(()=>{f!==`discovery`||!_||!m||V.isPending||V.data||V.mutate({addonId:m})},[f,_,m,V]);let H=ne({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function U(e,t,n,r,i,a,o,s){if(!B.isPending){if(h(e),ae(s),b(n),E(r),M(null),o===`broker`){if(!a){M(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),p(`broker`);return}if(o===`account`){p(`config`);return}W(e,r)}}async function W(e,n){try{let r=await B.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function G(e){if(m)try{let t=await B.mutateAsync({addonId:m,name:e.name,settings:e.config});v(t.id),y===`auto`||y===`both`?p(`discovery`):q(t.id)}catch{}}async function K(e){if(m)try{let t=await B.mutateAsync({addonId:m,name:w,settings:{brokerId:e}});O(t.id),v(t.id),q(t.id)}catch{}}async function le(e){if(m){for(let t of e){let e=ce?.find(e=>e.stableId===t);e&&await H.mutateAsync({addonId:m,candidate:e,...D===null?{}:{integrationId:D}})}q()}}function q(e){let n=e??_??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),h(null),v(null),b(`manual`),C(null),E(``),O(null),M(null),ae(!1)}function Y(){t(),J()}F(e);let X=B.isPending,Z=I(X,z);if(!e)return null;let Q={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},ue=X?m:null,$=B.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:Q[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(k,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[A&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),s(R,{onSelect:U,onClose:Y,pendingAddonId:ue})]}),f===`config`&&m&&s(re,{addonId:m,configSchema:se??null,canTest:N,onSave:G,onBack:()=>p(`picker`)}),f===`broker`&&S&&s(x,{kind:S,onResolved:e=>{K(e)},onBack:()=>p(`picker`)}),f===`discovery`&&_&&s(L,{providerId:_,onImport:le,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(ie,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function B({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?E:w,{className:`h-3.5 w-3.5`})}),s(v,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function V(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(B,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(P,{status:e.status})}]}t();function ce(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var H=`expand`;function U(){let{t}=j(),a=T(),c=l(),[f]=O(),[ee,g]=o(!1),te=e(()=>g(!0),[]),ne=e(()=>g(!1),[]),[re,x]=o(!1),ie=e(()=>x(!0),[]),w=e(()=>x(!1),[]);h([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),h([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:E,isLoading:D,refetch:k}=p(void 0),{data:A,isLoading:N,refetch:P}=u({}),F=r(()=>A??[],[A]),I=r(()=>E??[],[E]),L=r(()=>{let e=new Map;for(let t of F)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[F]),R=r(()=>{let e=new Map;for(let t of d(F)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[F]),oe=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ce(e),deviceCount:R.get(e.addonId)??0})),[I,R]),z=f.get(H),B=e(e=>{let t=new URLSearchParams(window.location.search);t.get(H)===e?t.delete(H):t.set(H,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`))},[]),U=e(e=>a(`/integrations/${e.id}`),[a]),W=e(e=>L.get(e)??null,[L]),G=e(e=>s(v,{type:e,size:`sm`}),[]),K=e(e=>a(`/devices/${String(e)}`),[a]),le=e(e=>s(_,{context:`integration-detail`,devices:F,trpc:c.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:G,resolveParent:W,onNavigate:K}),[F,c.trpcClient,G,W,K]),q=e(e=>z===e.addonId,[z]),J=r(()=>V({isExpanded:q,onToggleExpand:B}),[q,B]),Y=e(e=>`${e.name} ${e.addonId}`,[]),X=e(e=>e.addonId,[]),Z=e(()=>{k(),P()},[k,P]),Q=D||N,ue=I.length>0;return n(ae,{icon:M,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`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:s(C,{className:m(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:ie,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(b,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:te,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(y,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!ue&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&ue&&s(_,{mode:`generic`,items:oe,getKey:X,getSearchText:Y,columns:J,onRowClick:U,isExpanded:q,renderExpanded:le,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(se,{open:ee,onClose:ne}),s(S,{open:re,onClose:w})]})}export{U as IntegrationsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as s}from"./player-overlays-BCuyatPp.js";import{C as c,En as l,_r as u,ar as d,cr as f,dr as p,fr as m,ir as ee,ln as h,lr as g,sr as _,ur as v}from"./src-BmCjCFGO.js";import{V as y,ot as b,ut as x}from"./src-D8hsVOc6.js";import{t as S}from"./pencil-CCyVFYXA.js";import{t as te}from"./plus-D-xjJ9wd.js";import{t as C}from"./radio-DvHOeyw2.js";import{t as w}from"./wifi-Wacew_4h.js";import{C as T,J as E,K as D,i as O,s as k,v as A}from"./index-CoX6Kh_l.js";import{t as j}from"./AdminPage-CCD07UMs.js";import{t as M}from"./AdminTabs-Ya-WafVI.js";import{t as N}from"./BrokerForm-Cja9Cp03.js";import{t as P}from"./useBodyScrollLock-BDocajQE.js";import{t as F}from"./AddonCollectionPage-CCm-n_-k.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`}]]);e();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 H({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${V[e]}`,children:e})}function U(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function W({title:e,subtitle:n,onClose:r,children:i}){return P(),o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`space-y-0.5`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:o(O,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function G({kinds:e,onClose:n,onDone:s}){let c=i(),l=e=>`${e.addonId??``}::${e.kind}`,[u,d]=a(e[0]?l(e[0]):``),[f,p]=a(``),[m,h]=a(!1),[g,_]=a(``),v=e.find(e=>l(e)===u)??e[0],y=v?.kind??``,b=v?.addonId,x=ee({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),S=e=>{if(!y||f.trim().length===0)return;let t=m?g.trim():``;m&&t===``||x.mutate({kind:y,name:f.trim(),settings:e,...t===``?{}:{id:t},...b===void 0?{}:{addonId:b}})};return o(W,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:x.isPending?()=>{}:n,children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),o(`select`,{value:u,onChange:e=>d(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=>o(`option`,{value:l(e),children:e.label},l(e)))})]}),t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),o(`input`,{type:`text`,value:f,onChange:e=>p(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`})]}),t(`div`,{className:`space-y-1 rounded border border-border px-3 py-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[o(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),m&&t(r,{children:[o(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:`ha_004`,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`}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`})]})]}),x.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:x.error instanceof Error?x.error.message:String(x.error)}),y&&o(N,{kind:y,...b===void 0?{}:{addonId:b},onSubmit:S,onCancel:n,submitLabel:x.isPending?`Adding…`:`Add broker`,disabled:x.isPending}),f.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),m&&g.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter the original id, or clear the checkbox to create a new broker.`})]})})}function K({broker:e,onClose:r,onDone:a}){let s=i(),c=d({id:e.id,addonId:e.addonId}),l=p({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),u=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(W,{title:`Edit ${e.name}`,subtitle:`${z(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(T,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),o(`div`,{className:`flex justify-end`,children:o(`button`,{type:`button`,onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:l.error instanceof Error?l.error.message:String(l.error)}),o(N,{kind:e.kind,addonId:e.addonId,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function q({broker:e,onEdit:n}){let r=i(),s=h(),[c,l]=a(null),u=m({onSuccess:e=>l(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>l({ok:!1,error:e instanceof Error?e.message:String(e)})}),d=v({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),f=async()=>{await s({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&d.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:z(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(H,{status:e.status}),c&&o(`span`,{className:`ml-2 text-[10px] ${c.ok?`text-success`:`text-danger`}`,children:c.ok?`OK`:c.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(`button`,{type:`button`,onClick:()=>u.mutate({id:e.id,addonId:e.addonId}),disabled:u.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:[u.isPending?o(T,{className:`h-3 w-3 animate-spin`}):o(w,{className:`h-3 w-3`}),`Test`]}),t(`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:[o(S,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{f()},disabled:d.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:[d.isPending?o(T,{className:`h-3 w-3 animate-spin`}):o(k,{className:`h-3 w-3`}),`Delete`]})]})})]})}function J(){let e=f({}),r=g(),i=n(()=>U(e.data),[e.data]),[s,c]=a(!1),[l,u]=a(null),d=n(()=>{let e=new Map;for(let t of B(r.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 i)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:z(t.kind)});return[...e.values()]},[i,r.data]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(`button`,{type:`button`,onClick:()=>c(!0),disabled:d.length===0,title:d.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:[o(te,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[e.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(T,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&o(`tr`,{children:t(`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&&i.length===0&&o(`tr`,{children:o(`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.`})}),i.map(e=>o(q,{broker:e,onEdit:u},e.id))]})]})}),s&&o(G,{kinds:d,onClose:()=>c(!1),onDone:()=>c(!1)}),l&&o(K,{broker:l,onClose:()=>u(null),onDone:()=>u(null)})]})}var Y=[{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:C,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 X(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 Z(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=X(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 Q(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function ne(e){for(let[t,n]of Object.entries(y))if(n===e)return t;return null}function re(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 o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function ie({addonId:e}){let{data:t,isLoading:n}=_({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=x.safeParse(t);if(!r.success)return null;let i=r.data;return o($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ae({addonId:e}){let{data:t,isLoading:n}=u({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 o($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function oe({kind:e,addonId:t}){return e===`broker`?o(ie,{addonId:t}):e===`device-export`?o(ae,{addonId:t}):null}function se({descriptor:e,rows:n,isLoading:i}){let a=ne(e.kind),l=e.kind===`device-export`,u=s(),d=E();return o(F,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:a??e.kind,installButtonLabel:e.addLabel,items:n,isLoading:i,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:n=>{let i=re(n.processState);return t(r,{children:[o($,{label:i.label,className:i.className}),o(oe,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:l?e=>o(c,{addonId:e.addonId,trpc:u.trpcClient,onOpenDevice:e=>d(`/devices/${e}`)}):void 0,showChrome:!0})}function ce(){let e=l(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Z).filter(e=>e!==null);return o(j,{icon:A,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:o(M,{tabs:Y.map(n=>{let r=Object.entries(y).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(J,{}):o(se,{descriptor:n,rows:Q(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{ce as IntegrationsPage};
|
|
1
|
+
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as s}from"./player-overlays-DsK1iDkv.js";import{C as c,En as l,_r as u,ar as d,cr as f,dr as p,fr as m,ir as ee,ln as h,lr as g,sr as _,ur as v}from"./src-DnZ6ZcH0.js";import{H as y,dt as b,st as x}from"./src-DY4vbC0g.js";import{t as S}from"./pencil-DDE9Ut_f.js";import{t as te}from"./plus-CKJhtG9S.js";import{t as C}from"./radio-Cgg_wmnh.js";import{t as w}from"./wifi-BHTVIRt4.js";import{C as T,J as E,K as D,i as O,s as k,v as A}from"./index-D7fwM52p.js";import{t as j}from"./AdminPage-CCD07UMs.js";import{t as M}from"./AdminTabs-BFe9RXxD.js";import{t as N}from"./BrokerForm-RC8ZQms1.js";import{t as P}from"./useBodyScrollLock-BDocajQE.js";import{t as F}from"./AddonCollectionPage-Czx0Rf1Y.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`}]]);e();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 H({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${V[e]}`,children:e})}function U(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function W({title:e,subtitle:n,onClose:r,children:i}){return P(),o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`space-y-0.5`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:o(O,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function G({kinds:e,onClose:n,onDone:s}){let c=i(),l=e=>`${e.addonId??``}::${e.kind}`,[u,d]=a(e[0]?l(e[0]):``),[f,p]=a(``),[m,h]=a(!1),[g,_]=a(``),v=e.find(e=>l(e)===u)??e[0],y=v?.kind??``,b=v?.addonId,x=ee({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),S=e=>{if(!y||f.trim().length===0)return;let t=m?g.trim():``;m&&t===``||x.mutate({kind:y,name:f.trim(),settings:e,...t===``?{}:{id:t},...b===void 0?{}:{addonId:b}})};return o(W,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:x.isPending?()=>{}:n,children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),o(`select`,{value:u,onChange:e=>d(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=>o(`option`,{value:l(e),children:e.label},l(e)))})]}),t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),o(`input`,{type:`text`,value:f,onChange:e=>p(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`})]}),t(`div`,{className:`space-y-1 rounded border border-border px-3 py-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[o(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),m&&t(r,{children:[o(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:`ha_004`,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`}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`})]})]}),x.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:x.error instanceof Error?x.error.message:String(x.error)}),y&&o(N,{kind:y,...b===void 0?{}:{addonId:b},onSubmit:S,onCancel:n,submitLabel:x.isPending?`Adding…`:`Add broker`,disabled:x.isPending}),f.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),m&&g.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter the original id, or clear the checkbox to create a new broker.`})]})})}function K({broker:e,onClose:r,onDone:a}){let s=i(),c=d({id:e.id,addonId:e.addonId}),l=p({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),u=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(W,{title:`Edit ${e.name}`,subtitle:`${z(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(T,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),o(`div`,{className:`flex justify-end`,children:o(`button`,{type:`button`,onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:l.error instanceof Error?l.error.message:String(l.error)}),o(N,{kind:e.kind,addonId:e.addonId,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function q({broker:e,onEdit:n}){let r=i(),s=h(),[c,l]=a(null),u=m({onSuccess:e=>l(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>l({ok:!1,error:e instanceof Error?e.message:String(e)})}),d=v({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),f=async()=>{await s({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&d.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:z(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(H,{status:e.status}),c&&o(`span`,{className:`ml-2 text-[10px] ${c.ok?`text-success`:`text-danger`}`,children:c.ok?`OK`:c.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(`button`,{type:`button`,onClick:()=>u.mutate({id:e.id,addonId:e.addonId}),disabled:u.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:[u.isPending?o(T,{className:`h-3 w-3 animate-spin`}):o(w,{className:`h-3 w-3`}),`Test`]}),t(`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:[o(S,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{f()},disabled:d.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:[d.isPending?o(T,{className:`h-3 w-3 animate-spin`}):o(k,{className:`h-3 w-3`}),`Delete`]})]})})]})}function J(){let e=f({}),r=g(),i=n(()=>U(e.data),[e.data]),[s,c]=a(!1),[l,u]=a(null),d=n(()=>{let e=new Map;for(let t of B(r.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 i)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:z(t.kind)});return[...e.values()]},[i,r.data]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(`button`,{type:`button`,onClick:()=>c(!0),disabled:d.length===0,title:d.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:[o(te,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[e.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(T,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&o(`tr`,{children:t(`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&&i.length===0&&o(`tr`,{children:o(`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.`})}),i.map(e=>o(q,{broker:e,onEdit:u},e.id))]})]})}),s&&o(G,{kinds:d,onClose:()=>c(!1),onDone:()=>c(!1)}),l&&o(K,{broker:l,onClose:()=>u(null),onDone:()=>u(null)})]})}var Y=[{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:C,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 X(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 Z(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=X(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 Q(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function ne(e){for(let[t,n]of Object.entries(y))if(n===e)return t;return null}function re(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 o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function ie({addonId:e}){let{data:t,isLoading:n}=_({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;return o($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ae({addonId:e}){let{data:t,isLoading:n}=u({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=x.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 o($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function oe({kind:e,addonId:t}){return e===`broker`?o(ie,{addonId:t}):e===`device-export`?o(ae,{addonId:t}):null}function se({descriptor:e,rows:n,isLoading:i}){let a=ne(e.kind),l=e.kind===`device-export`,u=s(),d=E();return o(F,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:a??e.kind,installButtonLabel:e.addLabel,items:n,isLoading:i,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:n=>{let i=re(n.processState);return t(r,{children:[o($,{label:i.label,className:i.className}),o(oe,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:l?e=>o(c,{addonId:e.addonId,trpc:u.trpcClient,onOpenDevice:e=>d(`/devices/${e}`)}):void 0,showChrome:!0})}function ce(){let e=l(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Z).filter(e=>e!==null);return o(j,{icon:A,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:o(M,{tabs:Y.map(n=>{let r=Object.entries(y).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(J,{}):o(se,{descriptor:n,rows:Q(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{ce as IntegrationsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{x as e}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{J as t}from"./src-
|
|
1
|
+
import{x as e}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{J as t}from"./src-DnZ6ZcH0.js";import{t as n}from"./AdminPage-CCD07UMs.js";function r(){return e(n,{children:e(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e(t,{limit:500,maxHeight:`max-h-[calc(100vh-250px)]`,showScope:!0,showFilters:!0})})})}export{r as LogsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{J as l,U as u,W as ee,Z as d,ct as f,j as p,n as m}from"./player-overlays-
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{J as l,U as u,W as ee,Z as d,ct as f,j as p,n as m}from"./player-overlays-DsK1iDkv.js";import{MaskShapeCanvas as h}from"./MaskShapeCanvas-Dcpby34M.js";var te=f(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]);n();var ne=110,g=`motion-zones`,_=0,re=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:n}){let f=ee(d().trpcClient,n),[w,D]=o(null),[O,k]=o(!1),[A,j]=o(null),[M,N]=o(null),[P,F]=o(v),[I,L]=o(!1),[R,z]=o(!1),B=t(!1);c(()=>{if(!f)return;let e=!1;return B.current=!1,D(null),k(!1),j(null),N(null),F(v),z(!1),(async()=>{try{let t=await f.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(D(t),B.current)return;let n=await f.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);B.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);N(i),j(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;u(t)?k(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[f]);let V=w?w.grid.width:0,H=w?w.grid.height:0,U=C(V,P),W=C(H,P),G=i(()=>A&&w?E(A,V,H,P):null,[A,w,V,H,P]),K=i(()=>G!==null&&M!==null&&!S(G,M),[G,M]),q=i(()=>G?G.reduce((e,t)=>t?e+1:e,0):0,[G]),J=V*H,Y=U*W,X=e(e=>{Y>0&&j(Array.from({length:Y},()=>e))},[Y]),Z=e(()=>{j(e=>e&&e.map(e=>!e))},[]),ie=e(()=>{M&&w&&j(T(M,V,H,P))},[M,w,V,H,P]),ae=e(e=>{e===P||!w||j(t=>{if(!t)return F(e),t;let n=T(E(t,V,H,P),V,H,e);return F(e),n})},[P,w,V,H]),Q=i(()=>w&&A?[{id:_,shape:{kind:`grid`,gridWidth:U,gridHeight:W,cells:[...A]}}]:[],[w,A,U,W]),$=e((e,t)=>{t.kind===`grid`&&j(t.cells)},[]),oe=e(async()=>{if(!(!f||!A||!w)){L(!0);try{let e=E(A,w.grid.width,w.grid.height,P),t={kind:`grid`,gridWidth:w.grid.width,gridHeight:w.grid.height,cells:e};await f.motionZones?.setZone({patch:{regions:[{id:_,enabled:!0,shape:t}]}});let n=await f.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],w.grid.width,w.grid.height);N(t),j(T(t,w.grid.width,w.grid.height,P))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{L(!1)}}},[f,A,w,P]);return m(i(()=>R&&!O&&w&&A?{id:g,order:ne,node:s(h,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:U,height:W},selectedId:_,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[R,O,w,A,Q,$,U,W])),f?s(l,{title:`Motion Zones`,icon:s(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:s(`div`,{className:`flex flex-col gap-3`,children:O?s(`p`,{className:`${p} leading-relaxed`,children:`This camera doesn't expose an on-board motion zones grid.`}):!O&&w!==null&&A!==null?r(a,{children:[r(`p`,{className:`${p} leading-relaxed`,children:[`Toggle `,s(`strong`,{className:`text-foreground`,children:`Edit grid`}),` to paint the region directly on the live frame, then `,s(`strong`,{className:`text-foreground`,children:`Save`}),` to push the mask to the camera. Pick a bigger`,` `,s(`strong`,{className:`text-foreground`,children:`Cell size`}),` for quicker, broad-stroke painting — it's resampled to the camera's native `,w.grid.width,`×`,w.grid.height,` grid on save (×1 is the finest).`]}),r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`button`,{type:`button`,onClick:()=>z(e=>!e),disabled:I,"aria-pressed":R,className:R?b:y,children:R?`Done editing`:`Edit grid`}),s(`button`,{type:`button`,onClick:()=>X(!0),disabled:I,className:y,children:`All on`}),s(`button`,{type:`button`,onClick:()=>X(!1),disabled:I,className:y,children:`All off`}),s(`button`,{type:`button`,onClick:Z,disabled:I,className:y,children:`Invert`}),r(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":`Cell size`,children:[s(`span`,{className:`${p} mr-0.5`,children:`Cell size`}),re.map(e=>r(`button`,{type:`button`,onClick:()=>ae(e),disabled:I,"aria-pressed":P===e,title:e===1?`Camera grid ${V}×${H} (finest)`:`${C(V,e)}×${C(H,e)} painting grid · cells ×${e} bigger`,className:P===e?b:y,children:[`×`,e]},e))]}),r(`span`,{className:`${p} ml-1 tabular-nums`,children:[q,` / `,J,` cells · `,w.grid.width,`×`,w.grid.height,P===1?``:` · paint ${U}×${W}`]}),s(`span`,{className:`flex-1`}),s(`button`,{type:`button`,onClick:ie,disabled:I||!K,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),s(`button`,{type:`button`,onClick:()=>void oe(),disabled:I||!K,className:b,children:I?`Saving…`:`Save`})]})]}):s(`p`,{className:`${p} leading-relaxed`,children:`Loading the camera's grid…`})})}):null}export{D as MotionZonesSettings};
|