unleash-server 5.1.0 → 5.1.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 (22) hide show
  1. package/dist/lib/db/event-store.js +2 -1
  2. package/dist/lib/db/event-store.js.map +1 -1
  3. package/frontend/build/index.html +1 -1
  4. package/frontend/build/static/{CreateProject-3c093214.js → CreateProject-217f67b6.js} +1 -1
  5. package/frontend/build/static/{Error-10dff66c.js → Error-5606eccd.js} +1 -1
  6. package/frontend/build/static/FeatureArchiveDialog-c311c641.js +4 -0
  7. package/frontend/build/static/{FeatureMetricsChart-d5c6311d.js → FeatureMetricsChart-1c6bb078.js} +1 -1
  8. package/frontend/build/static/{FeatureViewLazyExport-e52ae7b0.js → FeatureViewLazyExport-06cf4baa.js} +2 -2
  9. package/frontend/build/static/{LazyAdminExport-2554e446.js → LazyAdminExport-04c8032d.js} +2 -2
  10. package/frontend/build/static/{LazyProjectExport-682e75c0.js → LazyProjectExport-d9663a8c.js} +1 -1
  11. package/frontend/build/static/{NetworkOverview-4653e26c.js → NetworkOverview-2bce4916.js} +1 -1
  12. package/frontend/build/static/{NetworkTraffic-4332556b.js → NetworkTraffic-7db94d86.js} +1 -1
  13. package/frontend/build/static/{Playground-130e9113.js → Playground-6602cb1a.js} +1 -1
  14. package/frontend/build/static/{StrategyItemContainer-893b13f0.js → StrategyItemContainer-0140b94f.js} +1 -1
  15. package/frontend/build/static/{chartjs-adapter-date-fns.esm-23b8f0d9.js → chartjs-adapter-date-fns.esm-c75aa905.js} +1 -1
  16. package/frontend/build/static/{index-66ec1ba9.js → index-1f392976.js} +2 -2
  17. package/frontend/build/static/{index-4d0a5ffb.js → index-b3def5eb.js} +1 -1
  18. package/frontend/build/static/{index-e7efdb59.js → index-f8439975.js} +1 -1
  19. package/frontend/build/static/{unknownify-6ed6e58e.js → unknownify-6683037a.js} +1 -1
  20. package/frontend/build/static/{useProjectRole-ce09b03e.js → useProjectRole-122ac4bb.js} +1 -1
  21. package/package.json +1 -1
  22. package/frontend/build/static/FeatureArchiveDialog-365cb2af.js +0 -4
@@ -1 +1 @@
1
- import{fr as $,c as _,j as t,H as E,f as l,A as N,N as z,cb as Q,U as V,F as k,C,a as T,X as q,cZ as X,S as Y,h as Z,i as J,k as ee,W as R,bK as L,ao as te,di as ne,bQ as oe,fs as se,s as y,aL as U,dz as re,l as B,dB as A,r as u,I as ae,R as v,cc as le,de as ie,d as I,e as ce,a2 as F,aJ as H,cr as de,ft as ue,bl as he,b8 as M,a4 as pe,bZ as me,ca as ye,a9 as fe,aj as O,T as w,dv as be,cM as ge,a5 as Ce,dy as Te,bY as ke,dx as Se,eM as Ae,aO as ve,aP as W,aQ as G,ch as Ie,aR as we}from"./index-66ec1ba9.js";const Ee=$(),qe=Ee,Ne=_(t("path",{d:"M21 10h-8.35C11.83 7.67 9.61 6 7 6c-3.31 0-6 2.69-6 6s2.69 6 6 6c2.61 0 4.83-1.67 5.65-4H13l2 2 2-2 2 2 4-4.04L21 10zM7 15c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z"}),"Key"),xe=()=>{const{uiConfig:e}=E();return l(N,{severity:"info",children:[l("p",{children:["Read the"," ",t("a",{href:"https://docs.getunleash.io/reference/sdks",target:"_blank",rel:"noreferrer",children:"SDK overview"})," ","to connect Unleash to your application. Please note it can take up to ",t("strong",{children:"1 minute"})," before a new API key is activated."]}),t("br",{}),t("strong",{children:"API URL: "})," ",l("pre",{style:{display:"inline"},children:[e.unleashUrl,"/api/"]})]})},De=["Icon","createdAt"],Pe=["Icon","project","seenAt"],Xe=({compact:e=!1,setHiddenColumns:n,columns:s,loading:o,rows:r,getTableProps:a,getTableBodyProps:i,headerGroups:c,globalFilter:d,prepareRow:f})=>{const g=z(Q.breakpoints.down("md"));return V([{condition:g,columns:De},{condition:e,columns:Pe}],n,s),l(k,{children:[t(C,{condition:r.length>0,show:t(T,{sx:{mb:4},children:t(xe,{})})}),t(T,{sx:{overflowX:"auto"},children:t(q,{value:d,children:l(X,{...a(),children:[t(Y,{headerGroups:c}),t(Z,{...i(),children:r.map(b=>(f(b),t(J,{hover:!0,...b.getRowProps(),children:b.cells.map(h=>t(ee,{...h.getCellProps(),children:h.render("Cell")}))})))})]})})}),t(C,{condition:r.length===0&&!o,show:t(C,{condition:(d==null?void 0:d.length)>0,show:l(R,{children:["No tokens found matching “",d,"”"]}),elseShow:t(R,{children:l("span",{children:["No tokens available. Read ",t(L,{href:"https://docs.getunleash.io/how-to/api",target:"_blank",rel:"noreferrer",children:"API How-to guides"})," "," to learn more."]})})})})]})},Ye=({path:e,permission:n,project:s})=>{const o=te();return t(ne,{Icon:oe,onClick:()=>o(e),"data-testid":se,permission:n,projectId:s,maxWidth:"700px",children:"New API token"})},Re=y(U)(({theme:e})=>({textDecoration:"none",color:e.palette.links,"&:hover, &:focus":{textDecoration:"underline"}})),Be=({projects:e,project:n})=>{const{searchQuery:s}=re();let o=e&&Array.isArray(e)?e:n?[n]:[];return o.length===0?t(B,{children:t(A,{search:s,children:"*"})}):t(B,{children:o.map((r,a)=>l(u.Fragment,{children:[a>0&&", ",!r||r==="*"?t(A,{search:s,children:"*"}):t(Re,{to:`/projects/${r}`,children:t(A,{search:s,children:r})})]},r))})},Ze=(e,n)=>{const s=u.useMemo(()=>({sortBy:[{id:"createdAt"}]}),[]),o=u.useMemo(()=>[{id:"Icon",width:"1%",Cell:()=>t(ae,{icon:t(Ne,{color:"disabled"})}),disableSortBy:!0,disableGlobalFilter:!0},{Header:"Username",accessor:"username",Cell:v},{Header:"Type",accessor:"type",Cell:({value:h})=>t(v,{value:j[h.toLowerCase()].label,subtitle:j[h.toLowerCase()].title}),minWidth:280},{Header:"Project",accessor:"project",Cell:h=>t(Be,{project:h.row.original.project,projects:h.row.original.projects}),minWidth:120},{Header:"Environment",accessor:"environment",Cell:v,minWidth:120},{Header:"Created",accessor:"createdAt",Cell:le,minWidth:150,disableGlobalFilter:!0},{Header:"Last seen",accessor:"seenAt",Cell:ie,minWidth:150,disableGlobalFilter:!0},{Header:"Actions",id:"Actions",align:"center",width:"1%",disableSortBy:!0,disableGlobalFilter:!0,Cell:n}],[]),{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:c,prepareRow:d,state:f,setGlobalFilter:g,setHiddenColumns:b}=I.useTable({columns:o,data:e,initialState:s,sortTypes:ce,autoResetHiddenColumns:!1,disableSortRemove:!0},I.useGlobalFilter,I.useSortBy);return{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:c,prepareRow:d,state:f,setGlobalFilter:g,setHiddenColumns:b,columns:o}},j={client:{label:"CLIENT",title:"Connect server-side SDK or Unleash Proxy"},frontend:{label:"FRONTEND",title:"Connect web and mobile SDK"},admin:{label:"ADMIN",title:"Full access for managing Unleash"}},Je=({token:e,project:n,permission:s,track:o})=>{const{setToastData:r}=F(),a=i=>{ue(i)&&(r({type:"success",title:"Token copied to clipboard"}),o&&typeof o=="function"&&o())};return t(H,{permission:s,projectId:n,tooltipProps:{title:"Copy token",arrow:!0},onClick:()=>a(e.secret),size:"large",children:t(de,{})})},je=y("ul")({marginBottom:0}),et=({token:e,permission:n,onRemove:s,project:o})=>{const[r,a]=u.useState(!1),{setToastData:i,setToastApiError:c}=F();return l(k,{children:[t(H,{permission:n,projectId:o,tooltipProps:{title:"Delete token",arrow:!0},onClick:()=>a(!0),size:"large",children:t(he,{})}),t(M,{open:r,onClick:async()=>{try{await s(),a(!1),i({type:"success",title:"API token removed"})}catch(f){c(pe(f))}},onClose:()=>a(!1),title:"Confirm deletion",children:l("div",{children:["Are you sure you want to delete the following API token?",t("br",{}),l(je,{children:[l("li",{children:[t("strong",{children:"username"}),":"," ",t("code",{children:e.username})]}),l("li",{children:[t("strong",{children:"type"}),": ",t("code",{children:e.type})]})]})]})})]})},Le=y("div")(()=>({maxWidth:"400px"})),Ue=y("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Fe=y(me)(({theme:e})=>({width:"100%",marginBottom:e.spacing(2)})),He=y(ye)(({theme:e})=>({marginBottom:e.spacing(2),minWidth:"400px",[e.breakpoints.down("sm")]:{minWidth:"379px"}})),K=y("p")(({theme:e})=>({marginBottom:e.spacing(1)})),Me=y("label")(({theme:e})=>({marginBottom:e.spacing(1)})),Oe=y(fe)(({theme:e})=>({marginLeft:e.spacing(3)})),We=y(T)({marginTop:"auto",display:"flex",justifyContent:"flex-end"}),tt=({children:e,actions:n,handleSubmit:s,handleCancel:o})=>{var i;const{uiConfig:r}=E(),a=!!((i=r==null?void 0:r.flags)!=null&&i.UNLEASH_CLOUD);return l(Ue,{onSubmit:s,children:[t(C,{condition:a,show:l(N,{severity:"info",sx:{mb:4},children:["Please be aware of our"," ",t(L,{href:"https://www.getunleash.io/fair-use-policy",children:"fair use policy"}),"."]})}),e,l(We,{children:[n,t(Oe,{onClick:o,children:"Cancel"})]})]})},nt=e=>{var D;const{environments:n}=O(),s=(D=n==null?void 0:n.find(p=>p.enabled))==null?void 0:D.name,[o,r]=u.useState(""),[a,i]=u.useState("CLIENT"),[c,d]=u.useState([e||"*"]),[f,g]=u.useState(c),[b,h]=u.useState(),[x,S]=u.useState({});return u.useEffect(()=>{h(a==="ADMIN"?"*":s)},[a,s]),{username:o,type:a,projects:c,environment:b,setUsername:r,setTokenType:p=>{p==="ADMIN"?(i(p),g(c),d(["*"]),h("*")):(i(p),d(f),h(s))},setProjects:d,setEnvironment:h,getApiTokenPayload:()=>({username:o,type:a,environment:b,projects:c}),isValid:()=>{const p={};return o||(p.username="Username is required"),c.length===0&&(p.projects="At least one project is required"),S(p),Object.keys(p).length===0},clearErrors:p=>{if(p){const P={...x};delete P[p],S(P)}else S({})},errors:x}};var m=(e=>(e.ADMIN="ADMIN",e.CLIENT="CLIENT",e.FRONTEND="FRONTEND",e))(m||{});const ot=({open:e,closeConfirm:n,token:s,type:o})=>l(M,{open:e,onClick:n,primaryButtonText:"Close",title:"New token created",children:[t(w,{variant:"body1",children:"Your new token has been created successfully."}),t(be,{token:s}),t(C,{condition:o===m.FRONTEND,show:l(N,{sx:{mt:2},severity:"info",children:["By default, all ",m.FRONTEND," tokens may be used from any CORS origin. If you'd like to configure a strict set of origins, please use the"," ",t(U,{to:"/admin/cors",target:"_blank",rel:"noreferrer",children:"CORS origins configuration page"}),"."]})})]}),st=({username:e,setUsername:n,errors:s,clearErrors:o})=>l(k,{children:[t(K,{children:"What would you like to call this token?"}),t(Fe,{value:e,name:"username",onChange:r=>n(r.target.value),label:"Token name",error:s.username!==void 0,errorText:s.username,onFocus:()=>o("username"),autoFocus:!0})]}),rt=({type:e,setType:n})=>{const s=ge("projectId"),{uiConfig:o}=E(),r=[{key:m.CLIENT,label:`Server-side SDK (${m.CLIENT})`,title:"Connect server-side SDK or Unleash Proxy"}];return s||r.push({key:m.ADMIN,label:m.ADMIN,title:"Full access for managing Unleash"}),o.flags.embedProxyFrontend&&r.splice(1,0,{key:m.FRONTEND,label:`Client-side SDK (${m.FRONTEND})`,title:"Connect web and mobile SDK directly to Unleash"}),t(Le,{children:l(Ce,{sx:{mb:2,width:"100%"},children:[t(Me,{id:"token-type",children:"What do you want to connect?"}),t(Te,{"aria-labelledby":"token-type",defaultValue:"CLIENT",name:"radio-buttons-group",value:e,onChange:(a,i)=>n(i),children:r.map(({key:a,label:i,title:c})=>t(ke,{value:a,sx:{mb:1},control:t(Se,{sx:{ml:.75,alignSelf:"flex-start"}}),label:t(T,{children:l(T,{children:[t(w,{children:i}),t(w,{variant:"body2",color:"text.secondary",children:c})]})})},a))})]})})},at=({type:e,environment:n,setEnvironment:s})=>{const{environments:o}=O(),r=e===m.ADMIN?[{key:"*",label:"ALL"}]:o.map(a=>({key:a.name,label:`${a.name.concat(a.enabled?"":" - deprecated")}`,title:a.name,disabled:!1}));return l(k,{children:[t(K,{children:"Which environment should the token have access to?"}),t(He,{disabled:e===m.ADMIN,options:r,value:n,onChange:s,label:"Environment",id:"api_key_environment",name:"environment",IconComponent:Ae,fullWidth:!0})]})},Ge=e=>e.map(n=>({...n.user,joinedAt:new Date(n.joinedAt),createdBy:n.createdBy})),lt=e=>{const{data:n,error:s,mutate:o}=ve(W(`api/admin/groups/${e}`),Ke);return u.useMemo(()=>({group:n&&{...n,users:Ge((n==null?void 0:n.users)??[])},loading:!s&&!n,refetchGroup:()=>o(),error:s}),[n,s,o])},Ke=e=>fetch(e).then(G("Group")).then(n=>n.json()),it=(e,n={})=>{const s=()=>{const d=W(`api/admin/roles/${e}`);return fetch(d,{method:"GET"}).then(G("project role")).then(f=>f.json())},{data:o,error:r}=Ie({},`api/admin/roles/${e}`,s,n),[a,i]=u.useState(!r&&!o),c=()=>{we(`api/admin/roles/${e}`)};return u.useEffect(()=>{i(!r&&!o)},[o,r]),{role:o||{},error:r,loading:a,refetch:c}};export{Xe as A,qe as B,Ye as C,at as E,et as R,K as S,m as T,Je as a,nt as b,tt as c,st as d,rt as e,ot as f,lt as g,it as h,Ge as m,Ze as u};
1
+ import{fr as $,c as _,j as t,H as E,f as l,A as N,N as z,cb as Q,U as V,F as k,C,a as T,X as q,cZ as X,S as Y,h as Z,i as J,k as ee,W as R,bK as L,ao as te,di as ne,bQ as oe,fs as se,s as y,aL as U,dz as re,l as B,dB as A,r as u,I as ae,R as v,cc as le,de as ie,d as I,e as ce,a2 as F,aJ as H,cr as de,ft as ue,bl as he,b8 as M,a4 as pe,bZ as me,ca as ye,a9 as fe,aj as O,T as w,dv as be,cM as ge,a5 as Ce,dy as Te,bY as ke,dx as Se,eM as Ae,aO as ve,aP as W,aQ as G,ch as Ie,aR as we}from"./index-1f392976.js";const Ee=$(),qe=Ee,Ne=_(t("path",{d:"M21 10h-8.35C11.83 7.67 9.61 6 7 6c-3.31 0-6 2.69-6 6s2.69 6 6 6c2.61 0 4.83-1.67 5.65-4H13l2 2 2-2 2 2 4-4.04L21 10zM7 15c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z"}),"Key"),xe=()=>{const{uiConfig:e}=E();return l(N,{severity:"info",children:[l("p",{children:["Read the"," ",t("a",{href:"https://docs.getunleash.io/reference/sdks",target:"_blank",rel:"noreferrer",children:"SDK overview"})," ","to connect Unleash to your application. Please note it can take up to ",t("strong",{children:"1 minute"})," before a new API key is activated."]}),t("br",{}),t("strong",{children:"API URL: "})," ",l("pre",{style:{display:"inline"},children:[e.unleashUrl,"/api/"]})]})},De=["Icon","createdAt"],Pe=["Icon","project","seenAt"],Xe=({compact:e=!1,setHiddenColumns:n,columns:s,loading:o,rows:r,getTableProps:a,getTableBodyProps:i,headerGroups:c,globalFilter:d,prepareRow:f})=>{const g=z(Q.breakpoints.down("md"));return V([{condition:g,columns:De},{condition:e,columns:Pe}],n,s),l(k,{children:[t(C,{condition:r.length>0,show:t(T,{sx:{mb:4},children:t(xe,{})})}),t(T,{sx:{overflowX:"auto"},children:t(q,{value:d,children:l(X,{...a(),children:[t(Y,{headerGroups:c}),t(Z,{...i(),children:r.map(b=>(f(b),t(J,{hover:!0,...b.getRowProps(),children:b.cells.map(h=>t(ee,{...h.getCellProps(),children:h.render("Cell")}))})))})]})})}),t(C,{condition:r.length===0&&!o,show:t(C,{condition:(d==null?void 0:d.length)>0,show:l(R,{children:["No tokens found matching “",d,"”"]}),elseShow:t(R,{children:l("span",{children:["No tokens available. Read ",t(L,{href:"https://docs.getunleash.io/how-to/api",target:"_blank",rel:"noreferrer",children:"API How-to guides"})," "," to learn more."]})})})})]})},Ye=({path:e,permission:n,project:s})=>{const o=te();return t(ne,{Icon:oe,onClick:()=>o(e),"data-testid":se,permission:n,projectId:s,maxWidth:"700px",children:"New API token"})},Re=y(U)(({theme:e})=>({textDecoration:"none",color:e.palette.links,"&:hover, &:focus":{textDecoration:"underline"}})),Be=({projects:e,project:n})=>{const{searchQuery:s}=re();let o=e&&Array.isArray(e)?e:n?[n]:[];return o.length===0?t(B,{children:t(A,{search:s,children:"*"})}):t(B,{children:o.map((r,a)=>l(u.Fragment,{children:[a>0&&", ",!r||r==="*"?t(A,{search:s,children:"*"}):t(Re,{to:`/projects/${r}`,children:t(A,{search:s,children:r})})]},r))})},Ze=(e,n)=>{const s=u.useMemo(()=>({sortBy:[{id:"createdAt"}]}),[]),o=u.useMemo(()=>[{id:"Icon",width:"1%",Cell:()=>t(ae,{icon:t(Ne,{color:"disabled"})}),disableSortBy:!0,disableGlobalFilter:!0},{Header:"Username",accessor:"username",Cell:v},{Header:"Type",accessor:"type",Cell:({value:h})=>t(v,{value:j[h.toLowerCase()].label,subtitle:j[h.toLowerCase()].title}),minWidth:280},{Header:"Project",accessor:"project",Cell:h=>t(Be,{project:h.row.original.project,projects:h.row.original.projects}),minWidth:120},{Header:"Environment",accessor:"environment",Cell:v,minWidth:120},{Header:"Created",accessor:"createdAt",Cell:le,minWidth:150,disableGlobalFilter:!0},{Header:"Last seen",accessor:"seenAt",Cell:ie,minWidth:150,disableGlobalFilter:!0},{Header:"Actions",id:"Actions",align:"center",width:"1%",disableSortBy:!0,disableGlobalFilter:!0,Cell:n}],[]),{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:c,prepareRow:d,state:f,setGlobalFilter:g,setHiddenColumns:b}=I.useTable({columns:o,data:e,initialState:s,sortTypes:ce,autoResetHiddenColumns:!1,disableSortRemove:!0},I.useGlobalFilter,I.useSortBy);return{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:c,prepareRow:d,state:f,setGlobalFilter:g,setHiddenColumns:b,columns:o}},j={client:{label:"CLIENT",title:"Connect server-side SDK or Unleash Proxy"},frontend:{label:"FRONTEND",title:"Connect web and mobile SDK"},admin:{label:"ADMIN",title:"Full access for managing Unleash"}},Je=({token:e,project:n,permission:s,track:o})=>{const{setToastData:r}=F(),a=i=>{ue(i)&&(r({type:"success",title:"Token copied to clipboard"}),o&&typeof o=="function"&&o())};return t(H,{permission:s,projectId:n,tooltipProps:{title:"Copy token",arrow:!0},onClick:()=>a(e.secret),size:"large",children:t(de,{})})},je=y("ul")({marginBottom:0}),et=({token:e,permission:n,onRemove:s,project:o})=>{const[r,a]=u.useState(!1),{setToastData:i,setToastApiError:c}=F();return l(k,{children:[t(H,{permission:n,projectId:o,tooltipProps:{title:"Delete token",arrow:!0},onClick:()=>a(!0),size:"large",children:t(he,{})}),t(M,{open:r,onClick:async()=>{try{await s(),a(!1),i({type:"success",title:"API token removed"})}catch(f){c(pe(f))}},onClose:()=>a(!1),title:"Confirm deletion",children:l("div",{children:["Are you sure you want to delete the following API token?",t("br",{}),l(je,{children:[l("li",{children:[t("strong",{children:"username"}),":"," ",t("code",{children:e.username})]}),l("li",{children:[t("strong",{children:"type"}),": ",t("code",{children:e.type})]})]})]})})]})},Le=y("div")(()=>({maxWidth:"400px"})),Ue=y("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Fe=y(me)(({theme:e})=>({width:"100%",marginBottom:e.spacing(2)})),He=y(ye)(({theme:e})=>({marginBottom:e.spacing(2),minWidth:"400px",[e.breakpoints.down("sm")]:{minWidth:"379px"}})),K=y("p")(({theme:e})=>({marginBottom:e.spacing(1)})),Me=y("label")(({theme:e})=>({marginBottom:e.spacing(1)})),Oe=y(fe)(({theme:e})=>({marginLeft:e.spacing(3)})),We=y(T)({marginTop:"auto",display:"flex",justifyContent:"flex-end"}),tt=({children:e,actions:n,handleSubmit:s,handleCancel:o})=>{var i;const{uiConfig:r}=E(),a=!!((i=r==null?void 0:r.flags)!=null&&i.UNLEASH_CLOUD);return l(Ue,{onSubmit:s,children:[t(C,{condition:a,show:l(N,{severity:"info",sx:{mb:4},children:["Please be aware of our"," ",t(L,{href:"https://www.getunleash.io/fair-use-policy",children:"fair use policy"}),"."]})}),e,l(We,{children:[n,t(Oe,{onClick:o,children:"Cancel"})]})]})},nt=e=>{var D;const{environments:n}=O(),s=(D=n==null?void 0:n.find(p=>p.enabled))==null?void 0:D.name,[o,r]=u.useState(""),[a,i]=u.useState("CLIENT"),[c,d]=u.useState([e||"*"]),[f,g]=u.useState(c),[b,h]=u.useState(),[x,S]=u.useState({});return u.useEffect(()=>{h(a==="ADMIN"?"*":s)},[a,s]),{username:o,type:a,projects:c,environment:b,setUsername:r,setTokenType:p=>{p==="ADMIN"?(i(p),g(c),d(["*"]),h("*")):(i(p),d(f),h(s))},setProjects:d,setEnvironment:h,getApiTokenPayload:()=>({username:o,type:a,environment:b,projects:c}),isValid:()=>{const p={};return o||(p.username="Username is required"),c.length===0&&(p.projects="At least one project is required"),S(p),Object.keys(p).length===0},clearErrors:p=>{if(p){const P={...x};delete P[p],S(P)}else S({})},errors:x}};var m=(e=>(e.ADMIN="ADMIN",e.CLIENT="CLIENT",e.FRONTEND="FRONTEND",e))(m||{});const ot=({open:e,closeConfirm:n,token:s,type:o})=>l(M,{open:e,onClick:n,primaryButtonText:"Close",title:"New token created",children:[t(w,{variant:"body1",children:"Your new token has been created successfully."}),t(be,{token:s}),t(C,{condition:o===m.FRONTEND,show:l(N,{sx:{mt:2},severity:"info",children:["By default, all ",m.FRONTEND," tokens may be used from any CORS origin. If you'd like to configure a strict set of origins, please use the"," ",t(U,{to:"/admin/cors",target:"_blank",rel:"noreferrer",children:"CORS origins configuration page"}),"."]})})]}),st=({username:e,setUsername:n,errors:s,clearErrors:o})=>l(k,{children:[t(K,{children:"What would you like to call this token?"}),t(Fe,{value:e,name:"username",onChange:r=>n(r.target.value),label:"Token name",error:s.username!==void 0,errorText:s.username,onFocus:()=>o("username"),autoFocus:!0})]}),rt=({type:e,setType:n})=>{const s=ge("projectId"),{uiConfig:o}=E(),r=[{key:m.CLIENT,label:`Server-side SDK (${m.CLIENT})`,title:"Connect server-side SDK or Unleash Proxy"}];return s||r.push({key:m.ADMIN,label:m.ADMIN,title:"Full access for managing Unleash"}),o.flags.embedProxyFrontend&&r.splice(1,0,{key:m.FRONTEND,label:`Client-side SDK (${m.FRONTEND})`,title:"Connect web and mobile SDK directly to Unleash"}),t(Le,{children:l(Ce,{sx:{mb:2,width:"100%"},children:[t(Me,{id:"token-type",children:"What do you want to connect?"}),t(Te,{"aria-labelledby":"token-type",defaultValue:"CLIENT",name:"radio-buttons-group",value:e,onChange:(a,i)=>n(i),children:r.map(({key:a,label:i,title:c})=>t(ke,{value:a,sx:{mb:1},control:t(Se,{sx:{ml:.75,alignSelf:"flex-start"}}),label:t(T,{children:l(T,{children:[t(w,{children:i}),t(w,{variant:"body2",color:"text.secondary",children:c})]})})},a))})]})})},at=({type:e,environment:n,setEnvironment:s})=>{const{environments:o}=O(),r=e===m.ADMIN?[{key:"*",label:"ALL"}]:o.map(a=>({key:a.name,label:`${a.name.concat(a.enabled?"":" - deprecated")}`,title:a.name,disabled:!1}));return l(k,{children:[t(K,{children:"Which environment should the token have access to?"}),t(He,{disabled:e===m.ADMIN,options:r,value:n,onChange:s,label:"Environment",id:"api_key_environment",name:"environment",IconComponent:Ae,fullWidth:!0})]})},Ge=e=>e.map(n=>({...n.user,joinedAt:new Date(n.joinedAt),createdBy:n.createdBy})),lt=e=>{const{data:n,error:s,mutate:o}=ve(W(`api/admin/groups/${e}`),Ke);return u.useMemo(()=>({group:n&&{...n,users:Ge((n==null?void 0:n.users)??[])},loading:!s&&!n,refetchGroup:()=>o(),error:s}),[n,s,o])},Ke=e=>fetch(e).then(G("Group")).then(n=>n.json()),it=(e,n={})=>{const s=()=>{const d=W(`api/admin/roles/${e}`);return fetch(d,{method:"GET"}).then(G("project role")).then(f=>f.json())},{data:o,error:r}=Ie({},`api/admin/roles/${e}`,s,n),[a,i]=u.useState(!r&&!o),c=()=>{we(`api/admin/roles/${e}`)};return u.useEffect(()=>{i(!r&&!o)},[o,r]),{role:o||{},error:r,loading:a,refetch:c}};export{Xe as A,qe as B,Ye as C,at as E,et as R,K as S,m as T,Je as a,nt as b,tt as c,st as d,rt as e,ot as f,lt as g,it as h,Ge as m,Ze as u};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unleash-server",
3
3
  "description": "Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.",
4
- "version": "5.1.0",
4
+ "version": "5.1.2",
5
5
  "keywords": [
6
6
  "unleash",
7
7
  "feature toggle",
@@ -1,4 +0,0 @@
1
- import{c as se,j as n,u as ne,aF as U,aX as M,f as b,b8 as q,C as _,A as pe,T as w,c5 as fe,e_ as ee,r as C,eT as ye,e$ as me,aZ as Te,aW as re,a2 as $,H as oe,ao as ie,aG as K,a$ as ce,ap as le,fe as be,ff as Ee,as as Ce,aY as ve,fg as Se,fh as Ae,fi as Re,fj as we,b0 as ue,b9 as xe,a4 as x,fk as ke,s as I,bm as H,F as Y,aK as te,a as Pe,dY as _e,bN as N,fl as Oe,dT as Fe,fm as De,fn as qe,fo as $e,bb as Be,bc as Le,bd as Ue,ad as de,ac as ge,bQ as Ie,c7 as Ye,d5 as Ve,w as ze,fp as We,d4 as je,Z as Ge,bL as Je,aR as Ke,aP as He,aQ as Me,ar as Ne}from"./index-66ec1ba9.js";const Qe=se(n("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z"}),"Cloud"),yt=se(n("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10 10-4.5 10-10S17.5 2 12 2zm4.2 14.2L11 13V7h1.5v5.2l4.5 2.7-.8 1.3z"}),"WatchLater"),mt=({enabled:t,className:s})=>{const e=ne(),o=t?"Environment enabled":"Environment disabled",a={backgroundColor:t?e.palette.primary.light:e.palette.neutral.border,borderRadius:"50%",width:"28px",height:"28px",minWidth:"28px",display:"flex",alignItems:"center",justifyContent:"center",marginRight:e.spacing(1)},r={fill:e.palette.common.white,width:"16px",height:"16px"};return n("div",{style:a,className:s,children:n(Qe,{style:r,titleAccess:o})})},Ze=({isOpen:t,onConfirm:s,onClose:e,showBanner:o,environment:a,messageComponent:r})=>{const i=U("projectId"),{data:h}=M(i),{changeRequestInReviewOrApproved:l,alert:d}=fe(h),g=l(a||"");return b(q,{open:t,primaryButtonText:g?"Add to existing change request":"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:s,onClose:e,title:"Request changes",fullWidth:!0,children:[n(_,{condition:g,show:d}),n(_,{condition:!!o,show:b(pe,{severity:"info",sx:{mb:2},children:["Change requests feature is enabled for ",a,". Your changes need to be approved before they will be live. All the changes you do now will be added into a draft that you can submit for review."]})}),n(w,{variant:"body2",color:"text.secondary",children:"Your suggestion:"}),r]})},Tt="UPDATE_FEATURE_STRATEGY",bt="DELETE_FEATURE_STRATEGY",Et="UPDATE_PROJECT",Ct="READ_PROJECT_API_TOKEN",vt="CREATE_PROJECT_API_TOKEN",St="DELETE_PROJECT_API_TOKEN",Xe=(t,s)=>{const e={};return s.parameters.forEach(o=>{e[o.name]=et(t,o)}),{name:s.name,constraints:[],parameters:e}},et=(t,s)=>s.name==="rollout"||s.name==="percentage"||s.type==="percentage"?"50":s.name==="stickiness"?"":s.name==="groupId"?t:s.type==="boolean"?"false":"",At=()=>{const t=U("projectId"),s=U("featureId"),e=ee("environmentId"),o=ee("strategyName"),[a,r]=C.useState({}),[i,h]=C.useState([]),{strategyDefinition:l}=ye(o),d=me(),{addStrategyToFeature:g,loading:T}=Te(),{addChange:c}=re(),{setToastData:u,setToastApiError:p}=$(),{uiConfig:m}=oe(),{unleashUrl:E}=m,v=ie(),{feature:S,refetchFeature:A}=K(t,s),f=C.useRef(S),{isChangeRequestConfigured:B}=ce(t),{refetch:V}=M(t),{trackEvent:O}=le(),{data:k,staleDataNotification:F,forceRefreshCache:z}=be({unleashGetter:K,params:[t,s],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},S,{afterSubmitAction:A},ke);C.useEffect(()=>{f.current.name===""&&S.name&&(z(S),f.current=S)},[S.name]),C.useEffect(()=>{l&&r(Xe(s,l))},[s,l]);const W=async R=>{await g(t,s,e,R),u({title:"Strategy created",type:"success",confetti:!0})},j=async R=>{await c(t,e,{action:"addStrategy",feature:s,payload:R}),u({title:"Strategy added to draft",type:"success",confetti:!0}),V()},D=Ee(a,i),L=async()=>{O("strategyTitle",{props:{hasTitle:!!a.title,on:"create"}});try{B(e)?await j(D):await W(D),A(),v(xe(t,s))}catch(R){p(x(R))}};return!k||!k.project?null:b(Ce,{modal:!0,title:ve(o),description:Se,documentationLink:Ae,documentationLinkLabel:Re,formatApiCode:()=>at(t,s,e,D,E),children:[n(we,{projectId:t,feature:k,strategy:a,setStrategy:r,segments:i,setSegments:h,environmentId:e,onSubmit:L,loading:T,permission:ue,errors:d,isChangeRequest:B(e)}),F]})},tt=(t,s,e,o)=>{const a=new URLSearchParams({environmentId:e,strategyName:o});return`/projects/${t}/features/${s}/strategies/create?${a}`},at=(t,s,e,o,a)=>{if(!a)return"";const r=`${a}/api/admin/projects/${t}/features/${s}/environments/${e}/strategies`,i=JSON.stringify(o,void 0,2);return`curl --location --request POST '${r}' \\
2
- --header 'Authorization: INSERT_API_KEY' \\
3
- --header 'Content-Type: application/json' \\
4
- --data-raw '${i}'`},ae=I("p")(({theme:t})=>({marginBottom:t.spacing(.5),fontSize:t.fontSizes.bodySize})),Rt=({open:t,environmentName:s,featureId:e,projectId:o,onClose:a})=>{const r=ie(),i=tt(o,e,s,"default");return b(q,{open:t,maxWidth:"sm",onClose:()=>a(),title:"You need to add a strategy to your toggle",primaryButtonText:"Take me directly to add strategy",permissionButton:n(H,{type:"button",permission:ue,projectId:o,environmentId:s,onClick:()=>{a(),r(i)},children:"Take me directly to add strategy"}),secondaryButtonText:"Cancel",children:[n(ae,{children:"Before you can enable the toggle in the environment, you need to add an activation strategy."}),n(ae,{children:"You can add the activation strategy by selecting the toggle, open the environment accordion and add the activation strategy."})]})},st="You can not enable the environment before it has strategies",nt=t=>{const{setToastData:s,setToastApiError:e}=$(),{addChange:o}=re(),{refetch:a}=M(t),[r,i]=C.useState({isOpen:!1}),h=C.useCallback((g,T,c,u)=>{i({featureName:g,environment:T,enabled:c,shouldActivateDisabledStrategies:u,isOpen:!0})},[]),l=C.useCallback(()=>{i(g=>({...g,isOpen:!1}))},[]),d=C.useCallback(async()=>{try{await o(t,r.environment,{feature:r.featureName,action:"updateEnabled",payload:{enabled:!!r.enabled,shouldActivateDisabledStrategies:!!r.shouldActivateDisabledStrategies}}),a(),i(g=>({...g,isOpen:!1})),s({type:"success",title:"Changes added to the draft!"})}catch(g){e(x(g)),i(T=>({...T,isOpen:!1}))}},[o]);return{onChangeRequestToggle:h,onChangeRequestToggleClose:l,onChangeRequestToggleConfirm:d,changeRequestDialogDetails:r}},rt=({isOpen:t,onAddDefaultStrategy:s,onActivateDisabledStrategies:e,onClose:o,environment:a,disabledStrategiesCount:r=0})=>{const i=U("projectId");return b(q,{open:t,secondaryButtonText:"Cancel",permissionButton:b(Y,{children:[n(H,{type:"button",permission:te,projectId:i,environmentId:a,onClick:s,children:"Add default strategy"}),n(H,{type:"button",variant:"text",permission:te,projectId:i,environmentId:a,onClick:e,children:"Enable all strategies"})]}),onClose:o,title:"Enable feature toggle",fullWidth:!0,children:[b(w,{variant:"body1",color:"text.primary",sx:{mb:h=>h.spacing(2)},children:["The feature toggle has ",r," disabled",r===1?" strategy":" strategies","."]}),n(w,{variant:"body1",color:"text.primary",children:"You can choose to enable all the disabled strategies or you can add the default strategy to enable this feature toggle."})]})},ot=({enabled:t,featureName:s,environment:e})=>b(w,{"data-testid":"update-enabled-message",children:[n("strong",{children:t?"Enable":"Disable"})," feature toggle"," ",n("strong",{children:s})," in ",n("strong",{children:e})]}),it=I(Pe)(()=>({mx:"auto",..._e})),wt=({projectId:t,featureId:s,environmentName:e,value:o,onToggle:a,onError:r})=>{var R;const{toggleFeatureEnvironmentOn:i,toggleFeatureEnvironmentOff:h}=N(),{setToastData:l,setToastApiError:d}=$(),{isChangeRequestConfigured:g}=ce(t),{onChangeRequestToggle:T,onChangeRequestToggleClose:c,onChangeRequestToggleConfirm:u,changeRequestDialogDetails:p}=nt(t),[m,E,v]=Oe(o),[S,A]=C.useState(!1),{feature:f}=K(t,s),B=((R=f==null?void 0:f.environments.find(y=>y.name===e))==null?void 0:R.strategies.filter(y=>y.disabled).length)??0,{uiConfig:V}=oe(),O=!!V.flags.strategyImprovements,{trackEvent:k}=le(),F=async(y=!1)=>{try{E(!m),await i(t,f.name,e,y),l({type:"success",title:`Available in ${e}`,text:`${f.name} is now available in ${e} based on its defined strategies.`}),a==null||a(t,f.name,e,!m)}catch(P){P instanceof Error&&P.message===st?r==null||r():d(x(P)),v()}},z=async()=>{try{E(!m),await h(t,f.name,e),l({type:"success",title:`Unavailable in ${e}`,text:`${f.name} is unavailable in ${e} and its strategies will no longer have any effect.`}),a==null||a(t,f.name,e,!m)}catch(y){d(x(y)),v()}},W=async y=>{if(g(e)){y.preventDefault(),L()&&O?A(!0):T(f.name,e,!o,!1);return}if(o){await z();return}L()&&O?A(!0):await F()},j=async()=>{await k("strategyImprovements",{props:{eventType:"activate disabled strategies"}}),g(e)?T(f.name,e,!o,!0):await F(!0),A(!1)},D=async()=>{await k("strategyImprovements",{props:{eventType:"add default strategy"}}),g(e)?T(f.name,e,!o,!1):await F(),A(!1)},L=()=>{var P,Z,X;const y=(P=f==null?void 0:f.environments)==null?void 0:P.find(J=>J.name===e);return(y==null?void 0:y.strategies)&&((Z=y==null?void 0:y.strategies)==null?void 0:Z.length)>0&&((X=y==null?void 0:y.strategies)==null?void 0:X.every(J=>J.disabled))},G=`${f.name}-${e}`;return b(Y,{children:[n(it,{"data-testid":`TOGGLE-${G}`,children:n(Fe,{tooltip:o?`Disable feature in ${e}`:`Enable feature in ${e}`,checked:m,environmentId:e,projectId:t,permission:De,inputProps:{"aria-label":e},onClick:W,disabled:m!==o})},G),O&&n(rt,{isOpen:S,onClose:()=>A(!1),environment:e,disabledStrategiesCount:B,onActivateDisabledStrategies:j,onAddDefaultStrategy:D}),n(Ze,{isOpen:p.isOpen,onClose:c,environment:p==null?void 0:p.environment,onConfirm:u,messageComponent:n(ot,{enabled:p==null?void 0:p.enabled,featureName:p==null?void 0:p.featureName,environment:p.environment})})]})},ct=I(qe)(({theme:t})=>({color:t.palette.warning.main,fontSize:t.fontSizes.bodySize})),xt=()=>n($e,{arrow:!0,title:b(Y,{children:["This environment has no variants enabled. If you check this feature's variants in this environment, you will get the"," ",n("a",{href:"https://docs.getunleash.io/reference/feature-toggle-variants#the-disabled-variant",target:"_blank",rel:"noreferrer",children:"disabled variant"}),"."]}),children:n(ct,{})});var Q={},lt=Le;Object.defineProperty(Q,"__esModule",{value:!0});var he=Q.default=void 0,ut=lt(Be()),dt=Ue,gt=(0,ut.default)((0,dt.jsx)("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-2 10H7v-2h10v2z"}),"IndeterminateCheckBox");he=Q.default=gt;const ht=We(),kt=({options:t,selectedOptions:s,indeterminateOptions:e,tagType:o,existingTags:a,disabled:r=!1,onChange:i})=>{const h=n(je,{fontSize:"small"});return n(de,{multiple:!0,id:"checkboxes-tag",sx:{marginTop:c=>c.spacing(2),width:500},disableCloseOnSelect:!0,placeholder:"Select Values",options:t,value:s,renderTags:(c,u)=>c.map((p,m)=>a.some(v=>v.value===p.title&&v.type===o.name)&&e===void 0?null:n(ze,{...u({index:m}),label:p.title})),isOptionEqualToValue:(c,u)=>u.inputValue&&u.inputValue!==""?c.title===u.inputValue:c.title===u.title,getOptionLabel:c=>c.inputValue?c.inputValue:c.title,renderOption:(c,u,{selected:p})=>{const m=(e==null?void 0:e.some(E=>E.title===u.title))??!1;return b("li",{...c,children:[n(_,{condition:!!u.inputValue,show:n(Ie,{sx:{mr:E=>E.spacing(.5)}}),elseShow:n(Ye,{icon:h,checkedIcon:n(Ve,{fontSize:"small"}),indeterminateIcon:n(he,{fontSize:"small"}),sx:{mr:E=>E.spacing(.5)},checked:p&&!m,indeterminate:m})}),u.title]})},filterOptions:(c,u)=>{const p=ht(c,u),{inputValue:m}=u,E=c.some(v=>m===v.title);return m!==""&&!E&&p.push({inputValue:m,title:`Create new value "${m}"`}),p},ListboxProps:{style:{maxHeight:200,overflow:"auto"}},onChange:i,renderInput:c=>n(ge,{...c,label:"Select values",placeholder:"Select values"}),disabled:r})},pt=I("li")({flexDirection:"column"}),Pt=({options:t,value:s,disabled:e=!1,onChange:o})=>{const a=ne();return n(de,{disablePortal:!0,disabled:e,id:"tag-type-select",sx:{marginTop:r=>r.spacing(2),width:500},options:t,disableClearable:!0,value:s,getOptionLabel:r=>r.name,renderOption:(r,i)=>b(pt,{...r,style:{alignItems:"flex-start",gap:a.spacing(.5)},children:[n(w,{variant:"body1",children:i.name}),n(w,{variant:"caption",children:i.description})]}),renderInput:r=>n(ge,{...r,label:"Tag type",value:s}),onChange:o,ListboxProps:{style:{maxHeight:200,overflow:"auto"}}})},_t=()=>{const{makeRequest:t,createRequest:s,errors:e,loading:o}=Ge({propagateErrors:!0});return{createTag:async i=>{const l=s("api/admin/tags",{method:"POST",body:JSON.stringify(i)});try{return await t(l.caller,l.id)}catch(d){throw d}},bulkUpdateTags:async i=>{const l=s("api/admin/tags/features",{method:"PUT",body:JSON.stringify(i)});try{return await t(l.caller,l.id)}catch(d){throw d}},errors:e,loading:o}},Ot=(t,s={})=>{const e=async()=>{const d=He(`api/admin/tags/${t}`);return(await fetch(d,{method:"GET"}).then(Me("Tags"))).json()},o=`api/admin/tags/${t}`,{data:a,error:r}=Je(!!t,{tags:[]},o,e,s),[i,h]=C.useState(!r&&!a),l=()=>{Ke(o)};return C.useEffect(()=>{h(!r&&!a)},[a,r]),{tags:(a==null?void 0:a.tags)||[],error:r,loading:i,refetch:l}},Ft=({isStale:t,isOpen:s,projectId:e,featureId:o,onClose:a})=>{const{setToastData:r,setToastApiError:i}=$(),{patchFeatureToggle:h}=N(),l=n(w,{children:"Setting a toggle to stale marks it for cleanup"}),d=n(w,{children:"Setting a toggle to active marks it as in active use"}),g=t?"active":"stale",T=async c=>{c.stopPropagation();try{await h(e,o,[{op:"replace",path:"/stale",value:!t}]),a()}catch(u){i(x(u))}r(t?{type:"success",title:"And we're back!",text:"The toggle is no longer marked as stale."}:{type:"success",title:"A job well done.",text:"The toggle has been marked as stale."})};return n(q,{open:s,secondaryButtonText:"Cancel",primaryButtonText:`Flip to ${g}`,title:`Set feature state to ${g}`,onClick:T,onClose:a,children:n(_,{condition:t,show:d,elseShow:l})})},Dt=({isOpen:t,onClose:s,onConfirm:e,projectId:o,featureIds:a})=>{const{archiveFeatureToggle:r}=N(),{archiveFeatures:i}=Ne(),{setToastData:h,setToastApiError:l}=$(),d=(a==null?void 0:a.length)>1;return n(q,{onClick:d?async()=>{try{await i(o,a),h({text:"Selected feature toggles have been archived",type:"success",title:"Feature toggles archived"}),e(),s()}catch(c){l(x(c)),s()}}:async()=>{try{await r(o,a[0]),h({text:"Your feature toggle has been archived",type:"success",title:"Feature archived"}),e(),s()}catch(c){l(x(c)),s()}},open:t,onClose:s,primaryButtonText:d?"Archive toggles":"Archive toggle",secondaryButtonText:"Cancel",title:d?"Archive feature toggles":"Archive feature toggle",children:n(_,{condition:d,show:b(Y,{children:[b("p",{children:["Are you sure you want to archive"," ",n("strong",{children:a==null?void 0:a.length})," feature toggles?"]}),n(_,{condition:(a==null?void 0:a.length)<=5,show:n("ul",{children:a==null?void 0:a.map(c=>n("li",{children:c},c))})})]}),elseShow:n("p",{children:"Are you sure you want to archive these feature toggles?"})})})};export{Ze as C,bt as D,mt as E,wt as F,Ct as R,Pt as T,Tt as U,xt as V,yt as W,Rt as a,Ot as b,kt as c,At as d,Dt as e,tt as f,Ft as g,nt as h,ot as i,Et as j,St as k,vt as l,_t as u};