ManagedACLTab-DBnl7SO6.js raw

   1  import{j as e,T as N,d as S,e as b,f as j,r as t,t as i,I as p,B as h,b as k}from"./index-DfKg850Q.js";async function y(r,x=[]){const l=await k.nip86Request(r,x);if(l.error)throw new Error(l.error);return l.result}function v({children:r,empty:x}){const l=Array.isArray(r)?r.length>0:!!r;return e.jsx("div",{className:"rounded-lg border border-border bg-card max-h-72 overflow-y-auto",children:l?r:e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground italic",children:x})})}function g({children:r}){return e.jsx("div",{className:"flex items-center gap-3 border-b border-border px-3 py-2 last:border-b-0 text-sm",children:r})}function E(){const[r,x]=t.useState([]),[l,c]=t.useState(""),[d,f]=t.useState(""),[n,a]=t.useState(!1),o=t.useCallback(async()=>{try{const s=await y("listbannedpubkeys");x(Array.isArray(s)?s:[])}catch(s){i.error(`Load banned pubkeys: ${s instanceof Error?s.message:String(s)}`)}},[]);t.useEffect(()=>{o()},[o]);const u=async()=>{if(l.trim()){a(!0);try{await y("banpubkey",[l.trim(),d.trim()]),i.success("Pubkey banned"),c(""),f(""),await o()}catch(s){i.error(`Ban failed: ${s instanceof Error?s.message:String(s)}`)}finally{a(!1)}}};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Banned Pubkeys"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(p,{className:"flex-1 min-w-[200px]",placeholder:"Pubkey (64 hex chars)",value:l,onChange:s=>c(s.target.value)}),e.jsx(p,{className:"flex-1 min-w-[140px]",placeholder:"Reason (optional)",value:d,onChange:s=>f(s.target.value)}),e.jsx(h,{size:"sm",onClick:u,disabled:n,children:"Ban Pubkey"})]}),e.jsx(v,{empty:"No banned pubkeys.",children:r.map((s,m)=>e.jsxs(g,{children:[e.jsx("span",{className:"font-mono text-xs break-all flex-1",children:s.pubkey}),s.reason&&e.jsx("span",{className:"text-muted-foreground italic text-xs",children:s.reason})]},m))})]})}function C(){const[r,x]=t.useState([]),[l,c]=t.useState(""),[d,f]=t.useState(""),[n,a]=t.useState(!1),o=t.useCallback(async()=>{try{const s=await y("listallowedpubkeys");x(Array.isArray(s)?s:[])}catch(s){i.error(`Load allowed pubkeys: ${s instanceof Error?s.message:String(s)}`)}},[]);t.useEffect(()=>{o()},[o]);const u=async()=>{if(l.trim()){a(!0);try{await y("allowpubkey",[l.trim(),d.trim()]),i.success("Pubkey allowed"),c(""),f(""),await o()}catch(s){i.error(`Allow failed: ${s instanceof Error?s.message:String(s)}`)}finally{a(!1)}}};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Allowed Pubkeys"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(p,{className:"flex-1 min-w-[200px]",placeholder:"Pubkey (64 hex chars)",value:l,onChange:s=>c(s.target.value)}),e.jsx(p,{className:"flex-1 min-w-[140px]",placeholder:"Reason (optional)",value:d,onChange:s=>f(s.target.value)}),e.jsx(h,{size:"sm",onClick:u,disabled:n,children:"Allow Pubkey"})]}),e.jsx(v,{empty:"No allowed pubkeys.",children:r.map((s,m)=>e.jsxs(g,{children:[e.jsx("span",{className:"font-mono text-xs break-all flex-1",children:s.pubkey}),s.reason&&e.jsx("span",{className:"text-muted-foreground italic text-xs",children:s.reason})]},m))})]})}function A(){const[r,x]=t.useState([]),[l,c]=t.useState(""),[d,f]=t.useState(""),[n,a]=t.useState(!1),o=t.useCallback(async()=>{try{const s=await y("listbannedevents");x(Array.isArray(s)?s:[])}catch(s){i.error(`Load banned events: ${s instanceof Error?s.message:String(s)}`)}},[]);t.useEffect(()=>{o()},[o]);const u=async()=>{if(l.trim()){a(!0);try{await y("banevent",[l.trim(),d.trim()]),i.success("Event banned"),c(""),f(""),await o()}catch(s){i.error(`Ban failed: ${s instanceof Error?s.message:String(s)}`)}finally{a(!1)}}};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Banned Events"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(p,{className:"flex-1 min-w-[200px]",placeholder:"Event ID (64 hex chars)",value:l,onChange:s=>c(s.target.value)}),e.jsx(p,{className:"flex-1 min-w-[140px]",placeholder:"Reason (optional)",value:d,onChange:s=>f(s.target.value)}),e.jsx(h,{size:"sm",onClick:u,disabled:n,children:"Ban Event"})]}),e.jsx(v,{empty:"No banned events.",children:r.map((s,m)=>e.jsxs(g,{children:[e.jsx("span",{className:"font-mono text-xs break-all flex-1",children:s.id}),s.reason&&e.jsx("span",{className:"text-muted-foreground italic text-xs",children:s.reason})]},m))})]})}function I(){const[r,x]=t.useState(""),[l,c]=t.useState(""),[d,f]=t.useState(!1),n=async()=>{if(r.trim()){f(!0);try{await y("allowevent",[r.trim(),l.trim()]),i.success("Event allowed"),x(""),c("")}catch(a){i.error(`Allow failed: ${a instanceof Error?a.message:String(a)}`)}finally{f(!1)}}};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Allow Event"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(p,{className:"flex-1 min-w-[200px]",placeholder:"Event ID (64 hex chars)",value:r,onChange:a=>x(a.target.value)}),e.jsx(p,{className:"flex-1 min-w-[140px]",placeholder:"Reason (optional)",value:l,onChange:a=>c(a.target.value)}),e.jsx(h,{size:"sm",onClick:n,disabled:d,children:"Allow Event"})]})]})}function R(){const[r,x]=t.useState([]),[l,c]=t.useState(""),[d,f]=t.useState(!1),n=t.useCallback(async()=>{try{const u=await y("listallowedkinds");x(Array.isArray(u)?u:[])}catch(u){i.error(`Load allowed kinds: ${u instanceof Error?u.message:String(u)}`)}},[]);t.useEffect(()=>{n()},[n]);const a=async()=>{const u=parseInt(l,10);if(isNaN(u)){i.error("Invalid kind number");return}f(!0);try{await y("allowkind",[u]),i.success(`Kind ${u} allowed`),c(""),await n()}catch(s){i.error(`Allow kind failed: ${s instanceof Error?s.message:String(s)}`)}finally{f(!1)}},o=async u=>{f(!0);try{await y("disallowkind",[u]),i.success(`Kind ${u} disallowed`),await n()}catch(s){i.error(`Disallow kind failed: ${s instanceof Error?s.message:String(s)}`)}finally{f(!1)}};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Allowed Event Kinds"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(p,{className:"w-40",type:"number",placeholder:"Kind number",value:l,onChange:u=>c(u.target.value)}),e.jsx(h,{size:"sm",onClick:a,disabled:d,children:"Allow Kind"})]}),e.jsx(v,{empty:"No allowed kinds configured. All kinds are allowed by default.",children:r.map(u=>e.jsxs(g,{children:[e.jsxs("span",{className:"font-mono text-xs flex-1",children:["Kind ",u]}),e.jsx(h,{variant:"ghost-destructive",size:"sm",onClick:()=>o(u),disabled:d,children:"Remove"})]},u))})]})}function P(){const[r,x]=t.useState([]),[l,c]=t.useState(""),[d,f]=t.useState(""),[n,a]=t.useState(!1),o=t.useCallback(async()=>{try{const m=await y("listblockedips");x(Array.isArray(m)?m:[])}catch(m){i.error(`Load blocked IPs: ${m instanceof Error?m.message:String(m)}`)}},[]);t.useEffect(()=>{o()},[o]);const u=async()=>{if(l.trim()){a(!0);try{await y("blockip",[l.trim(),d.trim()]),i.success("IP blocked"),c(""),f(""),await o()}catch(m){i.error(`Block failed: ${m instanceof Error?m.message:String(m)}`)}finally{a(!1)}}},s=async m=>{a(!0);try{await y("unblockip",[m]),i.success("IP unblocked"),await o()}catch(w){i.error(`Unblock failed: ${w instanceof Error?w.message:String(w)}`)}finally{a(!1)}};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Blocked IPs"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(p,{className:"flex-1 min-w-[160px]",placeholder:"IP address",value:l,onChange:m=>c(m.target.value)}),e.jsx(p,{className:"flex-1 min-w-[140px]",placeholder:"Reason (optional)",value:d,onChange:m=>f(m.target.value)}),e.jsx(h,{size:"sm",onClick:u,disabled:n,children:"Block IP"})]}),e.jsx(v,{empty:"No blocked IPs.",children:r.map((m,w)=>e.jsxs(g,{children:[e.jsx("span",{className:"font-mono text-xs flex-1",children:m.ip}),m.reason&&e.jsx("span",{className:"text-muted-foreground italic text-xs",children:m.reason}),e.jsx(h,{variant:"ghost-destructive",size:"sm",onClick:()=>s(m.ip),disabled:n,children:"Unblock"})]},w))})]})}function B(){const[r,x]=t.useState([]),[l,c]=t.useState(!1),d=t.useCallback(async()=>{c(!0);try{const a=await y("listeventsneedingmoderation");x(Array.isArray(a)?a:[])}catch(a){i.error(`Load moderation queue: ${a instanceof Error?a.message:String(a)}`),x([])}finally{c(!1)}},[]);t.useEffect(()=>{d()},[d]);const f=async a=>{c(!0);try{await y("allowevent",[a,"Approved from moderation queue"]),i.success("Event approved"),await d()}catch(o){i.error(`Approve failed: ${o instanceof Error?o.message:String(o)}`)}finally{c(!1)}},n=async a=>{c(!0);try{await y("banevent",[a,"Rejected from moderation queue"]),i.success("Event rejected"),await d()}catch(o){i.error(`Reject failed: ${o instanceof Error?o.message:String(o)}`)}finally{c(!1)}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Events Needing Moderation"}),e.jsx(h,{variant:"outline",size:"sm",onClick:d,disabled:l,children:l?"Loading...":"Refresh"})]}),e.jsx(v,{empty:"No events need moderation.",children:r.map((a,o)=>e.jsxs(g,{children:[e.jsx("span",{className:"font-mono text-xs break-all flex-1",children:a.id}),a.reason&&e.jsx("span",{className:"text-muted-foreground italic text-xs",children:a.reason}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsx(h,{size:"sm",onClick:()=>f(a.id),disabled:l,children:"Allow"}),e.jsx(h,{variant:"destructive",size:"sm",onClick:()=>n(a.id),disabled:l,children:"Ban"})]})]},o))})]})}function $(){const[r,x]=t.useState({relay_name:"",relay_description:"",relay_icon:""}),[l,c]=t.useState(!1),d=t.useCallback(async()=>{c(!0);try{const n=await k.fetchRelayInfo();n&&x({relay_name:n.name||"",relay_description:n.description||"",relay_icon:n.icon||""})}catch(n){i.error(`Fetch relay info: ${n instanceof Error?n.message:String(n)}`)}finally{c(!1)}},[]);t.useEffect(()=>{d()},[d]);const f=async()=>{c(!0);try{const n=[];if(r.relay_name&&n.push(y("changerelayname",[r.relay_name])),r.relay_description&&n.push(y("changerelaydescription",[r.relay_description])),r.relay_icon&&n.push(y("changerelayicon",[r.relay_icon])),n.length===0){i.info("No changes to update");return}await Promise.all(n),i.success("Relay configuration updated"),await d()}catch(n){i.error(`Update failed: ${n instanceof Error?n.message:String(n)}`)}finally{c(!1)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Relay Configuration"}),e.jsx(h,{variant:"outline",size:"sm",onClick:d,disabled:l,children:"Refresh"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",htmlFor:"acl-relay-name",children:"Relay Name"}),e.jsx(p,{id:"acl-relay-name",placeholder:"Enter relay name",value:r.relay_name,onChange:n=>x(a=>({...a,relay_name:n.target.value}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",htmlFor:"acl-relay-desc",children:"Relay Description"}),e.jsx("textarea",{id:"acl-relay-desc",className:"flex w-full rounded-lg border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:border-ring min-h-[80px] resize-y",placeholder:"Enter relay description",value:r.relay_description,onChange:n=>x(a=>({...a,relay_description:n.target.value}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",htmlFor:"acl-relay-icon",children:"Relay Icon URL"}),e.jsx(p,{id:"acl-relay-icon",type:"url",placeholder:"Enter icon URL",value:r.relay_icon,onChange:n=>x(a=>({...a,relay_icon:n.target.value}))})]})]}),e.jsx(h,{onClick:f,disabled:l,children:l?"Saving...":"Save Configuration"})]})}function L(){return e.jsxs("div",{className:"p-4 space-y-4 w-full",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Managed ACL Configuration"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"NIP-86 relay management"}),e.jsxs("div",{className:"mt-2 rounded-md bg-yellow-500/10 border border-yellow-500/30 px-3 py-2 text-sm",children:[e.jsx("span",{className:"font-semibold",children:"Owner only"})," -- this interface is restricted to relay owners."]})]}),e.jsxs(N,{defaultValue:"pubkeys",children:[e.jsxs(S,{className:"flex flex-wrap h-auto gap-1",children:[e.jsx(b,{value:"pubkeys",children:"Pubkeys"}),e.jsx(b,{value:"events",children:"Events"}),e.jsx(b,{value:"ips",children:"IPs"}),e.jsx(b,{value:"kinds",children:"Kinds"}),e.jsx(b,{value:"moderation",children:"Moderation"}),e.jsx(b,{value:"relay",children:"Relay Config"})]}),e.jsxs(j,{value:"pubkeys",className:"space-y-6",children:[e.jsx(E,{}),e.jsx(C,{})]}),e.jsxs(j,{value:"events",className:"space-y-6",children:[e.jsx(A,{}),e.jsx(I,{})]}),e.jsx(j,{value:"ips",children:e.jsx(P,{})}),e.jsx(j,{value:"kinds",children:e.jsx(R,{})}),e.jsx(j,{value:"moderation",children:e.jsx(B,{})}),e.jsx(j,{value:"relay",children:e.jsx($,{})})]})]})}export{L as default};
   2