Files
jwinterm fe2fc91cdd fix(admin-ui): repair Keys tab + console UX
- Keys tab crashed on render: api.keys() expected an array but the
  backend returns {keys:[...]}; unwrap it (KeysTab maps over the array).
- Config save now sends only CHANGED fields, not the whole section, so
  the backend stops spuriously flagging restarts and pinning env-sourced
  values into the DB overlay.
- Config edit state survives a reload (saving one section no longer
  discards unsaved edits in others); numeric inputs ignore empty/NaN
  instead of silently coercing to 0.
- Mint and Revoke now surface errors instead of swallowing them.
Rebuilt admin-ui/dist.
2026-07-19 05:30:33 -04:00

6 lines
22 KiB
JavaScript

(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const _ of document.querySelectorAll('link[rel="modulepreload"]'))o(_);new MutationObserver(_=>{for(const r of _)if(r.type==="childList")for(const s of r.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&o(s)}).observe(document,{childList:!0,subtree:!0});function n(_){const r={};return _.integrity&&(r.integrity=_.integrity),_.referrerPolicy&&(r.referrerPolicy=_.referrerPolicy),_.crossOrigin==="use-credentials"?r.credentials="include":_.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function o(_){if(_.ep)return;_.ep=!0;const r=n(_);fetch(_.href,r)}})();var J,y,xe,P,ce,Se,Te,Y,D,M,Ce,ie,ee,te,R={},z=[],De=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,G=Array.isArray;function N(t,e){for(var n in e)t[n]=e[n];return t}function _e(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function Fe(t,e,n){var o,_,r,s={};for(r in e)r=="key"?o=e[r]:r=="ref"?_=e[r]:s[r]=e[r];if(arguments.length>2&&(s.children=arguments.length>3?J.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(r in t.defaultProps)s[r]===void 0&&(s[r]=t.defaultProps[r]);return F(t,s,o,_,null)}function F(t,e,n,o,_){var r={type:t,props:e,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:_??++xe,__i:-1,__u:0};return _==null&&y.vnode!=null&&y.vnode(r),r}function V(t){return t.children}function j(t,e){this.props=t,this.context=e}function H(t,e){if(e==null)return t.__?H(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?H(t):null}function je(t){if(t.__P&&t.__d){var e=t.__v,n=e.__e,o=[],_=[],r=N({},e);r.__v=e.__v+1,y.vnode&&y.vnode(r),le(t.__P,r,e,t.__n,t.__P.namespaceURI,32&e.__u?[n]:null,o,n??H(e),!!(32&e.__u),_),r.__v=e.__v,r.__.__k[r.__i]=r,Oe(o,r,_),e.__e=e.__=null,r.__e!=n&&$e(r)}}function $e(t){if((t=t.__)!=null&&t.__c!=null)return t.__e=t.__c.base=null,t.__k.some(function(e){if(e!=null&&e.__e!=null)return t.__e=t.__c.base=e.__e}),$e(t)}function ue(t){(!t.__d&&(t.__d=!0)&&P.push(t)&&!q.__r++||ce!=y.debounceRendering)&&((ce=y.debounceRendering)||Se)(q)}function q(){try{for(var t,e=1;P.length;)P.length>e&&P.sort(Te),t=P.shift(),e=P.length,je(t)}finally{P.length=q.__r=0}}function Ne(t,e,n,o,_,r,s,a,f,l,d){var p,i,u,h,w,v,k,m=o&&o.__k||z,S=e.length;for(f=We(n,e,m,f,S),p=0;p<S;p++)(u=n.__k[p])!=null&&(i=u.__i!=-1&&m[u.__i]||R,u.__i=p,v=le(t,u,i,_,r,s,a,f,l,d),h=u.__e,u.ref&&i.ref!=u.ref&&(i.ref&&se(i.ref,null,u),d.push(u.ref,u.__c||h,u)),w==null&&h!=null&&(w=h),(k=!!(4&u.__u))||i.__k===u.__k?(f=Pe(u,f,t,k),k&&i.__e&&(i.__e=null)):typeof u.type=="function"&&v!==void 0?f=v:h&&(f=h.nextSibling),u.__u&=-7);return n.__e=w,f}function We(t,e,n,o,_){var r,s,a,f,l,d=n.length,p=d,i=0;for(t.__k=new Array(_),r=0;r<_;r++)(s=e[r])!=null&&typeof s!="boolean"&&typeof s!="function"?(typeof s=="string"||typeof s=="number"||typeof s=="bigint"||s.constructor==String?s=t.__k[r]=F(null,s,null,null,null):G(s)?s=t.__k[r]=F(V,{children:s},null,null,null):s.constructor===void 0&&s.__b>0?s=t.__k[r]=F(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):t.__k[r]=s,f=r+i,s.__=t,s.__b=t.__b+1,a=null,(l=s.__i=Re(s,n,f,p))!=-1&&(p--,(a=n[l])&&(a.__u|=2)),a==null||a.__v==null?(l==-1&&(_>d?i--:_<d&&i++),typeof s.type!="function"&&(s.__u|=4)):l!=f&&(l==f-1?i--:l==f+1?i++:(l>f?i--:i++,s.__u|=4))):t.__k[r]=null;if(p)for(r=0;r<d;r++)(a=n[r])!=null&&!(2&a.__u)&&(a.__e==o&&(o=H(a)),He(a,a));return o}function Pe(t,e,n,o){var _,r;if(typeof t.type=="function"){for(_=t.__k,r=0;_&&r<_.length;r++)_[r]&&(_[r].__=t,e=Pe(_[r],e,n,o));return e}t.__e!=e&&(o&&(e&&t.type&&!e.parentNode&&(e=H(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function Re(t,e,n,o){var _,r,s,a=t.key,f=t.type,l=e[n],d=l!=null&&(2&l.__u)==0;if(l===null&&a==null||d&&a==l.key&&f==l.type)return n;if(o>(d?1:0)){for(_=n-1,r=n+1;_>=0||r<e.length;)if((l=e[s=_>=0?_--:r++])!=null&&!(2&l.__u)&&a==l.key&&f==l.type)return s}return-1}function de(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||De.test(e)?n:n+"px"}function U(t,e,n,o,_){var r,s;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof o=="string"&&(t.style.cssText=o=""),o)for(e in o)n&&e in n||de(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||de(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")r=e!=(e=e.replace(Ce,"$1")),s=e.toLowerCase(),e=s in t||e=="onFocusOut"||e=="onFocusIn"?s.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+r]=n,n?o?n[M]=o[M]:(n[M]=ie,t.addEventListener(e,r?te:ee,r)):t.removeEventListener(e,r?te:ee,r);else{if(_=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function fe(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e[D]==null)e[D]=ie++;else if(e[D]<n[M])return;return n(y.event?y.event(e):e)}}}function le(t,e,n,o,_,r,s,a,f,l){var d,p,i,u,h,w,v,k,m,S,I,E,L,ae,B,X,$=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(f=!!(32&n.__u),r=[a=e.__e=n.__e]),(d=y.__b)&&d(e);e:if(typeof $=="function"){p=s.length;try{if(m=e.props,S=$.prototype&&$.prototype.render,I=(d=$.contextType)&&o[d.__c],E=d?I?I.props.value:d.__:o,n.__c?k=(i=e.__c=n.__c).__=i.__E:(S?e.__c=i=new $(m,E):(e.__c=i=new j(m,E),i.constructor=$,i.render=qe),I&&I.sub(i),i.state||(i.state={}),i.__n=o,u=i.__d=!0,i.__h=[],i._sb=[]),S&&i.__s==null&&(i.__s=i.state),S&&$.getDerivedStateFromProps!=null&&(i.__s==i.state&&(i.__s=N({},i.__s)),N(i.__s,$.getDerivedStateFromProps(m,i.__s))),h=i.props,w=i.state,i.__v=e,u)S&&$.getDerivedStateFromProps==null&&i.componentWillMount!=null&&i.componentWillMount(),S&&i.componentDidMount!=null&&i.__h.push(i.componentDidMount);else{if(S&&$.getDerivedStateFromProps==null&&m!==h&&i.componentWillReceiveProps!=null&&i.componentWillReceiveProps(m,E),e.__v==n.__v||!i.__e&&i.shouldComponentUpdate!=null&&i.shouldComponentUpdate(m,i.__s,E)===!1){e.__v!=n.__v&&(i.props=m,i.state=i.__s,i.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(O){O&&(O.__=e)}),z.push.apply(i.__h,i._sb),i._sb=[],i.__h.length&&s.push(i);break e}i.componentWillUpdate!=null&&i.componentWillUpdate(m,i.__s,E),S&&i.componentDidUpdate!=null&&i.__h.push(function(){i.componentDidUpdate(h,w,v)})}if(i.context=E,i.props=m,i.__P=t,i.__e=!1,L=y.__r,ae=0,S)i.state=i.__s,i.__d=!1,L&&L(e),d=i.render(i.props,i.state,i.context),z.push.apply(i.__h,i._sb),i._sb=[];else do i.__d=!1,L&&L(e),d=i.render(i.props,i.state,i.context),i.state=i.__s;while(i.__d&&++ae<25);i.state=i.__s,i.getChildContext!=null&&(o=N(N({},o),i.getChildContext())),S&&!u&&i.getSnapshotBeforeUpdate!=null&&(v=i.getSnapshotBeforeUpdate(h,w)),B=d!=null&&d.type===V&&d.key==null?Ae(d.props.children):d,a=Ne(t,G(B)?B:[B],e,n,o,_,r,s,a,f,l),i.base=e.__e,e.__u&=-161,i.__h.length&&s.push(i),k&&(i.__E=i.__=null)}catch(O){if(s.length=p,e.__v=null,f||r!=null){if(O.then){for(e.__u|=f?160:128;a&&a.nodeType==8&&a.nextSibling;)a=a.nextSibling;r!=null&&(r[r.indexOf(a)]=null),e.__e=a}else if(r!=null)for(X=r.length;X--;)_e(r[X])}else e.__e=n.__e;e.__k==null&&(e.__k=n.__k||[]),O.then||Ee(e),y.__e(O,e,n)}}else r==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):a=e.__e=ze(n.__e,e,n,o,_,r,s,f,l);return(d=y.diffed)&&d(e),128&e.__u?void 0:a}function Ee(t){t&&(t.__c&&(t.__c.__e=!0),t.__k&&t.__k.some(Ee))}function Oe(t,e,n){for(var o=0;o<n.length;o++)se(n[o],n[++o],n[++o]);y.__c&&y.__c(e,t),t.some(function(_){try{t=_.__h,_.__h=[],t.some(function(r){r.call(_)})}catch(r){y.__e(r,_.__v)}})}function Ae(t){return typeof t!="object"||t==null||t.__b>0?t:G(t)?t.map(Ae):t.constructor!==void 0?null:N({},t)}function ze(t,e,n,o,_,r,s,a,f){var l,d,p,i,u,h,w,v=n.props||R,k=e.props,m=e.type;if(m=="svg"?_="http://www.w3.org/2000/svg":m=="math"?_="http://www.w3.org/1998/Math/MathML":_||(_="http://www.w3.org/1999/xhtml"),r!=null){for(l=0;l<r.length;l++)if((u=r[l])&&"setAttribute"in u==!!m&&(m?u.localName==m:u.nodeType==3)){t=u,r[l]=null;break}}if(t==null){if(m==null)return document.createTextNode(k);t=document.createElementNS(_,m,k.is&&k),a&&(y.__m&&y.__m(e,r),a=!1),r=null}if(m==null)v===k||a&&t.data==k||(t.data=k);else{if(r=m=="textarea"&&k.defaultValue!=null?null:r&&J.call(t.childNodes),!a&&r!=null)for(v={},l=0;l<t.attributes.length;l++)v[(u=t.attributes[l]).name]=u.value;for(l in v)u=v[l],l=="dangerouslySetInnerHTML"?p=u:l=="children"||l in k||l=="value"&&"defaultValue"in k||l=="checked"&&"defaultChecked"in k||U(t,l,null,u,_);for(l in k)u=k[l],l=="children"?i=u:l=="dangerouslySetInnerHTML"?d=u:l=="value"?h=u:l=="checked"?w=u:a&&typeof u!="function"||v[l]===u||U(t,l,u,v[l],_);if(d)a||p&&(d.__html==p.__html||d.__html==t.innerHTML)||(t.innerHTML=d.__html),e.__k=[];else if(p&&(t.innerHTML=""),Ne(e.type=="template"?t.content:t,G(i)?i:[i],e,n,o,m=="foreignObject"?"http://www.w3.org/1999/xhtml":_,r,s,r?r[0]:n.__k&&H(n,0),a,f),r!=null)for(l=r.length;l--;)_e(r[l]);a&&m!="textarea"||(l="value",m=="progress"&&h==null?t.removeAttribute("value"):h!=null&&(h!==t[l]||m=="progress"&&!h||m=="option"&&h!=v[l])&&U(t,l,h,v[l],_),l="checked",w!=null&&w!=t[l]&&U(t,l,w,v[l],_))}return t}function se(t,e,n){try{if(typeof t=="function"){var o=typeof t.__u=="function";o&&t.__u(),o&&e==null||(t.__u=t(e))}else t.current=e}catch(_){y.__e(_,n)}}function He(t,e,n){var o,_;if(y.unmount&&y.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||se(o,null,e)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(r){y.__e(r,e)}o.base=o.__P=o.__n=null}if(o=t.__k)for(_=0;_<o.length;_++)o[_]&&He(o[_],e,n||typeof t.type!="function");n||_e(t.__e),t.__c=t.__=t.__e=void 0}function qe(t,e,n){return this.constructor(t,n)}function Ke(t,e,n){var o,_,r,s;e==document&&(e=document.documentElement),y.__&&y.__(t,e),_=(o=!1)?null:e.__k,r=[],s=[],le(e,t=e.__k=Fe(V,null,[t]),_||R,R,e.namespaceURI,_?null:e.firstChild?J.call(e.childNodes):null,r,_?_.__e:e.firstChild,o,s),Oe(r,t,s),t.props.children=null}J=z.slice,y={__e:function(t,e,n,o){for(var _,r,s;e=e.__;)if((_=e.__c)&&!_.__)try{if((r=_.constructor)&&r.getDerivedStateFromError!=null&&(_.setState(r.getDerivedStateFromError(t)),s=_.__d),_.componentDidCatch!=null&&(_.componentDidCatch(t,o||{}),s=_.__d),s)return _.__E=_}catch(a){t=a}throw t}},xe=0,j.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=N({},this.state),typeof t=="function"&&(t=t(N({},n),this.props)),t&&N(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),ue(this))},j.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),ue(this))},j.prototype.render=V,P=[],Se=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Te=function(t,e){return t.__v.__b-e.__v.__b},q.__r=0,Y=Math.random().toString(8),D="__d"+Y,M="__a"+Y,Ce=/(PointerCapture)$|Capture$/i,ie=0,ee=fe(!1),te=fe(!0);var Je=0;function c(t,e,n,o,_,r){e||(e={});var s,a,f=e;if("ref"in f)for(a in f={},e)a=="ref"?s=e[a]:f[a]=e[a];var l={type:t,props:f,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Je,__i:-1,__u:0,__source:_,__self:r};if(typeof t=="function"&&(s=t.defaultProps))for(a in s)f[a]===void 0&&(f[a]=s[a]);return y.vnode&&y.vnode(l),l}var K,g,Z,pe,ne=0,Ie=[],b=y,he=b.__b,me=b.__r,ye=b.diffed,ge=b.__c,ve=b.unmount,be=b.__;function Le(t,e){b.__h&&b.__h(g,t,ne||e),ne=0;var n=g.__H||(g.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function x(t){return ne=1,Ge(Be,t)}function Ge(t,e,n){var o=Le(K++,2);if(o.t=t,!o.__c&&(o.__=[Be(void 0,e),function(a){var f=o.__N?o.__N[0]:o.__[0],l=o.t(f,a);f!==l&&(o.__N=[l,o.__[1]],o.__c.setState({}))}],o.__c=g,!g.__f)){var _=function(a,f,l){if(!o.__c.__H)return!0;var d=!1,p=o.__c.props!==a;if(o.__c.__H.__.some(function(u){if(u.__N){d=!0;var h=u.__[0];u.__=u.__N,u.__N=void 0,h!==u.__[0]&&(p=!0)}}),r){var i=r.call(this,a,f,l);return d?i||p:i}return!d||p};g.__f=!0;var r=g.shouldComponentUpdate,s=g.componentWillUpdate;g.componentWillUpdate=function(a,f,l){if(this.__e){var d=r;r=void 0,_(a,f,l),r=d}s&&s.call(this,a,f,l)},g.shouldComponentUpdate=_}return o.__N||o.__}function Me(t,e){var n=Le(K++,3);!b.__s&&Xe(n.__H,e)&&(n.__=t,n.u=e,g.__H.__h.push(n))}function Ve(){for(var t;t=Ie.shift();){var e=t.__H;if(t.__P&&e)try{e.__h.some(W),e.__h.some(re),e.__h=[]}catch(n){e.__h=[],b.__e(n,t.__v)}}}b.__b=function(t){g=null,he&&he(t)},b.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),be&&be(t,e)},b.__r=function(t){me&&me(t),K=0;var e=(g=t.__c).__H;e&&(Z===g?(e.__h=[],g.__h=[],e.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.some(W),e.__h.some(re),e.__h=[],K=0)),Z=g},b.diffed=function(t){ye&&ye(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Ie.push(e)!==1&&pe===b.requestAnimationFrame||((pe=b.requestAnimationFrame)||Qe)(Ve)),e.__H.__.some(function(n){n.u&&(n.__H=n.u,n.u=void 0)})),Z=g=null},b.__c=function(t,e){e.some(function(n){try{n.__h.some(W),n.__h=n.__h.filter(function(o){return!o.__||re(o)})}catch(o){e.some(function(_){_.__h&&(_.__h=[])}),e=[],b.__e(o,n.__v)}}),ge&&ge(t,e)},b.unmount=function(t){ve&&ve(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.some(function(o){try{W(o)}catch(_){e=_}}),n.__H=void 0,e&&b.__e(e,n.__v))};var ke=typeof requestAnimationFrame=="function";function Qe(t){var e,n=function(){clearTimeout(o),ke&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,35);ke&&(e=requestAnimationFrame(n))}function W(t){var e=g,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),g=e}function re(t){var e=g;t.__c=t.__(),g=e}function Xe(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Be(t,e){return typeof e=="function"?e(t):e}let oe=null;function Ue(t){oe=t}async function T(t,e,n){const o={};oe&&(o.Authorization=`Bearer ${oe}`),n!==void 0&&(o["Content-Type"]="application/json");const _=await fetch(e,{method:t,headers:o,body:n!==void 0?JSON.stringify(n):void 0}),r=await _.text(),s=r?JSON.parse(r):null;if(!_.ok){const a=s?.error??s?.message??`${_.status} ${_.statusText}`;throw new Error(a)}return s}const C={challenge:()=>T("POST","/admin/auth/challenge",{}),verify:(t,e)=>T("POST","/admin/auth/verify",{admin_token:t,challenge:e}),logout:()=>T("POST","/admin/auth/logout",{}),me:()=>T("GET","/admin/me"),features:()=>T("GET","/admin/features"),keys:()=>T("GET","/admin/keys").then(t=>t.keys),addKey:(t,e)=>T("POST","/admin/keys",e?{pubkey:t,label:e}:{pubkey:t}),revokeKey:t=>T("DELETE",`/admin/keys/${t}`),config:()=>T("GET","/admin/config"),putConfig:(t,e)=>T("PUT","/admin/config",{patch:t,expected_versions:e}),invites:()=>T("GET","/admin/invites"),mintInvites:(t,e)=>T("POST","/admin/invites",e?{count:t,label:e}:{count:t})};async function we(t){const e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(t));return[...new Uint8Array(e)].map(n=>n.toString(16).padStart(2,"0")).join("")}async function Ye(t,e){const o=`POST
/admin/auth/verify
${await we("")}`,_=await we(o),r=await e.signEvent({kind:27235,created_at:Math.floor(Date.now()/1e3),content:"",tags:[["u",t.url],["method","POST"],["purpose","admin_login"],["challenge",t.challenge],["payload",_],["instance_id",t.instance_id]]});return`Nostr ${btoa(JSON.stringify(r))}`}function Ze(){const t=window.nostr;return t&&typeof t.signEvent=="function"?t:null}function et({onDone:t}){const[e,n]=x(!1),[o,_]=x(null);return c("div",{style:{maxWidth:420,margin:"12vh auto",padding:24,textAlign:"center"},children:[c("div",{style:{fontSize:40},children:"🐸"}),c("h1",{children:"Smirk Operator Console"}),c("p",{style:{color:"var(--smirk-fg-muted)"},children:"Sign in with an admin Nostr key on your instance's allowlist."}),c("button",{class:"primary",style:{padding:"12px 20px",fontSize:16},disabled:e,onClick:async()=>{n(!0),_(null);try{const s=Ze();if(!s)throw new Error("No NIP-07 signer found. Enable your Smirk wallet (or nos2x/Alby) on this origin, then reload.");const a=await C.challenge(),f=await Ye(a,s),{access_token:l}=await C.verify(f,a.challenge);Ue(l),t()}catch(s){_(s instanceof Error?s.message:"Sign-in failed")}finally{n(!1)}},children:e?"Signing in…":"Sign in with Smirk"}),o&&c("p",{style:{color:"var(--smirk-danger)",marginTop:16},children:o})]})}function A({title:t,children:e}){return c("div",{style:{background:"var(--smirk-bg-elevated)",border:"1px solid var(--smirk-border)",borderRadius:"var(--smirk-radius)",padding:16,marginBottom:16},children:[c("h3",{style:{marginTop:0},children:t}),e]})}function Q(t,e=[]){const[n,o]=x(null),[_,r]=x(null),s=()=>{r(null),t().then(o).catch(a=>r(a instanceof Error?a.message:String(a)))};return Me(s,e),{data:n,err:_,reload:s}}function tt(){const{data:t,err:e}=Q(()=>C.features());return c(A,{title:"Instance features",children:[e&&c("p",{style:{color:"var(--smirk-danger)"},children:e}),c("pre",{style:{overflow:"auto",fontSize:12},children:JSON.stringify(t,null,2)})]})}function nt(){const{data:t,err:e,reload:n}=Q(()=>C.keys()),[o,_]=x(""),[r,s]=x(!1),[a,f]=x(null),l=async()=>{s(!0),f(null);try{await C.addKey(o.trim().toLowerCase()),_(""),n()}catch(p){f(p instanceof Error?p.message:String(p))}finally{s(!1)}},d=async p=>{if(confirm("Revoke this admin key?")){f(null);try{await C.revokeKey(p),n()}catch(i){f(i instanceof Error?i.message:String(i))}}};return c(A,{title:"Admin keys",children:[e&&c("p",{style:{color:"var(--smirk-danger)"},children:e}),c("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:c("tbody",{children:(t??[]).map(p=>c("tr",{style:{borderTop:"1px solid var(--smirk-border)"},children:[c("td",{style:{fontFamily:"monospace",padding:"6px 4px"},children:[p.pubkey.slice(0,16),"…"]}),c("td",{style:{padding:"6px 4px"},children:p.status}),c("td",{style:{padding:"6px 4px",textAlign:"right"},children:p.status!=="revoked"&&c("button",{class:"danger",onClick:()=>d(p.id),children:"Revoke"})})]}))})}),c("div",{style:{display:"flex",gap:8,marginTop:12},children:[c("input",{style:{flex:1},placeholder:"new admin pubkey (64 hex)",value:o,onInput:p=>_(p.target.value)}),c("button",{class:"primary",disabled:r||o.trim().length!==64,onClick:l,children:"Add key"})]}),a&&c("p",{style:{color:"var(--smirk-danger)"},children:a})]})}function rt(){const{data:t,err:e,reload:n}=Q(()=>C.invites()),[o,_]=x(5),[r,s]=x(""),[a,f]=x(null),[l,d]=x(!1),[p,i]=x(null),u=async()=>{d(!0),i(null);try{const h=await C.mintInvites(o,r.trim()||void 0);f(h.codes),n()}catch(h){i(h instanceof Error?h.message:String(h))}finally{d(!1)}};return c(A,{title:`Invite codes${t?` — ${t.unused_count} unused`:""}`,children:[e&&c("p",{style:{color:"var(--smirk-danger)"},children:e}),c("div",{style:{display:"flex",gap:8,alignItems:"center",marginBottom:12},children:[c("input",{type:"number",min:1,max:1e3,style:{width:80},value:o,onInput:h=>_(Number(h.target.value))}),c("input",{style:{flex:1},placeholder:"label (optional)",value:r,onInput:h=>s(h.target.value)}),c("button",{class:"primary",disabled:l||o<1,onClick:u,children:"Mint"})]}),p&&c("p",{style:{color:"var(--smirk-danger)"},children:p}),a&&c("div",{style:{background:"var(--smirk-bg-sunken)",padding:12,borderRadius:8,marginBottom:12},children:[c("b",{children:"New codes — copy now, they are shown once:"}),c("pre",{style:{margin:"6px 0 0",whiteSpace:"pre-wrap"},children:a.join(`
`)})]}),c("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:c("tbody",{children:(t?.invites??[]).map(h=>c("tr",{style:{borderTop:"1px solid var(--smirk-border)"},children:[c("td",{style:{fontFamily:"monospace",padding:"6px 4px"},children:[h.code_prefix,"…"]}),c("td",{style:{padding:"6px 4px"},children:h.label??""}),c("td",{style:{padding:"6px 4px",color:"var(--smirk-fg-muted)"},children:h.created_at.slice(0,10)}),c("td",{style:{padding:"6px 4px"},children:h.status})]}))})})]})}function ot(){const{data:t,err:e,reload:n}=Q(()=>C.config()),[o,_]=x({}),[r,s]=x(null);if(Me(()=>{t&&_(l=>{const d={...l};for(const p of Object.keys(t.effective))p in d||(d[p]=structuredClone(t.effective[p]));return d})},[t]),e)return c(A,{title:"Config",children:c("p",{style:{color:"var(--smirk-danger)"},children:e})});if(!t)return c(A,{title:"Config",children:"Loading…"});const a=(l,d,p)=>_(i=>({...i,[l]:{...i[l]??{},[d]:p}})),f=async l=>{s(null);const d=t.effective[l]??{},p=o[l]??{},i={};for(const u of Object.keys(p))JSON.stringify(p[u])!==JSON.stringify(d[u])&&(i[u]=p[u]);if(Object.keys(i).length===0){s(`No changes in ${l}.`);return}try{await C.putConfig({[l]:i},{[l]:t.versions[l]??0}),s(`Saved ${l}.`),n()}catch(u){s(u instanceof Error?u.message:String(u))}};return c("div",{children:[t.restart_pending&&c("div",{style:{background:"rgba(245,158,11,0.12)",border:"1px solid var(--smirk-warn)",borderRadius:8,padding:10,marginBottom:16},children:"⚠ A saved change needs a restart to take effect (systemctl restart, or auto mode)."}),r&&c("p",{style:{color:"var(--smirk-accent)"},children:r}),Object.keys(o).sort().map(l=>c(A,{title:l,children:[Object.entries(o[l]??{}).map(([d,p])=>{const i=t.runtime_class[`${l}.${d}`]??"restart-required",u=t.overlay[l]?.[d]!==void 0;return c("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 0"},children:[c("label",{style:{flex:1,minWidth:0},children:[d," ",c("span",{style:{fontSize:11,color:"var(--smirk-fg-muted)"},children:["· ",i==="restart-required"?"restart":"live",u?" · db":""]})]}),typeof p=="boolean"?c("input",{type:"checkbox",checked:p,onChange:h=>a(l,d,h.target.checked)}):c("input",{style:{width:220},value:String(p??""),onInput:h=>{const w=h.target.value;if(typeof p=="number"){if(w==="")return;const v=Number(w);Number.isNaN(v)||a(l,d,v)}else a(l,d,w)}})]})}),c("button",{class:"primary",style:{marginTop:8},onClick:()=>f(l),children:["Save ",l]})]}))]})}const it=["Status","Keys","Invites","Config"];function _t({onLogout:t}){const[e,n]=x("Status");return c("div",{style:{maxWidth:760,margin:"0 auto",padding:20},children:[c("header",{style:{display:"flex",alignItems:"center",marginBottom:16},children:[c("h2",{style:{margin:0,flex:1},children:"🐸 Smirk Operator Console"}),c("button",{onClick:()=>{C.logout().catch(()=>{}),Ue(null),t()},children:"Sign out"})]}),c("nav",{style:{display:"flex",gap:6,marginBottom:16},children:it.map(o=>c("button",{class:o===e?"primary":"",onClick:()=>n(o),children:o}))}),e==="Status"&&c(tt,{}),e==="Keys"&&c(nt,{}),e==="Invites"&&c(rt,{}),e==="Config"&&c(ot,{})]})}function lt(){const[t,e]=x(!1);return t?c(_t,{onLogout:()=>e(!1)}):c(et,{onDone:()=>e(!0)})}Ke(c(lt,{}),document.getElementById("app"));