unleash-server 5.4.0 → 5.4.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 (34) hide show
  1. package/dist/lib/addons/slack-app-definition.js +1 -0
  2. package/dist/lib/addons/slack-app-definition.js.map +1 -1
  3. package/dist/lib/routes/admin-api/feature-type.js +2 -7
  4. package/dist/lib/routes/admin-api/feature-type.js.map +1 -1
  5. package/dist/lib/types/experimental.d.ts +1 -1
  6. package/dist/lib/types/experimental.js +0 -1
  7. package/dist/lib/types/experimental.js.map +1 -1
  8. package/dist/server-dev.js +0 -1
  9. package/dist/server-dev.js.map +1 -1
  10. package/dist/test/e2e/api/admin/feature-type.test.js +0 -1
  11. package/dist/test/e2e/api/admin/feature-type.test.js.map +1 -1
  12. package/frontend/build/index.html +1 -1
  13. package/frontend/build/static/{AdvancedPlayground-2d715a2c.js → AdvancedPlayground-1748fcdd.js} +1 -1
  14. package/frontend/build/static/{CreateProject-5b1090c2.js → CreateProject-972fa820.js} +1 -1
  15. package/frontend/build/static/{Error-e44ea66b.js → Error-cbce6b64.js} +1 -1
  16. package/frontend/build/static/{FeatureArchiveDialog-b47b18e8.js → FeatureArchiveDialog-8a281845.js} +1 -1
  17. package/frontend/build/static/{FeatureMetricsChart-36caeeb7.js → FeatureMetricsChart-8fd8a304.js} +1 -1
  18. package/frontend/build/static/{FeatureViewLazyExport-49d56afd.js → FeatureViewLazyExport-a215d53b.js} +2 -2
  19. package/frontend/build/static/{LazyAdminExport-87c9ab51.js → LazyAdminExport-ba7d55ca.js} +13 -13
  20. package/frontend/build/static/{LazyProjectExport-c4634b2a.js → LazyProjectExport-12bccd40.js} +1 -1
  21. package/frontend/build/static/{NetworkOverview-c762698b.js → NetworkOverview-349a7bdd.js} +2 -2
  22. package/frontend/build/static/{NetworkTraffic-c8d9eb9b.js → NetworkTraffic-60478e50.js} +1 -1
  23. package/frontend/build/static/{RoleCell-d1aa8288.js → RoleCell-144e7eca.js} +1 -1
  24. package/frontend/build/static/{StrategyItemContainer-c7c352a4.js → StrategyItemContainer-a4caeace.js} +1 -1
  25. package/frontend/build/static/{chartjs-adapter-date-fns.esm-9c67372b.js → chartjs-adapter-date-fns.esm-03d2fbea.js} +1 -1
  26. package/frontend/build/static/{flowchart-elk-definition-170a3958-5ea9fc56.js → flowchart-elk-definition-170a3958-fc100c77.js} +1 -1
  27. package/frontend/build/static/{index-b7003840.js → index-17d74ac9.js} +84 -84
  28. package/frontend/build/static/{index-1aaa8c27.js → index-3c63138f.js} +1 -1
  29. package/frontend/build/static/{index-670c9345.js → index-866f9bf9.js} +1 -1
  30. package/frontend/build/static/{is_dark-b445e102.js → is_dark-31c253e9.js} +1 -1
  31. package/frontend/build/static/{mindmap-definition-44684416-254e936e.js → mindmap-definition-44684416-398682f9.js} +1 -1
  32. package/frontend/build/static/{timeline-definition-8e5a9bc6-24fd1725.js → timeline-definition-8e5a9bc6-04a0ae08.js} +1 -1
  33. package/frontend/build/static/{unknownify-ea4585e8.js → unknownify-b8618d88.js} +1 -1
  34. package/package.json +1 -1
@@ -1,35 +1,35 @@
1
- import{s as g,r as p,cv as Wo,cw as zo,cx as Fo,j as e,cy as _n,cz as ln,cA as Dt,cB as qo,cC as Vo,cD as Yo,cE as Jo,c as ht,cF as Hn,cG as Ko,cH as Ne,cI as jt,aN as oe,aM as we,aO as ue,cJ as Wn,cK as Te,cL as cn,cM as dn,cN as Me,aq as ee,ar as ne,d as r,y as B,al as pe,cO as zn,cP as Fn,cQ as Zo,cR as Xo,cS as pt,cT as Qo,q as ea,cU as ta,f as Z,X as G,au as ye,bT as qn,ax as Pe,az as Vn,cV as Ht,h as K,aC as De,bv as b,cW as me,cX as Se,F as mt,I as Yn,S as Jn,M as Re,l as Q,u as $e,cY as ze,E as J,i as z,b6 as ie,T as D,aJ as de,B as N,C,cu as gt,cm as ft,cZ as yt,c_ as na,D as Wt,c$ as Kn,e as Zn,d0 as oa,d1 as Ge,x as Fe,d2 as aa,a1 as $,a2 as be,a9 as te,a3 as ra,a4 as ia,a5 as zt,a6 as Xe,a7 as sa,am as ge,d3 as ve,t as He,d4 as la,aP as Xn,d5 as Qn,d6 as Y,bF as eo,d7 as ca,d8 as to,d9 as no,da as ce,bG as oo,db as da,ce as un,dc as ao,$ as ro,dd as We,a$ as Le,bt as ua,de as ha,b3 as It,aK as Qe,b5 as Pt,df as Ue,dg as pa,dh as ma,bM as bt,A as ga,di as fa,dj as Bt,m as io,n as ya,o as ba,aa as fe,cb as Oe,ab as Ce,ac as et,ad as xe,dk as Sa,bW as Ft,dl as so,ah as lo,dm as qt,bR as St,dn as va,an as qe,dp as tt,L as Ca,dq as wa,dr as Ta,bS as hn,ds as xa,dt as Ea,aD as Vt,du as Yt,v as co,af as ka,b as Jt,dv as Ve,dw as Ra,ak as nt,aH as Ae,dx as Aa,dy as Da,dz as Ia,dA as Pa,bU as ot,bV as H,dB as Ba,by as Kt,ag as Zt,dC as La,cd as uo,co as Xt,dD as je,dE as Ua,aj as ho,dF as Oa,dG as $a,dH as po,dI as pn,dJ as Ie,N as Na,dK as it,bz as Ga,bA as Ma,bE as ja,bB as _a,dL as Ha,dM as Wa,dN as za,dO as Fa,dP as qa,dQ as Va,bY as Ya,dR as Ja,dS as Ka,dT as Za,dU as mo,dV as Xa,a8 as Qa,dW as Lt,dX as er,dY as go,dZ as ut,d_ as fo,d$ as tr,e0 as nr,bL as Qt,e1 as or,e2 as mn,e3 as ar,e4 as rr,e5 as ir,e6 as sr,e7 as lr,e8 as cr,c9 as dr,bs as ur,e9 as yo,ea as hr,eb as pr,ec as mr,ed as gr,ee as gn,ai as bo,b4 as fr,bH as Ut,ef as yr,eg as So,eh as vo,ei as br,ej as Sr}from"./index-b7003840.js";import{u as vr,C as Cr,A as wr,a as Tr,R as xr,S as Er,T as kr,b as Rr,c as Ar,d as Dr,e as Ir,E as Pr,f as Br,m as Lr,g as vt,h as en,B as Ur,i as Or,j as Co}from"./RoleCell-d1aa8288.js";import{a as $r}from"./index-670c9345.js";import{a as Nr}from"./index-1aaa8c27.js";const Gr=["component","direction","spacing","divider","children"];function Mr(t,n){const o=p.Children.toArray(t).filter(Boolean);return o.reduce((a,i,s)=>(a.push(i),s<o.length-1&&a.push(p.cloneElement(n,{key:`separator-${s}`})),a),[])}const jr=t=>({row:"Left","row-reverse":"Right",column:"Top","column-reverse":"Bottom"})[t],_r=({ownerState:t,theme:n})=>{let o=_n({display:"flex",flexDirection:"column"},ln({theme:n},Dt({values:t.direction,breakpoints:n.breakpoints.values}),a=>({flexDirection:a})));if(t.spacing){const a=qo(n),i=Object.keys(n.breakpoints.values).reduce((u,c)=>((typeof t.spacing=="object"&&t.spacing[c]!=null||typeof t.direction=="object"&&t.direction[c]!=null)&&(u[c]=!0),u),{}),s=Dt({values:t.direction,base:i}),l=Dt({values:t.spacing,base:i});typeof s=="object"&&Object.keys(s).forEach((u,c,h)=>{if(!s[u]){const S=c>0?s[h[c-1]]:"column";s[u]=S}}),o=Vo(o,ln({theme:n},l,(u,c)=>({"& > :not(style) + :not(style)":{margin:0,[`margin${jr(c?s[c]:t.direction)}`]:Jo(a,u)}})))}return o=Yo(n.breakpoints,o),o},Hr=g("div",{name:"MuiStack",slot:"Root",overridesResolver:(t,n)=>[n.root]})(_r),Wr=p.forwardRef(function(n,o){const a=Wo({props:n,name:"MuiStack"}),i=zo(a),{component:s="div",direction:l="column",spacing:d=0,divider:u,children:c}=i,h=Fo(i,Gr);return e(Hr,_n({as:s,ownerState:{direction:l,spacing:d},ref:o},h,{children:u?Mr(c,u):c}))}),zr=Wr,Fr=ht(e("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"),qr=ht(e("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"),Vr=ht(e("path",{d:"M11.99 2c-5.52 0-10 4.48-10 10s4.48 10 10 10 10-4.48 10-10-4.48-10-10-10zm3.61 6.34c1.07 0 1.93.86 1.93 1.93 0 1.07-.86 1.93-1.93 1.93-1.07 0-1.93-.86-1.93-1.93-.01-1.07.86-1.93 1.93-1.93zm-6-1.58c1.3 0 2.36 1.06 2.36 2.36 0 1.3-1.06 2.36-2.36 2.36s-2.36-1.06-2.36-2.36c0-1.31 1.05-2.36 2.36-2.36zm0 9.13v3.75c-2.4-.75-4.3-2.6-5.14-4.96 1.05-1.12 3.67-1.69 5.14-1.69.53 0 1.2.08 1.9.22-1.64.87-1.9 2.02-1.9 2.68zM11.99 20c-.27 0-.53-.01-.79-.04v-4.07c0-1.42 2.94-2.13 4.4-2.13 1.07 0 2.92.39 3.84 1.15-1.17 2.97-4.06 5.09-7.45 5.09z"}),"SupervisedUserCircle"),Yr=ht(e("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");function dt(t,n){if(Hn(2,arguments),!n||Ko(n)!=="object")return new Date(NaN);var o=n.years?Ne(n.years):0,a=n.months?Ne(n.months):0,i=n.weeks?Ne(n.weeks):0,s=n.days?Ne(n.days):0,l=n.hours?Ne(n.hours):0,d=n.minutes?Ne(n.minutes):0,u=n.seconds?Ne(n.seconds):0,c=jt(t),h=a||o?Nr(c,a+o*12):c,m=s||i?$r(h,s+i*7):h,S=d+l*60,f=u+S*60,y=f*1e3,v=new Date(m.getTime()+y);return v}function fn(t,n){Hn(2,arguments);var o=jt(t),a=jt(n);return o.getTime()>a.getTime()}const tn=(t={})=>{const n=oe("api/admin/api-tokens"),{data:o,error:a,mutate:i}=we(n,Jr,t),s=p.useMemo(()=>o??[],[o]),l=p.useCallback(()=>{i().catch(console.warn)},[i]);return{tokens:s,error:a,loading:!a&&!o,refetch:l}},Jr=async t=>(await(await fetch(t).then(ue("Api tokens"))).json()).tokens,Kr=()=>{const{tokens:t,loading:n,refetch:o}=tn(),{deleteToken:a}=Wn(),{getTableProps:i,getTableBodyProps:s,headerGroups:l,rows:d,prepareRow:u,state:{globalFilter:c},setGlobalFilter:h,setHiddenColumns:m,columns:S}=vr(t,f=>{const y=f.row.original.type==="client"?cn:f.row.original.type==="frontend"?dn:Me,v=f.row.original.type==="client"?Zo:f.row.original.type==="frontend"?Xo:Me;return r(pt,{children:[e(Tr,{token:f.row.original,permission:y}),e(xr,{token:f.row.original,permission:v,onRemove:async()=>{await a(f.row.original.secret),o()}})]})});return e(Te,{permissions:[cn,dn,Me],children:e(ee,{header:e(ne,{title:`API access (${d.length})`,actions:r(B,{children:[e(pe,{initialValue:c,onChange:h}),e(ne.Divider,{}),e(Cr,{permission:[zn,Fn,Me],path:"/admin/api/create-token"})]})}),children:e(wr,{loading:n,headerGroups:l,setHiddenColumns:m,prepareRow:u,getTableBodyProps:s,getTableProps:i,rows:d,columns:S,globalFilter:c})})})},Zr=({type:t,projects:n,setProjects:o,errors:a,clearErrors:i})=>{const s=Qo("projectId"),{projects:l}=ea(),d=l.map(u=>({value:u.id,label:u.name}));return s?null:r(B,{children:[e(Er,{children:"Which project do you want to give access to?"}),e(ta,{disabled:t===kr.ADMIN,options:d,defaultValue:n,onChange:o,error:a==null?void 0:a.projects,onFocus:()=>i("projects")})]})},yn="Create API token",Xr=({modal:t=!1})=>{const{setToastApiError:n}=Z(),{uiConfig:o}=G(),a=ye(),[i,s]=p.useState(!1),[l,d]=p.useState(""),{getApiTokenPayload:u,username:c,type:h,projects:m,environment:S,setUsername:f,setTokenType:y,setProjects:v,setEnvironment:T,isValid:w,errors:k,clearErrors:E,apiTokenTypes:x}=Rr(),{createToken:P,loading:M}=Wn(),{refetch:L}=tn();qn(yn);const I="api/admin/api-tokens";return r(Pe,{loading:M,title:yn,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:()=>`curl --location --request POST '${o.unleashUrl}/${I}' \\
1
+ import{s as g,r as p,cv as Ho,cw as zo,cx as Fo,j as e,cy as _n,cz as ln,cA as Dt,cB as qo,cC as Vo,cD as Yo,cE as Jo,c as ht,cF as Wn,cG as Ko,cH as Ne,cI as jt,aN as oe,aM as we,aO as ue,cJ as Hn,cK as Te,cL as cn,cM as dn,cN as Me,aq as ee,ar as ne,d as r,y as B,al as me,cO as zn,cP as Fn,cQ as Zo,cR as Xo,cS as pt,cT as Qo,q as ea,cU as ta,f as Z,X as G,au as be,bT as qn,ax as Pe,az as Vn,cV as Wt,h as K,aC as De,bv as b,cW as he,cX as ge,F as mt,I as Yn,S as Jn,M as Re,l as Q,u as $e,C,cY as ze,E as J,i as z,b6 as ie,T as D,aJ as de,B as N,cu as gt,cm as ft,cZ as yt,c_ as na,D as Ht,c$ as Kn,e as Zn,d0 as oa,d1 as Ge,x as Fe,d2 as aa,a1 as $,a2 as Se,a9 as te,a3 as ra,a4 as ia,a5 as zt,a6 as Xe,a7 as sa,am as fe,d3 as ve,t as We,d4 as la,aP as Xn,d5 as Qn,d6 as Y,bF as eo,d7 as ca,d8 as to,d9 as no,da as ce,bG as oo,db as da,ce as un,dc as ao,$ as ro,dd as He,a$ as Ue,bt as ua,de as ha,b3 as It,aK as Qe,b5 as Pt,df as Le,dg as pa,dh as ma,bM as bt,A as ga,di as fa,dj as Bt,m as io,n as ya,o as ba,aa as ye,cb as Oe,ab as Ce,ac as et,ad as xe,dk as Sa,bW as Ft,dl as so,ah as lo,dm as qt,bR as St,dn as va,an as qe,dp as tt,L as Ca,dq as wa,dr as Ta,bS as hn,ds as xa,dt as Ea,aD as Vt,du as Yt,v as co,af as ka,b as Jt,dv as Ve,dw as Ra,ak as nt,aH as Ae,dx as Aa,dy as Da,dz as Ia,dA as Pa,bU as ot,bV as W,dB as Ba,by as Kt,ag as Zt,dC as Ua,cd as uo,co as Xt,dD as je,dE as La,aj as ho,dF as Oa,dG as $a,dH as po,dI as pn,dJ as Ie,N as Na,dK as it,bz as Ga,bA as Ma,bE as ja,bB as _a,dL as Wa,dM as Ha,dN as za,dO as Fa,dP as qa,dQ as Va,bY as Ya,dR as Ja,dS as Ka,dT as Za,dU as mo,dV as Xa,a8 as Qa,dW as Ut,dX as er,dY as go,dZ as ut,d_ as fo,d$ as tr,e0 as nr,bL as Qt,e1 as or,e2 as mn,e3 as ar,e4 as rr,e5 as ir,e6 as sr,e7 as lr,e8 as cr,c9 as dr,bs as ur,e9 as yo,ea as hr,eb as pr,ec as mr,ed as gr,ee as gn,ai as bo,b4 as fr,bH as Lt,ef as yr,eg as So,eh as vo,ei as br,ej as Sr}from"./index-17d74ac9.js";import{u as vr,C as Cr,A as wr,a as Tr,R as xr,S as Er,T as kr,b as Rr,c as Ar,d as Dr,e as Ir,E as Pr,f as Br,m as Ur,g as vt,h as en,B as Lr,i as Or,j as Co}from"./RoleCell-144e7eca.js";import{a as $r}from"./index-866f9bf9.js";import{a as Nr}from"./index-3c63138f.js";const Gr=["component","direction","spacing","divider","children"];function Mr(t,n){const o=p.Children.toArray(t).filter(Boolean);return o.reduce((a,i,s)=>(a.push(i),s<o.length-1&&a.push(p.cloneElement(n,{key:`separator-${s}`})),a),[])}const jr=t=>({row:"Left","row-reverse":"Right",column:"Top","column-reverse":"Bottom"})[t],_r=({ownerState:t,theme:n})=>{let o=_n({display:"flex",flexDirection:"column"},ln({theme:n},Dt({values:t.direction,breakpoints:n.breakpoints.values}),a=>({flexDirection:a})));if(t.spacing){const a=qo(n),i=Object.keys(n.breakpoints.values).reduce((u,c)=>((typeof t.spacing=="object"&&t.spacing[c]!=null||typeof t.direction=="object"&&t.direction[c]!=null)&&(u[c]=!0),u),{}),s=Dt({values:t.direction,base:i}),l=Dt({values:t.spacing,base:i});typeof s=="object"&&Object.keys(s).forEach((u,c,h)=>{if(!s[u]){const S=c>0?s[h[c-1]]:"column";s[u]=S}}),o=Vo(o,ln({theme:n},l,(u,c)=>({"& > :not(style) + :not(style)":{margin:0,[`margin${jr(c?s[c]:t.direction)}`]:Jo(a,u)}})))}return o=Yo(n.breakpoints,o),o},Wr=g("div",{name:"MuiStack",slot:"Root",overridesResolver:(t,n)=>[n.root]})(_r),Hr=p.forwardRef(function(n,o){const a=Ho({props:n,name:"MuiStack"}),i=zo(a),{component:s="div",direction:l="column",spacing:d=0,divider:u,children:c}=i,h=Fo(i,Gr);return e(Wr,_n({as:s,ownerState:{direction:l,spacing:d},ref:o},h,{children:u?Mr(c,u):c}))}),zr=Hr,Fr=ht(e("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"),qr=ht(e("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"),Vr=ht(e("path",{d:"M11.99 2c-5.52 0-10 4.48-10 10s4.48 10 10 10 10-4.48 10-10-4.48-10-10-10zm3.61 6.34c1.07 0 1.93.86 1.93 1.93 0 1.07-.86 1.93-1.93 1.93-1.07 0-1.93-.86-1.93-1.93-.01-1.07.86-1.93 1.93-1.93zm-6-1.58c1.3 0 2.36 1.06 2.36 2.36 0 1.3-1.06 2.36-2.36 2.36s-2.36-1.06-2.36-2.36c0-1.31 1.05-2.36 2.36-2.36zm0 9.13v3.75c-2.4-.75-4.3-2.6-5.14-4.96 1.05-1.12 3.67-1.69 5.14-1.69.53 0 1.2.08 1.9.22-1.64.87-1.9 2.02-1.9 2.68zM11.99 20c-.27 0-.53-.01-.79-.04v-4.07c0-1.42 2.94-2.13 4.4-2.13 1.07 0 2.92.39 3.84 1.15-1.17 2.97-4.06 5.09-7.45 5.09z"}),"SupervisedUserCircle"),Yr=ht(e("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");function dt(t,n){if(Wn(2,arguments),!n||Ko(n)!=="object")return new Date(NaN);var o=n.years?Ne(n.years):0,a=n.months?Ne(n.months):0,i=n.weeks?Ne(n.weeks):0,s=n.days?Ne(n.days):0,l=n.hours?Ne(n.hours):0,d=n.minutes?Ne(n.minutes):0,u=n.seconds?Ne(n.seconds):0,c=jt(t),h=a||o?Nr(c,a+o*12):c,m=s||i?$r(h,s+i*7):h,S=d+l*60,f=u+S*60,y=f*1e3,v=new Date(m.getTime()+y);return v}function fn(t,n){Wn(2,arguments);var o=jt(t),a=jt(n);return o.getTime()>a.getTime()}const tn=(t={})=>{const n=oe("api/admin/api-tokens"),{data:o,error:a,mutate:i}=we(n,Jr,t),s=p.useMemo(()=>o??[],[o]),l=p.useCallback(()=>{i().catch(console.warn)},[i]);return{tokens:s,error:a,loading:!a&&!o,refetch:l}},Jr=async t=>(await(await fetch(t).then(ue("Api tokens"))).json()).tokens,Kr=()=>{const{tokens:t,loading:n,refetch:o}=tn(),{deleteToken:a}=Hn(),{getTableProps:i,getTableBodyProps:s,headerGroups:l,rows:d,prepareRow:u,state:{globalFilter:c},setGlobalFilter:h,setHiddenColumns:m,columns:S}=vr(t,f=>{const y=f.row.original.type==="client"?cn:f.row.original.type==="frontend"?dn:Me,v=f.row.original.type==="client"?Zo:f.row.original.type==="frontend"?Xo:Me;return r(pt,{children:[e(Tr,{token:f.row.original,permission:y}),e(xr,{token:f.row.original,permission:v,onRemove:async()=>{await a(f.row.original.secret),o()}})]})});return e(Te,{permissions:[cn,dn,Me],children:e(ee,{header:e(ne,{title:`API access (${d.length})`,actions:r(B,{children:[e(me,{initialValue:c,onChange:h}),e(ne.Divider,{}),e(Cr,{permission:[zn,Fn,Me],path:"/admin/api/create-token"})]})}),children:e(wr,{loading:n,headerGroups:l,setHiddenColumns:m,prepareRow:u,getTableBodyProps:s,getTableProps:i,rows:d,columns:S,globalFilter:c})})})},Zr=({type:t,projects:n,setProjects:o,errors:a,clearErrors:i})=>{const s=Qo("projectId"),{projects:l}=ea(),d=l.map(u=>({value:u.id,label:u.name}));return s?null:r(B,{children:[e(Er,{children:"Which project do you want to give access to?"}),e(ta,{disabled:t===kr.ADMIN,options:d,defaultValue:n,onChange:o,error:a==null?void 0:a.projects,onFocus:()=>i("projects")})]})},yn="Create API token",Xr=({modal:t=!1})=>{const{setToastApiError:n}=Z(),{uiConfig:o}=G(),a=be(),[i,s]=p.useState(!1),[l,d]=p.useState(""),{getApiTokenPayload:u,username:c,type:h,projects:m,environment:S,setUsername:f,setTokenType:y,setProjects:v,setEnvironment:T,isValid:w,errors:k,clearErrors:E,apiTokenTypes:x}=Rr(),{createToken:P,loading:M}=Hn(),{refetch:U}=tn();qn(yn);const I="api/admin/api-tokens";return r(Pe,{loading:M,title:yn,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:()=>`curl --location --request POST '${o.unleashUrl}/${I}' \\
2
2
  --header 'Authorization: INSERT_API_KEY' \\
3
3
  --header 'Content-Type: application/json' \\
4
- --data-raw '${JSON.stringify(u(),void 0,2)}'`,children:[r(Ar,{handleSubmit:async X=>{if(X.preventDefault(),!!w())try{const R=u();await P(R).then(_=>_.json()).then(_=>{Ht(),d(_.secret),s(!0),L()})}catch(R){n(K(R))}},handleCancel:()=>{a(De)},mode:"Create",actions:e(Vn,{name:"token",permission:[Me,Fn,zn]}),children:[e(Dr,{username:c,setUsername:f,errors:k,clearErrors:E}),e(Ir,{type:h,setType:y,apiTokenTypes:x}),e(Zr,{type:h,projects:m,setProjects:v,errors:k,clearErrors:E}),e(Pr,{type:h,environment:S,setEnvironment:T})]}),e(Br,{open:i,closeConfirm:()=>{s(!1),a(De)},token:l,type:h})]})},wo=({data:t={enabled:!1,autoCreate:!1},setValue:n})=>{const o=()=>{n("autoCreate",!t.autoCreate)},a=s=>{n("defaultRootRole",s.target.value)},i=s=>{n(s.target.name,s.target.value)};return r(p.Fragment,{children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Auto-create users"}),e("p",{children:"Enable automatic creation of new users when signing in."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(me,{control:e(Se,{onChange:o,name:"enabled",checked:t.autoCreate,disabled:!t.enabled}),label:"Auto-create users"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Default Root Role"}),e("p",{children:"Choose which root role the user should get when no explicit role mapping exists."})]}),e(b,{item:!0,md:6,children:r(mt,{style:{minWidth:"200px"},children:[e(Yn,{id:"defaultRootRole-label",children:"Default Role"}),r(Jn,{label:"Default Role",labelId:"defaultRootRole-label",id:"defaultRootRole",name:"defaultRootRole",disabled:!t.autoCreate||!t.enabled,value:t.defaultRootRole||"Editor",onChange:a,children:[e(Re,{value:"Viewer",children:"Viewer"}),e(Re,{value:"Editor",children:"Editor"}),e(Re,{value:"Admin",children:"Admin"})]})]})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Email domains"}),e("p",{children:"Comma separated list of email domains that should be allowed to sign in."})]}),e(b,{item:!0,md:6,children:e(Q,{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"})})]})]})},Qr=async(t,n)=>{if(t){if(n){const o=await n.json();throw t({message:o.message}),new Error(o.message)}throw new Error}},Ct=t=>{const{makeRequest:n,createRequest:o,errors:a,loading:i}=$e({propagateErrors:!0,handleBadRequest:Qr});return{updateSettings:async l=>{const d=`api/admin/auth/${t}/settings`,u=o(d,{method:"POST",body:JSON.stringify(l)});try{await n(u.caller,u.id)}catch(c){throw c}},errors:a,loading:i}},nn=t=>{const o=Object.entries(t).filter(([,a])=>a!=="");return Object.fromEntries(o)},To=({ssoType:t,data:n={enabled:!1,enableGroupSyncing:!1,groupJsonPath:""},setValue:o})=>{const a=()=>{o("enableGroupSyncing",!n.enableGroupSyncing)},i=s=>{o(s.target.name,s.target.value)};return r(B,{children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Enable Group Syncing"}),r("p",{children:["Enables automatically syncing of users from the"," ",t,"provider when a user logs in."]})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(me,{control:e(Se,{onChange:a,value:n.enableGroupSyncing,name:"enableGroupSyncing",checked:n.enableGroupSyncing,disabled:!n.enabled}),label:n.enableGroupSyncing?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Group Field JSON Path"}),r("p",{children:["Specifies the path in the ",t," token response from which to read the groups the user belongs to."]})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:i,label:"Group JSON Path",name:"groupJsonPath",value:n.groupJsonPath,disabled:!n.enableGroupSyncing,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]})]})},ei={enabled:!1,enableSingleSignOut:!1,enableGroupSyncing:!1,autoCreate:!1,unleashHostname:location.hostname,groupJsonPath:"",clientId:"",discoverUrl:"",secret:"",acrValues:"",idTokenSigningAlgorithm:"RS256"},ti=()=>{const{setToastData:t,setToastApiError:n}=Z(),{uiConfig:o}=G(),[a,i]=p.useState(ei),{config:s}=ze("oidc"),{updateSettings:l,errors:d,loading:u}=Ct("oidc");p.useEffect(()=>{s.discoverUrl&&i(s)},[s]);const c=y=>{S(y.target.name,y.target.value)},h=()=>{i({...a,enabled:!a.enabled})},m=()=>{i({...a,enableSingleSignOut:!a.enableSingleSignOut})},S=(y,v)=>{i({...a,[y]:v})},f=async y=>{y.preventDefault();try{await l(nn(a)),t({title:"Settings stored",type:"success"})}catch(v){n(K(v))}};return r(B,{children:[e(b,{container:!0,sx:{mb:3},children:e(b,{item:!0,md:12,children:r(J,{severity:"info",children:["Please read the"," ",e("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("br",{}),"Callback URL:"," ",r("code",{children:[o.unleashUrl,"/auth/oidc/callback"]})]})})}),r("form",{onSubmit:f,children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Enable"}),e("p",{children:"Enable Open Id Connect Authentication."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(me,{control:e(Se,{onChange:h,value:a.enabled,name:"enabled",checked:a.enabled}),label:a.enabled?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Discover URL"}),e("p",{children:"(Required) Issuer discover metadata URL"})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Discover URL",name:"discoverUrl",value:a.discoverUrl,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Client ID"}),e("p",{children:"(Required) Client ID of your OpenID application"})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Client ID",name:"clientId",value:a.clientId,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:4,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Client secret"}),r("p",{children:["(Required) Client secret of your OpenID application."," "]})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Client Secret",name:"secret",value:a.secret,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e("h3",{children:"Optional Configuration"}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Enable Single Sign-Out"}),e("p",{children:"If you enable Single Sign-Out Unleash will redirect the user to the IDP as part of the Sign-out process."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(me,{control:e(Se,{onChange:m,value:a.enableSingleSignOut,disabled:!a.enabled,name:"enableSingleSignOut",checked:a.enableSingleSignOut}),label:a.enableSingleSignOut?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"ACR Values"}),e("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(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"ACR Values",name:"acrValues",value:a.acrValues,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),e(To,{ssoType:"OIDC",data:a,setValue:S}),e(wo,{data:a,setValue:S}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"ID Signing algorithm"}),r("p",{children:["Which signing algorithm to use. ",e("br",{}),' Leave this alone unless you see errors that look like "unexpected JWT alg received, expected RS256, got: RS512" in your logs.']})]}),e(b,{item:!0,md:6,children:r(mt,{style:{minWidth:"200px"},children:[e(Yn,{id:"defaultRootRole-label",children:"Signing algorithm"}),r(Jn,{label:"Signing algorithm",labelId:"idTokenSigningAlgorithm-label",id:"idTokenSigningAlgorithm",name:"idTokenSigningAlgorithm",value:a.idTokenSigningAlgorithm||"RS256",onChange:y=>S("idTokenSigningAlgorithm",y.target.value),children:[e(Re,{value:"RS256",children:"RS256"}),e(Re,{value:"RS384",children:"RS384"}),e(Re,{value:"RS512",children:"RS512"})]})]})})]}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:12,children:[e(z,{variant:"contained",color:"primary",type:"submit",disabled:u,children:"Save"})," ",e("p",{children:e("small",{style:{color:"red"},children:d==null?void 0:d.message})})]})})]})]})},ni={enabled:!1,autoCreate:!1,enableGroupSyncing:!1,unleashHostname:location.hostname,entityId:"",signOnUrl:"",certificate:"",signOutUrl:"",spCertificate:"",groupJsonPath:""},oi=()=>{const{setToastData:t,setToastApiError:n}=Z(),{uiConfig:o}=G(),[a,i]=p.useState(ni),{config:s}=ze("saml"),{updateSettings:l,errors:d,loading:u}=Ct("saml");p.useEffect(()=>{s.entityId&&i(s)},[s]);const c=f=>{m(f.target.name,f.target.value)},h=()=>{i({...a,enabled:!a.enabled})},m=(f,y)=>{i({...a,[f]:y})},S=async f=>{f.preventDefault();try{await l(nn(a)),t({title:"Settings stored",type:"success"})}catch(y){n(K(y))}};return r(B,{children:[e(b,{container:!0,sx:{mb:3},children:e(b,{item:!0,md:12,children:r(J,{severity:"info",children:["Please read the"," ",e("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("br",{}),"Callback URL:"," ",r("code",{children:[o.unleashUrl,"/auth/saml/callback"]})]})})}),r("form",{onSubmit:S,children:[r(b,{container:!0,spacing:3,children:[r(b,{item:!0,md:5,mb:2,children:[e("strong",{children:"Enable"}),e("p",{children:"Enable SAML 2.0 Authentication."})]}),e(b,{item:!0,md:6,children:e(me,{control:e(Se,{onChange:h,value:a.enabled,name:"enabled",checked:a.enabled}),label:a.enabled?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Entity ID"}),e("p",{children:"(Required) The Entity Identity provider issuer."})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Entity ID",name:"entityId",value:a.entityId,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Single Sign-On URL"}),e("p",{children:"(Required) The url to redirect the user to for signing in."})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Single Sign-On URL",name:"signOnUrl",value:a.signOnUrl,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:4,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"X.509 Certificate"}),e("p",{children:"(Required) The certificate used to sign the SAML 2.0 request."})]}),e(b,{item:!0,md:7,children:e(Q,{onChange:c,label:"X.509 Certificate",name:"certificate",value:a.certificate,disabled:!a.enabled,style:{width:"100%"},InputProps:{style:{fontSize:"0.6em",fontFamily:"monospace"}},multiline:!0,rows:14,maxRows:14,variant:"outlined",size:"small",required:!0})})]}),e("h3",{children:"Optional Configuration"}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Single Sign-out URL"}),e("p",{children:"(Optional) The url to redirect the user to for signing out of the IDP."})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Single Sign-out URL",name:"signOutUrl",value:a.signOutUrl,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Service Provider X.509 Certificate"}),e("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(b,{item:!0,md:7,children:e(Q,{onChange:c,label:"X.509 Certificate",name:"spCertificate",value:a.spCertificate,disabled:!a.enabled,style:{width:"100%"},InputProps:{style:{fontSize:"0.6em",fontFamily:"monospace"}},multiline:!0,rows:14,maxRows:14,variant:"outlined",size:"small"})})]}),e(To,{ssoType:"SAML",data:a,setValue:m}),e(wo,{data:a,setValue:m}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:5,children:[e(z,{variant:"contained",color:"primary",type:"submit",disabled:u,children:"Save"})," ",e("p",{children:e("small",{style:{color:"red"},children:d==null?void 0:d.message})})]})})]})]})},ai=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/user-admin/admin-count"),ri);return{data:t,loading:!n&&!t,refetch:()=>o(),error:n}},ri=t=>fetch(t).then(ue("Admin count")).then(n=>n.json()),ii=({open:t,setOpen:n,onClick:o,adminCount:a,tokens:i})=>r(ie,{open:t,onClose:()=>{n(!1)},onClick:o,title:"Disable password based login?",primaryButtonText:"Disable password based login",secondaryButtonText:"Cancel",children:[r(J,{severity:"warning",children:[e("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("br",{}),e("br",{}),e("strong",{children:"Password based administrators: "})," ",a==null?void 0:a.password,e("br",{}),e("strong",{children:"Other administrators: "})," ",a==null?void 0:a.noPassword,e("br",{}),e("strong",{children:"Admin service accounts: "})," ",a==null?void 0:a.service,e("br",{}),e("strong",{children:"Admin API tokens: "})," ",i.filter(({type:s})=>s==="admin").length]}),e(D,{sx:{mt:3},children:"You are about to disable password based login. Are you sure you want to proceed?"})]}),si=()=>{const{setToastData:t,setToastApiError:n}=Z(),{config:o,refetch:a}=ze("simple"),[i,s]=p.useState(!1),{updateSettings:l,errors:d,loading:u}=Ct("simple"),[c,h]=p.useState(!1),{data:m}=ai(),{tokens:S}=tn();p.useEffect(()=>{s(!!o.disabled)},[o.disabled]);const f=()=>{s(!i)},y=async T=>{T.preventDefault(),!o.disabled&&i?h(!0):v()},v=async()=>{try{await l({disabled:i}),a(),t({title:"Successfully saved",text:"Password authentication settings stored.",autoHideDuration:4e3,type:"success",show:!0})}catch(T){n(K(T)),s(o.disabled)}};return e(B,{children:r("form",{onSubmit:y,children:[r(J,{severity:"info",sx:{mb:3},children:["Overview of administrators on your Unleash instance:",e("br",{}),e("br",{}),e("strong",{children:"Password based administrators: "})," ",e(de,{to:"/admin/users",children:m==null?void 0:m.password}),e("br",{}),e("strong",{children:"Other administrators: "})," ",e(de,{to:"/admin/users",children:m==null?void 0:m.noPassword}),e("br",{}),e("strong",{children:"Admin service accounts: "})," ",e(de,{to:"/admin/service-accounts",children:m==null?void 0:m.service}),e("br",{}),e("strong",{children:"Admin API tokens: "})," ",e(de,{to:"/admin/api",children:S.filter(({type:T})=>T==="admin").length})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Password based login"}),e("p",{children:"Allow users to login with username & password"})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(me,{control:e(Se,{onChange:f,value:!i,name:"disabled",checked:!i}),label:i?"Disabled":"Enabled"})})]}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:12,children:[e(z,{variant:"contained",color:"primary",type:"submit",disabled:u,children:"Save"})," ",e("p",{children:e("small",{style:{color:"red"},children:d==null?void 0:d.message})})]})}),e(ii,{open:c,setOpen:h,onClick:()=>{h(!1),v()},adminCount:m,tokens:S})]})})},li={enabled:!1,autoCreate:!1,unleashHostname:location.hostname,clientId:"",clientSecret:"",emailDomains:""},ci=()=>{const{setToastData:t,setToastApiError:n}=Z(),{uiConfig:o}=G(),[a,i]=p.useState(li),{config:s}=ze("google"),{updateSettings:l,errors:d,loading:u}=Ct("google");p.useEffect(()=>{s.clientId&&i(s)},[s]);const c=f=>{i({...a,[f.target.name]:f.target.value})},h=()=>{i({...a,enabled:!a.enabled})},m=()=>{i({...a,autoCreate:!a.autoCreate})},S=async f=>{f.preventDefault();try{await l(nn(a)),t({title:"Settings stored",type:"success"})}catch(y){n(K(y))}};return r(B,{children:[r(N,{children:[r(J,{severity:"error",sx:{mb:2},children:["This integration is deprecated and will be removed in next major version. Please use ",e("strong",{children:"OpenID Connect"})," to enable Google SSO."]}),r(J,{severity:"info",sx:{mb:3},children:["Read the"," ",e("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("br",{}),"Callback URL:"," ",r("code",{children:[o.unleashUrl,"/auth/google/callback"]})]})]}),r("form",{onSubmit:S,children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,xs:5,children:[e("strong",{children:"Enable"}),e("p",{children:"Enable Google users to login. Value is ignored if Client ID and Client Secret are not defined."})]}),e(b,{item:!0,xs:6,style:{padding:"20px"},children:e(me,{control:e(Se,{onChange:h,value:a.enabled,name:"enabled",checked:a.enabled}),label:a.enabled?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,xs:5,children:[e("strong",{children:"Client ID"}),e("p",{children:"(Required) The Client ID provided by Google when registering the application."})]}),e(b,{item:!0,xs:6,children:e(Q,{onChange:c,label:"Client ID",name:"clientId",placeholder:"",value:a.clientId,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Client Secret"}),e("p",{children:"(Required) Client Secret provided by Google when registering the application."})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Client Secret",name:"clientSecret",value:a.clientSecret,placeholder:"",style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Unleash hostname"}),r("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("small",{children:e("code",{children:"https://[unleash.hostname.com]/auth/google/callback"})})]})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Unleash Hostname",name:"unleashHostname",placeholder:"",value:a.unleashHostname||"",style:{width:"400px"},variant:"outlined",size:"small"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Auto-create users"}),e("p",{children:"Enable automatic creation of new users when signing in with Google."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(Se,{onChange:m,name:"enabled",checked:a.autoCreate})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Email domains"}),e("p",{children:"(Optional) Comma separated list of email domains that should be allowed to sign in."})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Email domains",name:"emailDomains",value:a.emailDomains,placeholder:"@company.com, @anotherCompany.com",style:{width:"400px"},rows:2,multiline:!0,variant:"outlined",size:"small"})})]}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:5,children:[e(z,{variant:"contained",color:"primary",type:"submit",disabled:u,children:"Save"})," ",e("p",{children:e("small",{style:{color:"error.dark"},children:d==null?void 0:d.message})})]})})]})]})},di=()=>{const{authenticationType:t}=G().uiConfig,{uiConfig:n}=G(),o=[{label:"OpenID Connect",component:e(ti,{})},{label:"SAML 2.0",component:e(oi,{})},{label:"Password",component:e(si,{})},{label:"Google",component:e(ci,{})}].filter(s=>{var l;return((l=n.flags)==null?void 0:l.googleAuthEnabled)||s.label!=="Google"}),[a,i]=p.useState(0);return e("div",{children:e(Te,{permissions:Me,children:r(ee,{withTabs:!0,header:e(C,{condition:t==="enterprise",show:e(gt,{value:a,onChange:(s,l)=>{i(l)},indicatorColor:"primary",textColor:"primary",children:o.map((s,l)=>e(ft,{label:s.label,id:`tab-${l}`,"aria-controls":`tabpanel-${l}`,sx:{minWidth:{lg:160}}},`${s.label}_${l}`))})}),children:[e(C,{condition:t==="open-source",show:e(yt,{feature:"sso"})}),e(C,{condition:t==="demo",show:e(J,{severity:"warning",children:"You are running Unleash in demo mode. You have to use the Enterprise edition in order configure Single Sign-on."})}),e(C,{condition:t==="custom",show:e(J,{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(C,{condition:t==="hosted",show:e(J,{severity:"info",children:"Your Unleash instance is managed by the Unleash team."})}),e(C,{condition:t==="enterprise",show:e("div",{children:o.map((s,l)=>e(na,{value:a,index:l,children:s.component},l))})})]})})})},ui=oe("api/admin/invoices"),hi=g(z)(({theme:t})=>({width:"100%",marginBottom:t.spacing(1.5)})),pi=({update:t})=>e(hi,{href:`${ui}/${t?"portal":"checkout"}`,variant:t?"outlined":"contained",children:t?"Update billing information":"Add billing information"}),mi=g("aside")(({theme:t})=>({padding:t.spacing(4),height:"100%",borderRadius:t.shape.borderRadiusLarge,backgroundColor:t.palette.background.elevation2})),gi=g(D)(({theme:t})=>({marginBottom:t.spacing(4)})),fi=g(J)(({theme:t})=>({marginBottom:t.spacing(4)})),bn=g(D)(({theme:t})=>({fontSize:t.fontSizes.smallBody,color:t.palette.text.secondary})),yi=g(Wt)(({theme:t})=>({margin:`${t.spacing(2.5)} 0`,borderColor:t.palette.divider})),bi=({instanceStatus:t})=>{const n=t.state!==Kn.ACTIVE;return e(b,{item:!0,xs:12,md:5,children:r(mi,{children:[e(gi,{variant:"body1",children:"Billing information"}),e(C,{condition:n,show:r(fi,{severity:"warning",children:["In order to ",e("strong",{children:"Upgrade trial"})," you need to provide us your billing information."]})}),e(pi,{update:!n}),e(bn,{children:n?"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(yi,{}),r(bn,{children:[e("a",{href:"mailto:elise@getunleash.ai?subject=PRO plan clarifications",children:"Get in touch with us"})," ","for any clarification"]})]})})},Ee=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/user-admin"),Si);return p.useMemo(()=>({users:(t==null?void 0:t.users)??[],roles:(t==null?void 0:t.rootRoles)??[],loading:!n&&!t,refetch:()=>o(),error:n}),[t,n,o])},Si=t=>fetch(t).then(ue("Users")).then(n=>n.json()),vi=g(b)(({theme:t})=>({flexWrap:"nowrap",gap:t.spacing(1)})),st=({sx:t,children:n})=>e(vi,{container:!0,item:!0,justifyContent:"space-between",alignItems:"center",sx:t,children:n}),Be=({children:t,vertical:n=!1})=>e(b,{container:n,item:!0,display:"flex",alignItems:n?"start":"center",direction:n?"column":void 0,children:t}),Ci=g("span")(({theme:t})=>({fontSize:t.fontSizes.smallBody,marginLeft:t.spacing(1)})),Sn=({children:t})=>r(Ci,{children:["(",t,")"]}),wi=g("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)}})),vn=g(D)(({theme:t})=>({fontSize:t.fontSizes.smallBody,color:t.palette.text.secondary})),Ti=g("span")(({theme:t})=>({fontSize:"3.25rem",lineHeight:1,color:t.palette.primary.main,fontWeight:800})),xi=g("span")(({theme:t})=>({marginLeft:t.spacing(1.5),fontWeight:t.fontWeight.bold})),Ei=g("span")(({theme:t})=>({color:t.palette.primary.main,fontSize:t.fontSizes.mainHeader,fontWeight:t.fontWeight.bold})),ki=g(J)(({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=g(Zn)(({theme:t})=>({fontSize:"1rem",marginRight:t.spacing(1)})),Ai=g(Wt)(({theme:t})=>({margin:`${t.spacing(3)} 0`})),Di=({instanceStatus:t})=>{var f;const{users:n}=Ee(),o=oa(t),{uiConfig:a}=G(),i=n.filter(y=>y.email),s={[Ge.PRO]:80,[Ge.COMPANY]:0,[Ge.TEAM]:0,[Ge.ENTERPRISE]:0,[Ge.UNKNOWN]:0,user:15},l=s[t.plan],d=t.seats??5,u=Math.min(i.length,d),c=i.length-u,h=s.user*c,m=l+h,S=t.state!==Kn.ACTIVE;return e(b,{item:!0,xs:12,md:7,children:r(wi,{children:[e(C,{condition:S,show:r(ki,{severity:"info",children:["After you have sent your billing information, your instance will be upgraded - you don't have to do anything."," ",e("a",{href:"mailto:elise@getunleash.ai?subject=PRO plan clarifications",children:"Get in touch with us"})," ","for any clarification"]})}),e(Fe,{color:"success",children:"Current plan"}),e(b,{container:!0,children:r(st,{sx:y=>({marginBottom:y.spacing(3)}),children:[r(Be,{children:[e(Ti,{children:t.plan}),e(C,{condition:aa(t),show:e(xi,{sx:y=>({color:o?y.palette.error.dark:y.palette.warning.dark}),children:o?"Trial expired":t.trialExtended?"Extended Trial":"Trial"})})]}),e(Be,{children:e(C,{condition:l>0,show:r(Ei,{children:["$",l.toFixed(2)]})})})]})}),e(C,{condition:!!((f=a==null?void 0:a.flags)!=null&&f.proPlanAutoCharge&&t.plan===Ge.PRO),show:r(B,{children:[r(b,{container:!0,children:[r(st,{sx:y=>({marginBottom:y.spacing(1.5)}),children:[r(Be,{vertical:!0,children:[r(D,{children:[e("strong",{children:"Included members"}),e(Sn,{children:r(de,{to:"/admin/users",children:[u," of 5 assigned"]})})]}),e(vn,{children:"You have 5 team members included in your PRO plan"})]}),r(Be,{children:[e(Ri,{}),e(D,{variant:"body2",children:"included"})]})]}),r(st,{children:[r(Be,{vertical:!0,children:[r(D,{children:[e("strong",{children:"Paid members"}),e(Sn,{children:r(de,{to:"/admin/users",children:[c," assigned"]})})]}),e(vn,{children:"$15/month per paid member"})]}),e(Be,{children:r(D,{sx:y=>({fontSize:y.fontSizes.mainHeader}),children:["$",h.toFixed(2)]})})]})]}),e(Ai,{}),e(b,{container:!0,children:r(st,{children:[e(Be,{children:e(D,{sx:y=>({fontWeight:y.fontWeight.bold,fontSize:y.fontSizes.mainHeader}),children:"Total per month"})}),e(Be,{children:r(D,{sx:y=>({fontWeight:y.fontWeight.bold,fontSize:"2rem"}),children:["$",m.toFixed(2)]})})]})})]})})]})})},Ii=({instanceStatus:t})=>r(b,{container:!0,spacing:4,children:[e(bi,{instanceStatus:t}),e(Di,{instanceStatus:t})]}),Pi=g(D)(({theme:t})=>({marginTop:t.spacing(6),marginBottom:t.spacing(2.5),fontSize:t.fontSizes.mainHeader})),Bi=[{Header:"Amount",accessor:"amountFormatted"},{Header:"Status",accessor:"status",disableGlobalFilter:!0},{Header:"Created date",accessor:"created",Cell:ve,sortType:"date",disableGlobalFilter:!0},{Header:"Due date",accessor:"dueDate",Cell:ve,sortType:"date",disableGlobalFilter:!0},{Header:"Download",accessor:"invoicePDF",align:"center",Cell:({value:t})=>e(N,{sx:{display:"flex",justifyContent:"center"},"data-loading":!0,children:e(He,{href:t,children:e(la,{})})}),width:100,disableGlobalFilter:!0,disableSortBy:!0}],Li=({data:t,isLoading:n=!1})=>{const o=p.useMemo(()=>({sortBy:[{id:"created"}]}),[]),{getTableProps:a,getTableBodyProps:i,headerGroups:s,rows:l,prepareRow:d}=$.useTable({columns:Bi,data:t,initialState:o,sortTypes:be,autoResetGlobalFilter:!1,disableSortRemove:!0,defaultColumn:{Cell:te}},$.useGlobalFilter,$.useSortBy);return r(ee,{isLoading:n,disablePadding:!0,children:[e(Pi,{children:"Payment history"}),r(ra,{...a(),children:[e(ia,{headerGroups:s}),e(zt,{...i(),children:l.map(u=>(d(u),e(Xe,{hover:!0,...u.getRowProps(),children:u.cells.map(c=>e(sa,{...c.getCellProps(),children:c.render("Cell")}))})))})]}),e(C,{condition:l.length===0,show:e(ge,{children:"No invoices to show."})})]})},_t="api/admin/invoices",Ui=oe(_t),xo=(t={})=>{const n=()=>fetch(Ui,{method:"GET"}).then(ue("Invoices")).then(d=>d.json()),{data:o,error:a}=we(_t,n,t),[i,s]=p.useState(!a&&!o),l=()=>{Xn(_t)};return p.useEffect(()=>{s(!a&&!o)},[o,a]),{invoices:(o==null?void 0:o.invoices)||[],error:a,loading:i,refetchInvoices:l}},Oi=()=>{const{instanceStatus:t,isBilling:n,refetchInstanceStatus:o,refresh:a,loading:i}=Qn(),{invoices:s}=xo();return p.useEffect(()=>{(async()=>{await a(),o()})()},[o,a]),e("div",{children:e(ee,{header:"Billing",isLoading:i,children:e(C,{condition:n,show:e(Te,{permissions:Y,children:r(B,{children:[e(Ii,{instanceStatus:t}),e(Li,{data:s})]})}),elseShow:e(J,{severity:"error",children:"Billing is not enabled for this instance."})})})})},$i=oe("api/admin/invoices/portal"),Ni=()=>{const{refetchInvoices:t,invoices:n}=xo(),[o,a]=p.useState(!1),{locationSettings:i}=eo();return p.useEffect(()=>{t(),a(!0)},[]),e(C,{condition:n.length>0,show:e(ee,{header:e(ne,{title:"Invoices",actions:e(z,{href:$i,rel:"noreferrer",target:"_blank",endIcon:e(ca,{}),children:"Billing portal"})}),children:e("div",{children:r(to,{children:[e(no,{children:r(Xe,{children:[e(ce,{children:"Amount"}),e(ce,{children:"Status"}),e(ce,{children:"Due date"}),e(ce,{children:"PDF"}),e(ce,{children:"Link"})]})}),e(zt,{children:n.map(s=>r(Xe,{style:{backgroundColor:s.status==="past-due"?"error.dark":"inherit"},children:[e(ce,{style:{textAlign:"left"},children:s.amountFormatted}),e(ce,{style:{textAlign:"left"},children:s.status}),e(ce,{style:{textAlign:"left"},children:s.dueDate&&oo(s.dueDate,i.locale)}),e(ce,{style:{textAlign:"left"},children:e("a",{href:s.invoicePDF,children:"PDF"})}),e(ce,{style:{textAlign:"left"},children:e("a",{href:s.invoiceURL,target:"_blank",rel:"noreferrer",children:"Payment link"})})]},s.invoiceURL))})]})})}),elseShow:e(ee,{children:o&&"No invoices to show."})})},Gi=()=>e("div",{children:e(Te,{permissions:Y,children:e(Ni,{})})}),Mi=()=>{const{uiConfig:t,loading:n}=G();return n?null:t.flags.UNLEASH_CLOUD?e(da,{to:"/admin/billing",replace:!0}):e(Gi,{})},ji=()=>r(J,{severity:"info",children:[r("p",{children:["Use this page to configure allowed CORS origins for the Frontend API (",e("code",{children:"/api/frontend"}),")."]}),r("p",{children:["This configuration will not affect the Admin API (",e("code",{children:"/api/admin"}),") nor the Client API (",e("code",{children:"/api/client"}),")."]}),r("p",{children:["An asterisk (",e("code",{children:"*"}),") may be used to allow API calls from any origin."]}),e("br",{}),e("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)."})]}),_i=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=$e({propagateErrors:!0});return{setFrontendSettings:async s=>{const d=n("api/admin/ui-config",{method:"POST",body:JSON.stringify({frontendSettings:{frontendApiOrigins:s}})},"setFrontendSettings");await t(d.caller,d.id)},loading:a,errors:o}},Hi=({frontendApiOrigins:t})=>{const{setFrontendSettings:n}=_i(),{setToastData:o,setToastApiError:a}=Z(),[i,s]=p.useState(Cn(t)),l=un(),d=un();return e("form",{onSubmit:async c=>{try{const h=Wi(i);c.preventDefault(),await n(h),s(Cn(h)),o({title:"Settings saved",type:"success"})}catch(h){a(K(h))}},children:r(N,{sx:{display:"grid",gap:1},children:[r("label",{htmlFor:l,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("br",{}),e("br",{}),'If you specify "*" it will be the chosen origin.',e("br",{}),e("br",{}),"Example:"]}),r("code",{style:{fontSize:"0.7em"},children:["https://www.example.com",e("br",{}),"https://www.example2.com"]}),e(Q,{id:l,"aria-describedby":d,placeholder:zi,value:i,onChange:c=>s(c.target.value),multiline:!0,rows:12,variant:"outlined",fullWidth:!0,InputProps:{style:{fontFamily:"monospace",fontSize:"0.8em"}}}),e(ao,{permission:Y})]})})},Wi=t=>t.split(/[,\n\s]+/).map(n=>n.replace(/\/$/,"")).filter(Boolean),Cn=t=>(t==null?void 0:t.join(`
4
+ --data-raw '${JSON.stringify(u(),void 0,2)}'`,children:[r(Ar,{handleSubmit:async X=>{if(X.preventDefault(),!!w())try{const R=u();await P(R).then(_=>_.json()).then(_=>{Wt(),d(_.secret),s(!0),U()})}catch(R){n(K(R))}},handleCancel:()=>{a(De)},mode:"Create",actions:e(Vn,{name:"token",permission:[Me,Fn,zn]}),children:[e(Dr,{username:c,setUsername:f,errors:k,clearErrors:E}),e(Ir,{type:h,setType:y,apiTokenTypes:x}),e(Zr,{type:h,projects:m,setProjects:v,errors:k,clearErrors:E}),e(Pr,{type:h,environment:S,setEnvironment:T})]}),e(Br,{open:i,closeConfirm:()=>{s(!1),a(De)},token:l,type:h})]})},wo=({data:t={enabled:!1,autoCreate:!1},setValue:n})=>{const o=()=>{n("autoCreate",!t.autoCreate)},a=s=>{n("defaultRootRole",s.target.value)},i=s=>{n(s.target.name,s.target.value)};return r(p.Fragment,{children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Auto-create users"}),e("p",{children:"Enable automatic creation of new users when signing in."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(he,{control:e(ge,{onChange:o,name:"enabled",checked:t.autoCreate,disabled:!t.enabled}),label:"Auto-create users"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Default Root Role"}),e("p",{children:"Choose which root role the user should get when no explicit role mapping exists."})]}),e(b,{item:!0,md:6,children:r(mt,{style:{minWidth:"200px"},children:[e(Yn,{id:"defaultRootRole-label",children:"Default Role"}),r(Jn,{label:"Default Role",labelId:"defaultRootRole-label",id:"defaultRootRole",name:"defaultRootRole",disabled:!t.autoCreate||!t.enabled,value:t.defaultRootRole||"Editor",onChange:a,children:[e(Re,{value:"Viewer",children:"Viewer"}),e(Re,{value:"Editor",children:"Editor"}),e(Re,{value:"Admin",children:"Admin"})]})]})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Email domains"}),e("p",{children:"Comma separated list of email domains that should be allowed to sign in."})]}),e(b,{item:!0,md:6,children:e(Q,{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"})})]})]})},Qr=async(t,n)=>{if(t){if(n){const o=await n.json();throw t({message:o.message}),new Error(o.message)}throw new Error}},Ct=t=>{const{makeRequest:n,createRequest:o,errors:a,loading:i}=$e({propagateErrors:!0,handleBadRequest:Qr});return{updateSettings:async l=>{const d=`api/admin/auth/${t}/settings`,u=o(d,{method:"POST",body:JSON.stringify(l)});try{await n(u.caller,u.id)}catch(c){throw c}},errors:a,loading:i}},nn=t=>{const o=Object.entries(t).filter(([,a])=>a!=="");return Object.fromEntries(o)},To=({ssoType:t,data:n={enabled:!1,enableGroupSyncing:!1,groupJsonPath:"",addGroupsScope:!1},setValue:o})=>{const a=()=>{o("enableGroupSyncing",!n.enableGroupSyncing)},i=l=>{o(l.target.name,l.target.value)},s=()=>{o("addGroupsScope",!n.addGroupsScope)};return r(B,{children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Enable Group Syncing"}),r("p",{children:["Enables automatically syncing of users from the"," ",t,"provider when a user logs in."]})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(he,{control:e(ge,{onChange:a,value:n.enableGroupSyncing,name:"enableGroupSyncing",checked:n.enableGroupSyncing,disabled:!n.enabled}),label:n.enableGroupSyncing?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Group Field JSON Path"}),r("p",{children:["Specifies the path in the ",t," token response from which to read the groups the user belongs to."]})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:i,label:"Group JSON Path",name:"groupJsonPath",value:n.groupJsonPath,disabled:!n.enableGroupSyncing,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e(C,{condition:t==="OIDC",show:r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Request 'groups' Scope"}),e("p",{children:"When enabled Unleash will also request the 'groups' scope as part of the login request."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(he,{control:e(ge,{onChange:s,value:n.addGroupsScope,disabled:!n.enableGroupSyncing,name:"addGroupsScope",checked:n.addGroupsScope}),label:n.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:n}=Z(),{uiConfig:o}=G(),[a,i]=p.useState(ei),{config:s}=ze("oidc"),{updateSettings:l,errors:d,loading:u}=Ct("oidc");p.useEffect(()=>{s.discoverUrl&&i(s)},[s]);const c=y=>{S(y.target.name,y.target.value)},h=()=>{i({...a,enabled:!a.enabled})},m=()=>{i({...a,enableSingleSignOut:!a.enableSingleSignOut})},S=(y,v)=>{i({...a,[y]:v})},f=async y=>{y.preventDefault();try{await l(nn(a)),t({title:"Settings stored",type:"success"})}catch(v){n(K(v))}};return r(B,{children:[e(b,{container:!0,sx:{mb:3},children:e(b,{item:!0,md:12,children:r(J,{severity:"info",children:["Please read the"," ",e("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("br",{}),"Callback URL:"," ",r("code",{children:[o.unleashUrl,"/auth/oidc/callback"]})]})})}),r("form",{onSubmit:f,children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Enable"}),e("p",{children:"Enable Open Id Connect Authentication."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(he,{control:e(ge,{onChange:h,value:a.enabled,name:"enabled",checked:a.enabled}),label:a.enabled?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Discover URL"}),e("p",{children:"(Required) Issuer discover metadata URL"})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Discover URL",name:"discoverUrl",value:a.discoverUrl,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Client ID"}),e("p",{children:"(Required) Client ID of your OpenID application"})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Client ID",name:"clientId",value:a.clientId,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:4,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Client secret"}),r("p",{children:["(Required) Client secret of your OpenID application."," "]})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Client Secret",name:"secret",value:a.secret,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e("h3",{children:"Optional Configuration"}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Enable Single Sign-Out"}),e("p",{children:"If you enable Single Sign-Out Unleash will redirect the user to the IDP as part of the Sign-out process."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(he,{control:e(ge,{onChange:m,value:a.enableSingleSignOut,disabled:!a.enabled,name:"enableSingleSignOut",checked:a.enableSingleSignOut}),label:a.enableSingleSignOut?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"ACR Values"}),e("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(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"ACR Values",name:"acrValues",value:a.acrValues,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),e(To,{ssoType:"OIDC",data:a,setValue:S}),e(wo,{data:a,setValue:S}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"ID Signing algorithm"}),r("p",{children:["Which signing algorithm to use. ",e("br",{}),' Leave this alone unless you see errors that look like "unexpected JWT alg received, expected RS256, got: RS512" in your logs.']})]}),e(b,{item:!0,md:6,children:r(mt,{style:{minWidth:"200px"},children:[e(Yn,{id:"defaultRootRole-label",children:"Signing algorithm"}),r(Jn,{label:"Signing algorithm",labelId:"idTokenSigningAlgorithm-label",id:"idTokenSigningAlgorithm",name:"idTokenSigningAlgorithm",value:a.idTokenSigningAlgorithm||"RS256",onChange:y=>S("idTokenSigningAlgorithm",y.target.value),children:[e(Re,{value:"RS256",children:"RS256"}),e(Re,{value:"RS384",children:"RS384"}),e(Re,{value:"RS512",children:"RS512"})]})]})})]}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:12,children:[e(z,{variant:"contained",color:"primary",type:"submit",disabled:u,children:"Save"})," ",e("p",{children:e("small",{style:{color:"red"},children:d==null?void 0:d.message})})]})})]})]})},ni={enabled:!1,autoCreate:!1,enableGroupSyncing:!1,addGroupsScope:!1,unleashHostname:location.hostname,entityId:"",signOnUrl:"",certificate:"",signOutUrl:"",spCertificate:"",groupJsonPath:""},oi=()=>{const{setToastData:t,setToastApiError:n}=Z(),{uiConfig:o}=G(),[a,i]=p.useState(ni),{config:s}=ze("saml"),{updateSettings:l,errors:d,loading:u}=Ct("saml");p.useEffect(()=>{s.entityId&&i(s)},[s]);const c=f=>{m(f.target.name,f.target.value)},h=()=>{i({...a,enabled:!a.enabled})},m=(f,y)=>{i({...a,[f]:y})},S=async f=>{f.preventDefault();try{await l(nn(a)),t({title:"Settings stored",type:"success"})}catch(y){n(K(y))}};return r(B,{children:[e(b,{container:!0,sx:{mb:3},children:e(b,{item:!0,md:12,children:r(J,{severity:"info",children:["Please read the"," ",e("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("br",{}),"Callback URL:"," ",r("code",{children:[o.unleashUrl,"/auth/saml/callback"]})]})})}),r("form",{onSubmit:S,children:[r(b,{container:!0,spacing:3,children:[r(b,{item:!0,md:5,mb:2,children:[e("strong",{children:"Enable"}),e("p",{children:"Enable SAML 2.0 Authentication."})]}),e(b,{item:!0,md:6,children:e(he,{control:e(ge,{onChange:h,value:a.enabled,name:"enabled",checked:a.enabled}),label:a.enabled?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Entity ID"}),e("p",{children:"(Required) The Entity Identity provider issuer."})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Entity ID",name:"entityId",value:a.entityId,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Single Sign-On URL"}),e("p",{children:"(Required) The url to redirect the user to for signing in."})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Single Sign-On URL",name:"signOnUrl",value:a.signOnUrl,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:4,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"X.509 Certificate"}),e("p",{children:"(Required) The certificate used to sign the SAML 2.0 request."})]}),e(b,{item:!0,md:7,children:e(Q,{onChange:c,label:"X.509 Certificate",name:"certificate",value:a.certificate,disabled:!a.enabled,style:{width:"100%"},InputProps:{style:{fontSize:"0.6em",fontFamily:"monospace"}},multiline:!0,rows:14,maxRows:14,variant:"outlined",size:"small",required:!0})})]}),e("h3",{children:"Optional Configuration"}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Single Sign-out URL"}),e("p",{children:"(Optional) The url to redirect the user to for signing out of the IDP."})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Single Sign-out URL",name:"signOutUrl",value:a.signOutUrl,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Service Provider X.509 Certificate"}),e("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(b,{item:!0,md:7,children:e(Q,{onChange:c,label:"X.509 Certificate",name:"spCertificate",value:a.spCertificate,disabled:!a.enabled,style:{width:"100%"},InputProps:{style:{fontSize:"0.6em",fontFamily:"monospace"}},multiline:!0,rows:14,maxRows:14,variant:"outlined",size:"small"})})]}),e(To,{ssoType:"SAML",data:a,setValue:m}),e(wo,{data:a,setValue:m}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:5,children:[e(z,{variant:"contained",color:"primary",type:"submit",disabled:u,children:"Save"})," ",e("p",{children:e("small",{style:{color:"red"},children:d==null?void 0:d.message})})]})})]})]})},ai=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/user-admin/admin-count"),ri);return{data:t,loading:!n&&!t,refetch:()=>o(),error:n}},ri=t=>fetch(t).then(ue("Admin count")).then(n=>n.json()),ii=({open:t,setOpen:n,onClick:o,adminCount:a,tokens:i})=>r(ie,{open:t,onClose:()=>{n(!1)},onClick:o,title:"Disable password based login?",primaryButtonText:"Disable password based login",secondaryButtonText:"Cancel",children:[r(J,{severity:"warning",children:[e("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("br",{}),e("br",{}),e("strong",{children:"Password based administrators: "})," ",a==null?void 0:a.password,e("br",{}),e("strong",{children:"Other administrators: "})," ",a==null?void 0:a.noPassword,e("br",{}),e("strong",{children:"Admin service accounts: "})," ",a==null?void 0:a.service,e("br",{}),e("strong",{children:"Admin API tokens: "})," ",i.filter(({type:s})=>s==="admin").length]}),e(D,{sx:{mt:3},children:"You are about to disable password based login. Are you sure you want to proceed?"})]}),si=()=>{const{setToastData:t,setToastApiError:n}=Z(),{config:o,refetch:a}=ze("simple"),[i,s]=p.useState(!1),{updateSettings:l,errors:d,loading:u}=Ct("simple"),[c,h]=p.useState(!1),{data:m}=ai(),{tokens:S}=tn();p.useEffect(()=>{s(!!o.disabled)},[o.disabled]);const f=()=>{s(!i)},y=async T=>{T.preventDefault(),!o.disabled&&i?h(!0):v()},v=async()=>{try{await l({disabled:i}),a(),t({title:"Successfully saved",text:"Password authentication settings stored.",autoHideDuration:4e3,type:"success",show:!0})}catch(T){n(K(T)),s(o.disabled)}};return e(B,{children:r("form",{onSubmit:y,children:[r(J,{severity:"info",sx:{mb:3},children:["Overview of administrators on your Unleash instance:",e("br",{}),e("br",{}),e("strong",{children:"Password based administrators: "})," ",e(de,{to:"/admin/users",children:m==null?void 0:m.password}),e("br",{}),e("strong",{children:"Other administrators: "})," ",e(de,{to:"/admin/users",children:m==null?void 0:m.noPassword}),e("br",{}),e("strong",{children:"Admin service accounts: "})," ",e(de,{to:"/admin/service-accounts",children:m==null?void 0:m.service}),e("br",{}),e("strong",{children:"Admin API tokens: "})," ",e(de,{to:"/admin/api",children:S.filter(({type:T})=>T==="admin").length})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Password based login"}),e("p",{children:"Allow users to login with username & password"})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(he,{control:e(ge,{onChange:f,value:!i,name:"disabled",checked:!i}),label:i?"Disabled":"Enabled"})})]}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:12,children:[e(z,{variant:"contained",color:"primary",type:"submit",disabled:u,children:"Save"})," ",e("p",{children:e("small",{style:{color:"red"},children:d==null?void 0:d.message})})]})}),e(ii,{open:c,setOpen:h,onClick:()=>{h(!1),v()},adminCount:m,tokens:S})]})})},li={enabled:!1,autoCreate:!1,unleashHostname:location.hostname,clientId:"",clientSecret:"",emailDomains:""},ci=()=>{const{setToastData:t,setToastApiError:n}=Z(),{uiConfig:o}=G(),[a,i]=p.useState(li),{config:s}=ze("google"),{updateSettings:l,errors:d,loading:u}=Ct("google");p.useEffect(()=>{s.clientId&&i(s)},[s]);const c=f=>{i({...a,[f.target.name]:f.target.value})},h=()=>{i({...a,enabled:!a.enabled})},m=()=>{i({...a,autoCreate:!a.autoCreate})},S=async f=>{f.preventDefault();try{await l(nn(a)),t({title:"Settings stored",type:"success"})}catch(y){n(K(y))}};return r(B,{children:[r(N,{children:[r(J,{severity:"error",sx:{mb:2},children:["This integration is deprecated and will be removed in next major version. Please use ",e("strong",{children:"OpenID Connect"})," to enable Google SSO."]}),r(J,{severity:"info",sx:{mb:3},children:["Read the"," ",e("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("br",{}),"Callback URL:"," ",r("code",{children:[o.unleashUrl,"/auth/google/callback"]})]})]}),r("form",{onSubmit:S,children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,xs:5,children:[e("strong",{children:"Enable"}),e("p",{children:"Enable Google users to login. Value is ignored if Client ID and Client Secret are not defined."})]}),e(b,{item:!0,xs:6,style:{padding:"20px"},children:e(he,{control:e(ge,{onChange:h,value:a.enabled,name:"enabled",checked:a.enabled}),label:a.enabled?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,xs:5,children:[e("strong",{children:"Client ID"}),e("p",{children:"(Required) The Client ID provided by Google when registering the application."})]}),e(b,{item:!0,xs:6,children:e(Q,{onChange:c,label:"Client ID",name:"clientId",placeholder:"",value:a.clientId,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Client Secret"}),e("p",{children:"(Required) Client Secret provided by Google when registering the application."})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Client Secret",name:"clientSecret",value:a.clientSecret,placeholder:"",style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Unleash hostname"}),r("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("small",{children:e("code",{children:"https://[unleash.hostname.com]/auth/google/callback"})})]})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Unleash Hostname",name:"unleashHostname",placeholder:"",value:a.unleashHostname||"",style:{width:"400px"},variant:"outlined",size:"small"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Auto-create users"}),e("p",{children:"Enable automatic creation of new users when signing in with Google."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(ge,{onChange:m,name:"enabled",checked:a.autoCreate})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Email domains"}),e("p",{children:"(Optional) Comma separated list of email domains that should be allowed to sign in."})]}),e(b,{item:!0,md:6,children:e(Q,{onChange:c,label:"Email domains",name:"emailDomains",value:a.emailDomains,placeholder:"@company.com, @anotherCompany.com",style:{width:"400px"},rows:2,multiline:!0,variant:"outlined",size:"small"})})]}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:5,children:[e(z,{variant:"contained",color:"primary",type:"submit",disabled:u,children:"Save"})," ",e("p",{children:e("small",{style:{color:"error.dark"},children:d==null?void 0:d.message})})]})})]})]})},di=()=>{const{authenticationType:t}=G().uiConfig,{uiConfig:n}=G(),o=[{label:"OpenID Connect",component:e(ti,{})},{label:"SAML 2.0",component:e(oi,{})},{label:"Password",component:e(si,{})},{label:"Google",component:e(ci,{})}].filter(s=>{var l;return((l=n.flags)==null?void 0:l.googleAuthEnabled)||s.label!=="Google"}),[a,i]=p.useState(0);return e("div",{children:e(Te,{permissions:Me,children:r(ee,{withTabs:!0,header:e(C,{condition:t==="enterprise",show:e(gt,{value:a,onChange:(s,l)=>{i(l)},indicatorColor:"primary",textColor:"primary",children:o.map((s,l)=>e(ft,{label:s.label,id:`tab-${l}`,"aria-controls":`tabpanel-${l}`,sx:{minWidth:{lg:160}}},`${s.label}_${l}`))})}),children:[e(C,{condition:t==="open-source",show:e(yt,{feature:"sso"})}),e(C,{condition:t==="demo",show:e(J,{severity:"warning",children:"You are running Unleash in demo mode. You have to use the Enterprise edition in order configure Single Sign-on."})}),e(C,{condition:t==="custom",show:e(J,{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(C,{condition:t==="hosted",show:e(J,{severity:"info",children:"Your Unleash instance is managed by the Unleash team."})}),e(C,{condition:t==="enterprise",show:e("div",{children:o.map((s,l)=>e(na,{value:a,index:l,children:s.component},l))})})]})})})},ui=oe("api/admin/invoices"),hi=g(z)(({theme:t})=>({width:"100%",marginBottom:t.spacing(1.5)})),pi=({update:t})=>e(hi,{href:`${ui}/${t?"portal":"checkout"}`,variant:t?"outlined":"contained",children:t?"Update billing information":"Add billing information"}),mi=g("aside")(({theme:t})=>({padding:t.spacing(4),height:"100%",borderRadius:t.shape.borderRadiusLarge,backgroundColor:t.palette.background.elevation2})),gi=g(D)(({theme:t})=>({marginBottom:t.spacing(4)})),fi=g(J)(({theme:t})=>({marginBottom:t.spacing(4)})),bn=g(D)(({theme:t})=>({fontSize:t.fontSizes.smallBody,color:t.palette.text.secondary})),yi=g(Ht)(({theme:t})=>({margin:`${t.spacing(2.5)} 0`,borderColor:t.palette.divider})),bi=({instanceStatus:t})=>{const n=t.state!==Kn.ACTIVE;return e(b,{item:!0,xs:12,md:5,children:r(mi,{children:[e(gi,{variant:"body1",children:"Billing information"}),e(C,{condition:n,show:r(fi,{severity:"warning",children:["In order to ",e("strong",{children:"Upgrade trial"})," you need to provide us your billing information."]})}),e(pi,{update:!n}),e(bn,{children:n?"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(yi,{}),r(bn,{children:[e("a",{href:"mailto:elise@getunleash.ai?subject=PRO plan clarifications",children:"Get in touch with us"})," ","for any clarification"]})]})})},Ee=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/user-admin"),Si);return p.useMemo(()=>({users:(t==null?void 0:t.users)??[],roles:(t==null?void 0:t.rootRoles)??[],loading:!n&&!t,refetch:()=>o(),error:n}),[t,n,o])},Si=t=>fetch(t).then(ue("Users")).then(n=>n.json()),vi=g(b)(({theme:t})=>({flexWrap:"nowrap",gap:t.spacing(1)})),st=({sx:t,children:n})=>e(vi,{container:!0,item:!0,justifyContent:"space-between",alignItems:"center",sx:t,children:n}),Be=({children:t,vertical:n=!1})=>e(b,{container:n,item:!0,display:"flex",alignItems:n?"start":"center",direction:n?"column":void 0,children:t}),Ci=g("span")(({theme:t})=>({fontSize:t.fontSizes.smallBody,marginLeft:t.spacing(1)})),Sn=({children:t})=>r(Ci,{children:["(",t,")"]}),wi=g("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)}})),vn=g(D)(({theme:t})=>({fontSize:t.fontSizes.smallBody,color:t.palette.text.secondary})),Ti=g("span")(({theme:t})=>({fontSize:"3.25rem",lineHeight:1,color:t.palette.primary.main,fontWeight:800})),xi=g("span")(({theme:t})=>({marginLeft:t.spacing(1.5),fontWeight:t.fontWeight.bold})),Ei=g("span")(({theme:t})=>({color:t.palette.primary.main,fontSize:t.fontSizes.mainHeader,fontWeight:t.fontWeight.bold})),ki=g(J)(({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=g(Zn)(({theme:t})=>({fontSize:"1rem",marginRight:t.spacing(1)})),Ai=g(Ht)(({theme:t})=>({margin:`${t.spacing(3)} 0`})),Di=({instanceStatus:t})=>{var f;const{users:n}=Ee(),o=oa(t),{uiConfig:a}=G(),i=n.filter(y=>y.email),s={[Ge.PRO]:80,[Ge.COMPANY]:0,[Ge.TEAM]:0,[Ge.ENTERPRISE]:0,[Ge.UNKNOWN]:0,user:15},l=s[t.plan],d=t.seats??5,u=Math.min(i.length,d),c=i.length-u,h=s.user*c,m=l+h,S=t.state!==Kn.ACTIVE;return e(b,{item:!0,xs:12,md:7,children:r(wi,{children:[e(C,{condition:S,show:r(ki,{severity:"info",children:["After you have sent your billing information, your instance will be upgraded - you don't have to do anything."," ",e("a",{href:"mailto:elise@getunleash.ai?subject=PRO plan clarifications",children:"Get in touch with us"})," ","for any clarification"]})}),e(Fe,{color:"success",children:"Current plan"}),e(b,{container:!0,children:r(st,{sx:y=>({marginBottom:y.spacing(3)}),children:[r(Be,{children:[e(Ti,{children:t.plan}),e(C,{condition:aa(t),show:e(xi,{sx:y=>({color:o?y.palette.error.dark:y.palette.warning.dark}),children:o?"Trial expired":t.trialExtended?"Extended Trial":"Trial"})})]}),e(Be,{children:e(C,{condition:l>0,show:r(Ei,{children:["$",l.toFixed(2)]})})})]})}),e(C,{condition:!!((f=a==null?void 0:a.flags)!=null&&f.proPlanAutoCharge&&t.plan===Ge.PRO),show:r(B,{children:[r(b,{container:!0,children:[r(st,{sx:y=>({marginBottom:y.spacing(1.5)}),children:[r(Be,{vertical:!0,children:[r(D,{children:[e("strong",{children:"Included members"}),e(Sn,{children:r(de,{to:"/admin/users",children:[u," of 5 assigned"]})})]}),e(vn,{children:"You have 5 team members included in your PRO plan"})]}),r(Be,{children:[e(Ri,{}),e(D,{variant:"body2",children:"included"})]})]}),r(st,{children:[r(Be,{vertical:!0,children:[r(D,{children:[e("strong",{children:"Paid members"}),e(Sn,{children:r(de,{to:"/admin/users",children:[c," assigned"]})})]}),e(vn,{children:"$15/month per paid member"})]}),e(Be,{children:r(D,{sx:y=>({fontSize:y.fontSizes.mainHeader}),children:["$",h.toFixed(2)]})})]})]}),e(Ai,{}),e(b,{container:!0,children:r(st,{children:[e(Be,{children:e(D,{sx:y=>({fontWeight:y.fontWeight.bold,fontSize:y.fontSizes.mainHeader}),children:"Total per month"})}),e(Be,{children:r(D,{sx:y=>({fontWeight:y.fontWeight.bold,fontSize:"2rem"}),children:["$",m.toFixed(2)]})})]})})]})})]})})},Ii=({instanceStatus:t})=>r(b,{container:!0,spacing:4,children:[e(bi,{instanceStatus:t}),e(Di,{instanceStatus:t})]}),Pi=g(D)(({theme:t})=>({marginTop:t.spacing(6),marginBottom:t.spacing(2.5),fontSize:t.fontSizes.mainHeader})),Bi=[{Header:"Amount",accessor:"amountFormatted"},{Header:"Status",accessor:"status",disableGlobalFilter:!0},{Header:"Created date",accessor:"created",Cell:ve,sortType:"date",disableGlobalFilter:!0},{Header:"Due date",accessor:"dueDate",Cell:ve,sortType:"date",disableGlobalFilter:!0},{Header:"Download",accessor:"invoicePDF",align:"center",Cell:({value:t})=>e(N,{sx:{display:"flex",justifyContent:"center"},"data-loading":!0,children:e(We,{href:t,children:e(la,{})})}),width:100,disableGlobalFilter:!0,disableSortBy:!0}],Ui=({data:t,isLoading:n=!1})=>{const o=p.useMemo(()=>({sortBy:[{id:"created"}]}),[]),{getTableProps:a,getTableBodyProps:i,headerGroups:s,rows:l,prepareRow:d}=$.useTable({columns:Bi,data:t,initialState:o,sortTypes:Se,autoResetGlobalFilter:!1,disableSortRemove:!0,defaultColumn:{Cell:te}},$.useGlobalFilter,$.useSortBy);return r(ee,{isLoading:n,disablePadding:!0,children:[e(Pi,{children:"Payment history"}),r(ra,{...a(),children:[e(ia,{headerGroups:s}),e(zt,{...i(),children:l.map(u=>(d(u),e(Xe,{hover:!0,...u.getRowProps(),children:u.cells.map(c=>e(sa,{...c.getCellProps(),children:c.render("Cell")}))})))})]}),e(C,{condition:l.length===0,show:e(fe,{children:"No invoices to show."})})]})},_t="api/admin/invoices",Li=oe(_t),xo=(t={})=>{const n=()=>fetch(Li,{method:"GET"}).then(ue("Invoices")).then(d=>d.json()),{data:o,error:a}=we(_t,n,t),[i,s]=p.useState(!a&&!o),l=()=>{Xn(_t)};return p.useEffect(()=>{s(!a&&!o)},[o,a]),{invoices:(o==null?void 0:o.invoices)||[],error:a,loading:i,refetchInvoices:l}},Oi=()=>{const{instanceStatus:t,isBilling:n,refetchInstanceStatus:o,refresh:a,loading:i}=Qn(),{invoices:s}=xo();return p.useEffect(()=>{(async()=>{await a(),o()})()},[o,a]),e("div",{children:e(ee,{header:"Billing",isLoading:i,children:e(C,{condition:n,show:e(Te,{permissions:Y,children:r(B,{children:[e(Ii,{instanceStatus:t}),e(Ui,{data:s})]})}),elseShow:e(J,{severity:"error",children:"Billing is not enabled for this instance."})})})})},$i=oe("api/admin/invoices/portal"),Ni=()=>{const{refetchInvoices:t,invoices:n}=xo(),[o,a]=p.useState(!1),{locationSettings:i}=eo();return p.useEffect(()=>{t(),a(!0)},[]),e(C,{condition:n.length>0,show:e(ee,{header:e(ne,{title:"Invoices",actions:e(z,{href:$i,rel:"noreferrer",target:"_blank",endIcon:e(ca,{}),children:"Billing portal"})}),children:e("div",{children:r(to,{children:[e(no,{children:r(Xe,{children:[e(ce,{children:"Amount"}),e(ce,{children:"Status"}),e(ce,{children:"Due date"}),e(ce,{children:"PDF"}),e(ce,{children:"Link"})]})}),e(zt,{children:n.map(s=>r(Xe,{style:{backgroundColor:s.status==="past-due"?"error.dark":"inherit"},children:[e(ce,{style:{textAlign:"left"},children:s.amountFormatted}),e(ce,{style:{textAlign:"left"},children:s.status}),e(ce,{style:{textAlign:"left"},children:s.dueDate&&oo(s.dueDate,i.locale)}),e(ce,{style:{textAlign:"left"},children:e("a",{href:s.invoicePDF,children:"PDF"})}),e(ce,{style:{textAlign:"left"},children:e("a",{href:s.invoiceURL,target:"_blank",rel:"noreferrer",children:"Payment link"})})]},s.invoiceURL))})]})})}),elseShow:e(ee,{children:o&&"No invoices to show."})})},Gi=()=>e("div",{children:e(Te,{permissions:Y,children:e(Ni,{})})}),Mi=()=>{const{uiConfig:t,loading:n}=G();return n?null:t.flags.UNLEASH_CLOUD?e(da,{to:"/admin/billing",replace:!0}):e(Gi,{})},ji=()=>r(J,{severity:"info",children:[r("p",{children:["Use this page to configure allowed CORS origins for the Frontend API (",e("code",{children:"/api/frontend"}),")."]}),r("p",{children:["This configuration will not affect the Admin API (",e("code",{children:"/api/admin"}),") nor the Client API (",e("code",{children:"/api/client"}),")."]}),r("p",{children:["An asterisk (",e("code",{children:"*"}),") may be used to allow API calls from any origin."]}),e("br",{}),e("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)."})]}),_i=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=$e({propagateErrors:!0});return{setFrontendSettings:async s=>{const d=n("api/admin/ui-config",{method:"POST",body:JSON.stringify({frontendSettings:{frontendApiOrigins:s}})},"setFrontendSettings");await t(d.caller,d.id)},loading:a,errors:o}},Wi=({frontendApiOrigins:t})=>{const{setFrontendSettings:n}=_i(),{setToastData:o,setToastApiError:a}=Z(),[i,s]=p.useState(Cn(t)),l=un(),d=un();return e("form",{onSubmit:async c=>{try{const h=Hi(i);c.preventDefault(),await n(h),s(Cn(h)),o({title:"Settings saved",type:"success"})}catch(h){a(K(h))}},children:r(N,{sx:{display:"grid",gap:1},children:[r("label",{htmlFor:l,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("br",{}),e("br",{}),'If you specify "*" it will be the chosen origin.',e("br",{}),e("br",{}),"Example:"]}),r("code",{style:{fontSize:"0.7em"},children:["https://www.example.com",e("br",{}),"https://www.example2.com"]}),e(Q,{id:l,"aria-describedby":d,placeholder:zi,value:i,onChange:c=>s(c.target.value),multiline:!0,rows:12,variant:"outlined",fullWidth:!0,InputProps:{style:{fontFamily:"monospace",fontSize:"0.8em"}}}),e(ao,{permission:Y})]})})},Hi=t=>t.split(/[,\n\s]+/).map(n=>n.replace(/\/$/,"")).filter(Boolean),Cn=t=>(t==null?void 0:t.join(`
5
5
  `))??"",zi=["https://example.com","https://example.org"].join(`
6
- `),Fi=()=>e("div",{children:e(Te,{permissions:Y,children:e(qi,{})})}),qi=()=>{const{uiConfig:t,loading:n}=G();return n?null:e(ee,{header:e(ne,{title:"CORS origins"}),children:r(N,{sx:{display:"grid",gap:4},children:[e(ji,{}),e(Hi,{frontendApiOrigins:t.frontendApiOrigins})]})})},_e=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/groups"),Vi);return p.useMemo(()=>({groups:(t==null?void 0:t.groups.map(a=>({...a,users:Lr(a.users??[])})))??[],loading:!n&&!t,refetchGroups:()=>o(),error:n}),[t,n,o])},Vi=t=>fetch(t).then(ue("Groups")).then(n=>n.json()),Yi=g(ro)(({theme:t})=>({pointerEvents:"none",".MuiPaper-root":{padding:t.spacing(2)}})),Ji=g("div")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1)})),Ki=({user:t,open:n,anchorEl:o,onPopoverClose:a})=>r(Yi,{open:n,anchorEl:o,onClose:a,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},children:[e(Ji,{children:(t==null?void 0:t.name)||(t==null?void 0:t.username)}),e("div",{children:t==null?void 0:t.email})]}),Zi=g("div")(({theme:t})=>({display:"inline-flex",alignItems:"center",flexWrap:"wrap",marginLeft:t.spacing(1)})),wn=g(We)(({theme:t})=>({outline:`${t.spacing(.25)} solid ${t.palette.background.paper}`,marginLeft:t.spacing(-1),"&:hover":{outlineColor:t.palette.primary.main}})),Xi=({users:t})=>{const n=p.useMemo(()=>t.sort((c,h)=>(h==null?void 0:h.joinedAt.getTime())-(c==null?void 0:c.joinedAt.getTime())).slice(0,9),[t]),[o,a]=p.useState(null),[i,s]=p.useState(),l=c=>{a(c.currentTarget)},d=()=>{a(null)},u=!!o;return r(Zi,{children:[n.map(c=>e(wn,{user:c,onMouseEnter:h=>{l(h),s(c)},onMouseLeave:d},c.id)),e(C,{condition:t.length>9,show:r(wn,{children:["+",t.length-n.length]})}),e(Ki,{open:u,user:i,anchorEl:o,onPopoverClose:d})]})},Qi=g("div")(({theme:t})=>({display:"flex",justifyContent:"center",transform:"translate3d(8px, -6px, 0)"})),es=g(ro)(({theme:t})=>({borderRadius:t.shape.borderRadiusLarge,padding:t.spacing(1,1.5)})),ts=({groupId:t,onEditUsers:n,onRemove:o})=>{const[a,i]=p.useState(null),s=!!a,l=h=>{i(h.currentTarget)},d=()=>{i(null)},u=`feature-${t}-actions`,c=`${u}-menu`;return r(Qi,{onClick:h=>{h.preventDefault(),h.stopPropagation()},children:[e(Le,{title:"Group actions",arrow:!0,describeChild:!0,children:e(He,{id:u,"aria-controls":s?c:void 0,"aria-haspopup":"true","aria-expanded":s?"true":void 0,onClick:l,type:"button",children:e(ua,{})})}),e(es,{id:c,anchorEl:a,open:s,onClose:d,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},disableScrollLock:!0,children:r(ha,{"aria-labelledby":u,children:[r(Re,{onClick:d,component:de,to:`/admin/groups/${t}/edit`,children:[e(It,{children:e(Qe,{})}),e(Pt,{children:e(D,{variant:"body2",children:"Edit group"})})]}),r(Re,{onClick:()=>{n(),d()},children:[e(It,{children:e(qr,{})}),e(Pt,{children:e(D,{variant:"body2",children:"Edit group users"})})]}),r(Re,{onClick:()=>{o(),d()},children:[e(It,{children:e(Ue,{})}),e(Pt,{children:e(D,{variant:"body2",children:"Delete group"})})]})]})})]})},ns=g(de)(({theme:t})=>({textDecoration:"none",color:t.palette.text.primary})),os=g("aside")(({theme:t})=>({padding:t.spacing(2.5),height:"100%",border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadiusLarge,boxShadow:t.boxShadows.card,display:"flex",flexDirection:"column",[t.breakpoints.up("md")]:{padding:t.spacing(4)},"&:hover":{transition:"background-color 0.2s ease-in-out",backgroundColor:t.palette.neutral.light}})),Eo=g("div")(()=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),as=g(Eo)(()=>({alignItems:"flex-start"})),rs=g(Eo)(()=>({marginTop:"auto"})),is=g("h2")(({theme:t})=>({fontSize:t.fontSizes.mainHeader,fontWeight:t.fontWeight.medium})),ss=g("div")(({theme:t})=>({display:"flex",alignItems:"center",color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody})),ls=g("p")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1),marginBottom:t.spacing(4)})),cs=g("span")(({theme:t})=>({color:t.palette.text.secondary,marginLeft:t.spacing(1)})),ds=g("div")(({theme:t})=>({maxWidth:"50%",display:"flex",justifyContent:"flex-end",gap:t.spacing(.5),flexWrap:"wrap"})),us=g("span")(({theme:t})=>({display:"flex",color:t.palette.text.secondary,alignItems:"center",gap:t.spacing(1),fontSize:t.fontSizes.smallBody})),hs=({group:t,onEditUsers:n,onRemoveGroup:o})=>{var i;const a=ye();return e(B,{children:e(ns,{to:`/admin/groups/${t.id}`,children:r(os,{children:[r(as,{children:[e(is,{children:t.name}),e(ss,{children:e(ts,{groupId:t.id,onEditUsers:()=>n(t),onRemove:()=>o(t)})})]}),e(C,{condition:!!t.rootRole,show:r(us,{children:[e("p",{children:"Root role:"}),e(pa,{roleId:t.rootRole})]})}),e(ls,{children:t.description}),r(rs,{children:[e(C,{condition:((i=t.users)==null?void 0:i.length)>0,show:e(Xi,{users:t.users}),elseShow:e(cs,{children:"This group has no users."})}),e(ds,{children:e(C,{condition:t.projects.length>0,show:t.projects.map(s=>e(Le,{title:"View project",arrow:!0,placement:"bottom-end",describeChild:!0,children:e(Fe,{onClick:l=>{l.preventDefault(),a(`/projects/${s}/settings/access`)},color:"secondary",icon:e(ma,{}),children:s})},s)),elseShow:e(Le,{title:"This group is not used in any project",arrow:!0,describeChild:!0,children:e(C,{condition:!t.rootRole,show:e(Fe,{children:"Not used"})})})})})]})]})},t.id)})},ps=()=>{const t=g("div")(({theme:o})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",margin:o.spacing(6),marginLeft:"auto",marginRight:"auto"})),n=g(D)(({theme:o})=>({fontSize:o.fontSizes.bodySize,marginBottom:o.spacing(2.5)}));return r(t,{children:[e(n,{children:"No groups available. Get started by adding a new group."}),e(z,{to:"/admin/groups/create-group",component:de,variant:"outlined",color:"primary",children:"Create your first group"})]})},at=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=$e({propagateErrors:!0});return{createGroup:async d=>{const c=n("api/admin/groups",{method:"POST",body:JSON.stringify(d)});try{return await(await t(c.caller,c.id)).json()}catch(h){throw h}},updateGroup:async(d,u)=>{const c=`api/admin/groups/${d}`,h=n(c,{method:"PUT",body:JSON.stringify(u)});try{await t(h.caller,h.id)}catch(m){throw m}},removeGroup:async d=>{const u=`api/admin/groups/${d}`,c=n(u,{method:"DELETE"});try{await t(c.caller,c.id)}catch(h){throw h}},errors:o,loading:a}},rt=()=>{const{isEnterprise:t}=G(),{data:n,error:o,mutate:a}=bt(t(),{serviceAccounts:[],rootRoles:[]},oe("api/admin/service-account"),ms);return p.useMemo(()=>({serviceAccounts:(n==null?void 0:n.serviceAccounts)??[],roles:(n==null?void 0:n.rootRoles)??[],loading:!o&&!n,refetch:()=>a(),error:o}),[n,o,a])},ms=t=>fetch(t).then(ue("Service Accounts")).then(n=>n.json()),gs=g("div")(({theme:t})=>({display:"flex",flexDirection:"column","& > span:first-of-type":{color:t.palette.text.secondary}})),fs=g("div")(({theme:t})=>({paddingLeft:t.spacing(1)})),ys=g("div")(({theme:t})=>({display:"flex",marginBottom:t.spacing(3),"& > div:first-of-type":{width:"100%",maxWidth:t.spacing(50),marginRight:t.spacing(1)}})),bs=(t,n,o)=>r("li",{...t,children:[e(io,{icon:e(ya,{fontSize:"small"}),checkedIcon:e(ba,{fontSize:"small"}),style:{marginRight:8},checked:o}),r(gs,{children:[e("span",{children:n.name||n.username}),e("span",{children:n.name&&n.username?n.username:n.email})]})]}),Ss=t=>e(fs,{children:t.length>1?`${t.length} users selected`:t[0].name||t[0].username||t[0].email}),ko=({users:t,setUsers:n})=>{const{users:o}=Ee(),{serviceAccounts:a}=rt(),i=[...o.map(s=>({...s,type:"USERS"})).sort((s,l)=>{const d=s.name||s.username||"",u=l.name||l.username||"";return d.localeCompare(u)}),...a.map(s=>({...s,type:"SERVICE ACCOUNTS"})).sort((s,l)=>{const d=s.name||s.username||"",u=l.name||l.username||"";return d.localeCompare(u)})];return e(ys,{children:e(ga,{"data-testid":fa,size:"small",multiple:!0,limitTags:1,openOnFocus:!0,disableCloseOnSelect:!0,value:t,onChange:(s,l,d)=>{s.type==="keydown"&&s.key==="Backspace"&&d==="removeOption"||n(l)},groupBy:s=>s.type,options:i,renderOption:(s,l,{selected:d})=>bs(s,l,d),filterOptions:(s,{inputValue:l})=>s.filter(({name:d,username:u,email:c})=>Bt(l,c)||Bt(l,d)||Bt(l,u)),isOptionEqualToValue:(s,l)=>s.id===l.id,getOptionLabel:s=>s.email||s.name||s.username||"",renderInput:s=>e(Q,{...s,label:"Select users"}),renderTags:s=>Ss(s)})})},vs=["imageUrl","name"],Ro=({users:t,setUsers:n})=>{const o=fe(Oe.breakpoints.down("md")),a=p.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:c}})=>e(te,{children:e(We,{user:c})}),maxWidth:85,disableSortBy:!0},{id:"name",Header:"Name",accessor:c=>c.name||"",Cell:({value:c,row:{original:h}})=>e(Ce,{value:c,subtitle:h.email||h.username}),minWidth:100,searchable:!0},{Header:"Action",id:"Action",align:"center",Cell:({row:{original:c}})=>e(pt,{children:e(Le,{title:"Remove user from group",arrow:!0,describeChild:!0,children:e(He,{onClick:()=>n(h=>h.filter(m=>m.id!==c.id)),children:e(Ue,{})})})}),maxWidth:100,disableSortBy:!0},{accessor:c=>c.username||"",Header:"Username",searchable:!0},{accessor:c=>c.email||"",Header:"Email",searchable:!0}],[n]),[i]=p.useState(()=>({hiddenColumns:["Username","Email"]})),{headerGroups:s,rows:l,prepareRow:d,setHiddenColumns:u}=$.useTable({columns:a,data:t,initialState:i,sortTypes:be,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return et([{condition:o,columns:vs}],u,a),e(C,{condition:l.length>0,show:e(xe,{rows:l,headerGroups:s,prepareRow:d})})},on=(t="",n="",o=[],a=[],i=null)=>{const l=Sa().get("name"),[d,u]=p.useState(l||t),[c,h]=p.useState(n),[m,S]=p.useState(o),[f,y]=p.useState(a),[v,T]=p.useState(i),[w,k]=p.useState({});return{name:d,setName:u,description:c,setDescription:h,mappingsSSO:m,setMappingsSSO:S,users:f,setUsers:y,getGroupPayload:()=>({name:d,description:c,mappingsSSO:m,users:f.map(({id:P})=>({user:{id:P}})),rootRole:v||void 0}),clearErrors:()=>{k({})},errors:w,setErrors:k,rootRole:v,setRootRole:T}},Cs=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ws=g("p")(({theme:t})=>({color:t.palette.text.secondary,marginBottom:t.spacing(1)})),Ts=g("div")(()=>({marginTop:"auto",display:"flex",justifyContent:"flex-end"})),xs=g(z)(({theme:t})=>({marginLeft:t.spacing(3)})),Es=g(N)(({theme:t})=>({marginTop:t.spacing(2)})),Ao=({open:t,setOpen:n,group:o})=>{const{refetchGroup:a}=vt(o.id),{refetchGroups:i}=_e(),{updateGroup:s,loading:l}=at(),{setToastData:d,setToastApiError:u}=Z(),{uiConfig:c}=G(),{users:h,setUsers:m,getGroupPayload:S}=on(o.name,o.description,o.mappingsSSO,o.users,o.rootRole);return p.useEffect(()=>{m(o.users)},[o.users,t,m]),e(Ft,{open:t,onClose:()=>{n(!1)},label:"Edit users",children:e(Pe,{loading:l,modal:!0,title:"Edit users",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/advanced/groups",documentationLinkLabel:"Groups documentation",formatApiCode:()=>`curl --location --request PUT '${c.unleashUrl}/api/admin/groups/${o.id}' \\
6
+ `),Fi=()=>e("div",{children:e(Te,{permissions:Y,children:e(qi,{})})}),qi=()=>{const{uiConfig:t,loading:n}=G();return n?null:e(ee,{header:e(ne,{title:"CORS origins"}),children:r(N,{sx:{display:"grid",gap:4},children:[e(ji,{}),e(Wi,{frontendApiOrigins:t.frontendApiOrigins})]})})},_e=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/groups"),Vi);return p.useMemo(()=>({groups:(t==null?void 0:t.groups.map(a=>({...a,users:Ur(a.users??[])})))??[],loading:!n&&!t,refetchGroups:()=>o(),error:n}),[t,n,o])},Vi=t=>fetch(t).then(ue("Groups")).then(n=>n.json()),Yi=g(ro)(({theme:t})=>({pointerEvents:"none",".MuiPaper-root":{padding:t.spacing(2)}})),Ji=g("div")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1)})),Ki=({user:t,open:n,anchorEl:o,onPopoverClose:a})=>r(Yi,{open:n,anchorEl:o,onClose:a,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},children:[e(Ji,{children:(t==null?void 0:t.name)||(t==null?void 0:t.username)}),e("div",{children:t==null?void 0:t.email})]}),Zi=g("div")(({theme:t})=>({display:"inline-flex",alignItems:"center",flexWrap:"wrap",marginLeft:t.spacing(1)})),wn=g(He)(({theme:t})=>({outline:`${t.spacing(.25)} solid ${t.palette.background.paper}`,marginLeft:t.spacing(-1),"&:hover":{outlineColor:t.palette.primary.main}})),Xi=({users:t})=>{const n=p.useMemo(()=>t.sort((c,h)=>(h==null?void 0:h.joinedAt.getTime())-(c==null?void 0:c.joinedAt.getTime())).slice(0,9),[t]),[o,a]=p.useState(null),[i,s]=p.useState(),l=c=>{a(c.currentTarget)},d=()=>{a(null)},u=!!o;return r(Zi,{children:[n.map(c=>e(wn,{user:c,onMouseEnter:h=>{l(h),s(c)},onMouseLeave:d},c.id)),e(C,{condition:t.length>9,show:r(wn,{children:["+",t.length-n.length]})}),e(Ki,{open:u,user:i,anchorEl:o,onPopoverClose:d})]})},Qi=g("div")(({theme:t})=>({display:"flex",justifyContent:"center",transform:"translate3d(8px, -6px, 0)"})),es=g(ro)(({theme:t})=>({borderRadius:t.shape.borderRadiusLarge,padding:t.spacing(1,1.5)})),ts=({groupId:t,onEditUsers:n,onRemove:o})=>{const[a,i]=p.useState(null),s=!!a,l=h=>{i(h.currentTarget)},d=()=>{i(null)},u=`feature-${t}-actions`,c=`${u}-menu`;return r(Qi,{onClick:h=>{h.preventDefault(),h.stopPropagation()},children:[e(Ue,{title:"Group actions",arrow:!0,describeChild:!0,children:e(We,{id:u,"aria-controls":s?c:void 0,"aria-haspopup":"true","aria-expanded":s?"true":void 0,onClick:l,type:"button",children:e(ua,{})})}),e(es,{id:c,anchorEl:a,open:s,onClose:d,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},disableScrollLock:!0,children:r(ha,{"aria-labelledby":u,children:[r(Re,{onClick:d,component:de,to:`/admin/groups/${t}/edit`,children:[e(It,{children:e(Qe,{})}),e(Pt,{children:e(D,{variant:"body2",children:"Edit group"})})]}),r(Re,{onClick:()=>{n(),d()},children:[e(It,{children:e(qr,{})}),e(Pt,{children:e(D,{variant:"body2",children:"Edit group users"})})]}),r(Re,{onClick:()=>{o(),d()},children:[e(It,{children:e(Le,{})}),e(Pt,{children:e(D,{variant:"body2",children:"Delete group"})})]})]})})]})},ns=g(de)(({theme:t})=>({textDecoration:"none",color:t.palette.text.primary})),os=g("aside")(({theme:t})=>({padding:t.spacing(2.5),height:"100%",border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadiusLarge,boxShadow:t.boxShadows.card,display:"flex",flexDirection:"column",[t.breakpoints.up("md")]:{padding:t.spacing(4)},"&:hover":{transition:"background-color 0.2s ease-in-out",backgroundColor:t.palette.neutral.light}})),Eo=g("div")(()=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),as=g(Eo)(()=>({alignItems:"flex-start"})),rs=g(Eo)(()=>({marginTop:"auto"})),is=g("h2")(({theme:t})=>({fontSize:t.fontSizes.mainHeader,fontWeight:t.fontWeight.medium})),ss=g("div")(({theme:t})=>({display:"flex",alignItems:"center",color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody})),ls=g("p")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1),marginBottom:t.spacing(4)})),cs=g("span")(({theme:t})=>({color:t.palette.text.secondary,marginLeft:t.spacing(1)})),ds=g("div")(({theme:t})=>({maxWidth:"50%",display:"flex",justifyContent:"flex-end",gap:t.spacing(.5),flexWrap:"wrap"})),us=g("span")(({theme:t})=>({display:"flex",color:t.palette.text.secondary,alignItems:"center",gap:t.spacing(1),fontSize:t.fontSizes.smallBody})),hs=({group:t,onEditUsers:n,onRemoveGroup:o})=>{var i;const a=be();return e(B,{children:e(ns,{to:`/admin/groups/${t.id}`,children:r(os,{children:[r(as,{children:[e(is,{children:t.name}),e(ss,{children:e(ts,{groupId:t.id,onEditUsers:()=>n(t),onRemove:()=>o(t)})})]}),e(C,{condition:!!t.rootRole,show:r(us,{children:[e("p",{children:"Root role:"}),e(pa,{roleId:t.rootRole})]})}),e(ls,{children:t.description}),r(rs,{children:[e(C,{condition:((i=t.users)==null?void 0:i.length)>0,show:e(Xi,{users:t.users}),elseShow:e(cs,{children:"This group has no users."})}),e(ds,{children:e(C,{condition:t.projects.length>0,show:t.projects.map(s=>e(Ue,{title:"View project",arrow:!0,placement:"bottom-end",describeChild:!0,children:e(Fe,{onClick:l=>{l.preventDefault(),a(`/projects/${s}/settings/access`)},color:"secondary",icon:e(ma,{}),children:s})},s)),elseShow:e(Ue,{title:"This group is not used in any project",arrow:!0,describeChild:!0,children:e(C,{condition:!t.rootRole,show:e(Fe,{children:"Not used"})})})})})]})]})},t.id)})},ps=()=>{const t=g("div")(({theme:o})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",margin:o.spacing(6),marginLeft:"auto",marginRight:"auto"})),n=g(D)(({theme:o})=>({fontSize:o.fontSizes.bodySize,marginBottom:o.spacing(2.5)}));return r(t,{children:[e(n,{children:"No groups available. Get started by adding a new group."}),e(z,{to:"/admin/groups/create-group",component:de,variant:"outlined",color:"primary",children:"Create your first group"})]})},at=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=$e({propagateErrors:!0});return{createGroup:async d=>{const c=n("api/admin/groups",{method:"POST",body:JSON.stringify(d)});try{return await(await t(c.caller,c.id)).json()}catch(h){throw h}},updateGroup:async(d,u)=>{const c=`api/admin/groups/${d}`,h=n(c,{method:"PUT",body:JSON.stringify(u)});try{await t(h.caller,h.id)}catch(m){throw m}},removeGroup:async d=>{const u=`api/admin/groups/${d}`,c=n(u,{method:"DELETE"});try{await t(c.caller,c.id)}catch(h){throw h}},errors:o,loading:a}},rt=()=>{const{isEnterprise:t}=G(),{data:n,error:o,mutate:a}=bt(t(),{serviceAccounts:[],rootRoles:[]},oe("api/admin/service-account"),ms);return p.useMemo(()=>({serviceAccounts:(n==null?void 0:n.serviceAccounts)??[],roles:(n==null?void 0:n.rootRoles)??[],loading:!o&&!n,refetch:()=>a(),error:o}),[n,o,a])},ms=t=>fetch(t).then(ue("Service Accounts")).then(n=>n.json()),gs=g("div")(({theme:t})=>({display:"flex",flexDirection:"column","& > span:first-of-type":{color:t.palette.text.secondary}})),fs=g("div")(({theme:t})=>({paddingLeft:t.spacing(1)})),ys=g("div")(({theme:t})=>({display:"flex",marginBottom:t.spacing(3),"& > div:first-of-type":{width:"100%",maxWidth:t.spacing(50),marginRight:t.spacing(1)}})),bs=(t,n,o)=>r("li",{...t,children:[e(io,{icon:e(ya,{fontSize:"small"}),checkedIcon:e(ba,{fontSize:"small"}),style:{marginRight:8},checked:o}),r(gs,{children:[e("span",{children:n.name||n.username}),e("span",{children:n.name&&n.username?n.username:n.email})]})]}),Ss=t=>e(fs,{children:t.length>1?`${t.length} users selected`:t[0].name||t[0].username||t[0].email}),ko=({users:t,setUsers:n})=>{const{users:o}=Ee(),{serviceAccounts:a}=rt(),i=[...o.map(s=>({...s,type:"USERS"})).sort((s,l)=>{const d=s.name||s.username||"",u=l.name||l.username||"";return d.localeCompare(u)}),...a.map(s=>({...s,type:"SERVICE ACCOUNTS"})).sort((s,l)=>{const d=s.name||s.username||"",u=l.name||l.username||"";return d.localeCompare(u)})];return e(ys,{children:e(ga,{"data-testid":fa,size:"small",multiple:!0,limitTags:1,openOnFocus:!0,disableCloseOnSelect:!0,value:t,onChange:(s,l,d)=>{s.type==="keydown"&&s.key==="Backspace"&&d==="removeOption"||n(l)},groupBy:s=>s.type,options:i,renderOption:(s,l,{selected:d})=>bs(s,l,d),filterOptions:(s,{inputValue:l})=>s.filter(({name:d,username:u,email:c})=>Bt(l,c)||Bt(l,d)||Bt(l,u)),isOptionEqualToValue:(s,l)=>s.id===l.id,getOptionLabel:s=>s.email||s.name||s.username||"",renderInput:s=>e(Q,{...s,label:"Select users"}),renderTags:s=>Ss(s)})})},vs=["imageUrl","name"],Ro=({users:t,setUsers:n})=>{const o=ye(Oe.breakpoints.down("md")),a=p.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:c}})=>e(te,{children:e(He,{user:c})}),maxWidth:85,disableSortBy:!0},{id:"name",Header:"Name",accessor:c=>c.name||"",Cell:({value:c,row:{original:h}})=>e(Ce,{value:c,subtitle:h.email||h.username}),minWidth:100,searchable:!0},{Header:"Action",id:"Action",align:"center",Cell:({row:{original:c}})=>e(pt,{children:e(Ue,{title:"Remove user from group",arrow:!0,describeChild:!0,children:e(We,{onClick:()=>n(h=>h.filter(m=>m.id!==c.id)),children:e(Le,{})})})}),maxWidth:100,disableSortBy:!0},{accessor:c=>c.username||"",Header:"Username",searchable:!0},{accessor:c=>c.email||"",Header:"Email",searchable:!0}],[n]),[i]=p.useState(()=>({hiddenColumns:["Username","Email"]})),{headerGroups:s,rows:l,prepareRow:d,setHiddenColumns:u}=$.useTable({columns:a,data:t,initialState:i,sortTypes:Se,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return et([{condition:o,columns:vs}],u,a),e(C,{condition:l.length>0,show:e(xe,{rows:l,headerGroups:s,prepareRow:d})})},on=(t="",n="",o=[],a=[],i=null)=>{const l=Sa().get("name"),[d,u]=p.useState(l||t),[c,h]=p.useState(n),[m,S]=p.useState(o),[f,y]=p.useState(a),[v,T]=p.useState(i),[w,k]=p.useState({});return{name:d,setName:u,description:c,setDescription:h,mappingsSSO:m,setMappingsSSO:S,users:f,setUsers:y,getGroupPayload:()=>({name:d,description:c,mappingsSSO:m,users:f.map(({id:P})=>({user:{id:P}})),rootRole:v||void 0}),clearErrors:()=>{k({})},errors:w,setErrors:k,rootRole:v,setRootRole:T}},Cs=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ws=g("p")(({theme:t})=>({color:t.palette.text.secondary,marginBottom:t.spacing(1)})),Ts=g("div")(()=>({marginTop:"auto",display:"flex",justifyContent:"flex-end"})),xs=g(z)(({theme:t})=>({marginLeft:t.spacing(3)})),Es=g(N)(({theme:t})=>({marginTop:t.spacing(2)})),Ao=({open:t,setOpen:n,group:o})=>{const{refetchGroup:a}=vt(o.id),{refetchGroups:i}=_e(),{updateGroup:s,loading:l}=at(),{setToastData:d,setToastApiError:u}=Z(),{uiConfig:c}=G(),{users:h,setUsers:m,getGroupPayload:S}=on(o.name,o.description,o.mappingsSSO,o.users,o.rootRole);return p.useEffect(()=>{m(o.users)},[o.users,t,m]),e(Ft,{open:t,onClose:()=>{n(!1)},label:"Edit users",children:e(Pe,{loading:l,modal:!0,title:"Edit users",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/advanced/groups",documentationLinkLabel:"Groups documentation",formatApiCode:()=>`curl --location --request PUT '${c.unleashUrl}/api/admin/groups/${o.id}' \\
7
7
  --header 'Authorization: INSERT_API_KEY' \\
8
8
  --header 'Content-Type: application/json' \\
9
- --data-raw '${JSON.stringify(S(),void 0,2)}'`,children:r(Cs,{onSubmit:async v=>{v.preventDefault();try{await s(o.id,S()),a(),i(),n(!1),d({title:"Group users saved successfully",type:"success"})}catch(T){u(K(T))}},children:[r("div",{children:[e(ws,{children:"Edit users in this group"}),e(ko,{users:h,setUsers:m}),e(Ro,{users:h,setUsers:m})]}),e(Ts,{children:r(Es,{children:[e(z,{type:"submit",variant:"contained",color:"primary","data-testid":so,children:"Save"}),e(xs,{onClick:()=>{n(!1)},children:"Cancel"})]})})]})})})},Do=({open:t,setOpen:n,group:o})=>{const{refetchGroups:a}=_e(),{removeGroup:i}=at(),{setToastData:s,setToastApiError:l}=Z(),d=ye();return e(ie,{open:t,primaryButtonText:"Delete group",secondaryButtonText:"Cancel",onClick:async()=>{try{await i(o.id),a(),n(!1),d("/admin/groups"),s({title:"Group removed successfully",type:"success"})}catch(c){l(K(c))}},onClose:()=>{n(!1)},title:"Delete group?",children:r(D,{children:["Do you really want to delete ",e("strong",{children:o.name}),"? Users who are granted access to projects only via this group will lose access to those projects."]})})},ks=(t,n)=>{var i,s,l,d,u,c;const o=n.toLowerCase(),a={names:(i=t.users)==null?void 0:i.map(h=>{var m;return((m=h.name)==null?void 0:m.toLowerCase())||""}),usernames:(s=t.users)==null?void 0:s.map(h=>{var m;return((m=h.username)==null?void 0:m.toLowerCase())||""}),emails:(l=t.users)==null?void 0:l.map(h=>{var m;return((m=h.email)==null?void 0:m.toLowerCase())||""})};return t.name.toLowerCase().includes(o)||t.description.toLowerCase().includes(o)||((d=a.names)==null?void 0:d.some(h=>h.includes(o)))||((u=a.usernames)==null?void 0:u.some(h=>h.includes(o)))||((c=a.emails)==null?void 0:c.some(h=>h.includes(o)))},Rs=()=>{const t=ye(),[n,o]=p.useState(!1),[a,i]=p.useState(!1),[s,l]=p.useState(void 0),{groups:d=[],loading:u}=_e(),[c,h]=lo(),[m,S]=p.useState(c.get("search")||""),f=fe(Oe.breakpoints.down("md"));p.useEffect(()=>{const w={};m&&(w.search=m),h(w,{replace:!0})},[m,h]);const y=p.useMemo(()=>{const w=d.sort((k,E)=>k.name.localeCompare(E.name));return m?w.filter(k=>ks(k,m)):w},[d,m]),v=w=>{l(w),o(!0)},T=w=>{l(w),i(!0)};return r(ee,{isLoading:u,header:e(ne,{title:`Groups (${y.length})`,actions:r(B,{children:[e(C,{condition:!f,show:r(B,{children:[e(pe,{initialValue:m,onChange:S}),e(ne.Divider,{})]})}),e(qt,{onClick:()=>t("/admin/groups/create-group"),maxWidth:"700px",Icon:St,permission:Y,"data-testid":va,children:"New group"})]}),children:e(C,{condition:f,show:e(pe,{initialValue:m,onChange:S})})}),children:[e(qe,{value:m,children:e(b,{container:!0,spacing:2,children:y.map(w=>e(b,{item:!0,xs:12,md:6,children:e(hs,{group:w,onEditUsers:v,onRemoveGroup:T})},w.id))})}),e(C,{condition:!u&&y.length===0,show:e(C,{condition:(m==null?void 0:m.length)>0,show:r(ge,{children:["No groups found matching “",m,"”"]}),elseShow:e(ps,{})})}),e(C,{condition:!!s,show:e(Ao,{open:n,setOpen:o,group:s})}),e(C,{condition:!!s,show:e(Do,{open:a,setOpen:i,group:s})})]})},As=g("div")(({theme:t})=>({display:"flex",marginBottom:t.spacing(1),"& > div:first-of-type":{width:"100%",marginRight:t.spacing(1),"& > div:first-of-type":{width:"100%"}}})),Ds=({label:t,value:n,onChange:o,...a})=>{const[i,s]=p.useState(""),l=()=>{o(u=>[...u,i]),s("")},d=u=>{o(c=>c.filter(h=>h!==u))};return r("div",{...a,children:[r(As,{children:[e(tt,{label:t,value:i,onChange:u=>s(u.target.value),onKeyPress:u=>{u.key==="Enter"&&l()}}),e(z,{startIcon:e(St,{}),onClick:l,variant:"outlined",color:"primary",disabled:!i.trim()||n.includes(i),children:"Add"})]}),e(zr,{flexDirection:"row",flexWrap:"wrap",gap:1,children:n==null?void 0:n.map((u,c)=>e(Ca,{label:u,onDelete:()=>d(u)},c))})]})},Is=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Ke=g("p")(({theme:t})=>({color:t.palette.text.secondary,marginBottom:t.spacing(1)})),Tn=g(tt)(({theme:t})=>({width:"100%",maxWidth:t.spacing(60),marginBottom:t.spacing(2)})),Ps=g(Ds)(({theme:t})=>({width:"100%",maxWidth:t.spacing(60),marginBottom:t.spacing(2)})),Bs=g("div")(({theme:t})=>({marginBottom:t.spacing(6)})),Ls=g("div")(()=>({marginTop:"auto",display:"flex",justifyContent:"flex-end"})),Us=g(z)(({theme:t})=>({marginLeft:t.spacing(3)})),Os=g("div")(({theme:t})=>({width:"100%",maxWidth:t.spacing(60),padding:t.spacing(3),backgroundColor:t.palette.neutral.light,color:t.palette.text.primary,fontSize:t.fontSizes.smallBody,borderRadius:t.shape.borderRadiusMedium,marginBottom:t.spacing(2),a:{color:t.palette.links}})),$s=g("div")(({theme:t})=>({"& > div:first-of-type":{width:"100%",maxWidth:t.spacing(50),marginBottom:t.spacing(2)}})),Io=({name:t,description:n,mappingsSSO:o,users:a,rootRole:i,setName:s,setDescription:l,setMappingsSSO:d,setUsers:u,handleSubmit:c,handleCancel:h,setRootRole:m,errors:S,mode:f,children:y})=>{const{config:v}=ze("oidc"),{config:T}=ze("saml"),{roles:w}=Ee(),k=(v==null?void 0:v.enabled)&&v.enableGroupSyncing||(T==null?void 0:T.enabled)&&T.enableGroupSyncing,E=x=>w.find(P=>P.id===x)||null;return r(Is,{onSubmit:c,children:[r("div",{children:[e(Ke,{children:"What would you like to call your group?"}),e(Tn,{autoFocus:!0,label:"Name",id:"group-name",error:!!S.name,errorText:S.name,value:t,onChange:x=>s(x.target.value),"data-testid":wa,required:!0}),e(Ke,{children:"How would you describe your group?"}),e(Tn,{multiline:!0,rows:4,label:"Description",placeholder:"A short description of the group",value:n,onChange:x=>l(x.target.value),"data-testid":Ta}),e(C,{condition:k,show:r(B,{children:[e(Ke,{children:"Is this group associated with SSO groups?"}),e(Ps,{label:"SSO group ID / name",value:o,onChange:d})]}),elseShow:()=>r(Os,{children:[r(N,{sx:{display:"flex"},children:["You can enable SSO groups synchronization if needed",e(hn,{tooltip:"SSO groups synchronization allows SSO groups to be mapped to Unleash groups, so that user group membership is properly synchronized."})]}),e(de,{"data-loading":!0,to:"/admin/auth",children:e("span",{"data-loading":!0,children:"View SSO configuration"})})]})}),e(Ke,{children:r(N,{sx:{display:"flex"},children:["Do you want to associate a root role with this group?",e(hn,{tooltip:"When you associate an Admin or Editor role with this group, users in this group will automatically inherit the role globally. Note that groups with a root role association cannot be assigned to projects."})]})}),e($s,{children:e(en,{"data-testid":"GROUP_ROOT_ROLE",roles:w,value:E(i),setValue:x=>m((x==null?void 0:x.id)||null)})}),e(C,{condition:f==="Create",show:r(B,{children:[e(Ke,{children:"Add users to this group"}),e(ko,{users:a,setUsers:u}),e(Bs,{children:e(Ro,{users:a,setUsers:u})})]})})]}),r(Ls,{children:[y,e(Us,{onClick:h,children:"Cancel"})]})]})},Ns=()=>{const{setToastData:t,setToastApiError:n}=Z(),{uiConfig:o}=G(),a=ye(),{name:i,setName:s,description:l,setDescription:d,mappingsSSO:u,setMappingsSSO:c,users:h,setUsers:m,rootRole:S,setRootRole:f,getGroupPayload:y,clearErrors:v,errors:T,setErrors:w}=on(),{groups:k}=_e(),{createGroup:E,loading:x}=at(),P=async U=>{if(U.preventDefault(),v(),!O)return;const X=y();try{const R=await E(X);a(`/admin/groups/${R.id}`),t({title:"Group created successfully",text:"Now you can start using your group.",confetti:!0,type:"success"})}catch(R){n(K(R))}},M=()=>`curl --location --request POST '${o.unleashUrl}/api/admin/groups' \\
9
+ --data-raw '${JSON.stringify(S(),void 0,2)}'`,children:r(Cs,{onSubmit:async v=>{v.preventDefault();try{await s(o.id,S()),a(),i(),n(!1),d({title:"Group users saved successfully",type:"success"})}catch(T){u(K(T))}},children:[r("div",{children:[e(ws,{children:"Edit users in this group"}),e(ko,{users:h,setUsers:m}),e(Ro,{users:h,setUsers:m})]}),e(Ts,{children:r(Es,{children:[e(z,{type:"submit",variant:"contained",color:"primary","data-testid":so,children:"Save"}),e(xs,{onClick:()=>{n(!1)},children:"Cancel"})]})})]})})})},Do=({open:t,setOpen:n,group:o})=>{const{refetchGroups:a}=_e(),{removeGroup:i}=at(),{setToastData:s,setToastApiError:l}=Z(),d=be();return e(ie,{open:t,primaryButtonText:"Delete group",secondaryButtonText:"Cancel",onClick:async()=>{try{await i(o.id),a(),n(!1),d("/admin/groups"),s({title:"Group removed successfully",type:"success"})}catch(c){l(K(c))}},onClose:()=>{n(!1)},title:"Delete group?",children:r(D,{children:["Do you really want to delete ",e("strong",{children:o.name}),"? Users who are granted access to projects only via this group will lose access to those projects."]})})},ks=(t,n)=>{var i,s,l,d,u,c;const o=n.toLowerCase(),a={names:(i=t.users)==null?void 0:i.map(h=>{var m;return((m=h.name)==null?void 0:m.toLowerCase())||""}),usernames:(s=t.users)==null?void 0:s.map(h=>{var m;return((m=h.username)==null?void 0:m.toLowerCase())||""}),emails:(l=t.users)==null?void 0:l.map(h=>{var m;return((m=h.email)==null?void 0:m.toLowerCase())||""})};return t.name.toLowerCase().includes(o)||t.description.toLowerCase().includes(o)||((d=a.names)==null?void 0:d.some(h=>h.includes(o)))||((u=a.usernames)==null?void 0:u.some(h=>h.includes(o)))||((c=a.emails)==null?void 0:c.some(h=>h.includes(o)))},Rs=()=>{const t=be(),[n,o]=p.useState(!1),[a,i]=p.useState(!1),[s,l]=p.useState(void 0),{groups:d=[],loading:u}=_e(),[c,h]=lo(),[m,S]=p.useState(c.get("search")||""),f=ye(Oe.breakpoints.down("md"));p.useEffect(()=>{const w={};m&&(w.search=m),h(w,{replace:!0})},[m,h]);const y=p.useMemo(()=>{const w=d.sort((k,E)=>k.name.localeCompare(E.name));return m?w.filter(k=>ks(k,m)):w},[d,m]),v=w=>{l(w),o(!0)},T=w=>{l(w),i(!0)};return r(ee,{isLoading:u,header:e(ne,{title:`Groups (${y.length})`,actions:r(B,{children:[e(C,{condition:!f,show:r(B,{children:[e(me,{initialValue:m,onChange:S}),e(ne.Divider,{})]})}),e(qt,{onClick:()=>t("/admin/groups/create-group"),maxWidth:"700px",Icon:St,permission:Y,"data-testid":va,children:"New group"})]}),children:e(C,{condition:f,show:e(me,{initialValue:m,onChange:S})})}),children:[e(qe,{value:m,children:e(b,{container:!0,spacing:2,children:y.map(w=>e(b,{item:!0,xs:12,md:6,children:e(hs,{group:w,onEditUsers:v,onRemoveGroup:T})},w.id))})}),e(C,{condition:!u&&y.length===0,show:e(C,{condition:(m==null?void 0:m.length)>0,show:r(fe,{children:["No groups found matching “",m,"”"]}),elseShow:e(ps,{})})}),e(C,{condition:!!s,show:e(Ao,{open:n,setOpen:o,group:s})}),e(C,{condition:!!s,show:e(Do,{open:a,setOpen:i,group:s})})]})},As=g("div")(({theme:t})=>({display:"flex",marginBottom:t.spacing(1),"& > div:first-of-type":{width:"100%",marginRight:t.spacing(1),"& > div:first-of-type":{width:"100%"}}})),Ds=({label:t,value:n,onChange:o,...a})=>{const[i,s]=p.useState(""),l=()=>{o(u=>[...u,i]),s("")},d=u=>{o(c=>c.filter(h=>h!==u))};return r("div",{...a,children:[r(As,{children:[e(tt,{label:t,value:i,onChange:u=>s(u.target.value),onKeyPress:u=>{u.key==="Enter"&&l()}}),e(z,{startIcon:e(St,{}),onClick:l,variant:"outlined",color:"primary",disabled:!i.trim()||n.includes(i),children:"Add"})]}),e(zr,{flexDirection:"row",flexWrap:"wrap",gap:1,children:n==null?void 0:n.map((u,c)=>e(Ca,{label:u,onDelete:()=>d(u)},c))})]})},Is=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Ke=g("p")(({theme:t})=>({color:t.palette.text.secondary,marginBottom:t.spacing(1)})),Tn=g(tt)(({theme:t})=>({width:"100%",maxWidth:t.spacing(60),marginBottom:t.spacing(2)})),Ps=g(Ds)(({theme:t})=>({width:"100%",maxWidth:t.spacing(60),marginBottom:t.spacing(2)})),Bs=g("div")(({theme:t})=>({marginBottom:t.spacing(6)})),Us=g("div")(()=>({marginTop:"auto",display:"flex",justifyContent:"flex-end"})),Ls=g(z)(({theme:t})=>({marginLeft:t.spacing(3)})),Os=g("div")(({theme:t})=>({width:"100%",maxWidth:t.spacing(60),padding:t.spacing(3),backgroundColor:t.palette.neutral.light,color:t.palette.text.primary,fontSize:t.fontSizes.smallBody,borderRadius:t.shape.borderRadiusMedium,marginBottom:t.spacing(2),a:{color:t.palette.links}})),$s=g("div")(({theme:t})=>({"& > div:first-of-type":{width:"100%",maxWidth:t.spacing(50),marginBottom:t.spacing(2)}})),Io=({name:t,description:n,mappingsSSO:o,users:a,rootRole:i,setName:s,setDescription:l,setMappingsSSO:d,setUsers:u,handleSubmit:c,handleCancel:h,setRootRole:m,errors:S,mode:f,children:y})=>{const{config:v}=ze("oidc"),{config:T}=ze("saml"),{roles:w}=Ee(),k=(v==null?void 0:v.enabled)&&v.enableGroupSyncing||(T==null?void 0:T.enabled)&&T.enableGroupSyncing,E=x=>w.find(P=>P.id===x)||null;return r(Is,{onSubmit:c,children:[r("div",{children:[e(Ke,{children:"What would you like to call your group?"}),e(Tn,{autoFocus:!0,label:"Name",id:"group-name",error:!!S.name,errorText:S.name,value:t,onChange:x=>s(x.target.value),"data-testid":wa,required:!0}),e(Ke,{children:"How would you describe your group?"}),e(Tn,{multiline:!0,rows:4,label:"Description",placeholder:"A short description of the group",value:n,onChange:x=>l(x.target.value),"data-testid":Ta}),e(C,{condition:k,show:r(B,{children:[e(Ke,{children:"Is this group associated with SSO groups?"}),e(Ps,{label:"SSO group ID / name",value:o,onChange:d})]}),elseShow:()=>r(Os,{children:[r(N,{sx:{display:"flex"},children:["You can enable SSO groups synchronization if needed",e(hn,{tooltip:"SSO groups synchronization allows SSO groups to be mapped to Unleash groups, so that user group membership is properly synchronized."})]}),e(de,{"data-loading":!0,to:"/admin/auth",children:e("span",{"data-loading":!0,children:"View SSO configuration"})})]})}),e(Ke,{children:r(N,{sx:{display:"flex"},children:["Do you want to associate a root role with this group?",e(hn,{tooltip:"When you associate an Admin or Editor role with this group, users in this group will automatically inherit the role globally. Note that groups with a root role association cannot be assigned to projects."})]})}),e($s,{children:e(en,{"data-testid":"GROUP_ROOT_ROLE",roles:w,value:E(i),setValue:x=>m((x==null?void 0:x.id)||null)})}),e(C,{condition:f==="Create",show:r(B,{children:[e(Ke,{children:"Add users to this group"}),e(ko,{users:a,setUsers:u}),e(Bs,{children:e(Ro,{users:a,setUsers:u})})]})})]}),r(Us,{children:[y,e(Ls,{onClick:h,children:"Cancel"})]})]})},Ns=()=>{const{setToastData:t,setToastApiError:n}=Z(),{uiConfig:o}=G(),a=be(),{name:i,setName:s,description:l,setDescription:d,mappingsSSO:u,setMappingsSSO:c,users:h,setUsers:m,rootRole:S,setRootRole:f,getGroupPayload:y,clearErrors:v,errors:T,setErrors:w}=on(),{groups:k}=_e(),{createGroup:E,loading:x}=at(),P=async L=>{if(L.preventDefault(),v(),!O)return;const X=y();try{const R=await E(X);a(`/admin/groups/${R.id}`),t({title:"Group created successfully",text:"Now you can start using your group.",confetti:!0,type:"success"})}catch(R){n(K(R))}},M=()=>`curl --location --request POST '${o.unleashUrl}/api/admin/groups' \\
10
10
  --header 'Authorization: INSERT_API_KEY' \\
11
11
  --header 'Content-Type: application/json' \\
12
- --data-raw '${JSON.stringify(y(),void 0,2)}'`,L=()=>{a(De)},I=U=>U.length,F=U=>!(k!=null&&k.filter(X=>X.name===U).length),O=I(i)&&F(i);return e(Pe,{loading:x,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/advanced/groups",documentationLinkLabel:"Groups documentation",formatApiCode:M,children:e(Io,{name:i,description:l,mappingsSSO:u,rootRole:S,users:h,setName:U=>{v(),F(U)||w({name:"A group with that name already exists."}),s(U)},setDescription:d,setMappingsSSO:c,setRootRole:f,setUsers:m,errors:T,handleSubmit:P,handleCancel:L,mode:xa,children:e(z,{type:"submit",variant:"contained",color:"primary",disabled:!O,"data-testid":Ea,children:"Create group"})})})},Gs=()=>{const t=Number(Vt("groupId")),{group:n,refetchGroup:o}=vt(t);return n?e(Ms,{group:n,groupId:t,refetchGroup:o}):null},Ms=({group:t,groupId:n,refetchGroup:o})=>{const{refetchGroups:a}=_e(),{setToastData:i,setToastApiError:s}=Z(),{uiConfig:l}=G(),d=ye(),{name:u,setName:c,description:h,setDescription:m,mappingsSSO:S,setMappingsSSO:f,users:y,setUsers:v,rootRole:T,setRootRole:w,getGroupPayload:k,clearErrors:E,errors:x,setErrors:P}=on(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:M}=_e(),{updateGroup:L,loading:I}=at(),F=async q=>{q.preventDefault(),E();const se=k();try{await L(n,se),o(),a(),d(De),i({title:"Group updated successfully",type:"success"})}catch(ae){s(K(ae))}},O=()=>`curl --location --request PUT '${l.unleashUrl}/api/admin/groups/${n}' \\
12
+ --data-raw '${JSON.stringify(y(),void 0,2)}'`,U=()=>{a(De)},I=L=>L.length,F=L=>!(k!=null&&k.filter(X=>X.name===L).length),O=I(i)&&F(i);return e(Pe,{loading:x,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/advanced/groups",documentationLinkLabel:"Groups documentation",formatApiCode:M,children:e(Io,{name:i,description:l,mappingsSSO:u,rootRole:S,users:h,setName:L=>{v(),F(L)||w({name:"A group with that name already exists."}),s(L)},setDescription:d,setMappingsSSO:c,setRootRole:f,setUsers:m,errors:T,handleSubmit:P,handleCancel:U,mode:xa,children:e(z,{type:"submit",variant:"contained",color:"primary",disabled:!O,"data-testid":Ea,children:"Create group"})})})},Gs=()=>{const t=Number(Vt("groupId")),{group:n,refetchGroup:o}=vt(t);return n?e(Ms,{group:n,groupId:t,refetchGroup:o}):null},Ms=({group:t,groupId:n,refetchGroup:o})=>{const{refetchGroups:a}=_e(),{setToastData:i,setToastApiError:s}=Z(),{uiConfig:l}=G(),d=be(),{name:u,setName:c,description:h,setDescription:m,mappingsSSO:S,setMappingsSSO:f,users:y,setUsers:v,rootRole:T,setRootRole:w,getGroupPayload:k,clearErrors:E,errors:x,setErrors:P}=on(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:M}=_e(),{updateGroup:U,loading:I}=at(),F=async q=>{q.preventDefault(),E();const se=k();try{await U(n,se),o(),a(),d(De),i({title:"Group updated successfully",type:"success"})}catch(ae){s(K(ae))}},O=()=>`curl --location --request PUT '${l.unleashUrl}/api/admin/groups/${n}' \\
13
13
  --header 'Authorization: INSERT_API_KEY' \\
14
14
  --header 'Content-Type: application/json' \\
15
- --data-raw '${JSON.stringify(k(),void 0,2)}'`,A=()=>{d(De)},U=q=>q.length,X=q=>!(M!=null&&M.filter(se=>se.name===q&&se.id!==n).length),R=U(u)&&X(u);return e(Pe,{loading:I,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/advanced/groups",documentationLinkLabel:"Groups documentation",formatApiCode:O,children:e(Io,{name:u,description:h,mappingsSSO:S,users:y,rootRole:T,setName:q=>{E(),X(q)||P({name:"A group with that name already exists."}),c(q)},setDescription:m,setMappingsSSO:f,setUsers:v,setRootRole:w,errors:x,handleSubmit:F,handleCancel:A,mode:Yt,children:e(z,{type:"submit",variant:"contained",color:"primary",disabled:!R,"data-testid":so,children:"Save"})})})},js=g(co)(({theme:t})=>({borderRadius:t.shape.borderRadiusLarge,padding:t.spacing(2.5,4),boxShadow:"none",marginBottom:t.spacing(2),fontSize:t.fontSizes.smallBody})),_s=g("div")(({theme:t})=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),Hs=g("h1")(({theme:t})=>({fontSize:t.fontSizes.mainHeader})),Ws=g("div")(({theme:t})=>({display:"flex"})),zs=g("span")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginLeft:t.spacing(1)})),Fs=({title:t,description:n,actions:o})=>(qn(t),r(js,{children:[r(_s,{children:[e(Hs,{children:t}),e(Ws,{children:o})]}),e(C,{condition:!!(n!=null&&n.length),show:r(B,{children:["Description:",e(zs,{children:n})]})})]})),qs=({open:t,setOpen:n,user:o,group:a})=>{const{refetchGroup:i}=vt(a.id),{updateGroup:s}=at(),{setToastData:l,setToastApiError:d}=Z(),u=async()=>{try{const h={...a,users:a.users.filter(({id:m})=>m!==(o==null?void 0:o.id)).map(({id:m})=>({user:{id:m}}))};await s(a.id,h),i(),n(!1),l({title:"User removed from group successfully",type:"success"})}catch(h){d(K(h))}},c=(o==null?void 0:o.name)||(o==null?void 0:o.username)||(o==null?void 0:o.email);return e(ie,{open:t&&!!o,primaryButtonText:"Remove user",secondaryButtonText:"Cancel",onClick:u,onClose:()=>{n(!1)},title:"Remove user from group?",children:r(D,{children:["Do you really want to remove ",e("strong",{children:c})," from"," ",e("strong",{children:a.name}),"? ",e("strong",{children:c})," will lose all access rights granted by this group."]})})},Vs=Array(15).fill({name:"Name of the user",username:"Username of the user"}),Ys={id:"joinedAt"},{value:xn,setValue:Js}=ka("Group:v1",Ys),Ks=()=>{const t=Number(Vt("groupId")),n=Jt(),o=fe(n.breakpoints.down("md")),{group:a,loading:i}=vt(t),[s,l]=p.useState(!1),[d,u]=p.useState(!1),[c,h]=p.useState(!1),[m,S]=p.useState(),f=p.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:A}})=>e(te,{children:e(We,{user:A})}),maxWidth:85,disableSortBy:!0},{id:"name",Header:"Name",accessor:A=>A.name||"",Cell:({value:A,row:{original:U}})=>e(Ce,{value:A,subtitle:U.email||U.username}),minWidth:100,searchable:!0},{Header:"Joined",accessor:"joinedAt",Cell:ve,sortType:"date",maxWidth:150},{id:"createdBy",Header:"Added by",accessor:"createdBy",Cell:Ce,minWidth:90,searchable:!0},{Header:"Last login",accessor:A=>A.seenAt||"",Cell:({row:{original:A}})=>e(Ve,{value:A.seenAt,emptyText:"Never",title:U=>`Last login: ${U}`}),sortType:"date",maxWidth:150},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:A}})=>e(pt,{children:e(Le,{title:"Remove user from group",arrow:!0,describeChild:!0,children:e("span",{children:e(He,{"data-testid":`${Ra}-${A.id}`,onClick:()=>{S(A),h(!0)},children:e(Ue,{})})})})}),maxWidth:100,disableSortBy:!0},{accessor:A=>A.username||"",Header:"Username",searchable:!0},{accessor:A=>A.email||"",Header:"Email",searchable:!0}],[S,h]),[y,v]=lo(),[T]=p.useState(()=>({sortBy:[{id:y.get("sort")||xn.id,desc:y.has("order")?y.get("order")==="desc":xn.desc}],hiddenColumns:["Username","Email"],globalFilter:y.get("search")||""})),[w,k]=p.useState(T.globalFilter),{data:E,getSearchText:x,getSearchContext:P}=nt(f,w,(a==null?void 0:a.users)??[]),M=p.useMemo(()=>(E==null?void 0:E.length)===0&&i?Vs:E,[E,i]),{headerGroups:L,rows:I,prepareRow:F,state:{sortBy:O}}=$.useTable({columns:f,data:M,initialState:T,sortTypes:be,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return p.useEffect(()=>{const A={};A.sort=O[0].id,O[0].desc&&(A.order="desc"),w&&(A.search=w),v(A,{replace:!0}),Js({id:O[0].id,desc:O[0].desc||!1})},[O,w,v]),e(C,{condition:!!a,show:r(B,{children:[e(Fs,{title:a==null?void 0:a.name,description:a==null?void 0:a.description,actions:r(B,{children:[e(Ae,{"data-testid":Aa,to:`/admin/groups/${t}/edit`,component:de,"data-loading":!0,permission:Y,tooltipProps:{title:"Edit group"},children:e(Qe,{})}),e(Ae,{"data-testid":Da,"data-loading":!0,onClick:()=>l(!0),permission:Y,tooltipProps:{title:"Delete group"},children:e(Ue,{})})]})}),r(ee,{isLoading:i,header:e(ne,{secondary:!0,title:`Users (${I.length<M.length?`${I.length} of ${M.length}`:M.length})`,actions:r(B,{children:[e(C,{condition:!o,show:r(B,{children:[e(pe,{initialValue:w,onChange:k,hasFilters:!0,getSearchContext:P}),e(ne.Divider,{})]})}),e(qt,{"data-testid":Ia,onClick:()=>{u(!0)},maxWidth:"700px",Icon:St,permission:Y,children:"Edit users"})]}),children:e(C,{condition:o,show:e(pe,{initialValue:w,onChange:k,hasFilters:!0,getSearchContext:P})})}),children:[e(qe,{value:x(w),children:e(xe,{rows:I,headerGroups:L,prepareRow:F})}),e(C,{condition:I.length===0,show:e(C,{condition:(w==null?void 0:w.length)>0,show:r(ge,{children:["No users found matching “",w,"” in this group."]}),elseShow:e(ge,{children:"This group is empty. Get started by adding a user to the group."})})}),e(Do,{open:s,setOpen:l,group:a}),e(Ao,{open:d,setOpen:u,group:a}),e(qs,{open:c,setOpen:h,user:m,group:a})]})]})})},Zs=()=>{const{uiConfig:t,isEnterprise:n}=G();return n()||t.flags[Pa]===!0?e("div",{children:e(Te,{permissions:Me,children:r(ot,{children:[e(H,{index:!0,element:e(Rs,{})}),e(H,{path:"create-group",element:e(Ns,{})}),e(H,{path:":groupId/edit",element:e(Gs,{})}),e(H,{path:":groupId",element:e(Ks,{})})]})})}):e(yt,{feature:"groups",page:!0})},Xs=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/instance-admin/statistics"),Qs);return p.useMemo(()=>({stats:t,loading:!n&&!t,refetchGroup:()=>o(),error:n}),[t,n,o])},Qs=t=>fetch(t).then(ue("Instance Stats")).then(n=>n.json()),el=()=>{const{stats:t}=Xs();let n,o;t!=null&&t.versionEnterprise?(n="Unleash Enterprise version",o=t.versionEnterprise):(n="Unleash OSS version",o=t==null?void 0:t.versionOSS);const a=[{title:"Instance Id",value:t==null?void 0:t.instanceId},{title:n,value:o},{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&&a.push({title:"SAML enabled",value:t!=null&&t.SAMLenabled?"Yes":"No"},{title:"OIDC enabled",value:t!=null&&t.OIDCenabled?"Yes":"No"}),e(ee,{header:e(ne,{title:"Instance Statistics"}),children:r(Ur,{sx:{display:"grid",gap:4},children:[r(to,{"aria-label":"Instance statistics",children:[e(no,{children:r(Xe,{children:[e(ce,{children:"Field"}),e(ce,{align:"right",children:"Value"})]})}),e(zt,{children:a.map(i=>r(Xe,{children:[e(ce,{component:"th",scope:"row",children:i.title}),e(ce,{align:"right",children:i.value})]},i.title))})]}),e("span",{style:{textAlign:"center"},children:e(z,{startIcon:e(Ba,{}),"aria-label":"Download instance statistics",color:"primary",variant:"contained",target:"_blank",rel:"noreferrer",href:oe("/api/admin/instance-admin/statistics/csv"),children:"Download"})})]})})},tl=()=>e("div",{children:e(el,{})}),nl=g("div")(({theme:t})=>({display:"flex",flexDirection:"column",padding:t.spacing(3),border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadiusLarge})),ol=g(N)(()=>({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"})),al=g(N)(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(2)})),rl=g("p")(({theme:t})=>({display:"table-cell",fontWeight:t.fontWeight.bold,paddingTop:t.spacing(2)})),il=g("p")(({theme:t})=>({display:"table-cell",paddingTop:t.spacing(2),paddingLeft:t.spacing(4)})),sl=g("div")(({theme:t})=>({display:"table-cell",width:"75%",paddingTop:t.spacing(2),paddingBottom:t.spacing(2)})),ll=g("div")(({theme:t})=>({display:"table-cell"})),cl=g("span")(({theme:t})=>({display:"block",textAlign:"right",color:t.palette.neutral.dark})),dl=g("div")(({theme:t})=>({maxWidth:t.spacing(50),color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody})),ul=g("div")(()=>({display:"table-row"})),En=g("div")(()=>({display:"table"})),hl=g("div")(()=>({display:"table-cell"})),pl=({changeInfoText:t,variablesText:n,dependsOnText:o})=>r(dl,{children:[e(kn,{children:t}),e(ml,{children:e("div",{children:n})}),e(C,{condition:!!o,show:e(kn,{children:o})})]}),ml=g("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})),kn=g("p")(({theme:t})=>({color:t.palette.text.primary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1)})),Rn=({title:t,infoText:n,concreteDetails:o,enabled:a,changeInfoText:i,variablesText:s,dependsOnText:l})=>r(nl,{children:[r(ol,{children:[e("b",{children:t}),e(ll,{children:e(C,{condition:a,show:e(Fe,{color:"success",icon:e(Zn,{}),children:"Data is collected"}),elseShow:e(Fe,{color:"neutral",icon:e(Or,{}),children:"No data is collected"})})})]}),r(al,{children:[r(En,{children:[e(sl,{children:n}),e(hl,{children:e(cl,{children:e(Kt,{tooltip:e(pl,{changeInfoText:i,variablesText:s,dependsOnText:l}),children:a?"How to disable collecting data?":"How to enable collecting data?"})})})]}),e(En,{children:Object.entries(o).map(([d,u])=>r(ul,{children:[e(rl,{children:d}),e(il,{children:u})]},d))})]})]}),gl=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/telemetry/settings"),fl);return p.useMemo(()=>({settings:t,loading:!n&&!t,refetchGroup:()=>o(),error:n}),[t,n,o])},fl=t=>fetch(t).then(ue("Telemetry Settings")).then(n=>n.json()),yl=g(N)(({theme:t})=>({display:"grid",gap:t.spacing(4)})),Ot={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"}},$t={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"}},An={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."}},Dn={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."}},bl=()=>{const{settings:t}=gl(),{loading:n}=G();if(n)return null;const o=t!=null&&t.versionInfoCollectionEnabled?An.enabled:An.disabled,a=t!=null&&t.featureInfoCollectionEnabled?Dn.enabled:Dn.disabled;let i;return t!=null&&t.versionInfoCollectionEnabled||(i=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(ee,{header:e(ne,{title:"Instance Privacy"}),children:r(yl,{children:[e(Rn,{title:Ot.title,infoText:Ot.infoText,concreteDetails:Ot.concreteDetails,enabled:t==null?void 0:t.versionInfoCollectionEnabled,changeInfoText:o.changeInfoText,variablesText:o.environmentVariables}),e(Rn,{title:$t.title,infoText:$t.infoText,concreteDetails:$t.concreteDetails,enabled:(t==null?void 0:t.featureInfoCollectionEnabled)&&(t==null?void 0:t.versionInfoCollectionEnabled),changeInfoText:a.changeInfoText,variablesText:a.environmentVariables,dependsOnText:i})]})})},Sl=()=>e(J,{severity:"warning",children:r("p",{children:[e("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."]})}),vl=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/maintenance"),Cl);return p.useMemo(()=>({enabled:!!(t!=null&&t.enabled),loading:!n&&!t,refetchMaintenance:o,error:n}),[t,n,o])},Cl=t=>fetch(t).then(ue("Maintenance")).then(n=>n.json()),wl=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=$e({propagateErrors:!0});return{toggleMaintenance:async s=>{const d=n("api/admin/maintenance",{method:"POST",body:JSON.stringify(s)});try{await t(d.caller,d.id)}catch(u){throw u}},errors:o,loading:a}},Tl=g("div")(({theme:t})=>({display:"flex",flexDirection:"column",padding:t.spacing(3),border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadiusLarge})),xl=g(N)(({theme:t})=>({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"})),El=g(N)(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(2)})),kl=g(D)(({theme:t})=>({fontSize:t.fontSizes.smallBody})),Rl=()=>{const{enabled:t,refetchMaintenance:n}=vl(),{toggleMaintenance:o}=wl(),{trackEvent:a}=Zt(),{setToastData:i}=Z();return r(Tl,{children:[r(xl,{children:[e("b",{children:"Maintenance Mode"}),e(me,{sx:{margin:0},control:e(Se,{onChange: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}),n()},value:t,name:"enabled",checked:t}),label:e(kl,{children:t?"Enabled":"Disabled"})})]}),e(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."})]})},Al=()=>e("div",{children:e(Te,{permissions:Y,children:e(Il,{})})}),Dl=g(N)(({theme:t})=>({display:"grid",gap:t.spacing(4)})),Il=()=>{const{loading:t}=G();return t?null:e(ee,{header:e(ne,{title:"Maintenance"}),children:r(Dl,{children:[e(Sl,{}),e(Rl,{})]})})},Pl=g(La)(({theme:t})=>({display:"flex",justifyContent:"center",alignItems:"center",width:"100%",height:"100%",textDecoration:"none",color:"inherit",padding:t.spacing(0,5),"&.active":{fontWeight:"bold"}})),an=({to:t,children:n})=>e(Pl,{to:t,children:n}),Bl=p.lazy(()=>uo(()=>import("./NetworkOverview-c762698b.js").then(t=>t.N),[])),Ll=p.lazy(()=>uo(()=>import("./NetworkTraffic-c8d9eb9b.js"),[])),Ul=[{label:"Overview",path:"/admin/network"},{label:"Traffic",path:"/admin/network/traffic"}],Ol=()=>{const{pathname:t}=Xt();return e("div",{children:e(ee,{withTabs:!0,header:e(gt,{value:t,indicatorColor:"primary",textColor:"primary",variant:"scrollable",allowScrollButtonsMobile:!0,children:Ul.map(({label:n,path:o})=>e(ft,{value:o,label:e(an,{to:o,children:e("span",{children:n})}),sx:{padding:0}},n))}),children:r(ot,{children:[e(H,{path:"traffic",element:e(Ll,{})}),e(H,{path:"*",element:e(Bl,{})})]})})})},$l=g(N)(()=>({display:"flex",justifyContent:"center"})),Nl=({role:t,onEdit:n,onDelete:o})=>{const a=je.includes(t.type);return r($l,{children:[e(Ae,{"data-loading":!0,onClick:n,permission:Y,disabled:a,tooltipProps:{title:a?"You cannot edit a predefined role":"Edit role"},children:e(Qe,{})}),e(Ae,{"data-loading":!0,onClick:o,permission:Y,disabled:a,tooltipProps:{title:a?"You cannot remove a predefined role":"Remove role"},children:e(Ue,{})})]})},Gl=g(Fe)(({theme:t})=>({marginLeft:t.spacing(1)})),Ml=({role:t})=>e(Ce,{value:t.name,subtitle:t.description,afterTitle:e(C,{condition:je.includes(t.type),show:e(Gl,{color:"success",children:"Predefined"})})}),jl=({users:t})=>{const[n]=p.useState(()=>({sortBy:[{id:"last-login"}]})),o=p.useMemo(()=>[{id:"name",Header:"Name",accessor:l=>l.name||"",minWidth:200,Cell:({row:{original:l}})=>e(Ce,{value:l.name,subtitle:l.email||l.username})},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",width:120,maxWidth:120},{id:"last-login",Header:"Last login",accessor:l=>l.seenAt||"",Cell:({row:{original:l}})=>e(Ve,{value:l.seenAt,emptyText:"Never",title:d=>`Last login: ${d}`}),sortType:"date",maxWidth:150}],[]),{headerGroups:a,rows:i,prepareRow:s}=$.useTable({columns:o,data:t,initialState:n,sortTypes:be,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return e(xe,{rows:i,headerGroups:a,prepareRow:s})},_l=g(D)(({theme:t})=>({fontSize:t.fontSizes.smallerBody})),Po=({serviceAccount:t,value:n,onCreateToken:o})=>{var i,s,l;const{searchQuery:a}=Ua();return!t.tokens||t.tokens.length===0?o?e(ho,{title:"Create token",onClick:o}):e(te,{children:"0 tokens"}):e(te,{children:e(Kt,{tooltip:e(B,{children:(i=t.tokens)==null?void 0:i.map(({id:d,description:u})=>e(_l,{children:e(Oa,{search:a,children:u})},d))}),highlighted:a.length>0&&n.toLowerCase().includes(a.toLowerCase()),children:((s=t.tokens)==null?void 0:s.length)===1?"1 token":`${(l=t.tokens)==null?void 0:l.length} tokens`})})},Hl=({serviceAccounts:t})=>{const[n]=p.useState(()=>({sortBy:[{id:"seenAt"}]})),o=p.useMemo(()=>[{id:"name",Header:"Name",accessor:l=>l.name||"",minWidth:200,Cell:({row:{original:l}})=>e(Ce,{value:l.name,subtitle:l.username})},{id:"tokens",Header:"Tokens",accessor:l=>{var d;return((d=l.tokens)==null?void 0:d.map(({description:u})=>u).join(`
16
- `))||""},Cell:({row:{original:l},value:d})=>e(Po,{serviceAccount:l,value:d}),maxWidth:100},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",width:120,maxWidth:120},{id:"seenAt",Header:"Last seen",accessor:l=>{var d;return(d=l.tokens.sort((u,c)=>{const h=new Date(u.seenAt||0),m=new Date(c.seenAt||0);return(m==null?void 0:m.getTime())-(h==null?void 0:h.getTime())})[0])==null?void 0:d.seenAt},Cell:Ve,sortType:"date",maxWidth:150}],[]),{headerGroups:a,rows:i,prepareRow:s}=$.useTable({columns:o,data:t,initialState:n,sortTypes:be,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return e(xe,{rows:i,headerGroups:a,prepareRow:s})},Wl=({groups:t})=>{const[n]=p.useState(()=>({sortBy:[{id:"createdAt"}]})),o=p.useMemo(()=>[{id:"name",Header:"Name",accessor:l=>l.name||"",minWidth:200,Cell:({row:{original:l}})=>e(Ce,{value:l.name,subtitle:l.description})},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",width:120,maxWidth:120},{id:"users",Header:"Users",accessor:l=>l.users.length===1?"1 user":`${l.users.length} users`,Cell:te,maxWidth:150}],[]),{headerGroups:a,rows:i,prepareRow:s}=$.useTable({columns:o,data:t,initialState:n,sortTypes:be,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return e(xe,{rows:i,headerGroups:a,prepareRow:s})},Nt=g("div")(({theme:t})=>({marginTop:t.spacing(1.5)})),Gt=g("p")(({theme:t})=>({marginTop:t.spacing(3)})),zl=({role:t,open:n,setOpen:o,onConfirm:a})=>{const{users:i}=Ee(),{serviceAccounts:s}=rt(),{groups:l}=_e(),d=i.filter(({rootRole:m})=>m===(t==null?void 0:t.id)),u=s.filter(({rootRole:m})=>m===(t==null?void 0:t.id)),c=l==null?void 0:l.filter(({rootRole:m})=>m===(t==null?void 0:t.id)),h=!!(d.length||u.length||c!=null&&c.length);return e(ie,{title:"Delete root role?",open:n,primaryButtonText:"Delete role",secondaryButtonText:"Cancel",disabledPrimaryButton:h,onClick:()=>a(t),onClose:()=>{o(!1)},children:e(C,{condition:h,show:r(B,{children:[e(J,{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(C,{condition:!!d.length,show:r(B,{children:[r(Gt,{children:["Users (",d.length,"):"]}),e(Nt,{children:e(jl,{users:d})})]})}),e(C,{condition:!!u.length,show:r(B,{children:[r(Gt,{children:["Service accounts (",u.length,"):"]}),e(Nt,{children:e(Hl,{serviceAccounts:u})})]})}),e(C,{condition:!!(c!=null&&c.length),show:r(B,{children:[r(Gt,{children:["Groups (",c==null?void 0:c.length,"):"]}),e(Nt,{children:e(Wl,{groups:c})})]})})]}),elseShow:r("p",{children:["You are about to delete role:"," ",e("strong",{children:t==null?void 0:t.name})]})})})},Fl=t=>{const{isEnterprise:n}=G(),{data:o,error:a,mutate:i}=bt(n()&&t,{projects:[]},oe(`api/admin/projects/roles/${t}/access`),ql);return p.useMemo(()=>({projects:(o==null?void 0:o.projects)??[],loading:!a&&!o,refetch:()=>i(),error:a}),[o,a,i])},ql=t=>fetch(t).then(ue("Project role usage")).then(n=>n.json()),Vl=({projects:t})=>{const[n]=p.useState(()=>({sortBy:[{id:"name"}]})),o=p.useMemo(()=>[{id:"name",Header:"Project name",accessor:l=>l.project||"",minWidth:200,Cell:({row:{original:l}})=>e(ho,{title:l.project,to:`/projects/${l.project}`})},{id:"users",Header:"Assigned users",accessor:l=>l.userCount===1?"1 user":`${l.userCount} users`,Cell:te,maxWidth:150},{id:"serviceAccounts",Header:"Service accounts",accessor:l=>l.serviceAccountCount===1?"1 account":`${l.serviceAccountCount} accounts`,Cell:te,maxWidth:150},{id:"groups",Header:"Assigned groups",accessor:l=>l.groupCount===1?"1 group":`${l.groupCount} groups`,Cell:te,maxWidth:150}],[]),{headerGroups:a,rows:i,prepareRow:s}=$.useTable({columns:o,data:t,initialState:n,sortTypes:be,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return e(xe,{rows:i,headerGroups:a,prepareRow:s})},Yl=g("div")(({theme:t})=>({marginTop:t.spacing(1.5)})),Jl=g("p")(({theme:t})=>({marginTop:t.spacing(3)})),Kl=({role:t,open:n,setOpen:o,onConfirm:a})=>{const{projects:i}=Fl(t==null?void 0:t.id),s=!!(i!=null&&i.length);return e(ie,{title:"Delete project role?",open:n,primaryButtonText:"Delete role",secondaryButtonText:"Cancel",disabledPrimaryButton:s,onClick:()=>a(t),onClose:()=>{o(!1)},maxWidth:"md",children:e(C,{condition:s,show:r(B,{children:[e(J,{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(C,{condition:!!(i!=null&&i.length),show:r(B,{children:[r(Jl,{children:["Role assigned in ",i==null?void 0:i.length," ","projects:"]}),e(Yl,{children:e(Vl,{projects:i})})]})})]}),elseShow:r("p",{children:["You are about to delete role:"," ",e("strong",{children:t==null?void 0:t.name})]})})})},Zl="custom",Xl=({role:t,open:n,setOpen:o,onConfirm:a})=>(t==null?void 0:t.type)===Zl?e(Kl,{role:t,open:n,setOpen:o,onConfirm:a}):e(zl,{role:t,open:n,setOpen:o,onConfirm:a}),Bo=()=>{const{loading:t,makeRequest:n,createRequest:o,errors:a}=$e({propagateErrors:!0});return{addRole:async u=>{const c="addRole",h=o("api/admin/roles",{method:"POST",body:JSON.stringify(u)},c);return await(await n(h.caller,h.id)).json()},updateRole:async(u,c)=>{const h="updateRole",m=o(`api/admin/roles/${u}`,{method:"PUT",body:JSON.stringify(c)},h);await n(m.caller,m.id)},removeRole:async u=>{const c="removeRole",h=o(`api/admin/roles/${u}`,{method:"DELETE"},c);await n(h.caller,h.id)},validateRole:async u=>{const c="validateRole",h=o("api/admin/roles/validate",{method:"POST",body:JSON.stringify(u)},c);await n(h.caller,h.id)},errors:a,loading:t}},wt=()=>{const{isEnterprise:t}=G(),{data:n,error:o,mutate:a}=bt(t(),{roles:[],projectRoles:[]},oe("api/admin/roles"),Ql);return p.useMemo(()=>({roles:(n==null?void 0:n.roles.filter(({type:i})=>$a.includes(i)).sort(In))??[],projectRoles:(n==null?void 0:n.roles.filter(({type:i})=>po.includes(i)).sort(In))??[],loading:!o&&!n,refetch:()=>a(),error:o}),[n,o,a])},Ql=t=>fetch(t).then(ue("Roles")).then(n=>n.json()),In=(t,n)=>je.includes(t.type)&&!je.includes(n.type)?-1:!je.includes(t.type)&&je.includes(n.type)?1:t.name.localeCompare(n.name);var Lo=(t=>(t.NAME="name",t))(Lo||{});const ec=(t="",n="",o=[])=>{const{roles:a}=wt(),[i,s]=p.useState(t),[l,d]=p.useState(n),[u,c]=p.useState({}),[h,m]=p.useState({});return p.useEffect(()=>{s(t)},[t]),p.useEffect(()=>{d(n)},[n]),p.useEffect(()=>{const E=pn(o);c(E)},[o.length]),{name:i,description:l,checkedPermissions:u,errors:h,setName:s,setDescription:d,setCheckedPermissions:c,getRolePayload:(E=Ie)=>({name:i,description:l,type:E===Ie?"root-custom":"custom",permissions:Object.values(u)}),clearError:E=>{m(x=>({...x,[E]:void 0}))},setError:(E,x)=>{m(P=>({...P,[E]:x}))},isNameUnique:E=>!a.some(x=>x.name!==t&&x.name.toLowerCase()===E.toLowerCase()),isNotEmpty:E=>E.length,hasPermissions:E=>Object.keys(E).length>0,ErrorField:Lo,reload:()=>{s(t),d(n),c(pn(o))}}},tc=g(N)(({theme:t})=>({display:"flex",alignItems:"center",[t.breakpoints.down(500)]:{flexDirection:"column",alignItems:"flex-start"}})),nc=g(Na)(({theme:t})=>({fontWeight:t.typography.fontWeightBold,marginRight:t.spacing(1)})),oc=({title:t,permissions:n,checkedPermissions:o,Icon:a,isInitiallyExpanded:i=!1,context:s,onPermissionChange:l,onCheckAll:d})=>{const[u,c]=p.useState(i),h=p.useMemo(()=>(n==null?void 0:n.reduce((f,y)=>(f[it(y)]=!0,f),{}))||{},[n]),m=p.useMemo(()=>Object.keys(o).filter(f=>h[f]).length||0,[o,h]),S=p.useMemo(()=>m===(n==null?void 0:n.length),[m,n]);return e(N,{sx:{my:2,pb:1},children:r(Ga,{expanded:u,onChange:()=>c(!u),sx:{boxShadow:"none",px:3,py:1,border:f=>`1px solid ${f.palette.divider}`,borderRadius:f=>`${f.shape.borderRadiusLarge}px`},children:[e(Ma,{expandIcon:e(He,{children:e(ja,{titleAccess:"Toggle"})}),sx:{boxShadow:"none",padding:"0"},children:r(tc,{children:[a,e(nc,{text:t,maxWidth:"120",maxLength:25})," ",r(D,{variant:"body2",color:"text.secondary",children:["(",m," / ",n==null?void 0:n.length," ","permissions)"]})]})}),r(_a,{sx:{px:0,py:1,flexWrap:"wrap"},children:[e(Wt,{sx:{mb:1}}),r(z,{variant:"text",size:"small",onClick:d,sx:{fontWeight:f=>f.typography.fontWeightRegular},children:[S?"Unselect ":"Select ","all ",s," permissions"]}),e(N,{children:n==null?void 0:n.map(f=>e(me,{sx:{minWidth:{sm:"300px",xs:"auto"}},"data-testid":it(f),control:e(io,{checked:!!o[it(f)],onChange:()=>l(f),color:"primary"}),label:f.displayName},it(f)))})]})]})})},Mt=g("p")(({theme:t})=>({display:"flex",color:t.palette.text.primary,marginBottom:t.spacing(1),"&:not(:first-of-type)":{marginTop:t.spacing(4)}})),Pn=g(tt)(({theme:t})=>({width:"100%",maxWidth:t.spacing(50)})),ac=({type:t=Ie,name:n,onSetName:o,description:a,setDescription:i,checkedPermissions:s,setCheckedPermissions:l,errors:d})=>{const{permissions:u}=Ha({revalidateIfStale:!1,revalidateOnReconnect:!1,revalidateOnFocus:!1}),h=po.includes(t)?Wa(za(u.project,u.environments)):Fa(u.root),m=f=>{const y=Ka(s,f);l(y)},S=f=>{const y=Za(s,f);l(y)};return r("div",{children:[e(Mt,{children:"What is your new role name?"}),e(Pn,{autoFocus:!0,label:"Role name",error:!!d.name,errorText:d.name,value:n,onChange:f=>o(f.target.value),autoComplete:"off",required:!0}),e(Mt,{children:"What is your new role description?"}),e(Pn,{label:"Role description",value:a,onChange:f=>i(f.target.value),autoComplete:"off",required:!0}),e(Mt,{children:"What is your role allowed to do?"}),h.map(({label:f,type:y,permissions:v})=>e(oc,{title:`${f} permissions`,context:f.toLowerCase(),Icon:y===qa?e(Yr,{color:"disabled",sx:{mr:1}}):y===Va?e(Ya,{color:"disabled",sx:{mr:1}}):e(Ja,{color:"disabled",sx:{mr:1}}),permissions:v,checkedPermissions:s,onPermissionChange:T=>m(T),onCheckAll:()=>S(v)},f))]})},rc=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ic=g("div")(({theme:t})=>({marginTop:"auto",display:"flex",justifyContent:"flex-end",paddingTop:t.spacing(4)})),sc=g(z)(({theme:t})=>({marginLeft:t.spacing(3)})),lc=({type:t=Ie,roleId:n,open:o,setOpen:a})=>{const{role:i,refetch:s}=mo(n==null?void 0:n.toString()),{name:l,setName:d,description:u,setDescription:c,checkedPermissions:h,setCheckedPermissions:m,getRolePayload:S,isNameUnique:f,isNotEmpty:y,hasPermissions:v,errors:T,setError:w,clearError:k,ErrorField:E,reload:x}=ec(i==null?void 0:i.name,i==null?void 0:i.description,i==null?void 0:i.permissions),{refetch:P}=wt(),{addRole:M,updateRole:L,loading:I}=Bo(),{setToastData:F,setToastApiError:O}=Z(),{uiConfig:A}=G(),U=i!==void 0,X=f(l)&&y(l)&&y(u)&&v(h),R=S(t),_=()=>`curl --location --request ${U?"PUT":"POST"} '${A.unleashUrl}/api/admin/roles${U?`/${i.id}`:""}' \\
15
+ --data-raw '${JSON.stringify(k(),void 0,2)}'`,A=()=>{d(De)},L=q=>q.length,X=q=>!(M!=null&&M.filter(se=>se.name===q&&se.id!==n).length),R=L(u)&&X(u);return e(Pe,{loading:I,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/advanced/groups",documentationLinkLabel:"Groups documentation",formatApiCode:O,children:e(Io,{name:u,description:h,mappingsSSO:S,users:y,rootRole:T,setName:q=>{E(),X(q)||P({name:"A group with that name already exists."}),c(q)},setDescription:m,setMappingsSSO:f,setUsers:v,setRootRole:w,errors:x,handleSubmit:F,handleCancel:A,mode:Yt,children:e(z,{type:"submit",variant:"contained",color:"primary",disabled:!R,"data-testid":so,children:"Save"})})})},js=g(co)(({theme:t})=>({borderRadius:t.shape.borderRadiusLarge,padding:t.spacing(2.5,4),boxShadow:"none",marginBottom:t.spacing(2),fontSize:t.fontSizes.smallBody})),_s=g("div")(({theme:t})=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),Ws=g("h1")(({theme:t})=>({fontSize:t.fontSizes.mainHeader})),Hs=g("div")(({theme:t})=>({display:"flex"})),zs=g("span")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginLeft:t.spacing(1)})),Fs=({title:t,description:n,actions:o})=>(qn(t),r(js,{children:[r(_s,{children:[e(Ws,{children:t}),e(Hs,{children:o})]}),e(C,{condition:!!(n!=null&&n.length),show:r(B,{children:["Description:",e(zs,{children:n})]})})]})),qs=({open:t,setOpen:n,user:o,group:a})=>{const{refetchGroup:i}=vt(a.id),{updateGroup:s}=at(),{setToastData:l,setToastApiError:d}=Z(),u=async()=>{try{const h={...a,users:a.users.filter(({id:m})=>m!==(o==null?void 0:o.id)).map(({id:m})=>({user:{id:m}}))};await s(a.id,h),i(),n(!1),l({title:"User removed from group successfully",type:"success"})}catch(h){d(K(h))}},c=(o==null?void 0:o.name)||(o==null?void 0:o.username)||(o==null?void 0:o.email);return e(ie,{open:t&&!!o,primaryButtonText:"Remove user",secondaryButtonText:"Cancel",onClick:u,onClose:()=>{n(!1)},title:"Remove user from group?",children:r(D,{children:["Do you really want to remove ",e("strong",{children:c})," from"," ",e("strong",{children:a.name}),"? ",e("strong",{children:c})," will lose all access rights granted by this group."]})})},Vs=Array(15).fill({name:"Name of the user",username:"Username of the user"}),Ys={id:"joinedAt"},{value:xn,setValue:Js}=ka("Group:v1",Ys),Ks=()=>{const t=Number(Vt("groupId")),n=Jt(),o=ye(n.breakpoints.down("md")),{group:a,loading:i}=vt(t),[s,l]=p.useState(!1),[d,u]=p.useState(!1),[c,h]=p.useState(!1),[m,S]=p.useState(),f=p.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:A}})=>e(te,{children:e(He,{user:A})}),maxWidth:85,disableSortBy:!0},{id:"name",Header:"Name",accessor:A=>A.name||"",Cell:({value:A,row:{original:L}})=>e(Ce,{value:A,subtitle:L.email||L.username}),minWidth:100,searchable:!0},{Header:"Joined",accessor:"joinedAt",Cell:ve,sortType:"date",maxWidth:150},{id:"createdBy",Header:"Added by",accessor:"createdBy",Cell:Ce,minWidth:90,searchable:!0},{Header:"Last login",accessor:A=>A.seenAt||"",Cell:({row:{original:A}})=>e(Ve,{value:A.seenAt,emptyText:"Never",title:L=>`Last login: ${L}`}),sortType:"date",maxWidth:150},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:A}})=>e(pt,{children:e(Ue,{title:"Remove user from group",arrow:!0,describeChild:!0,children:e("span",{children:e(We,{"data-testid":`${Ra}-${A.id}`,onClick:()=>{S(A),h(!0)},children:e(Le,{})})})})}),maxWidth:100,disableSortBy:!0},{accessor:A=>A.username||"",Header:"Username",searchable:!0},{accessor:A=>A.email||"",Header:"Email",searchable:!0}],[S,h]),[y,v]=lo(),[T]=p.useState(()=>({sortBy:[{id:y.get("sort")||xn.id,desc:y.has("order")?y.get("order")==="desc":xn.desc}],hiddenColumns:["Username","Email"],globalFilter:y.get("search")||""})),[w,k]=p.useState(T.globalFilter),{data:E,getSearchText:x,getSearchContext:P}=nt(f,w,(a==null?void 0:a.users)??[]),M=p.useMemo(()=>(E==null?void 0:E.length)===0&&i?Vs:E,[E,i]),{headerGroups:U,rows:I,prepareRow:F,state:{sortBy:O}}=$.useTable({columns:f,data:M,initialState:T,sortTypes:Se,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return p.useEffect(()=>{const A={};A.sort=O[0].id,O[0].desc&&(A.order="desc"),w&&(A.search=w),v(A,{replace:!0}),Js({id:O[0].id,desc:O[0].desc||!1})},[O,w,v]),e(C,{condition:!!a,show:r(B,{children:[e(Fs,{title:a==null?void 0:a.name,description:a==null?void 0:a.description,actions:r(B,{children:[e(Ae,{"data-testid":Aa,to:`/admin/groups/${t}/edit`,component:de,"data-loading":!0,permission:Y,tooltipProps:{title:"Edit group"},children:e(Qe,{})}),e(Ae,{"data-testid":Da,"data-loading":!0,onClick:()=>l(!0),permission:Y,tooltipProps:{title:"Delete group"},children:e(Le,{})})]})}),r(ee,{isLoading:i,header:e(ne,{secondary:!0,title:`Users (${I.length<M.length?`${I.length} of ${M.length}`:M.length})`,actions:r(B,{children:[e(C,{condition:!o,show:r(B,{children:[e(me,{initialValue:w,onChange:k,hasFilters:!0,getSearchContext:P}),e(ne.Divider,{})]})}),e(qt,{"data-testid":Ia,onClick:()=>{u(!0)},maxWidth:"700px",Icon:St,permission:Y,children:"Edit users"})]}),children:e(C,{condition:o,show:e(me,{initialValue:w,onChange:k,hasFilters:!0,getSearchContext:P})})}),children:[e(qe,{value:x(w),children:e(xe,{rows:I,headerGroups:U,prepareRow:F})}),e(C,{condition:I.length===0,show:e(C,{condition:(w==null?void 0:w.length)>0,show:r(fe,{children:["No users found matching “",w,"” in this group."]}),elseShow:e(fe,{children:"This group is empty. Get started by adding a user to the group."})})}),e(Do,{open:s,setOpen:l,group:a}),e(Ao,{open:d,setOpen:u,group:a}),e(qs,{open:c,setOpen:h,user:m,group:a})]})]})})},Zs=()=>{const{uiConfig:t,isEnterprise:n}=G();return n()||t.flags[Pa]===!0?e("div",{children:e(Te,{permissions:Me,children:r(ot,{children:[e(W,{index:!0,element:e(Rs,{})}),e(W,{path:"create-group",element:e(Ns,{})}),e(W,{path:":groupId/edit",element:e(Gs,{})}),e(W,{path:":groupId",element:e(Ks,{})})]})})}):e(yt,{feature:"groups",page:!0})},Xs=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/instance-admin/statistics"),Qs);return p.useMemo(()=>({stats:t,loading:!n&&!t,refetchGroup:()=>o(),error:n}),[t,n,o])},Qs=t=>fetch(t).then(ue("Instance Stats")).then(n=>n.json()),el=()=>{const{stats:t}=Xs();let n,o;t!=null&&t.versionEnterprise?(n="Unleash Enterprise version",o=t.versionEnterprise):(n="Unleash OSS version",o=t==null?void 0:t.versionOSS);const a=[{title:"Instance Id",value:t==null?void 0:t.instanceId},{title:n,value:o},{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&&a.push({title:"SAML enabled",value:t!=null&&t.SAMLenabled?"Yes":"No"},{title:"OIDC enabled",value:t!=null&&t.OIDCenabled?"Yes":"No"}),e(ee,{header:e(ne,{title:"Instance Statistics"}),children:r(Lr,{sx:{display:"grid",gap:4},children:[r(to,{"aria-label":"Instance statistics",children:[e(no,{children:r(Xe,{children:[e(ce,{children:"Field"}),e(ce,{align:"right",children:"Value"})]})}),e(zt,{children:a.map(i=>r(Xe,{children:[e(ce,{component:"th",scope:"row",children:i.title}),e(ce,{align:"right",children:i.value})]},i.title))})]}),e("span",{style:{textAlign:"center"},children:e(z,{startIcon:e(Ba,{}),"aria-label":"Download instance statistics",color:"primary",variant:"contained",target:"_blank",rel:"noreferrer",href:oe("/api/admin/instance-admin/statistics/csv"),children:"Download"})})]})})},tl=()=>e("div",{children:e(el,{})}),nl=g("div")(({theme:t})=>({display:"flex",flexDirection:"column",padding:t.spacing(3),border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadiusLarge})),ol=g(N)(()=>({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"})),al=g(N)(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(2)})),rl=g("p")(({theme:t})=>({display:"table-cell",fontWeight:t.fontWeight.bold,paddingTop:t.spacing(2)})),il=g("p")(({theme:t})=>({display:"table-cell",paddingTop:t.spacing(2),paddingLeft:t.spacing(4)})),sl=g("div")(({theme:t})=>({display:"table-cell",width:"75%",paddingTop:t.spacing(2),paddingBottom:t.spacing(2)})),ll=g("div")(({theme:t})=>({display:"table-cell"})),cl=g("span")(({theme:t})=>({display:"block",textAlign:"right",color:t.palette.neutral.dark})),dl=g("div")(({theme:t})=>({maxWidth:t.spacing(50),color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody})),ul=g("div")(()=>({display:"table-row"})),En=g("div")(()=>({display:"table"})),hl=g("div")(()=>({display:"table-cell"})),pl=({changeInfoText:t,variablesText:n,dependsOnText:o})=>r(dl,{children:[e(kn,{children:t}),e(ml,{children:e("div",{children:n})}),e(C,{condition:!!o,show:e(kn,{children:o})})]}),ml=g("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})),kn=g("p")(({theme:t})=>({color:t.palette.text.primary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1)})),Rn=({title:t,infoText:n,concreteDetails:o,enabled:a,changeInfoText:i,variablesText:s,dependsOnText:l})=>r(nl,{children:[r(ol,{children:[e("b",{children:t}),e(ll,{children:e(C,{condition:a,show:e(Fe,{color:"success",icon:e(Zn,{}),children:"Data is collected"}),elseShow:e(Fe,{color:"neutral",icon:e(Or,{}),children:"No data is collected"})})})]}),r(al,{children:[r(En,{children:[e(sl,{children:n}),e(hl,{children:e(cl,{children:e(Kt,{tooltip:e(pl,{changeInfoText:i,variablesText:s,dependsOnText:l}),children:a?"How to disable collecting data?":"How to enable collecting data?"})})})]}),e(En,{children:Object.entries(o).map(([d,u])=>r(ul,{children:[e(rl,{children:d}),e(il,{children:u})]},d))})]})]}),gl=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/telemetry/settings"),fl);return p.useMemo(()=>({settings:t,loading:!n&&!t,refetchGroup:()=>o(),error:n}),[t,n,o])},fl=t=>fetch(t).then(ue("Telemetry Settings")).then(n=>n.json()),yl=g(N)(({theme:t})=>({display:"grid",gap:t.spacing(4)})),Ot={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"}},$t={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"}},An={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."}},Dn={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."}},bl=()=>{const{settings:t}=gl(),{loading:n}=G();if(n)return null;const o=t!=null&&t.versionInfoCollectionEnabled?An.enabled:An.disabled,a=t!=null&&t.featureInfoCollectionEnabled?Dn.enabled:Dn.disabled;let i;return t!=null&&t.versionInfoCollectionEnabled||(i=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(ee,{header:e(ne,{title:"Instance Privacy"}),children:r(yl,{children:[e(Rn,{title:Ot.title,infoText:Ot.infoText,concreteDetails:Ot.concreteDetails,enabled:t==null?void 0:t.versionInfoCollectionEnabled,changeInfoText:o.changeInfoText,variablesText:o.environmentVariables}),e(Rn,{title:$t.title,infoText:$t.infoText,concreteDetails:$t.concreteDetails,enabled:(t==null?void 0:t.featureInfoCollectionEnabled)&&(t==null?void 0:t.versionInfoCollectionEnabled),changeInfoText:a.changeInfoText,variablesText:a.environmentVariables,dependsOnText:i})]})})},Sl=()=>e(J,{severity:"warning",children:r("p",{children:[e("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."]})}),vl=()=>{const{data:t,error:n,mutate:o}=we(oe("api/admin/maintenance"),Cl);return p.useMemo(()=>({enabled:!!(t!=null&&t.enabled),loading:!n&&!t,refetchMaintenance:o,error:n}),[t,n,o])},Cl=t=>fetch(t).then(ue("Maintenance")).then(n=>n.json()),wl=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=$e({propagateErrors:!0});return{toggleMaintenance:async s=>{const d=n("api/admin/maintenance",{method:"POST",body:JSON.stringify(s)});try{await t(d.caller,d.id)}catch(u){throw u}},errors:o,loading:a}},Tl=g("div")(({theme:t})=>({display:"flex",flexDirection:"column",padding:t.spacing(3),border:`1px solid ${t.palette.divider}`,borderRadius:t.shape.borderRadiusLarge})),xl=g(N)(({theme:t})=>({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"})),El=g(N)(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(2)})),kl=g(D)(({theme:t})=>({fontSize:t.fontSizes.smallBody})),Rl=()=>{const{enabled:t,refetchMaintenance:n}=vl(),{toggleMaintenance:o}=wl(),{trackEvent:a}=Zt(),{setToastData:i}=Z();return r(Tl,{children:[r(xl,{children:[e("b",{children:"Maintenance Mode"}),e(he,{sx:{margin:0},control:e(ge,{onChange: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}),n()},value:t,name:"enabled",checked:t}),label:e(kl,{children:t?"Enabled":"Disabled"})})]}),e(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."})]})},Al=()=>e("div",{children:e(Te,{permissions:Y,children:e(Il,{})})}),Dl=g(N)(({theme:t})=>({display:"grid",gap:t.spacing(4)})),Il=()=>{const{loading:t}=G();return t?null:e(ee,{header:e(ne,{title:"Maintenance"}),children:r(Dl,{children:[e(Sl,{}),e(Rl,{})]})})},Pl=g(Ua)(({theme:t})=>({display:"flex",justifyContent:"center",alignItems:"center",width:"100%",height:"100%",textDecoration:"none",color:"inherit",padding:t.spacing(0,5),"&.active":{fontWeight:"bold"}})),an=({to:t,children:n})=>e(Pl,{to:t,children:n}),Bl=p.lazy(()=>uo(()=>import("./NetworkOverview-349a7bdd.js").then(t=>t.N),[])),Ul=p.lazy(()=>uo(()=>import("./NetworkTraffic-60478e50.js"),[])),Ll=[{label:"Overview",path:"/admin/network"},{label:"Traffic",path:"/admin/network/traffic"}],Ol=()=>{const{pathname:t}=Xt();return e("div",{children:e(ee,{withTabs:!0,header:e(gt,{value:t,indicatorColor:"primary",textColor:"primary",variant:"scrollable",allowScrollButtonsMobile:!0,children:Ll.map(({label:n,path:o})=>e(ft,{value:o,label:e(an,{to:o,children:e("span",{children:n})}),sx:{padding:0}},n))}),children:r(ot,{children:[e(W,{path:"traffic",element:e(Ul,{})}),e(W,{path:"*",element:e(Bl,{})})]})})})},$l=g(N)(()=>({display:"flex",justifyContent:"center"})),Nl=({role:t,onEdit:n,onDelete:o})=>{const a=je.includes(t.type);return r($l,{children:[e(Ae,{"data-loading":!0,onClick:n,permission:Y,disabled:a,tooltipProps:{title:a?"You cannot edit a predefined role":"Edit role"},children:e(Qe,{})}),e(Ae,{"data-loading":!0,onClick:o,permission:Y,disabled:a,tooltipProps:{title:a?"You cannot remove a predefined role":"Remove role"},children:e(Le,{})})]})},Gl=g(Fe)(({theme:t})=>({marginLeft:t.spacing(1)})),Ml=({role:t})=>e(Ce,{value:t.name,subtitle:t.description,afterTitle:e(C,{condition:je.includes(t.type),show:e(Gl,{color:"success",children:"Predefined"})})}),jl=({users:t})=>{const[n]=p.useState(()=>({sortBy:[{id:"last-login"}]})),o=p.useMemo(()=>[{id:"name",Header:"Name",accessor:l=>l.name||"",minWidth:200,Cell:({row:{original:l}})=>e(Ce,{value:l.name,subtitle:l.email||l.username})},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",width:120,maxWidth:120},{id:"last-login",Header:"Last login",accessor:l=>l.seenAt||"",Cell:({row:{original:l}})=>e(Ve,{value:l.seenAt,emptyText:"Never",title:d=>`Last login: ${d}`}),sortType:"date",maxWidth:150}],[]),{headerGroups:a,rows:i,prepareRow:s}=$.useTable({columns:o,data:t,initialState:n,sortTypes:Se,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return e(xe,{rows:i,headerGroups:a,prepareRow:s})},_l=g(D)(({theme:t})=>({fontSize:t.fontSizes.smallerBody})),Po=({serviceAccount:t,value:n,onCreateToken:o})=>{var i,s,l;const{searchQuery:a}=La();return!t.tokens||t.tokens.length===0?o?e(ho,{title:"Create token",onClick:o}):e(te,{children:"0 tokens"}):e(te,{children:e(Kt,{tooltip:e(B,{children:(i=t.tokens)==null?void 0:i.map(({id:d,description:u})=>e(_l,{children:e(Oa,{search:a,children:u})},d))}),highlighted:a.length>0&&n.toLowerCase().includes(a.toLowerCase()),children:((s=t.tokens)==null?void 0:s.length)===1?"1 token":`${(l=t.tokens)==null?void 0:l.length} tokens`})})},Wl=({serviceAccounts:t})=>{const[n]=p.useState(()=>({sortBy:[{id:"seenAt"}]})),o=p.useMemo(()=>[{id:"name",Header:"Name",accessor:l=>l.name||"",minWidth:200,Cell:({row:{original:l}})=>e(Ce,{value:l.name,subtitle:l.username})},{id:"tokens",Header:"Tokens",accessor:l=>{var d;return((d=l.tokens)==null?void 0:d.map(({description:u})=>u).join(`
16
+ `))||""},Cell:({row:{original:l},value:d})=>e(Po,{serviceAccount:l,value:d}),maxWidth:100},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",width:120,maxWidth:120},{id:"seenAt",Header:"Last seen",accessor:l=>{var d;return(d=l.tokens.sort((u,c)=>{const h=new Date(u.seenAt||0),m=new Date(c.seenAt||0);return(m==null?void 0:m.getTime())-(h==null?void 0:h.getTime())})[0])==null?void 0:d.seenAt},Cell:Ve,sortType:"date",maxWidth:150}],[]),{headerGroups:a,rows:i,prepareRow:s}=$.useTable({columns:o,data:t,initialState:n,sortTypes:Se,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return e(xe,{rows:i,headerGroups:a,prepareRow:s})},Hl=({groups:t})=>{const[n]=p.useState(()=>({sortBy:[{id:"createdAt"}]})),o=p.useMemo(()=>[{id:"name",Header:"Name",accessor:l=>l.name||"",minWidth:200,Cell:({row:{original:l}})=>e(Ce,{value:l.name,subtitle:l.description})},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",width:120,maxWidth:120},{id:"users",Header:"Users",accessor:l=>l.users.length===1?"1 user":`${l.users.length} users`,Cell:te,maxWidth:150}],[]),{headerGroups:a,rows:i,prepareRow:s}=$.useTable({columns:o,data:t,initialState:n,sortTypes:Se,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return e(xe,{rows:i,headerGroups:a,prepareRow:s})},Nt=g("div")(({theme:t})=>({marginTop:t.spacing(1.5)})),Gt=g("p")(({theme:t})=>({marginTop:t.spacing(3)})),zl=({role:t,open:n,setOpen:o,onConfirm:a})=>{const{users:i}=Ee(),{serviceAccounts:s}=rt(),{groups:l}=_e(),d=i.filter(({rootRole:m})=>m===(t==null?void 0:t.id)),u=s.filter(({rootRole:m})=>m===(t==null?void 0:t.id)),c=l==null?void 0:l.filter(({rootRole:m})=>m===(t==null?void 0:t.id)),h=!!(d.length||u.length||c!=null&&c.length);return e(ie,{title:"Delete root role?",open:n,primaryButtonText:"Delete role",secondaryButtonText:"Cancel",disabledPrimaryButton:h,onClick:()=>a(t),onClose:()=>{o(!1)},children:e(C,{condition:h,show:r(B,{children:[e(J,{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(C,{condition:!!d.length,show:r(B,{children:[r(Gt,{children:["Users (",d.length,"):"]}),e(Nt,{children:e(jl,{users:d})})]})}),e(C,{condition:!!u.length,show:r(B,{children:[r(Gt,{children:["Service accounts (",u.length,"):"]}),e(Nt,{children:e(Wl,{serviceAccounts:u})})]})}),e(C,{condition:!!(c!=null&&c.length),show:r(B,{children:[r(Gt,{children:["Groups (",c==null?void 0:c.length,"):"]}),e(Nt,{children:e(Hl,{groups:c})})]})})]}),elseShow:r("p",{children:["You are about to delete role:"," ",e("strong",{children:t==null?void 0:t.name})]})})})},Fl=t=>{const{isEnterprise:n}=G(),{data:o,error:a,mutate:i}=bt(n()&&t,{projects:[]},oe(`api/admin/projects/roles/${t}/access`),ql);return p.useMemo(()=>({projects:(o==null?void 0:o.projects)??[],loading:!a&&!o,refetch:()=>i(),error:a}),[o,a,i])},ql=t=>fetch(t).then(ue("Project role usage")).then(n=>n.json()),Vl=({projects:t})=>{const[n]=p.useState(()=>({sortBy:[{id:"name"}]})),o=p.useMemo(()=>[{id:"name",Header:"Project name",accessor:l=>l.project||"",minWidth:200,Cell:({row:{original:l}})=>e(ho,{title:l.project,to:`/projects/${l.project}`})},{id:"users",Header:"Assigned users",accessor:l=>l.userCount===1?"1 user":`${l.userCount} users`,Cell:te,maxWidth:150},{id:"serviceAccounts",Header:"Service accounts",accessor:l=>l.serviceAccountCount===1?"1 account":`${l.serviceAccountCount} accounts`,Cell:te,maxWidth:150},{id:"groups",Header:"Assigned groups",accessor:l=>l.groupCount===1?"1 group":`${l.groupCount} groups`,Cell:te,maxWidth:150}],[]),{headerGroups:a,rows:i,prepareRow:s}=$.useTable({columns:o,data:t,initialState:n,sortTypes:Se,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return e(xe,{rows:i,headerGroups:a,prepareRow:s})},Yl=g("div")(({theme:t})=>({marginTop:t.spacing(1.5)})),Jl=g("p")(({theme:t})=>({marginTop:t.spacing(3)})),Kl=({role:t,open:n,setOpen:o,onConfirm:a})=>{const{projects:i}=Fl(t==null?void 0:t.id),s=!!(i!=null&&i.length);return e(ie,{title:"Delete project role?",open:n,primaryButtonText:"Delete role",secondaryButtonText:"Cancel",disabledPrimaryButton:s,onClick:()=>a(t),onClose:()=>{o(!1)},maxWidth:"md",children:e(C,{condition:s,show:r(B,{children:[e(J,{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(C,{condition:!!(i!=null&&i.length),show:r(B,{children:[r(Jl,{children:["Role assigned in ",i==null?void 0:i.length," ","projects:"]}),e(Yl,{children:e(Vl,{projects:i})})]})})]}),elseShow:r("p",{children:["You are about to delete role:"," ",e("strong",{children:t==null?void 0:t.name})]})})})},Zl="custom",Xl=({role:t,open:n,setOpen:o,onConfirm:a})=>(t==null?void 0:t.type)===Zl?e(Kl,{role:t,open:n,setOpen:o,onConfirm:a}):e(zl,{role:t,open:n,setOpen:o,onConfirm:a}),Bo=()=>{const{loading:t,makeRequest:n,createRequest:o,errors:a}=$e({propagateErrors:!0});return{addRole:async u=>{const c="addRole",h=o("api/admin/roles",{method:"POST",body:JSON.stringify(u)},c);return await(await n(h.caller,h.id)).json()},updateRole:async(u,c)=>{const h="updateRole",m=o(`api/admin/roles/${u}`,{method:"PUT",body:JSON.stringify(c)},h);await n(m.caller,m.id)},removeRole:async u=>{const c="removeRole",h=o(`api/admin/roles/${u}`,{method:"DELETE"},c);await n(h.caller,h.id)},validateRole:async u=>{const c="validateRole",h=o("api/admin/roles/validate",{method:"POST",body:JSON.stringify(u)},c);await n(h.caller,h.id)},errors:a,loading:t}},wt=()=>{const{isEnterprise:t}=G(),{data:n,error:o,mutate:a}=bt(t(),{roles:[],projectRoles:[]},oe("api/admin/roles"),Ql);return p.useMemo(()=>({roles:(n==null?void 0:n.roles.filter(({type:i})=>$a.includes(i)).sort(In))??[],projectRoles:(n==null?void 0:n.roles.filter(({type:i})=>po.includes(i)).sort(In))??[],loading:!o&&!n,refetch:()=>a(),error:o}),[n,o,a])},Ql=t=>fetch(t).then(ue("Roles")).then(n=>n.json()),In=(t,n)=>je.includes(t.type)&&!je.includes(n.type)?-1:!je.includes(t.type)&&je.includes(n.type)?1:t.name.localeCompare(n.name);var Uo=(t=>(t.NAME="name",t))(Uo||{});const ec=(t="",n="",o=[])=>{const{roles:a}=wt(),[i,s]=p.useState(t),[l,d]=p.useState(n),[u,c]=p.useState({}),[h,m]=p.useState({});return p.useEffect(()=>{s(t)},[t]),p.useEffect(()=>{d(n)},[n]),p.useEffect(()=>{const E=pn(o);c(E)},[o.length]),{name:i,description:l,checkedPermissions:u,errors:h,setName:s,setDescription:d,setCheckedPermissions:c,getRolePayload:(E=Ie)=>({name:i,description:l,type:E===Ie?"root-custom":"custom",permissions:Object.values(u)}),clearError:E=>{m(x=>({...x,[E]:void 0}))},setError:(E,x)=>{m(P=>({...P,[E]:x}))},isNameUnique:E=>!a.some(x=>x.name!==t&&x.name.toLowerCase()===E.toLowerCase()),isNotEmpty:E=>E.length,hasPermissions:E=>Object.keys(E).length>0,ErrorField:Uo,reload:()=>{s(t),d(n),c(pn(o))}}},tc=g(N)(({theme:t})=>({display:"flex",alignItems:"center",[t.breakpoints.down(500)]:{flexDirection:"column",alignItems:"flex-start"}})),nc=g(Na)(({theme:t})=>({fontWeight:t.typography.fontWeightBold,marginRight:t.spacing(1)})),oc=({title:t,permissions:n,checkedPermissions:o,Icon:a,isInitiallyExpanded:i=!1,context:s,onPermissionChange:l,onCheckAll:d})=>{const[u,c]=p.useState(i),h=p.useMemo(()=>(n==null?void 0:n.reduce((f,y)=>(f[it(y)]=!0,f),{}))||{},[n]),m=p.useMemo(()=>Object.keys(o).filter(f=>h[f]).length||0,[o,h]),S=p.useMemo(()=>m===(n==null?void 0:n.length),[m,n]);return e(N,{sx:{my:2,pb:1},children:r(Ga,{expanded:u,onChange:()=>c(!u),sx:{boxShadow:"none",px:3,py:1,border:f=>`1px solid ${f.palette.divider}`,borderRadius:f=>`${f.shape.borderRadiusLarge}px`},children:[e(Ma,{expandIcon:e(We,{children:e(ja,{titleAccess:"Toggle"})}),sx:{boxShadow:"none",padding:"0"},children:r(tc,{children:[a,e(nc,{text:t,maxWidth:"120",maxLength:25})," ",r(D,{variant:"body2",color:"text.secondary",children:["(",m," / ",n==null?void 0:n.length," ","permissions)"]})]})}),r(_a,{sx:{px:0,py:1,flexWrap:"wrap"},children:[e(Ht,{sx:{mb:1}}),r(z,{variant:"text",size:"small",onClick:d,sx:{fontWeight:f=>f.typography.fontWeightRegular},children:[S?"Unselect ":"Select ","all ",s," permissions"]}),e(N,{children:n==null?void 0:n.map(f=>e(he,{sx:{minWidth:{sm:"300px",xs:"auto"}},"data-testid":it(f),control:e(io,{checked:!!o[it(f)],onChange:()=>l(f),color:"primary"}),label:f.displayName},it(f)))})]})]})})},Mt=g("p")(({theme:t})=>({display:"flex",color:t.palette.text.primary,marginBottom:t.spacing(1),"&:not(:first-of-type)":{marginTop:t.spacing(4)}})),Pn=g(tt)(({theme:t})=>({width:"100%",maxWidth:t.spacing(50)})),ac=({type:t=Ie,name:n,onSetName:o,description:a,setDescription:i,checkedPermissions:s,setCheckedPermissions:l,errors:d})=>{const{permissions:u}=Wa({revalidateIfStale:!1,revalidateOnReconnect:!1,revalidateOnFocus:!1}),h=po.includes(t)?Ha(za(u.project,u.environments)):Fa(u.root),m=f=>{const y=Ka(s,f);l(y)},S=f=>{const y=Za(s,f);l(y)};return r("div",{children:[e(Mt,{children:"What is your new role name?"}),e(Pn,{autoFocus:!0,label:"Role name",error:!!d.name,errorText:d.name,value:n,onChange:f=>o(f.target.value),autoComplete:"off",required:!0}),e(Mt,{children:"What is your new role description?"}),e(Pn,{label:"Role description",value:a,onChange:f=>i(f.target.value),autoComplete:"off",required:!0}),e(Mt,{children:"What is your role allowed to do?"}),h.map(({label:f,type:y,permissions:v})=>e(oc,{title:`${f} permissions`,context:f.toLowerCase(),Icon:y===qa?e(Yr,{color:"disabled",sx:{mr:1}}):y===Va?e(Ya,{color:"disabled",sx:{mr:1}}):e(Ja,{color:"disabled",sx:{mr:1}}),permissions:v,checkedPermissions:s,onPermissionChange:T=>m(T),onCheckAll:()=>S(v)},f))]})},rc=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ic=g("div")(({theme:t})=>({marginTop:"auto",display:"flex",justifyContent:"flex-end",paddingTop:t.spacing(4)})),sc=g(z)(({theme:t})=>({marginLeft:t.spacing(3)})),lc=({type:t=Ie,roleId:n,open:o,setOpen:a})=>{const{role:i,refetch:s}=mo(n==null?void 0:n.toString()),{name:l,setName:d,description:u,setDescription:c,checkedPermissions:h,setCheckedPermissions:m,getRolePayload:S,isNameUnique:f,isNotEmpty:y,hasPermissions:v,errors:T,setError:w,clearError:k,ErrorField:E,reload:x}=ec(i==null?void 0:i.name,i==null?void 0:i.description,i==null?void 0:i.permissions),{refetch:P}=wt(),{addRole:M,updateRole:U,loading:I}=Bo(),{setToastData:F,setToastApiError:O}=Z(),{uiConfig:A}=G(),L=i!==void 0,X=f(l)&&y(l)&&y(u)&&v(h),R=S(t),_=()=>`curl --location --request ${L?"PUT":"POST"} '${A.unleashUrl}/api/admin/roles${L?`/${i.id}`:""}' \\
17
17
  --header 'Authorization: INSERT_API_KEY' \\
18
18
  --header 'Content-Type: application/json' \\
19
- --data-raw '${JSON.stringify(R,void 0,2)}'`,q=re=>{k(E.NAME),f(re)||w(E.NAME,"A role with that name already exists."),d(re)},se=()=>{P(),s()},ae=async re=>{if(re.preventDefault(),!!X)try{U?await L(i.id,R):await M(R),F({title:`Role ${U?"updated":"added"} successfully`,type:"success"}),se(),a(!1)}catch(Ye){O(K(Ye))}};p.useEffect(()=>{x()},[o]);const W=t[0].toUpperCase()+t.slice(1);return e(Ft,{open:o,onClose:()=>{a(!1)},label:U?`Edit ${t} role`:`New ${t} role`,children:e(Pe,{loading:I,modal:!0,title:U?`Edit ${t} role`:`New ${t} role`,description:`${W} roles allow you to control access to ${t} resources. Besides the built-in ${t} roles, you can create and manage custom ${t} roles to fit your needs.`,documentationLink:`https://docs.getunleash.io/reference/rbac${t===Ie?"#custom-root-roles":"#custom-project-roles"}`,documentationLinkLabel:"Roles documentation",formatApiCode:_,children:r(rc,{onSubmit:ae,children:[e(ac,{type:t,name:l,onSetName:q,description:u,setDescription:c,checkedPermissions:h,setCheckedPermissions:m,errors:T}),r(ic,{children:[r(z,{type:"submit",variant:"contained",color:"primary",disabled:!X,children:[U?"Save":"Add"," role"]}),e(sc,{onClick:()=>{a(!1)},children:"Cancel"})]})]})})})},cc=({row:t})=>{var a,i;const{original:n}=t,{role:o}=mo(n.id.toString());return!o||je.includes(o.type)?null:e(te,{children:e(Kt,{tooltip:e(Xa,{roleId:n.id,tooltip:!0}),children:((a=o.permissions)==null?void 0:a.length)===1?"1 permission":`${(i=o.permissions)==null?void 0:i.length} permissions`})})},Bn=({type:t=Ie,searchValue:n="",modalOpen:o,setModalOpen:a,selectedRole:i,setSelectedRole:s})=>{const{setToastData:l,setToastApiError:d}=Z(),u=Jt(),{roles:c,projectRoles:h,refetch:m,loading:S}=wt(),{removeRole:f}=Bo(),[y,v]=p.useState(!1),T=async O=>{try{await f(O.id),l({title:`${O.name} has been deleted`,type:"success"}),m(),v(!1)}catch(A){d(K(A))}},w=fe(u.breakpoints.down("md")),k=p.useMemo(()=>[{id:"Icon",Cell:()=>e(Qa,{icon:e(Vr,{color:"disabled"})}),disableGlobalFilter:!0,maxWidth:50},{Header:"Role",accessor:"name",Cell:({row:{original:O}})=>e(Ml,{role:O}),searchable:!0,minWidth:100},{id:"permissions",Header:"Permissions",Cell:cc,maxWidth:140},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:O}})=>e(Nl,{role:O,onEdit:()=>{s(O),a(!0)},onDelete:()=>{s(O),v(!0)}}),width:150,disableSortBy:!0},{accessor:"description",Header:"Description",searchable:!0}],[]),[E]=p.useState({sortBy:[{id:"name"}],hiddenColumns:["description"]}),{data:x,getSearchText:P}=nt(k,n,t===Ie?c:h),{headerGroups:M,rows:L,prepareRow:I,setHiddenColumns:F}=$.useTable({columns:k,data:x,initialState:E,sortTypes:be,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0,defaultColumn:{Cell:te}},$.useSortBy,$.useFlexLayout);return et([{condition:w,columns:["Icon"]}],F,k),r(ee,{isLoading:S,children:[e(qe,{value:P(n),children:e(xe,{rows:L,headerGroups:M,prepareRow:I})}),e(C,{condition:L.length===0,show:e(C,{condition:(n==null?void 0:n.length)>0,show:r(ge,{children:["No ",t," roles found matching “",n,"”"]}),elseShow:r(ge,{children:["No ",t," roles available. Get started by adding one."]})})}),e(lc,{type:t,roleId:i==null?void 0:i.id,open:o,setOpen:a}),e(Xl,{role:i,open:y,setOpen:v,onConfirm:T})]})},dc=g("div")(()=>({display:"flex",justifyContent:"space-between",alignItems:"center"})),uc=g("div")({flex:1}),hc=g("div")({display:"flex",alignItems:"center"}),pc=()=>{const{uiConfig:t}=G(),{pathname:n}=Xt(),{roles:o,projectRoles:a,loading:i}=wt(),[s,l]=p.useState(""),[d,u]=p.useState(!1),[c,h]=p.useState(),m=t.flags.customRootRolesKillSwitch?[{label:"Project roles",path:"/admin/roles",total:a.length}]:[{label:"Root roles",path:"/admin/roles",total:o.length},{label:"Project roles",path:"/admin/roles/project-roles",total:a.length}],S=fe(Oe.breakpoints.down("md")),f=t.flags.customRootRolesKillSwitch||n.includes("project-roles")?Lt:Ie;return e(ee,{withTabs:!0,bodyClass:"page-body",isLoading:i,header:r(B,{children:[r(dc,{children:[e(uc,{children:e(gt,{value:n,indicatorColor:"primary",textColor:"primary",variant:"scrollable",allowScrollButtonsMobile:!0,children:m.map(({label:y,path:v,total:T})=>e(ft,{value:v,label:e(an,{to:v,children:r("span",{children:[y," (",T,")"]})}),sx:{padding:0}},y))})}),r(hc,{children:[e(C,{condition:!S,show:r(B,{children:[e(pe,{initialValue:s,onChange:l}),e(ne.Divider,{})]})}),r(qt,{onClick:()=>{h(void 0),u(!0)},maxWidth:`${Oe.breakpoints.values.sm}px`,Icon:St,permission:Y,children:["New ",f," role"]})]})]}),e(C,{condition:S,show:e(pe,{initialValue:s,onChange:l})})]}),children:r(ot,{children:[e(H,{path:"project-roles",element:e(Bn,{type:Lt,searchValue:s,modalOpen:d,setModalOpen:u,selectedRole:c,setSelectedRole:h})}),e(H,{path:"*",element:e(Bn,{type:t.flags.customRootRolesKillSwitch?Lt:Ie,searchValue:s,modalOpen:d,setModalOpen:u,selectedRole:c,setSelectedRole:h})})]})})},mc=()=>{const{isEnterprise:t}=G();return t()?e("div",{children:e(Te,{permissions:[er,Y],children:e(pc,{})})}):e(yt,{feature:"project-roles",page:!0})},Uo=()=>{const{loading:t,makeRequest:n,createRequest:o,errors:a}=$e({propagateErrors:!0});return{addServiceAccount:async d=>{const u="addServiceAccount",c=o("api/admin/service-account",{method:"POST",body:JSON.stringify(d)},u);return await(await n(c.caller,c.id)).json()},updateServiceAccount:async(d,u)=>{const c="updateServiceAccount",h=o(`api/admin/service-account/${d}`,{method:"PUT",body:JSON.stringify(u)},c);await n(h.caller,h.id)},removeServiceAccount:async d=>{const u="removeServiceAccount",c=o(`api/admin/service-account/${d}`,{method:"DELETE"},u);await n(c.caller,c.id)},errors:a,loading:t}},Oo=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=$e({propagateErrors:!0});return{createServiceAccountToken:async(l,d)=>{const u=n(`api/admin/service-account/${l}/token`,{method:"POST",body:JSON.stringify(d)});try{return await(await t(u.caller,u.id)).json()}catch(c){throw c}},deleteServiceAccountToken:async(l,d)=>{const u=n(`api/admin/service-account/${l}/token/${d}`,{method:"DELETE"});try{await t(u.caller,u.id)}catch(c){throw c}},errors:o,loading:a}},gc=t=>{const{isEnterprise:n}=G(),{data:o,error:a,mutate:i}=bt(n(),{pats:[]},oe(`api/admin/service-account/${t}/token`),fc);return{tokens:o?o.pats:void 0,loading:!a&&!o,refetchTokens:()=>i(),error:a}},fc=t=>fetch(t).then(ue("Service Account Tokens")).then(n=>n.json()),lt=go["30DAYS"],yc=({open:t,setOpen:n,tokens:o,onCreateClick:a})=>{const[i,s]=p.useState(""),[l,d]=p.useState(lt),[u,c]=p.useState(ut(lt)),[h,m]=p.useState({});p.useEffect(()=>{s(""),d(lt),c(ut(lt)),m({})},[t]);const S=y=>!(o!=null&&o.some(v=>v.description===y)),f=i.length&&S(i)&&u>new Date;return e(ie,{open:t,primaryButtonText:"Create token",secondaryButtonText:"Cancel",onClick:()=>a({description:i,expiresAt:u}),disabledPrimaryButton:!f,onClose:()=>{n(!1)},title:"New token",children:e(fo,{description:i,setDescription:s,isDescriptionUnique:S,expiration:l,setExpiration:d,expiresAt:u,setExpiresAt:c,errors:h,setErrors:m})})},bc=g(J)(({theme:t})=>({marginBottom:t.spacing(3)})),$o=({open:t,setOpen:n,token:o})=>r(ie,{open:t,secondaryButtonText:"Close",onClose:(a,i)=>{i||n(!1)},title:"Service account token created",children:[e(bc,{severity:"info",children:"Make sure to copy your service account API token now. You won't be able to see it again!"}),e(D,{variant:"body1",children:"Your token:"}),e(tr,{token:(o==null?void 0:o.secret)||""})]}),Sc=g("div")(({theme:t})=>({display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:t.spacing(2),gap:t.spacing(2),"& > div":{[t.breakpoints.down("md")]:{marginTop:0}}})),vc=g("div")(({theme:t})=>({display:"flex",flexDirection:"column",alignItems:"center",padding:t.spacing(3)})),Cc=g(D)(({theme:t})=>({fontSize:t.fontSizes.bodySize,marginBottom:t.spacing(.5)})),wc=g(D)(({theme:t})=>({fontSize:t.fontSizes.smallBody,color:t.palette.text.secondary,marginBottom:t.spacing(1.5)})),Tc={id:"createdAt"},No=({serviceAccount:t,readOnly:n})=>{const o=Jt(),{setToastData:a,setToastApiError:i}=Z(),s=fe(o.breakpoints.down("md")),l=fe(o.breakpoints.down("sm")),{tokens:d=[],refetchTokens:u}=gc(t.id),{refetch:c}=rt(),{createServiceAccountToken:h,deleteServiceAccountToken:m}=Oo(),[S]=p.useState(()=>({sortBy:n?[{id:"seenAt"}]:[Tc]})),[f,y]=p.useState(""),[v,T]=p.useState(!1),[w,k]=p.useState(!1),[E,x]=p.useState(!1),[P,M]=p.useState(),[L,I]=p.useState(),F=async W=>{try{const re=await h(t.id,W);c(),u(),T(!1),M(re),k(!0),a({title:"Token created successfully",type:"success"})}catch(re){i(K(re))}},O=async()=>{if(L)try{await m(t.id,L==null?void 0:L.id),c(),u(),x(!1),a({title:"Token deleted successfully",type:"success"})}catch(W){i(K(W))}},A=p.useMemo(()=>[{Header:"Description",accessor:"description",Cell:Ce,minWidth:100,searchable:!0},{Header:"Expires",accessor:"expiresAt",Cell:({value:W})=>new Date(W).getFullYear()>new Date().getFullYear()+100?e(te,{children:"Never"}):e(ve,{value:W}),sortType:"date",maxWidth:150},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",maxWidth:150},{Header:"Last seen",accessor:"seenAt",Cell:Ve,sortType:"date",maxWidth:150},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:W}})=>e(pt,{children:e(Le,{title:"Delete token",arrow:!0,describeChild:!0,children:e("span",{children:e(He,{onClick:()=>{I(W),x(!0)},children:e(Ue,{})})})})}),maxWidth:100,disableSortBy:!0}],[I,x]),{data:U,getSearchText:X,getSearchContext:R}=nt(A,f,d),{headerGroups:_,rows:q,prepareRow:se,setHiddenColumns:ae}=$.useTable({columns:A,data:U,initialState:S,sortTypes:be,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return et([{condition:l,columns:["expiresAt"]},{condition:s,columns:["createdAt"]},{condition:!!n,columns:["Actions","expiresAt","createdAt"]}],ae,A),r(B,{children:[e(C,{condition:!n,show:r(Sc,{children:[e(pe,{initialValue:f,onChange:y,getSearchContext:R}),e(z,{variant:"contained",color:"primary",disabled:d.length>=nr,onClick:()=>T(!0),children:"New token"})]})}),e(qe,{value:X(f),children:e(xe,{rows:q,headerGroups:_,prepareRow:se})}),e(C,{condition:q.length===0,show:e(C,{condition:(f==null?void 0:f.length)>0,show:r(ge,{children:["No tokens found matching “",f,"”"]}),elseShow:r(vc,{children:[e(Cc,{children:"You have no tokens for this service account yet."}),e(wc,{children:"Create a service account token for access to the Unleash API."}),e(z,{variant:"outlined",onClick:()=>T(!0),children:"Create new service account token"})]})})}),e(yc,{open:v,setOpen:T,tokens:d,onCreateClick:F}),e($o,{open:w,setOpen:k,token:P}),e(ie,{open:E,primaryButtonText:"Delete token",secondaryButtonText:"Cancel",onClick:O,onClose:()=>{x(!1)},title:"Delete token?",children:r(D,{children:['Any applications or scripts using this token "',e("strong",{children:L==null?void 0:L.description}),'" will no longer be able to access the Unleash API. You cannot undo this action.']})})]})},xc=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Ze=g("p")(({theme:t})=>({display:"flex",color:t.palette.text.primary,marginBottom:t.spacing(1),"&:not(:first-of-type)":{marginTop:t.spacing(4)}})),Ln=g("p")(({theme:t})=>({color:t.palette.text.secondary,marginBottom:t.spacing(1)})),Un=g(tt)(({theme:t})=>({width:"100%",maxWidth:t.spacing(50)})),Ec=g(en)(({theme:t})=>({width:"100%",maxWidth:t.spacing(50)})),kc=g("div")(({theme:t})=>({padding:t.spacing(3),backgroundColor:t.palette.background.elevation2,borderRadius:t.shape.borderRadiusMedium,marginTop:t.spacing(4),marginBottom:t.spacing(2)})),Rc=g("div")(({theme:t})=>({padding:t.spacing(0,4),"& > p:not(:first-of-type)":{marginTop:t.spacing(2)}})),Ac=g("div")(({theme:t})=>({marginTop:"auto",display:"flex",justifyContent:"flex-end",paddingTop:t.spacing(4)})),Dc=g(z)(({theme:t})=>({marginLeft:t.spacing(3)})),ct=go["30DAYS"],Ic=({serviceAccount:t,open:n,setOpen:o,newToken:a})=>{const{users:i}=Ee(),{serviceAccounts:s,roles:l,refetch:d}=rt(),{addServiceAccount:u,updateServiceAccount:c,loading:h}=Uo(),{createServiceAccountToken:m}=Oo(),{setToastData:S,setToastApiError:f}=Z(),{uiConfig:y}=G(),[v,T]=p.useState(""),[w,k]=p.useState(""),[E,x]=p.useState(null),[P,M]=p.useState("later"),[L,I]=p.useState({}),F=V=>{I(he=>({...he,[V]:void 0}))},O=(V,he)=>{I(At=>({...At,[V]:he}))},[A,U]=p.useState(""),[X,R]=p.useState(ct),[_,q]=p.useState(ut(ct)),[se,ae]=p.useState({}),W=t!==void 0;p.useEffect(()=>{T((t==null?void 0:t.name)||""),k((t==null?void 0:t.username)||""),x(l.find(({id:V})=>V===(t==null?void 0:t.rootRole))||null),M("later"),I({}),U(""),R(ct),q(ut(ct)),ae({})},[n,t]);const re=()=>({name:v,username:w,rootRole:(E==null?void 0:E.id)||0}),Ye=async V=>{V.preventDefault();try{if(W)await c(t.id,re());else{const{id:he}=await u(re());if(P==="now"){const At=await m(he,{description:A,expiresAt:_});a(At)}}S({title:`Service account ${W?"updated":"added"} successfully`,type:"success"}),d(),o(!1)}catch(he){f(K(he))}},Et=()=>`curl --location --request ${W?"PUT":"POST"} '${y.unleashUrl}/api/admin/service-account${W?`/${t.id}`:""}' \\
19
+ --data-raw '${JSON.stringify(R,void 0,2)}'`,q=re=>{k(E.NAME),f(re)||w(E.NAME,"A role with that name already exists."),d(re)},se=()=>{P(),s()},ae=async re=>{if(re.preventDefault(),!!X)try{L?await U(i.id,R):await M(R),F({title:`Role ${L?"updated":"added"} successfully`,type:"success"}),se(),a(!1)}catch(Ye){O(K(Ye))}};p.useEffect(()=>{x()},[o]);const H=t[0].toUpperCase()+t.slice(1);return e(Ft,{open:o,onClose:()=>{a(!1)},label:L?`Edit ${t} role`:`New ${t} role`,children:e(Pe,{loading:I,modal:!0,title:L?`Edit ${t} role`:`New ${t} role`,description:`${H} roles allow you to control access to ${t} resources. Besides the built-in ${t} roles, you can create and manage custom ${t} roles to fit your needs.`,documentationLink:`https://docs.getunleash.io/reference/rbac${t===Ie?"#custom-root-roles":"#custom-project-roles"}`,documentationLinkLabel:"Roles documentation",formatApiCode:_,children:r(rc,{onSubmit:ae,children:[e(ac,{type:t,name:l,onSetName:q,description:u,setDescription:c,checkedPermissions:h,setCheckedPermissions:m,errors:T}),r(ic,{children:[r(z,{type:"submit",variant:"contained",color:"primary",disabled:!X,children:[L?"Save":"Add"," role"]}),e(sc,{onClick:()=>{a(!1)},children:"Cancel"})]})]})})})},cc=({row:t})=>{var a,i;const{original:n}=t,{role:o}=mo(n.id.toString());return!o||je.includes(o.type)?null:e(te,{children:e(Kt,{tooltip:e(Xa,{roleId:n.id,tooltip:!0}),children:((a=o.permissions)==null?void 0:a.length)===1?"1 permission":`${(i=o.permissions)==null?void 0:i.length} permissions`})})},Bn=({type:t=Ie,searchValue:n="",modalOpen:o,setModalOpen:a,selectedRole:i,setSelectedRole:s})=>{const{setToastData:l,setToastApiError:d}=Z(),u=Jt(),{roles:c,projectRoles:h,refetch:m,loading:S}=wt(),{removeRole:f}=Bo(),[y,v]=p.useState(!1),T=async O=>{try{await f(O.id),l({title:`${O.name} has been deleted`,type:"success"}),m(),v(!1)}catch(A){d(K(A))}},w=ye(u.breakpoints.down("md")),k=p.useMemo(()=>[{id:"Icon",Cell:()=>e(Qa,{icon:e(Vr,{color:"disabled"})}),disableGlobalFilter:!0,maxWidth:50},{Header:"Role",accessor:"name",Cell:({row:{original:O}})=>e(Ml,{role:O}),searchable:!0,minWidth:100},{id:"permissions",Header:"Permissions",Cell:cc,maxWidth:140},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:O}})=>e(Nl,{role:O,onEdit:()=>{s(O),a(!0)},onDelete:()=>{s(O),v(!0)}}),width:150,disableSortBy:!0},{accessor:"description",Header:"Description",searchable:!0}],[]),[E]=p.useState({sortBy:[{id:"name"}],hiddenColumns:["description"]}),{data:x,getSearchText:P}=nt(k,n,t===Ie?c:h),{headerGroups:M,rows:U,prepareRow:I,setHiddenColumns:F}=$.useTable({columns:k,data:x,initialState:E,sortTypes:Se,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0,defaultColumn:{Cell:te}},$.useSortBy,$.useFlexLayout);return et([{condition:w,columns:["Icon"]}],F,k),r(ee,{isLoading:S,children:[e(qe,{value:P(n),children:e(xe,{rows:U,headerGroups:M,prepareRow:I})}),e(C,{condition:U.length===0,show:e(C,{condition:(n==null?void 0:n.length)>0,show:r(fe,{children:["No ",t," roles found matching “",n,"”"]}),elseShow:r(fe,{children:["No ",t," roles available. Get started by adding one."]})})}),e(lc,{type:t,roleId:i==null?void 0:i.id,open:o,setOpen:a}),e(Xl,{role:i,open:y,setOpen:v,onConfirm:T})]})},dc=g("div")(()=>({display:"flex",justifyContent:"space-between",alignItems:"center"})),uc=g("div")({flex:1}),hc=g("div")({display:"flex",alignItems:"center"}),pc=()=>{const{uiConfig:t}=G(),{pathname:n}=Xt(),{roles:o,projectRoles:a,loading:i}=wt(),[s,l]=p.useState(""),[d,u]=p.useState(!1),[c,h]=p.useState(),m=t.flags.customRootRolesKillSwitch?[{label:"Project roles",path:"/admin/roles",total:a.length}]:[{label:"Root roles",path:"/admin/roles",total:o.length},{label:"Project roles",path:"/admin/roles/project-roles",total:a.length}],S=ye(Oe.breakpoints.down("md")),f=t.flags.customRootRolesKillSwitch||n.includes("project-roles")?Ut:Ie;return e(ee,{withTabs:!0,bodyClass:"page-body",isLoading:i,header:r(B,{children:[r(dc,{children:[e(uc,{children:e(gt,{value:n,indicatorColor:"primary",textColor:"primary",variant:"scrollable",allowScrollButtonsMobile:!0,children:m.map(({label:y,path:v,total:T})=>e(ft,{value:v,label:e(an,{to:v,children:r("span",{children:[y," (",T,")"]})}),sx:{padding:0}},y))})}),r(hc,{children:[e(C,{condition:!S,show:r(B,{children:[e(me,{initialValue:s,onChange:l}),e(ne.Divider,{})]})}),r(qt,{onClick:()=>{h(void 0),u(!0)},maxWidth:`${Oe.breakpoints.values.sm}px`,Icon:St,permission:Y,children:["New ",f," role"]})]})]}),e(C,{condition:S,show:e(me,{initialValue:s,onChange:l})})]}),children:r(ot,{children:[e(W,{path:"project-roles",element:e(Bn,{type:Ut,searchValue:s,modalOpen:d,setModalOpen:u,selectedRole:c,setSelectedRole:h})}),e(W,{path:"*",element:e(Bn,{type:t.flags.customRootRolesKillSwitch?Ut:Ie,searchValue:s,modalOpen:d,setModalOpen:u,selectedRole:c,setSelectedRole:h})})]})})},mc=()=>{const{isEnterprise:t}=G();return t()?e("div",{children:e(Te,{permissions:[er,Y],children:e(pc,{})})}):e(yt,{feature:"project-roles",page:!0})},Lo=()=>{const{loading:t,makeRequest:n,createRequest:o,errors:a}=$e({propagateErrors:!0});return{addServiceAccount:async d=>{const u="addServiceAccount",c=o("api/admin/service-account",{method:"POST",body:JSON.stringify(d)},u);return await(await n(c.caller,c.id)).json()},updateServiceAccount:async(d,u)=>{const c="updateServiceAccount",h=o(`api/admin/service-account/${d}`,{method:"PUT",body:JSON.stringify(u)},c);await n(h.caller,h.id)},removeServiceAccount:async d=>{const u="removeServiceAccount",c=o(`api/admin/service-account/${d}`,{method:"DELETE"},u);await n(c.caller,c.id)},errors:a,loading:t}},Oo=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=$e({propagateErrors:!0});return{createServiceAccountToken:async(l,d)=>{const u=n(`api/admin/service-account/${l}/token`,{method:"POST",body:JSON.stringify(d)});try{return await(await t(u.caller,u.id)).json()}catch(c){throw c}},deleteServiceAccountToken:async(l,d)=>{const u=n(`api/admin/service-account/${l}/token/${d}`,{method:"DELETE"});try{await t(u.caller,u.id)}catch(c){throw c}},errors:o,loading:a}},gc=t=>{const{isEnterprise:n}=G(),{data:o,error:a,mutate:i}=bt(n(),{pats:[]},oe(`api/admin/service-account/${t}/token`),fc);return{tokens:o?o.pats:void 0,loading:!a&&!o,refetchTokens:()=>i(),error:a}},fc=t=>fetch(t).then(ue("Service Account Tokens")).then(n=>n.json()),lt=go["30DAYS"],yc=({open:t,setOpen:n,tokens:o,onCreateClick:a})=>{const[i,s]=p.useState(""),[l,d]=p.useState(lt),[u,c]=p.useState(ut(lt)),[h,m]=p.useState({});p.useEffect(()=>{s(""),d(lt),c(ut(lt)),m({})},[t]);const S=y=>!(o!=null&&o.some(v=>v.description===y)),f=i.length&&S(i)&&u>new Date;return e(ie,{open:t,primaryButtonText:"Create token",secondaryButtonText:"Cancel",onClick:()=>a({description:i,expiresAt:u}),disabledPrimaryButton:!f,onClose:()=>{n(!1)},title:"New token",children:e(fo,{description:i,setDescription:s,isDescriptionUnique:S,expiration:l,setExpiration:d,expiresAt:u,setExpiresAt:c,errors:h,setErrors:m})})},bc=g(J)(({theme:t})=>({marginBottom:t.spacing(3)})),$o=({open:t,setOpen:n,token:o})=>r(ie,{open:t,secondaryButtonText:"Close",onClose:(a,i)=>{i||n(!1)},title:"Service account token created",children:[e(bc,{severity:"info",children:"Make sure to copy your service account API token now. You won't be able to see it again!"}),e(D,{variant:"body1",children:"Your token:"}),e(tr,{token:(o==null?void 0:o.secret)||""})]}),Sc=g("div")(({theme:t})=>({display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:t.spacing(2),gap:t.spacing(2),"& > div":{[t.breakpoints.down("md")]:{marginTop:0}}})),vc=g("div")(({theme:t})=>({display:"flex",flexDirection:"column",alignItems:"center",padding:t.spacing(3)})),Cc=g(D)(({theme:t})=>({fontSize:t.fontSizes.bodySize,marginBottom:t.spacing(.5)})),wc=g(D)(({theme:t})=>({fontSize:t.fontSizes.smallBody,color:t.palette.text.secondary,marginBottom:t.spacing(1.5)})),Tc={id:"createdAt"},No=({serviceAccount:t,readOnly:n})=>{const o=Jt(),{setToastData:a,setToastApiError:i}=Z(),s=ye(o.breakpoints.down("md")),l=ye(o.breakpoints.down("sm")),{tokens:d=[],refetchTokens:u}=gc(t.id),{refetch:c}=rt(),{createServiceAccountToken:h,deleteServiceAccountToken:m}=Oo(),[S]=p.useState(()=>({sortBy:n?[{id:"seenAt"}]:[Tc]})),[f,y]=p.useState(""),[v,T]=p.useState(!1),[w,k]=p.useState(!1),[E,x]=p.useState(!1),[P,M]=p.useState(),[U,I]=p.useState(),F=async H=>{try{const re=await h(t.id,H);c(),u(),T(!1),M(re),k(!0),a({title:"Token created successfully",type:"success"})}catch(re){i(K(re))}},O=async()=>{if(U)try{await m(t.id,U==null?void 0:U.id),c(),u(),x(!1),a({title:"Token deleted successfully",type:"success"})}catch(H){i(K(H))}},A=p.useMemo(()=>[{Header:"Description",accessor:"description",Cell:Ce,minWidth:100,searchable:!0},{Header:"Expires",accessor:"expiresAt",Cell:({value:H})=>new Date(H).getFullYear()>new Date().getFullYear()+100?e(te,{children:"Never"}):e(ve,{value:H}),sortType:"date",maxWidth:150},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",maxWidth:150},{Header:"Last seen",accessor:"seenAt",Cell:Ve,sortType:"date",maxWidth:150},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:H}})=>e(pt,{children:e(Ue,{title:"Delete token",arrow:!0,describeChild:!0,children:e("span",{children:e(We,{onClick:()=>{I(H),x(!0)},children:e(Le,{})})})})}),maxWidth:100,disableSortBy:!0}],[I,x]),{data:L,getSearchText:X,getSearchContext:R}=nt(A,f,d),{headerGroups:_,rows:q,prepareRow:se,setHiddenColumns:ae}=$.useTable({columns:A,data:L,initialState:S,sortTypes:Se,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},$.useSortBy,$.useFlexLayout);return et([{condition:l,columns:["expiresAt"]},{condition:s,columns:["createdAt"]},{condition:!!n,columns:["Actions","expiresAt","createdAt"]}],ae,A),r(B,{children:[e(C,{condition:!n,show:r(Sc,{children:[e(me,{initialValue:f,onChange:y,getSearchContext:R}),e(z,{variant:"contained",color:"primary",disabled:d.length>=nr,onClick:()=>T(!0),children:"New token"})]})}),e(qe,{value:X(f),children:e(xe,{rows:q,headerGroups:_,prepareRow:se})}),e(C,{condition:q.length===0,show:e(C,{condition:(f==null?void 0:f.length)>0,show:r(fe,{children:["No tokens found matching “",f,"”"]}),elseShow:r(vc,{children:[e(Cc,{children:"You have no tokens for this service account yet."}),e(wc,{children:"Create a service account token for access to the Unleash API."}),e(z,{variant:"outlined",onClick:()=>T(!0),children:"Create new service account token"})]})})}),e(yc,{open:v,setOpen:T,tokens:d,onCreateClick:F}),e($o,{open:w,setOpen:k,token:P}),e(ie,{open:E,primaryButtonText:"Delete token",secondaryButtonText:"Cancel",onClick:O,onClose:()=>{x(!1)},title:"Delete token?",children:r(D,{children:['Any applications or scripts using this token "',e("strong",{children:U==null?void 0:U.description}),'" will no longer be able to access the Unleash API. You cannot undo this action.']})})]})},xc=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Ze=g("p")(({theme:t})=>({display:"flex",color:t.palette.text.primary,marginBottom:t.spacing(1),"&:not(:first-of-type)":{marginTop:t.spacing(4)}})),Un=g("p")(({theme:t})=>({color:t.palette.text.secondary,marginBottom:t.spacing(1)})),Ln=g(tt)(({theme:t})=>({width:"100%",maxWidth:t.spacing(50)})),Ec=g(en)(({theme:t})=>({width:"100%",maxWidth:t.spacing(50)})),kc=g("div")(({theme:t})=>({padding:t.spacing(3),backgroundColor:t.palette.background.elevation2,borderRadius:t.shape.borderRadiusMedium,marginTop:t.spacing(4),marginBottom:t.spacing(2)})),Rc=g("div")(({theme:t})=>({padding:t.spacing(0,4),"& > p:not(:first-of-type)":{marginTop:t.spacing(2)}})),Ac=g("div")(({theme:t})=>({marginTop:"auto",display:"flex",justifyContent:"flex-end",paddingTop:t.spacing(4)})),Dc=g(z)(({theme:t})=>({marginLeft:t.spacing(3)})),ct=go["30DAYS"],Ic=({serviceAccount:t,open:n,setOpen:o,newToken:a})=>{const{users:i}=Ee(),{serviceAccounts:s,roles:l,refetch:d}=rt(),{addServiceAccount:u,updateServiceAccount:c,loading:h}=Lo(),{createServiceAccountToken:m}=Oo(),{setToastData:S,setToastApiError:f}=Z(),{uiConfig:y}=G(),[v,T]=p.useState(""),[w,k]=p.useState(""),[E,x]=p.useState(null),[P,M]=p.useState("later"),[U,I]=p.useState({}),F=V=>{I(pe=>({...pe,[V]:void 0}))},O=(V,pe)=>{I(At=>({...At,[V]:pe}))},[A,L]=p.useState(""),[X,R]=p.useState(ct),[_,q]=p.useState(ut(ct)),[se,ae]=p.useState({}),H=t!==void 0;p.useEffect(()=>{T((t==null?void 0:t.name)||""),k((t==null?void 0:t.username)||""),x(l.find(({id:V})=>V===(t==null?void 0:t.rootRole))||null),M("later"),I({}),L(""),R(ct),q(ut(ct)),ae({})},[n,t]);const re=()=>({name:v,username:w,rootRole:(E==null?void 0:E.id)||0}),Ye=async V=>{V.preventDefault();try{if(H)await c(t.id,re());else{const{id:pe}=await u(re());if(P==="now"){const At=await m(pe,{description:A,expiresAt:_});a(At)}}S({title:`Service account ${H?"updated":"added"} successfully`,type:"success"}),d(),o(!1)}catch(pe){f(K(pe))}},Et=()=>`curl --location --request ${H?"PUT":"POST"} '${y.unleashUrl}/api/admin/service-account${H?`/${t.id}`:""}' \\
20
20
  --header 'Authorization: INSERT_API_KEY' \\
21
21
  --header 'Content-Type: application/json' \\
22
- --data-raw '${JSON.stringify(re(),void 0,2)}'`,ke=V=>V.length,Je=V=>!(i!=null&&i.some(he=>he.username===V))&&!(s!=null&&s.some(he=>he.username===V)),kt=E!==null,j=P==="later"||ke(A)&&_>new Date,le=ke(v)&&ke(w)&&(W||Je(w))&&kt&&j,Rt=()=>{if(ke(v)&&!ke(w)){const V=`service-${v.toLowerCase().replace(/ /g,"-").replace(/[^\w_-]/g,"")}`;Je(V)&&k(V)}},Ho=V=>{F("username"),Je(V)||O("username","A service account or user with that username already exists."),k(V)};return e(Ft,{open:n,onClose:()=>{o(!1)},label:W?"Edit service account":"New service account",children:e(Pe,{loading:h,modal:!0,title:W?"Edit service account":"New service account",description:"A service account is a special type of account that can only be used to authenticate with the Unleash API. Service accounts can be used to automate tasks.",documentationLink:"https://docs.getunleash.io",documentationLinkLabel:"Service accounts documentation",formatApiCode:Et,children:r(xc,{onSubmit:Ye,children:[r("div",{children:[e(Ze,{children:"What is your new service account name?"}),e(Un,{autoFocus:!0,label:"Service account name",value:v,onChange:V=>T(V.target.value),onBlur:Rt,autoComplete:"off",required:!0}),e(Ze,{children:"What is your new service account username?"}),e(Un,{label:"Service account username",error:!!L.username,errorText:L.username,value:w,onChange:V=>Ho(V.target.value),autoComplete:"off",required:!0,disabled:W}),e(Ze,{children:"What is your service account allowed to do?"}),e(Ec,{roles:l,value:E,setValue:x,required:!0}),e(C,{condition:!W,show:r(kc,{children:[e(Ze,{children:"Token"}),r(Ln,{children:["In order to connect your newly created service account, you will also need a token."," ",e(Qt,{href:"https://docs.getunleash.io/reference/api-tokens-and-client-keys",target:"_blank",rel:"noreferrer",children:"Read more about API tokens"}),"."]}),e(mt,{children:r(or,{value:P,onChange:V=>M(V.target.value),name:"token-generation",children:[e(me,{value:"later",control:e(mn,{}),label:"I want to generate a token later"}),e(me,{value:"now",control:e(mn,{}),label:"Generate a token now"})]})}),r(Rc,{children:[e(Ln,{children:"A new personal access token (PAT) will be generated for the service account, so you can get started right away."}),e(C,{condition:P==="now",show:e(fo,{description:A,setDescription:U,expiration:X,setExpiration:R,expiresAt:_,setExpiresAt:q,errors:se,setErrors:ae})})]})]}),elseShow:r(B,{children:[e(Ze,{children:"Service account tokens"}),e(No,{serviceAccount:t})]})})]}),r(Ac,{children:[r(z,{type:"submit",variant:"contained",color:"primary",disabled:!le,children:[W?"Save":"Add"," service account"]}),e(Dc,{onClick:()=>{o(!1)},children:"Cancel"})]})]})})})},Pc=g("div")(({theme:t})=>({marginTop:t.spacing(1.5)})),On=g("p")(({theme:t})=>({marginTop:t.spacing(3)})),Bc=({serviceAccount:t,open:n,setOpen:o,onConfirm:a})=>{const i=r(B,{children:["You are about to delete service account:"," ",e("strong",{children:t==null?void 0:t.name})]});return e(ie,{title:"Delete service account?",open:n,primaryButtonText:"Delete service account",secondaryButtonText:"Cancel",onClick:()=>a(t),onClose:()=>{o(!1)},children:e(C,{condition:!!(t!=null&&t.tokens.length),show:r(B,{children:[e(J,{severity:"error",children:"Deleting this service account may break any existing implementations currently using it."}),e(On,{children:i}),e(On,{children:"Service account tokens:"}),e(Pc,{children:e(No,{serviceAccount:t,readOnly:!0})})]}),elseShow:e("p",{children:i})})})},Lc=g(N)(()=>({display:"flex",justifyContent:"center"})),Uc=({onEdit:t,onDelete:n})=>r(Lc,{children:[e(Ae,{"data-loading":!0,onClick:t,permission:Y,tooltipProps:{title:"Edit service account"},children:e(Qe,{})}),e(Ae,{"data-loading":!0,onClick:n,permission:Y,tooltipProps:{title:"Remove service account"},children:e(Ue,{})})]}),Oc=()=>{const{setToastData:t,setToastApiError:n}=Z(),{serviceAccounts:o,roles:a,refetch:i,loading:s}=rt(),{removeServiceAccount:l}=Uo(),[d,u]=p.useState(""),[c,h]=p.useState(!1),[m,S]=p.useState(!1),[f,y]=p.useState(),[v,T]=p.useState(!1),[w,k]=p.useState(),E=async R=>{try{await l(R.id),t({title:`${R.name} has been deleted`,type:"success"}),i(),T(!1)}catch(_){n(K(_))}},x=fe(Oe.breakpoints.down("sm")),P=fe(Oe.breakpoints.down("md")),M=p.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:R}})=>e(te,{children:e(We,{user:R})}),disableSortBy:!0,maxWidth:80},{id:"name",Header:"Name",accessor:R=>R.name||"",minWidth:200,Cell:({row:{original:R}})=>e(Ce,{value:R.name,subtitle:R.username}),searchable:!0},{id:"role",Header:"Role",accessor:R=>{var _;return((_=a.find(q=>q.id===R.rootRole))==null?void 0:_.name)||""},Cell:({row:{original:R},value:_})=>e(Co,{value:_,roleId:R.rootRole}),maxWidth:120},{id:"tokens",Header:"Tokens",accessor:R=>{var _;return((_=R.tokens)==null?void 0:_.map(({description:q})=>q).join(`
23
- `))||""},Cell:({row:{original:R},value:_})=>e(Po,{serviceAccount:R,value:_,onCreateToken:()=>{k(R),h(!0)}}),searchable:!0},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",width:120,maxWidth:120},{id:"seenAt",Header:"Last seen",accessor:R=>{var _;return(_=R.tokens.sort((q,se)=>{const ae=new Date(q.seenAt||0),W=new Date(se.seenAt||0);return(W==null?void 0:W.getTime())-(ae==null?void 0:ae.getTime())})[0])==null?void 0:_.seenAt},Cell:Ve,sortType:"date",maxWidth:150},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:R}})=>e(Uc,{onEdit:()=>{k(R),h(!0)},onDelete:()=>{k(R),T(!0)}}),width:150,disableSortBy:!0},{accessor:"username",Header:"Username",searchable:!0}],[a]),[L]=p.useState({sortBy:[{id:"createdAt"}],hiddenColumns:["username"]}),{data:I,getSearchText:F}=nt(M,d,o),{headerGroups:O,rows:A,prepareRow:U,setHiddenColumns:X}=$.useTable({columns:M,data:I,initialState:L,sortTypes:be,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0,defaultColumn:{Cell:te}},$.useSortBy,$.useFlexLayout);return et([{condition:x,columns:["role","seenAt"]},{condition:P,columns:["imageUrl","tokens","createdAt"]}],X,M),r(ee,{isLoading:s,header:e(ne,{title:`Service Accounts (${A.length})`,actions:r(B,{children:[e(C,{condition:!P,show:r(B,{children:[e(pe,{initialValue:d,onChange:u}),e(ne.Divider,{})]})}),e(z,{variant:"contained",color:"primary",onClick:()=>{k(void 0),h(!0)},children:"New service account"})]}),children:e(C,{condition:P,show:e(pe,{initialValue:d,onChange:u})})}),children:[e(qe,{value:F(d),children:e(xe,{rows:A,headerGroups:O,prepareRow:U})}),e(C,{condition:A.length===0,show:e(C,{condition:(d==null?void 0:d.length)>0,show:r(ge,{children:["No service accounts found matching “",d,"”"]}),elseShow:e(ge,{children:"No service accounts available. Get started by adding one."})})}),e(Ic,{serviceAccount:w,open:c,setOpen:h,newToken:R=>{y(R),S(!0)}}),e($o,{open:m,setOpen:S,token:f}),e(Bc,{serviceAccount:w,open:v,setOpen:T,onConfirm:E})]})},$c=()=>{const{isEnterprise:t}=G();return e("div",{children:e(C,{condition:t(),show:e(Te,{permissions:Y,children:e(Oc,{})}),elseShow:e(yt,{feature:"service-accounts",page:!0})})})},Nc=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Gc=g("div")(({theme:t})=>({maxWidth:t.spacing(50)})),Mc=g("p")(({theme:t})=>({marginBottom:t.spacing(1)})),$n=g(tt)(({theme:t})=>({width:"100%",marginBottom:t.spacing(2)})),Nn=g(D)(({theme:t})=>({margin:t.spacing(1,0)})),jc=g("div")(()=>({display:"flex",alignItems:"center"})),_c=g("div")(()=>({marginTop:"auto",display:"flex",justifyContent:"flex-end"})),Hc=g(z)(({theme:t})=>({marginLeft:t.spacing(3)})),Go=({children:t,email:n,name:o,rootRole:a,sendEmail:i,setEmail:s,setName:l,setSendEmail:d,setRootRole:u,handleSubmit:c,handleCancel:h,errors:m,clearErrors:S,mode:f})=>{const{uiConfig:y}=G(),{roles:v}=Ee();return r(Nc,{onSubmit:c,children:[r(Gc,{children:[e(Mc,{children:"Who is the new Unleash user?"}),e($n,{label:"Full name",value:o,onChange:T=>l(T.target.value),error:!!m.name,errorText:m.name,onFocus:()=>S(),autoFocus:!0}),e($n,{label:"Email",type:"email",value:n,onChange:T=>s(T.target.value),error:!!m.email,errorText:m.email,onFocus:()=>S()}),e(Nn,{variant:"subtitle1","data-loading":!0,children:"What is your team member allowed to do?"}),e(en,{roles:v,value:a,setValue:u,required:!0}),e(C,{condition:f!==Yt&&!!(y!=null&&y.emailEnabled),show:r(mt,{children:[e(Nn,{variant:"subtitle1","data-loading":!0,children:"Should we send an email to your new team member"}),r(jc,{children:[e(Se,{name:"sendEmail",onChange:()=>d(!i),checked:i}),e(D,{children:i?"Yes":"No"})]})]})})]}),r(_c,{children:[t,e(Hc,{onClick:h,children:"Cancel"})]})]})},Wc=async(t,n,o)=>{const a=await n.json(),i=a.isJoi?a.details[0].message:a[0].msg;throw t(s=>({...s,[o]:i})),new Error},zc=(t,n,o)=>{throw t(a=>({...a,[o]:"Could not find the requested resource."})),new ar(n.status)},Fc=async(t,n,o)=>{const a=await n.json(),i=a.isJoi?a.details[0].message:a[0].msg;throw t(s=>({...s,[o]:i})),new rr(n.status)},qc=async(t,n,o)=>{const a=await n.json(),i=a.isJoi?a.details[0].message:a[0].msg;throw t(s=>({...s,[o]:i})),new ir(n.status)},Gn="removeUser",Tt=()=>{const{loading:t,makeRequest:n,createRequest:o,errors:a}=$e({handleBadRequest:Wc,handleNotFound:zc,handleUnauthorized:Fc,handleForbidden:qc});return{addUser:async c=>{const h="addUser",m=o("api/admin/user-admin",{method:"POST",body:JSON.stringify(c)},h);return n(m.caller,m.id)},updateUser:async c=>{const h="updateUser",m=o(`api/admin/user-admin/${c.id}`,{method:"PUT",body:JSON.stringify(c)},h);return n(m.caller,m.id)},removeUser:async c=>{const h="removeUser",m=o(`api/admin/user-admin/${c}`,{method:"DELETE"},h);return n(m.caller,m.id)},changePassword:async(c,h)=>{const m="changePassword",S=o(`api/admin/user-admin/${c}/change-password`,{method:"POST",body:JSON.stringify({password:h})},m);return n(S.caller,S.id)},validatePassword:async c=>{const h="validatePassword",m=o("api/admin/user-admin/validate-password",{method:"POST",body:JSON.stringify({password:c})},h);return n(m.caller,m.id)},userApiErrors:a,userLoading:t}},Mo=(t="",n="",o=null)=>{const{uiConfig:a}=G(),{users:i,roles:s}=Ee(),[l,d]=p.useState(t),[u,c]=p.useState(n),[h,m]=p.useState(!1),[S,f]=p.useState(s.find(({id:x})=>x===o)||null),[y,v]=p.useState({});return p.useEffect(()=>{d(t)},[t]),p.useEffect(()=>{c(n)},[n]),p.useEffect(()=>{m((a==null?void 0:a.emailEnabled)||!1)},[a==null?void 0:a.emailEnabled]),p.useEffect(()=>{f(s.find(({id:x})=>x===o)||null)},[o]),{name:l,setName:d,email:u,setEmail:c,sendEmail:h,setSendEmail:m,rootRole:S,setRootRole:f,getAddUserPayload:()=>({name:l,email:u,sendEmail:h,rootRole:(S==null?void 0:S.id)||0}),validateName:()=>l.length===0?(v(x=>({...x,name:"Name can not be empty."})),!1):u.length===0?(v(x=>({...x,email:"Email can not be empty."})),!1):!0,validateEmail:()=>i.some(x=>x.email===u)?(v(x=>({...x,email:"Email already exists"})),!1):!0,clearErrors:()=>{v({})},errors:y}},Vc=t=>p.createElement("svg",{width:197,height:177,viewBox:"0 0 197 177",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},p.createElement("g",{clipPath:"url(#clip0)"},p.createElement("path",{d:"M195.272 67.6884C195.201 67.6884 195.132 67.6668 195.074 67.6264L99.4918 1.00044C99.2009 0.798626 98.8553 0.690774 98.5013 0.691378C98.1474 0.691982 97.8021 0.801012 97.5119 1.00382L2.61779 67.6257C2.54273 67.6784 2.44984 67.6991 2.35954 67.6832C2.26924 67.6674 2.18893 67.6163 2.13629 67.5411C2.08364 67.466 2.06297 67.373 2.07881 67.2826C2.09466 67.1923 2.14573 67.1119 2.22079 67.0592L97.115 0.437299C97.5213 0.153417 98.0047 0.000817369 98.5002 2.3283e-06C98.9957 -0.000812712 99.4796 0.150195 99.8868 0.432738L195.469 67.0585C195.53 67.1006 195.575 67.1609 195.599 67.2306C195.623 67.3004 195.624 67.3758 195.602 67.4461C195.58 67.5164 195.536 67.5778 195.476 67.6214C195.417 67.6649 195.345 67.6884 195.272 67.6884L195.272 67.6884Z",fill:"#3F3D56"}),p.createElement("path",{d:"M8.04028 70.0501L98.5953 2.87773L189.837 74.8297L103.261 126.199L56.2576 115.476L8.04028 70.0501Z",fill:"#E6E6E6"}),p.createElement("path",{d:"M60.2251 157.928H15.4887C15.214 157.928 14.942 157.875 14.6881 157.77C14.4342 157.665 14.2035 157.511 14.0091 157.316C13.8147 157.122 13.6606 156.891 13.5554 156.637C13.4502 156.383 13.396 156.111 13.396 155.836C13.396 155.561 13.4502 155.289 13.5554 155.035C13.6606 154.781 13.8147 154.55 14.0091 154.356C14.2035 154.162 14.4342 154.008 14.6881 153.903C14.942 153.798 15.214 153.744 15.4887 153.744H60.2251C60.4998 153.744 60.7719 153.798 61.0258 153.903C61.2797 154.008 61.5104 154.162 61.7048 154.356C61.8991 154.55 62.0533 154.781 62.1585 155.035C62.2637 155.289 62.3179 155.561 62.3179 155.836C62.3179 156.111 62.2637 156.383 62.1585 156.637C62.0533 156.891 61.8991 157.122 61.7048 157.316C61.5104 157.511 61.2797 157.665 61.0258 157.77C60.7719 157.875 60.4998 157.928 60.2251 157.928Z",fill:"#607D8B"}),p.createElement("path",{d:"M31.5392 148.934H15.4887C15.214 148.934 14.942 148.88 14.6881 148.776C14.4342 148.671 14.2035 148.516 14.0091 148.322C13.8147 148.128 13.6606 147.897 13.5554 147.643C13.4502 147.389 13.396 147.117 13.396 146.842C13.396 146.567 13.4502 146.295 13.5554 146.041C13.6606 145.787 13.8147 145.556 14.0091 145.362C14.2035 145.168 14.4342 145.014 14.6881 144.909C14.942 144.804 15.214 144.75 15.4887 144.75H31.5392C31.8139 144.75 32.0859 144.804 32.3398 144.909C32.5937 145.014 32.8244 145.168 33.0188 145.362C33.2132 145.556 33.3674 145.787 33.4726 146.041C33.5778 146.295 33.6319 146.567 33.6319 146.842C33.6319 147.117 33.5778 147.389 33.4726 147.643C33.3674 147.897 33.2132 148.128 33.0188 148.322C32.8244 148.516 32.5937 148.671 32.3398 148.776C32.0859 148.88 31.8139 148.934 31.5392 148.934Z",fill:"#607D8B"}),p.createElement("path",{d:"M99.8687 107.464C99.5287 107.465 99.1918 107.399 98.8771 107.27L43.0291 84.0761V11.4759C43.0298 10.8339 43.2849 10.2184 43.7385 9.76446C44.192 9.31051 44.8069 9.05515 45.4484 9.0544H152.589C153.23 9.05515 153.845 9.31051 154.299 9.76446C154.752 10.2184 155.007 10.8339 155.008 11.4759V84.1267L154.903 84.1717L100.89 107.258C100.567 107.394 100.22 107.464 99.8687 107.464Z",fill:"white"}),p.createElement("path",{d:"M99.8687 107.637C99.5061 107.637 99.1469 107.567 98.8112 107.43L42.8562 84.1916V11.4759C42.857 10.788 43.1303 10.1286 43.6163 9.64218C44.1022 9.1558 44.7611 8.88221 45.4483 8.88143H152.589C153.276 8.88221 153.935 9.1558 154.421 9.64218C154.907 10.1286 155.18 10.788 155.181 11.4759V84.2409L100.958 107.417C100.613 107.563 100.243 107.637 99.8687 107.637ZM43.5474 83.7295L99.0748 106.79C99.5928 107.001 100.173 106.997 100.688 106.781L154.49 83.7842V11.4759C154.489 10.9714 154.288 10.4879 153.932 10.1312C153.576 9.77452 153.093 9.57387 152.589 9.57328H45.4483C44.9444 9.57387 44.4612 9.77452 44.1049 10.1312C43.7485 10.4879 43.548 10.9714 43.5474 11.4759L43.5474 83.7295Z",fill:"#3F3D56"}),p.createElement("path",{d:"M194.581 66.9965H194.512L154.835 83.9537L100.55 107.155C100.337 107.244 100.11 107.291 99.8797 107.292C99.6496 107.293 99.4215 107.249 99.2084 107.162L43.2018 83.9052L2.55059 67.0242L2.48849 66.9965H2.4193C1.77788 66.9972 1.16293 67.2526 0.70938 67.7066C0.255828 68.1605 0.000711706 68.776 0 69.418V174.579C0.000712619 175.221 0.255828 175.836 0.70938 176.29C1.16293 176.744 1.77788 176.999 2.4193 177H194.581C195.222 176.999 195.837 176.744 196.291 176.29C196.744 175.836 196.999 175.221 197 174.579V69.418C196.999 68.776 196.744 68.1605 196.291 67.7066C195.837 67.2526 195.222 66.9972 194.581 66.9965ZM196.309 174.579C196.309 175.037 196.126 175.477 195.802 175.801C195.478 176.126 195.039 176.308 194.581 176.308H2.4193C1.96104 176.308 1.52161 176.126 1.19757 175.801C0.873536 175.477 0.691411 175.037 0.691228 174.579V69.418C0.691855 68.9707 0.865197 68.541 1.17501 68.2187C1.48483 67.8963 1.90713 67.7063 2.35365 67.6884L43.2018 84.6524L98.9425 107.802C99.5459 108.047 100.222 108.044 100.823 107.791L154.835 84.7043L194.65 67.6884C195.096 67.7076 195.517 67.8982 195.826 68.2203C196.135 68.5425 196.308 68.9714 196.309 69.418V174.579Z",fill:"#3F3D56"}),p.createElement("path",{d:"M99.3104 86.8775C97.2487 86.8813 95.2416 86.214 93.5919 84.9762L93.4896 84.8994L71.9541 68.3963C70.9567 67.6314 70.1197 66.6774 69.4907 65.5888C68.8617 64.5001 68.4531 63.2981 68.2882 62.0514C68.1233 60.8047 68.2054 59.5377 68.5297 58.3228C68.8541 57.1078 69.4143 55.9687 70.1785 54.9704C70.9426 53.9722 71.8958 53.1344 72.9835 52.5048C74.0711 51.8753 75.2721 51.4663 76.5177 51.3013C77.7632 51.1362 79.0291 51.2184 80.243 51.543C81.4569 51.8676 82.595 52.4284 83.5923 53.1932L97.5414 63.8988L130.505 20.8706C131.27 19.8726 132.223 19.0351 133.311 18.4059C134.399 17.7767 135.6 17.3682 136.846 17.2036C138.091 17.039 139.357 17.1216 140.571 17.4467C141.785 17.7718 142.923 18.333 143.92 19.0982L143.715 19.3767L143.925 19.1023C145.936 20.6494 147.252 22.9319 147.584 25.449C147.916 27.9661 147.237 30.5122 145.696 32.5287L106.922 83.1402C106.026 84.3065 104.872 85.2503 103.552 85.8984C102.232 86.5466 100.781 86.8816 99.3104 86.8775Z",fill:"#607D8B"})),p.createElement("defs",null,p.createElement("clipPath",{id:"clip0"},p.createElement("rect",{width:197,height:177,fill:"white"})))),xt=({inviteLink:t,small:n})=>{const{setToastData:o}=Z(),a=()=>{try{return navigator.clipboard.writeText(t).then(()=>{o({type:"success",title:"Successfully copied invite link."})}).catch(()=>{i()})}catch{i()}},i=()=>o({type:"error",title:"Could not copy invite link."});return r(N,{sx:{backgroundColor:s=>s.palette.background.elevation2,py:4,px:4,borderRadius:s=>`${s.shape.borderRadius}px`,mt:2,display:"flex",justifyContent:"space-between",alignItems:"center",wordBreak:"break-all",...n?{my:0,py:.5,pl:1.5,pr:.5,fontSize:s=>s.typography.body2.fontSize}:{}},children:[t,e(Le,{title:"Copy link",arrow:!0,children:e(He,{onClick:a,size:n?"small":"large",sx:n?{ml:.5}:{},children:e(sr,{sx:{fontSize:n?20:void 0}})})})]})},Yc=({open:t,closeConfirm:n,inviteLink:o})=>r(ie,{open:t,title:"Team member added",primaryButtonText:"Close",onClick:n,children:[e(D,{children:"A new team member has been added. We’ve sent an email on your behalf to inform them of their new account and role. No further steps are required."}),e(N,{sx:{width:"100%",textAlign:"center",px:"auto",py:4},children:e(Vc,{})}),e(D,{style:{fontWeight:"bold"},variant:"subtitle1",children:"In a rush?"}),e(D,{children:"You may also copy the invite link and send it to the user."}),e(xt,{inviteLink:o})]}),Jc=({open:t,closeConfirm:n,inviteLink:o})=>r(ie,{open:t,onClick:n,primaryButtonText:"Close",title:"Team member added",children:[e(D,{variant:"body1",sx:{mb:2},children:"A new team member has been added."}),e(D,{variant:"body1",children:"Please provide them with the following link. This will allow them to set up their password and get started with their Unleash account."}),e(xt,{inviteLink:o}),e(J,{severity:"info",sx:{mt:2},children:r(D,{variant:"body2",children:["Want to avoid this step in the future?"," ",e("a",{href:"https://docs.getunleash.io/docs/deploy/email",target:"_blank",rel:"noopener noreferrer",children:"If you configure an email server for Unleash"})," ","we'll automatically send informational getting started emails to new users once you add them."]})})]}),jo=({open:t,closeConfirm:n,emailSent:o,inviteLink:a})=>o?e(Yc,{open:t,closeConfirm:n,inviteLink:a}):e(Jc,{open:t,closeConfirm:n,inviteLink:a}),rn=t=>{var d;const{instanceStatus:n}=Qn(),{uiConfig:o}=G(),a=!!((d=o==null?void 0:o.flags)!=null&&d.proPlanAutoCharge&&(n==null?void 0:n.plan)===Ge.PRO),i=(n==null?void 0:n.seats)??5,s=p.useMemo(()=>Kc(t,a,i),[t,a,i]),l=s.filter(u=>u.paid).length;return{seats:i,extraSeats:l,planUsers:s,isBillingUsers:a}},Kc=(t,n,o=0)=>(!n||!o||t.sort((a,i)=>a.createdAt.localeCompare(i.createdAt)).forEach((a,i)=>{a.paid=!1,i>=o&&(a.paid=!0)}),t),Zc=()=>{const{users:t}=Ee(),{isBillingUsers:n,seats:o,planUsers:a}=rn(t);return!n||a.length<o?null:e(J,{severity:"info",sx:{marginBottom:i=>i.spacing(3)},children:r("p",{children:[e("strong",{children:"Heads up!"})," You are exceeding your allocated free members included in your plan (",a.length," of ",o,"). Creating this user will add ",e("strong",{children:"$15/month"})," to your invoice, starting with your next payment."]})})},Xc=()=>{const{setToastApiError:t}=Z(),{uiConfig:n}=G(),o=ye(),{name:a,setName:i,email:s,setEmail:l,sendEmail:d,setSendEmail:u,rootRole:c,setRootRole:h,getAddUserPayload:m,validateName:S,validateEmail:f,errors:y,clearErrors:v}=Mo(),[T,w]=p.useState(!1),[k,E]=p.useState(""),{addUser:x,userLoading:P}=Tt();return r(Pe,{loading:P,title:"Create Unleash user",description:"In order for a user to get access to Unleash, they need to be assigned a root role, such as Viewer, Editor, or Admin.",documentationLink:"https://docs.getunleash.io/reference/rbac#predefined-roles",documentationLinkLabel:"User management documentation",formatApiCode:()=>`curl --location --request POST '${n.unleashUrl}/api/admin/user-admin' \\
22
+ --data-raw '${JSON.stringify(re(),void 0,2)}'`,ke=V=>V.length,Je=V=>!(i!=null&&i.some(pe=>pe.username===V))&&!(s!=null&&s.some(pe=>pe.username===V)),kt=E!==null,j=P==="later"||ke(A)&&_>new Date,le=ke(v)&&ke(w)&&(H||Je(w))&&kt&&j,Rt=()=>{if(ke(v)&&!ke(w)){const V=`service-${v.toLowerCase().replace(/ /g,"-").replace(/[^\w_-]/g,"")}`;Je(V)&&k(V)}},Wo=V=>{F("username"),Je(V)||O("username","A service account or user with that username already exists."),k(V)};return e(Ft,{open:n,onClose:()=>{o(!1)},label:H?"Edit service account":"New service account",children:e(Pe,{loading:h,modal:!0,title:H?"Edit service account":"New service account",description:"A service account is a special type of account that can only be used to authenticate with the Unleash API. Service accounts can be used to automate tasks.",documentationLink:"https://docs.getunleash.io",documentationLinkLabel:"Service accounts documentation",formatApiCode:Et,children:r(xc,{onSubmit:Ye,children:[r("div",{children:[e(Ze,{children:"What is your new service account name?"}),e(Ln,{autoFocus:!0,label:"Service account name",value:v,onChange:V=>T(V.target.value),onBlur:Rt,autoComplete:"off",required:!0}),e(Ze,{children:"What is your new service account username?"}),e(Ln,{label:"Service account username",error:!!U.username,errorText:U.username,value:w,onChange:V=>Wo(V.target.value),autoComplete:"off",required:!0,disabled:H}),e(Ze,{children:"What is your service account allowed to do?"}),e(Ec,{roles:l,value:E,setValue:x,required:!0}),e(C,{condition:!H,show:r(kc,{children:[e(Ze,{children:"Token"}),r(Un,{children:["In order to connect your newly created service account, you will also need a token."," ",e(Qt,{href:"https://docs.getunleash.io/reference/api-tokens-and-client-keys",target:"_blank",rel:"noreferrer",children:"Read more about API tokens"}),"."]}),e(mt,{children:r(or,{value:P,onChange:V=>M(V.target.value),name:"token-generation",children:[e(he,{value:"later",control:e(mn,{}),label:"I want to generate a token later"}),e(he,{value:"now",control:e(mn,{}),label:"Generate a token now"})]})}),r(Rc,{children:[e(Un,{children:"A new personal access token (PAT) will be generated for the service account, so you can get started right away."}),e(C,{condition:P==="now",show:e(fo,{description:A,setDescription:L,expiration:X,setExpiration:R,expiresAt:_,setExpiresAt:q,errors:se,setErrors:ae})})]})]}),elseShow:r(B,{children:[e(Ze,{children:"Service account tokens"}),e(No,{serviceAccount:t})]})})]}),r(Ac,{children:[r(z,{type:"submit",variant:"contained",color:"primary",disabled:!le,children:[H?"Save":"Add"," service account"]}),e(Dc,{onClick:()=>{o(!1)},children:"Cancel"})]})]})})})},Pc=g("div")(({theme:t})=>({marginTop:t.spacing(1.5)})),On=g("p")(({theme:t})=>({marginTop:t.spacing(3)})),Bc=({serviceAccount:t,open:n,setOpen:o,onConfirm:a})=>{const i=r(B,{children:["You are about to delete service account:"," ",e("strong",{children:t==null?void 0:t.name})]});return e(ie,{title:"Delete service account?",open:n,primaryButtonText:"Delete service account",secondaryButtonText:"Cancel",onClick:()=>a(t),onClose:()=>{o(!1)},children:e(C,{condition:!!(t!=null&&t.tokens.length),show:r(B,{children:[e(J,{severity:"error",children:"Deleting this service account may break any existing implementations currently using it."}),e(On,{children:i}),e(On,{children:"Service account tokens:"}),e(Pc,{children:e(No,{serviceAccount:t,readOnly:!0})})]}),elseShow:e("p",{children:i})})})},Uc=g(N)(()=>({display:"flex",justifyContent:"center"})),Lc=({onEdit:t,onDelete:n})=>r(Uc,{children:[e(Ae,{"data-loading":!0,onClick:t,permission:Y,tooltipProps:{title:"Edit service account"},children:e(Qe,{})}),e(Ae,{"data-loading":!0,onClick:n,permission:Y,tooltipProps:{title:"Remove service account"},children:e(Le,{})})]}),Oc=()=>{const{setToastData:t,setToastApiError:n}=Z(),{serviceAccounts:o,roles:a,refetch:i,loading:s}=rt(),{removeServiceAccount:l}=Lo(),[d,u]=p.useState(""),[c,h]=p.useState(!1),[m,S]=p.useState(!1),[f,y]=p.useState(),[v,T]=p.useState(!1),[w,k]=p.useState(),E=async R=>{try{await l(R.id),t({title:`${R.name} has been deleted`,type:"success"}),i(),T(!1)}catch(_){n(K(_))}},x=ye(Oe.breakpoints.down("sm")),P=ye(Oe.breakpoints.down("md")),M=p.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:R}})=>e(te,{children:e(He,{user:R})}),disableSortBy:!0,maxWidth:80},{id:"name",Header:"Name",accessor:R=>R.name||"",minWidth:200,Cell:({row:{original:R}})=>e(Ce,{value:R.name,subtitle:R.username}),searchable:!0},{id:"role",Header:"Role",accessor:R=>{var _;return((_=a.find(q=>q.id===R.rootRole))==null?void 0:_.name)||""},Cell:({row:{original:R},value:_})=>e(Co,{value:_,roleId:R.rootRole}),maxWidth:120},{id:"tokens",Header:"Tokens",accessor:R=>{var _;return((_=R.tokens)==null?void 0:_.map(({description:q})=>q).join(`
23
+ `))||""},Cell:({row:{original:R},value:_})=>e(Po,{serviceAccount:R,value:_,onCreateToken:()=>{k(R),h(!0)}}),searchable:!0},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",width:120,maxWidth:120},{id:"seenAt",Header:"Last seen",accessor:R=>{var _;return(_=R.tokens.sort((q,se)=>{const ae=new Date(q.seenAt||0),H=new Date(se.seenAt||0);return(H==null?void 0:H.getTime())-(ae==null?void 0:ae.getTime())})[0])==null?void 0:_.seenAt},Cell:Ve,sortType:"date",maxWidth:150},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:R}})=>e(Lc,{onEdit:()=>{k(R),h(!0)},onDelete:()=>{k(R),T(!0)}}),width:150,disableSortBy:!0},{accessor:"username",Header:"Username",searchable:!0}],[a]),[U]=p.useState({sortBy:[{id:"createdAt"}],hiddenColumns:["username"]}),{data:I,getSearchText:F}=nt(M,d,o),{headerGroups:O,rows:A,prepareRow:L,setHiddenColumns:X}=$.useTable({columns:M,data:I,initialState:U,sortTypes:Se,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0,defaultColumn:{Cell:te}},$.useSortBy,$.useFlexLayout);return et([{condition:x,columns:["role","seenAt"]},{condition:P,columns:["imageUrl","tokens","createdAt"]}],X,M),r(ee,{isLoading:s,header:e(ne,{title:`Service Accounts (${A.length})`,actions:r(B,{children:[e(C,{condition:!P,show:r(B,{children:[e(me,{initialValue:d,onChange:u}),e(ne.Divider,{})]})}),e(z,{variant:"contained",color:"primary",onClick:()=>{k(void 0),h(!0)},children:"New service account"})]}),children:e(C,{condition:P,show:e(me,{initialValue:d,onChange:u})})}),children:[e(qe,{value:F(d),children:e(xe,{rows:A,headerGroups:O,prepareRow:L})}),e(C,{condition:A.length===0,show:e(C,{condition:(d==null?void 0:d.length)>0,show:r(fe,{children:["No service accounts found matching “",d,"”"]}),elseShow:e(fe,{children:"No service accounts available. Get started by adding one."})})}),e(Ic,{serviceAccount:w,open:c,setOpen:h,newToken:R=>{y(R),S(!0)}}),e($o,{open:m,setOpen:S,token:f}),e(Bc,{serviceAccount:w,open:v,setOpen:T,onConfirm:E})]})},$c=()=>{const{isEnterprise:t}=G();return e("div",{children:e(C,{condition:t(),show:e(Te,{permissions:Y,children:e(Oc,{})}),elseShow:e(yt,{feature:"service-accounts",page:!0})})})},Nc=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Gc=g("div")(({theme:t})=>({maxWidth:t.spacing(50)})),Mc=g("p")(({theme:t})=>({marginBottom:t.spacing(1)})),$n=g(tt)(({theme:t})=>({width:"100%",marginBottom:t.spacing(2)})),Nn=g(D)(({theme:t})=>({margin:t.spacing(1,0)})),jc=g("div")(()=>({display:"flex",alignItems:"center"})),_c=g("div")(()=>({marginTop:"auto",display:"flex",justifyContent:"flex-end"})),Wc=g(z)(({theme:t})=>({marginLeft:t.spacing(3)})),Go=({children:t,email:n,name:o,rootRole:a,sendEmail:i,setEmail:s,setName:l,setSendEmail:d,setRootRole:u,handleSubmit:c,handleCancel:h,errors:m,clearErrors:S,mode:f})=>{const{uiConfig:y}=G(),{roles:v}=Ee();return r(Nc,{onSubmit:c,children:[r(Gc,{children:[e(Mc,{children:"Who is the new Unleash user?"}),e($n,{label:"Full name",value:o,onChange:T=>l(T.target.value),error:!!m.name,errorText:m.name,onFocus:()=>S(),autoFocus:!0}),e($n,{label:"Email",type:"email",value:n,onChange:T=>s(T.target.value),error:!!m.email,errorText:m.email,onFocus:()=>S()}),e(Nn,{variant:"subtitle1","data-loading":!0,children:"What is your team member allowed to do?"}),e(en,{roles:v,value:a,setValue:u,required:!0}),e(C,{condition:f!==Yt&&!!(y!=null&&y.emailEnabled),show:r(mt,{children:[e(Nn,{variant:"subtitle1","data-loading":!0,children:"Should we send an email to your new team member"}),r(jc,{children:[e(ge,{name:"sendEmail",onChange:()=>d(!i),checked:i}),e(D,{children:i?"Yes":"No"})]})]})})]}),r(_c,{children:[t,e(Wc,{onClick:h,children:"Cancel"})]})]})},Hc=async(t,n,o)=>{const a=await n.json(),i=a.isJoi?a.details[0].message:a[0].msg;throw t(s=>({...s,[o]:i})),new Error},zc=(t,n,o)=>{throw t(a=>({...a,[o]:"Could not find the requested resource."})),new ar(n.status)},Fc=async(t,n,o)=>{const a=await n.json(),i=a.isJoi?a.details[0].message:a[0].msg;throw t(s=>({...s,[o]:i})),new rr(n.status)},qc=async(t,n,o)=>{const a=await n.json(),i=a.isJoi?a.details[0].message:a[0].msg;throw t(s=>({...s,[o]:i})),new ir(n.status)},Gn="removeUser",Tt=()=>{const{loading:t,makeRequest:n,createRequest:o,errors:a}=$e({handleBadRequest:Hc,handleNotFound:zc,handleUnauthorized:Fc,handleForbidden:qc});return{addUser:async c=>{const h="addUser",m=o("api/admin/user-admin",{method:"POST",body:JSON.stringify(c)},h);return n(m.caller,m.id)},updateUser:async c=>{const h="updateUser",m=o(`api/admin/user-admin/${c.id}`,{method:"PUT",body:JSON.stringify(c)},h);return n(m.caller,m.id)},removeUser:async c=>{const h="removeUser",m=o(`api/admin/user-admin/${c}`,{method:"DELETE"},h);return n(m.caller,m.id)},changePassword:async(c,h)=>{const m="changePassword",S=o(`api/admin/user-admin/${c}/change-password`,{method:"POST",body:JSON.stringify({password:h})},m);return n(S.caller,S.id)},validatePassword:async c=>{const h="validatePassword",m=o("api/admin/user-admin/validate-password",{method:"POST",body:JSON.stringify({password:c})},h);return n(m.caller,m.id)},userApiErrors:a,userLoading:t}},Mo=(t="",n="",o=null)=>{const{uiConfig:a}=G(),{users:i,roles:s}=Ee(),[l,d]=p.useState(t),[u,c]=p.useState(n),[h,m]=p.useState(!1),[S,f]=p.useState(s.find(({id:x})=>x===o)||null),[y,v]=p.useState({});return p.useEffect(()=>{d(t)},[t]),p.useEffect(()=>{c(n)},[n]),p.useEffect(()=>{m((a==null?void 0:a.emailEnabled)||!1)},[a==null?void 0:a.emailEnabled]),p.useEffect(()=>{f(s.find(({id:x})=>x===o)||null)},[o]),{name:l,setName:d,email:u,setEmail:c,sendEmail:h,setSendEmail:m,rootRole:S,setRootRole:f,getAddUserPayload:()=>({name:l,email:u,sendEmail:h,rootRole:(S==null?void 0:S.id)||0}),validateName:()=>l.length===0?(v(x=>({...x,name:"Name can not be empty."})),!1):u.length===0?(v(x=>({...x,email:"Email can not be empty."})),!1):!0,validateEmail:()=>i.some(x=>x.email===u)?(v(x=>({...x,email:"Email already exists"})),!1):!0,clearErrors:()=>{v({})},errors:y}},Vc=t=>p.createElement("svg",{width:197,height:177,viewBox:"0 0 197 177",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},p.createElement("g",{clipPath:"url(#clip0)"},p.createElement("path",{d:"M195.272 67.6884C195.201 67.6884 195.132 67.6668 195.074 67.6264L99.4918 1.00044C99.2009 0.798626 98.8553 0.690774 98.5013 0.691378C98.1474 0.691982 97.8021 0.801012 97.5119 1.00382L2.61779 67.6257C2.54273 67.6784 2.44984 67.6991 2.35954 67.6832C2.26924 67.6674 2.18893 67.6163 2.13629 67.5411C2.08364 67.466 2.06297 67.373 2.07881 67.2826C2.09466 67.1923 2.14573 67.1119 2.22079 67.0592L97.115 0.437299C97.5213 0.153417 98.0047 0.000817369 98.5002 2.3283e-06C98.9957 -0.000812712 99.4796 0.150195 99.8868 0.432738L195.469 67.0585C195.53 67.1006 195.575 67.1609 195.599 67.2306C195.623 67.3004 195.624 67.3758 195.602 67.4461C195.58 67.5164 195.536 67.5778 195.476 67.6214C195.417 67.6649 195.345 67.6884 195.272 67.6884L195.272 67.6884Z",fill:"#3F3D56"}),p.createElement("path",{d:"M8.04028 70.0501L98.5953 2.87773L189.837 74.8297L103.261 126.199L56.2576 115.476L8.04028 70.0501Z",fill:"#E6E6E6"}),p.createElement("path",{d:"M60.2251 157.928H15.4887C15.214 157.928 14.942 157.875 14.6881 157.77C14.4342 157.665 14.2035 157.511 14.0091 157.316C13.8147 157.122 13.6606 156.891 13.5554 156.637C13.4502 156.383 13.396 156.111 13.396 155.836C13.396 155.561 13.4502 155.289 13.5554 155.035C13.6606 154.781 13.8147 154.55 14.0091 154.356C14.2035 154.162 14.4342 154.008 14.6881 153.903C14.942 153.798 15.214 153.744 15.4887 153.744H60.2251C60.4998 153.744 60.7719 153.798 61.0258 153.903C61.2797 154.008 61.5104 154.162 61.7048 154.356C61.8991 154.55 62.0533 154.781 62.1585 155.035C62.2637 155.289 62.3179 155.561 62.3179 155.836C62.3179 156.111 62.2637 156.383 62.1585 156.637C62.0533 156.891 61.8991 157.122 61.7048 157.316C61.5104 157.511 61.2797 157.665 61.0258 157.77C60.7719 157.875 60.4998 157.928 60.2251 157.928Z",fill:"#607D8B"}),p.createElement("path",{d:"M31.5392 148.934H15.4887C15.214 148.934 14.942 148.88 14.6881 148.776C14.4342 148.671 14.2035 148.516 14.0091 148.322C13.8147 148.128 13.6606 147.897 13.5554 147.643C13.4502 147.389 13.396 147.117 13.396 146.842C13.396 146.567 13.4502 146.295 13.5554 146.041C13.6606 145.787 13.8147 145.556 14.0091 145.362C14.2035 145.168 14.4342 145.014 14.6881 144.909C14.942 144.804 15.214 144.75 15.4887 144.75H31.5392C31.8139 144.75 32.0859 144.804 32.3398 144.909C32.5937 145.014 32.8244 145.168 33.0188 145.362C33.2132 145.556 33.3674 145.787 33.4726 146.041C33.5778 146.295 33.6319 146.567 33.6319 146.842C33.6319 147.117 33.5778 147.389 33.4726 147.643C33.3674 147.897 33.2132 148.128 33.0188 148.322C32.8244 148.516 32.5937 148.671 32.3398 148.776C32.0859 148.88 31.8139 148.934 31.5392 148.934Z",fill:"#607D8B"}),p.createElement("path",{d:"M99.8687 107.464C99.5287 107.465 99.1918 107.399 98.8771 107.27L43.0291 84.0761V11.4759C43.0298 10.8339 43.2849 10.2184 43.7385 9.76446C44.192 9.31051 44.8069 9.05515 45.4484 9.0544H152.589C153.23 9.05515 153.845 9.31051 154.299 9.76446C154.752 10.2184 155.007 10.8339 155.008 11.4759V84.1267L154.903 84.1717L100.89 107.258C100.567 107.394 100.22 107.464 99.8687 107.464Z",fill:"white"}),p.createElement("path",{d:"M99.8687 107.637C99.5061 107.637 99.1469 107.567 98.8112 107.43L42.8562 84.1916V11.4759C42.857 10.788 43.1303 10.1286 43.6163 9.64218C44.1022 9.1558 44.7611 8.88221 45.4483 8.88143H152.589C153.276 8.88221 153.935 9.1558 154.421 9.64218C154.907 10.1286 155.18 10.788 155.181 11.4759V84.2409L100.958 107.417C100.613 107.563 100.243 107.637 99.8687 107.637ZM43.5474 83.7295L99.0748 106.79C99.5928 107.001 100.173 106.997 100.688 106.781L154.49 83.7842V11.4759C154.489 10.9714 154.288 10.4879 153.932 10.1312C153.576 9.77452 153.093 9.57387 152.589 9.57328H45.4483C44.9444 9.57387 44.4612 9.77452 44.1049 10.1312C43.7485 10.4879 43.548 10.9714 43.5474 11.4759L43.5474 83.7295Z",fill:"#3F3D56"}),p.createElement("path",{d:"M194.581 66.9965H194.512L154.835 83.9537L100.55 107.155C100.337 107.244 100.11 107.291 99.8797 107.292C99.6496 107.293 99.4215 107.249 99.2084 107.162L43.2018 83.9052L2.55059 67.0242L2.48849 66.9965H2.4193C1.77788 66.9972 1.16293 67.2526 0.70938 67.7066C0.255828 68.1605 0.000711706 68.776 0 69.418V174.579C0.000712619 175.221 0.255828 175.836 0.70938 176.29C1.16293 176.744 1.77788 176.999 2.4193 177H194.581C195.222 176.999 195.837 176.744 196.291 176.29C196.744 175.836 196.999 175.221 197 174.579V69.418C196.999 68.776 196.744 68.1605 196.291 67.7066C195.837 67.2526 195.222 66.9972 194.581 66.9965ZM196.309 174.579C196.309 175.037 196.126 175.477 195.802 175.801C195.478 176.126 195.039 176.308 194.581 176.308H2.4193C1.96104 176.308 1.52161 176.126 1.19757 175.801C0.873536 175.477 0.691411 175.037 0.691228 174.579V69.418C0.691855 68.9707 0.865197 68.541 1.17501 68.2187C1.48483 67.8963 1.90713 67.7063 2.35365 67.6884L43.2018 84.6524L98.9425 107.802C99.5459 108.047 100.222 108.044 100.823 107.791L154.835 84.7043L194.65 67.6884C195.096 67.7076 195.517 67.8982 195.826 68.2203C196.135 68.5425 196.308 68.9714 196.309 69.418V174.579Z",fill:"#3F3D56"}),p.createElement("path",{d:"M99.3104 86.8775C97.2487 86.8813 95.2416 86.214 93.5919 84.9762L93.4896 84.8994L71.9541 68.3963C70.9567 67.6314 70.1197 66.6774 69.4907 65.5888C68.8617 64.5001 68.4531 63.2981 68.2882 62.0514C68.1233 60.8047 68.2054 59.5377 68.5297 58.3228C68.8541 57.1078 69.4143 55.9687 70.1785 54.9704C70.9426 53.9722 71.8958 53.1344 72.9835 52.5048C74.0711 51.8753 75.2721 51.4663 76.5177 51.3013C77.7632 51.1362 79.0291 51.2184 80.243 51.543C81.4569 51.8676 82.595 52.4284 83.5923 53.1932L97.5414 63.8988L130.505 20.8706C131.27 19.8726 132.223 19.0351 133.311 18.4059C134.399 17.7767 135.6 17.3682 136.846 17.2036C138.091 17.039 139.357 17.1216 140.571 17.4467C141.785 17.7718 142.923 18.333 143.92 19.0982L143.715 19.3767L143.925 19.1023C145.936 20.6494 147.252 22.9319 147.584 25.449C147.916 27.9661 147.237 30.5122 145.696 32.5287L106.922 83.1402C106.026 84.3065 104.872 85.2503 103.552 85.8984C102.232 86.5466 100.781 86.8816 99.3104 86.8775Z",fill:"#607D8B"})),p.createElement("defs",null,p.createElement("clipPath",{id:"clip0"},p.createElement("rect",{width:197,height:177,fill:"white"})))),xt=({inviteLink:t,small:n})=>{const{setToastData:o}=Z(),a=()=>{try{return navigator.clipboard.writeText(t).then(()=>{o({type:"success",title:"Successfully copied invite link."})}).catch(()=>{i()})}catch{i()}},i=()=>o({type:"error",title:"Could not copy invite link."});return r(N,{sx:{backgroundColor:s=>s.palette.background.elevation2,py:4,px:4,borderRadius:s=>`${s.shape.borderRadius}px`,mt:2,display:"flex",justifyContent:"space-between",alignItems:"center",wordBreak:"break-all",...n?{my:0,py:.5,pl:1.5,pr:.5,fontSize:s=>s.typography.body2.fontSize}:{}},children:[t,e(Ue,{title:"Copy link",arrow:!0,children:e(We,{onClick:a,size:n?"small":"large",sx:n?{ml:.5}:{},children:e(sr,{sx:{fontSize:n?20:void 0}})})})]})},Yc=({open:t,closeConfirm:n,inviteLink:o})=>r(ie,{open:t,title:"Team member added",primaryButtonText:"Close",onClick:n,children:[e(D,{children:"A new team member has been added. We’ve sent an email on your behalf to inform them of their new account and role. No further steps are required."}),e(N,{sx:{width:"100%",textAlign:"center",px:"auto",py:4},children:e(Vc,{})}),e(D,{style:{fontWeight:"bold"},variant:"subtitle1",children:"In a rush?"}),e(D,{children:"You may also copy the invite link and send it to the user."}),e(xt,{inviteLink:o})]}),Jc=({open:t,closeConfirm:n,inviteLink:o})=>r(ie,{open:t,onClick:n,primaryButtonText:"Close",title:"Team member added",children:[e(D,{variant:"body1",sx:{mb:2},children:"A new team member has been added."}),e(D,{variant:"body1",children:"Please provide them with the following link. This will allow them to set up their password and get started with their Unleash account."}),e(xt,{inviteLink:o}),e(J,{severity:"info",sx:{mt:2},children:r(D,{variant:"body2",children:["Want to avoid this step in the future?"," ",e("a",{href:"https://docs.getunleash.io/docs/deploy/email",target:"_blank",rel:"noopener noreferrer",children:"If you configure an email server for Unleash"})," ","we'll automatically send informational getting started emails to new users once you add them."]})})]}),jo=({open:t,closeConfirm:n,emailSent:o,inviteLink:a})=>o?e(Yc,{open:t,closeConfirm:n,inviteLink:a}):e(Jc,{open:t,closeConfirm:n,inviteLink:a}),rn=t=>{var d;const{instanceStatus:n}=Qn(),{uiConfig:o}=G(),a=!!((d=o==null?void 0:o.flags)!=null&&d.proPlanAutoCharge&&(n==null?void 0:n.plan)===Ge.PRO),i=(n==null?void 0:n.seats)??5,s=p.useMemo(()=>Kc(t,a,i),[t,a,i]),l=s.filter(u=>u.paid).length;return{seats:i,extraSeats:l,planUsers:s,isBillingUsers:a}},Kc=(t,n,o=0)=>(!n||!o||t.sort((a,i)=>a.createdAt.localeCompare(i.createdAt)).forEach((a,i)=>{a.paid=!1,i>=o&&(a.paid=!0)}),t),Zc=()=>{const{users:t}=Ee(),{isBillingUsers:n,seats:o,planUsers:a}=rn(t);return!n||a.length<o?null:e(J,{severity:"info",sx:{marginBottom:i=>i.spacing(3)},children:r("p",{children:[e("strong",{children:"Heads up!"})," You are exceeding your allocated free members included in your plan (",a.length," of ",o,"). Creating this user will add ",e("strong",{children:"$15/month"})," to your invoice, starting with your next payment."]})})},Xc=()=>{const{setToastApiError:t}=Z(),{uiConfig:n}=G(),o=be(),{name:a,setName:i,email:s,setEmail:l,sendEmail:d,setSendEmail:u,rootRole:c,setRootRole:h,getAddUserPayload:m,validateName:S,validateEmail:f,errors:y,clearErrors:v}=Mo(),[T,w]=p.useState(!1),[k,E]=p.useState(""),{addUser:x,userLoading:P}=Tt();return r(Pe,{loading:P,title:"Create Unleash user",description:"In order for a user to get access to Unleash, they need to be assigned a root role, such as Viewer, Editor, or Admin.",documentationLink:"https://docs.getunleash.io/reference/rbac#predefined-roles",documentationLinkLabel:"User management documentation",formatApiCode:()=>`curl --location --request POST '${n.unleashUrl}/api/admin/user-admin' \\
24
24
  --header 'Authorization: INSERT_API_KEY' \\
25
25
  --header 'Content-Type: application/json' \\
26
- --data-raw '${JSON.stringify(m(),void 0,2)}'`,children:[e(Zc,{}),e(Go,{errors:y,handleSubmit:async O=>{O.preventDefault(),v();const A=S(),U=f();if(A&&U){const X=m();try{await x(X).then(R=>R.json()).then(R=>{Ht(),E(R.inviteLink),w(!0)})}catch(R){t(K(R))}}},handleCancel:()=>{o(De)},name:a,setName:i,email:s,setEmail:l,sendEmail:d,setSendEmail:u,rootRole:c,setRootRole:h,clearErrors:v,children:e(Vn,{name:"user",permission:Y})}),e(jo,{open:T,closeConfirm:()=>{w(!1),o("/admin/users")},emailSent:d,inviteLink:k})]})},sn="api/admin/invite-link/tokens",Qc=()=>{const t=oe(sn);return fetch(t,{method:"GET"}).then(n=>n.json())},_o=(t={})=>{var s;const{data:n,error:o}=we(sn,Qc,t),[a,i]=p.useState(!o&&!n);return p.useEffect(()=>{i(!o&&!n)},[n,o]),{data:n?{tokens:(s=n.tokens)==null?void 0:s.filter(l=>l.enabled)}:void 0,error:o,loading:a}},Mn=[{key:dt(new Date,{hours:48}).toISOString(),label:"48 hours"},{key:dt(new Date,{weeks:1}).toISOString(),label:"1 week"},{key:dt(new Date,{months:1}).toISOString(),label:"1 month"}],ed=(t,n)=>{const{uiConfig:o}=G();return t?()=>`curl --location --request PUT '${o.unleashUrl}/api/admin/invite-link/tokens/default' \\
26
+ --data-raw '${JSON.stringify(m(),void 0,2)}'`,children:[e(Zc,{}),e(Go,{errors:y,handleSubmit:async O=>{O.preventDefault(),v();const A=S(),L=f();if(A&&L){const X=m();try{await x(X).then(R=>R.json()).then(R=>{Wt(),E(R.inviteLink),w(!0)})}catch(R){t(K(R))}}},handleCancel:()=>{o(De)},name:a,setName:i,email:s,setEmail:l,sendEmail:d,setSendEmail:u,rootRole:c,setRootRole:h,clearErrors:v,children:e(Vn,{name:"user",permission:Y})}),e(jo,{open:T,closeConfirm:()=>{w(!1),o("/admin/users")},emailSent:d,inviteLink:k})]})},sn="api/admin/invite-link/tokens",Qc=()=>{const t=oe(sn);return fetch(t,{method:"GET"}).then(n=>n.json())},_o=(t={})=>{var s;const{data:n,error:o}=we(sn,Qc,t),[a,i]=p.useState(!o&&!n);return p.useEffect(()=>{i(!o&&!n)},[n,o]),{data:n?{tokens:(s=n.tokens)==null?void 0:s.filter(l=>l.enabled)}:void 0,error:o,loading:a}},Mn=[{key:dt(new Date,{hours:48}).toISOString(),label:"48 hours"},{key:dt(new Date,{weeks:1}).toISOString(),label:"1 week"},{key:dt(new Date,{months:1}).toISOString(),label:"1 month"}],ed=(t,n)=>{const{uiConfig:o}=G();return t?()=>`curl --location --request PUT '${o.unleashUrl}/api/admin/invite-link/tokens/default' \\
27
27
  --header 'Authorization: INSERT_API_KEY' \\
28
28
  --header 'Content-Type: application/json' \\
29
29
  --data-raw '${JSON.stringify({expiresAt:n},void 0,2)}'`:()=>`curl --location --request POST '${o.unleashUrl}/api/admin/invite-link/tokens' \\
30
30
  --header 'Authorization: INSERT_API_KEY' \\
31
31
  --header 'Content-Type: application/json' \\
32
- --data-raw '${JSON.stringify({name:"default",expiresAt:n},void 0,2)}'`},td=()=>{var L;const t=ye(),{data:n,loading:o}=_o(),[a,i]=p.useState(""),{mutate:s}=lr(),{trackEvent:l}=Zt(),[d,u]=p.useState(Mn[0].key),[c,h]=p.useState(!1),m=(L=n==null?void 0:n.tokens)==null?void 0:L.find(I=>I.name==="default"),S=!!m,f=ed(S,d),[y,v]=p.useState(!1),{setToastApiError:T}=Z(),{createToken:w,updateToken:k}=cr();return r(Pe,{loading:o||y,title:S?"Update invite link":"Create invite link",description:"When you send an invite link to someone, they will be able to create an account and get access to Unleash. This new user will only have read access, until you change their assigned role.",documentationLink:"https://docs.getunleash.io/reference/public-signup",documentationLinkLabel:"Invite link documentation",formatApiCode:f,children:[r(N,{component:"form",onSubmit:async I=>{I.preventDefault(),v(!0),l("invite",{props:{eventType:S?"link update submitted":"link created"}});try{if(S)await k(m.secret,{expiresAt:d}),i(m.url);else{const O=await(await w({name:"default",expiresAt:d})).json();i(O.url)}}catch(F){T(K(F))}finally{v(!1),s(sn)}},sx:{display:"flex",flexDirection:"column",flexGrow:1},"data-testid":"create-invite-link-form",children:[r(N,{sx:{maxWidth:"400px"},children:[r(N,{sx:{mb:2},children:[e(D,{sx:{mb:1},children:"Expiration period for the invite link"}),e(dr,{label:"Link will expire in",name:"type",options:Mn,value:d,onChange:u,fullWidth:!0})]}),e(D,{sx:{mb:1},children:"People using this link will be invited as:"}),r(N,{sx:{p:2,borderRadius:I=>`${I.shape.borderRadiusMedium}px`,backgroundColor:I=>I.palette.background.elevation2},children:[e(D,{variant:"body2",fontWeight:"bold",children:"Viewer"}),e(D,{variant:"body2",color:"text.secondary",children:"Users with this role can only read root resources in Unleash. The viewer can be added to specific projects as project member. Viewers may not view API tokens."})]})]}),r(N,{sx:{display:"flex",justifyContent:"flex-end",mt:"auto"},children:[e(ur,{type:"submit",permission:Y,disabled:y,children:S?"Update invite link":"Create invite link"}),e(C,{condition:S,show:e(z,{sx:{ml:2},onClick:async()=>{h(!0)},color:"error",children:"Delete link"})}),e(z,{sx:{ml:2},onClick:()=>{t(De)},children:"Cancel"})]})]}),e(ie,{open:!!a,onClick:()=>{i(""),t("/admin/users")},primaryButtonText:"Close",title:"Invite link created",children:r(N,{children:[e(D,{variant:"body1",sx:{mb:2},children:"Using this link, new team members can now sign-up to Unleash."}),e(D,{variant:"body1",children:"Please provide them with the following link to get started. This will allow them to set up their password and get started with their Unleash account."}),e(xt,{inviteLink:a})]})}),e(ie,{open:c,onClose:()=>h(!1),onClick:async()=>{v(!0);try{await k(m.secret,{enabled:!1}),t(De)}catch(I){T(K(I))}finally{v(!1)}},title:"Are you sure you want to delete your invite link?"})]})},nd={overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.25)",zIndex:5},content:{width:"500px",maxWidth:"90%",margin:"0",top:"50%",left:"50%",right:"auto",bottom:"auto",transform:"translate(-50%, -50%)"}},od=g(We)(({theme:t})=>({width:t.spacing(5),height:t.spacing(5),margin:0})),ad=({showDialog:t,closeDialog:n,user:o})=>{const[a,i]=p.useState({}),[s,l]=p.useState(),[d,u]=p.useState(!1),{classes:c}=yo(),{changePassword:h}=Tt(),m=y=>{l(void 0),i({...a,[y.target.name]:gr(y.target.value)})},S=async y=>{if(y.preventDefault(),a.password===a.confirm){if(!d){l(gn);return}try{await h(o.id,a.password),i({}),n()}catch(v){console.warn(v),l(gn)}}};return e(ie,{open:t,onClick:S,style:nd,onClose:y=>{y.preventDefault(),i({}),l(void 0),n()},primaryButtonText:"Save",title:"Update password",secondaryButtonText:"Cancel",maxWidth:"xs",children:r("form",{onSubmit:S,className:hr(c.contentSpacingY,c.flexColumn),children:[e(D,{variant:"subtitle1",children:"Changing password for user"}),r("div",{className:c.flexRow,children:[e(od,{user:o,variant:"rounded"}),e(D,{variant:"subtitle1",style:{marginLeft:"1rem"},children:o.username||o.email})]}),e(pr,{password:a.password,callback:u}),e(Q,{label:"New password",name:"password",type:"password",value:a.password,error:!!s,helperText:s,onChange:m,variant:"outlined",size:"small"}),e(Q,{label:"Confirm password",name:"confirm",type:"password",value:a.confirm,onChange:m,variant:"outlined",size:"small"}),e(mr,{started:!!(a.password&&a.confirm),matchingPasswords:a.password===a.confirm})]})})},rd=g(We)(({theme:t})=>({width:t.spacing(5),height:t.spacing(5),margin:0})),id=({showDialog:t,closeDialog:n,user:o,userLoading:a,removeUser:i,userApiErrors:s})=>{const l=bo(a),{classes:d}=yo();return e(ie,{open:t,title:"Really delete user?",onClose:n,onClick:i,primaryButtonText:"Delete user",secondaryButtonText:"Cancel",children:r("div",{ref:l,children:[e(C,{condition:!!s[Gn],show:e(J,{"data-loading":!0,severity:"error",style:{margin:"1rem 0"},children:s[Gn]})}),r("div",{"data-loading":!0,className:d.flexRow,children:[e(rd,{user:o,variant:"rounded"}),e(D,{variant:"subtitle1",style:{marginLeft:"1rem"},children:o.username||o.email})]}),r(D,{"data-loading":!0,variant:"body1",style:{marginTop:"1rem"},children:["Are you sure you want to delete"," ",o?`${o.name||"user"} (${o.email||o.username})`:"","?"]})]})})},sd=g(Fr)(({theme:t})=>({color:t.palette.primary.light,fontSize:"1.5rem",backgroundColor:"#F1F0FC",borderRadius:t.shape.borderRadiusLarge})),ld=({value:t})=>e(te,{children:e(C,{condition:t,show:e(Le,{title:"Paid user",arrow:!0,children:e(sd,{})}),elseShow:"Included"})}),cd=g(N)(()=>({display:"flex",justifyContent:"center"})),dd=({onEdit:t,onChangePassword:n,onDelete:o})=>r(cd,{children:[e(Ae,{"data-loading":!0,onClick:t,permission:Y,tooltipProps:{title:"Edit user"},children:e(Qe,{})}),e(Ae,{"data-loading":!0,onClick:n,permission:Y,tooltipProps:{title:"Change password"},children:e(fr,{})}),e(Ae,{"data-loading":!0,onClick:o,permission:Y,tooltipProps:{title:"Remove user"},children:e(Ue,{})})]}),jn=20,ud=()=>{const{users:t}=Ee(),{isBillingUsers:n,planUsers:o}=rn(t);return!n||(o==null?void 0:o.length)<jn?null:e(J,{severity:"info",sx:{marginBottom:a=>a.spacing(3)},children:r("p",{children:[e("strong",{children:"Heads up!"})," You have reached your maximum number of registered users for you PRO account (up to max ",jn," ","users). If you need more users please"," ",e(Qt,{component:de,to:"https://www.getunleash.io/signup-enterprise",children:"get in touch with us"}),"."]})})},hd=()=>{const t=ye(),{users:n,roles:o,refetch:a,loading:i}=Ee(),{setToastData:s,setToastApiError:l}=Z(),{removeUser:d,userLoading:u,userApiErrors:c}=Tt(),[h,m]=p.useState({open:!1}),[S,f]=p.useState(!1),[y,v]=p.useState(!1),[T,w]=p.useState(!1),[k,E]=p.useState(""),[x,P]=p.useState(),{planUsers:M,isBillingUsers:L}=rn(n),[I,F]=p.useState(""),O=fe(Oe.breakpoints.down("sm")),A=fe(Oe.breakpoints.down("md")),U=()=>{f(!1),P(void 0)},X=j=>le=>{le.preventDefault(),f(!0),P(j)},R=j=>le=>{le.preventDefault(),m({open:!0,user:j})},_=()=>{m({open:!1})},q=async j=>{try{await d(j.id),s({title:`${j.name} has been deleted`,type:"success"}),a(),U()}catch(le){l(K(le))}},se=()=>{v(!1),w(!1),E("")},ae=p.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:j}})=>e(te,{children:e(We,{user:j})}),disableSortBy:!0,maxWidth:80},{id:"name",Header:"Name",accessor:j=>j.name||"",minWidth:200,Cell:({row:{original:j}})=>e(Ce,{value:j.name,subtitle:j.email||j.username}),searchable:!0},{id:"role",Header:"Role",accessor:j=>{var le;return((le=o.find(Rt=>Rt.id===j.rootRole))==null?void 0:le.name)||""},Cell:({row:{original:j},value:le})=>e(Co,{value:le,roleId:j.rootRole}),maxWidth:120},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",width:120,maxWidth:120},{id:"last-login",Header:"Last login",accessor:j=>j.seenAt||"",Cell:({row:{original:j}})=>e(Ve,{value:j.seenAt,emptyText:"Never",title:le=>`Last login: ${le}`}),sortType:"date",maxWidth:150},{id:"type",Header:"Type",accessor:"paid",maxWidth:100,Cell:({row:{original:j}})=>e(ld,{value:L&&j.paid}),sortType:"boolean"},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:j}})=>e(dd,{onEdit:()=>{t(`/admin/users/${j.id}/edit`)},onChangePassword:R(j),onDelete:X(j)}),width:150,disableSortBy:!0},{accessor:"username",Header:"Username",searchable:!0},{accessor:"email",Header:"Email",searchable:!0}],[o,t,L]),W=p.useMemo(()=>({sortBy:[{id:"createdAt"}],hiddenColumns:L?["username","email"]:["type","username","email"]}),[L]),{data:re,getSearchText:Ye}=nt(ae,I,L?M:n),{headerGroups:Et,rows:ke,prepareRow:Je,setHiddenColumns:kt}=$.useTable({columns:ae,data:re,initialState:W,sortTypes:be,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0,defaultColumn:{Cell:te}},$.useSortBy,$.useFlexLayout);return et([{condition:!L||A,columns:["type"]},{condition:O,columns:["imageUrl","role"]},{condition:A,columns:["createdAt","last-login"]}],kt,ae),r(ee,{isLoading:i,header:e(ne,{title:`Users (${ke.length})`,actions:r(B,{children:[e(pe,{initialValue:I,onChange:F}),e(ne.Divider,{}),e(z,{variant:"contained",color:"primary",onClick:()=>t("/admin/create-user"),children:"Add new user"})]})}),children:[e(ud,{}),e(qe,{value:Ye(I),children:e(xe,{rows:ke,headerGroups:Et,prepareRow:Je})}),e(C,{condition:ke.length===0,show:e(C,{condition:(I==null?void 0:I.length)>0,show:r(ge,{children:["No users found matching “",I,"”"]}),elseShow:e(ge,{children:"No users available. Get started by adding one."})})}),e(jo,{open:y,closeConfirm:se,emailSent:T,inviteLink:k}),e(C,{condition:!!h.user,show:()=>e(ad,{showDialog:h.open,closeDialog:_,user:h.user})}),e(C,{condition:!!x,show:e(id,{showDialog:S,closeDialog:U,user:x,removeUser:()=>q(x),userLoading:u,userApiErrors:c})})]})},pd=()=>{var T,w,k,E,x;const t=ye(),{data:n,loading:o}=_o(),a=bo(o),{trackEvent:i}=Zt(),s=((T=n==null?void 0:n.tokens)==null?void 0:T.find(P=>P.name==="default"))??null,l=s==null?void 0:s.url,d=((k=(w=n==null?void 0:n.tokens)==null?void 0:w[0])==null?void 0:k.createdAt)??"",c=(((x=(E=n==null?void 0:n.tokens)==null?void 0:E[0])==null?void 0:x.expiresAt)??"")||!1,h=!!(c&&fn(new Date,Ut(c))),m=c&&fn(dt(new Date,{days:14}),Ut(c)),S=c?yr(Ut(c)):!1,{locationSettings:f}=eo(),y=e(D,{component:"span",variant:"body2",color:m?"warning.dark":"inherit",fontWeight:"bold",children:S}),v=()=>{i("invite",{props:{eventType:l?"link bar action: edit":"link bar action: create"}}),t("/admin/invite-link")};return r(N,{sx:P=>({backgroundColor:P.palette.background.paper,py:2,px:4,mb:2,borderRadius:`${P.shape.borderRadiusLarge}px`,display:"flex",flexDirection:{xs:"column",md:"row"},border:"2px solid",borderColor:P.palette.background.alternative}),ref:a,children:[e(N,{sx:{mb:{xs:1,md:0},display:"flex",justifyContent:"center",flexDirection:"column"},children:e(C,{condition:!!l,show:r(B,{children:[r(D,{variant:"body2",sx:{mb:1},children:[`You have an invite link created on ${oo(d,f.locale)} `,e(C,{condition:h,show:r(B,{children:["that expired ",y," ","ago"]}),elseShow:r(B,{children:["that will expire in"," ",y]})})]}),e(xt,{small:!0,inviteLink:l})]}),elseShow:e(D,{variant:"body2","data-loading":!0,children:"You can easily create an invite link here that you can share and use to invite people from your company to your Unleash setup."})})}),e(N,{sx:{minWidth:200,display:"flex",justifyContent:{xs:"center",md:"flex-end"},alignItems:"center",flexGrow:1},children:r(z,{variant:"outlined",onClick:v,"data-loading":!0,children:[l?"Update":"Create"," invite link"]})})]})},md=(t,n={})=>{const o=()=>{const u=oe(`api/admin/user-admin/${t}`);return fetch(u,{method:"GET"}).then(ue("Users")).then(c=>c.json())},{data:a,error:i}=we(`api/admin/user-admin/${t}`,o,n),[s,l]=p.useState(!i&&!a),d=()=>{Xn(`api/admin/user-admin/${t}`)};return p.useEffect(()=>{l(!i&&!a)},[a,i]),{user:a||{},error:i,loading:s,refetch:d}},gd=()=>{p.useEffect(()=>{Ht()},[]);const{uiConfig:t}=G(),{setToastData:n,setToastApiError:o}=Z(),a=Vt("id"),{user:i,refetch:s}=md(a),{updateUser:l,userLoading:d}=Tt(),u=ye(),{name:c,setName:h,email:m,setEmail:S,sendEmail:f,setSendEmail:y,rootRole:v,setRootRole:T,getAddUserPayload:w,validateName:k,errors:E,clearErrors:x}=Mo(i==null?void 0:i.name,i==null?void 0:i.email,i==null?void 0:i.rootRole);return e(Pe,{loading:d,title:"Edit user",description:"In order for a user to get access to Unleash, they need to be assigned a root role, such as Viewer, Editor, or Admin.",documentationLink:"https://docs.getunleash.io/reference/rbac#predefined-roles",documentationLinkLabel:"User management documentation",formatApiCode:()=>`curl --location --request PUT '${t.unleashUrl}/api/admin/user-admin/${a}' \\
32
+ --data-raw '${JSON.stringify({name:"default",expiresAt:n},void 0,2)}'`},td=()=>{var U;const t=be(),{data:n,loading:o}=_o(),[a,i]=p.useState(""),{mutate:s}=lr(),{trackEvent:l}=Zt(),[d,u]=p.useState(Mn[0].key),[c,h]=p.useState(!1),m=(U=n==null?void 0:n.tokens)==null?void 0:U.find(I=>I.name==="default"),S=!!m,f=ed(S,d),[y,v]=p.useState(!1),{setToastApiError:T}=Z(),{createToken:w,updateToken:k}=cr();return r(Pe,{loading:o||y,title:S?"Update invite link":"Create invite link",description:"When you send an invite link to someone, they will be able to create an account and get access to Unleash. This new user will only have read access, until you change their assigned role.",documentationLink:"https://docs.getunleash.io/reference/public-signup",documentationLinkLabel:"Invite link documentation",formatApiCode:f,children:[r(N,{component:"form",onSubmit:async I=>{I.preventDefault(),v(!0),l("invite",{props:{eventType:S?"link update submitted":"link created"}});try{if(S)await k(m.secret,{expiresAt:d}),i(m.url);else{const O=await(await w({name:"default",expiresAt:d})).json();i(O.url)}}catch(F){T(K(F))}finally{v(!1),s(sn)}},sx:{display:"flex",flexDirection:"column",flexGrow:1},"data-testid":"create-invite-link-form",children:[r(N,{sx:{maxWidth:"400px"},children:[r(N,{sx:{mb:2},children:[e(D,{sx:{mb:1},children:"Expiration period for the invite link"}),e(dr,{label:"Link will expire in",name:"type",options:Mn,value:d,onChange:u,fullWidth:!0})]}),e(D,{sx:{mb:1},children:"People using this link will be invited as:"}),r(N,{sx:{p:2,borderRadius:I=>`${I.shape.borderRadiusMedium}px`,backgroundColor:I=>I.palette.background.elevation2},children:[e(D,{variant:"body2",fontWeight:"bold",children:"Viewer"}),e(D,{variant:"body2",color:"text.secondary",children:"Users with this role can only read root resources in Unleash. The viewer can be added to specific projects as project member. Viewers may not view API tokens."})]})]}),r(N,{sx:{display:"flex",justifyContent:"flex-end",mt:"auto"},children:[e(ur,{type:"submit",permission:Y,disabled:y,children:S?"Update invite link":"Create invite link"}),e(C,{condition:S,show:e(z,{sx:{ml:2},onClick:async()=>{h(!0)},color:"error",children:"Delete link"})}),e(z,{sx:{ml:2},onClick:()=>{t(De)},children:"Cancel"})]})]}),e(ie,{open:!!a,onClick:()=>{i(""),t("/admin/users")},primaryButtonText:"Close",title:"Invite link created",children:r(N,{children:[e(D,{variant:"body1",sx:{mb:2},children:"Using this link, new team members can now sign-up to Unleash."}),e(D,{variant:"body1",children:"Please provide them with the following link to get started. This will allow them to set up their password and get started with their Unleash account."}),e(xt,{inviteLink:a})]})}),e(ie,{open:c,onClose:()=>h(!1),onClick:async()=>{v(!0);try{await k(m.secret,{enabled:!1}),t(De)}catch(I){T(K(I))}finally{v(!1)}},title:"Are you sure you want to delete your invite link?"})]})},nd={overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.25)",zIndex:5},content:{width:"500px",maxWidth:"90%",margin:"0",top:"50%",left:"50%",right:"auto",bottom:"auto",transform:"translate(-50%, -50%)"}},od=g(He)(({theme:t})=>({width:t.spacing(5),height:t.spacing(5),margin:0})),ad=({showDialog:t,closeDialog:n,user:o})=>{const[a,i]=p.useState({}),[s,l]=p.useState(),[d,u]=p.useState(!1),{classes:c}=yo(),{changePassword:h}=Tt(),m=y=>{l(void 0),i({...a,[y.target.name]:gr(y.target.value)})},S=async y=>{if(y.preventDefault(),a.password===a.confirm){if(!d){l(gn);return}try{await h(o.id,a.password),i({}),n()}catch(v){console.warn(v),l(gn)}}};return e(ie,{open:t,onClick:S,style:nd,onClose:y=>{y.preventDefault(),i({}),l(void 0),n()},primaryButtonText:"Save",title:"Update password",secondaryButtonText:"Cancel",maxWidth:"xs",children:r("form",{onSubmit:S,className:hr(c.contentSpacingY,c.flexColumn),children:[e(D,{variant:"subtitle1",children:"Changing password for user"}),r("div",{className:c.flexRow,children:[e(od,{user:o,variant:"rounded"}),e(D,{variant:"subtitle1",style:{marginLeft:"1rem"},children:o.username||o.email})]}),e(pr,{password:a.password,callback:u}),e(Q,{label:"New password",name:"password",type:"password",value:a.password,error:!!s,helperText:s,onChange:m,variant:"outlined",size:"small"}),e(Q,{label:"Confirm password",name:"confirm",type:"password",value:a.confirm,onChange:m,variant:"outlined",size:"small"}),e(mr,{started:!!(a.password&&a.confirm),matchingPasswords:a.password===a.confirm})]})})},rd=g(He)(({theme:t})=>({width:t.spacing(5),height:t.spacing(5),margin:0})),id=({showDialog:t,closeDialog:n,user:o,userLoading:a,removeUser:i,userApiErrors:s})=>{const l=bo(a),{classes:d}=yo();return e(ie,{open:t,title:"Really delete user?",onClose:n,onClick:i,primaryButtonText:"Delete user",secondaryButtonText:"Cancel",children:r("div",{ref:l,children:[e(C,{condition:!!s[Gn],show:e(J,{"data-loading":!0,severity:"error",style:{margin:"1rem 0"},children:s[Gn]})}),r("div",{"data-loading":!0,className:d.flexRow,children:[e(rd,{user:o,variant:"rounded"}),e(D,{variant:"subtitle1",style:{marginLeft:"1rem"},children:o.username||o.email})]}),r(D,{"data-loading":!0,variant:"body1",style:{marginTop:"1rem"},children:["Are you sure you want to delete"," ",o?`${o.name||"user"} (${o.email||o.username})`:"","?"]})]})})},sd=g(Fr)(({theme:t})=>({color:t.palette.primary.light,fontSize:"1.5rem",backgroundColor:"#F1F0FC",borderRadius:t.shape.borderRadiusLarge})),ld=({value:t})=>e(te,{children:e(C,{condition:t,show:e(Ue,{title:"Paid user",arrow:!0,children:e(sd,{})}),elseShow:"Included"})}),cd=g(N)(()=>({display:"flex",justifyContent:"center"})),dd=({onEdit:t,onChangePassword:n,onDelete:o})=>r(cd,{children:[e(Ae,{"data-loading":!0,onClick:t,permission:Y,tooltipProps:{title:"Edit user"},children:e(Qe,{})}),e(Ae,{"data-loading":!0,onClick:n,permission:Y,tooltipProps:{title:"Change password"},children:e(fr,{})}),e(Ae,{"data-loading":!0,onClick:o,permission:Y,tooltipProps:{title:"Remove user"},children:e(Le,{})})]}),jn=20,ud=()=>{const{users:t}=Ee(),{isBillingUsers:n,planUsers:o}=rn(t);return!n||(o==null?void 0:o.length)<jn?null:e(J,{severity:"info",sx:{marginBottom:a=>a.spacing(3)},children:r("p",{children:[e("strong",{children:"Heads up!"})," You have reached your maximum number of registered users for you PRO account (up to max ",jn," ","users). If you need more users please"," ",e(Qt,{component:de,to:"https://www.getunleash.io/signup-enterprise",children:"get in touch with us"}),"."]})})},hd=()=>{const t=be(),{users:n,roles:o,refetch:a,loading:i}=Ee(),{setToastData:s,setToastApiError:l}=Z(),{removeUser:d,userLoading:u,userApiErrors:c}=Tt(),[h,m]=p.useState({open:!1}),[S,f]=p.useState(!1),[y,v]=p.useState(!1),[T,w]=p.useState(!1),[k,E]=p.useState(""),[x,P]=p.useState(),{planUsers:M,isBillingUsers:U}=rn(n),[I,F]=p.useState(""),O=ye(Oe.breakpoints.down("sm")),A=ye(Oe.breakpoints.down("md")),L=()=>{f(!1),P(void 0)},X=j=>le=>{le.preventDefault(),f(!0),P(j)},R=j=>le=>{le.preventDefault(),m({open:!0,user:j})},_=()=>{m({open:!1})},q=async j=>{try{await d(j.id),s({title:`${j.name} has been deleted`,type:"success"}),a(),L()}catch(le){l(K(le))}},se=()=>{v(!1),w(!1),E("")},ae=p.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:j}})=>e(te,{children:e(He,{user:j})}),disableSortBy:!0,maxWidth:80},{id:"name",Header:"Name",accessor:j=>j.name||"",minWidth:200,Cell:({row:{original:j}})=>e(Ce,{value:j.name,subtitle:j.email||j.username}),searchable:!0},{id:"role",Header:"Role",accessor:j=>{var le;return((le=o.find(Rt=>Rt.id===j.rootRole))==null?void 0:le.name)||""},Cell:({row:{original:j},value:le})=>e(Co,{value:le,roleId:j.rootRole}),maxWidth:120},{Header:"Created",accessor:"createdAt",Cell:ve,sortType:"date",width:120,maxWidth:120},{id:"last-login",Header:"Last login",accessor:j=>j.seenAt||"",Cell:({row:{original:j}})=>e(Ve,{value:j.seenAt,emptyText:"Never",title:le=>`Last login: ${le}`}),sortType:"date",maxWidth:150},{id:"type",Header:"Type",accessor:"paid",maxWidth:100,Cell:({row:{original:j}})=>e(ld,{value:U&&j.paid}),sortType:"boolean"},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:j}})=>e(dd,{onEdit:()=>{t(`/admin/users/${j.id}/edit`)},onChangePassword:R(j),onDelete:X(j)}),width:150,disableSortBy:!0},{accessor:"username",Header:"Username",searchable:!0},{accessor:"email",Header:"Email",searchable:!0}],[o,t,U]),H=p.useMemo(()=>({sortBy:[{id:"createdAt"}],hiddenColumns:U?["username","email"]:["type","username","email"]}),[U]),{data:re,getSearchText:Ye}=nt(ae,I,U?M:n),{headerGroups:Et,rows:ke,prepareRow:Je,setHiddenColumns:kt}=$.useTable({columns:ae,data:re,initialState:H,sortTypes:Se,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0,defaultColumn:{Cell:te}},$.useSortBy,$.useFlexLayout);return et([{condition:!U||A,columns:["type"]},{condition:O,columns:["imageUrl","role"]},{condition:A,columns:["createdAt","last-login"]}],kt,ae),r(ee,{isLoading:i,header:e(ne,{title:`Users (${ke.length})`,actions:r(B,{children:[e(me,{initialValue:I,onChange:F}),e(ne.Divider,{}),e(z,{variant:"contained",color:"primary",onClick:()=>t("/admin/create-user"),children:"Add new user"})]})}),children:[e(ud,{}),e(qe,{value:Ye(I),children:e(xe,{rows:ke,headerGroups:Et,prepareRow:Je})}),e(C,{condition:ke.length===0,show:e(C,{condition:(I==null?void 0:I.length)>0,show:r(fe,{children:["No users found matching “",I,"”"]}),elseShow:e(fe,{children:"No users available. Get started by adding one."})})}),e(jo,{open:y,closeConfirm:se,emailSent:T,inviteLink:k}),e(C,{condition:!!h.user,show:()=>e(ad,{showDialog:h.open,closeDialog:_,user:h.user})}),e(C,{condition:!!x,show:e(id,{showDialog:S,closeDialog:L,user:x,removeUser:()=>q(x),userLoading:u,userApiErrors:c})})]})},pd=()=>{var T,w,k,E,x;const t=be(),{data:n,loading:o}=_o(),a=bo(o),{trackEvent:i}=Zt(),s=((T=n==null?void 0:n.tokens)==null?void 0:T.find(P=>P.name==="default"))??null,l=s==null?void 0:s.url,d=((k=(w=n==null?void 0:n.tokens)==null?void 0:w[0])==null?void 0:k.createdAt)??"",c=(((x=(E=n==null?void 0:n.tokens)==null?void 0:E[0])==null?void 0:x.expiresAt)??"")||!1,h=!!(c&&fn(new Date,Lt(c))),m=c&&fn(dt(new Date,{days:14}),Lt(c)),S=c?yr(Lt(c)):!1,{locationSettings:f}=eo(),y=e(D,{component:"span",variant:"body2",color:m?"warning.dark":"inherit",fontWeight:"bold",children:S}),v=()=>{i("invite",{props:{eventType:l?"link bar action: edit":"link bar action: create"}}),t("/admin/invite-link")};return r(N,{sx:P=>({backgroundColor:P.palette.background.paper,py:2,px:4,mb:2,borderRadius:`${P.shape.borderRadiusLarge}px`,display:"flex",flexDirection:{xs:"column",md:"row"},border:"2px solid",borderColor:P.palette.background.alternative}),ref:a,children:[e(N,{sx:{mb:{xs:1,md:0},display:"flex",justifyContent:"center",flexDirection:"column"},children:e(C,{condition:!!l,show:r(B,{children:[r(D,{variant:"body2",sx:{mb:1},children:[`You have an invite link created on ${oo(d,f.locale)} `,e(C,{condition:h,show:r(B,{children:["that expired ",y," ","ago"]}),elseShow:r(B,{children:["that will expire in"," ",y]})})]}),e(xt,{small:!0,inviteLink:l})]}),elseShow:e(D,{variant:"body2","data-loading":!0,children:"You can easily create an invite link here that you can share and use to invite people from your company to your Unleash setup."})})}),e(N,{sx:{minWidth:200,display:"flex",justifyContent:{xs:"center",md:"flex-end"},alignItems:"center",flexGrow:1},children:r(z,{variant:"outlined",onClick:v,"data-loading":!0,children:[l?"Update":"Create"," invite link"]})})]})},md=(t,n={})=>{const o=()=>{const u=oe(`api/admin/user-admin/${t}`);return fetch(u,{method:"GET"}).then(ue("Users")).then(c=>c.json())},{data:a,error:i}=we(`api/admin/user-admin/${t}`,o,n),[s,l]=p.useState(!i&&!a),d=()=>{Xn(`api/admin/user-admin/${t}`)};return p.useEffect(()=>{l(!i&&!a)},[a,i]),{user:a||{},error:i,loading:s,refetch:d}},gd=()=>{p.useEffect(()=>{Wt()},[]);const{uiConfig:t}=G(),{setToastData:n,setToastApiError:o}=Z(),a=Vt("id"),{user:i,refetch:s}=md(a),{updateUser:l,userLoading:d}=Tt(),u=be(),{name:c,setName:h,email:m,setEmail:S,sendEmail:f,setSendEmail:y,rootRole:v,setRootRole:T,getAddUserPayload:w,validateName:k,errors:E,clearErrors:x}=Mo(i==null?void 0:i.name,i==null?void 0:i.email,i==null?void 0:i.rootRole);return e(Pe,{loading:d,title:"Edit user",description:"In order for a user to get access to Unleash, they need to be assigned a root role, such as Viewer, Editor, or Admin.",documentationLink:"https://docs.getunleash.io/reference/rbac#predefined-roles",documentationLinkLabel:"User management documentation",formatApiCode:()=>`curl --location --request PUT '${t.unleashUrl}/api/admin/user-admin/${a}' \\
33
33
  --header 'Authorization: INSERT_API_KEY' \\
34
34
  --header 'Content-Type: application/json' \\
35
- --data-raw '${JSON.stringify(w(),void 0,2)}'`,children:e(Go,{errors:E,handleSubmit:async I=>{I.preventDefault();const F=w();if(k())try{await l({...F,id:a}),s(),u("/admin/users"),n({title:"User information updated",type:"success"})}catch(A){o(K(A))}},handleCancel:()=>{u(De)},name:c,setName:h,email:m,setEmail:S,sendEmail:f,setSendEmail:y,rootRole:v,setRootRole:T,clearErrors:x,mode:Yt,children:e(ao,{permission:Y})})})},fd=()=>e("div",{children:e(Te,{permissions:Y,children:r(ot,{children:[e(H,{index:!0,element:r(B,{children:[e(pd,{}),e(hd,{})]})}),e(H,{path:":id/edit",element:e(gd,{})}),e(H,{path:"*",element:e(So,{})})]})})}),yd=()=>{const n=vo().reduce((o,a)=>{const i=a.group||"other",s=o.findIndex(l=>l.name===i);return s===-1?(o.push({name:i,description:br[i]||"Other",items:[a]}),o):(o[s].items.push(a),o)},[]);return e(ee,{header:e(ne,{title:"Manage Unleash"}),children:n.map(o=>r(N,{sx:a=>({marginBottom:a.spacing(2)}),children:[e(D,{variant:"h2",children:o.description}),e("ul",{children:o.items.map(a=>e("li",{children:e(Qt,{component:de,to:a.path,children:a.title})},a.path))})]},o.name))})},bd=g(co)(({theme:t})=>({marginBottom:"1rem",borderRadius:`${t.shape.borderRadiusLarge}px`,boxShadow:"none",padding:t.spacing(0,2)})),Sd=g("div")(({theme:t})=>({marginLeft:t.spacing(1),display:"flex",alignItems:"center"})),vd=()=>{var u;const{uiConfig:t,isPro:n,isOss:o}=G(),{pathname:a}=Xt(),i=a.split("/")[2],s=vo(),l=(u=s.find(c=>a.includes(c.path)))==null?void 0:u.group,d=s.filter(c=>!l||c.group===l||o()&&c.group!=="log");return l?e(bd,{children:e(gt,{value:i,variant:"scrollable",scrollButtons:"auto",allowScrollButtonsMobile:!0,children:d.map(c=>{var h,m,S,f;return e(ft,{sx:{padding:0},value:(m=(h=c.route)==null?void 0:h.split("/"))==null?void 0:m[2],label:r(an,{to:c.path,children:[c.title,e(C,{condition:!!((S=c.menu.mode)!=null&&S.includes("enterprise")&&!((f=c.menu.mode)!=null&&f.includes("pro"))&&n()),show:e(Sd,{children:e(Sr,{size:16})})})]})},c.route)})})}):null},Ed=()=>r(B,{children:[e(vd,{}),r(ot,{children:[e(H,{index:!0,element:e(yd,{})}),e(H,{path:"users/*",element:e(fd,{})}),e(H,{path:"api",element:e(Kr,{})}),e(H,{path:"api/create-token",element:e(Xr,{})}),e(H,{path:"service-accounts",element:e($c,{})}),e(H,{path:"create-user",element:e(Xc,{})}),e(H,{path:"invite-link",element:e(td,{})}),e(H,{path:"groups/*",element:e(Zs,{})}),e(H,{path:"roles/*",element:e(mc,{})}),e(H,{path:"instance",element:e(tl,{})}),e(H,{path:"network/*",element:e(Ol,{})}),e(H,{path:"maintenance",element:e(Al,{})}),e(H,{path:"cors",element:e(Fi,{})}),e(H,{path:"auth",element:e(di,{})}),e(H,{path:"admin-invoices",element:e(Mi,{})}),e(H,{path:"billing",element:e(Oi,{})}),e(H,{path:"instance-privacy",element:e(bl,{})}),e(H,{path:"*",element:e(So,{})})]})]});export{Ed as default};
35
+ --data-raw '${JSON.stringify(w(),void 0,2)}'`,children:e(Go,{errors:E,handleSubmit:async I=>{I.preventDefault();const F=w();if(k())try{await l({...F,id:a}),s(),u("/admin/users"),n({title:"User information updated",type:"success"})}catch(A){o(K(A))}},handleCancel:()=>{u(De)},name:c,setName:h,email:m,setEmail:S,sendEmail:f,setSendEmail:y,rootRole:v,setRootRole:T,clearErrors:x,mode:Yt,children:e(ao,{permission:Y})})})},fd=()=>e("div",{children:e(Te,{permissions:Y,children:r(ot,{children:[e(W,{index:!0,element:r(B,{children:[e(pd,{}),e(hd,{})]})}),e(W,{path:":id/edit",element:e(gd,{})}),e(W,{path:"*",element:e(So,{})})]})})}),yd=()=>{const n=vo().reduce((o,a)=>{const i=a.group||"other",s=o.findIndex(l=>l.name===i);return s===-1?(o.push({name:i,description:br[i]||"Other",items:[a]}),o):(o[s].items.push(a),o)},[]);return e(ee,{header:e(ne,{title:"Manage Unleash"}),children:n.map(o=>r(N,{sx:a=>({marginBottom:a.spacing(2)}),children:[e(D,{variant:"h2",children:o.description}),e("ul",{children:o.items.map(a=>e("li",{children:e(Qt,{component:de,to:a.path,children:a.title})},a.path))})]},o.name))})},bd=g(co)(({theme:t})=>({marginBottom:"1rem",borderRadius:`${t.shape.borderRadiusLarge}px`,boxShadow:"none",padding:t.spacing(0,2)})),Sd=g("div")(({theme:t})=>({marginLeft:t.spacing(1),display:"flex",alignItems:"center"})),vd=()=>{var u;const{uiConfig:t,isPro:n,isOss:o}=G(),{pathname:a}=Xt(),i=a.split("/")[2],s=vo(),l=(u=s.find(c=>a.includes(c.path)))==null?void 0:u.group,d=s.filter(c=>!l||c.group===l||o()&&c.group!=="log");return l?e(bd,{children:e(gt,{value:i,variant:"scrollable",scrollButtons:"auto",allowScrollButtonsMobile:!0,children:d.map(c=>{var h,m,S,f;return e(ft,{sx:{padding:0},value:(m=(h=c.route)==null?void 0:h.split("/"))==null?void 0:m[2],label:r(an,{to:c.path,children:[c.title,e(C,{condition:!!((S=c.menu.mode)!=null&&S.includes("enterprise")&&!((f=c.menu.mode)!=null&&f.includes("pro"))&&n()),show:e(Sd,{children:e(Sr,{size:16})})})]})},c.route)})})}):null},Ed=()=>r(B,{children:[e(vd,{}),r(ot,{children:[e(W,{index:!0,element:e(yd,{})}),e(W,{path:"users/*",element:e(fd,{})}),e(W,{path:"api",element:e(Kr,{})}),e(W,{path:"api/create-token",element:e(Xr,{})}),e(W,{path:"service-accounts",element:e($c,{})}),e(W,{path:"create-user",element:e(Xc,{})}),e(W,{path:"invite-link",element:e(td,{})}),e(W,{path:"groups/*",element:e(Zs,{})}),e(W,{path:"roles/*",element:e(mc,{})}),e(W,{path:"instance",element:e(tl,{})}),e(W,{path:"network/*",element:e(Ol,{})}),e(W,{path:"maintenance",element:e(Al,{})}),e(W,{path:"cors",element:e(Fi,{})}),e(W,{path:"auth",element:e(di,{})}),e(W,{path:"admin-invoices",element:e(Mi,{})}),e(W,{path:"billing",element:e(Oi,{})}),e(W,{path:"instance-privacy",element:e(bl,{})}),e(W,{path:"*",element:e(So,{})})]})]});export{Ed as default};