import{r as e,j as a}from"./vendor-react-AXa6hZO5.js";import{J as i,b as r,q as t,O as s,K as n,N as o}from"./cec18ad9a-DiLjrOUd.js";import{u as c,a as u}from"./vendor-query-D7SPXjZv.js";const d=e.memo(({code:e,onCopy:r})=>a.jsxs("div",{className:"relative",children:[a.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-all rounded-lg border-0.5 bg-surface-3/50 py-2 pl-2 pr-10 font-mono text-xs text-primary",children:e}),a.jsx(i,{variant:"ghost",iconOnly:!0,icon:"Copy",size:"sm",onClick:r,"aria-label":"Copy to clipboard",className:"absolute right-1 top-1 text-secondary"})]}));d.displayName="CodeBlock";const m=3e5,l="org_services",_="service_keys",v=/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;function y(e){const a=e.indexOf(":");return a>=0?e.substring(a+1):e}const g="anthropic:cccr",p="anthropic:cyber";function b(e){return e===g?"Claude Code Review":e===p?"Claude Security":y(e)}function h(e){return!(0===e.length||e.length>64)&&(!e.includes("--")&&v.test(e))}function f(e){return`external:${e}`}const N=e=>{const{activeOrganization:a}=r();return t(`/api/oauth/organizations/${a?.uuid}/services?limit=100&offset=0`,{queryKey:[l,a?.uuid],staleTime:m,enabled:!!a?.uuid&&(e?.enabled??!0)})},z=e=>{const{activeOrganization:a}=r(),i=n("Query error"),{data:t,isLoading:s,error:o}=N({enabled:e?.enabled}),u=t?.data??[],d=u.filter(e=>e.name.startsWith("external:")),l=c({queries:d.map(e=>({queryKey:[_,a?.uuid,e.name],queryFn:async()=>(await i(`/api/oauth/organizations/${a?.uuid}/services/${e.name}/keys?limit=100&offset=0`,{})).data.map(a=>({...a,org_service_name:e.name})),staleTime:m,enabled:!!a?.uuid&&!0,retry:1}))}),v=l.some(e=>e.isLoading),y=s||v,g=l.filter(e=>e.error),p=!!o||g.length>0,b=[...o?[o]:[],...g.map(e=>e.error)].filter(Boolean);return{data:l.filter(e=>e.data&&!e.error).flatMap(e=>e.data??[]),isLoading:y,services:u,hasError:p,errors:b,failedServiceCount:g.length}},S=e=>{const{activeOrganization:a}=r(),i=u();return o(e=>`/api/oauth/organizations/${a?.uuid}/services/${e.serviceName}/keys`,"POST",{transformVariables:e=>({name:e.name,expires_in_seconds:e.expires_in_seconds,scope:e.scope}),onSuccess:(r,t)=>{i.invalidateQueries({queryKey:[_,a?.uuid,t.serviceName]}),i.setQueryData([l,a?.uuid],e=>{if(!e)return e;return e.data.some(e=>e.name===t.serviceName)?e:{...e,data:[...e.data,{name:t.serviceName,created_at:(new Date).toISOString()}]}}),e?.onSuccess?.(r)},onError:e?.onError})},$=e=>{const{activeOrganization:a}=r(),i=u();return o(e=>`/api/oauth/organizations/${a?.uuid}/services/${e.serviceName}/keys/${e.tokenUuid}/revoke`,"POST",{onSuccess:(r,t)=>{i.setQueryData([_,a?.uuid,t.serviceName],e=>e?.filter(e=>e.id!==t.tokenUuid)??[]),e?.onSuccess?.()},onError:e?.onError})},x=(e,a)=>{const{activeOrganization:i}=r();return t(`/api/organizations/${i?.uuid}/overage_spend_limit?org_service_name=${e}`,{queryKey:[s,i?.uuid,e],staleTime:m,enabled:!!i?.uuid&&!!e&&(a?.enabled??!0)})},O=e=>{const a=(e=>{const{activeOrganization:a}=r(),i=u();return o(`/api/organizations/${a?.uuid}/overage_spend_limit`,"POST",{transformVariables:e=>({org_service_name:e.serviceName,monthly_credit_limit:e.monthly_credit_limit,is_enabled:e.is_enabled??!0}),onSuccess:(r,t)=>{i.setQueryData([s,a?.uuid,t.serviceName],r),e?.onSuccess?.(r)},onError:e?.onError})})(e),i=(e=>{const{activeOrganization:a}=r(),i=u();return o(`/api/organizations/${a?.uuid}/overage_spend_limit`,"PUT",{transformVariables:e=>({org_service_name:e.serviceName,monthly_credit_limit:e.monthly_credit_limit,is_enabled:e.is_enabled}),onSuccess:(r,t)=>{i.setQueryData([s,a?.uuid,t.serviceName],r),e?.onSuccess?.(r)},onError:e?.onError})})(e);return{mutate:(e,r)=>{e.isUpdate?i.mutate({serviceName:e.serviceName,monthly_credit_limit:e.monthly_credit_limit,is_enabled:e.is_enabled},r):a.mutate({serviceName:e.serviceName,monthly_credit_limit:e.monthly_credit_limit,is_enabled:e.is_enabled},r)},mutateAsync:async e=>e.isUpdate?i.mutateAsync({serviceName:e.serviceName,monthly_credit_limit:e.monthly_credit_limit,is_enabled:e.is_enabled}):a.mutateAsync({serviceName:e.serviceName,monthly_credit_limit:e.monthly_credit_limit,is_enabled:e.is_enabled}),isPending:a.isPending||i.isPending}},E=e=>{const{activeOrganization:a}=r(),i=u();return o(e=>`/api/oauth/organizations/${a?.uuid}/services/${e.serviceName}`,"DELETE",{onSuccess:(r,t)=>{i.setQueryData([l,a?.uuid],e=>e?{...e,data:e.data.filter(e=>e.name!==t.serviceName)}:e),i.removeQueries({queryKey:[_,a?.uuid,t.serviceName]}),e?.onSuccess?.()},onError:e?.onError})};function k(e){return e.startsWith("external:")}export{d as C,g as a,O as b,p as c,N as d,y as e,S as f,b as g,f as h,h as i,z as j,$ as k,E as l,k as m,x as u};
