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 T,e as D,j as e,V as L,y as H,D as $,fF as I,B as f,du as z,al as se,dd as ne,ao as oe,C as b,az as re,ap as ae,ay as G,c0 as P,bt as ie,ew as le,bh as ce,iL as de,L as q,em as ue,ak as v,g4 as S,r as d,en as w,av as he,G as pe,H as xe,aj as W,fl as me,an as E,ec as je,eF as ge,ac as k,ad as fe,cB as V,b3 as ye,aY as Y,h as be,w as Te,aT as Ce,i as ke,aA as J,iM as N,hG as ve,dJ as Ae,dI as we,T as R,dZ as Ee,F as Ne,f7 as Ie,dW as Se,f8 as Re,gJ as De,ch as Le,b9 as Q,bb as X,ba as Pe,b8 as _e,b4 as Be,dS as Fe}from"./index-CBxzHo9v.js";import{u as Oe}from"./useApiTokens-CUb6SDEP.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,Me=()=>{const{uiConfig:t}=T(),{setToastData:s}=D(),n=a=>()=>{z(a),s({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/reference/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(H,{title:"Copy URL",arrow:!0,children:e.jsx($,{onClick:n(o),size:"small",children:e.jsx(I,{})})})}),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(H,{title:"Copy URL",arrow:!0,children:e.jsx($,{onClick:n(r),size:"small",children:e.jsx(I,{})})})})]})]})},He=["Icon","createdAt","seenAt"],$e=["Icon","project","seenAt"],ft=({compact:t=!1,setHiddenColumns:s,columns:n,loading:o,rows:r,headerGroups:a,globalFilter:i,prepareRow:x})=>{const u=se(ne.breakpoints.down("xl"));return oe([{condition:u,columns:He},{condition:t,columns:$e}],s,n),e.jsxs(e.Fragment,{children:[e.jsx(b,{condition:r.length>0,show:e.jsx(f,{sx:{mb:4},children:e.jsx(Me,{})})}),e.jsx(f,{sx:{overflowX:"auto"},children:e.jsx(re,{value:i,children:e.jsx(ae,{rows:r,headerGroups:a,prepareRow:x})})}),e.jsx(b,{condition:r.length===0&&!o,show:e.jsx(b,{condition:(i==null?void 0:i.length)>0,show:e.jsxs(G,{children:["No tokens found matching “",i,"”"]}),elseShow:e.jsx(G,{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."]})})})})]})},Ge=(t,s)=>{const n=s>=t;return{limitReached:n,limitMessage:n?`You have reached the limit of ${t} API tokens`:void 0}},yt=({path:t,permission:s,project:n})=>{const o=ie(),{tokens:r,loading:a}=Oe(),{uiConfig:i}=T(),{limitReached:x,limitMessage:u}=Ge(i.resourceLimits.apiTokens,r.length);return e.jsx(le,{Icon:ce,onClick:()=>o(t),"data-testid":de,permission:s,projectId:n,maxWidth:"700px",disabled:a||x,tooltipProps:{title:u},children:"New API token"})},We=c(q)(({theme:t})=>({textDecoration:"none",color:t.palette.links,"&:hover, &:focus":{textDecoration:"underline"}})),Ke=c("div")({display:"flex",alignItems:"center"}),ze=({projects:t,project:s})=>{const{searchQuery:n}=ue(),o=t&&Array.isArray(t)&&t.length>1?t:[];if(o.length>0)return e.jsx(v,{children:e.jsx(S,{title:o.map((r,a)=>e.jsxs(d.Fragment,{children:[a>0&&", ",!r||r==="*"?e.jsx(w,{search:n,children:"*"}):e.jsx(We,{to:`/projects/${r}`,children:e.jsx(w,{search:n,children:r})})]},r)),placement:"bottom-start",arrow:!0,tabIndex:0,children:e.jsxs("span",{children:[`${o.length}`," projects"]})})});if(o.length===1&&o[0]!=="*"||s&&s!=="*"){const r=s||o[0];return e.jsx(he,{to:`/projects/${r}`,title:r})}return e.jsx(v,{children:e.jsx(S,{title:"ALL current and future projects.",placement:"bottom",arrow:!0,children:e.jsx(Ke,{children:e.jsx(w,{search:n,children:"*"})})})})};var _={},qe=xe;Object.defineProperty(_,"__esModule",{value:!0});var Z=_.default=void 0,Ve=qe(pe()),Ye=e,Je=(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=Je;const Qe=({secret:t,project:s,projects:n})=>{const o=t!=null&&t.includes(":")?"v2":"v1",r=t==null?void 0:t.startsWith("*:"),a=n&&(n==null?void 0:n.length)>1||(n==null?void 0:n.length)===1&&n[0]!=="*"||s&&s!=="*";return o==="v2"&&!r&&!a},Xe=({...t})=>Qe(t)?e.jsx(W,{icon:e.jsx(S,{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(W,{icon:e.jsx(Z,{color:"disabled"})}),bt=(t,s)=>{const n=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:E,minWidth:35},{Header:"Type",accessor:"type",Cell:({value:h})=>e.jsx(E,{value:K[h.toLowerCase()].label,subtitle:K[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:E,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:s}],[]),{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:x,prepareRow:u,state:j,setGlobalFilter:m,setHiddenColumns:y}=k.useTable({columns:o,data:t,initialState:n,sortTypes:fe,autoResetHiddenColumns:!1,disableSortRemove:!0},k.useGlobalFilter,k.useSortBy,k.useFlexLayout);return{getTableProps:r,getTableBodyProps:a,headerGroups:i,rows:x,prepareRow:u,state:j,setGlobalFilter:m,setHiddenColumns:y,columns:o}},K={client:{label:"CLIENT",title:"Connect server-side SDK or Unleash Proxy/Edge"},frontend:{label:"FRONTEND",title:"Connect web and mobile SDK"},admin:{label:"ADMIN",title:"Full access for managing Unleash"}},Tt=({token:t,project:s,permission:n,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:n,projectId:s,tooltipProps:{title:"Copy token",arrow:!0},onClick:()=>a(t.secret),size:"large",children:e.jsx(I,{})})},Ze=c("ul")({marginBottom:0}),Ct=({token:t,permission:s,onRemove:n,project:o})=>{const[r,a]=d.useState(!1),{setToastData:i,setToastApiError:x}=D(),u=async()=>{try{await n(),a(!1),i({type:"success",text:"API token removed"})}catch(j){x(be(j))}};return e.jsxs(e.Fragment,{children:[e.jsx(V,{permission:s,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%"})),st=c(Te)(({theme:t})=>({width:"100%",marginBottom:t.spacing(2)})),nt=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(ke)(({theme:t})=>({marginLeft:t.spacing(3)})),at=c(f)({marginTop:"auto",display:"flex",justifyContent:"flex-end"}),kt=({children:t,actions:s,handleSubmit:n,handleCancel:o})=>{var i;const{uiConfig:r}=T(),a=!!((i=r==null?void 0:r.flags)!=null&&i.UNLEASH_CLOUD);return e.jsxs(tt,{onSubmit:n,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:[s,e.jsx(rt,{onClick:o,children:"Cancel"})]})]})};var p=(t=>(t.ADMIN="ADMIN",t.CLIENT="CLIENT",t.FRONTEND="FRONTEND",t))(p||{});const vt=t=>{var O,U;const{environments:s}=J(),n=(O=s==null?void 0:s.find(l=>l.enabled))==null?void 0:O.name,o=N(ve,t),r=[{key:p.CLIENT,label:`Server-side SDK (${p.CLIENT})`,title:"Connect server-side SDK or Unleash Proxy/Edge",enabled:N(Ae)||o},{key:p.FRONTEND,label:`Client-side SDK (${p.FRONTEND})`,title:"Connect web and mobile SDK directly to Unleash",enabled:N(we)||o}],a=(U=r.find(l=>l.enabled))==null?void 0:U.key,[i,x]=d.useState(""),[u,j]=d.useState(a||p.CLIENT),[m,y]=d.useState([t||"*"]),[h,te]=d.useState(m),[B,C]=d.useState(),[F,A]=d.useState({});return d.useEffect(()=>{C(u==="ADMIN"?"*":n)},[u,n]),{tokenName:i,type:u,apiTokenTypes:r,projects:m,environment:B,setTokenName:x,setTokenType:l=>{l==="ADMIN"?(j(p.ADMIN),te(m),y(["*"]),C("*")):(j(l),y(h),C(n))},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"),A(l),Object.keys(l).length===0},clearErrors:l=>{if(l){const M={...F};delete M[l],A(M)}else A({})},errors:F}},At=({open:t,setOpen:s,closeConfirm:n,token:o,type:r})=>e.jsxs(Y,{open:t,setOpen:s,onClick:n,primaryButtonText:"Close",title:"New token created",children:[e.jsx(R,{variant:"body1",children:"Your new token has been created successfully."}),e.jsx(Ee,{token:o}),e.jsx(b,{condition:r===p.FRONTEND,show:e.jsxs(L,{sx:{mt:2},severity:"info",children:["By default, all ",p.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"}),"."]})})]}),wt=({tokenName:t,setTokenName:s,errors:n,clearErrors:o})=>e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:"What would you like to call this token?"}),e.jsx(st,{value:t,name:"tokenName",onChange:r=>s(r.target.value),label:"Token name",error:n.tokenName!==void 0,errorText:n.tokenName,onFocus:()=>o("tokenName"),autoFocus:!0})]}),Et=({type:t,setType:s,apiTokenTypes:n})=>e.jsx(et,{children:e.jsxs(Ne,{sx:{mb:2,width:"100%"},children:[e.jsx(ot,{id:"token-type",children:"What do you want to connect?"}),e.jsx(Ie,{"aria-labelledby":"token-type",defaultValue:"CLIENT",name:"radio-buttons-group",value:t,onChange:(o,r)=>s(r),children:n.map(({key:o,label:r,title:a,enabled:i})=>e.jsx(Se,{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))})]})}),Nt=({type:t,environment:s,setEnvironment:n})=>{const{environments:o}=J(),r=t===p.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(nt,{disabled:t===p.ADMIN,options:r,value:s,onChange:n,label:"Environment",id:"api_key_environment",name:"environment",IconComponent:De,fullWidth:!0})]})},it=t=>t.map(s=>({...s.user,joinedAt:new Date(s.joinedAt),createdBy:s.createdBy})),It=t=>{const{data:s,error:n,mutate:o}=Le(Q(`api/admin/groups/${t}`),lt);return d.useMemo(()=>({group:s&&{...s,users:it((s==null?void 0:s.users)??[])},loading:!n&&!s,refetchGroup:()=>o(),error:n}),[s,n,o])},lt=t=>fetch(t).then(X("Group")).then(s=>s.json()),St=()=>{const{isEnterprise:t}=T(),{data:s,error:n,mutate:o}=Pe(t(),{serviceAccounts:[],rootRoles:[]},Q("api/admin/service-account"),ct);return d.useMemo(()=>({serviceAccounts:(s==null?void 0:s.serviceAccounts)??[],roles:(s==null?void 0:s.rootRoles)??[],loading:!n&&!s,refetch:()=>o(),error:n}),[s,n,o])},ct=t=>fetch(t).then(X("Service Accounts")).then(s=>s.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:s,value:n})=>{const{isEnterprise:o}=T();if(o()){const r=s||[t];return e.jsx(v,{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:n})})})}return e.jsx(v,{children:n})};export{ft as A,yt as C,Nt as E,Ct as R,ee as S,p as T,Tt as a,vt as b,kt as c,wt as d,Et as e,At as f,St as g,It as h,Rt as i,Z as j,it as m,bt as u};