UNPKG

unleash-server

Version:

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

2 lines (1 loc) 5.05 kB
import{s as c,bs as E,j as e,N as d,c0 as v,js as f,bc as y,b9 as B,ch as q,r as A,bb as I,cT as F,c1 as _,C as p,V as x,L as j,j4 as P,iZ as M,i_ as N,i$ as $,j0 as k,j1 as z,j2 as H,j3 as O}from"./index-CBxzHo9v.js";import{a as W}from"./formatTickValue-UVMjaxYs.js";import{u as Y,a as G,B as V,S as Z,T as J,P as K,c as Q,g as X}from"./useChartDataSelection-oJZtWCYi.js";import{p as ee,c as l}from"./LazyAdminExport-B8NZvb6Q.js";import"./RoleCell-C2bUEPUX.js";import"./useApiTokens-CUb6SDEP.js";const S=c("article")(({theme:s})=>({minWidth:"200px",border:`2px solid ${s.palette.divider}`,borderRadius:s.shape.borderRadiusLarge,padding:s.spacing(3),display:"flex",flexDirection:"column",gap:s.spacing(2)})),T=c("h3")(({theme:s})=>({margin:0,fontSize:s.typography.body1.fontSize})),w=c("dl")(({theme:s})=>({display:"flex",flexDirection:"column",gap:s.spacing(2.5),padding:0,margin:0})),a=c("div")(({theme:s})=>({display:"flex",flexFlow:"row wrap",justifyContent:"space-between",gap:s.spacing(1,3),fontSize:s.typography.body2.fontSize,color:s.palette.text.secondary,"& dd":{margin:0,color:s.palette.text.primary}})),se=s=>{const r=t=>t.toLocaleString("en-US",{month:"short",year:"numeric"});if(s.grouping==="monthly"){const t=new Date,n=f(t,s.monthsBack),o=f(t,1);return`Average requests from ${r(n)} to ${r(o)}`}return`Requests used in ${r(ee(s.month))}`},te=({period:s,usageTotal:r,includedTraffic:t,purchasedTraffic:n,currentMonth:o})=>{const{locationSettings:i}=E();return e.jsxs(S,{children:[e.jsx(T,{children:"Number of requests to Unleash"}),e.jsxs(w,{children:[e.jsxs(a,{children:[e.jsx("dt",{children:se(s)}),e.jsx("dd",{children:e.jsxs(d,{color:t>0?r<=t?"success":"error":"neutral",children:[r.toLocaleString(i.locale??"en-US")," ","requests"]})})]}),t>0&&e.jsxs(a,{children:[e.jsx("dt",{children:"Included in your plan"}),e.jsxs("dd",{children:[t.toLocaleString("en-US")," requests"]})]}),n>0&&o&&e.jsxs(a,{children:[e.jsx("dt",{children:"Additional traffic purchased"}),e.jsxs("dd",{children:[n.toLocaleString("en-US")," requests"]})]}),t>0&&o&&e.jsxs(a,{children:[e.jsx("dt",{children:"Total traffic available"}),e.jsxs("dd",{children:[(t+n).toLocaleString("en-US")," ","requests"]})]})]})]})},ne=({overages:s,overageCost:r,estimatedMonthlyCost:t})=>e.jsxs(S,{children:[e.jsx(T,{children:"Accrued traffic charges"}),e.jsxs(w,{children:[e.jsxs(a,{children:[e.jsxs("dt",{children:["Request overages this month (",e.jsx(v,{href:"https://www.getunleash.io/pricing",children:"pricing"}),")"]}),e.jsxs("dd",{children:[s.toLocaleString()," requests"]})]}),e.jsxs(a,{children:[e.jsx("dt",{children:"Accrued traffic charges"}),e.jsx("dd",{children:e.jsxs(d,{color:"secondary",children:[r," USD"]})})]}),t>0&&e.jsxs(a,{children:[e.jsx("dt",{children:"Estimated charges based on current usage"}),e.jsx("dd",{children:e.jsxs(d,{color:"secondary",children:[t," USD"]})})]})]})]}),re=53,oe=259,m=1e6,ae=(s,r)=>!s||r==="pay-as-you-go"?re:oe;function ie(s,r,t){return s===void 0?ae(r,t):s}function ce(s){return s===void 0?0:s}const le=()=>{const{isEnterprise:s,uiConfig:r}=y(),t=B("/api/instance/trafficBundles"),{data:n,error:o,mutate:i}=q(t,de);return{trafficBundles:A.useMemo(()=>({includedTraffic:ie(n==null?void 0:n.includedTraffic,s(),r.billing)*m,purchasedTraffic:ce(n==null?void 0:n.purchasedTraffic)*m}),[n]),loading:!o&&!n,refetch:i}},de=s=>fetch(s).then(I("configuration")).then(r=>r.json()),ue=c("div")(({theme:s})=>({display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, max-content))",flex:1,gap:s.spacing(2,4)})),me=()=>{F("Network - Data Usage");const s=_("estimateTrafficDataCost"),{isOss:r}=y(),{trafficBundles:t}=le(),n=t.includedTraffic+t.purchasedTraffic,{chartDataSelection:o,setChartDataSelection:i,options:u}=Y(n),{chartData:C,usageTotal:h,overageCost:g,estimatedMonthlyCost:b,requestSummaryUsage:L}=G(n,o),U=o.grouping==="daily"&&o.month===l&&n>0&&h-n>0&&s,D=o.grouping==="daily"&&o.month===l,R=(o.grouping==="monthly"||o.month===l)&&n>0&&g>0;return e.jsx(p,{condition:r(),show:e.jsx(x,{severity:"warning",children:"Not enabled."}),elseShow:e.jsxs(e.Fragment,{children:[e.jsx(p,{condition:R,show:e.jsxs(x,{severity:"warning",sx:{mb:4},children:[e.jsx(V,{children:"Heads up!"})," You are currently consuming more requests than your plan includes and will be billed according to our terms. Please see"," ",e.jsx(j,{to:"https://www.getunleash.io/pricing",children:"this page"})," ","for more information. In order to reduce your traffic consumption, you may configure an"," ",e.jsx(j,{to:"https://docs.getunleash.io/reference/unleash-edge",children:"Unleash Edge instance"})," ","in your own datacenter."]})}),e.jsxs(Z,{children:[e.jsxs(J,{children:[e.jsxs(ue,{children:[e.jsx(te,{period:o,usageTotal:L,includedTraffic:t.includedTraffic,purchasedTraffic:t.purchasedTraffic,currentMonth:D}),U&&e.jsx(ne,{overageCost:g,overages:h-n,estimatedMonthlyCost:b})]}),e.jsx(K,{selectedPeriod:o,setPeriod:i})]}),e.jsx(P,{data:C,plugins:[Q()],options:u,"aria-label":X(o)})]})]})})};M.register(W,N,$,k,z,H,O);export{me as default};