unleash-server 5.9.0 → 5.9.2

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.
Files changed (48) hide show
  1. package/dist/lib/db/feature-tag-store.js +1 -1
  2. package/dist/lib/db/feature-tag-store.js.map +1 -1
  3. package/dist/lib/features/client-feature-toggles/client-feature-toggle-store.js +2 -2
  4. package/dist/lib/features/client-feature-toggles/client-feature-toggle-store.js.map +1 -1
  5. package/dist/lib/features/instance-stats/instance-stats-service.js +1 -1
  6. package/dist/lib/features/instance-stats/instance-stats-service.js.map +1 -1
  7. package/dist/lib/features/maintenance/maintenance-service.d.ts +1 -0
  8. package/dist/lib/features/maintenance/maintenance-service.d.ts.map +1 -1
  9. package/dist/lib/features/maintenance/maintenance-service.js +21 -3
  10. package/dist/lib/features/maintenance/maintenance-service.js.map +1 -1
  11. package/dist/lib/features/scheduler/scheduler-service.d.ts.map +1 -1
  12. package/dist/lib/features/scheduler/scheduler-service.js +2 -3
  13. package/dist/lib/features/scheduler/scheduler-service.js.map +1 -1
  14. package/dist/lib/routes/admin-api/config.js +1 -1
  15. package/dist/lib/routes/admin-api/config.js.map +1 -1
  16. package/dist/lib/services/version-service.d.ts +2 -3
  17. package/dist/lib/services/version-service.d.ts.map +1 -1
  18. package/dist/lib/services/version-service.js +13 -14
  19. package/dist/lib/services/version-service.js.map +1 -1
  20. package/dist/lib/services/version-service.test.js +3 -3
  21. package/dist/lib/services/version-service.test.js.map +1 -1
  22. package/dist/server-dev.js +1 -0
  23. package/dist/server-dev.js.map +1 -1
  24. package/frontend/build/index.html +1 -1
  25. package/frontend/build/static/{AdvancedPlayground-DoQ1u8B6.js → AdvancedPlayground-FbP1gTKc.js} +1 -1
  26. package/frontend/build/static/{CreateProject-iLBz5afO.js → CreateProject-vjn1sh4D.js} +1 -1
  27. package/frontend/build/static/{FeatureArchiveDialog-NSAcrt7Z.js → FeatureArchiveDialog-ctoNJoqg.js} +1 -1
  28. package/frontend/build/static/{FeatureMetricsChart-UhDepK_o.js → FeatureMetricsChart-ig6HN-Ms.js} +1 -1
  29. package/frontend/build/static/FeatureViewLazyExport-G75iq0Uc.js +25 -0
  30. package/frontend/build/static/{LazyAdminExport-w5iLam_A.js → LazyAdminExport-oCRFK_R5.js} +2 -2
  31. package/frontend/build/static/{LazyProjectExport-iqGbEmyw.js → LazyProjectExport-Ul0xAhZq.js} +1 -1
  32. package/frontend/build/static/{LineChartComponent-rG1KLVNr.js → LineChartComponent-3-eT314R.js} +1 -1
  33. package/frontend/build/static/{NetworkOverview-7SCGp57r.js → NetworkOverview-d20eBsIq.js} +2 -2
  34. package/frontend/build/static/{NetworkTraffic-awTd8Zg5.js → NetworkTraffic-_52gjNiG.js} +1 -1
  35. package/frontend/build/static/{ReactJSONEditor-N-DWXE0h.js → ReactJSONEditor-0HyqnatD.js} +1 -1
  36. package/frontend/build/static/{RoleCell-mJ7DV61l.js → RoleCell--QIy8Oj_.js} +1 -1
  37. package/frontend/build/static/{StrategyItemContainer-wxQbaPXr.js → StrategyItemContainer-X6EIzBwJ.js} +1 -1
  38. package/frontend/build/static/{flowchart-elk-definition-170a3958-fa48ti80.js → flowchart-elk-definition-170a3958-XjUu-j5x.js} +1 -1
  39. package/frontend/build/static/{index-pAMHRYpv.js → index-UE-HeGu0.js} +1 -1
  40. package/frontend/build/static/{index-p2PlVFLf.js → index-uUGk-gee.js} +104 -104
  41. package/frontend/build/static/{is_dark-aAyqOy_I.js → is_dark-8v9B-WN0.js} +1 -1
  42. package/frontend/build/static/{mindmap-definition-44684416-AfCKDD9v.js → mindmap-definition-44684416-5sTvrm1Q.js} +1 -1
  43. package/frontend/build/static/{timeline-definition-8e5a9bc6-NKNlIEgm.js → timeline-definition-8e5a9bc6-MtFefIHV.js} +1 -1
  44. package/frontend/build/static/{unknownify-g-QgUElr.js → unknownify-joALjS6W.js} +1 -1
  45. package/frontend/build/static/{useApiTokens-hvnEZWgJ.js → useApiTokens-gCm2i_7X.js} +1 -1
  46. package/frontend/build/static/{useProjectForm-zqz6LJw4.js → useProjectForm-oXjjbjX3.js} +1 -1
  47. package/package.json +1 -1
  48. package/frontend/build/static/FeatureViewLazyExport-SpKYIb_J.js +0 -25
@@ -0,0 +1,25 @@
1
+ import{c as ht,j as t,s as p,aE as A,aF as M,aG as Qn,aH as Zn,C as b,aI as re,aJ as Ce,aK as Q,aL as we,aM as Xn,aN as We,r as g,aO as ge,aP as ye,aQ as ft,aR as es,aS as ts,aT as ns,aU as ss,b as U,aV as se,aW as te,f as V,T as W,aX as Fe,aY as he,aZ as on,a_ as Z,a$ as de,t as ee,x as $e,b0 as as,b1 as rs,b2 as ke,M as ue,b3 as Te,b4 as cn,b5 as me,b6 as ln,b7 as oe,ay as ce,b8 as Ue,J as ie,b9 as os,ba as is,bb as cs,bc as ut,bd as ls,be as ds,B as K,bf as us,bg as ps,bh as gs,bi as hs,bj as fs,bk as xs,bl as ms,bm as dn,bn as ys,bo as Rt,bp as un,aw as js,bq as Ss,a as xt,ac as Ie,br as Ye,G as Ee,K as bs,bs as mt,h as je,bt as Ae,bu as pn,bv as yt,bw as jt,bx as St,ax as fe,aj as ae,by as bt,bz as gn,aA as Ge,bA as hn,bB as fn,bC as xn,bD as vs,bE as vt,R as Ct,bF as mn,Y as Cs,bG as wt,bH as ve,bI as pe,bJ as yn,a1 as jn,bK as ws,bL as le,bM as Ts,bN as Es,X as As,ai as Ds,bO as Fs,bP as Rs,bQ as $s,bR as ks,bS as Is,bT as Ps,u as Os,bU as Sn,bV as Tt,bW as Bs,bX as Ls,bY as $t,bZ as bn,b_ as vn,b$ as _s,c0 as Cn,c1 as Ms,c2 as qs,c3 as zs,c4 as Et,c5 as Ns,c6 as Ke,c7 as Vs,Q as wn,D as Re,c8 as Hs,c9 as Ws,ca as Us,cb as Ys,cc as Tn,cd as En,ce as Gs,cf as Ks,cg as _e,ch as An,ci as Dn,cj as Fn,ck as xe,cl as pt,cm as Js,cn as Rn,co as Qs,cp as Zs,e as Xs,cq as ea,cr as kt,av as ta,cs as be,ct as It,cu as na,cv as sa,cw as aa,l as ra,at as At,au as oa,ao as Pt,cx as ia,cy as ca,cz as la,cA as Ot,ab as Ne,cB as da,a3 as Ze,af as ua,a5 as pa,a6 as ga,a7 as ha,a8 as fa,a9 as xa,aa as ma,cC as ya,cD as ja,cE as Bt,cF as Sa,cG as ba,cH as Xe,cI as va,cJ as Ca,cK as wa,cL as $n,q as Ta,cM as Lt,cN as Ea,cO as Aa,cP as Da,cQ as Fa,cR as Ra,cS as $a,al as ka,cT as Ia,cU as Pa,cV as Oa,cW as Ba,cX as La,cY as _a,cZ as Ma,c_ as qa}from"./index-uUGk-gee.js";import{C as kn,u as In,a as za,F as Na,V as Va,b as Ha,c as Wa,T as Ua,d as Ya,W as Ga,e as Ka,f as Ja}from"./FeatureArchiveDialog-ctoNJoqg.js";import{S as Qa}from"./StrategyItemContainer-X6EIzBwJ.js";const Za=ht(t.jsx("path",{d:"m20.54 5.23-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5 6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z"}),"Archive"),Xa=ht(t.jsx("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"}),"Assessment"),er=ht(t.jsx("path",{d:"M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z"}),"LibraryAdd"),tr=p("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),nr=()=>{const e=A("projectId"),n=A("featureId"),{feature:s}=M(e,n);return s.name?t.jsx(tr,{children:t.jsx(Qn,{title:"Event log",feature:n,displayInline:!0})}):null},sr=p("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,color:e.palette.primary.contrastText,backgroundColor:e.palette.background.alternative,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:e.spacing(2),[e.breakpoints.down(1e3)]:{width:"100%",maxWidth:"none",minWidth:"auto"}})),ar=p("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),rr=p("div")({display:"flex",alignItems:"center"}),or=p("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),ir=p("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),_t=p("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize})),Mt=p("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),cr=()=>{const e=A("projectId"),n=A("featureId"),{feature:s}=M(e,n),{project:r,description:a,type:o}=s,i=Xn(o);return t.jsx(sr,{children:t.jsxs(ar,{children:[t.jsxs(rr,{"data-loading":!0,children:[t.jsx(i,{sx:c=>({marginRight:c.spacing(2),height:"40px",width:"40px",fill:c.palette.primary.contrastText})})," ",t.jsxs(or,{children:[Zn(o||"")," toggle"]})]}),t.jsxs(ir,{children:[t.jsxs(_t,{"data-loading":!0,children:["Project: ",r]}),t.jsx(b,{condition:!!a,show:t.jsxs(_t,{"data-loading":!0,children:[t.jsx("div",{children:"Description:"}),t.jsxs(Mt,{children:[t.jsx("p",{children:a}),t.jsx(re,{projectId:e,permission:Ce,component:Q,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t.jsx(we,{sx:c=>({color:c.palette.primary.contrastText})})})]})]}),elseShow:t.jsx("span",{"data-loading":!0,children:t.jsxs(Mt,{children:["No description."," ",t.jsx(re,{projectId:e,permission:Ce,component:Q,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t.jsx(we,{sx:c=>({color:c.palette.primary.contrastText})})})]})})})]})]})})},qt={lastHourUsage:[],seenApplications:[]},lr=(e,n,s={})=>{const r=async()=>{const u=ge(`api/admin/client-metrics/features/${n}`),h=await fetch(u,{method:"GET"}).then(ye("feature metrics"));return h.ok?h.json():qt},a=`${e}_${n}_metrics`,{data:o,error:i}=We(a,r,{...s}),[c,l]=g.useState(!i&&!o),d=()=>{ft(a)};return g.useEffect(()=>{l(!i&&!o)},[o,i]),{metrics:o||qt,error:i,loading:c,refetch:d,FEATURE_METRICS_CACHE_KEY:a}},dr=e=>({yes:0,no:0,environment:e,timestamp:""}),ur=(e,n)=>e.map(s=>n.lastHourUsage.find(a=>a.environment===s.name)||dr(s.name)),pr=e=>(n,s,r)=>(r.revalidateOnFocus=!1,r.revalidateIfStale=!1,r.revalidateOnReconnect=!1,e(n,s,r)),gr=es(We,pr),Pn=(e,n)=>{const{refetchFeature:s}=M(e,n),r=ts(e,n),{data:a,error:o,mutate:i}=gr(["useFeatureImmutable",r],()=>ns(r)),c=g.useCallback(async()=>{await i(),await s()},[i,s]);return{feature:(a==null?void 0:a.body)||ss,refetchFeature:c,loading:!o&&!a,status:a==null?void 0:a.status,error:o}},On=(e,n,s)=>{const{setToastData:r,setToastApiError:a}=U(),{addChange:o}=se(),{refetch:i}=te(e),[c,l]=g.useState({isOpen:!1}),d=g.useCallback((y,T,f)=>{l({featureName:n,environment:y,fromEnvironment:f,strategy:T,isOpen:!0})},[]),u=g.useCallback((y,T,f)=>{l({featureName:n,environment:y,fromEnvironment:f,strategies:T,isOpen:!0})},[]),h=g.useCallback(()=>{l({isOpen:!1})},[]),m=g.useCallback(async()=>{try{await o(e,c.environment,{feature:c.featureName,action:s,payload:c.strategy}),i(),l({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(y){a(V(y)),l({isOpen:!1})}},[o]),j=g.useCallback(async()=>{try{await Promise.all(c.strategies.map(y=>o(e,c.environment,{feature:c.featureName,action:s,payload:y}))),i(),l({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(y){a(V(y)),l({isOpen:!1})}},[o]);return{onChangeRequestAddStrategy:d,onChangeRequestAddStrategies:u,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:m,onChangeRequestAddStrategiesConfirm:j,changeRequestDialogDetails:c}},hr=({payload:e,fromEnvironment:n,environment:s})=>t.jsxs(W,{children:[t.jsxs("strong",{children:["Copy ",Fe((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",s]}),fr=({environmentId:e,environments:n,strategy:s})=>{const r=A("projectId"),a=A("featureId"),[o,i]=g.useState(null),c=!!o,{addStrategyToFeature:l}=he(),{setToastData:d,setToastApiError:u}=U(),{refetchFeature:h}=M(r,a),{refetchFeature:m}=Pn(r,a),j=()=>{i(null)},y=on(r),{isChangeRequestConfigured:T}=Z(r),{changeRequestDialogDetails:f,onChangeRequestAddStrategyClose:x,onChangeRequestAddStrategy:R,onChangeRequestAddStrategyConfirm:L}=On(r,a,"addStrategy"),q=async v=>{const{id:C,...$}={...s,targetEnvironment:v};if(T(v)){await R(v,{id:C,...$},e);return}try{await l(r,a,v,s),h(),m(),d({title:"Strategy created",text:`Successfully copied a strategy to ${v}`,type:"success"})}catch(O){u(V(O))}j()},z=n.some(v=>y(de,v));return t.jsxs("div",{children:[t.jsx(kn,{isOpen:f.isOpen,onClose:x,environment:f==null?void 0:f.environment,onConfirm:L,messageComponent:t.jsx(hr,{fromEnvironment:f.fromEnvironment,payload:f.strategy})}),t.jsx(ee,{title:`Copy to another environment${z?"":" (Access denied)"}`,children:t.jsx("div",{children:t.jsx($e,{size:"large",id:`copy-strategy-icon-menu-${s.id}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:v=>{i(v.currentTarget)},"data-testid":as,disabled:!z,children:t.jsx(rs,{})})})}),t.jsx(ke,{id:"basic-menu",anchorEl:o,open:c,onClose:j,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${s.id}`},children:n.map(v=>{const C=y(de,v);return t.jsx(ee,{title:C?"":"You don't have access to add a strategy to this environment",children:t.jsx("div",{children:t.jsxs(ue,{onClick:()=>q(v),disabled:!C,children:[t.jsx(b,{condition:!C,show:t.jsx(Te,{children:t.jsx(cn,{fontSize:"small"})})}),t.jsxs(me,{children:["Copy to ",v]})]})})},v)})})]})},xr=()=>t.jsx(ie,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),mr=p("div")(({theme:e})=>({"> * + *":{marginTop:e.spacing(1)}})),yr=({changeRequests:e,projectId:n})=>e&&e.length>0?t.jsxs(ie,{severity:"warning",children:[t.jsx("p",{children:"This strategy is in use by at least one scheduled change request. If you remove it, those change requests can no longer be applied."}),t.jsx("p",{children:"The following scheduled change requests use this strategy:"}),t.jsx("ul",{children:e.map(({id:s,title:r})=>{const a=r?`#${s} (${r})`:`#${s}`;return t.jsx("li",{children:t.jsx(Q,{to:`/projects/${n}/change-requests/${s}`,target:"_blank",rel:"noopener noreferrer",title:`Change request ${s}`,children:a})},s)})})]}):e===void 0?t.jsx(ie,{severity:"warning",children:t.jsx("p",{children:"This strategy may be in use by one or more scheduled change requests. If you remove it, those change requests can no longer be applied."})}):null,Bn=({scheduledChangeRequestsForStrategy:e})=>t.jsxs(mr,{children:[t.jsx(xr,{}),t.jsx(yr,{projectId:e.projectId,changeRequests:e.changeRequests})]}),jr=({onRemove:e,onClose:n,isOpen:s,scheduledChangeRequestsForStrategy:r})=>t.jsx(oe,{title:"Are you sure you want to delete this strategy?",open:s,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t.jsx(Bn,{scheduledChangeRequestsForStrategy:r})}),Sr=p("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),br=({onRemove:e,onClose:n,isOpen:s,scheduledChangeRequestsForStrategy:r})=>t.jsxs(oe,{title:"Suggest changes",open:s,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t.jsx(Bn,{scheduledChangeRequestsForStrategy:r}),t.jsx(Sr,{children:t.jsx(W,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t.jsx(W,{fontWeight:"bold",children:"Remove strategy"})]}),vr=({projectId:e,featureId:n,environmentId:s,strategyId:r})=>{const{deleteStrategyFromFeature:a}=he(),{setToastData:o,setToastApiError:i}=U(),c=ce(),{refetchFeature:l}=M(e,n);return async u=>{try{u.preventDefault(),await a(e,n,s,r),o({title:"Strategy deleted",type:"success"}),l(),c(Ue(e,n))}catch(h){i(V(h))}}},Cr=({projectId:e,featureId:n,environmentId:s,strategyId:r})=>{const{addChange:a}=se(),{refetch:o}=te(e),{setToastData:i,setToastApiError:c}=U();return async d=>{try{d.preventDefault(),await a(e,s,{action:"deleteStrategy",feature:n,payload:{id:r}}),i({title:"Changes added to the draft!",type:"success"}),await o()}catch(u){c(V(u))}}},wr=({projectId:e,featureId:n,environmentId:s,strategyId:r,isOpen:a,onClose:o})=>{const{isChangeRequestConfigured:i}=Z(e),{changeRequests:c}=ln(e,r),l={changeRequests:c,projectId:e},d=vr({featureId:n,projectId:e,strategyId:r,environmentId:s}),u=Cr({featureId:n,projectId:e,strategyId:r,environmentId:s});return i(s)?t.jsx(br,{isOpen:a,onClose:()=>o(),onRemove:async h=>{await u(h),o()},scheduledChangeRequestsForStrategy:l}):t.jsx(jr,{isOpen:a,onClose:()=>o(),onRemove:d,scheduledChangeRequestsForStrategy:l})},Tr=({projectId:e,environmentId:n,featureId:s,strategy:r})=>{const{refetchFeature:a}=M(e,s),{setStrategyDisabledState:o}=he(),{setToastData:i,setToastApiError:c}=U(),l=d=>async()=>{try{await o(e,s,n,r.id,!d),i({title:`Strategy ${d?"enabled":"disabled"}`,type:"success"}),a()}catch(u){c(V(u))}};return{onDisable:l(!1),onEnable:l(!0)}},Er=({projectId:e,environmentId:n,featureId:s,strategy:r})=>{const{addChange:a}=se(),{refetch:o}=te(e),{setToastData:i,setToastApiError:c}=U(),l=d=>async()=>{try{await a(e,n,{action:"updateStrategy",feature:s,payload:{...r,disabled:!d}}),i({title:"Changes added to the draft!",type:"success"}),await o()}catch(u){c(V(u))}};return{onSuggestDisable:l(!1),onSuggestEnable:l(!0)}},Ar=({isOpen:e,onClose:n,...s})=>{var j;const{projectId:r,environmentId:a}=s,{isChangeRequestConfigured:o}=Z(r),i=o(a),{onSuggestEnable:c,onSuggestDisable:l}=Er({...s}),{onEnable:d,onDisable:u}=Tr({...s}),h=!!((j=s.strategy)!=null&&j.disabled),m=y=>{y.preventDefault(),i?h?c():l():h?d():u(),n()};return t.jsx(oe,{title:i?`Add ${h?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${h?"enable":"disable"} this strategy?`,open:e,primaryButtonText:i?"Add to draft":`${h?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:m,onClose:()=>n(),children:t.jsx(b,{condition:i,show:t.jsx(os,{environment:a}),elseShow:t.jsxs(ie,{severity:"error",children:[h?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})};var Dt={},Dr=cs;Object.defineProperty(Dt,"__esModule",{value:!0});var Ln=Dt.default=void 0,Fr=Dr(is()),Rr=t,$r=(0,Fr.default)((0,Rr.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"}),"Delete");Ln=Dt.default=$r;const kr=({projectId:e,strategy:n,featureId:s,environmentId:r})=>{const[a,o]=g.useState(null),[i,c]=g.useState(!1),[l,d]=g.useState(!1),u=!!a,h=T=>{o(T.currentTarget)},m=T=>{o(null),T.stopPropagation()},j=ut(ls,e,r),y=ut(ds,e,r);return t.jsxs(t.Fragment,{children:[t.jsx(K,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t.jsx(ee,{title:"More actions",children:t.jsx($e,{onClick:h,size:"small","aria-controls":u?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":u?"true":void 0,"data-testid":us,children:t.jsx(ps,{sx:{width:32,height:32}})})})}),t.jsxs(ke,{anchorEl:a,id:"actions-menu",open:u,onClose:m,onClick:m,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":gs,children:[t.jsx(ee,{title:n.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:t.jsxs(ue,{disabled:!j,onClick:()=>c(!0),children:[t.jsx(Te,{children:n.disabled?t.jsx(hs,{}):t.jsx(fs,{})}),t.jsx(me,{children:n.disabled?"Enable":"Disable"})]})}),t.jsx(ee,{title:"Remove strategy",arrow:!0,placement:"left",children:t.jsxs(ue,{disabled:!y,onClick:()=>d(!0),"data-testid":xs,children:[t.jsx(Te,{children:t.jsx(Ln,{})}),t.jsx(me,{children:"Remove"})]})})]}),t.jsx(Ar,{isOpen:i,onClose:()=>c(!1),projectId:e,featureId:s,environmentId:r,strategy:n}),t.jsx(wr,{isOpen:l,onClose:()=>d(!1),projectId:e,featureId:s,environmentId:r,strategyId:n.id})]})},Ir=({environmentId:e,strategy:n,onDragStart:s,onDragEnd:r,otherEnvironments:a,orderNumber:o,headerChildren:i})=>{const c=A("projectId"),l=A("featureId"),d=ms(c,l,e,n.id);return t.jsxs(Qa,{strategy:n,onDragStart:s,onDragEnd:r,orderNumber:o,actions:t.jsxs(t.Fragment,{children:[i,t.jsx(b,{condition:!!(a&&(a==null?void 0:a.length)>0),show:()=>t.jsx(fr,{environmentId:e,environments:a,strategy:n})}),t.jsx(re,{permission:dn,environmentId:e,projectId:c,component:Q,to:d,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t.jsx(we,{})}),t.jsx(kr,{projectId:c,featureId:l,environmentId:e,strategy:n})]}),children:[t.jsx(ys,{strategy:n}),n.variants&&n.variants.length>0&&(n.disabled?t.jsx(K,{sx:{opacity:"0.5"},children:t.jsx(Rt,{variants:n.variants})}):t.jsx(Rt,{variants:n.variants}))]})},Pr=e=>fetch(e).then(ye("ChangeRequest")).then(n=>n.json()),_n=(e,n)=>{const{data:s,error:r,mutate:a}=un([],ge(`api/admin/projects/${e}/change-requests/pending/${n}`),Pr);return{changeRequests:s,loading:!r&&!s,refetch:a,error:r}},Or=(e,n,s,r)=>{const{user:a}=js(),{changeRequests:o}=_n(e,n),i=[],c=o==null?void 0:o.filter(l=>l.environment===s);return c==null||c.forEach(l=>{const d=l==null?void 0:l.features.find(h=>h.name===n),u=d==null?void 0:d.changes.find(h=>h.action==="updateStrategy"||h.action==="deleteStrategy"?h.payload.id===r:!1);if(u){const h=l.state==="Scheduled",m=!h&&l.createdBy.id===(a==null?void 0:a.id);h&&i.push({changeRequestId:l.id,change:u,isScheduledChange:h}),m&&i.push({changeRequestId:l.id,change:u,isScheduledChange:h})}}),i},Me=p("div")({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}),qe=p("div")(({theme:e})=>({justifyContent:"center",paddingTop:e.spacing(.75),...Ss})),ze=p("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Ft=p(Q)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),Mn=({scheduledChangeRequestIds:e})=>{const n=xt(),s=Ie(n.breakpoints.down("sm")),r=A("projectId");return s?null:t.jsx(K,{sx:{mr:1.5},children:t.jsx(Ye,{tooltip:t.jsx(t.Fragment,{children:e==null?void 0:e.map((a,o)=>t.jsxs(Ft,{to:`/projects/${r}/change-requests/${a}`,children:["Change request #",a]},`${r}-${o}`))}),children:t.jsx(Ee,{color:"warning",children:"Changes Scheduled"})})})},Br=({strategy:e,index:n,environmentName:s,otherEnvironments:r,isDragging:a,onDragStartRef:o,onDragOver:i,onDragEnd:c})=>{const l=A("projectId"),d=A("featureId"),u=g.useRef(null),h=Or(l,d,s,e.id),{changeRequests:m}=ln(l,e.id);return t.jsxs(K,{ref:u,onDragOver:i(u,n),sx:{opacity:a?"0.5":"1"},children:[t.jsx(b,{condition:n>0,show:t.jsx(bs,{text:"OR"})}),t.jsx(Ir,{strategy:e,environmentId:s,otherEnvironments:r,onDragStart:o(u,n),onDragEnd:c,orderNumber:n+1,headerChildren:_r(h,m)})]},e.id)},Lr=({change:e})=>{const n=xt();return Ie(n.breakpoints.down("sm"))?null:t.jsxs(K,{sx:{mr:1.5},children:[t.jsx(b,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t.jsx(Ee,{color:"warning",children:"Modified in draft"})}),t.jsx(b,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t.jsx(Ee,{color:"error",children:"Deleted in draft"})})]})},_r=(e,n)=>{const s=[];if((e==null?void 0:e.length)===0&&(n==null?void 0:n.length)===0)return[];const r=e==null?void 0:e.find(({isScheduledChange:a})=>!a);return r&&s.push(t.jsx(Lr,{change:r.change},`draft-change#${r.change.id}`)),n&&n.length>0&&s.push(t.jsx(Mn,{scheduledChangeRequestIds:n.map(a=>a.id)},"scheduled-changes")),s},Mr=({environmentId:e,environments:n,onClick:s})=>{const r=A("projectId"),[a,o]=g.useState(null),i=!!a,{hasAccess:c}=g.useContext(mt),l=n.some(d=>c(de,r,d));return t.jsxs("div",{children:[t.jsx(ee,{title:l?"":"(Access denied)",children:t.jsx("div",{children:t.jsx(je,{id:`copy-all-strategies-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:d=>{o(d.currentTarget)},disabled:!l,variant:"outlined",children:"Copy from another environment"})})}),t.jsx(ke,{id:"basic-menu",anchorEl:a,open:i,onClose:()=>{o(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(d=>{const u=c(de,r,d);return t.jsx(ee,{title:u?"":"You don't have access to add a strategy to this environment",children:t.jsx("div",{children:t.jsxs(ue,{onClick:()=>s(d),disabled:!u,children:[t.jsx(b,{condition:!u,show:t.jsx(Te,{children:t.jsx(cn,{fontSize:"small"})})}),t.jsxs(me,{children:["Copy from ",d]})]})})},d)})})]})},qr=p("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),zr=({payload:e,fromEnvironment:n,environment:s})=>t.jsxs(qr,{children:[t.jsx(W,{children:t.jsx("strong",{children:"Copy: "})}),e==null?void 0:e.map(r=>t.jsxs(W,{children:[t.jsxs("strong",{children:[Fe((r==null?void 0:r.name)||"")," strategy"," "]})," "]})),t.jsxs(W,{children:["from ",n," to ",s]})]}),qn=(e,n)=>{const s={};return n.parameters.forEach(r=>{s[r.name]=Nr(e,r)}),{name:n.name,constraints:[],parameters:s}},Nr=(e,n)=>n.name==="rollout"||n.name==="percentage"||n.type==="percentage"?"50":n.name==="stickiness"?"":n.name==="groupId"?e:n.type==="boolean"?"false":"",Vr=()=>{const e=A("projectId"),n=A("featureId"),s=Ae("environmentId"),r=Ae("strategyName"),{strategy:a,defaultStrategyFallback:o}=In(e,s),i=JSON.parse(pn().get("defaultStrategy")||"false"),{segments:c}=yt(),l=(c||[]).filter(P=>{var H;return(H=a==null?void 0:a.segments)==null?void 0:H.includes(P.id)}),[d,u]=g.useState({}),[h,m]=g.useState(i?l:[]),{strategyDefinition:j}=jt(r),y=St(),{addStrategyToFeature:T,loading:f}=he(),{addChange:x}=se(),{setToastData:R,setToastApiError:L}=U(),{uiConfig:q}=fe(),{unleashUrl:z}=q,v=ce(),{feature:C,refetchFeature:$}=M(e,n),O=g.useRef(C),{isChangeRequestConfigured:N}=Z(e),{refetch:G}=te(e),{trackEvent:Y}=ae(),{data:S,staleDataNotification:k,forceRefreshCache:w}=bt({unleashGetter:M,params:[e,n],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},C,{afterSubmitAction:$},vt);g.useEffect(()=>{O.current.name===""&&C.name&&(w(C),O.current=C)},[C.name]),g.useEffect(()=>{var P;if(i){const H=a||o;((P=H.parameters)==null?void 0:P.groupId)===""&&n?u({...H,parameters:{...H.parameters,groupId:n}}):u(H)}else j&&u(qn(n,j))},[n,JSON.stringify(j),i]);const E=async P=>{await T(e,n,s,P),R({title:"Strategy created",type:"success",confetti:!0})},F=async P=>{await x(e,s,{action:"addStrategy",feature:n,payload:P}),R({title:"Strategy added to draft",type:"success",confetti:!0}),G()},B=gn(d,h),I=async()=>{Y("strategyTitle",{props:{hasTitle:!!d.title,on:"create"}});try{N(s)?await F(B):await E(B),$(),v(Ue(e,n))}catch(P){L(V(P))}};return!S||!S.project?null:t.jsxs(Ge,{modal:!0,title:Fe(r),description:hn,documentationLink:fn,documentationLinkLabel:xn,formatApiCode:()=>Hr(e,n,s,B,z),children:[t.jsx(vs,{projectId:e,feature:S,strategy:d,setStrategy:u,segments:h,setSegments:m,environmentId:s,onSubmit:I,loading:f,permission:de,errors:y,isChangeRequest:N(s)}),k]})},zn=(e,n,s,r,a=!1)=>{const o=new URLSearchParams({environmentId:s,strategyName:r,defaultStrategy:String(a)});return`/projects/${e}/features/${n}/strategies/create?${o}`},Hr=(e,n,s,r,a)=>{if(!a)return"";const o=`${a}/api/admin/projects/${e}/features/${n}/environments/${s}/strategies`,i=JSON.stringify(r,void 0,2);return`curl --location --request POST '${o}' \\
2
+ --header 'Authorization: INSERT_API_KEY' \\
3
+ --header 'Content-Type: application/json' \\
4
+ --data-raw '${i}'`},Wr=p("div")(({theme:e})=>({width:e.spacing(4),height:"auto","& > svg":{fill:e.palette.primary.main},"& > div":{height:e.spacing(2),marginLeft:"-.75rem",color:e.palette.primary.main}})),Ur=p("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Yr=p(Ct)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Gr=p(Q)(({theme:e})=>({display:"grid",gridTemplateColumns:"3rem 1fr",width:"20rem",padding:e.spacing(2),color:"inherit",textDecoration:"inherit",lineHeight:1.25,borderWidth:"1px",borderStyle:"solid",borderColor:e.palette.divider,borderRadius:e.spacing(1),"&:hover, &:focus":{borderColor:e.palette.primary.main}})),et=({projectId:e,featureId:n,environmentId:s,strategy:r,defaultStrategy:a})=>{const o=mn(r.name),i=Fe(r.name),{trackEvent:c}=ae(),l=zn(e,n,s,r.name,a),d=()=>{c("strategy-add",{props:{buttonTitle:r.displayName||i}})};return t.jsxs(Gr,{to:l,onClick:d,children:[t.jsx(Wr,{children:t.jsx(o,{})}),t.jsxs("div",{children:[t.jsx(Yr,{text:r.displayName||i,maxWidth:"200",maxLength:25}),t.jsx(Ur,{children:r.description})]})]})},tt=p(W)(({theme:e})=>({fontSize:e.fontSizes.smallBody,padding:e.spacing(1,2)})),Kr=({projectId:e,featureId:n,environmentId:s})=>{const{strategies:r}=Cs(),a=r.filter(c=>!c.deprecated&&!c.editable),o=r.filter(c=>!c.deprecated&&c.editable),i={name:"flexibleRollout",displayName:"Default strategy",description:"This is the default strategy defined for this environment in the project"};return t.jsxs(wt,{dense:!0,children:[t.jsxs(t.Fragment,{children:[t.jsxs(tt,{color:"textSecondary",children:[s," environment default strategy"]}),t.jsx(ve,{children:t.jsx(et,{projectId:e,featureId:n,environmentId:s,strategy:i,defaultStrategy:!0})},i.name)]}),t.jsx(tt,{color:"textSecondary",children:"Predefined strategy types"}),a.map(c=>t.jsx(ve,{children:t.jsx(et,{projectId:e,featureId:n,environmentId:s,strategy:c})},c.name)),t.jsx(b,{condition:o.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(tt,{color:"textSecondary",children:"Custom strategies"}),o.map(c=>t.jsx(ve,{children:t.jsx(et,{projectId:e,featureId:n,environmentId:s,strategy:c})},c.name))]})})]})},Jr=p("div")({flexShrink:0}),Qr=p(pe)(({theme:e})=>({minWidth:0,width:e.spacing(4.5),alignItems:"center",justifyContent:"center",align:"center",flexDirection:"column",marginLeft:e.spacing(1)})),gt=({label:e,projectId:n,featureId:s,environmentId:r,variant:a,size:o,matchWidth:i})=>{const[c,l]=g.useState(),d=ce(),{trackEvent:u}=ae(),h=!!c,m=h?"FeatureStrategyMenuPopover":void 0,j=()=>{l(void 0)},y=x=>{u("strategy-add",{props:{buttonTitle:e}}),d(f)},T=x=>{l(x.currentTarget)},f=zn(n,s,r,"flexibleRollout",!0);return t.jsxs(Jr,{onClick:x=>x.stopPropagation(),children:[t.jsx(pe,{permission:de,projectId:n,environmentId:r,onClick:y,"aria-labelledby":m,variant:a,size:o,sx:{minWidth:i?"282px":"auto"},children:e}),t.jsx(Qr,{permission:de,projectId:n,environmentId:r,onClick:T,"aria-labelledby":m,variant:"outlined",size:o,hideLockIcon:!0,tooltipProps:{title:"More strategies"},children:t.jsx(yn,{sx:x=>({margin:x.spacing(.25,0)})})}),t.jsx(jn,{id:m,open:h,anchorEl:c,onClose:j,onClick:j,PaperProps:{sx:x=>({paddingBottom:x.spacing(1)})},children:t.jsx(Kr,{projectId:n,featureId:s,environmentId:r})})]})},Zr=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Xr=p("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),eo=p("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),to=({projectId:e,featureId:n,environmentId:s})=>{const{addStrategyToFeature:r}=he(),{setToastData:a,setToastApiError:o}=U(),{refetchFeature:i}=M(e,n),{refetchFeature:c}=Pn(e,n),{feature:l}=M(e,n),d=l==null?void 0:l.environments.filter(R=>R.name!==s&&R.strategies&&R.strategies.length>0),{isChangeRequestConfigured:u}=Z(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:m,onChangeRequestAddStrategiesConfirm:j,onChangeRequestAddStrategyClose:y}=On(e,n,"addStrategy"),T=(R=!1)=>{i(),c(),a({title:R?"Strategies created":"Strategy created",text:R?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},f=async R=>{var q;const L=((q=d==null?void 0:d.find(z=>z.name===R))==null?void 0:q.strategies)||[];if(u(s)){await m(s,L,R);return}try{await Promise.all(L.map(z=>{const{id:v,...C}={...z,environment:s};return r(e,n,s,C)})),T(!0)}catch(z){o(V(z))}},x=d&&d.length>0;return t.jsxs(t.Fragment,{children:[t.jsx(kn,{isOpen:h.isOpen,onClose:y,environment:h==null?void 0:h.environment,onConfirm:j,messageComponent:t.jsx(zr,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),t.jsxs(Zr,{children:[t.jsx(Xr,{children:"You have not defined any strategies yet."}),t.jsxs(eo,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t.jsx(Q,{to:"/admin/api",children:"API key configured"})," for this environment."]}),t.jsxs(K,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t.jsx(gt,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:s,matchWidth:x}),t.jsx(b,{condition:x,show:t.jsx(Mr,{environmentId:s,environments:d.map(R=>R.name),onClick:f})})]})]})]})},no=p("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),so=p("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),ao=({featureEnvironment:e,isDisabled:n,otherEnvironments:s})=>{const r=A("projectId"),a=A("featureId"),{setStrategiesSortOrder:o}=he(),{addChange:i}=se(),{isChangeRequestConfigured:c}=Z(r),{refetch:l}=te(r),{setToastData:d,setToastApiError:u}=U(),{refetchFeature:h}=M(r,a),[m,j]=g.useState((e==null?void 0:e.strategies)||[]),[y,T]=g.useState(null);if(g.useEffect(()=>{j((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const f=async v=>{try{await o(r,a,e.name,v),h(),d({title:"Order of strategies updated",type:"success"})}catch(C){u(V(C))}},x=async v=>{await i(r,e.name,{action:"reorderStrategy",feature:a,payload:v}),d({title:"Strategy execution order added to draft",type:"success",confetti:!0}),l()},R=async v=>{try{c(e.name)?await x(v):await f(v)}catch(C){u(V(C))}},L=(v,C)=>$=>{var O;T({id:m[C].id,index:C,height:((O=v.current)==null?void 0:O.offsetHeight)||0}),v!=null&&v.current&&($.dataTransfer.effectAllowed="move",$.dataTransfer.setData("text/html",v.current.outerHTML),$.dataTransfer.setDragImage(v.current,20,20))},q=v=>(C,$)=>O=>{if(y===null||C.current===null||y.index===$||v===y.id)return;const{top:N,bottom:G}=C.current.getBoundingClientRect(),Y=O.clientY-N<y.height,S=G-O.clientY<y.height,k=y.index>$;if(Y&&k||S&&!k){const w=[...m],E=w.splice(y.index,1)[0];w.splice($,0,E),j(w),T({...y,index:$})}},z=()=>{T(null),R(m.map((v,C)=>({id:v.id,sortOrder:C})))};return t.jsx(no,{children:t.jsxs(so,{children:[t.jsx(b,{condition:m.length>0&&n,show:()=>t.jsx(ie,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t.jsx(b,{condition:m.length>0,show:t.jsx(t.Fragment,{children:m.map((v,C)=>t.jsx(Br,{strategy:v,index:C,environmentName:e.name,otherEnvironments:s,isDragging:(y==null?void 0:y.id)===v.id,onDragStartRef:L,onDragOver:q(v.id),onDragEnd:z},v.id))}),elseShow:t.jsx(to,{projectId:r,featureId:a,environmentId:e.name})})]})})},Nn=(e,n)=>e===0?0:Math.round(n/e*100);var Je={},Qe={};Object.defineProperty(Qe,"__esModule",{value:!0});Qe.defaultOptions=void 0;Qe.defaultOptions={lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var ne={};Object.defineProperty(ne,"__esModule",{value:!0});ne.getLocales=ne.getFractionDigits=ne.roundTo=ne.parseValue=void 0;function ro(e){const n=parseFloat(e==null?void 0:e.toString());if(isNaN(n))throw new Error("Input value is not a number");if(n>Number.MAX_SAFE_INTEGER||n<Number.MIN_SAFE_INTEGER)throw new RangeError("Input value is outside of safe integer range");return n}ne.parseValue=ro;function oo(e,n){if(!Number.isFinite(e))throw new Error("Input value is not a finite number");if(!Number.isInteger(n)||n<0)throw new Error("Precision is not a positive integer");return Number.isInteger(e)?e:parseFloat(e.toFixed(n))}ne.roundTo=oo;function io(e){var n;if(Number.isInteger(e))return 0;const s=e.toString().split(".")[1];return(n=s==null?void 0:s.length)!==null&&n!==void 0?n:0}ne.getFractionDigits=io;function co(){var e;return typeof navigator>"u"?[]:Array.from((e=navigator.languages)!==null&&e!==void 0?e:[])}ne.getLocales=co;Object.defineProperty(Je,"__esModule",{value:!0});Je.millify=void 0;const zt=Qe,Oe=ne,Nt=1e3;function*Vt(e){let n=Nt;for(;;){const s=e/n;if(s<1)return;yield s,n*=Nt}}function Vn(e,n){var s,r;const a=n?{...zt.defaultOptions,...n}:zt.defaultOptions;if(!Array.isArray(a.units)||!a.units.length)throw new Error("Option `units` must be a non-empty array");let o;try{o=Oe.parseValue(e)}catch(y){return y instanceof Error&&console.warn(`WARN: ${y.message} (millify)`),String(e)}const i=o<0?"-":"";o=Math.abs(o);let c=0;for(const y of Vt(o))o=y,c+=1;if(c>=a.units.length)return e.toString();let d=Oe.roundTo(o,a.precision);for(const y of Vt(d))d=y,c+=1;const u=(s=a.units[c])!==null&&s!==void 0?s:"",h=a.lowercase?u.toLowerCase():u,m=a.space?" ":"",j=d.toLocaleString((r=a.locales)!==null&&r!==void 0?r:Oe.getLocales(),{minimumFractionDigits:Oe.getFractionDigits(d)});return`${i}${j}${m}${h}`}Je.millify=Vn;var lo=Je.default=Vn;const Ve=({value:e,threshold:n=1e6,precision:s=2})=>{let r,a=!1;e<n?r=e.toLocaleString():(r=lo(e,{precision:s}),a=!0);const o=t.jsx("span",{"data-testid":ws,children:r});return t.jsx(b,{condition:a,show:t.jsx(ee,{title:e.toLocaleString(),arrow:!0,children:o}),elseShow:o})},uo=e=>e>48?`${Math.floor(e/24)} days (UTC)`:`${e} hours (local time)`,nt=p("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),st=p("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),at=p("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),rt=p("p")(({theme:e})=>({margin:e.spacing(1,0,0,0),padding:e.spacing(2,0,0,0),borderTopWidth:"1px",borderTopStyle:"solid",borderTopColor:e.palette.divider,fontSize:e.fontSizes.smallerBody,color:e.palette.text.secondary})),Hn=({totalYes:e,totalNo:n,hoursBack:s,statsSectionId:r,tableSectionId:a})=>{const o=s===1?"in the last hour":`in the last ${uo(s)}`;return t.jsxs(le,{container:!0,spacing:2,id:r,"aria-describedby":a,"aria-label":"Feature metrics summary",component:"section",children:[t.jsx(le,{item:!0,xs:12,sm:4,children:t.jsxs(nt,{children:[t.jsx(st,{children:"Exposure"}),t.jsx(at,{children:t.jsx(Ve,{value:e})}),t.jsxs(rt,{children:["Total exposure of the feature in the environment"," ",o,"."]})]})}),t.jsx(le,{item:!0,xs:12,sm:4,children:t.jsxs(nt,{children:[t.jsx(st,{children:"Exposure %"}),t.jsxs(at,{children:[Nn(e+n,e),"%"]}),t.jsxs(rt,{children:["% total exposure of the feature in the environment"," ",o,"."]})]})}),t.jsx(le,{item:!0,xs:12,sm:4,children:t.jsxs(nt,{children:[t.jsx(st,{children:"Requests"}),t.jsx(at,{children:t.jsx(Ve,{value:e+n})}),t.jsxs(rt,{children:["Total requests for the feature in the environment"," ",o,"."]})]})})]})},po=p("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",margin:"1rem 0",position:"relative","&:before":{content:'""',position:"absolute",top:"50%",transform:"translateY(-50%)",height:2,width:"100%",backgroundColor:e.palette.divider}})),go=p("span")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",padding:"0 1rem",background:e.palette.envAccordion.expanded,position:"relative",maxWidth:"80%",color:e.palette.text.primary})),ho=({children:e})=>t.jsx(po,{children:t.jsx(go,{children:e})}),fo=({environmentMetric:e})=>e?t.jsxs(t.Fragment,{children:[t.jsx(ho,{children:"Feature toggle exposure"}),t.jsx("div",{children:t.jsx(Hn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Ht=p("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),Wt=p("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Ut=p("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Yt=p("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),xo=p(Ts)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),mo=p("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),yo=({environmentMetric:e,disabled:n=!1})=>{const s=Es();if(!e)return null;const r=e.yes+e.no,a=Nn(r,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?t.jsxs(Ht,{children:[t.jsxs(Wt,{children:[t.jsxs(Ut,{style:{color:n?s.palette.text.secondary:void 0},"data-loading":!0,children:[a,"%"]}),t.jsxs(Yt,{style:{color:n?s.palette.text.secondary:s.palette.text.primary},"data-loading":!0,children:["The feature has been requested ",t.jsx("b",{children:"0 times"})," and exposed",t.jsx("b",{children:" 0 times"})," in the last hour"]})]}),t.jsx(xo,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):t.jsxs(Ht,{children:[t.jsxs(Wt,{children:[t.jsxs(Ut,{children:[a,"%"]}),t.jsxs(Yt,{children:["The feature has been requested"," ",t.jsxs("b",{children:[t.jsx(Ve,{value:r})," times"]})," ","and exposed"," ",t.jsxs("b",{children:[t.jsx(Ve,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t.jsx(mo,{"data-loading":!0,children:t.jsx(As,{percentage:a,size:"3rem"})})]})},ot=({strategy:e})=>{const n=mn(e.name);return t.jsx(ee,{title:Fe(e.name)+(e.title?` - ${e.title}`:""),arrow:!0,children:t.jsx(jo,{children:t.jsx(n,{})})})},jo=p("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.palette.action.disabled,"& svg":{width:e.spacing(2.5),height:e.spacing(2.5)}})),Gt=p("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),it=p("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),So=p("div")(({theme:e})=>({display:"flex",flexDirection:"row",alignItems:"center",gap:e.spacing(1)})),Be=5,bo=({strategies:e})=>e!=null&&e.length?e.length>Be+1?t.jsxs(Gt,{"aria-label":"Feature strategies",children:[e.slice(0,Be).map(n=>t.jsx(it,{children:t.jsx(ot,{strategy:n})},n.id)),t.jsxs(Ye,{tooltip:e.slice(Be).map(n=>t.jsx(it,{children:t.jsxs(So,{children:[t.jsx(ot,{strategy:n})," ",Fe(n.name)+(n.title?` - ${n.title}`:"")]})},n.id)),children:["(+",e.length-Be,")"]})]}):t.jsx(Gt,{"aria-label":"Feature strategies",children:e.map(n=>t.jsx(it,{children:t.jsx(ot,{strategy:n})},n.id))}):null,Wn=()=>{const{value:e,setValue:n}=Ds("global:v1",{});return{value:{...e,hiddenEnvironments:Array.from(e.hiddenEnvironments||[])},setValue:n}},vo=p("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2),backgroundColor:n?e.palette.background.paper:e.palette.envAccordion.disabled})),Co=p(Fs)({boxShadow:"none",background:"none"}),wo=p(Rs)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),To=p($s,{shouldForwardProp:e=>e!=="enabled"})(({theme:e})=>({padding:e.spacing(3),background:e.palette.envAccordion.expanded,borderBottomLeftRadius:e.shape.borderRadiusLarge,borderBottomRightRadius:e.shape.borderRadiusLarge,boxShadow:"inset 0px 2px 4px rgba(32, 32, 33, 0.05)",[e.breakpoints.down("md")]:{padding:e.spacing(2,1)}})),Eo=p(ao)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Ao=p("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({display:"flex",justifyContent:"center",flexDirection:"column",color:n?e.palette.text.primary:e.palette.text.secondary})),Do=p("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Fo=p(ks)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Ro=p(Ct)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),$o=p("div")(({theme:e})=>({display:"flex",alignItems:"center",marginTop:e.spacing(2),gap:e.spacing(2),flexWrap:"wrap",[e.breakpoints.down(560)]:{flexDirection:"column"}})),ko=({env:e})=>{var d;const n=A("projectId"),s=A("featureId"),{metrics:r}=lr(n,s),{feature:a}=M(n,s),{value:o}=Wn(),c=ur(a==null?void 0:a.environments,r).find(u=>u.environment===e.name),l=a==null?void 0:a.environments.find(u=>u.name===e.name);return t.jsx(b,{condition:!new Set(o.hiddenEnvironments).has(e.name),show:t.jsx(vo,{enabled:e.enabled,children:t.jsxs(Co,{TransitionProps:{mountOnEnter:!0},"data-testid":`${Is}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[t.jsxs(wo,{expandIcon:t.jsx(Ps,{titleAccess:"Toggle"}),children:[t.jsxs(Ao,{"data-loading":!0,enabled:e.enabled,children:[t.jsxs(Do,{children:[t.jsx(Fo,{enabled:e.enabled}),t.jsx("div",{children:t.jsx(Ro,{text:e.name,maxWidth:"100",maxLength:15})}),t.jsx(b,{condition:!e.enabled,show:t.jsx(Ee,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),t.jsxs($o,{children:[t.jsx(gt,{label:"Add strategy",projectId:n,featureId:s,environmentId:e.name,variant:"outlined",size:"small"}),t.jsx(bo,{strategies:l==null?void 0:l.strategies})]})]}),t.jsx(yo,{environmentMetric:c,disabled:!e.enabled})]}),t.jsxs(To,{enabled:e.enabled,children:[t.jsx(Eo,{featureEnvironment:l,isDisabled:!e.enabled,otherEnvironments:a==null?void 0:a.environments.map(({name:u})=>u).filter(u=>u!==e.name)}),t.jsx(b,{condition:(((d=l==null?void 0:l.strategies)==null?void 0:d.length)||0)>0,show:t.jsxs(t.Fragment,{children:[t.jsx(K,{sx:{display:"flex",justifyContent:"center",py:1},children:t.jsx(gt,{label:"Add strategy",projectId:n,featureId:s,environmentId:e.name})}),t.jsx(fo,{environmentMetric:c})]})})]})]})})})},Io=()=>{const e=A("projectId"),n=A("featureId"),{feature:s}=M(e,n);if(!s)return null;const{environments:r}=s;return t.jsx(t.Fragment,{children:r==null?void 0:r.map(a=>t.jsx(ko,{env:a},a.name))})},Un=e=>{const{makeRequest:n,createRequest:s,errors:r,loading:a}=Os({propagateErrors:!0}),o=async(d,u)=>{const h=s(`/api/admin/projects/${e}/features/${d}/dependencies`,{method:"POST",body:JSON.stringify(u)});await n(h.caller,h.id)},i=async(d,u)=>{const h=s(`/api/admin/projects/${e}/features/${d}/dependencies/${u}`,{method:"DELETE"});await n(h.caller,h.id)},c=async d=>{const u=s(`/api/admin/projects/${e}/features/${d}/dependencies`,{method:"DELETE"});await n(u.caller,u.id)},l=[s,n,V,e];return{addDependency:g.useCallback(o,l),removeDependency:g.useCallback(i,l),removeDependencies:g.useCallback(c,l),errors:r,loading:a}},Po=(e,n,s={})=>{const r=ge(`/api/admin/projects/${e}/features/${n}/parents`),{data:a,error:o,mutate:i}=We(r,Oo,s);return{parentOptions:a,error:o,loading:!o&&!a}},Oo=async e=>await(await fetch(e).then(ye("Parent Options"))).json(),Bo=()=>t.jsxs(ie,{severity:"warning",children:["Remember to update your Unleash client! Feature dependencies require new SDK versions. Read more about ",t.jsx(Lo,{}),"."]}),Lo=()=>t.jsx("a",{href:"https://docs.getunleash.io/reference/dependent-features#client-sdk-support",target:"_blank",rel:"noreferrer",children:"Client SDK support for feature dependencies"}),_o=p(Sn)(({theme:e})=>({marginTop:e.spacing(2),marginBottom:e.spacing(1.5)})),De={key:"none (remove dependency)",label:"none (remove dependency)"},Mo=({project:e,featureId:n,parent:s,onSelect:r})=>{const{parentOptions:a,loading:o}=Po(e,n),i=a?[De,...a.map(c=>({key:c,label:c}))]:[De];return t.jsx(_o,{fullWidth:!0,options:i,value:s,onChange:r})},qo=(e,n,s,r)=>{const{trackEvent:a}=ae(),{addChange:o}=se(),{refetch:i}=te(e),{setToastData:c,setToastApiError:l}=U(),{refetchFeature:d}=M(e,n),u=Tt(e)(),{isChangeRequestConfiguredInAnyEnv:h}=Z(e),{addDependency:m,removeDependencies:j}=Un(e),y=async f=>{if(!u){console.error("No change request environment");return}f==="addDependency"&&(await o(e,u,[{action:f,feature:n,payload:{feature:s}}]),a("dependent_features",{props:{eventType:"dependency added"}})),f==="deleteDependency"&&await o(e,u,[{action:f,feature:n,payload:void 0}]),i(),c({text:f==="addDependency"?`${n} will depend on ${s}`:`${n} dependency will be removed`,type:"success",title:"Change added to a draft"})};return async()=>{try{if(h()){const f=s===De.key?"deleteDependency":"addDependency";await y(f),a("dependent_features",{props:{eventType:f==="addDependency"?"add dependency added to change request":"delete dependency added to change request"}})}else s===De.key?(await j(n),a("dependent_features",{props:{eventType:"dependency removed"}}),c({title:"Dependency removed",type:"success"})):(await m(n,{feature:s}),a("dependent_features",{props:{eventType:"dependency added"}}),c({title:"Dependency added",type:"success"}))}catch(f){l(V(f))}await d(),r()}},zo=({project:e,featureId:n,showDependencyDialogue:s,onClose:r})=>{const[a,o]=g.useState(De.key),i=qo(e,n,a,r),{isChangeRequestConfiguredInAnyEnv:c}=Z(e);return t.jsx(oe,{open:s,title:"Add parent feature dependency",onClose:r,onClick:i,primaryButtonText:c()?"Add change to draft":a===De.key?"Remove":"Add",secondaryButtonText:"Cancel",children:t.jsxs(K,{children:[t.jsx(Bo,{}),t.jsx(K,{sx:{mt:2,mb:4},children:"Your feature will be evaluated only when the selected parent feature is enabled in the same environment."}),t.jsx(W,{children:"What feature do you want to depend on?"}),t.jsx(b,{condition:s,show:t.jsx(Mo,{project:e,featureId:n,parent:a,onSelect:o})})]})})},No=p(jn)(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,padding:e.spacing(1,1.5)})),Vo=({feature:e,onEdit:n,onDelete:s})=>{const r=`dependency-${e}-actions`,a=`${r}-menu`,[o,i]=g.useState(null),c=!!o,l=u=>{i(u.currentTarget)},d=()=>{i(null)};return t.jsxs("span",{children:[t.jsx(ee,{title:"Dependency actions",arrow:!0,describeChild:!0,children:t.jsx($e,{id:r,"aria-controls":c?a:void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:l,type:"button",children:t.jsx(yn,{})})}),t.jsx(No,{id:a,anchorEl:o,open:c,onClose:d,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},disableScrollLock:!0,children:t.jsxs(Bs,{"aria-labelledby":r,children:[t.jsx(b,{condition:!0,show:t.jsxs(ue,{onClick:()=>{n(),d()},children:[t.jsx(Te,{children:t.jsx(we,{})}),t.jsx(me,{children:t.jsx(W,{variant:"body2",children:"Edit"})})]})}),t.jsx(b,{condition:!0,show:t.jsxs(ue,{onClick:()=>{s(),d()},children:[t.jsx(Te,{children:t.jsx(Ls,{})}),t.jsx(me,{children:t.jsx(W,{variant:"body2",children:"Delete"})})]})})]})})]})},Yn=({childFeatures:e,project:n})=>t.jsx(Ye,{tooltip:t.jsx(t.Fragment,{children:e.map(s=>t.jsx(Ft,{to:`/projects/${n}/features/${s}`,children:t.jsx("div",{children:s})},`${n}-${s}`))}),children:e.length===1?"1 feature":`${e.length} features`}),Ho=(e,n)=>{const{trackEvent:s}=ae(),{addChange:r}=se(),{refetch:a}=te(e),{setToastData:o,setToastApiError:i}=U(),{refetchFeature:c}=M(e,n),l=Tt(e)(),{isChangeRequestConfiguredInAnyEnv:d}=Z(e),{removeDependencies:u}=Un(e),h=async()=>{if(!l){console.error("No change request environment");return}await r(e,l,[{action:"deleteDependency",feature:n,payload:void 0}])};return async()=>{try{d()?(await h(),s("dependent_features",{props:{eventType:"delete dependency added to change request"}}),o({text:`${n} dependency will be removed`,type:"success",title:"Change added to a draft"}),await a()):(await u(n),s("dependent_features",{props:{eventType:"dependency removed"}}),o({title:"Dependency removed",type:"success"}),await c())}catch(j){i(V(j))}}},Wo=({feature:e})=>{var d,u;const[n,s]=g.useState(!1),r=!!e.project&&e.dependencies.length===0&&e.children.length===0,a=!!e.project&&e.dependencies.length>0,o=!!e.project&&e.children.length>0,i=Tt(e.project)(),c=on(e.project),l=Ho(e.project,e.name);return t.jsxs(t.Fragment,{children:[t.jsx(b,{condition:r,show:t.jsx(Me,{children:t.jsxs(qe,{children:[t.jsx(ze,{children:"Dependency:"}),t.jsx(pe,{permission:$t,projectId:e.project,variant:"text",onClick:()=>{s(!0)},children:"Add parent feature"})]})})}),t.jsx(b,{condition:a,show:t.jsxs(Me,{children:[t.jsxs(qe,{children:[t.jsx(ze,{children:"Dependency:"}),t.jsx(Ft,{to:`/projects/${e.project}/features/${(d=e.dependencies[0])==null?void 0:d.feature}`,children:(u=e.dependencies[0])==null?void 0:u.feature})]}),t.jsx(b,{condition:c($t,i),show:t.jsx(Vo,{feature:e.name,onEdit:()=>s(!0),onDelete:l})})]})}),t.jsx(b,{condition:o,show:t.jsx(Me,{children:t.jsxs(qe,{children:[t.jsx(ze,{children:"Children:"}),t.jsx(Yn,{childFeatures:e.children,project:e.project})]})})}),t.jsx(b,{condition:!!e.project,show:t.jsx(zo,{project:e.project,featureId:e.name,onClose:()=>s(!1),showDependencyDialogue:n})})]})},Uo=(e,n={})=>{const s=ge(`/api/admin/projects/${e}/dependencies`),{data:r,error:a}=bn(e,!1,s,Yo,n);return{dependenciesExist:r,error:a,loading:!a&&!r}},Yo=async e=>await(await fetch(e).then(ye("Dependencies exist check"))).json(),Go=e=>{const{dependenciesExist:n}=Uo(e),{isOss:s}=fe();return!!(!s()||n)},Ko=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",justifyItems:"center",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),Jo=({feature:e,header:n})=>{var o;const{locationSettings:s}=vn();fe();const r=Go(e.project),a=(o=e.environments)==null?void 0:o.map(i=>({name:i.name,lastSeenAt:i.lastSeenAt,enabled:i.enabled}));return t.jsxs(Ko,{children:[n,t.jsxs(Me,{children:[t.jsxs(qe,{children:[t.jsx(ze,{children:"Created at:"}),t.jsx("span",{children:_s(Cn(e.createdAt),s.locale)})]}),t.jsx(Ms,{featureLastSeen:e.lastSeenAt,environments:a,sx:{p:0}})]}),t.jsx(b,{condition:r,show:t.jsx(Wo,{feature:e})})]})},Qo=p($e,{shouldForwardProp:e=>e!=="visibilityOff"})(({theme:e,visibilityOff:n})=>({marginLeft:"auto",marginRight:e.spacing(-1),color:n?e.palette.action.active:e.palette.action.focus,"&:hover":{color:e.palette.action.active}})),Zo=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:s})=>{const r=()=>{s(e.name)};return t.jsx(Qo,{onClick:r,visibilityOff:n.has(e.name),children:t.jsx(b,{condition:n.has(e.name),show:t.jsx(qs,{}),elseShow:t.jsx(zs,{})})})},Xo=p("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),ei=p("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),ti=({environment:e,callback:n,children:s,hiddenEnvironments:r,setHiddenEnvironments:a})=>{const o=A("projectId"),i=A("featureId"),{feature:c,refetchFeature:l}=M(o,i),{isChangeRequestConfigured:d}=Z(o),u=t.jsxs(t.Fragment,{children:[" ",t.jsxs("span",{"data-loading":!0,children:[e.enabled?"enabled":"disabled"," in"]})," ",t.jsx(Ct,{text:e.name,maxWidth:"120",maxLength:15})]}),{onToggle:h,modals:m}=za(o),j=(y,T)=>h(y,{projectId:o,featureId:i,environmentName:e.name,environmentType:e.type,hasStrategies:e.strategies.length>0,hasEnabledStrategies:e.strategies.some(f=>!f.disabled),isChangeRequestEnabled:d(e.name),onRollback:T,onSuccess:()=>{n&&n(),l()}});return t.jsxs(Xo,{children:[t.jsxs(ei,{children:[t.jsx(Na,{featureId:c.name,projectId:o,environmentName:e.name,onToggle:j,value:e.enabled}),s??u]}),t.jsx(Zo,{environment:e,hiddenEnvironments:r,setHiddenEnvironments:a}),m]})},ni=p("div")(({theme:e})=>({padding:e.spacing(3)})),si=p("div")(()=>({display:"flex",flexDirection:"column"})),ai=p("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),ri=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Kt=p("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),oi=p(Et)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),ii=({feature:e,header:n,hiddenEnvironments:s,setHiddenEnvironments:r})=>{const a=e.environments.some(o=>{var i;return o.enabled&&((i=o.variants)==null?void 0:i.length)});return t.jsxs(ni,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(o=>{const i=o.strategies.length===1?"1 strategy":`${o.strategies.length} strategies`,c=o.variants??[],l=c.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Kt,{}),t.jsx(ee,{title:"View variants",arrow:!0,describeChild:!0,children:t.jsx(oi,{component:Q,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:c.length===1?"1 variant":`${c.length} variants`})})]}),d=o.enabled&&c.length===0&&a;return t.jsx(ti,{environment:o,hiddenEnvironments:s,setHiddenEnvironments:r,children:t.jsxs(si,{children:[t.jsx(ai,{children:o.name}),t.jsxs(ri,{children:[i,l,t.jsx(b,{condition:d,show:t.jsxs(t.Fragment,{children:[t.jsx(Kt,{}),t.jsx(Va,{})]})})]})]})},o.name)})]})},Gn=(e,n={})=>{const s=async()=>{const d=ge(`api/admin/features/${e}/tags`);return(await fetch(d,{method:"GET"}).then(ye("Tags"))).json()},r=`api/admin/features/${e}/tags`,{data:a,error:o}=bn(!!e,{tags:[]},r,s,n),[i,c]=g.useState(!o&&!a),l=()=>{ft(r)};return g.useEffect(()=>{c(!o&&!a)},[a,o]),{tags:(a==null?void 0:a.tags)||[],error:o,loading:i,refetch:l}},ci=p("section")(({theme:e})=>({"& > *":{margin:e.spacing(1,0)}})),ct=e=>e.map(n=>({title:n.value})),Jt=(e,n)=>e.map(s=>({value:s.title,type:n})),Kn=({open:e,setOpen:n})=>{const{tagTypes:s}=Ns(),r=A("featureId"),{createTag:a}=Ha(),{updateFeatureTags:o,loading:i}=Ke(),{tags:c,refetch:l,loading:d}=Gn(r),{setToastData:u}=U(),h=s&&s.length>0?s[0]:{name:"simple",description:"Simple tag to get you started",icon:""},[m,j]=g.useState(h),y=i||d,[T,f]=g.useState(0),{trackEvent:x}=ae(),[R,L]=g.useState(ct(c.filter(E=>E.type===m.name))),{tags:q,refetch:z}=Wa(m.name),v=g.useMemo(()=>ct(q),[q]);g.useEffect(()=>{c&&m&&L(ct(c.filter(E=>E.type===m.name)))},[JSON.stringify(c),m]);const C=()=>{n(!1),L([])};function $(E,F){const B=E.filter(_=>_.type===m.name).filter(_=>!F.find(P=>_.value===P.value&&_.type===P.type)),I=F.filter(_=>_.type===m.name).filter(_=>!E.find(P=>_.value===P.value&&_.type===P.type));return f(B.length+I.length),{added:B,removed:I}}const O=E=>E.filter(F=>!F.title.startsWith("Create")),N=async(E,F)=>{try{await o(r,{addedTags:E,removedTags:F}),await l()}catch(B){const I=V(B);u({type:"error",title:"Failed to add tag",text:I,confetti:!1})}},G=(E,F)=>{let B="We successfully";return E>0&&(B=B.concat(` added ${E} new tag${E>1?"s":""}`)),E>0&&F>0&&(B=B.concat(" and ")),F>0&&(B=B.concat(` removed ${F} tag${F>1?"s":""}`)),B},Y=async E=>{E.preventDefault();const F=Jt(O(R),m.name),{added:B,removed:I}=$(F,c);T>0&&(await N(B,I),T>1&&x("suggest_tags",{props:{eventType:"multiple_tags_added"}}),T>0&&u({type:"success",title:`Updated tag${B.length>1?"s":""} to toggle`,text:G(B.length,I.length),confetti:!0})),f(0),L([]),n(!1)},S=(E,F)=>{F!=null&&typeof F!="string"&&(E.preventDefault(),j(F),L([]),f(0))},k=(E,F,B)=>{const I=Vs(F);B==="selectOption"&&F.forEach((P,H)=>{if(typeof P!="string"&&P.inputValue&&P.inputValue!==""){const J={value:P.inputValue,type:m.name};a(J).then(()=>{x("suggest_tags",{props:{eventType:"tag_created"}}),z()}),P.title=P.inputValue,P.inputValue="",I[H]=P}});const _=Jt(O(I),m.name);$(_,c),L(I)},w="add-tag-form";return t.jsx(oe,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update feature toggle tags",onClick:Y,disabledPrimaryButton:y||T===0,onClose:C,formId:w,children:t.jsxs(t.Fragment,{children:[t.jsx(W,{paragraph:!0,sx:{marginBottom:E=>E.spacing(2.5)},children:"Tags allow you to group features together"}),t.jsx("form",{id:w,onSubmit:Y,children:t.jsxs(ci,{children:[t.jsx(Ua,{options:s,value:m,onChange:S}),t.jsx(Ya,{options:v,existingTags:c,tagType:m,selectedOptions:R,onChange:k})]})})]})})},li=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),di=p("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),ui=p(wn)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),pi=p(Re)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),gi=p(je)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),hi=({feature:e,header:n})=>{const{tags:s,refetch:r}=Gn(e.name),{deleteTagFromFeature:a}=Ke(),[o,i]=g.useState(!1),[c,l]=g.useState(!1),[d,u]=g.useState(),{setToastData:h,setToastApiError:m}=U(),{hasAccess:j}=g.useContext(mt),y=j(Ce,e.project),T=async()=>{if(d)try{await a(e.name,d.type,d.value),r(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(f){m(V(f))}};return t.jsxs(li,{children:[n,t.jsx(di,{children:s.map(f=>{const x=`${f.type}:${f.value}`;return t.jsx(ui,{label:x,deleteIcon:t.jsx(Hs,{titleAccess:"Remove"}),onDelete:y?()=>{l(!0),u(f)}:void 0},x)})}),t.jsx(b,{condition:y,show:t.jsxs(t.Fragment,{children:[t.jsx(b,{condition:s.length>0,show:t.jsx(pi,{})}),t.jsx(gi,{"data-loading":!0,variant:"outlined",startIcon:t.jsx(Ws,{}),onClick:()=>i(!0),children:"Add new tag"})]})}),t.jsx(Kn,{open:o,setOpen:i}),t.jsxs(oe,{open:c,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{l(!1),u(void 0)},onClick:()=>{l(!1),T(),u(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",t.jsxs("strong",{children:[d==null?void 0:d.type,":",d==null?void 0:d.value]})]})]})},fi=p(K)(({theme:e})=>({top:e.spacing(2),borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:"1rem",marginTop:"1rem",[e.breakpoints.down(1e3)]:{marginBottom:"1rem",width:"100%",maxWidth:"none",minWidth:"auto"}})),lt=p("h3")(({theme:e})=>({display:"flex",gap:e.spacing(1),alignItems:"center",fontSize:e.fontSizes.bodySize,margin:0,marginBottom:e.spacing(3),"& > :last-child":{position:"relative",top:1}})),xi=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{var i;const s=A("projectId"),r=A("featureId"),{feature:a}=M(s,r),o=((i=a.environments)==null?void 0:i.length)<=3;return t.jsxs(fi,{as:o?Us:K,children:[t.jsx(ii,{header:t.jsxs(lt,{"data-loading":!0,children:["Enabled in environments (",a.environments.filter(({enabled:c})=>c).length,")",t.jsx(Ys,{tooltip:"When a feature is switched off in an environment, it will always return false. When switched on, it will return true or false depending on its strategies.",placement:"top"})]}),feature:a,hiddenEnvironments:e,setHiddenEnvironments:n}),t.jsx(Re,{}),t.jsx(Jo,{header:t.jsx(lt,{"data-loading":!0,children:"Feature toggle details"}),feature:a}),t.jsx(Re,{}),t.jsx(hi,{header:t.jsx(lt,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:a})]})},mi=()=>{const{trackEvent:e}=ae(),{value:n,setValue:s}=Wn(),[r,a]=g.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:r,setHiddenEnvironments:i=>{s(c=>{const l=new Set(Array.from(c.hiddenEnvironments||[]));return l.has(i)?(l.delete(i),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(l.add(i),e("hidden_environment",{props:{eventType:"environment hidden"}})),a(l),{...n,hiddenEnvironments:[...l]}})}}},yi=()=>{const[e,n]=g.useState(0),s=A("projectId"),r=A("featureId"),a=Ae("environmentId"),o=Ae("strategyName"),{strategy:i,defaultStrategyFallback:c}=In(s,a),l=JSON.parse(pn().get("defaultStrategy")||"false"),{segments:d}=yt(),u=(d||[]).filter(J=>{var D;return(D=i==null?void 0:i.segments)==null?void 0:D.includes(J.id)}),[h,m]=g.useState({}),[j,y]=g.useState(l?u:[]),{strategyDefinition:T}=jt(o),f=St(),{addStrategyToFeature:x,loading:R}=he(),{addChange:L}=se(),{setToastData:q,setToastApiError:z}=U(),{uiConfig:v}=fe(),{unleashUrl:C}=v,$=ce(),{feature:O,refetchFeature:N}=M(s,r),G=g.useRef(O),{isChangeRequestConfigured:Y}=Z(s),{refetch:S}=te(s),{trackEvent:k}=ae(),{data:w,staleDataNotification:E,forceRefreshCache:F}=bt({unleashGetter:M,params:[s,r],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},O,{afterSubmitAction:N},vt);g.useEffect(()=>{G.current.name===""&&O.name&&(F(O),G.current=O)},[O.name]),g.useEffect(()=>{var J;if(l){const D=i||c;((J=D.parameters)==null?void 0:J.groupId)===""&&r?m({...D,parameters:{...D.parameters,groupId:r}}):m(D)}else T&&m(qn(r,T))},[r,JSON.stringify(T),l]);const B=async J=>{await x(s,r,a,J),q({title:"Strategy created",type:"success",confetti:!0})},I=async J=>{await L(s,a,{action:"addStrategy",feature:r,payload:J}),q({title:"Strategy added to draft",type:"success",confetti:!0}),S()},_=gn(h,j),P=async()=>{k("strategyTitle",{props:{hasTitle:!!h.title,on:"create"}});try{Y(a)?await I(_):await B(_),N(),$(Ue(s,r))}catch(J){z(V(J))}};return!w||!w.project?null:t.jsxs(Ge,{modal:!0,description:hn,documentationLink:fn,documentationLinkLabel:xn,disablePadding:!0,formatApiCode:()=>ji(s,r,a,_,C),children:[t.jsx(Tn,{projectId:s,feature:w,strategy:h,setStrategy:m,segments:j,setSegments:y,environmentId:a,onSubmit:P,loading:R,permission:de,errors:f,isChangeRequest:Y(a),tab:e,setTab:n,StrategyVariants:t.jsx(En,{strategy:h,setStrategy:m,environment:a,projectId:s,editable:!0})}),E]})},ji=(e,n,s,r,a)=>{if(!a)return"";const o=`${a}/api/admin/projects/${e}/features/${n}/environments/${s}/strategies`,i=JSON.stringify(r,void 0,2);return`curl --location --request POST '${o}' \\
5
+ --header 'Authorization: INSERT_API_KEY' \\
6
+ --header 'Content-Type: application/json' \\
7
+ --data-raw '${i}'`},Si=()=>{const[e,n]=g.useState(""),{trackEvent:s}=ae();return{setPreviousTitle:n,trackTitle:(a="")=>{a===e&&s("strategyTitle",{props:{action:"none",on:"edit"}}),e===""&&a!==""&&s("strategyTitle",{props:{action:"added",on:"edit"}}),e!==""&&a===""&&s("strategyTitle",{props:{action:"removed",on:"edit"}}),e!==""&&a!==""&&a!==e&&s("strategyTitle",{props:{action:"edited",on:"edit"}})}}},bi=e=>{if(e)return e==null?void 0:e.constraints.map(n=>({...n,[Ks]:_e()}))},vi=()=>{const e=A("projectId"),n=A("featureId"),s=Ae("environmentId"),r=Ae("strategyId"),[a,o]=g.useState(0),[i,c]=g.useState({}),[l,d]=g.useState([]),{updateStrategyOnFeature:u,loading:h}=he(),{strategyDefinition:m}=jt(i.name),{setToastData:j,setToastApiError:y}=U(),T=St(),{uiConfig:f}=fe(),{unleashUrl:x}=f,R=ce(),{addChange:L}=se(),{isChangeRequestConfigured:q}=Z(e),{refetch:z}=te(e),{setPreviousTitle:v}=Si(),{feature:C,refetchFeature:$}=M(e,n),O=g.useRef(C),{data:N,staleDataNotification:G,forceRefreshCache:Y}=bt({unleashGetter:M,params:[e,n],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},C,{afterSubmitAction:$},vt);g.useEffect(()=>{O.current.name===""&&C.name&&(Y(C),O.current=C)},[C]);const{segments:S,refetchSegments:k}=yt(r);g.useEffect(()=>{const I=N==null?void 0:N.environments.flatMap(H=>H.strategies).find(H=>H.id===r),_=bi(I),P={...I,constraints:_};c(H=>({...H,...P})),v((I==null?void 0:I.title)||"")},[r,N]),g.useEffect(()=>{S&&d(S)},[JSON.stringify(S)]);const w=Ci(i,l),E=async I=>{await u(e,n,s,r,I),await k(),j({title:"Strategy updated",type:"success",confetti:!0})},F=async I=>{await L(e,s,{action:"updateStrategy",feature:n,payload:{...I,id:r}}),j({title:"Change added to draft",type:"success",confetti:!0}),z()},B=async()=>{try{q(s)?await F(w):await E(w),$(),R(wi(e,n))}catch(I){y(V(I))}};return!i.id||!m||!N?null:t.jsxs(Ge,{modal:!0,disablePadding:!0,description:Ei,documentationLink:Ai,documentationLinkLabel:Di,formatApiCode:()=>Ti(e,n,s,r,w,m,x),children:[t.jsx(Tn,{projectId:e,feature:N,strategy:i,setStrategy:c,segments:l,setSegments:d,environmentId:s,onSubmit:B,loading:h,permission:dn,errors:T,isChangeRequest:q(s),tab:a,setTab:o,StrategyVariants:t.jsx(En,{strategy:i,setStrategy:c,environment:s,projectId:e})}),G]})},Ci=(e,n)=>({name:e.name,title:e.title,constraints:e.constraints??[],parameters:e.parameters??{},variants:e.variants??[],segments:n.map(s=>s.id),disabled:e.disabled??!1}),wi=(e,n)=>`/projects/${e}/features/${n}`,Ti=(e,n,s,r,a,o,i)=>{if(!i)return"";const c={...a,parameters:Gs(a.parameters??{},o)},l=`${i}/api/admin/projects/${e}/features/${n}/environments/${s}/strategies/${r}`,d=JSON.stringify(c,void 0,2);return`curl --location --request PUT '${l}' \\
8
+ --header 'Authorization: INSERT_API_KEY' \\
9
+ --header 'Content-Type: application/json' \\
10
+ --data-raw '${d}'`},Ei=`
11
+ An activation strategy will only run when a feature toggle is enabled and provides a way to control who will get access to the feature.
12
+ If any of a feature toggle's activation strategies returns true, the user will get access.
13
+ `,Ai="https://docs.getunleash.io/reference/activation-strategies",Di="Strategies documentation",Fi=p("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),Ri=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),$i=()=>{const e=ce(),n=A("projectId"),s=A("featureId"),r=Ue(n,s),{hiddenEnvironments:a,setHiddenEnvironments:o}=mi(),i=()=>e(r);An(s);const c=Dn("newStrategyConfiguration");return t.jsxs(Fi,{children:[t.jsxs("div",{children:[t.jsx(cr,{}),t.jsx(xi,{hiddenEnvironments:a,setHiddenEnvironments:o})]}),t.jsx(Ri,{children:t.jsx(Io,{})}),t.jsxs(Fn,{children:[t.jsx(xe,{path:"strategies/create",element:t.jsx(pt,{label:"Create feature strategy",onClose:i,open:!0,children:t.jsx(b,{condition:c,show:t.jsx(yi,{}),elseShow:t.jsx(Vr,{})})})}),t.jsx(xe,{path:"strategies/edit",element:t.jsx(pt,{label:"Edit feature strategy",onClose:i,open:!0,children:t.jsx(b,{condition:c,show:t.jsx(vi,{}),elseShow:t.jsx(Js,{})})})})]})]})},ki=p("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"},marginTop:e.spacing(-3.5),marginBottom:e.spacing(2),backgroundColor:e.palette.background.default,paddingTop:e.spacing(2),paddingBottom:e.spacing(2),position:"sticky",top:0,zIndex:2})),Ii=p(Rn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Pi=p("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontSize:e.fontSizes.mainHeader,fontWeight:e.fontWeight.bold})),Oi=p("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Bi=p(ie)(({theme:e})=>({marginBottom:e.spacing(2)})),Li=p(ie)(({theme:e})=>({marginTop:e.spacing(4)})),_i=p("div")({display:"flex",flexDirection:"column"}),Mi=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),Qt=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),qi=p(Re)(({theme:e})=>({margin:e.spacing(4,0)})),zi=p(Qs)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),Ni=p("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),Vi=p(je)(({theme:e})=>({marginLeft:e.spacing(3)})),Hi=g.memo(Zs),Wi=({environment:e,open:n,setOpen:s,getApiPayload:r,getCrPayload:a,onConfirm:o})=>{const i=A("projectId"),c=A("featureId"),{uiConfig:l}=fe(),{context:d}=Xs(),{defaultStickiness:u,loading:h}=ea(i),{isChangeRequestConfigured:m}=Z(i),{data:j}=te(i),{changeRequestInReviewOrApproved:y,alert:T}=na(j),f=(e==null?void 0:e.variants)||[],[x,R]=g.useState([]),[L,q]=g.useState();g.useEffect(()=>{h||R(f.length?f.map(D=>({...D,isValid:!0,new:!1,id:_e()})):[{name:"",weightType:kt.VARIABLE,weight:0,overrides:[],stickiness:(x==null?void 0:x.length)>0?x[0].stickiness:u,new:!0,isValid:!1,id:_e()}])},[n,h]);const z=(D,X)=>{R(Se=>It(Se.map(Pe=>Pe.id===X?D:Pe),1e3))},v=()=>{const D=_e();R(X=>[...X,{name:"",weightType:kt.VARIABLE,weight:0,overrides:[],stickiness:(X==null?void 0:X.length)>0?X[0].stickiness:u,new:!0,isValid:!1,id:D}]),q(D)};g.useEffect(()=>{if(L){const D=document.getElementById(`variant-name-input-${L}`);D==null||D.scrollIntoView({behavior:"smooth",block:"center"}),D==null||D.focus({preventScroll:!0}),q(void 0)}},[L]);const C=x.map(({new:D,isValid:X,id:Se,...Pe})=>Pe),$=r(f,C),O=a(C),N=async D=>{D.preventDefault(),o(C)},G=()=>w?`curl --location --request POST '${l.unleashUrl}/api/admin/projects/${i}/environments/${e==null?void 0:e.name}/change-requests' \\
14
+ --header 'Authorization: INSERT_API_KEY' \\
15
+ --header 'Content-Type: application/json' \\
16
+ --data-raw '${JSON.stringify(O,void 0,2)}'`:`curl --location --request PATCH '${l.unleashUrl}/api/admin/projects/${i}/features/${c}/environments/${e==null?void 0:e.name}/variants' \\
17
+ --header 'Authorization: INSERT_API_KEY' \\
18
+ --header 'Content-Type: application/json' \\
19
+ --data-raw '${JSON.stringify($.patch,void 0,2)}'`,Y=x.every(({isValid:D})=>D),S=y((e==null?void 0:e.name)||""),k=S?"Add to existing change request":"Add change to draft",w=m((e==null?void 0:e.name)||""),E=g.useMemo(()=>{var D;return h?"":((D=C[0])==null?void 0:D.stickiness)||u},[h,u,JSON.stringify(C[0]??{})]),F=g.useMemo(()=>["default",...d.filter(D=>D.stickiness).map(D=>D.name)],[d]),B=F.map(D=>({key:D,label:D}));F.includes(E)||B.push({key:E,label:E});const I=async D=>{R(X=>X.map(Se=>({...Se,stickiness:D})))},_=D=>{I(D)},[P,H]=g.useState();g.useEffect(()=>{H(void 0),$.error&&H($.error)},[$.error]);const J=()=>{I(u),s(!1)};return h||E===""?t.jsx(ta,{}):t.jsx(pt,{open:n,onClose:J,label:"",children:t.jsxs(Ge,{modal:!0,title:"",description:"Variants allow you to return a variant object if the feature toggle is considered enabled for the current request.",documentationLink:"https://docs.getunleash.io/reference/feature-toggle-variants",documentationLinkLabel:"Feature toggle variants documentation",formatApiCode:G,loading:!n,children:[t.jsxs(ki,{children:[t.jsxs("div",{children:[t.jsx(Ii,{deprecated:!(e!=null&&e.enabled)}),t.jsx(Pi,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t.jsx(pe,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:v,variant:"outlined",permission:be,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),t.jsxs(Oi,{onSubmit:N,children:[t.jsx(b,{condition:S,show:T,elseShow:t.jsx(b,{condition:!!w,show:t.jsxs(Bi,{severity:"info",children:[t.jsx("strong",{children:"Change requests"})," are enabled",e?` for ${e.name}`:"",". Your changes need to be approved before they will be live. All the changes you do now will be added into a draft that you can submit for review."]})})}),t.jsx(_i,{children:x.map(D=>t.jsx(Hi,{variant:D,variants:x,updateVariant:X=>z(X,D.id),removeVariant:()=>R(X=>It(X.filter(Se=>Se.id!==D.id),1e3)),error:$.error},D.id))}),t.jsx(pe,{onClick:v,variant:"outlined",permission:be,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"}),t.jsx(qi,{}),t.jsx(b,{condition:x.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(Mi,{children:t.jsx("p",{children:"Stickiness"})}),t.jsxs(Qt,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t.jsx(Et,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t.jsx("div",{children:t.jsx(zi,{value:E,label:"",editable:!0,onChange:D=>_(D.target.value)})})]}),elseShow:t.jsx(Qt,{children:"This environment has no variants. Get started by adding a variant."})}),t.jsxs(Li,{severity:"error",hidden:!P,children:[t.jsx("strong",{children:"Error: "}),P]}),t.jsxs(Ni,{children:[t.jsx(je,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!Y,children:w?k:"Save variants"}),t.jsx(Vi,{onClick:J,children:"Cancel"})]})]})]})})},Ui=e=>fetch(e).then(ye("ChangeRequest")).then(n=>n.json()),Yi=(e,n)=>{const{data:s,error:r,mutate:a}=un([],ge(`api/admin/projects/${e}/change-requests/scheduled?variantForFlag=${n}`),Ui);return{changeRequests:s,loading:!r&&!s,refetch:a,error:r}},Gi=(e,n,s)=>{const{changeRequests:r}=Yi(e,n),a=r==null?void 0:r.filter(o=>o.environment===s);return a?a.map(o=>o.id):[]},Ki=p("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.divider}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),Ji=p("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Qi=p(Rn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Zi=p("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontWeight:e.fontWeight.bold})),Xi=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),ec=p("div")(({theme:e})=>({margin:e.spacing(3,0)})),tc=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),nc=({environment:e,searchValue:n,children:s})=>{var l;const r=A("projectId"),a=A("featureId"),o=Gi(r,a,e.name),i=e.variants??[],c=((l=i[0])==null?void 0:l.stickiness)||"default";return t.jsxs(Ki,{children:[t.jsxs(Ji,{children:[t.jsxs("div",{children:[t.jsx(Qi,{deprecated:!e.enabled}),t.jsx(Zi,{deprecated:!e.enabled,children:e.name}),t.jsx(b,{condition:o.length>0,show:t.jsx(sa,{sx:{ml:2},children:t.jsx(Mn,{scheduledChangeRequestIds:o})})})]}),s]}),t.jsx(b,{condition:i.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(ec,{children:t.jsx(aa,{variants:i,searchValue:n})}),t.jsx(b,{condition:i.length>1,show:t.jsxs(t.Fragment,{children:[t.jsxs(tc,{children:[t.jsx("p",{children:"Stickiness:"}),t.jsx(Ee,{children:c})]}),t.jsxs(Xi,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t.jsx(Et,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},sc=p(me)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),ac=({environment:e,permission:n,projectId:s,environmentId:r,onCopyVariantsFrom:a,otherEnvsWithVariants:o})=>{const[i,c]=g.useState(null),l=!!i,d=e.variants??[];return t.jsx(b,{condition:o.length>0&&d.length===0,show:t.jsxs(t.Fragment,{children:[t.jsx(pe,{onClick:u=>{c(u.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,variant:"outlined",permission:n,projectId:s,environmentId:r,children:"Copy variants from"}),t.jsx(ke,{anchorEl:i,open:l,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:o.map(u=>t.jsx(ue,{onClick:()=>a(u,e),children:t.jsx(sc,{children:`Copy from ${u.name}`})},u.name))})]})})},rc=({permission:e,projectId:n,environment:s,checked:r,onClick:a,...o})=>{const i=ut(e,n,s);return t.jsxs(ue,{disabled:!i,onClick:a,...o,children:[t.jsx(ra,{checked:r}),s]})},oc=p(ke)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),ic=p("div")(({theme:e})=>({margin:e.spacing(1,2)})),cc=p(je)(({theme:e})=>({marginTop:e.spacing(2)})),lc=({current:e,environments:n,permission:s,projectId:r,onSubmit:a})=>{var T;const[o,i]=g.useState(null),c=!!o,[l,d]=g.useState([]),u=f=>{d(x=>[...x,f])},h=f=>{d(x=>x.filter(({name:R})=>R!==f.name))},m=f=>{l.includes(f)?h(f):u(f)},j=()=>{d([]),i(null)},y=((T=n.find(f=>f.name===e))==null?void 0:T.variants)??[];return t.jsx(b,{condition:y.length>0&&n.length>1,show:t.jsxs(t.Fragment,{children:[t.jsx(je,{onClick:f=>{i(f.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,variant:"outlined",children:"Copy to environment"}),t.jsxs(oc,{anchorEl:o,open:c,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(f=>f.name!==e).map(f=>t.jsx(rc,{projectId:r,permission:s,environment:f.name,checked:l.includes(f),onClick:()=>m(f)},f.name)),t.jsxs(ic,{children:[t.jsx(Re,{}),t.jsxs(cc,{variant:"outlined",onClick:()=>{a(l),j()},disabled:l.length===0,children:["Push to selected (",l.length,")"]})]})]})]})})},dc=p("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),uc=()=>{const{setToastData:e,setToastApiError:n}=U(),s=xt(),r=Ie(s.breakpoints.down("md")),a=A("projectId"),o=A("featureId"),{feature:i,refetchFeature:c,loading:l}=M(a,o),{patchFeatureEnvironmentVariants:d,overrideVariantsInEnvironments:u}=Ke(),{refetch:h}=te(a),{addChange:m}=se(),{isChangeRequestConfigured:j}=Z(a),[y,T]=g.useState(""),[f,x]=g.useState(),[R,L]=g.useState(!1),q=g.useMemo(()=>{var S;return((S=i==null?void 0:i.environments)==null?void 0:S.map(k=>({...k,crEnabled:j(k.name)})))||[]},[i.environments]),z=(S,k)=>la(S,k),v=(S,k)=>{try{const w=ca(k,1e3);return{patch:z(S,w)}}catch(w){return{patch:[],error:V(w)}}},C=S=>({feature:o,action:"patchVariant",payload:{variants:S}}),$=async(S,k)=>{if(S.crEnabled)await m(a,S.name,C(k)),h();else{const w=S.variants??[],{patch:E,error:F}=v(w,k);if(E.length===0)return;if(F){e({type:"error",title:F});return}await d(a,o,S.name,E)}c()},O=async(S,k)=>{try{const w=k.filter(({crEnabled:_})=>_),E=k.filter(({crEnabled:_})=>!_);w.length&&await Promise.all(w.map(_=>m(a,_.name,C(S)))),E.length&&await u(a,o,S,E.map(({name:_})=>_)),h(),c();const F=E.length?`Variants pushed to ${E.length===1?E[0].name:`${E.length} environments`}`:"",B=w.length?`Variants push added to ${w.length===1?`${w[0].name} draft`:`${w.length} drafts`}`:"",I=`${F}${F&&B?". ":""}${B}`;e({title:I,type:"success"})}catch(w){n(V(w))}},N=S=>{x(S),L(!0)},G=async S=>{if(f)try{await $(f,S),L(!1),e({title:f.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(k){n(V(k))}},Y=async(S,k)=>{try{const w=S.variants??[];await $(k,w),e({title:k.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(w){n(V(w))}};return t.jsxs(At,{isLoading:l,header:t.jsx(oa,{title:"Variants",actions:t.jsx(b,{condition:!r,show:t.jsx(t.Fragment,{children:t.jsx(Pt,{initialValue:y,onChange:T})})}),children:t.jsx(b,{condition:r,show:t.jsx(Pt,{initialValue:y,onChange:T})})}),children:[t.jsx(ia,{}),q.map(S=>{var w;const k=q.filter(({name:E,variants:F})=>E!==S.name&&(F==null?void 0:F.length));return t.jsx(nc,{environment:S,searchValue:y,children:t.jsxs(dc,{children:[t.jsx(lc,{current:S.name,environments:q,permission:be,projectId:a,onSubmit:E=>O(S.variants??[],E)}),t.jsx(ac,{environment:S,permission:be,projectId:a,environmentId:S.name,onCopyVariantsFrom:Y,otherEnvsWithVariants:k}),t.jsx(b,{condition:!!((w=S.variants)!=null&&w.length),show:t.jsx(re,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>N(S),permission:be,projectId:a,environmentId:S.name,tooltipProps:{title:"Edit variants"},children:t.jsx(we,{})}),elseShow:t.jsx(pe,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>N(S),variant:"outlined",permission:be,projectId:a,environmentId:S.name,children:"Add variant"})})]})},S.name)}),t.jsx(Wi,{environment:f,open:R,setOpen:L,getApiPayload:v,getCrPayload:C,onConfirm:G})]})},pc=ge("api/admin/client-metrics/features"),Jn=(e,n)=>{const s=ge(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:r,error:a}=We(s,()=>gc(s)),o=g.useCallback(()=>{ft(pc).catch(console.warn)},[]);return{featureMetrics:r==null?void 0:r.data,loading:!a&&!r,refetchFeatureMetrics:o,error:a}},gc=e=>fetch(e).then(ye("Features")).then(n=>n.json()).then(),hc=()=>{const{isEnterprise:e}=fe(),n=Dn("extendedUsageMetricsUI");return e()&&n},fc=p("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),He=48,xc=({hoursBack:e,setHoursBack:n})=>{const{trackEvent:s}=ae(),r=c=>{n(parseInt(c)),s("feature-metrics",{props:{eventType:"change-period",hoursBack:c}})},o=hc()?[...Zt,...mc]:Zt,i=o.map(c=>Number(c.key)).includes(e)?e:He;return g.useEffect(()=>{e!==i&&n(i)},[e]),t.jsxs("div",{children:[t.jsx(fc,{children:"Period"}),t.jsx(Sn,{name:"feature-metrics-period",id:"feature-metrics-period",options:o,value:String(i),onChange:r,fullWidth:!0})]})},Zt=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:"48",label:"Last 48 hours"}],mc=[{key:`${7*24}`,label:"Last 7 days"},{key:`${30*24}`,label:"Last 30 days"},{key:`${90*24}`,label:"Last 90 days"}],yc=({value:e,timeZone:n})=>{const{locationSettings:s}=vn(),r=e?e instanceof Date?Ot(e,s.locale,n):Ot(Cn(e),s.locale,n):void 0;return t.jsx(Ne,{lineClamp:1,children:r})},jc=p(W)(({theme:e})=>({fontSize:e.fontSizes.smallerBody})),Sc=({row:e})=>e.original.selectedApplications&&e.original.selectedApplications.length>1?t.jsx(Ne,{children:t.jsx(Ye,{tooltip:t.jsx(t.Fragment,{children:e.original.selectedApplications.map(n=>t.jsx(jc,{children:n},n))}),children:e.original.appName})}):t.jsx(Ne,{children:e.original.appName}),bc=({metrics:e,tableSectionId:n})=>{const s=Ie(da.breakpoints.down("md")),r=g.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:a,getTableBodyProps:o,headerGroups:i,rows:c,prepareRow:l,setHiddenColumns:d}=Ze.useTable({initialState:r,columns:Xt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:Ne}},Ze.useGlobalFilter,Ze.useSortBy);return ua([{condition:s,columns:["appName","environment"]}],d,Xt),e.length===0?null:t.jsxs(pa,{...a(),rowHeight:"standard",id:n,children:[t.jsx(ga,{headerGroups:i}),t.jsx(ha,{...o(),children:c.map(u=>(l(u),t.jsx(fa,{hover:!0,...u.getRowProps(),children:u.cells.map(h=>t.jsx(xa,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},Xt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t.jsx(ma,{icon:t.jsx(Xa,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t.jsx(yc,{value:e.row.original.timestamp,timeZone:e.row.original.timestamp.includes("23:59")?"UTC":void 0})},{Header:"Application",accessor:"appName",Cell:Sc},{Header:"Environment",accessor:"environment"},{id:"requested",Header:"Requested",accessor:e=>e.yes+e.no},{Header:"Exposed",accessor:"yes"}],vc=({metrics:e,...n})=>{const s=g.useMemo(()=>e.reduce((a,o)=>a+o.yes,0),[e]),r=g.useMemo(()=>e.reduce((a,o)=>a+o.no,0),[e]);return t.jsx(Hn,{...n,totalYes:s,totalNo:r})},Cc=({metrics:e,hoursBack:n})=>{const s=Bt(),r=Bt();return e.length===0?t.jsxs(K,{mt:6,children:[t.jsx(W,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t.jsx(W,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):t.jsxs(g.Suspense,{fallback:null,children:[t.jsx(K,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t.jsx(wc,{metrics:e,hoursBack:n,statsSectionId:s})}),t.jsx(K,{mt:4,children:t.jsx(vc,{metrics:e,hoursBack:n,statsSectionId:s,tableSectionId:r})}),t.jsx(K,{mt:4,children:t.jsx(bc,{metrics:e,tableSectionId:r})})]})},wc=ya.lazy(()=>ja(()=>import("./FeatureMetricsChart-ig6HN-Ms.js"),__vite__mapDeps([]))),Tc=p("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ec=p("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%",alignItems:"center",maxHeight:"200px",overflowY:"auto"})),Ac=p("li")(({theme:e})=>({"& > [aria-pressed=true]":{backgroundColor:e.palette.background.alternative,color:e.palette.primary.contrastText},"& > [aria-pressed=true]:hover":{backgroundColor:e.palette.primary.light}})),en=({title:e,values:n,selectedValues:s,toggleValue:r,toggleValues:a})=>{const o=l=>()=>{r(l)},i=[...n].every(l=>s.includes(l)),c=g.useMemo(()=>Array.from(n).sort((l,d)=>l.localeCompare(d)),[n]);return t.jsxs("div",{children:[t.jsx(Tc,{children:e}),t.jsxs(Ec,{children:[c.map(l=>t.jsx(Ac,{children:t.jsx(wn,{label:l,onClick:o(l),"aria-pressed":s==null?void 0:s.includes(l),sx:Sa})},l)),a&&n.size>1&&t.jsx(je,{size:"small",onClick:a,"aria-pressed":i,children:i?"Unselect":"Select all"})]})]})},Dc=e=>{const n=new Map;return e.forEach(s=>{let r=n.get(s.timestamp);if(r||(r={...s,yes:0,no:0,variants:{}},n.set(s.timestamp,r)),r.yes+=s.yes,r.no+=s.no,s.variants){r.variants=r.variants||{};for(const[a,o]of Object.entries(s.variants))r.variants[a]=(r.variants[a]||0)+o}}),Array.from(n.values()).map(s=>({...s,variants:s.variants&&Object.keys(s.variants).length===0?void 0:s.variants}))},Fc=()=>{const e=A("projectId"),n=A("featureId"),s=Rc(e,n);An("Metrics");const r=Array.from(s)[0],[a,o]=ba({environment:Xe(va,r),applications:Xe(Ca,[]),hoursBack:Xe(wa,He)}),i=$c(n,a.hoursBack||He),c=Array.from(i)[0],{environment:l,hoursBack:d}=a,u=a.applications.filter(f=>f!==null);g.useEffect(()=>{a.applications&&a.applications.length===0&&c&&o({applications:[c]})},[JSON.stringify(Array.from(i))]);const h=[...i].every(f=>u.includes(f)),{featureMetrics:m}=Jn(n,d),[j,y]=g.useState(m);g.useEffect(()=>{m&&y(m)},[m]);const T=g.useMemo(()=>Dc((j==null?void 0:j.filter(f=>l===f.environment).filter(f=>u.includes(f.appName)))||[]).map(f=>({...f,appName:u.length>1?"all selected":f.appName,selectedApplications:u})),[j,l,JSON.stringify(u)]);return T?t.jsxs(At,{children:[t.jsxs(le,{container:!0,component:"header",spacing:2,children:[t.jsx(le,{item:!0,xs:12,md:5,children:t.jsx(b,{condition:s.size>0,show:t.jsx(en,{title:"Environments",values:s,selectedValues:[l],toggleValue:f=>{o({environment:f})}})})}),t.jsx(le,{item:!0,xs:12,md:5,children:t.jsx(b,{condition:i.size>0,show:t.jsx(en,{title:"Applications",values:i,selectedValues:u,toggleValues:()=>{o(h?{applications:[c]}:{applications:[...i]})},toggleValue:f=>{u.includes(f)?o({applications:u.filter(x=>x!==f)}):o({applications:[...u,f]})}})})}),t.jsx(le,{item:!0,xs:12,md:2,children:t.jsx(xc,{hoursBack:d,setHoursBack:f=>o({hoursBack:f})})})]}),t.jsx(Cc,{metrics:T,hoursBack:d})]}):null},Rc=(e,n)=>{const{feature:s}=M(e,n),r=s.environments.map(a=>a.name);return new Set(r)},$c=(e,n=He)=>{const{featureMetrics:s=[]}=Jn(e,n),r=s.map(a=>a.appName);return new Set(r)},kc=(e,n)=>{const s=new Set(e),r=new Set(n);return s.size!==r.size?!1:[...s].every(a=>r.has(a))},tn=p("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),nn=p(ie)(({theme:e})=>({marginBottom:e.spacing(1)})),Ic=p(wt)({padding:0}),Pc=({projectId:e,open:n,onClose:s,onClick:r,feature:a,changeRequests:o})=>{const i=A("projectId"),{project:c}=$n(e),{isChangeRequestConfiguredInAnyEnv:l}=Z(e),d=l(),u=g.useMemo(()=>kc(a.environments.map(j=>j.name),c.environments.map(j=>j.environment)),[a,c]),h=o?o.length>0:!1,m=a.dependencies.length>0||a.children.length>0;return t.jsx(b,{condition:u&&!m&&!h&&!d,show:t.jsx(oe,{open:n,onClose:s,onClick:r,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:t.jsxs(tn,{children:[t.jsx(nn,{severity:"success",children:"This feature toggle is compatible with the new project."}),t.jsx("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t.jsx(oe,{open:n,onClick:s,title:"Confirm change project",primaryButtonText:"Close",children:t.jsxs(tn,{children:[t.jsx(nn,{severity:"warning",children:"Cannot proceed with the move"}),t.jsx(b,{condition:m,show:t.jsxs("p",{children:[t.jsx("span",{children:"The feature toggle must not have any dependencies."})," ",t.jsx("br",{}),t.jsx("span",{children:"Please remove feature dependencies first."})]})}),t.jsx(b,{condition:!u,show:t.jsx("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t.jsx(b,{condition:h,show:t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"The feature toggle must not have any pending change requests. This feature toggle is currently referenced in the following change requests:"}),t.jsx(Ic,{children:o==null?void 0:o.map(j=>t.jsx(ve,{children:t.jsxs(Q,{to:`/projects/${i}/change-requests/${j.id}`,children:["View change request"," ",j.id]})},j.id))})]})}),t.jsx(b,{condition:d,show:t.jsxs("p",{children:["You're not allowed to move the feature to project"," ",t.jsx(Q,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},Oc=()=>{const{hasAccess:e}=g.useContext(mt),n=A("projectId"),s=A("featureId"),{feature:r,refetchFeature:a}=M(n,s),[o,i]=g.useState(!1),{changeFeatureProject:c}=Ke(),{setToastData:l,setToastApiError:d}=U(),[u,h]=g.useState(n),{projects:m}=Ta(),j=ce(),{changeRequests:y}=_n(n,s),T=async()=>{try{u&&(await c(n,s,u),a(),l({title:"Project changed",type:"success"}),i(!1),j(`/projects/${u}/features/${s}/settings`,{replace:!0}))}catch(x){d(V(x))}},f=g.useMemo(()=>m.map(x=>x.id).filter(x=>e(Lt,x)),[m,e]);return f.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx(Ea,{value:u,onChange:h,label:"Project",filter:x=>f.includes(x),enabled:!0}),t.jsx(pe,{permission:Lt,onClick:()=>i(!0),disabled:u===n,projectId:n,children:"Save"}),t.jsx(Pc,{changeRequests:y,projectId:u,open:o,feature:r,onClose:()=>i(!1),onClick:T})]})},Bc=p("div")({display:"flex",alignItems:"center"}),Lc=p(W)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),_c=({projectId:e,featureId:n})=>{var o;const{feature:s}=M(e,n),r=ce(),a=()=>{r(`/projects/${e}/features/${n}/edit`)};return t.jsxs(t.Fragment,{children:[t.jsxs(Bc,{children:[t.jsx(Lc,{children:"Feature information"}),t.jsx(re,{permission:Ce,projectId:e,"data-loading":!0,onClick:a,tooltipProps:{title:"Edit"},children:t.jsx(we,{})})]}),t.jsxs(W,{children:["Name: ",t.jsx("strong",{children:s.name})]}),t.jsxs(W,{children:["Description:"," ",t.jsx("strong",{children:(o=s.description)!=null&&o.length?s.description:"no description"})]}),t.jsxs(W,{children:["Type: ",t.jsx("strong",{children:s.type})]}),t.jsxs(W,{children:["Impression Data:"," ",t.jsx("strong",{children:s.impressionData?"enabled":"disabled"})]})]})},Le="metadata",dt="project",Mc=p("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),qc=p("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,"& > *":{margin:e.spacing(1,0)}})),zc=()=>{const e=A("projectId"),n=A("featureId"),[s,r]=g.useState(Le),{uiConfig:a}=fe();return t.jsx(At,{header:"Settings",sx:{padding:0},children:t.jsxs(K,{sx:{display:"flex"},children:[t.jsx(Mc,{children:t.jsxs(wt,{children:[t.jsx(ve,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(Le),selected:s===Le,children:"Metadata"},0),t.jsx(ve,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(dt),selected:s===dt,hidden:!a.flags.P,children:"Project"},1)]})}),t.jsxs(qc,{children:[t.jsx(b,{condition:s===Le,show:t.jsx(_c,{projectId:e,featureId:n})}),t.jsx(b,{condition:s===dt&&a.flags.P,show:t.jsx(Oc,{})})]})]})})},Nc=({stale:e,showActive:n=!0})=>{if(!e&&!n)return null;const s=e?"Feature toggle is deprecated.":"Feature toggle is active.",r=e?"Stale":"Active";return t.jsx("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t.jsx(Ee,{color:e?"error":"success",title:s,children:r})})},sn=p("strong")({wordBreak:"break-all"}),Vc=()=>{const e=A("projectId"),n=A("featureId"),{archivedFeatures:s}=Aa(),r=Da(e,{name:n});return s?s.some(o=>o.name===n)?t.jsxs("p",{children:["The feature ",t.jsx(sn,{children:n})," has been archived. You can find it on the"," ",t.jsx(Q,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):t.jsxs("p",{children:["The feature ",t.jsx(sn,{children:n})," does not exist. Would you like to"," ",t.jsx(Q,{to:r,children:"create it"}),"?"]}):null},Hc=p(Q)(({theme:e})=>({textDecoration:"none",color:e.palette.primary.main,fontWeight:e.fontWeight.bold})),Wc=({isOpen:e,onClose:n,features:s,project:r})=>t.jsxs(oe,{title:"You can't archive a feature that other features depend on",open:e,primaryButtonText:"OK",onClick:n,children:[t.jsx("p",{children:"The following features depend on your feature:"}),t.jsx("ul",{children:s.map(a=>t.jsx("li",{children:t.jsx(Hc,{to:`/projects/${r}/features/${a}`,target:"_blank",rel:"noopener noreferrer",children:a})},a))})]}),Uc=e=>g.createElement("svg",{fill:"none",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},g.createElement("path",{d:"M1 12a5 5 0 0 1 5-5h4a5 5 0 0 1 4.584 7H14a1.993 1.993 0 0 1-1.375-.547A3 3 0 0 0 10 9H6a3 3 0 1 0 0 6h2.803a6.03 6.03 0 0 0 1.822 1.961A5.033 5.033 0 0 1 10 17H6a5 5 0 0 1-5-5Z",fill:"#202021"}),g.createElement("path",{d:"M9 12c0-.711.148-1.387.416-2H10c.532 0 1.016.208 1.375.547A3 3 0 0 0 14 15h4a3 3 0 1 0 0-6h-2.803a6.03 6.03 0 0 0-1.822-1.961C13.58 7.013 13.788 7 14 7h4a5 5 0 0 1 0 10h-4a5 5 0 0 1-5-5Z",fill:"#202021"})),Yc=e=>g.createElement("svg",{fill:"none",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},g.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1 8a5 5 0 0 1 5-5h4a5 5 0 0 1 4.584 7H14a1.993 1.993 0 0 1-1.375-.547A3 3 0 0 0 10 5H6a3 3 0 0 0 0 6h2.803a6.03 6.03 0 0 0 1.822 1.961A5.033 5.033 0 0 1 10 13H8v3a1 1 0 0 0 1 1h1.17A3.001 3.001 0 0 1 13 15h7a3 3 0 1 1 0 6h-7a3.001 3.001 0 0 1-2.83-2H9a3 3 0 0 1-3-3v-3a5 5 0 0 1-5-5Zm8 0c0-.711.148-1.388.416-2H10c.532 0 1.016.208 1.375.547A3 3 0 0 0 14 11h4a3 3 0 1 0 0-6h-2.803a6.03 6.03 0 0 0-1.822-1.961C13.58 3.013 13.788 3 14 3h4a5 5 0 0 1 0 10h-4a5 5 0 0 1-5-5Z",fill:"#202021"})),Gc=p("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),Kc=p("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),an=p("div")({display:"flex",alignItems:"center"}),rn=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1),marginTop:e.spacing(1),fontSize:e.fontSizes.smallBody,padding:e.spacing(.75,1.5),backgroundColor:e.palette.background.elevation2,borderRadius:`${e.shape.borderRadiusMedium}px`,width:"max-content"}));p(Uc)(({theme:e})=>({width:e.fontSizes.smallBody,height:e.fontSizes.smallBody}));p(Yc)(({theme:e})=>({width:e.fontSizes.smallBody,height:e.fontSizes.smallBody}));const Jc=p("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),Qc=p("div")({flexShrink:0,display:"flex"}),Zc=p("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),Xc=p("div")(({theme:e})=>({padding:e.spacing(0,4)})),el=p(Fa)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),tl=p(Q)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),nl=()=>{var S,k;const e=A("projectId"),n=A("featureId"),{refetch:s}=$n(e),{favorite:r,unfavorite:a}=Ra(),{refetchFeature:o}=M(e,n),{setToastData:i,setToastApiError:c}=U(),[l,d]=g.useState(!1),[u,h]=g.useState(!1),[m,j]=g.useState(!1),[y,T]=g.useState(!1),f=Ie("(max-width:500px)"),{feature:x,loading:R,error:L,status:q}=M(e,n),z=ce(),{pathname:v}=$a(),C=ka(R),$=`/projects/${e}/features/${n}`,O=[{title:"Overview",path:`${$}`,name:"overview"},{title:"Metrics",path:`${$}/metrics`,name:"Metrics"},{title:"Variants",path:`${$}/variants`,name:"Variants"},{title:"Settings",path:`${$}/settings`,name:"Settings"},{title:"Event log",path:`${$}/logs`,name:"Event log"}],N=O.find(w=>w.path===v)??O[0],G=async()=>{try{x!=null&&x.favorite?await a(e,x.name):await r(e,x.name),o()}catch{c("Something went wrong, could not update favorite")}};if(q===404)return t.jsx(Vc,{});if(L!==void 0)return t.jsx("div",{ref:C});const Y=()=>{try{qa(x.name),T(!0),setTimeout(()=>{T(!1)},3e3)}catch{i({type:"error",title:"Could not copy feature name"})}};return t.jsxs("div",{ref:C,children:[t.jsxs(Gc,{children:[t.jsxs(Kc,{children:[t.jsxs(an,{children:[t.jsx(Ia,{onClick:G,isFavorite:x==null?void 0:x.favorite}),t.jsxs("div",{children:[t.jsxs(an,{children:[t.jsxs(Jc,{"data-loading":!0,children:[x.name," "]}),t.jsx(ee,{title:y?"Copied!":"Copy name",arrow:!0,children:t.jsx($e,{onClick:Y,style:{marginLeft:8},children:y?t.jsx(Pa,{style:{fontSize:16}}):t.jsx(Oa,{style:{fontSize:16}})})}),t.jsx(b,{condition:!f,show:t.jsx(Nc,{stale:x==null?void 0:x.stale})})]}),t.jsx(b,{condition:x.dependencies.length>0,show:t.jsxs(rn,{children:[t.jsx("b",{children:"Has parent: "}),t.jsx(tl,{to:`/projects/${x.project}/features/${(S=x==null?void 0:x.dependencies[0])==null?void 0:S.feature}`,children:(k=x==null?void 0:x.dependencies[0])==null?void 0:k.feature})]})}),t.jsx(b,{condition:x.children.length>0,show:t.jsxs(rn,{children:[t.jsx("b",{children:"Has children:"}),t.jsx(Yn,{childFeatures:x.children,project:x.project})]})})]})]}),t.jsxs(Qc,{children:[t.jsx(re,{permission:Ba,projectId:e,"data-loading":!0,component:Q,to:`/projects/${e}/features/${n}/copy`,tooltipProps:{title:"Clone"},children:t.jsx(er,{})}),t.jsx(re,{permission:La,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>h(!0),children:t.jsx(Za,{})}),t.jsx(re,{onClick:()=>j(!0),permission:Ce,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t.jsx(Ga,{})}),t.jsx(re,{onClick:()=>d(!0),permission:Ce,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t.jsx(_a,{})})]})]}),t.jsx(Zc,{}),t.jsx(Xc,{children:t.jsx(Ma,{value:N.path,indicatorColor:"primary",textColor:"primary",children:O.map(w=>t.jsx(el,{label:w.title,value:w.path,onClick:()=>z(w.path),"data-testid":`TAB-${w.title}`},w.title))})})]}),t.jsxs(Fn,{children:[t.jsx(xe,{path:"metrics",element:t.jsx(Fc,{})}),t.jsx(xe,{path:"logs",element:t.jsx(nr,{})}),t.jsx(xe,{path:"variants",element:t.jsx(uc,{})}),t.jsx(xe,{path:"settings",element:t.jsx(zc,{})}),t.jsx(xe,{path:"*",element:t.jsx($i,{})})]}),t.jsx(b,{condition:x.children.length>0,show:t.jsx(Wc,{features:x.children,project:e,isOpen:u,onClose:()=>h(!1)}),elseShow:t.jsx(Ka,{isOpen:u,onConfirm:()=>{s(),z(`/projects/${e}`)},onClose:()=>h(!1),projectId:e,featureIds:[n]})}),t.jsx(Ja,{isStale:x.stale,isOpen:m,onClose:()=>{j(!1),o()},featureId:n,projectId:e}),t.jsx(Kn,{open:l,setOpen:d})]})},ol=Object.freeze(Object.defineProperty({__proto__:null,default:nl},Symbol.toStringTag,{value:"Module"}));export{ol as F,uo as d};
20
+ function __vite__mapDeps(indexes) {
21
+ if (!__vite__mapDeps.viteFileDeps) {
22
+ __vite__mapDeps.viteFileDeps = []
23
+ }
24
+ return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
25
+ }
@@ -1,4 +1,4 @@
1
- import{c as ft,j as e,c$ as zs,d0 as ge,d1 as xs,d2 as gs,d3 as $e,at as Q,au as X,ao as le,d4 as Vs,d5 as Ys,d6 as Kn,d7 as Zn,d8 as yt,d9 as Qn,q as Xn,da as eo,b as J,ax as N,ay as ve,r as h,ch as Js,aA as Ce,aB as Ks,db as Kt,f as z,aD as Ee,s as m,A as Zs,k as Z,C as S,dc as Qs,bZ as Zt,aO as ie,dd as to,de as Xs,aP as je,df as Ne,bL as f,dg as ce,dh as me,F as bt,u as fe,di as Me,J as K,I as so,S as no,M as He,h as _,aN as Le,b7 as se,T as B,aK as re,B as q,cZ as St,cQ as vt,dj as rt,dk as oo,D as Qt,dl as en,d as tn,dm as ao,dn as Ue,G as ze,dp as io,ba as ro,bb as lo,a3 as U,a4 as pe,ab as te,a5 as co,a6 as uo,a7 as Xt,a8 as it,a9 as ho,ap as de,dq as xe,x as Ge,aQ as sn,dr as nn,ds as M,b_ as on,dt as po,du as an,dv as rn,dw as ae,b$ as ln,dx as mo,cE as js,dy as cn,a1 as dn,dz as Oe,t as Be,bJ as xo,bW as go,b3 as Ot,aL as Ve,b5 as Ut,bX as Ae,dA as jo,dB as fo,dC as yo,dD as $t,l as es,m as bo,n as So,ac as he,cB as De,ae as Se,af as Ye,ag as ye,bu as vo,cl as Ct,dE as un,ak as hn,dF as ts,c9 as wt,dG as Co,aq as qe,v as _e,dH as wo,Q as To,dI as ko,dJ as Ro,cb as at,dK as Eo,dL as Ao,aE as ss,dM as ns,y as pn,ai as Do,a as os,dN as Je,dO as Io,an as Ke,aI as ue,dP as Po,dQ as Bo,dR as Lo,dS as Oo,cj as lt,ck as G,cv as fs,dT as mn,br as as,aj as is,dU as Uo,cD as xn,cS as rs,dV as $o,am as gn,dW as No,dX as ys,dY as Ie,R as Fo,dZ as pt,bO as Go,bP as qo,bT as _o,bQ as Wo,d_ as Ho,d$ as Mo,e0 as zo,e1 as Vo,e2 as Yo,e3 as Jo,cn as Ko,e4 as Zo,e5 as Qo,e6 as Xo,e7 as jn,aa as ea,e8 as ta,e9 as Nt,ea as sa,eb as na,ec as fn,ed as jt,ee as yn,ef as oa,eg as aa,c4 as ls,eh as ia,ei as bs,ej as ra,ek as la,el as ca,em as Tt,en as Ft,eo as da,ep as ua,eq as ha,bU as bn,bI as pa,er as ma,es as cs,et as Sn,eu as xa,ev as ga,ew as ja,ex as Ss,al as fa,b4 as ya,ey as ba,ez as vn,eA as Cn,eB as Sa,eC as va,eD as wn,eE as Ca,c3 as wa,eF as Ta,eG as Tn,eH as ka,eI as Ra,eJ as Ea}from"./index-p2PlVFLf.js";import{u as Aa,C as Da,A as Ia,a as Pa,R as Ba,S as La,T as Oa,b as Ua,c as $a,d as Na,e as Fa,E as Ga,f as qa,m as _a,g as ct,h as kt,i as Wa,j as kn}from"./RoleCell-mJ7DV61l.js";import{u as ds}from"./useApiTokens-hvnEZWgJ.js";const Ha=ft(e.jsx("path",{d:"M11.8 10.9c-2.27-.59-3-1.2-3-2.15 0-1.09 1.01-1.85 2.7-1.85 1.42 0 2.13.54 2.39 1.4.12.4.45.7.87.7h.3c.66 0 1.13-.65.9-1.27-.42-1.18-1.4-2.16-2.96-2.54V4.5c0-.83-.67-1.5-1.5-1.5S10 3.67 10 4.5v.66c-1.94.42-3.5 1.68-3.5 3.61 0 2.31 1.91 3.46 4.7 4.13 2.5.6 3 1.48 3 2.41 0 .69-.49 1.79-2.7 1.79-1.65 0-2.5-.59-2.83-1.43-.15-.39-.49-.67-.9-.67h-.28c-.67 0-1.14.68-.89 1.3.57 1.39 1.9 2.21 3.4 2.53v.67c0 .83.67 1.5 1.5 1.5s1.5-.67 1.5-1.5v-.65c1.95-.37 3.5-1.5 3.5-3.55 0-2.84-2.43-3.81-4.7-4.4z"}),"AttachMoneyRounded"),Ma=ft(e.jsx("path",{d:"M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5s-3 1.34-3 3 1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V18c0 .55.45 1 1 1h12c.55 0 1-.45 1-1v-1.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05.02.01.03.03.04.04 1.14.83 1.93 1.94 1.93 3.41V18c0 .35-.07.69-.18 1H22c.55 0 1-.45 1-1v-1.5c0-2.33-4.67-3.5-7-3.5z"}),"GroupRounded"),za=ft(e.jsx("path",{d:"M13 3c-4.97 0-9 4.03-9 9H1l4 4 4-4H6c0-3.86 3.14-7 7-7s7 3.14 7 7-3.14 7-7 7c-1.9 0-3.62-.76-4.88-1.99L6.7 18.42C8.32 20.01 10.55 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm2 8v-1c0-1.1-.9-2-2-2s-2 .9-2 2v1c-.55 0-1 .45-1 1v3c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-3c0-.55-.45-1-1-1zm-1 0h-2v-1c0-.55.45-1 1-1s1 .45 1 1v1z"}),"LockReset"),Va=ft(e.jsx("path",{d:"M20 6h-8l-2-2H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm-6 10H6v-2h8v2zm4-4H6v-2h12v2z"}),"Topic"),Ya=()=>{const{tokens:t,loading:s,refetch:n}=ds(),{deleteToken:o}=zs(),{getTableProps:a,getTableBodyProps:i,headerGroups:r,rows:l,prepareRow:c,state:{globalFilter:d},setGlobalFilter:u,setHiddenColumns:p,columns:x}=Aa(t,g=>{const j=g.row.original.type==="client"?xs:g.row.original.type==="frontend"?gs:$e,y=g.row.original.type==="client"?Kn:g.row.original.type==="frontend"?Zn:$e;return e.jsxs(yt,{children:[e.jsx(Pa,{token:g.row.original,permission:j}),e.jsx(Ba,{token:g.row.original,permission:y,onRemove:async()=>{await o(g.row.original.secret),n()}})]})});return e.jsx(ge,{permissions:[xs,gs,$e],children:e.jsx(Q,{header:e.jsx(X,{title:`API access (${l.length})`,actions:e.jsxs(e.Fragment,{children:[e.jsx(le,{initialValue:d,onChange:u}),e.jsx(X.Divider,{}),e.jsx(Da,{permission:[Vs,Ys,$e],path:"/admin/api/create-token"})]})}),children:e.jsx(Ia,{loading:s,headerGroups:r,setHiddenColumns:p,prepareRow:c,getTableBodyProps:i,getTableProps:a,rows:l,columns:x,globalFilter:d})})})},Ja=({type:t,projects:s,setProjects:n,errors:o,clearErrors:a})=>{const i=Qn("projectId"),{projects:r}=Xn(),l=r.map(c=>({value:c.id,label:c.name}));return i?null:e.jsxs(e.Fragment,{children:[e.jsx(La,{children:"Which project do you want to give access to?"}),e.jsx(eo,{disabled:t===Oa.ADMIN,options:l,defaultValue:s,onChange:n,error:o==null?void 0:o.projects,onFocus:()=>a("projects")})]})},vs="Create API token",Ka=({modal:t=!1})=>{const{setToastApiError:s}=J(),{uiConfig:n}=N(),o=ve(),[a,i]=h.useState(!1),[r,l]=h.useState(""),{getApiTokenPayload:c,username:d,type:u,projects:p,environment:x,setUsername:g,setTokenType:j,setProjects:y,setEnvironment:w,isValid:C,errors:k,clearErrors:A,apiTokenTypes:T}=Ua(),{createToken:L,loading:P}=zs(),{refetch:I}=ds();Js(vs);const v="api/admin/api-tokens",F=async W=>{if(W.preventDefault(),!!C())try{const E=c();await L(E).then($=>$.json()).then($=>{Kt(),l($.secret),i(!0),I()})}catch(E){s(z(E))}},R=()=>{i(!1),o(Ee)},b=()=>`curl --location --request POST '${n.unleashUrl}/${v}' \\
1
+ import{c as ft,j as e,c$ as zs,d0 as ge,d1 as xs,d2 as gs,d3 as $e,at as Q,au as X,ao as le,d4 as Vs,d5 as Ys,d6 as Kn,d7 as Zn,d8 as yt,d9 as Qn,q as Xn,da as eo,b as J,ax as N,ay as ve,r as h,ch as Js,aA as Ce,aB as Ks,db as Kt,f as z,aD as Ee,s as m,A as Zs,k as Z,C as S,dc as Qs,bZ as Zt,aO as ie,dd as to,de as Xs,aP as je,df as Ne,bL as f,dg as ce,dh as me,F as bt,u as fe,di as Me,J as K,I as so,S as no,M as He,h as _,aN as Le,b7 as se,T as B,aK as re,B as q,cZ as St,cQ as vt,dj as rt,dk as oo,D as Qt,dl as en,d as tn,dm as ao,dn as Ue,G as ze,dp as io,ba as ro,bb as lo,a3 as U,a4 as pe,ab as te,a5 as co,a6 as uo,a7 as Xt,a8 as it,a9 as ho,ap as de,dq as xe,x as Ge,aQ as sn,dr as nn,ds as M,b_ as on,dt as po,du as an,dv as rn,dw as ae,b$ as ln,dx as mo,cE as js,dy as cn,a1 as dn,dz as Oe,t as Be,bJ as xo,bW as go,b3 as Ot,aL as Ve,b5 as Ut,bX as Ae,dA as jo,dB as fo,dC as yo,dD as $t,l as es,m as bo,n as So,ac as he,cB as De,ae as Se,af as Ye,ag as ye,bu as vo,cl as Ct,dE as un,ak as hn,dF as ts,c9 as wt,dG as Co,aq as qe,v as _e,dH as wo,Q as To,dI as ko,dJ as Ro,cb as at,dK as Eo,dL as Ao,aE as ss,dM as ns,y as pn,ai as Do,a as os,dN as Je,dO as Io,an as Ke,aI as ue,dP as Po,dQ as Bo,dR as Lo,dS as Oo,cj as lt,ck as G,cv as fs,dT as mn,br as as,aj as is,dU as Uo,cD as xn,cS as rs,dV as $o,am as gn,dW as No,dX as ys,dY as Ie,R as Fo,dZ as pt,bO as Go,bP as qo,bT as _o,bQ as Wo,d_ as Ho,d$ as Mo,e0 as zo,e1 as Vo,e2 as Yo,e3 as Jo,cn as Ko,e4 as Zo,e5 as Qo,e6 as Xo,e7 as jn,aa as ea,e8 as ta,e9 as Nt,ea as sa,eb as na,ec as fn,ed as jt,ee as yn,ef as oa,eg as aa,c4 as ls,eh as ia,ei as bs,ej as ra,ek as la,el as ca,em as Tt,en as Ft,eo as da,ep as ua,eq as ha,bU as bn,bI as pa,er as ma,es as cs,et as Sn,eu as xa,ev as ga,ew as ja,ex as Ss,al as fa,b4 as ya,ey as ba,ez as vn,eA as Cn,eB as Sa,eC as va,eD as wn,eE as Ca,c3 as wa,eF as Ta,eG as Tn,eH as ka,eI as Ra,eJ as Ea}from"./index-uUGk-gee.js";import{u as Aa,C as Da,A as Ia,a as Pa,R as Ba,S as La,T as Oa,b as Ua,c as $a,d as Na,e as Fa,E as Ga,f as qa,m as _a,g as ct,h as kt,i as Wa,j as kn}from"./RoleCell--QIy8Oj_.js";import{u as ds}from"./useApiTokens-gCm2i_7X.js";const Ha=ft(e.jsx("path",{d:"M11.8 10.9c-2.27-.59-3-1.2-3-2.15 0-1.09 1.01-1.85 2.7-1.85 1.42 0 2.13.54 2.39 1.4.12.4.45.7.87.7h.3c.66 0 1.13-.65.9-1.27-.42-1.18-1.4-2.16-2.96-2.54V4.5c0-.83-.67-1.5-1.5-1.5S10 3.67 10 4.5v.66c-1.94.42-3.5 1.68-3.5 3.61 0 2.31 1.91 3.46 4.7 4.13 2.5.6 3 1.48 3 2.41 0 .69-.49 1.79-2.7 1.79-1.65 0-2.5-.59-2.83-1.43-.15-.39-.49-.67-.9-.67h-.28c-.67 0-1.14.68-.89 1.3.57 1.39 1.9 2.21 3.4 2.53v.67c0 .83.67 1.5 1.5 1.5s1.5-.67 1.5-1.5v-.65c1.95-.37 3.5-1.5 3.5-3.55 0-2.84-2.43-3.81-4.7-4.4z"}),"AttachMoneyRounded"),Ma=ft(e.jsx("path",{d:"M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5s-3 1.34-3 3 1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V18c0 .55.45 1 1 1h12c.55 0 1-.45 1-1v-1.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05.02.01.03.03.04.04 1.14.83 1.93 1.94 1.93 3.41V18c0 .35-.07.69-.18 1H22c.55 0 1-.45 1-1v-1.5c0-2.33-4.67-3.5-7-3.5z"}),"GroupRounded"),za=ft(e.jsx("path",{d:"M13 3c-4.97 0-9 4.03-9 9H1l4 4 4-4H6c0-3.86 3.14-7 7-7s7 3.14 7 7-3.14 7-7 7c-1.9 0-3.62-.76-4.88-1.99L6.7 18.42C8.32 20.01 10.55 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm2 8v-1c0-1.1-.9-2-2-2s-2 .9-2 2v1c-.55 0-1 .45-1 1v3c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-3c0-.55-.45-1-1-1zm-1 0h-2v-1c0-.55.45-1 1-1s1 .45 1 1v1z"}),"LockReset"),Va=ft(e.jsx("path",{d:"M20 6h-8l-2-2H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm-6 10H6v-2h8v2zm4-4H6v-2h12v2z"}),"Topic"),Ya=()=>{const{tokens:t,loading:s,refetch:n}=ds(),{deleteToken:o}=zs(),{getTableProps:a,getTableBodyProps:i,headerGroups:r,rows:l,prepareRow:c,state:{globalFilter:d},setGlobalFilter:u,setHiddenColumns:p,columns:x}=Aa(t,g=>{const j=g.row.original.type==="client"?xs:g.row.original.type==="frontend"?gs:$e,y=g.row.original.type==="client"?Kn:g.row.original.type==="frontend"?Zn:$e;return e.jsxs(yt,{children:[e.jsx(Pa,{token:g.row.original,permission:j}),e.jsx(Ba,{token:g.row.original,permission:y,onRemove:async()=>{await o(g.row.original.secret),n()}})]})});return e.jsx(ge,{permissions:[xs,gs,$e],children:e.jsx(Q,{header:e.jsx(X,{title:`API access (${l.length})`,actions:e.jsxs(e.Fragment,{children:[e.jsx(le,{initialValue:d,onChange:u}),e.jsx(X.Divider,{}),e.jsx(Da,{permission:[Vs,Ys,$e],path:"/admin/api/create-token"})]})}),children:e.jsx(Ia,{loading:s,headerGroups:r,setHiddenColumns:p,prepareRow:c,getTableBodyProps:i,getTableProps:a,rows:l,columns:x,globalFilter:d})})})},Ja=({type:t,projects:s,setProjects:n,errors:o,clearErrors:a})=>{const i=Qn("projectId"),{projects:r}=Xn(),l=r.map(c=>({value:c.id,label:c.name}));return i?null:e.jsxs(e.Fragment,{children:[e.jsx(La,{children:"Which project do you want to give access to?"}),e.jsx(eo,{disabled:t===Oa.ADMIN,options:l,defaultValue:s,onChange:n,error:o==null?void 0:o.projects,onFocus:()=>a("projects")})]})},vs="Create API token",Ka=({modal:t=!1})=>{const{setToastApiError:s}=J(),{uiConfig:n}=N(),o=ve(),[a,i]=h.useState(!1),[r,l]=h.useState(""),{getApiTokenPayload:c,username:d,type:u,projects:p,environment:x,setUsername:g,setTokenType:j,setProjects:y,setEnvironment:w,isValid:C,errors:k,clearErrors:A,apiTokenTypes:T}=Ua(),{createToken:L,loading:P}=zs(),{refetch:I}=ds();Js(vs);const v="api/admin/api-tokens",F=async W=>{if(W.preventDefault(),!!C())try{const E=c();await L(E).then($=>$.json()).then($=>{Kt(),l($.secret),i(!0),I()})}catch(E){s(z(E))}},R=()=>{i(!1),o(Ee)},b=()=>`curl --location --request POST '${n.unleashUrl}/${v}' \\
2
2
  --header 'Authorization: INSERT_API_KEY' \\
3
3
  --header 'Content-Type: application/json' \\
4
4
  --data-raw '${JSON.stringify(c(),void 0,2)}'`,D=()=>{o(Ee)};return e.jsxs(Ce,{loading:P,title:vs,modal:t,description:"Unleash SDKs use API tokens to authenticate to the Unleash API. Client SDKs need a token with 'client privileges', which allows them to fetch feature toggle configurations and post usage metrics.",documentationLink:"https://docs.getunleash.io/reference/api-tokens-and-client-keys",documentationLinkLabel:"API tokens documentation",formatApiCode:b,children:[e.jsxs($a,{handleSubmit:F,handleCancel:D,mode:"Create",actions:e.jsx(Ks,{name:"token",permission:[$e,Ys,Vs]}),children:[e.jsx(Na,{username:d,setUsername:g,errors:k,clearErrors:A}),e.jsx(Fa,{type:u,setType:j,apiTokenTypes:T}),e.jsx(Ja,{type:u,projects:p,setProjects:y,errors:k,clearErrors:A}),e.jsx(Ga,{type:u,environment:x,setEnvironment:w})]}),e.jsx(qa,{open:a,setOpen:i,closeConfirm:R,token:r,type:u})]})},Za=m("div")(({theme:t})=>({display:"flex",flexDirection:"column","& > span:last-of-type":{fontSize:t.fontSizes.smallerBody,color:t.palette.text.secondary}})),Rt=({roles:t,value:s,setValue:n,required:o,hideDescription:a,...i})=>{const r=(l,c)=>e.jsx("li",{...l,children:e.jsxs(Za,{children:[e.jsx("span",{children:c.name}),e.jsx("span",{children:c.description})]})});return e.jsxs(e.Fragment,{children:[e.jsx(Zs,{openOnFocus:!0,size:"small",value:s,onChange:(l,c)=>n(c||null),options:t,renderOption:r,getOptionLabel:l=>l.name,renderInput:l=>e.jsx(Z,{...l,label:"Role",required:o}),...i}),e.jsx(S,{condition:!!s&&!a,show:()=>e.jsx(Qs,{sx:{marginTop:1},roleId:s.id})})]})},dt=()=>{const{isEnterprise:t}=N(),{data:s,error:n,mutate:o}=Zt(t(),{roles:[],projectRoles:[]},ie("api/admin/roles"),Qa);return h.useMemo(()=>({roles:(s==null?void 0:s.roles.filter(({type:a})=>to.includes(a)).sort(Cs))??[],projectRoles:(s==null?void 0:s.roles.filter(({type:a})=>Xs.includes(a)).sort(Cs))??[],loading:!n&&!s,refetch:()=>o(),error:n}),[s,n,o])},Qa=t=>fetch(t).then(je("Roles")).then(s=>s.json()),Cs=(t,s)=>Ne.includes(t.type)&&!Ne.includes(s.type)?-1:!Ne.includes(t.type)&&Ne.includes(s.type)?1:t.name.localeCompare(s.name),Rn=({data:t={enabled:!1,autoCreate:!1},setValue:s,onUpdateRole:n})=>{const{roles:o}=dt(),a=()=>{s("autoCreate",!t.autoCreate)},i=l=>{s(l.target.name,l.target.value)},r=({defaultRootRole:l,defaultRootRoleId:c})=>c?o.find(({id:d})=>d===c)||null:o.find(({name:d})=>d===l)||null;return e.jsxs(h.Fragment,{children:[e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Auto-create users"}),e.jsx("p",{children:"Enable automatic creation of new users when signing in."})]}),e.jsx(f,{item:!0,md:6,style:{padding:"20px"},children:e.jsx(ce,{control:e.jsx(me,{onChange:a,name:"enabled",checked:t.autoCreate,disabled:!t.enabled}),label:"Auto-create users"})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Default Root Role"}),e.jsx("p",{children:"Choose which root role the user should get when no explicit role mapping exists."})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(bt,{style:{width:"400px"},children:e.jsx(Rt,{roles:o,value:r(t),setValue:n,disabled:!t.autoCreate||!t.enabled,required:!0,hideDescription:!0})})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Email domains"}),e.jsx("p",{children:"Comma separated list of email domains that should be allowed to sign in."})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:i,label:"Email domains",name:"emailDomains",disabled:!t.autoCreate||!t.enabled,required:!!t.autoCreate,value:t.emailDomains||"",placeholder:"@company.com, @anotherCompany.com",style:{width:"400px"},rows:2,variant:"outlined",size:"small"})})]})]})},Xa=async(t,s)=>{if(t){if(s){const n=await s.json();throw t({message:n.message}),new Error(n.message)}throw new Error}},Et=t=>{const{makeRequest:s,createRequest:n,errors:o,loading:a}=fe({propagateErrors:!0,handleBadRequest:Xa});return{updateSettings:async r=>{const l=`api/admin/auth/${t}/settings`,c=n(l,{method:"POST",body:JSON.stringify(r)});await s(c.caller,c.id)},errors:o,loading:a}},us=t=>{const n=Object.entries(t).filter(([,o])=>o!=="");return Object.fromEntries(n)},En=({ssoType:t,data:s={enabled:!1,enableGroupSyncing:!1,groupJsonPath:"",addGroupsScope:!1},setValue:n})=>{const o=()=>{n("enableGroupSyncing",!s.enableGroupSyncing)},a=r=>{n(r.target.name,r.target.value)},i=()=>{n("addGroupsScope",!s.addGroupsScope)};return e.jsxs(e.Fragment,{children:[e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Enable Group Syncing"}),e.jsxs("p",{children:["Enables automatically syncing of users from the"," ",t,"provider when a user logs in."]})]}),e.jsx(f,{item:!0,md:6,style:{padding:"20px"},children:e.jsx(ce,{control:e.jsx(me,{onChange:o,value:s.enableGroupSyncing,name:"enableGroupSyncing",checked:s.enableGroupSyncing,disabled:!s.enabled}),label:s.enableGroupSyncing?"Enabled":"Disabled"})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Group Field JSON Path"}),e.jsxs("p",{children:["Specifies the path in the ",t," token response from which to read the groups the user belongs to."]})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:a,label:"Group JSON Path",name:"groupJsonPath",value:s.groupJsonPath,disabled:!s.enableGroupSyncing,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e.jsx(S,{condition:t==="OIDC",show:e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Request 'groups' Scope"}),e.jsx("p",{children:"When enabled Unleash will also request the 'groups' scope as part of the login request."})]}),e.jsx(f,{item:!0,md:6,style:{padding:"20px"},children:e.jsx(ce,{control:e.jsx(me,{onChange:i,value:s.addGroupsScope,disabled:!s.enableGroupSyncing,name:"addGroupsScope",checked:s.addGroupsScope}),label:s.addGroupsScope?"Enabled":"Disabled"})})]})})]})},ei={enabled:!1,enableSingleSignOut:!1,addGroupsScope:!1,enableGroupSyncing:!1,autoCreate:!1,unleashHostname:location.hostname,groupJsonPath:"",clientId:"",discoverUrl:"",secret:"",acrValues:"",idTokenSigningAlgorithm:"RS256"},ti=()=>{const{setToastData:t,setToastApiError:s}=J(),{uiConfig:n}=N(),[o,a]=h.useState(ei),{config:i}=Me("oidc"),{updateSettings:r,errors:l,loading:c}=Et("oidc");h.useEffect(()=>{i.discoverUrl&&a(i)},[i]);const d=y=>{x(y.target.name,y.target.value)},u=()=>{a({...o,enabled:!o.enabled})},p=()=>{a({...o,enableSingleSignOut:!o.enableSingleSignOut})},x=(y,w)=>{a({...o,[y]:w})},g=y=>{a({...o,defaultRootRole:void 0,defaultRootRoleId:y==null?void 0:y.id})},j=async y=>{y.preventDefault();try{await r(us(o)),t({title:"Settings stored",type:"success"})}catch(w){s(z(w))}};return e.jsxs(e.Fragment,{children:[e.jsx(f,{container:!0,sx:{mb:3},children:e.jsx(f,{item:!0,md:12,children:e.jsxs(K,{severity:"info",children:["Please read the"," ",e.jsx("a",{href:"https://www.unleash-hosted.com/docs/enterprise-authentication",target:"_blank",rel:"noreferrer",children:"documentation"})," ","to learn how to integrate with specific Open Id Connect providers (Okta, Keycloak, Google, etc). ",e.jsx("br",{}),"Callback URL:"," ",e.jsxs("code",{children:[n.unleashUrl,"/auth/oidc/callback"]})]})})}),e.jsxs("form",{onSubmit:j,children:[e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Enable"}),e.jsx("p",{children:"Enable Open Id Connect Authentication."})]}),e.jsx(f,{item:!0,md:6,style:{padding:"20px"},children:e.jsx(ce,{control:e.jsx(me,{onChange:u,value:o.enabled,name:"enabled",checked:o.enabled}),label:o.enabled?"Enabled":"Disabled"})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Discover URL"}),e.jsx("p",{children:"(Required) Issuer discover metadata URL"})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:d,label:"Discover URL",name:"discoverUrl",value:o.discoverUrl,disabled:!o.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Client ID"}),e.jsx("p",{children:"(Required) Client ID of your OpenID application"})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:d,label:"Client ID",name:"clientId",value:o.clientId,disabled:!o.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e.jsxs(f,{container:!0,spacing:3,mb:4,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Client secret"}),e.jsxs("p",{children:["(Required) Client secret of your OpenID application."," "]})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:d,label:"Client Secret",name:"secret",value:o.secret,disabled:!o.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e.jsx("h3",{children:"Optional Configuration"}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Enable Single Sign-Out"}),e.jsx("p",{children:"If you enable Single Sign-Out Unleash will redirect the user to the IDP as part of the Sign-out process."})]}),e.jsx(f,{item:!0,md:6,style:{padding:"20px"},children:e.jsx(ce,{control:e.jsx(me,{onChange:p,value:o.enableSingleSignOut,disabled:!o.enabled,name:"enableSingleSignOut",checked:o.enableSingleSignOut}),label:o.enableSingleSignOut?"Enabled":"Disabled"})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"ACR Values"}),e.jsx("p",{children:'Requested Authentication Context Class Reference values. If multiple values are specified they should be "space" separated. Will be sent as "acr_values" as part of the authentication request. Unleash will validate the acr value in the id token claims against the list of acr values.'})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:d,label:"ACR Values",name:"acrValues",value:o.acrValues,disabled:!o.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),e.jsx(En,{ssoType:"OIDC",data:o,setValue:x}),e.jsx(Rn,{data:o,setValue:x,onUpdateRole:g}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"ID Signing algorithm"}),e.jsxs("p",{children:["Which signing algorithm to use. ",e.jsx("br",{}),' Leave this alone unless you see errors that look like "unexpected JWT alg received, expected RS256, got: RS512" in your logs.']})]}),e.jsx(f,{item:!0,md:6,children:e.jsxs(bt,{style:{minWidth:"200px"},children:[e.jsx(so,{id:"defaultRootRole-label",children:"Signing algorithm"}),e.jsxs(no,{label:"Signing algorithm",labelId:"idTokenSigningAlgorithm-label",id:"idTokenSigningAlgorithm",name:"idTokenSigningAlgorithm",value:o.idTokenSigningAlgorithm||"RS256",onChange:y=>x("idTokenSigningAlgorithm",y.target.value),children:[e.jsx(He,{value:"RS256",children:"RS256"}),e.jsx(He,{value:"RS384",children:"RS384"}),e.jsx(He,{value:"RS512",children:"RS512"})]})]})})]}),e.jsx(f,{container:!0,spacing:3,children:e.jsxs(f,{item:!0,md:12,children:[e.jsx(_,{variant:"contained",color:"primary",type:"submit",disabled:c,children:"Save"})," ",e.jsx("p",{children:e.jsx("small",{style:{color:"red"},children:l==null?void 0:l.message})})]})})]})]})},si={enabled:!1,autoCreate:!1,enableGroupSyncing:!1,addGroupsScope:!1,unleashHostname:location.hostname,entityId:"",signOnUrl:"",certificate:"",signOutUrl:"",spCertificate:"",groupJsonPath:""},ni=()=>{const{setToastData:t,setToastApiError:s}=J(),{uiConfig:n}=N(),[o,a]=h.useState(si),{config:i}=Me("saml"),{updateSettings:r,errors:l,loading:c}=Et("saml");h.useEffect(()=>{i.entityId&&a(i)},[i]);const d=j=>{p(j.target.name,j.target.value)},u=()=>{a({...o,enabled:!o.enabled})},p=(j,y)=>{a({...o,[j]:y})},x=j=>{a({...o,defaultRootRole:void 0,defaultRootRoleId:j==null?void 0:j.id})},g=async j=>{j.preventDefault();try{await r(us(o)),t({title:"Settings stored",type:"success"})}catch(y){s(z(y))}};return e.jsxs(e.Fragment,{children:[e.jsx(f,{container:!0,sx:{mb:3},children:e.jsx(f,{item:!0,md:12,children:e.jsxs(K,{severity:"info",children:["Please read the"," ",e.jsx("a",{href:"https://www.unleash-hosted.com/docs/enterprise-authentication",target:"_blank",rel:"noreferrer",children:"documentation"})," ","to learn how to integrate with specific SAML 2.0 providers (Okta, Keycloak, etc). ",e.jsx("br",{}),"Callback URL:"," ",e.jsxs("code",{children:[n.unleashUrl,"/auth/saml/callback"]})]})})}),e.jsxs("form",{onSubmit:g,children:[e.jsxs(f,{container:!0,spacing:3,children:[e.jsxs(f,{item:!0,md:5,mb:2,children:[e.jsx("strong",{children:"Enable"}),e.jsx("p",{children:"Enable SAML 2.0 Authentication."})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(ce,{control:e.jsx(me,{onChange:u,value:o.enabled,name:"enabled",checked:o.enabled}),label:o.enabled?"Enabled":"Disabled"})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Entity ID"}),e.jsx("p",{children:"(Required) The Entity Identity provider issuer."})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:d,label:"Entity ID",name:"entityId",value:o.entityId,disabled:!o.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Single Sign-On URL"}),e.jsx("p",{children:"(Required) The url to redirect the user to for signing in."})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:d,label:"Single Sign-On URL",name:"signOnUrl",value:o.signOnUrl,disabled:!o.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e.jsxs(f,{container:!0,spacing:3,mb:4,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"X.509 Certificate"}),e.jsx("p",{children:"(Required) The certificate used to sign the SAML 2.0 request."})]}),e.jsx(f,{item:!0,md:7,children:e.jsx(Z,{onChange:d,label:"X.509 Certificate",name:"certificate",value:o.certificate,disabled:!o.enabled,style:{width:"100%"},InputProps:{style:{fontSize:"0.6em",fontFamily:"monospace"}},multiline:!0,rows:14,maxRows:14,variant:"outlined",size:"small",required:!0})})]}),e.jsx("h3",{children:"Optional Configuration"}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Single Sign-out URL"}),e.jsx("p",{children:"(Optional) The url to redirect the user to for signing out of the IDP."})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:d,label:"Single Sign-out URL",name:"signOutUrl",value:o.signOutUrl,disabled:!o.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Service Provider X.509 Certificate"}),e.jsx("p",{children:"(Optional) The private certificate used by the Service Provider used to sign the SAML 2.0 request towards the IDP. E.g. used to sign single logout requests (SLO)."})]}),e.jsx(f,{item:!0,md:7,children:e.jsx(Z,{onChange:d,label:"X.509 Certificate",name:"spCertificate",value:o.spCertificate,disabled:!o.enabled,style:{width:"100%"},InputProps:{style:{fontSize:"0.6em",fontFamily:"monospace"}},multiline:!0,rows:14,maxRows:14,variant:"outlined",size:"small"})})]}),e.jsx(En,{ssoType:"SAML",data:o,setValue:p}),e.jsx(Rn,{data:o,setValue:p,onUpdateRole:x}),e.jsx(f,{container:!0,spacing:3,children:e.jsxs(f,{item:!0,md:5,children:[e.jsx(_,{variant:"contained",color:"primary",type:"submit",disabled:c,children:"Save"})," ",e.jsx("p",{children:e.jsx("small",{style:{color:"red"},children:l==null?void 0:l.message})})]})})]})]})},oi=()=>{const{data:t,error:s,mutate:n}=Le(ie("api/admin/user-admin/admin-count"),ai);return{data:t,loading:!s&&!t,refetch:()=>n(),error:s}},ai=t=>fetch(t).then(je("Admin count")).then(s=>s.json()),ii=({open:t,setOpen:s,onClick:n,adminCount:o,tokens:a})=>e.jsxs(se,{open:t,onClose:()=>{s(!1)},onClick:n,title:"Disable password based login?",primaryButtonText:"Disable password based login",secondaryButtonText:"Cancel",children:[e.jsxs(K,{severity:"warning",children:[e.jsx("strong",{children:"Warning!"})," Disabling password based login may lock you out of the system permanently if you do not have any alternative admin credentials (such as an admin SSO account or admin API token) secured beforehand.",e.jsx("br",{}),e.jsx("br",{}),e.jsx("strong",{children:"Password based administrators: "})," ",o==null?void 0:o.password,e.jsx("br",{}),e.jsx("strong",{children:"Other administrators: "})," ",o==null?void 0:o.noPassword,e.jsx("br",{}),e.jsx("strong",{children:"Admin service accounts: "})," ",o==null?void 0:o.service,e.jsx("br",{}),e.jsx("strong",{children:"Admin API tokens: "})," ",a.filter(({type:i})=>i==="admin").length]}),e.jsx(B,{sx:{mt:3},children:"You are about to disable password based login. Are you sure you want to proceed?"})]}),ri=()=>{const{setToastData:t,setToastApiError:s}=J(),{config:n,refetch:o}=Me("simple"),[a,i]=h.useState(!1),{updateSettings:r,errors:l,loading:c}=Et("simple"),[d,u]=h.useState(!1),{data:p}=oi(),{tokens:x}=ds();h.useEffect(()=>{i(!!n.disabled)},[n.disabled]);const g=()=>{i(!a)},j=async w=>{w.preventDefault(),!n.disabled&&a?u(!0):y()},y=async()=>{try{await r({disabled:a}),o(),t({title:"Successfully saved",text:"Password authentication settings stored.",autoHideDuration:4e3,type:"success",show:!0})}catch(w){s(z(w)),i(n.disabled)}};return e.jsx(e.Fragment,{children:e.jsxs("form",{onSubmit:j,children:[e.jsxs(K,{severity:"info",sx:{mb:3},children:["Overview of administrators on your Unleash instance:",e.jsx("br",{}),e.jsx("br",{}),e.jsx("strong",{children:"Password based administrators: "})," ",e.jsx(re,{to:"/admin/users",children:p==null?void 0:p.password}),e.jsx("br",{}),e.jsx("strong",{children:"Other administrators: "})," ",e.jsx(re,{to:"/admin/users",children:p==null?void 0:p.noPassword}),e.jsx("br",{}),e.jsx("strong",{children:"Admin service accounts: "})," ",e.jsx(re,{to:"/admin/service-accounts",children:p==null?void 0:p.service}),e.jsx("br",{}),e.jsx("strong",{children:"Admin API tokens: "})," ",e.jsx(re,{to:"/admin/api",children:x.filter(({type:w})=>w==="admin").length})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Password based login"}),e.jsx("p",{children:"Allow users to login with username & password"})]}),e.jsx(f,{item:!0,md:6,style:{padding:"20px"},children:e.jsx(ce,{control:e.jsx(me,{onChange:g,value:!a,name:"disabled",checked:!a}),label:a?"Disabled":"Enabled"})})]}),e.jsx(f,{container:!0,spacing:3,children:e.jsxs(f,{item:!0,md:12,children:[e.jsx(_,{variant:"contained",color:"primary",type:"submit",disabled:c,children:"Save"})," ",e.jsx("p",{children:e.jsx("small",{style:{color:"red"},children:l==null?void 0:l.message})})]})}),e.jsx(ii,{open:d,setOpen:u,onClick:()=>{u(!1),y()},adminCount:p,tokens:x})]})})},li={enabled:!1,autoCreate:!1,unleashHostname:location.hostname,clientId:"",clientSecret:"",emailDomains:""},ci=()=>{const{setToastData:t,setToastApiError:s}=J(),{uiConfig:n}=N(),[o,a]=h.useState(li),{config:i}=Me("google"),{updateSettings:r,errors:l,loading:c}=Et("google");h.useEffect(()=>{i.clientId&&a(i)},[i]);const d=g=>{a({...o,[g.target.name]:g.target.value})},u=()=>{a({...o,enabled:!o.enabled})},p=()=>{a({...o,autoCreate:!o.autoCreate})},x=async g=>{g.preventDefault();try{await r(us(o)),t({title:"Settings stored",type:"success"})}catch(j){s(z(j))}};return e.jsxs(e.Fragment,{children:[e.jsxs(q,{children:[e.jsxs(K,{severity:"error",sx:{mb:2},children:["This integration is deprecated and will be removed in next major version. Please use ",e.jsx("strong",{children:"OpenID Connect"})," to enable Google SSO."]}),e.jsxs(K,{severity:"info",sx:{mb:3},children:["Read the"," ",e.jsx("a",{href:"https://www.unleash-hosted.com/docs/enterprise-authentication/google",target:"_blank",rel:"noreferrer",children:"documentation"})," ","to learn how to integrate with Google OAuth 2.0. ",e.jsx("br",{}),"Callback URL:"," ",e.jsxs("code",{children:[n.unleashUrl,"/auth/google/callback"]})]})]}),e.jsxs("form",{onSubmit:x,children:[e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,xs:5,children:[e.jsx("strong",{children:"Enable"}),e.jsx("p",{children:"Enable Google users to login. Value is ignored if Client ID and Client Secret are not defined."})]}),e.jsx(f,{item:!0,xs:6,style:{padding:"20px"},children:e.jsx(ce,{control:e.jsx(me,{onChange:u,value:o.enabled,name:"enabled",checked:o.enabled}),label:o.enabled?"Enabled":"Disabled"})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,xs:5,children:[e.jsx("strong",{children:"Client ID"}),e.jsx("p",{children:"(Required) The Client ID provided by Google when registering the application."})]}),e.jsx(f,{item:!0,xs:6,children:e.jsx(Z,{onChange:d,label:"Client ID",name:"clientId",placeholder:"",value:o.clientId,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Client Secret"}),e.jsx("p",{children:"(Required) Client Secret provided by Google when registering the application."})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:d,label:"Client Secret",name:"clientSecret",value:o.clientSecret,placeholder:"",style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Unleash hostname"}),e.jsxs("p",{children:["(Required) The hostname you are running Unleash on that Google should send the user back to. The final callback URL will be"," ",e.jsx("small",{children:e.jsx("code",{children:"https://[unleash.hostname.com]/auth/google/callback"})})]})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:d,label:"Unleash Hostname",name:"unleashHostname",placeholder:"",value:o.unleashHostname||"",style:{width:"400px"},variant:"outlined",size:"small"})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Auto-create users"}),e.jsx("p",{children:"Enable automatic creation of new users when signing in with Google."})]}),e.jsx(f,{item:!0,md:6,style:{padding:"20px"},children:e.jsx(me,{onChange:p,name:"enabled",checked:o.autoCreate})})]}),e.jsxs(f,{container:!0,spacing:3,mb:2,children:[e.jsxs(f,{item:!0,md:5,children:[e.jsx("strong",{children:"Email domains"}),e.jsx("p",{children:"(Optional) Comma separated list of email domains that should be allowed to sign in."})]}),e.jsx(f,{item:!0,md:6,children:e.jsx(Z,{onChange:d,label:"Email domains",name:"emailDomains",value:o.emailDomains,placeholder:"@company.com, @anotherCompany.com",style:{width:"400px"},rows:2,multiline:!0,variant:"outlined",size:"small"})})]}),e.jsx(f,{container:!0,spacing:3,children:e.jsxs(f,{item:!0,md:5,children:[e.jsx(_,{variant:"contained",color:"primary",type:"submit",disabled:c,children:"Save"})," ",e.jsx("p",{children:e.jsx("small",{style:{color:"error.dark"},children:l==null?void 0:l.message})})]})})]})]})},di=()=>{const{authenticationType:t}=N().uiConfig,{uiConfig:s}=N(),n=[{label:"OpenID Connect",component:e.jsx(ti,{})},{label:"SAML 2.0",component:e.jsx(ni,{})},{label:"Password",component:e.jsx(ri,{})},{label:"Google",component:e.jsx(ci,{})}].filter(i=>{var r;return((r=s.flags)==null?void 0:r.googleAuthEnabled)||i.label!=="Google"}),[o,a]=h.useState(0);return e.jsx("div",{children:e.jsx(ge,{permissions:$e,children:e.jsxs(Q,{withTabs:!0,header:e.jsx(S,{condition:t==="enterprise",show:e.jsx(St,{value:o,onChange:(i,r)=>{a(r)},indicatorColor:"primary",textColor:"primary",children:n.map((i,r)=>e.jsx(vt,{label:i.label,id:`tab-${r}`,"aria-controls":`tabpanel-${r}`,sx:{minWidth:{lg:160}}},`${i.label}_${r}`))})}),children:[e.jsx(S,{condition:t==="open-source",show:e.jsx(rt,{feature:"sso"})}),e.jsx(S,{condition:t==="demo",show:e.jsx(K,{severity:"warning",children:"You are running Unleash in demo mode. You have to use the Enterprise edition in order configure Single Sign-on."})}),e.jsx(S,{condition:t==="custom",show:e.jsx(K,{severity:"warning",children:"You have decided to use custom authentication type. You have to use the Enterprise edition in order configure Single Sign-on from the user interface."})}),e.jsx(S,{condition:t==="hosted",show:e.jsx(K,{severity:"info",children:"Your Unleash instance is managed by the Unleash team."})}),e.jsx(S,{condition:t==="enterprise",show:e.jsx("div",{children:n.map((i,r)=>e.jsx(oo,{value:o,index:r,children:i.component},r))})})]})})})},ui=ie("api/admin/invoices"),hi=m(_)(({theme:t})=>({width:"100%",marginBottom:t.spacing(1.5)})),pi=({update:t})=>e.jsx(hi,{href:`${ui}/${t?"portal":"checkout"}`,variant:t?"outlined":"contained",children:t?"Update billing information":"Add billing information"}),mi=m("aside")(({theme:t})=>({padding:t.spacing(4),height:"100%",borderRadius:t.shape.borderRadiusLarge,backgroundColor:t.palette.background.elevation2})),xi=m(B)(({theme:t})=>({marginBottom:t.spacing(4)})),gi=m(K)(({theme:t})=>({marginBottom:t.spacing(4)})),ws=m(B)(({theme:t})=>({fontSize:t.fontSizes.smallBody,color:t.palette.text.secondary})),ji=m(Qt)(({theme:t})=>({margin:`${t.spacing(2.5)} 0`,borderColor:t.palette.divider})),fi=({instanceStatus:t})=>{const s=t.state!==en.ACTIVE;return e.jsx(f,{item:!0,xs:12,md:5,children:e.jsxs(mi,{children:[e.jsx(xi,{variant:"body1",children:"Billing information"}),e.jsx(S,{condition:s,show:e.jsxs(gi,{severity:"warning",children:["In order to ",e.jsx("strong",{children:"Upgrade trial"})," you need to provide us your billing information."]})}),e.jsx(pi,{update:!s}),e.jsx(ws,{children:s?"Once we have received your billing information we will upgrade your trial within 1 business day":"Update your credit card and business information and change which email address we send invoices to"}),e.jsx(ji,{}),e.jsxs(ws,{children:[e.jsx("a",{href:"mailto:elise@getunleash.ai?subject=PRO plan clarifications",children:"Get in touch with us"})," ","for any clarification"]})]})})},we=()=>{const{data:t,error:s,mutate:n}=Le(ie("api/admin/user-admin"),yi);return h.useMemo(()=>({users:(t==null?void 0:t.users)??[],roles:(t==null?void 0:t.rootRoles)??[],loading:!s&&!t,refetch:()=>n(),error:s}),[t,s,n])},yi=t=>fetch(t).then(je("Users")).then(s=>s.json()),bi=m(f)(({theme:t})=>({flexWrap:"nowrap",gap:t.spacing(1)})),mt=({sx:t,children:s})=>e.jsx(bi,{container:!0,item:!0,justifyContent:"space-between",alignItems:"center",sx:t,children:s}),Pe=({children:t,vertical:s=!1})=>e.jsx(f,{container:s,item:!0,display:"flex",alignItems:s?"start":"center",direction:s?"column":void 0,children:t}),Si=m("span")(({theme:t})=>({fontSize:t.fontSizes.smallBody,marginLeft:t.spacing(1)})),Ts=({children:t})=>e.jsxs(Si,{children:["(",t,")"]}),vi=m("aside")(({theme:t})=>({padding:t.spacing(2.5),height:"100%",borderRadius:t.shape.borderRadiusLarge,boxShadow:t.boxShadows.elevated,[t.breakpoints.up("md")]:{padding:t.spacing(6.5)}})),ks=m(B)(({theme:t})=>({fontSize:t.fontSizes.smallBody,color:t.palette.text.secondary})),Ci=m("span")(({theme:t})=>({fontSize:"3.25rem",lineHeight:1,color:t.palette.primary.main,fontWeight:800})),wi=m("span")(({theme:t})=>({marginLeft:t.spacing(1.5),fontWeight:t.fontWeight.bold})),Ti=m("span")(({theme:t})=>({color:t.palette.primary.main,fontSize:t.fontSizes.mainHeader,fontWeight:t.fontWeight.bold})),ki=m(K)(({theme:t})=>({fontSize:t.fontSizes.smallerBody,marginBottom:t.spacing(3),marginTop:t.spacing(-1.5),[t.breakpoints.up("md")]:{marginTop:t.spacing(-4.5)}})),Ri=m(tn)(({theme:t})=>({fontSize:"1rem",marginRight:t.spacing(1)})),Ei=m(Qt)(({theme:t})=>({margin:`${t.spacing(3)} 0`})),Ai=({instanceStatus:t})=>{var g;const{users:s}=we(),n=ao(t),{uiConfig:o}=N(),a=s.filter(j=>j.email),i={[Ue.PRO]:80,[Ue.COMPANY]:0,[Ue.TEAM]:0,[Ue.ENTERPRISE]:0,[Ue.UNKNOWN]:0,user:15},r=i[t.plan],l=t.seats??5,c=Math.min(a.length,l),d=a.length-c,u=i.user*d,p=r+u,x=t.state!==en.ACTIVE;return e.jsx(f,{item:!0,xs:12,md:7,children:e.jsxs(vi,{children:[e.jsx(S,{condition:x,show:e.jsxs(ki,{severity:"info",children:["After you have sent your billing information, your instance will be upgraded - you don't have to do anything."," ",e.jsx("a",{href:"mailto:elise@getunleash.ai?subject=PRO plan clarifications",children:"Get in touch with us"})," ","for any clarification"]})}),e.jsx(ze,{color:"success",children:"Current plan"}),e.jsx(f,{container:!0,children:e.jsxs(mt,{sx:j=>({marginBottom:j.spacing(3)}),children:[e.jsxs(Pe,{children:[e.jsx(Ci,{children:t.plan}),e.jsx(S,{condition:io(t),show:e.jsx(wi,{sx:j=>({color:n?j.palette.error.dark:j.palette.warning.dark}),children:n?"Trial expired":t.trialExtended?"Extended Trial":"Trial"})})]}),e.jsx(Pe,{children:e.jsx(S,{condition:r>0,show:e.jsxs(Ti,{children:["$",r.toFixed(2)]})})})]})}),e.jsx(S,{condition:!!((g=o==null?void 0:o.flags)!=null&&g.proPlanAutoCharge&&t.plan===Ue.PRO),show:e.jsxs(e.Fragment,{children:[e.jsxs(f,{container:!0,children:[e.jsxs(mt,{sx:j=>({marginBottom:j.spacing(1.5)}),children:[e.jsxs(Pe,{vertical:!0,children:[e.jsxs(B,{children:[e.jsx("strong",{children:"Included members"}),e.jsx(Ts,{children:e.jsxs(re,{to:"/admin/users",children:[c," of 5 assigned"]})})]}),e.jsx(ks,{children:"You have 5 team members included in your PRO plan"})]}),e.jsxs(Pe,{children:[e.jsx(Ri,{}),e.jsx(B,{variant:"body2",children:"included"})]})]}),e.jsxs(mt,{children:[e.jsxs(Pe,{vertical:!0,children:[e.jsxs(B,{children:[e.jsx("strong",{children:"Paid members"}),e.jsx(Ts,{children:e.jsxs(re,{to:"/admin/users",children:[d," assigned"]})})]}),e.jsx(ks,{children:"$15/month per paid member"})]}),e.jsx(Pe,{children:e.jsxs(B,{sx:j=>({fontSize:j.fontSizes.mainHeader}),children:["$",u.toFixed(2)]})})]})]}),e.jsx(Ei,{}),e.jsx(f,{container:!0,children:e.jsxs(mt,{children:[e.jsx(Pe,{children:e.jsx(B,{sx:j=>({fontWeight:j.fontWeight.bold,fontSize:j.fontSizes.mainHeader}),children:"Total per month"})}),e.jsx(Pe,{children:e.jsxs(B,{sx:j=>({fontWeight:j.fontWeight.bold,fontSize:"2rem"}),children:["$",p.toFixed(2)]})})]})})]})})]})})},Di=({instanceStatus:t})=>e.jsxs(f,{container:!0,spacing:4,children:[e.jsx(fi,{instanceStatus:t}),e.jsx(Ai,{instanceStatus:t})]});var hs={},Ii=lo;Object.defineProperty(hs,"__esModule",{value:!0});var An=hs.default=void 0,Pi=Ii(ro()),Bi=e,Li=(0,Pi.default)((0,Bi.jsx)("path",{d:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"}),"FileDownload");An=hs.default=Li;const Oi=m(B)(({theme:t})=>({marginTop:t.spacing(6),marginBottom:t.spacing(2.5),fontSize:t.fontSizes.mainHeader})),Ui=[{Header:"Amount",accessor:"amountFormatted"},{Header:"Status",accessor:"status",disableGlobalFilter:!0},{Header:"Created date",accessor:"created",Cell:xe,disableGlobalFilter:!0},{Header:"Due date",accessor:"dueDate",Cell:xe,disableGlobalFilter:!0},{Header:"Download",accessor:"invoicePDF",align:"center",Cell:({value:t})=>e.jsx(q,{sx:{display:"flex",justifyContent:"center"},"data-loading":!0,children:e.jsx(Ge,{href:t,children:e.jsx(An,{})})}),width:100,disableGlobalFilter:!0,disableSortBy:!0}],$i=({data:t,isLoading:s=!1})=>{const n=h.useMemo(()=>({sortBy:[{id:"created",desc:!0}]}),[]),{getTableProps:o,getTableBodyProps:a,headerGroups:i,rows:r,prepareRow:l}=U.useTable({columns:Ui,data:t,initialState:n,sortTypes:pe,autoResetGlobalFilter:!1,disableSortRemove:!0,defaultColumn:{Cell:te}},U.useGlobalFilter,U.useSortBy);return e.jsxs(Q,{isLoading:s,disablePadding:!0,children:[e.jsx(Oi,{children:"Payment history"}),e.jsxs(co,{...o(),children:[e.jsx(uo,{headerGroups:i}),e.jsx(Xt,{...a(),children:r.map(c=>(l(c),e.jsx(it,{hover:!0,...c.getRowProps(),children:c.cells.map(d=>e.jsx(ho,{...d.getCellProps(),children:d.render("Cell")}))})))})]}),e.jsx(S,{condition:r.length===0,show:e.jsx(de,{children:"No invoices to show."})})]})},Jt="api/admin/invoices",Ni=ie(Jt),Dn=(t={})=>{const s=()=>fetch(Ni,{method:"GET"}).then(je("Invoices")).then(l=>l.json()),{data:n,error:o}=Le(Jt,s,t),[a,i]=h.useState(!o&&!n),r=()=>{sn(Jt)};return h.useEffect(()=>{i(!o&&!n)},[n,o]),{invoices:(n==null?void 0:n.invoices)||[],error:o,loading:a,refetchInvoices:r}},Fi=()=>{const{instanceStatus:t,isBilling:s,refetchInstanceStatus:n,refresh:o,loading:a}=nn(),{invoices:i}=Dn();return h.useEffect(()=>{(async()=>{await o(),n()})()},[n,o]),e.jsx("div",{children:e.jsx(Q,{header:"Billing",isLoading:a,children:e.jsx(S,{condition:s,show:e.jsx(ge,{permissions:M,children:e.jsxs(e.Fragment,{children:[e.jsx(Di,{instanceStatus:t}),e.jsx($i,{data:i})]})}),elseShow:e.jsx(K,{severity:"error",children:"Billing is not enabled for this instance."})})})})},Gi=ie("api/admin/invoices/portal"),qi=()=>{const{refetchInvoices:t,invoices:s}=Dn(),[n,o]=h.useState(!1),{locationSettings:a}=on();return h.useEffect(()=>{t(),o(!0)},[]),e.jsx(S,{condition:s.length>0,show:e.jsx(Q,{header:e.jsx(X,{title:"Invoices",actions:e.jsx(_,{href:Gi,rel:"noreferrer",target:"_blank",endIcon:e.jsx(po,{}),children:"Billing portal"})}),children:e.jsx("div",{children:e.jsxs(an,{children:[e.jsx(rn,{children:e.jsxs(it,{children:[e.jsx(ae,{children:"Amount"}),e.jsx(ae,{children:"Status"}),e.jsx(ae,{children:"Due date"}),e.jsx(ae,{children:"PDF"}),e.jsx(ae,{children:"Link"})]})}),e.jsx(Xt,{children:s.map(i=>e.jsxs(it,{style:{backgroundColor:i.status==="past-due"?"error.dark":"inherit"},children:[e.jsx(ae,{style:{textAlign:"left"},children:i.amountFormatted}),e.jsx(ae,{style:{textAlign:"left"},children:i.status}),e.jsx(ae,{style:{textAlign:"left"},children:i.dueDate&&ln(i.dueDate,a.locale)}),e.jsx(ae,{style:{textAlign:"left"},children:e.jsx("a",{href:i.invoicePDF,children:"PDF"})}),e.jsx(ae,{style:{textAlign:"left"},children:e.jsx("a",{href:i.invoiceURL,target:"_blank",rel:"noreferrer",children:"Payment link"})})]},i.invoiceURL))})]})})}),elseShow:e.jsx(Q,{children:n&&"No invoices to show."})})},_i=()=>e.jsx("div",{children:e.jsx(ge,{permissions:M,children:e.jsx(qi,{})})}),Wi=()=>{const{uiConfig:t,loading:s}=N();return s?null:t.flags.UNLEASH_CLOUD?e.jsx(mo,{to:"/admin/billing",replace:!0}):e.jsx(_i,{})},Hi=()=>e.jsxs(K,{severity:"info",children:[e.jsxs("p",{children:["Use this page to configure allowed CORS origins for the Frontend API (",e.jsx("code",{children:"/api/frontend"}),")."]}),e.jsxs("p",{children:["This configuration will not affect the Admin API (",e.jsx("code",{children:"/api/admin"}),") nor the Client API (",e.jsx("code",{children:"/api/client"}),")."]}),e.jsxs("p",{children:["An asterisk (",e.jsx("code",{children:"*"}),") may be used to allow API calls from any origin."]}),e.jsx("br",{}),e.jsx("p",{children:"Be aware that changes here will take up to two minutes to be updated. In addition, there is a maxAge on the Access-Control-Allow-Origin header that will instruct browsers to cache this header for some time. The cache period is set to the maxium that the browser allows (2h for Chrome, 24h for Firefox)."})]}),Mi=()=>{const{makeRequest:t,createRequest:s,errors:n,loading:o}=fe({propagateErrors:!0});return{setFrontendSettings:async i=>{const l=s("api/admin/ui-config",{method:"POST",body:JSON.stringify({frontendSettings:{frontendApiOrigins:i}})},"setFrontendSettings");await t(l.caller,l.id)},loading:o,errors:n}},zi=({frontendApiOrigins:t})=>{const{setFrontendSettings:s}=Mi(),{setToastData:n,setToastApiError:o}=J(),[a,i]=h.useState(Rs(t)),r=js(),l=js(),c=async d=>{try{const u=Vi(a);d.preventDefault(),await s(u),i(Rs(u)),n({title:"Settings saved",type:"success"})}catch(u){o(z(u))}};return e.jsx("form",{onSubmit:c,children:e.jsxs(q,{sx:{display:"grid",gap:1},children:[e.jsxs("label",{htmlFor:r,children:["Which origins should be allowed to call the Frontend API? Add only one origin per line. The CORS specification does not support wildcard for subdomains, it needs to be a fully qualified domain, including the protocol.",e.jsx("br",{}),e.jsx("br",{}),'If you specify "*" it will be the chosen origin.',e.jsx("br",{}),e.jsx("br",{}),"Example:"]}),e.jsxs("code",{style:{fontSize:"0.7em"},children:["https://www.example.com",e.jsx("br",{}),"https://www.example2.com"]}),e.jsx(Z,{id:r,"aria-describedby":l,placeholder:Yi,value:a,onChange:d=>i(d.target.value),multiline:!0,rows:12,variant:"outlined",fullWidth:!0,InputProps:{style:{fontFamily:"monospace",fontSize:"0.8em"}}}),e.jsx(cn,{permission:M})]})})},Vi=t=>t.split(/[,\n\s]+/).map(s=>s.replace(/\/$/,"")).filter(Boolean),Rs=t=>(t==null?void 0:t.join(`
@@ -12,7 +12,7 @@ import{c as ft,j as e,c$ as zs,d0 as ge,d1 as xs,d2 as gs,d3 as $e,at as Q,au as
12
12
  --data-raw '${JSON.stringify(j(),void 0,2)}'`,I=()=>{o(Ee)},v=D=>D.length,F=D=>!(k!=null&&k.filter(W=>W.name===D).length),R=v(a)&&F(a),b=D=>{y(),F(D)||C({name:"A group with that name already exists."}),i(D)};return e.jsx(Ce,{loading:T,title:"Create group",description:"Groups is the best and easiest way to organize users and then use them in projects to assign a specific role in one go to all the users in a group.",documentationLink:"https://docs.getunleash.io/reference/rbac#user-groups",documentationLinkLabel:"Groups documentation",formatApiCode:P,children:e.jsx(Un,{name:a,description:r,mappingsSSO:c,rootRole:x,users:u,setName:b,setDescription:l,setMappingsSSO:d,setRootRole:g,setUsers:p,errors:w,handleSubmit:L,handleCancel:I,mode:Eo,children:e.jsx(_,{type:"submit",variant:"contained",color:"primary",disabled:!R,"data-testid":Ao,children:"Create group"})})})},qr=()=>{const t=Number(ss("groupId")),{group:s,refetchGroup:n}=kt(t);return s?e.jsx(_r,{group:s,groupId:t,refetchGroup:n}):null},_r=({group:t,groupId:s,refetchGroup:n})=>{const{refetchGroups:o}=Fe(),{setToastData:a,setToastApiError:i}=J(),{uiConfig:r}=N(),l=ve(),{name:c,setName:d,description:u,setDescription:p,mappingsSSO:x,setMappingsSSO:g,users:j,setUsers:y,rootRole:w,setRootRole:C,getGroupPayload:k,clearErrors:A,errors:T,setErrors:L}=ps(t==null?void 0:t.name,t==null?void 0:t.description,t==null?void 0:t.mappingsSSO,t==null?void 0:t.users,t==null?void 0:t.rootRole),{groups:P}=Fe(),{updateGroup:I,loading:v}=ut(),F=async V=>{V.preventDefault(),A();const ne=k();try{await I(s,ne),n(),o(),l(Ee),a({title:"Group updated successfully",type:"success"})}catch(oe){i(z(oe))}},R=()=>`curl --location --request PUT '${r.unleashUrl}/api/admin/groups/${s}' \\
13
13
  --header 'Authorization: INSERT_API_KEY' \\
14
14
  --header 'Content-Type: application/json' \\
15
- --data-raw '${JSON.stringify(k(),void 0,2)}'`,b=()=>{l(Ee)},D=V=>V.length,W=V=>!(P!=null&&P.filter(ne=>ne.name===V&&ne.id!==s).length),E=D(c)&&W(c),$=V=>{A(),W(V)||L({name:"A group with that name already exists."}),d(V)};return e.jsx(Ce,{loading:v,title:"Edit group",description:"Groups is the best and easiest way to organize users and then use them in projects to assign a specific role in one go to all the users in a group.",documentationLink:"https://docs.getunleash.io/reference/rbac#user-groups",documentationLinkLabel:"Groups documentation",formatApiCode:R,children:e.jsx(Un,{name:c,description:u,mappingsSSO:x,users:j,rootRole:w,setName:$,setDescription:p,setMappingsSSO:g,setUsers:y,setRootRole:C,errors:T,handleSubmit:F,handleCancel:b,mode:ns,children:e.jsx(_,{type:"submit",variant:"contained",color:"primary",disabled:!E,"data-testid":un,children:"Save"})})})},Wr=m(pn)(({theme:t})=>({borderRadius:t.shape.borderRadiusLarge,padding:t.spacing(2.5,4),boxShadow:"none",marginBottom:t.spacing(2),fontSize:t.fontSizes.smallBody})),Hr=m("div")(({theme:t})=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),Mr=m("h1")(({theme:t})=>({fontSize:t.fontSizes.mainHeader})),zr=m("div")(({theme:t})=>({display:"flex"})),Vr=m("span")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginLeft:t.spacing(1)})),Yr=({title:t,description:s,actions:n})=>(Js(t),e.jsxs(Wr,{children:[e.jsxs(Hr,{children:[e.jsx(Mr,{children:t}),e.jsx(zr,{children:n})]}),e.jsx(S,{condition:!!(s!=null&&s.length),show:e.jsxs(e.Fragment,{children:["Description:",e.jsx(Vr,{children:s})]})})]})),Jr=({open:t,setOpen:s,user:n,group:o})=>{const{refetchGroup:a}=kt(o.id),{updateGroup:i}=ut(),{setToastData:r,setToastApiError:l}=J(),c=async()=>{try{const u={...o,users:o.users.filter(({id:p})=>p!==(n==null?void 0:n.id)).map(({id:p})=>({user:{id:p}}))};await i(o.id,u),a(),s(!1),r({title:"User removed from group successfully",type:"success"})}catch(u){l(z(u))}},d=(n==null?void 0:n.name)||(n==null?void 0:n.username)||(n==null?void 0:n.email);return e.jsx(se,{open:t&&!!n,primaryButtonText:"Remove user",secondaryButtonText:"Cancel",onClick:c,onClose:()=>{s(!1)},title:"Remove user from group?",children:e.jsxs(B,{children:["Do you really want to remove ",e.jsx("strong",{children:d})," from"," ",e.jsx("strong",{children:o.name}),"? ",e.jsx("strong",{children:d})," will lose all access rights granted by this group."]})})},Kr=Array(15).fill({name:"Name of the user",username:"Username of the user"}),Zr={id:"joinedAt",desc:!0},{value:Ds,setValue:Qr}=Do("Group:v1",Zr),Xr=()=>{const t=Number(ss("groupId")),s=os(),n=he(s.breakpoints.down("md")),{group:o,loading:a}=kt(t),[i,r]=h.useState(!1),[l,c]=h.useState(!1),[d,u]=h.useState(!1),[p,x]=h.useState(),g=h.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:b}})=>e.jsx(te,{children:e.jsx(Oe,{user:b})}),maxWidth:85,disableSortBy:!0},{id:"name",Header:"Name",accessor:b=>b.name||"",Cell:({value:b,row:{original:D}})=>e.jsx(Se,{value:b,subtitle:D.email||D.username}),minWidth:100,searchable:!0},{Header:"Joined",accessor:"joinedAt",Cell:xe,maxWidth:150},{id:"createdBy",Header:"Added by",accessor:"createdBy",Cell:Se,minWidth:90,searchable:!0},{Header:"Last login",accessor:b=>b.seenAt||"",Cell:({row:{original:b}})=>e.jsx(Je,{value:b.seenAt,emptyText:"Never",title:D=>`Last login: ${D}`}),maxWidth:150},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:b}})=>e.jsx(yt,{children:e.jsx(Be,{title:"Remove user from group",arrow:!0,describeChild:!0,children:e.jsx("span",{children:e.jsx(Ge,{"data-testid":`${Io}-${b.id}`,onClick:()=>{x(b),u(!0)},children:e.jsx(Ae,{})})})})}),maxWidth:100,disableSortBy:!0},{accessor:b=>b.username||"",Header:"Username",searchable:!0},{accessor:b=>b.email||"",Header:"Email",searchable:!0}],[x,u]),[j,y]=hn(),[w]=h.useState(()=>({sortBy:[{id:j.get("sort")||Ds.id,desc:j.has("order")?j.get("order")==="desc":Ds.desc}],hiddenColumns:["Username","Email"],globalFilter:j.get("search")||""})),[C,k]=h.useState(w.globalFilter),{data:A,getSearchText:T,getSearchContext:L}=Ke(g,C,(o==null?void 0:o.users)??[]),P=h.useMemo(()=>(A==null?void 0:A.length)===0&&a?Kr:A,[A,a]),{headerGroups:I,rows:v,prepareRow:F,state:{sortBy:R}}=U.useTable({columns:g,data:P,initialState:w,sortTypes:pe,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},U.useSortBy,U.useFlexLayout);return h.useEffect(()=>{const b={};b.sort=R[0].id,R[0].desc&&(b.order="desc"),C&&(b.search=C),y(b,{replace:!0}),Qr({id:R[0].id,desc:R[0].desc||!1})},[R,C,y]),e.jsx(S,{condition:!!o,show:e.jsxs(e.Fragment,{children:[e.jsx(Yr,{title:o==null?void 0:o.name,description:o==null?void 0:o.description,actions:e.jsxs(e.Fragment,{children:[e.jsx(ue,{"data-testid":Po,to:`/admin/groups/${t}/edit`,component:re,"data-loading":!0,permission:M,tooltipProps:{title:"Edit group"},children:e.jsx(Ve,{})}),e.jsx(ue,{"data-testid":Bo,"data-loading":!0,onClick:()=>r(!0),permission:M,tooltipProps:{title:"Delete group"},children:e.jsx(Ae,{})})]})}),e.jsxs(Q,{isLoading:a,header:e.jsx(X,{secondary:!0,title:`Users (${v.length<P.length?`${v.length} of ${P.length}`:P.length})`,actions:e.jsxs(e.Fragment,{children:[e.jsx(S,{condition:!n,show:e.jsxs(e.Fragment,{children:[e.jsx(le,{initialValue:C,onChange:k,hasFilters:!0,getSearchContext:L}),e.jsx(X.Divider,{})]})}),e.jsx(ts,{"data-testid":Lo,onClick:()=>{c(!0)},maxWidth:"700px",Icon:wt,permission:M,children:"Edit users"})]}),children:e.jsx(S,{condition:n,show:e.jsx(le,{initialValue:C,onChange:k,hasFilters:!0,getSearchContext:L})})}),children:[e.jsx(qe,{value:T(C),children:e.jsx(ye,{rows:v,headerGroups:I,prepareRow:F})}),e.jsx(S,{condition:v.length===0,show:e.jsx(S,{condition:(C==null?void 0:C.length)>0,show:e.jsxs(de,{children:["No users found matching “",C,"” in this group."]}),elseShow:e.jsx(de,{children:"This group is empty. Get started by adding a user to the group."})})}),e.jsx(On,{open:i,setOpen:r,group:o}),e.jsx(Ln,{open:l,setOpen:c,group:o}),e.jsx(Jr,{open:d,setOpen:u,user:p,group:o})]})]})})},el=()=>{const{uiConfig:t,isEnterprise:s}=N();return s()||t.flags[Oo]===!0?e.jsx("div",{children:e.jsx(ge,{permissions:$e,children:e.jsxs(lt,{children:[e.jsx(G,{index:!0,element:e.jsx(Dr,{})}),e.jsx(G,{path:"create-group",element:e.jsx(Gr,{})}),e.jsx(G,{path:":groupId/edit",element:e.jsx(qr,{})}),e.jsx(G,{path:":groupId",element:e.jsx(Xr,{})})]})})}):e.jsx(rt,{feature:"groups",page:!0})},tl=()=>{const{data:t,error:s,mutate:n}=Le(ie("api/admin/instance-admin/statistics"),sl);return h.useMemo(()=>({stats:t,loading:!s&&!t,refetchGroup:()=>n(),error:s}),[t,s,n])},sl=t=>fetch(t).then(je("Instance Stats")).then(s=>s.json()),nl=()=>{const{stats:t}=tl();let s,n;t!=null&&t.versionEnterprise?(s="Unleash Enterprise version",n=t.versionEnterprise):(s="Unleash OSS version",n=t==null?void 0:t.versionOSS);const o=[{title:"Instance Id",value:t==null?void 0:t.instanceId,offset:!1},{title:s,value:n},{title:"Users",value:t==null?void 0:t.users},{title:"Feature toggles",value:t==null?void 0:t.featureToggles},{title:"Projects",value:t==null?void 0:t.projects},{title:"Environments",value:t==null?void 0:t.environments},{title:"Roles",value:t==null?void 0:t.roles},{title:"Groups",value:t==null?void 0:t.groups},{title:"Context fields",value:t==null?void 0:t.contextFields},{title:"Strategies",value:t==null?void 0:t.strategies},{title:"Feature exports",value:t==null?void 0:t.featureExports},{title:"Feature imports",value:t==null?void 0:t.featureImports}];return t!=null&&t.versionEnterprise&&o.push({title:"SAML enabled",value:t!=null&&t.SAMLenabled?"Yes":"No"},{title:"OIDC enabled",value:t!=null&&t.OIDCenabled?"Yes":"No"}),e.jsx(Q,{header:e.jsx(X,{title:"Instance Statistics"}),children:e.jsxs(fs,{sx:{display:"grid",gap:4},children:[e.jsxs(an,{"aria-label":"Instance statistics",children:[e.jsx(rn,{children:e.jsxs(it,{children:[e.jsx(ae,{children:"Field"}),e.jsx(ae,{align:"right",children:"Value"})]})}),e.jsx(Xt,{children:o.map(a=>e.jsxs(it,{children:[e.jsx(ae,{component:"th",scope:"row",children:e.jsx(fs,{component:"span",sx:i=>({marginLeft:a.offset?i.spacing(2):0}),children:a.title})}),e.jsx(ae,{align:"right",children:a.value})]},a.title))})]}),e.jsx("span",{style:{textAlign:"center"},children:e.jsx(_,{startIcon:e.jsx(mn,{}),"aria-label":"Download instance statistics",color:"primary",variant:"contained",target:"_blank",rel:"noreferrer",href:ie("/api/admin/instance-admin/statistics/csv"),children:"Download"})})]})})},ol=()=>e.jsx("div",{children:e.jsx(nl,{})}),al=m("div")(({theme:t})=>({display:"flex",flexDirection:"column",padding:t.spacing(3),border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadiusLarge})),il=m(q)(()=>({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"})),rl=m(q)(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(2)})),ll=m("p")(({theme:t})=>({display:"table-cell",fontWeight:t.fontWeight.bold,paddingTop:t.spacing(2)})),cl=m("p")(({theme:t})=>({display:"table-cell",paddingTop:t.spacing(2),paddingLeft:t.spacing(4)})),dl=m("div")(({theme:t})=>({display:"table-cell",width:"75%",paddingTop:t.spacing(2),paddingBottom:t.spacing(2)})),ul=m("div")(({theme:t})=>({display:"table-cell"})),hl=m("span")(({theme:t})=>({display:"block",textAlign:"right",color:t.palette.neutral.dark})),pl=m("div")(({theme:t})=>({maxWidth:t.spacing(50),color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody})),ml=m("div")(()=>({display:"table-row"})),Is=m("div")(()=>({display:"table"})),xl=m("div")(()=>({display:"table-cell"})),gl=({changeInfoText:t,variablesText:s,dependsOnText:n})=>e.jsxs(pl,{children:[e.jsx(Ps,{children:t}),e.jsx(jl,{children:e.jsx("div",{children:s})}),e.jsx(S,{condition:!!n,show:e.jsx(Ps,{children:n})})]}),jl=m("code")(({theme:t})=>({display:"block",color:t.palette.text.primary,backgroundColor:t.palette.background.application,fontSize:t.fontSizes.smallerBody,marginTop:t.spacing(1),padding:t.spacing(1),border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadius,borderWidth:1,wordWrap:"break-word",whiteSpace:"pre-wrap",fontFamily:"monospace",lineHeight:1.5})),Ps=m("p")(({theme:t})=>({color:t.palette.text.primary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1)})),Bs=({title:t,infoText:s,concreteDetails:n,enabled:o,changeInfoText:a,variablesText:i,dependsOnText:r})=>e.jsxs(al,{children:[e.jsxs(il,{children:[e.jsx("b",{children:t}),e.jsx(ul,{children:e.jsx(S,{condition:o,show:e.jsx(ze,{color:"success",icon:e.jsx(tn,{}),children:"Data is collected"}),elseShow:e.jsx(ze,{color:"neutral",icon:e.jsx(Wa,{}),children:"No data is collected"})})})]}),e.jsxs(rl,{children:[e.jsxs(Is,{children:[e.jsx(dl,{children:s}),e.jsx(xl,{children:e.jsx(hl,{children:e.jsx(as,{tooltip:e.jsx(gl,{changeInfoText:a,variablesText:i,dependsOnText:r}),children:o?"How to disable collecting data?":"How to enable collecting data?"})})})]}),e.jsx(Is,{children:Object.entries(n).map(([l,c])=>e.jsxs(ml,{children:[e.jsx(ll,{children:l}),e.jsx(cl,{children:c})]},l))})]})]}),fl=()=>{const{data:t,error:s,mutate:n}=Le(ie("api/admin/telemetry/settings"),yl);return h.useMemo(()=>({settings:t,loading:!s&&!t,refetchGroup:()=>n(),error:s}),[t,s,n])},yl=t=>fetch(t).then(je("Telemetry Settings")).then(s=>s.json()),bl=m(q)(({theme:t})=>({display:"grid",gap:t.spacing(4)})),Gt={title:"Version data collection",infoText:"We collect the version of Unleash that you're using. We use this information to inform your Unleash instance of latest updates and critical security patches.",concreteDetails:{"Instance ID":"A unique ID generated for your instance",Version:"The version of Unleash that you're using"}},qt={title:"Feature data collection",infoText:"We collect data about your instance to improve the Unleash product user experience. We may also use the data in case you need help from our support team. Data collection is for internal use only and is not shared with third parties outside Unleash. As we want you to be in control of your data, we will leave it up to you to allow us to collect your data.",concreteDetails:{"Feature toggles":"The number of feature toggles in your instance",Users:"The number of users registered in your instance",Projects:"The number of projects in your instance","Context Fields":"The number of custom context fields in use",Groups:"The number of groups present in your instance",Roles:"The number of custom roles defined in your instance","Custom Root Roles":"The number of custom root roles defined in your instance","Custom Root Roles In Use":"The number of custom root roles that are in use by entities (users, groups, service accounts)",Environments:"The number of environments in your instance",Segments:"The number of segments defined in your instance",Strategies:"The number of strategies defined in your instance","Feature Exports":"The number of feature exports performed","Feature Imports":"The number of feature imports performed","Custom Strategies":"The number of custom strategies defined in your instance","Custom Strategies In Use":"The number of custom strategies that are in use by feature toggles"}},Ls={enabled:{environmentVariables:"CHECK_VERSION=false",changeInfoText:"Version info collection can be disabled by setting the environment variable `CHECK_VERSION` to `false` and restarting Unleash."},disabled:{environmentVariables:"CHECK_VERSION=true",changeInfoText:"Version info collection can be enabled by setting the environment variable to true and restarting Unleash."}},Os={enabled:{environmentVariables:"SEND_TELEMETRY=false",changeInfoText:"Feature usage collection can be disabled by setting the environment variable to false and restarting Unleash."},disabled:{environmentVariables:"SEND_TELEMETRY=true",changeInfoText:"To enable feature usage collection set the environment variable to true and restart Unleash."}},Sl=()=>{const{settings:t}=fl(),{loading:s}=N();if(s)return null;const n=t!=null&&t.versionInfoCollectionEnabled?Ls.enabled:Ls.disabled,o=t!=null&&t.featureInfoCollectionEnabled?Os.enabled:Os.disabled;let a;return t!=null&&t.versionInfoCollectionEnabled||(a=t!=null&&t.featureInfoCollectionEnabled?"Note: Feature usage collection is enabled, but for it to be active you must also enable version info collection":"When you enable feature usage collection you must also enable version info collection"),e.jsx(Q,{header:e.jsx(X,{title:"Instance Privacy"}),children:e.jsxs(bl,{children:[e.jsx(Bs,{title:Gt.title,infoText:Gt.infoText,concreteDetails:Gt.concreteDetails,enabled:t==null?void 0:t.versionInfoCollectionEnabled,changeInfoText:n.changeInfoText,variablesText:n.environmentVariables}),e.jsx(Bs,{title:qt.title,infoText:qt.infoText,concreteDetails:qt.concreteDetails,enabled:(t==null?void 0:t.featureInfoCollectionEnabled)&&(t==null?void 0:t.versionInfoCollectionEnabled),changeInfoText:o.changeInfoText,variablesText:o.environmentVariables,dependsOnText:a})]})})},vl=()=>e.jsx(K,{severity:"warning",children:e.jsxs("p",{children:[e.jsx("b",{children:"Heads up!"})," If you enable maintenance mode, edit access in the entire system will be disabled for all the users (admins, editors, custom roles, etc). During this time nobody will be able to do changes or to make new configurations."]})}),Cl=()=>{const{data:t,error:s,mutate:n}=Le(ie("api/admin/maintenance"),wl);return h.useMemo(()=>({enabled:!!(t!=null&&t.enabled),loading:!s&&!t,refetchMaintenance:n,error:s}),[t,s,n])},wl=t=>fetch(t).then(je("Maintenance")).then(s=>s.json()),Tl=()=>{const{makeRequest:t,createRequest:s,errors:n,loading:o}=fe({propagateErrors:!0});return{toggleMaintenance:async i=>{const l=s("api/admin/maintenance",{method:"POST",body:JSON.stringify(i)});await t(l.caller,l.id)},errors:n,loading:o}},kl=m("div")(({theme:t})=>({display:"flex",flexDirection:"column",padding:t.spacing(3),border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadiusLarge})),Rl=m(q)({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}),El=m(q)(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(2)})),Al=m(B)(({theme:t})=>({fontSize:t.fontSizes.smallBody})),Dl=()=>{const{enabled:t,refetchMaintenance:s}=Cl(),{refetch:n}=N(),{toggleMaintenance:o}=Tl(),{trackEvent:a}=is(),{setToastData:i}=J(),r=async()=>{i({type:"success",title:`Maintenance mode has been successfully ${t?"disabled":"enabled"}`}),a("maintenance",{props:{eventType:`maintenance ${t?"de":""}activated`}}),await o({enabled:!t}),s(),n()};return e.jsxs(kl,{children:[e.jsxs(Rl,{children:[e.jsx("b",{children:"Maintenance Mode"}),e.jsx(ce,{sx:{margin:0},control:e.jsx(me,{onChange:r,value:t,name:"enabled",checked:t}),label:e.jsx(Al,{children:t?"Enabled":"Disabled"})})]}),e.jsx(El,{children:"Maintenance Mode is useful when you want to freeze your system so nobody can do any changes during this time. When enabled it will show a banner at the top of the applications and only an admin can enable it or disable it."})]})},Il=()=>e.jsx("div",{children:e.jsx(ge,{permissions:M,children:e.jsx(Bl,{})})}),Pl=m(q)(({theme:t})=>({display:"grid",gap:t.spacing(4)})),Bl=()=>{const{loading:t}=N();return t?null:e.jsx(Q,{header:e.jsx(X,{title:"Maintenance"}),children:e.jsxs(Pl,{children:[e.jsx(vl,{}),e.jsx(Dl,{})]})})},Ll=m(Uo)(({theme:t})=>({display:"flex",justifyContent:"center",alignItems:"center",width:"100%",height:"100%",textDecoration:"none",color:"inherit",padding:t.spacing(0,5),"&.active":{fontWeight:"bold"}})),$n=({to:t,children:s})=>e.jsx(Ll,{to:t,children:s}),Ol=h.lazy(()=>xn(()=>import("./NetworkOverview-7SCGp57r.js").then(t=>t.N),__vite__mapDeps([]))),Ul=h.lazy(()=>xn(()=>import("./NetworkTraffic-awTd8Zg5.js"),__vite__mapDeps([]))),$l=[{label:"Overview",path:"/admin/network"},{label:"Traffic",path:"/admin/network/traffic"}],Nl=()=>{const{pathname:t}=rs();return e.jsx("div",{children:e.jsx(Q,{withTabs:!0,header:e.jsx(St,{value:t,indicatorColor:"primary",textColor:"primary",variant:"scrollable",allowScrollButtonsMobile:!0,children:$l.map(({label:s,path:n})=>e.jsx(vt,{value:n,label:e.jsx($n,{to:n,children:e.jsx("span",{children:s})}),sx:{padding:0}},s))}),children:e.jsxs(lt,{children:[e.jsx(G,{path:"traffic",element:e.jsx(Ul,{})}),e.jsx(G,{path:"*",element:e.jsx(Ol,{})})]})})})},Fl=m(q)(()=>({display:"flex",justifyContent:"center"})),Gl=({role:t,onEdit:s,onDelete:n})=>{const o=Ne.includes(t.type);return e.jsxs(Fl,{children:[e.jsx(ue,{"data-loading":!0,onClick:s,permission:M,disabled:o,tooltipProps:{title:o?"You cannot edit a predefined role":"Edit role"},children:e.jsx(Ve,{})}),e.jsx(ue,{"data-loading":!0,onClick:n,permission:M,disabled:o,tooltipProps:{title:o?"You cannot remove a predefined role":"Remove role"},children:e.jsx(Ae,{})})]})},ql=m(ze)(({theme:t})=>({marginLeft:t.spacing(1)})),_l=({role:t})=>e.jsx(Se,{value:t.name,subtitle:t.description,afterTitle:e.jsx(S,{condition:Ne.includes(t.type),show:e.jsx(ql,{color:"success",children:"Predefined"})})}),Wl=({users:t})=>{const[s]=h.useState(()=>({sortBy:[{id:"last-login",desc:!0}]})),n=h.useMemo(()=>[{id:"name",Header:"Name",accessor:r=>r.name||"",minWidth:200,Cell:({row:{original:r}})=>e.jsx(Se,{value:r.name,subtitle:r.email||r.username})},{Header:"Created",accessor:"createdAt",Cell:xe,width:120,maxWidth:120},{id:"last-login",Header:"Last login",accessor:r=>r.seenAt||"",Cell:({row:{original:r}})=>e.jsx(Je,{value:r.seenAt,emptyText:"Never",title:l=>`Last login: ${l}`}),maxWidth:150}],[]),{headerGroups:o,rows:a,prepareRow:i}=U.useTable({columns:n,data:t,initialState:s,sortTypes:pe,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},U.useSortBy,U.useFlexLayout);return e.jsx(ye,{rows:a,headerGroups:o,prepareRow:i})},Hl=m(B)(({theme:t})=>({fontSize:t.fontSizes.smallerBody})),Nn=({serviceAccount:t,value:s,onCreateToken:n})=>{var a,i,r;const{searchQuery:o}=$o();return!t.tokens||t.tokens.length===0?n?e.jsx(gn,{title:"Create token",onClick:n}):e.jsx(te,{children:"0 tokens"}):e.jsx(te,{children:e.jsx(as,{tooltip:e.jsx(e.Fragment,{children:(a=t.tokens)==null?void 0:a.map(({id:l,description:c})=>e.jsx(Hl,{children:e.jsx(No,{search:o,children:c})},l))}),highlighted:o.length>0&&s.toLowerCase().includes(o.toLowerCase()),children:((i=t.tokens)==null?void 0:i.length)===1?"1 token":`${(r=t.tokens)==null?void 0:r.length} tokens`})})},Ml=({serviceAccounts:t})=>{const[s]=h.useState(()=>({sortBy:[{id:"seenAt",desc:!0}]})),n=h.useMemo(()=>[{id:"name",Header:"Name",accessor:r=>r.name||"",minWidth:200,Cell:({row:{original:r}})=>e.jsx(Se,{value:r.name,subtitle:r.username})},{id:"tokens",Header:"Tokens",accessor:r=>{var l;return((l=r.tokens)==null?void 0:l.map(({description:c})=>c).join(`
15
+ --data-raw '${JSON.stringify(k(),void 0,2)}'`,b=()=>{l(Ee)},D=V=>V.length,W=V=>!(P!=null&&P.filter(ne=>ne.name===V&&ne.id!==s).length),E=D(c)&&W(c),$=V=>{A(),W(V)||L({name:"A group with that name already exists."}),d(V)};return e.jsx(Ce,{loading:v,title:"Edit group",description:"Groups is the best and easiest way to organize users and then use them in projects to assign a specific role in one go to all the users in a group.",documentationLink:"https://docs.getunleash.io/reference/rbac#user-groups",documentationLinkLabel:"Groups documentation",formatApiCode:R,children:e.jsx(Un,{name:c,description:u,mappingsSSO:x,users:j,rootRole:w,setName:$,setDescription:p,setMappingsSSO:g,setUsers:y,setRootRole:C,errors:T,handleSubmit:F,handleCancel:b,mode:ns,children:e.jsx(_,{type:"submit",variant:"contained",color:"primary",disabled:!E,"data-testid":un,children:"Save"})})})},Wr=m(pn)(({theme:t})=>({borderRadius:t.shape.borderRadiusLarge,padding:t.spacing(2.5,4),boxShadow:"none",marginBottom:t.spacing(2),fontSize:t.fontSizes.smallBody})),Hr=m("div")(({theme:t})=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),Mr=m("h1")(({theme:t})=>({fontSize:t.fontSizes.mainHeader})),zr=m("div")(({theme:t})=>({display:"flex"})),Vr=m("span")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginLeft:t.spacing(1)})),Yr=({title:t,description:s,actions:n})=>(Js(t),e.jsxs(Wr,{children:[e.jsxs(Hr,{children:[e.jsx(Mr,{children:t}),e.jsx(zr,{children:n})]}),e.jsx(S,{condition:!!(s!=null&&s.length),show:e.jsxs(e.Fragment,{children:["Description:",e.jsx(Vr,{children:s})]})})]})),Jr=({open:t,setOpen:s,user:n,group:o})=>{const{refetchGroup:a}=kt(o.id),{updateGroup:i}=ut(),{setToastData:r,setToastApiError:l}=J(),c=async()=>{try{const u={...o,users:o.users.filter(({id:p})=>p!==(n==null?void 0:n.id)).map(({id:p})=>({user:{id:p}}))};await i(o.id,u),a(),s(!1),r({title:"User removed from group successfully",type:"success"})}catch(u){l(z(u))}},d=(n==null?void 0:n.name)||(n==null?void 0:n.username)||(n==null?void 0:n.email);return e.jsx(se,{open:t&&!!n,primaryButtonText:"Remove user",secondaryButtonText:"Cancel",onClick:c,onClose:()=>{s(!1)},title:"Remove user from group?",children:e.jsxs(B,{children:["Do you really want to remove ",e.jsx("strong",{children:d})," from"," ",e.jsx("strong",{children:o.name}),"? ",e.jsx("strong",{children:d})," will lose all access rights granted by this group."]})})},Kr=Array(15).fill({name:"Name of the user",username:"Username of the user"}),Zr={id:"joinedAt",desc:!0},{value:Ds,setValue:Qr}=Do("Group:v1",Zr),Xr=()=>{const t=Number(ss("groupId")),s=os(),n=he(s.breakpoints.down("md")),{group:o,loading:a}=kt(t),[i,r]=h.useState(!1),[l,c]=h.useState(!1),[d,u]=h.useState(!1),[p,x]=h.useState(),g=h.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:b}})=>e.jsx(te,{children:e.jsx(Oe,{user:b})}),maxWidth:85,disableSortBy:!0},{id:"name",Header:"Name",accessor:b=>b.name||"",Cell:({value:b,row:{original:D}})=>e.jsx(Se,{value:b,subtitle:D.email||D.username}),minWidth:100,searchable:!0},{Header:"Joined",accessor:"joinedAt",Cell:xe,maxWidth:150},{id:"createdBy",Header:"Added by",accessor:"createdBy",Cell:Se,minWidth:90,searchable:!0},{Header:"Last login",accessor:b=>b.seenAt||"",Cell:({row:{original:b}})=>e.jsx(Je,{value:b.seenAt,emptyText:"Never",title:D=>`Last login: ${D}`}),maxWidth:150},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:b}})=>e.jsx(yt,{children:e.jsx(Be,{title:"Remove user from group",arrow:!0,describeChild:!0,children:e.jsx("span",{children:e.jsx(Ge,{"data-testid":`${Io}-${b.id}`,onClick:()=>{x(b),u(!0)},children:e.jsx(Ae,{})})})})}),maxWidth:100,disableSortBy:!0},{accessor:b=>b.username||"",Header:"Username",searchable:!0},{accessor:b=>b.email||"",Header:"Email",searchable:!0}],[x,u]),[j,y]=hn(),[w]=h.useState(()=>({sortBy:[{id:j.get("sort")||Ds.id,desc:j.has("order")?j.get("order")==="desc":Ds.desc}],hiddenColumns:["Username","Email"],globalFilter:j.get("search")||""})),[C,k]=h.useState(w.globalFilter),{data:A,getSearchText:T,getSearchContext:L}=Ke(g,C,(o==null?void 0:o.users)??[]),P=h.useMemo(()=>(A==null?void 0:A.length)===0&&a?Kr:A,[A,a]),{headerGroups:I,rows:v,prepareRow:F,state:{sortBy:R}}=U.useTable({columns:g,data:P,initialState:w,sortTypes:pe,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},U.useSortBy,U.useFlexLayout);return h.useEffect(()=>{const b={};b.sort=R[0].id,R[0].desc&&(b.order="desc"),C&&(b.search=C),y(b,{replace:!0}),Qr({id:R[0].id,desc:R[0].desc||!1})},[R,C,y]),e.jsx(S,{condition:!!o,show:e.jsxs(e.Fragment,{children:[e.jsx(Yr,{title:o==null?void 0:o.name,description:o==null?void 0:o.description,actions:e.jsxs(e.Fragment,{children:[e.jsx(ue,{"data-testid":Po,to:`/admin/groups/${t}/edit`,component:re,"data-loading":!0,permission:M,tooltipProps:{title:"Edit group"},children:e.jsx(Ve,{})}),e.jsx(ue,{"data-testid":Bo,"data-loading":!0,onClick:()=>r(!0),permission:M,tooltipProps:{title:"Delete group"},children:e.jsx(Ae,{})})]})}),e.jsxs(Q,{isLoading:a,header:e.jsx(X,{secondary:!0,title:`Users (${v.length<P.length?`${v.length} of ${P.length}`:P.length})`,actions:e.jsxs(e.Fragment,{children:[e.jsx(S,{condition:!n,show:e.jsxs(e.Fragment,{children:[e.jsx(le,{initialValue:C,onChange:k,hasFilters:!0,getSearchContext:L}),e.jsx(X.Divider,{})]})}),e.jsx(ts,{"data-testid":Lo,onClick:()=>{c(!0)},maxWidth:"700px",Icon:wt,permission:M,children:"Edit users"})]}),children:e.jsx(S,{condition:n,show:e.jsx(le,{initialValue:C,onChange:k,hasFilters:!0,getSearchContext:L})})}),children:[e.jsx(qe,{value:T(C),children:e.jsx(ye,{rows:v,headerGroups:I,prepareRow:F})}),e.jsx(S,{condition:v.length===0,show:e.jsx(S,{condition:(C==null?void 0:C.length)>0,show:e.jsxs(de,{children:["No users found matching “",C,"” in this group."]}),elseShow:e.jsx(de,{children:"This group is empty. Get started by adding a user to the group."})})}),e.jsx(On,{open:i,setOpen:r,group:o}),e.jsx(Ln,{open:l,setOpen:c,group:o}),e.jsx(Jr,{open:d,setOpen:u,user:p,group:o})]})]})})},el=()=>{const{uiConfig:t,isEnterprise:s}=N();return s()||t.flags[Oo]===!0?e.jsx("div",{children:e.jsx(ge,{permissions:$e,children:e.jsxs(lt,{children:[e.jsx(G,{index:!0,element:e.jsx(Dr,{})}),e.jsx(G,{path:"create-group",element:e.jsx(Gr,{})}),e.jsx(G,{path:":groupId/edit",element:e.jsx(qr,{})}),e.jsx(G,{path:":groupId",element:e.jsx(Xr,{})})]})})}):e.jsx(rt,{feature:"groups",page:!0})},tl=()=>{const{data:t,error:s,mutate:n}=Le(ie("api/admin/instance-admin/statistics"),sl);return h.useMemo(()=>({stats:t,loading:!s&&!t,refetchGroup:()=>n(),error:s}),[t,s,n])},sl=t=>fetch(t).then(je("Instance Stats")).then(s=>s.json()),nl=()=>{const{stats:t}=tl();let s,n;t!=null&&t.versionEnterprise?(s="Unleash Enterprise version",n=t.versionEnterprise):(s="Unleash OSS version",n=t==null?void 0:t.versionOSS);const o=[{title:"Instance Id",value:t==null?void 0:t.instanceId,offset:!1},{title:s,value:n},{title:"Users",value:t==null?void 0:t.users},{title:"Feature toggles",value:t==null?void 0:t.featureToggles},{title:"Projects",value:t==null?void 0:t.projects},{title:"Environments",value:t==null?void 0:t.environments},{title:"Roles",value:t==null?void 0:t.roles},{title:"Groups",value:t==null?void 0:t.groups},{title:"Context fields",value:t==null?void 0:t.contextFields},{title:"Strategies",value:t==null?void 0:t.strategies},{title:"Feature exports",value:t==null?void 0:t.featureExports},{title:"Feature imports",value:t==null?void 0:t.featureImports}];return t!=null&&t.versionEnterprise&&o.push({title:"SAML enabled",value:t!=null&&t.SAMLenabled?"Yes":"No"},{title:"OIDC enabled",value:t!=null&&t.OIDCenabled?"Yes":"No"}),e.jsx(Q,{header:e.jsx(X,{title:"Instance Statistics"}),children:e.jsxs(fs,{sx:{display:"grid",gap:4},children:[e.jsxs(an,{"aria-label":"Instance statistics",children:[e.jsx(rn,{children:e.jsxs(it,{children:[e.jsx(ae,{children:"Field"}),e.jsx(ae,{align:"right",children:"Value"})]})}),e.jsx(Xt,{children:o.map(a=>e.jsxs(it,{children:[e.jsx(ae,{component:"th",scope:"row",children:e.jsx(fs,{component:"span",sx:i=>({marginLeft:a.offset?i.spacing(2):0}),children:a.title})}),e.jsx(ae,{align:"right",children:a.value})]},a.title))})]}),e.jsx("span",{style:{textAlign:"center"},children:e.jsx(_,{startIcon:e.jsx(mn,{}),"aria-label":"Download instance statistics",color:"primary",variant:"contained",target:"_blank",rel:"noreferrer",href:ie("/api/admin/instance-admin/statistics/csv"),children:"Download"})})]})})},ol=()=>e.jsx("div",{children:e.jsx(nl,{})}),al=m("div")(({theme:t})=>({display:"flex",flexDirection:"column",padding:t.spacing(3),border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadiusLarge})),il=m(q)(()=>({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"})),rl=m(q)(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(2)})),ll=m("p")(({theme:t})=>({display:"table-cell",fontWeight:t.fontWeight.bold,paddingTop:t.spacing(2)})),cl=m("p")(({theme:t})=>({display:"table-cell",paddingTop:t.spacing(2),paddingLeft:t.spacing(4)})),dl=m("div")(({theme:t})=>({display:"table-cell",width:"75%",paddingTop:t.spacing(2),paddingBottom:t.spacing(2)})),ul=m("div")(({theme:t})=>({display:"table-cell"})),hl=m("span")(({theme:t})=>({display:"block",textAlign:"right",color:t.palette.neutral.dark})),pl=m("div")(({theme:t})=>({maxWidth:t.spacing(50),color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody})),ml=m("div")(()=>({display:"table-row"})),Is=m("div")(()=>({display:"table"})),xl=m("div")(()=>({display:"table-cell"})),gl=({changeInfoText:t,variablesText:s,dependsOnText:n})=>e.jsxs(pl,{children:[e.jsx(Ps,{children:t}),e.jsx(jl,{children:e.jsx("div",{children:s})}),e.jsx(S,{condition:!!n,show:e.jsx(Ps,{children:n})})]}),jl=m("code")(({theme:t})=>({display:"block",color:t.palette.text.primary,backgroundColor:t.palette.background.application,fontSize:t.fontSizes.smallerBody,marginTop:t.spacing(1),padding:t.spacing(1),border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadius,borderWidth:1,wordWrap:"break-word",whiteSpace:"pre-wrap",fontFamily:"monospace",lineHeight:1.5})),Ps=m("p")(({theme:t})=>({color:t.palette.text.primary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1)})),Bs=({title:t,infoText:s,concreteDetails:n,enabled:o,changeInfoText:a,variablesText:i,dependsOnText:r})=>e.jsxs(al,{children:[e.jsxs(il,{children:[e.jsx("b",{children:t}),e.jsx(ul,{children:e.jsx(S,{condition:o,show:e.jsx(ze,{color:"success",icon:e.jsx(tn,{}),children:"Data is collected"}),elseShow:e.jsx(ze,{color:"neutral",icon:e.jsx(Wa,{}),children:"No data is collected"})})})]}),e.jsxs(rl,{children:[e.jsxs(Is,{children:[e.jsx(dl,{children:s}),e.jsx(xl,{children:e.jsx(hl,{children:e.jsx(as,{tooltip:e.jsx(gl,{changeInfoText:a,variablesText:i,dependsOnText:r}),children:o?"How to disable collecting data?":"How to enable collecting data?"})})})]}),e.jsx(Is,{children:Object.entries(n).map(([l,c])=>e.jsxs(ml,{children:[e.jsx(ll,{children:l}),e.jsx(cl,{children:c})]},l))})]})]}),fl=()=>{const{data:t,error:s,mutate:n}=Le(ie("api/admin/telemetry/settings"),yl);return h.useMemo(()=>({settings:t,loading:!s&&!t,refetchGroup:()=>n(),error:s}),[t,s,n])},yl=t=>fetch(t).then(je("Telemetry Settings")).then(s=>s.json()),bl=m(q)(({theme:t})=>({display:"grid",gap:t.spacing(4)})),Gt={title:"Version data collection",infoText:"We collect the version of Unleash that you're using. We use this information to inform your Unleash instance of latest updates and critical security patches.",concreteDetails:{"Instance ID":"A unique ID generated for your instance",Version:"The version of Unleash that you're using"}},qt={title:"Feature data collection",infoText:"We collect data about your instance to improve the Unleash product user experience. We may also use the data in case you need help from our support team. Data collection is for internal use only and is not shared with third parties outside Unleash. As we want you to be in control of your data, we will leave it up to you to allow us to collect your data.",concreteDetails:{"Feature toggles":"The number of feature toggles in your instance",Users:"The number of users registered in your instance",Projects:"The number of projects in your instance","Context Fields":"The number of custom context fields in use",Groups:"The number of groups present in your instance",Roles:"The number of custom roles defined in your instance","Custom Root Roles":"The number of custom root roles defined in your instance","Custom Root Roles In Use":"The number of custom root roles that are in use by entities (users, groups, service accounts)",Environments:"The number of environments in your instance",Segments:"The number of segments defined in your instance",Strategies:"The number of strategies defined in your instance","Feature Exports":"The number of feature exports performed","Feature Imports":"The number of feature imports performed","Custom Strategies":"The number of custom strategies defined in your instance","Custom Strategies In Use":"The number of custom strategies that are in use by feature toggles"}},Ls={enabled:{environmentVariables:"CHECK_VERSION=false",changeInfoText:"Version info collection can be disabled by setting the environment variable `CHECK_VERSION` to `false` and restarting Unleash."},disabled:{environmentVariables:"CHECK_VERSION=true",changeInfoText:"Version info collection can be enabled by setting the environment variable to true and restarting Unleash."}},Os={enabled:{environmentVariables:"SEND_TELEMETRY=false",changeInfoText:"Feature usage collection can be disabled by setting the environment variable to false and restarting Unleash."},disabled:{environmentVariables:"SEND_TELEMETRY=true",changeInfoText:"To enable feature usage collection set the environment variable to true and restart Unleash."}},Sl=()=>{const{settings:t}=fl(),{loading:s}=N();if(s)return null;const n=t!=null&&t.versionInfoCollectionEnabled?Ls.enabled:Ls.disabled,o=t!=null&&t.featureInfoCollectionEnabled?Os.enabled:Os.disabled;let a;return t!=null&&t.versionInfoCollectionEnabled||(a=t!=null&&t.featureInfoCollectionEnabled?"Note: Feature usage collection is enabled, but for it to be active you must also enable version info collection":"When you enable feature usage collection you must also enable version info collection"),e.jsx(Q,{header:e.jsx(X,{title:"Instance Privacy"}),children:e.jsxs(bl,{children:[e.jsx(Bs,{title:Gt.title,infoText:Gt.infoText,concreteDetails:Gt.concreteDetails,enabled:t==null?void 0:t.versionInfoCollectionEnabled,changeInfoText:n.changeInfoText,variablesText:n.environmentVariables}),e.jsx(Bs,{title:qt.title,infoText:qt.infoText,concreteDetails:qt.concreteDetails,enabled:(t==null?void 0:t.featureInfoCollectionEnabled)&&(t==null?void 0:t.versionInfoCollectionEnabled),changeInfoText:o.changeInfoText,variablesText:o.environmentVariables,dependsOnText:a})]})})},vl=()=>e.jsx(K,{severity:"warning",children:e.jsxs("p",{children:[e.jsx("b",{children:"Heads up!"})," If you enable maintenance mode, edit access in the entire system will be disabled for all the users (admins, editors, custom roles, etc). During this time nobody will be able to do changes or to make new configurations."]})}),Cl=()=>{const{data:t,error:s,mutate:n}=Le(ie("api/admin/maintenance"),wl);return h.useMemo(()=>({enabled:!!(t!=null&&t.enabled),loading:!s&&!t,refetchMaintenance:n,error:s}),[t,s,n])},wl=t=>fetch(t).then(je("Maintenance")).then(s=>s.json()),Tl=()=>{const{makeRequest:t,createRequest:s,errors:n,loading:o}=fe({propagateErrors:!0});return{toggleMaintenance:async i=>{const l=s("api/admin/maintenance",{method:"POST",body:JSON.stringify(i)});await t(l.caller,l.id)},errors:n,loading:o}},kl=m("div")(({theme:t})=>({display:"flex",flexDirection:"column",padding:t.spacing(3),border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadiusLarge})),Rl=m(q)({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}),El=m(q)(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(2)})),Al=m(B)(({theme:t})=>({fontSize:t.fontSizes.smallBody})),Dl=()=>{const{enabled:t,refetchMaintenance:s}=Cl(),{refetch:n}=N(),{toggleMaintenance:o}=Tl(),{trackEvent:a}=is(),{setToastData:i}=J(),r=async()=>{i({type:"success",title:`Maintenance mode has been successfully ${t?"disabled":"enabled"}`}),a("maintenance",{props:{eventType:`maintenance ${t?"de":""}activated`}}),await o({enabled:!t}),s(),n()};return e.jsxs(kl,{children:[e.jsxs(Rl,{children:[e.jsx("b",{children:"Maintenance Mode"}),e.jsx(ce,{sx:{margin:0},control:e.jsx(me,{onChange:r,value:t,name:"enabled",checked:t}),label:e.jsx(Al,{children:t?"Enabled":"Disabled"})})]}),e.jsx(El,{children:"Maintenance Mode is useful when you want to freeze your system so nobody can do any changes during this time. When enabled it will show a banner at the top of the applications and only an admin can enable it or disable it."})]})},Il=()=>e.jsx("div",{children:e.jsx(ge,{permissions:M,children:e.jsx(Bl,{})})}),Pl=m(q)(({theme:t})=>({display:"grid",gap:t.spacing(4)})),Bl=()=>{const{loading:t}=N();return t?null:e.jsx(Q,{header:e.jsx(X,{title:"Maintenance"}),children:e.jsxs(Pl,{children:[e.jsx(vl,{}),e.jsx(Dl,{})]})})},Ll=m(Uo)(({theme:t})=>({display:"flex",justifyContent:"center",alignItems:"center",width:"100%",height:"100%",textDecoration:"none",color:"inherit",padding:t.spacing(0,5),"&.active":{fontWeight:"bold"}})),$n=({to:t,children:s})=>e.jsx(Ll,{to:t,children:s}),Ol=h.lazy(()=>xn(()=>import("./NetworkOverview-d20eBsIq.js").then(t=>t.N),__vite__mapDeps([]))),Ul=h.lazy(()=>xn(()=>import("./NetworkTraffic-_52gjNiG.js"),__vite__mapDeps([]))),$l=[{label:"Overview",path:"/admin/network"},{label:"Traffic",path:"/admin/network/traffic"}],Nl=()=>{const{pathname:t}=rs();return e.jsx("div",{children:e.jsx(Q,{withTabs:!0,header:e.jsx(St,{value:t,indicatorColor:"primary",textColor:"primary",variant:"scrollable",allowScrollButtonsMobile:!0,children:$l.map(({label:s,path:n})=>e.jsx(vt,{value:n,label:e.jsx($n,{to:n,children:e.jsx("span",{children:s})}),sx:{padding:0}},s))}),children:e.jsxs(lt,{children:[e.jsx(G,{path:"traffic",element:e.jsx(Ul,{})}),e.jsx(G,{path:"*",element:e.jsx(Ol,{})})]})})})},Fl=m(q)(()=>({display:"flex",justifyContent:"center"})),Gl=({role:t,onEdit:s,onDelete:n})=>{const o=Ne.includes(t.type);return e.jsxs(Fl,{children:[e.jsx(ue,{"data-loading":!0,onClick:s,permission:M,disabled:o,tooltipProps:{title:o?"You cannot edit a predefined role":"Edit role"},children:e.jsx(Ve,{})}),e.jsx(ue,{"data-loading":!0,onClick:n,permission:M,disabled:o,tooltipProps:{title:o?"You cannot remove a predefined role":"Remove role"},children:e.jsx(Ae,{})})]})},ql=m(ze)(({theme:t})=>({marginLeft:t.spacing(1)})),_l=({role:t})=>e.jsx(Se,{value:t.name,subtitle:t.description,afterTitle:e.jsx(S,{condition:Ne.includes(t.type),show:e.jsx(ql,{color:"success",children:"Predefined"})})}),Wl=({users:t})=>{const[s]=h.useState(()=>({sortBy:[{id:"last-login",desc:!0}]})),n=h.useMemo(()=>[{id:"name",Header:"Name",accessor:r=>r.name||"",minWidth:200,Cell:({row:{original:r}})=>e.jsx(Se,{value:r.name,subtitle:r.email||r.username})},{Header:"Created",accessor:"createdAt",Cell:xe,width:120,maxWidth:120},{id:"last-login",Header:"Last login",accessor:r=>r.seenAt||"",Cell:({row:{original:r}})=>e.jsx(Je,{value:r.seenAt,emptyText:"Never",title:l=>`Last login: ${l}`}),maxWidth:150}],[]),{headerGroups:o,rows:a,prepareRow:i}=U.useTable({columns:n,data:t,initialState:s,sortTypes:pe,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},U.useSortBy,U.useFlexLayout);return e.jsx(ye,{rows:a,headerGroups:o,prepareRow:i})},Hl=m(B)(({theme:t})=>({fontSize:t.fontSizes.smallerBody})),Nn=({serviceAccount:t,value:s,onCreateToken:n})=>{var a,i,r;const{searchQuery:o}=$o();return!t.tokens||t.tokens.length===0?n?e.jsx(gn,{title:"Create token",onClick:n}):e.jsx(te,{children:"0 tokens"}):e.jsx(te,{children:e.jsx(as,{tooltip:e.jsx(e.Fragment,{children:(a=t.tokens)==null?void 0:a.map(({id:l,description:c})=>e.jsx(Hl,{children:e.jsx(No,{search:o,children:c})},l))}),highlighted:o.length>0&&s.toLowerCase().includes(o.toLowerCase()),children:((i=t.tokens)==null?void 0:i.length)===1?"1 token":`${(r=t.tokens)==null?void 0:r.length} tokens`})})},Ml=({serviceAccounts:t})=>{const[s]=h.useState(()=>({sortBy:[{id:"seenAt",desc:!0}]})),n=h.useMemo(()=>[{id:"name",Header:"Name",accessor:r=>r.name||"",minWidth:200,Cell:({row:{original:r}})=>e.jsx(Se,{value:r.name,subtitle:r.username})},{id:"tokens",Header:"Tokens",accessor:r=>{var l;return((l=r.tokens)==null?void 0:l.map(({description:c})=>c).join(`
16
16
  `))||""},Cell:({row:{original:r},value:l})=>e.jsx(Nn,{serviceAccount:r,value:l}),maxWidth:100},{Header:"Created",accessor:"createdAt",Cell:xe,width:120,maxWidth:120},{id:"seenAt",Header:"Last seen",accessor:r=>{var l;return(l=r.tokens.sort((c,d)=>{const u=new Date(c.seenAt||0),p=new Date(d.seenAt||0);return(p==null?void 0:p.getTime())-(u==null?void 0:u.getTime())})[0])==null?void 0:l.seenAt},Cell:Je,maxWidth:150}],[]),{headerGroups:o,rows:a,prepareRow:i}=U.useTable({columns:n,data:t,initialState:s,sortTypes:pe,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},U.useSortBy,U.useFlexLayout);return e.jsx(ye,{rows:a,headerGroups:o,prepareRow:i})},zl=({groups:t})=>{const[s]=h.useState(()=>({sortBy:[{id:"createdAt",desc:!0}]})),n=h.useMemo(()=>[{id:"name",Header:"Name",accessor:r=>r.name||"",minWidth:200,Cell:({row:{original:r}})=>e.jsx(Se,{value:r.name,subtitle:r.description})},{Header:"Created",accessor:"createdAt",Cell:xe,width:120,maxWidth:120},{id:"users",Header:"Users",accessor:r=>r.users.length===1?"1 user":`${r.users.length} users`,Cell:te,maxWidth:150}],[]),{headerGroups:o,rows:a,prepareRow:i}=U.useTable({columns:n,data:t,initialState:s,sortTypes:pe,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},U.useSortBy,U.useFlexLayout);return e.jsx(ye,{rows:a,headerGroups:o,prepareRow:i})},_t=m("div")(({theme:t})=>({marginTop:t.spacing(1.5)})),Wt=m("p")(({theme:t})=>({marginTop:t.spacing(3)})),Vl=({role:t,open:s,setOpen:n,onConfirm:o})=>{const{users:a}=we(),{serviceAccounts:i}=ct(),{groups:r}=Fe(),l=a.filter(({rootRole:p})=>p===(t==null?void 0:t.id)),c=i.filter(({rootRole:p})=>p===(t==null?void 0:t.id)),d=r==null?void 0:r.filter(({rootRole:p})=>p===(t==null?void 0:t.id)),u=!!(l.length||c.length||d!=null&&d.length);return e.jsx(se,{title:"Delete root role?",open:s,primaryButtonText:"Delete role",secondaryButtonText:"Cancel",disabledPrimaryButton:u,onClick:()=>o(t),onClose:()=>{n(!1)},children:e.jsx(S,{condition:u,show:e.jsxs(e.Fragment,{children:[e.jsx(K,{severity:"error",children:"You are not allowed to delete a role that is currently in use. Please change the role of the following entities first:"}),e.jsx(S,{condition:!!l.length,show:e.jsxs(e.Fragment,{children:[e.jsxs(Wt,{children:["Users (",l.length,"):"]}),e.jsx(_t,{children:e.jsx(Wl,{users:l})})]})}),e.jsx(S,{condition:!!c.length,show:e.jsxs(e.Fragment,{children:[e.jsxs(Wt,{children:["Service accounts (",c.length,"):"]}),e.jsx(_t,{children:e.jsx(Ml,{serviceAccounts:c})})]})}),e.jsx(S,{condition:!!(d!=null&&d.length),show:e.jsxs(e.Fragment,{children:[e.jsxs(Wt,{children:["Groups (",d==null?void 0:d.length,"):"]}),e.jsx(_t,{children:e.jsx(zl,{groups:d})})]})})]}),elseShow:e.jsxs("p",{children:["You are about to delete role:"," ",e.jsx("strong",{children:t==null?void 0:t.name})]})})})},Yl=t=>{const{isEnterprise:s}=N(),{data:n,error:o,mutate:a}=Zt(s()&&t,{projects:[]},ie(`api/admin/projects/roles/${t}/access`),Jl);return h.useMemo(()=>({projects:(n==null?void 0:n.projects)??[],loading:!o&&!n,refetch:()=>a(),error:o}),[n,o,a])},Jl=t=>fetch(t).then(je("Project role usage")).then(s=>s.json()),Kl=({projects:t})=>{const[s]=h.useState(()=>({sortBy:[{id:"name"}]})),n=h.useMemo(()=>[{id:"name",Header:"Project name",accessor:r=>r.project||"",minWidth:200,Cell:({row:{original:r}})=>e.jsx(gn,{title:r.project,to:`/projects/${r.project}`})},{id:"users",Header:"Assigned users",accessor:r=>r.userCount===1?"1 user":`${r.userCount} users`,Cell:te,maxWidth:150},{id:"serviceAccounts",Header:"Service accounts",accessor:r=>r.serviceAccountCount===1?"1 account":`${r.serviceAccountCount} accounts`,Cell:te,maxWidth:150},{id:"groups",Header:"Assigned groups",accessor:r=>r.groupCount===1?"1 group":`${r.groupCount} groups`,Cell:te,maxWidth:150}],[]),{headerGroups:o,rows:a,prepareRow:i}=U.useTable({columns:n,data:t,initialState:s,sortTypes:pe,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},U.useSortBy,U.useFlexLayout);return e.jsx(ye,{rows:a,headerGroups:o,prepareRow:i})},Zl=m("div")(({theme:t})=>({marginTop:t.spacing(1.5)})),Ql=m("p")(({theme:t})=>({marginTop:t.spacing(3)})),Xl=({role:t,open:s,setOpen:n,onConfirm:o})=>{const{projects:a}=Yl(t==null?void 0:t.id),i=!!(a!=null&&a.length);return e.jsx(se,{title:"Delete project role?",open:s,primaryButtonText:"Delete role",secondaryButtonText:"Cancel",disabledPrimaryButton:i,onClick:()=>o(t),onClose:()=>{n(!1)},maxWidth:"md",children:e.jsx(S,{condition:i,show:e.jsxs(e.Fragment,{children:[e.jsx(K,{severity:"error",children:"You are not allowed to delete a role that is currently in use. Please change the role of the following entities first:"}),e.jsx(S,{condition:!!(a!=null&&a.length),show:e.jsxs(e.Fragment,{children:[e.jsxs(Ql,{children:["Role assigned in ",a==null?void 0:a.length," ","projects:"]}),e.jsx(Zl,{children:e.jsx(Kl,{projects:a})})]})})]}),elseShow:e.jsxs("p",{children:["You are about to delete role:"," ",e.jsx("strong",{children:t==null?void 0:t.name})]})})})},ec="custom",tc=({role:t,open:s,setOpen:n,onConfirm:o})=>(t==null?void 0:t.type)===ec?e.jsx(Xl,{role:t,open:s,setOpen:n,onConfirm:o}):e.jsx(Vl,{role:t,open:s,setOpen:n,onConfirm:o}),Fn=()=>{const{loading:t,makeRequest:s,createRequest:n,errors:o}=fe({propagateErrors:!0});return{addRole:async c=>{const u=n("api/admin/roles",{method:"POST",body:JSON.stringify(c)},"addRole");return(await s(u.caller,u.id)).json()},updateRole:async(c,d)=>{const p=n(`api/admin/roles/${c}`,{method:"PUT",body:JSON.stringify(d)},"updateRole");await s(p.caller,p.id)},removeRole:async c=>{const u=n(`api/admin/roles/${c}`,{method:"DELETE"},"removeRole");await s(u.caller,u.id)},validateRole:async c=>{const u=n("api/admin/roles/validate",{method:"POST",body:JSON.stringify(c)},"validateRole");await s(u.caller,u.id)},errors:o,loading:t}},Us={name:void 0,description:void 0,permissions:void 0},sc=(t="",s="",n=[])=>{const{roles:o,projectRoles:a}=dt(),[i,r]=h.useState(t),[l,c]=h.useState(s),[d,u]=h.useState({}),[p,x]=h.useState(Us),[g,j]=h.useState(!1);h.useEffect(()=>{r(t)},[t]),h.useEffect(()=>{c(s)},[s]),h.useEffect(()=>{const b=ys(n);u(b)},[n.length]);const y=(b=Ie)=>({name:i,description:l,type:b===Ie?"root-custom":"custom",permissions:Object.values(d).map(({name:D,environment:W})=>({name:D,environment:W}))}),w=b=>![...o,...a].some(D=>D.name!==t&&D.name.toLowerCase()===b.toLowerCase()),C=b=>b.length,k=b=>Object.keys(b).length>0,A=b=>{x(D=>({...D,[b]:void 0}))},T=(b,D)=>{x(W=>({...W,[b]:D}))},L=b=>C(b)?w(b)?(A("name"),!0):(T("name","Name must be unique."),!1):(T("name","Name is required."),!1),P=b=>C(b)?(A("description"),!0):(T("description","Description is required."),!1),I=b=>k(b)?(A("permissions"),!0):(T("permissions","You must select at least one permission."),!1),v=()=>{const b=L(i),D=P(l),W=I(d);return j(!0),b&&D&&W},F=g&&Object.values(p).some(Boolean);return{name:i,setName:r,validateName:L,description:l,setDescription:c,validateDescription:P,checkedPermissions:d,setCheckedPermissions:u,validatePermissions:I,getRolePayload:y,errors:p,showErrors:F,validate:v,reload:()=>{r(t),c(s),u(ys(n)),j(!1),x(Us)}}},nc=m(q)(({theme:t})=>({display:"flex",alignItems:"center",[t.breakpoints.down(500)]:{flexDirection:"column",alignItems:"flex-start"}})),oc=m(Fo)(({theme:t})=>({fontWeight:t.typography.fontWeightBold,marginRight:t.spacing(1)})),ac=({title:t,permissions:s,checkedPermissions:n,Icon:o,isInitiallyExpanded:a=!1,context:i,onPermissionChange:r,onCheckAll:l})=>{const[c,d]=h.useState(a),u=h.useMemo(()=>(s==null?void 0:s.reduce((g,j)=>(g[pt(j)]=!0,g),{}))||{},[s]),p=h.useMemo(()=>Object.keys(n).filter(g=>u[g]).length||0,[n,u]),x=h.useMemo(()=>p===(s==null?void 0:s.length),[p,s]);return e.jsx(q,{sx:{my:2,pb:1},children:e.jsxs(Go,{expanded:c,onChange:()=>d(!c),sx:{boxShadow:"none",px:3,py:1,border:g=>`1px solid ${g.palette.divider}`,borderRadius:g=>`${g.shape.borderRadiusLarge}px`},children:[e.jsx(qo,{expandIcon:e.jsx(Ge,{children:e.jsx(_o,{titleAccess:"Toggle"})}),sx:{boxShadow:"none",padding:"0"},children:e.jsxs(nc,{children:[o,e.jsx(oc,{text:t,maxWidth:"120",maxLength:25})," ",e.jsxs(B,{variant:"body2",color:"text.secondary",children:["(",p," / ",s==null?void 0:s.length," ","permissions)"]})]})}),e.jsxs(Wo,{sx:{px:0,py:1,flexWrap:"wrap"},children:[e.jsx(Qt,{sx:{mb:1}}),e.jsxs(_,{variant:"text",size:"small",onClick:l,sx:{fontWeight:g=>g.typography.fontWeightRegular},children:[x?"Unselect ":"Select ","all ",i," permissions"]}),e.jsx(q,{display:"grid",gridTemplateColumns:{sm:"1fr 1fr",xs:"1fr"},children:s==null?void 0:s.map(g=>e.jsx(ce,{"data-testid":pt(g),control:e.jsx(es,{checked:!!n[pt(g)],onChange:()=>r(g),color:"primary"}),label:g.displayName},pt(g)))})]})]})})},ic=({type:t,checkedPermissions:s,setCheckedPermissions:n,validatePermissions:o})=>{const{permissions:a}=Ho({revalidateIfStale:!1,revalidateOnReconnect:!1,revalidateOnFocus:!1}),i=Xs.includes(t),r=h.useMemo(()=>i?Mo(zo(a.project,a.environments)):Vo(a.root),[a,i]),l=d=>{const u=Qo(s,d);o(u),n(u)},c=d=>{const u=Xo(s,d);o(u),n(u)};return h.useMemo(()=>e.jsx(e.Fragment,{children:r.map(({label:d,type:u,permissions:p})=>e.jsx(ac,{title:`${d} permissions`,context:d.toLowerCase(),Icon:u===Yo?e.jsx(Va,{color:"disabled",sx:{mr:1}}):u===Jo?e.jsx(Ko,{color:"disabled",sx:{mr:1}}):e.jsx(Zo,{color:"disabled",sx:{mr:1}}),permissions:p,checkedPermissions:s,onPermissionChange:x=>l(x),onCheckAll:()=>c(p)},d))}),[r,s])},Ht=m("p")(({theme:t})=>({display:"flex",color:t.palette.text.primary,marginBottom:t.spacing(1),"&:not(:first-of-type)":{marginTop:t.spacing(4)}})),rc=m(_e)(({theme:t})=>({width:"100%",maxWidth:t.spacing(50)})),lc=m(_e)({width:"100%"}),cc=({type:t=Ie,name:s,setName:n,description:o,setDescription:a,checkedPermissions:i,setCheckedPermissions:r,errors:l,showErrors:c,validateName:d,validateDescription:u,validatePermissions:p})=>{const x=g=>{setTimeout(()=>g(),300)};return e.jsxs("div",{children:[e.jsx(Ht,{children:"What is your new role name?"}),e.jsx(rc,{autoFocus:!0,label:"Role name *",error:!!l.name,errorText:l.name,value:s,onChange:g=>{d(g.target.value),n(g.target.value)},onBlur:g=>x(()=>d(g.target.value)),autoComplete:"off"}),e.jsx(Ht,{children:"What is your new role description?"}),e.jsx(lc,{label:"Role description *",error:!!l.description,errorText:l.description,value:o,onChange:g=>{u(g.target.value),a(g.target.value)},onBlur:g=>x(()=>u(g.target.value)),autoComplete:"off"}),e.jsx(Ht,{children:"What is your role allowed to do?"}),e.jsx(K,{severity:"info",children:"You must select at least one permission."}),e.jsx(ic,{type:t,checkedPermissions:i,setCheckedPermissions:r,validatePermissions:p}),e.jsx(S,{condition:c,show:()=>e.jsx(K,{severity:"error",icon:!1,children:e.jsx("ul",{children:Object.values(l).filter(Boolean).map(g=>e.jsx("li",{children:g},g))})})})]})},dc=m("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),uc=m("div")(({theme:t})=>({marginTop:"auto",display:"flex",justifyContent:"flex-end",paddingTop:t.spacing(4)})),hc=m(_)(({theme:t})=>({marginLeft:t.spacing(3)})),pc=({type:t=Ie,roleId:s,open:n,setOpen:o})=>{const{role:a,refetch:i}=jn(s==null?void 0:s.toString()),{name:r,setName:l,validateName:c,description:d,setDescription:u,validateDescription:p,checkedPermissions:x,setCheckedPermissions:g,validatePermissions:j,getRolePayload:y,errors:w,showErrors:C,validate:k,reload:A}=sc(a==null?void 0:a.name,a==null?void 0:a.description,a==null?void 0:a.permissions),{refetch:T}=dt(),{addRole:L,updateRole:P,loading:I}=Fn(),{setToastData:v,setToastApiError:F}=J(),{uiConfig:R}=N(),b=a!==void 0,D=y(t),W=()=>`curl --location --request ${b?"PUT":"POST"} '${R.unleashUrl}/api/admin/roles${b?`/${a.id}`:""}' \\
17
17
  --header 'Authorization: INSERT_API_KEY' \\
18
18
  --header 'Content-Type: application/json' \\