UNPKG

unleash-server

Version:

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

1 lines 5.22 kB
import{n as e,s as t,t as n}from"./jsx-runtime-ButemYzH.js";import{_ as r,a as i,g as a,h as o,i as s,o as c,u as l}from"./chart-BMc0j_v5.js";import{$l as u,Ac as d,Al as f,Nl as p,Nu as m,Ol as h,Ri as g,Us as _,Wa as v,Xd as y,Xs as b,id as x,jt as S,kc as C,xd as w}from"./index-B0RbDPtk.js";import{d as T,s as E}from"./useInstanceTrafficMetrics--5pof2Er.js";import{a as D,c as O,i as k,l as A,n as j,r as M,t as N,u as P}from"./networkTrafficUsageHighlightPlugin-ecHJHisK.js";import{t as F}from"./chartjs-plugin-annotation.esm-CII-nIyK.js";var I=n(),L=w(`article`)(({theme:e})=>({minWidth:`200px`,border:`2px solid ${e.palette.divider}`,borderRadius:e.shape.borderRadiusLarge,padding:e.spacing(3),display:`flex`,flexDirection:`column`,gap:e.spacing(2)})),R=w(`h3`)(({theme:e})=>({margin:0,fontSize:e.typography.body1.fontSize})),z=w(`dl`)(({theme:e})=>({display:`flex`,flexDirection:`column`,gap:e.spacing(2.5),padding:0,margin:0})),B=w(`div`)(({theme:e})=>({display:`flex`,flexFlow:`row wrap`,justifyContent:`space-between`,gap:e.spacing(1,3),fontSize:e.typography.body2.fontSize,color:e.palette.text.secondary,"& dd":{margin:0,color:e.palette.text.primary}})),V=e=>{let t=e=>e.toLocaleString(`en-US`,{month:`short`,year:`numeric`});if(e.grouping===`monthly`){let n=new Date,r=p(n,e.monthsBack),i=p(n,1);return`Average requests from ${t(r)} to ${t(i)}`}return`Requests used in ${t(T(e.month))}`},H=({period:e,usageTotal:t,includedTraffic:n,purchasedTraffic:r,currentMonth:i})=>{let{locationSettings:a}=b();return(0,I.jsxs)(L,{children:[(0,I.jsx)(R,{children:`Number of requests to Unleash`}),(0,I.jsxs)(z,{children:[(0,I.jsxs)(B,{children:[(0,I.jsx)(`dt`,{children:V(e)}),(0,I.jsx)(`dd`,{children:(0,I.jsxs)(v,{color:n>0?t<=n?`success`:`error`:`neutral`,children:[t.toLocaleString(a.locale??`en-US`),` `,`requests`]})})]}),n>0&&(0,I.jsxs)(B,{children:[(0,I.jsx)(`dt`,{children:`Included in your plan`}),(0,I.jsxs)(`dd`,{children:[n.toLocaleString(`en-US`),` requests`]})]}),r>0&&i&&(0,I.jsxs)(B,{children:[(0,I.jsx)(`dt`,{children:`Additional traffic purchased`}),(0,I.jsxs)(`dd`,{children:[r.toLocaleString(`en-US`),` requests`]})]}),n>0&&i&&(0,I.jsxs)(B,{children:[(0,I.jsx)(`dt`,{children:`Total traffic available`}),(0,I.jsxs)(`dd`,{children:[(n+r).toLocaleString(`en-US`),` `,`requests`]})]})]})]})},U=({overages:e,overageCost:t,estimatedMonthlyCost:n})=>(0,I.jsxs)(L,{children:[(0,I.jsx)(R,{children:`Accrued traffic charges`}),(0,I.jsxs)(z,{children:[(0,I.jsxs)(B,{children:[(0,I.jsxs)(`dt`,{children:[`Request overages this month (`,(0,I.jsx)(m,{href:`https://www.getunleash.io/pricing`,children:`pricing`}),`)`]}),(0,I.jsxs)(`dd`,{children:[e.toLocaleString(),` requests`]})]}),(0,I.jsxs)(B,{children:[(0,I.jsx)(`dt`,{children:`Accrued traffic charges`}),(0,I.jsx)(`dd`,{children:(0,I.jsxs)(v,{color:`secondary`,children:[t,` USD`]})})]}),n>0&&(0,I.jsxs)(B,{children:[(0,I.jsx)(`dt`,{children:`Estimated charges based on current usage`}),(0,I.jsx)(`dd`,{children:(0,I.jsxs)(v,{color:`secondary`,children:[n,` USD`]})})]})]})]}),W=t(e(),1),G=53,K=259,q=1e6,J=(e,t)=>!e||t===`pay-as-you-go`?G:K;function Y(e,t,n){return e===void 0?J(t,n):e}function X(e){return e===void 0?0:e}var Z=()=>{let{isEnterprise:e,uiConfig:t}=C(),{data:n,error:r,mutate:i}=f(h(`/api/instance/trafficBundles`),Q);return{trafficBundles:(0,W.useMemo)(()=>({includedTraffic:Y(n?.includedTraffic,e(),t.billing)*q,purchasedTraffic:X(n?.purchasedTraffic)*q}),[n]),loading:!r&&!n,refetch:i}},Q=e=>fetch(e).then(d(`configuration`)).then(e=>e.json()),$=w(`div`)(({theme:e})=>({display:`grid`,gridTemplateColumns:`repeat(auto-fit, minmax(200px, max-content))`,flex:1,gap:e.spacing(2,4)})),ee=()=>{_(`Network - Data Usage`);let e=g(`estimateTrafficDataCost`),{isOss:t}=C(),{trafficBundles:n}=Z(),r=n.includedTraffic+n.purchasedTraffic,{chartDataSelection:i,setChartDataSelection:a,options:o}=j(r),{chartData:s,usageTotal:c,overageCost:l,estimatedMonthlyCost:d,requestSummaryUsage:f}=O(r,i),p=i.grouping===`daily`&&i.month===E&&r>0&&c-r>0&&e,m=i.grouping===`daily`&&i.month===E,h=(i.grouping===`monthly`||i.month===E)&&r>0&&l>0;return(0,I.jsx)(u,{condition:t(),show:(0,I.jsx)(x,{severity:`warning`,children:`Not enabled.`}),elseShow:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(u,{condition:h,show:(0,I.jsxs)(x,{severity:`warning`,sx:{mb:4},children:[(0,I.jsx)(M,{children:`Heads up!`}),` You are currently consuming more requests than your plan includes and will be billed according to our terms. Please see`,` `,(0,I.jsx)(y,{to:`https://www.getunleash.io/pricing`,children:`this page`}),` `,`for more information. In order to reduce your traffic consumption, you may configure an`,` `,(0,I.jsx)(y,{to:`https://docs.getunleash.io/unleash-edge`,children:`Unleash Edge instance`}),` `,`in your own datacenter.`]})}),(0,I.jsxs)(k,{children:[(0,I.jsxs)(D,{children:[(0,I.jsxs)($,{children:[(0,I.jsx)(H,{period:i,usageTotal:f,includedTraffic:n.includedTraffic,purchasedTraffic:n.purchasedTraffic,currentMonth:m}),p&&(0,I.jsx)(U,{overageCost:l,overages:c-r,estimatedMonthlyCost:d})]}),(0,I.jsx)(P,{selectedPeriod:i,setPeriod:a})]}),(0,I.jsx)(S,{data:s,plugins:[N],options:o,"aria-label":A(i)})]})]})})};c.register(F,i,l,s,a,r,o);export{ee as default};