UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

2 lines (1 loc) 13.6 kB
import{s as c,bc as k,e as D,j as e,V as L,y as M,D as G,fN as S,B as f,dk as z,al as ne,dv as se,ao as oe,C as b,az as re,ap as ae,ay as K,cK as P,bt as ie,eE as le,bh as ce,i_ as de,L as q,eu as ue,ak as A,cc as I,r as d,ev as E,av as he,G as pe,H as xe,aj as $,fr as me,an as N,ei as je,eL as ge,ac as T,ad as fe,cG as V,b3 as ye,aY as Y,h as be,w as ke,aT as Ce,i as Te,aA as Q,gQ as w,hR as Ae,dP as ve,dO as Ee,T as R,e3 as Ne,F as we,fd as Se,e0 as Ie,fe as Re,gP as De,cm as Le,b9 as J,bb as X,ba as Pe,b8 as _e,b4 as Be,dY as Fe}from"./index-BAMIkcom.js";import{u as Oe}from"./useApiTokens-Btk4Hd2u.js";const Ue=c("div")(({theme:t})=>({display:"grid",gridTemplateColumns:"auto auto 1fr",gridAutoRows:"min-content",alignItems:"center",gap:t.spacing(1),marginTop:t.spacing(1.5)})),g=f,He=()=>{const{uiConfig:t}=k(),{setToastData:n}=D(),s=a=>()=>{z(a),n({type:"success",text:"Copied to clipboard"})},o=`${t.unleashUrl}/api/`,r=`${t.unleashUrl}/api/frontend/`;return e.jsxs(L,{severity:"info",children:[e.jsxs("p",{children:["Read the"," ",e.jsx("a",{href:"https://docs.getunleash.io/sdks",target:"_blank",rel:"noreferrer",children:"SDK overview"})," ","to connect Unleash to your application. Please note it can take up to ",e.jsx("strong",{children:"1 minute"})," before a new API key is activated."]}),e.jsxs(Ue,{children:[e.jsx(g,{children:e.jsx("strong",{children:"CLIENT API URL: "})}),e.jsx(g,{children:e.jsx("pre",{style:{display:"inline"},children:o})}),e.jsx(g,{children:e.jsx(M,{title:"Copy URL",arrow:!0,children:e.jsx(G,{onClick:s(o),size:"small",children:e.jsx(S,{})})})}),e.jsx(g,{children:e.jsx("strong",{children:"FRONTEND API URL: "})}),e.jsx(g,{children:e.jsx("pre",{style:{display:"inline"},children:r})}),e.jsx(g,{children:e.jsx(M,{title:"Copy URL",arrow:!0,children:e.jsx(G,{onClick:s(r),size:"small",children:e.jsx(S,{})})})})]})]})},Me=["Icon","createdAt","seenAt"],Ge=["Icon","project","seenAt"],ft=({compact:t=!1,setHiddenColumns:n,columns:s,loading:o,rows:r,headerGroups:a,globalFilter:i,prepareRow:p})=>{const u=ne(se.breakpoints.down("xl"));return oe([{condition:u,columns:Me},{condition:t,columns:Ge}],n,s),e.jsxs(e.Fragment,{children:[e.jsx(b,{condition:r.length>0,show:e.jsx(f,{sx:{mb:4},children:e.jsx(He,{})})}),e.jsx(f,{sx:{overflowX:"auto"},children:e.jsx(re,{value:i,children:e.jsx(ae,{rows:r,headerGroups:a,prepareRow:p})})}),e.jsx(b,{condition:r.length===0&&!o,show:e.jsx(b,{condition:(i==null?void 0:i.length)>0,show:e.jsxs(K,{children:["No tokens found matching “",i,"”"]}),elseShow:e.jsx(K,{children:e.jsxs("span",{children:["No tokens available. Read ",e.jsx(P,{href:"https://docs.getunleash.io/api-overview",target:"_blank",rel:"noreferrer",children:"API How-to guides"})," "," to learn more."]})})})})]})},Ke=(t,n)=>{const s=n>=t;return{limitReached:s,limitMessage:s?`You have reached the limit of ${t} API tokens`:void 0}},yt=({path:t,permission:n,project:s})=>{const o=ie(),{tokens:r,loading:a}=Oe(),{uiConfig:i}=k(),{limitReached:p,limitMessage:u}=Ke(i.resourceLimits.apiTokens,r.length);return e.jsx(le,{Icon:ce,onClick:()=>o(t),"data-testid":de,permission:n,projectId:s,maxWidth:"700px",disabled:a||p,tooltipProps:{title:u},children:"New API token"})},$e=c(q)(({theme:t})=>({textDecoration:"none",color:t.palette.links,"&:hover, &:focus":{textDecoration:"underline"}})),We=c("div")({display:"flex",alignItems:"center"}),ze=({projects:t,project:n})=>{const{searchQuery:s}=ue(),o=t&&Array.isArray(t)&&t.length>1?t:[];if(o.length>0)return e.jsx(A,{children:e.jsx(I,{title:o.map((r,a)=>e.jsxs(d.Fragment,{children:[a>0&&", ",!r||r==="*"?e.jsx(E,{search:s,children:"*"}):e.jsx($e,{to:`/projects/${r}`,children:e.jsx(E,{search:s,children:r})})]},r)),placement:"bottom-start",arrow:!0,tabIndex:0,children:e.jsxs("span",{children:[`${o.length}`," projects"]})})});if(o.length===1&&o[0]!=="*"||n&&n!=="*"){const r=n||o[0];return e.jsx(he,{to:`/projects/${r}`,title:r})}return e.jsx(A,{children:e.jsx(I,{title:"ALL current and future projects.",placement:"bottom",arrow:!0,children:e.jsx(We,{children:e.jsx(E,{search:s,children:"*"})})})})};var _={},qe=xe;Object.defineProperty(_,"__esModule",{value:!0});var Z=_.default=void 0,Ve=qe(pe()),Ye=e,Qe=(0,Ve.default)((0,Ye.jsx)("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");Z=_.default=Qe;const Je=({secret:t,project:n,projects:s})=>{const o=t!=null&&t.includes(":")?"v2":"v1",r=t==null?void 0:t.startsWith("*:"),a=s&&(s==null?void 0:s.length)>1||(s==null?void 0:s.length)===1&&s[0]!=="*"||n&&n!=="*";return o==="v2"&&!r&&!a},Xe=({...t})=>Je(t)?e.jsx($,{icon:e.jsx(I,{title:e.jsxs("p",{children:["This is an orphaned token. All of its original projects have been deleted and it now has access to all current and future projects. You should stop using this token and delete it. Read more in"," ",e.jsx(P,{target:"_blank",rel:"noopener noreferrer",href:"https://github.com/Unleash/unleash/releases/tag/v6.1.0",children:"release notes"}),"."]}),placement:"bottom-start",arrow:!0,children:e.jsx(me,{"aria-label":"Orphaned token",color:"warning","data-testid":"orphaned-token-icon"})})}):e.jsx($,{icon:e.jsx(Z,{color:"disabled"})}),bt=(t,n)=>{const s=d.useMemo(()=>({sortBy:[{id:"createdAt",desc:!0}]}),[]),o=d.useMemo(()=>[{id:"Icon",Cell:h=>e.jsx(Xe,{secret:h.row.original.secret,project:h.row.original.project,projects:h.row.original.projects}),disableSortBy:!0,disableGlobalFilter:!0,width:50},{Header:"Token name",accessor:"tokenName",Cell:N,minWidth:35},{Header:"Type",accessor:"type",Cell:({value:h})=>e.jsx(N,{value:W[h.toLowerCase()].label,subtitle:W[h.toLowerCase()].title,subtitleTooltip:!0}),width:180},{Header:"Project",accessor:"project",Cell:h=>e.jsx(ze,{project:h.row.original.project,projects:h.row.original.projects}),width:160},{Header:"Environment",accessor:"environment",Cell:N,width:120},{Header:"Created",accessor:"createdAt",Cell:je,width:150,disableGlobalFilter:!0},{Header:"Last seen",accessor:"seenAt",Cell:ge,width:140,disableGlobalFilter:!0},{Header:"Actions",width:120,id:"Actions",align:"center",disableSortBy:!0,disableGlobalFilter:!0,Cell:n}],[]),{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:p,prepareRow:u,state:j,setGlobalFilter:m,setHiddenColumns:y}=T.useTable({columns:o,data:t,initialState:s,sortTypes:fe,autoResetHiddenColumns:!1,disableSortRemove:!0},T.useGlobalFilter,T.useSortBy,T.useFlexLayout);return{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:p,prepareRow:u,state:j,setGlobalFilter:m,setHiddenColumns:y,columns:o}},W={client:{label:"BACKEND",title:"Connect backend SDK or Unleash Edge"},backend:{label:"BACKEND",title:"Connect backend SDK or Unleash Edge"},frontend:{label:"FRONTEND",title:"Connect frontend SDK"},admin:{label:"ADMIN",title:"Full access for managing Unleash"}},kt=({token:t,project:n,permission:s,track:o})=>{const{setToastData:r}=D(),a=i=>{z(i)&&(r({type:"success",text:"Token copied to clipboard"}),o&&typeof o=="function"&&o())};return e.jsx(V,{permission:s,projectId:n,tooltipProps:{title:"Copy token",arrow:!0},onClick:()=>a(t.secret),size:"large",children:e.jsx(S,{})})},Ze=c("ul")({marginBottom:0}),Ct=({token:t,permission:n,onRemove:s,project:o})=>{const[r,a]=d.useState(!1),{setToastData:i,setToastApiError:p}=D(),u=async()=>{try{await s(),a(!1),i({type:"success",text:"API token removed"})}catch(j){p(be(j))}};return e.jsxs(e.Fragment,{children:[e.jsx(V,{permission:n,projectId:o,tooltipProps:{title:"Delete token",arrow:!0},onClick:()=>a(!0),size:"large",children:e.jsx(ye,{})}),e.jsx(Y,{open:r,onClick:u,onClose:()=>a(!1),title:"Confirm deletion",children:e.jsxs("div",{children:["Are you sure you want to delete the following API token?",e.jsx("br",{}),e.jsxs(Ze,{children:[e.jsxs("li",{children:[e.jsx("strong",{children:"name"}),":"," ",e.jsx("code",{children:t.tokenName})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"type"}),": ",e.jsx("code",{children:t.type})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"environment"}),":"," ",e.jsx("code",{children:t.environment})]})]})]})})]})},et=c("div")(()=>({maxWidth:"400px"})),tt=c("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),nt=c(ke)(({theme:t})=>({width:"100%",marginBottom:t.spacing(2)})),st=c(Ce)(({theme:t})=>({marginBottom:t.spacing(2),minWidth:"400px",[t.breakpoints.down("sm")]:{minWidth:"379px"}})),ee=c("p")(({theme:t})=>({marginBottom:t.spacing(1)})),ot=c("label")(({theme:t})=>({marginBottom:t.spacing(1)})),rt=c(Te)(({theme:t})=>({marginLeft:t.spacing(3)})),at=c(f)({marginTop:"auto",display:"flex",justifyContent:"flex-end"}),Tt=({children:t,actions:n,handleSubmit:s,handleCancel:o})=>{var i;const{uiConfig:r}=k(),a=!!((i=r==null?void 0:r.flags)!=null&&i.UNLEASH_CLOUD);return e.jsxs(tt,{onSubmit:s,children:[e.jsx(b,{condition:a,show:e.jsxs(L,{severity:"info",sx:{mb:4},children:["Please be aware of our"," ",e.jsx(P,{href:"https://www.getunleash.io/fair-use-policy",children:"fair use policy"}),"."]})}),t,e.jsxs(at,{children:[n,e.jsx(rt,{onClick:o,children:"Cancel"})]})]})};var x=(t=>(t.ADMIN="ADMIN",t.CLIENT="CLIENT",t.FRONTEND="FRONTEND",t))(x||{});const At=t=>{var O,U;const{environments:n}=Q(),s=(O=n==null?void 0:n.find(l=>l.enabled))==null?void 0:O.name,o=w(Ae,t),r=[{key:x.CLIENT,label:"Backend SDK",title:"Creates a backend token to connect a backend SDK or Unleash Edge",enabled:w(ve)||o},{key:x.FRONTEND,label:"Frontend SDK",title:"Creates a frontend token to connect a frontend SDK",enabled:w(Ee)||o}],a=(U=r.find(l=>l.enabled))==null?void 0:U.key,[i,p]=d.useState(""),[u,j]=d.useState(a||x.CLIENT),[m,y]=d.useState([t||"*"]),[h,te]=d.useState(m),[B,C]=d.useState(),[F,v]=d.useState({});return d.useEffect(()=>{C(u==="ADMIN"?"*":s)},[u,s]),{tokenName:i,type:u,apiTokenTypes:r,projects:m,environment:B,setTokenName:p,setTokenType:l=>{l==="ADMIN"?(j(x.ADMIN),te(m),y(["*"]),C("*")):(j(l),y(h),C(s))},setProjects:y,setEnvironment:C,getApiTokenPayload:()=>({tokenName:i,type:u,environment:B,projects:m}),isValid:()=>{const l={};return i||(l.tokenName="Token name is required"),m.length===0&&(l.projects="At least one project is required"),v(l),Object.keys(l).length===0},clearErrors:l=>{if(l){const H={...F};delete H[l],v(H)}else v({})},errors:F}},vt=({open:t,setOpen:n,closeConfirm:s,token:o,type:r})=>e.jsxs(Y,{open:t,setOpen:n,onClick:s,primaryButtonText:"Close",title:"New token created",children:[e.jsx(R,{variant:"body1",children:"Your new token has been created successfully."}),e.jsx(Ne,{token:o}),e.jsx(b,{condition:r===x.FRONTEND,show:e.jsxs(L,{sx:{mt:2},severity:"info",children:["By default, all ",x.FRONTEND," tokens may be used from any CORS origin. If you'd like to configure a strict set of origins, please use the"," ",e.jsx(q,{to:"/admin/cors",target:"_blank",rel:"noreferrer",children:"CORS origins configuration page"}),"."]})})]}),Et=({tokenName:t,setTokenName:n,errors:s,clearErrors:o})=>e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:"What would you like to call this token?"}),e.jsx(nt,{value:t,name:"tokenName",onChange:r=>n(r.target.value),label:"Token name",error:s.tokenName!==void 0,errorText:s.tokenName,onFocus:()=>o("tokenName"),autoFocus:!0})]}),Nt=({type:t,setType:n,apiTokenTypes:s})=>e.jsx(et,{children:e.jsxs(we,{sx:{mb:2,width:"100%"},children:[e.jsx(ot,{id:"token-type",children:"What do you want to connect?"}),e.jsx(Se,{"aria-labelledby":"token-type",defaultValue:"CLIENT",name:"radio-buttons-group",value:t,onChange:(o,r)=>n(r),children:s.map(({key:o,label:r,title:a,enabled:i})=>e.jsx(Ie,{value:o,sx:{mb:1},disabled:!i,control:e.jsx(Re,{sx:{ml:.75,alignSelf:"flex-start"}}),label:e.jsx(f,{children:e.jsxs(f,{children:[e.jsx(R,{children:r}),e.jsx(R,{variant:"body2",color:"text.secondary",children:a})]})})},o))})]})}),wt=({type:t,environment:n,setEnvironment:s})=>{const{environments:o}=Q(),r=t===x.ADMIN?[{key:"*",label:"ALL"}]:o.map(a=>({key:a.name,label:`${a.name.concat(a.enabled?"":" - deprecated")}`,title:a.name,disabled:!1}));return e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:"Which environment should the token have access to?"}),e.jsx(st,{disabled:t===x.ADMIN,options:r,value:n,onChange:s,label:"Environment",id:"api_key_environment",name:"environment",IconComponent:De,fullWidth:!0})]})},it=t=>t.map(n=>({...n.user,joinedAt:new Date(n.joinedAt),createdBy:n.createdBy})),St=t=>{const{data:n,error:s,mutate:o}=Le(J(`api/admin/groups/${t}`),lt);return d.useMemo(()=>({group:n&&{...n,users:it((n==null?void 0:n.users)??[])},loading:!s&&!n,refetchGroup:()=>o(),error:s}),[n,s,o])},lt=t=>fetch(t).then(X("Group")).then(n=>n.json()),It=()=>{const{isEnterprise:t}=k(),{data:n,error:s,mutate:o}=Pe(t(),{serviceAccounts:[],rootRoles:[]},J("api/admin/service-account"),ct);return d.useMemo(()=>({serviceAccounts:(n==null?void 0:n.serviceAccounts)??[],roles:(n==null?void 0:n.rootRoles)??[],loading:!s&&!n,refetch:()=>o(),error:s}),[n,s,o])},ct=t=>fetch(t).then(X("Service Accounts")).then(n=>n.json()),dt=c("div")(({theme:t})=>({display:"flex",flexDirection:"column",gap:t.spacing(.5),"& > *:not(:last-child)":{borderBottom:`1px solid ${t.palette.divider}`,paddingBottom:t.spacing(1)}})),ut=c(_e)(()=>({display:"block"})),Rt=({role:t,roles:n,value:s})=>{const{isEnterprise:o}=k();if(o()){const r=n||[t];return e.jsx(A,{children:e.jsx(Be,{tooltip:e.jsx(dt,{children:r.map(a=>e.jsx(Fe,{roleId:a,tooltip:!0},a))}),children:e.jsx(ut,{children:s})})})}return e.jsx(A,{children:s})};export{ft as A,yt as C,wt as E,Ct as R,ee as S,x as T,kt as a,At as b,Tt as c,Et as d,Nt as e,vt as f,It as g,St as h,Rt as i,Z as j,it as m,bt as u};