@kong-ui-public/analytics-metric-provider 1.1.15 → 1.1.17

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.
@@ -1,2 +1,2 @@
1
- (function(R,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue"),require("@kong-ui-public/i18n")):typeof define=="function"&&define.amd?define(["exports","vue","@kong-ui-public/i18n"],o):(R=typeof globalThis<"u"?globalThis:R||self,o(R["kong-ui-public-vitals-metric-provider"]={},R.Vue,R["kong-ui-public-i18n"]))})(this,function(R,o,de){"use strict";var Ue=Object.defineProperty,Ve=(e,t,r)=>t in e?Ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,C=(e,t,r)=>(Ve(e,typeof t!="symbol"?t+"":t,r),r),y=(e=>(e.MINUTELY="Minutely",e.HOURLY="Hourly",e.DAILY="Daily",e.WEEKLY="Weekly",e))(y||{}),T=(e=>(e.FIFTEEN_MIN="15m",e.ONE_HOUR="1h",e.SIX_HOUR="6h",e.TWELVE_HOUR="12h",e.ONE_DAY="24h",e.SEVEN_DAY="7d",e.THIRTY_DAY="30d",e.CURRENT_WEEK="current_week",e.CURRENT_MONTH="current_month",e.CURRENT_QUARTER="current_quarter",e.PREVIOUS_WEEK="previous_week",e.PREVIOUS_MONTH="previous_month",e.PREVIOUS_QUARTER="previous_quarter",e))(T||{});const fe={[y.MINUTELY]:60*1e3,[y.HOURLY]:60*60*1e3,[y.DAILY]:60*60*24*1e3,[y.WEEKLY]:60*60*24*7*1e3};function Pe(e,t){return e?{duration:e,type:"duration",origin:t}:null}function me(e,t,r){const i=fe[r],a=i>=fe[y.DAILY]?t.getTimezoneOffset()*60*1e3:0;return new Date(e((t.getTime()-a)/i)*i+a)}function he(e,t){return me(Math.floor,e,t)}function Ye(e,t){return me(Math.ceil,e,t)}function G(e){"@babel/helpers - typeof";return G=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},G(e)}function _(e){if(e===null||e===!0||e===!1)return NaN;var t=Number(e);return isNaN(t)?t:t<0?Math.ceil(t):Math.floor(t)}function w(e,t){if(t.length<e)throw new TypeError(e+" argument"+(e>1?"s":"")+" required, but only "+t.length+" present")}function L(e){w(1,arguments);var t=Object.prototype.toString.call(e);return e instanceof Date||G(e)==="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):((typeof e=="string"||t==="[object String]")&&typeof console<"u"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function Q(e,t){w(2,arguments);var r=L(e),i=_(t);return isNaN(i)?new Date(NaN):(i&&r.setDate(r.getDate()+i),r)}function Fe(e,t){w(2,arguments);var r=L(e),i=_(t);if(isNaN(i))return new Date(NaN);if(!i)return r;var a=r.getDate(),n=new Date(r.getTime());n.setMonth(r.getMonth()+i+1,0);var l=n.getDate();return a>=l?n:(r.setFullYear(n.getFullYear(),n.getMonth(),a),r)}var xe={};function Be(){return xe}function z(e,t){var r,i,a,n,l,f,d,s;w(1,arguments);var u=Be(),c=_((r=(i=(a=(n=t==null?void 0:t.weekStartsOn)!==null&&n!==void 0?n:t==null||(l=t.locale)===null||l===void 0||(f=l.options)===null||f===void 0?void 0:f.weekStartsOn)!==null&&a!==void 0?a:u.weekStartsOn)!==null&&i!==void 0?i:(d=u.locale)===null||d===void 0||(s=d.options)===null||s===void 0?void 0:s.weekStartsOn)!==null&&r!==void 0?r:0);if(!(c>=0&&c<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var m=L(e),h=m.getDay(),p=(h<c?7:0)+h-c;return m.setDate(m.getDate()-p),m.setHours(0,0,0,0),m}function ye(e){w(1,arguments);var t=L(e);return t.setHours(0,0,0,0),t}var He=60,$e=3600;function V(e){w(1,arguments);var t=L(e);return t.setDate(1),t.setHours(0,0,0,0),t}function Ge(e){w(1,arguments);var t=L(e),r=t.getFullYear(),i=t.getMonth(),a=new Date(0);return a.setFullYear(r,i+1,0),a.setHours(0,0,0,0),a.getDate()}function Z(e){w(1,arguments);var t=L(e),r=t.getTime();return r}function pe(e){return w(1,arguments),Math.floor(Z(e)/1e3)}function ze(e){return w(1,arguments),Math.floor(e*$e)}function Ke(e,t){w(2,arguments);var r=_(t);return Q(e,-r)}function qe(e){w(1,arguments);var t=e/He;return Math.floor(t)}function ge(e,t){w(2,arguments);var r=_(t);return Fe(e,-r)}function je(e,t){if(w(2,arguments),!t||G(t)!=="object")return new Date(NaN);var r=t.years?_(t.years):0,i=t.months?_(t.months):0,a=t.weeks?_(t.weeks):0,n=t.days?_(t.days):0,l=t.hours?_(t.hours):0,f=t.minutes?_(t.minutes):0,d=t.seconds?_(t.seconds):0,s=ge(e,i+r*12),u=Ke(s,n+a*7),c=f+l*60,m=d+c*60,h=m*1e3,p=new Date(u.getTime()-h);return p}class J{constructor(t){if(C(this,"timeframe"),this.constructor===J)throw new Error("BaseQueryTime is not meant to be used directly.");this.timeframe=t}calculateStartDate(t,r,i=1){if(t)return new Date(this.endDate().getTime()-this.timeframe.timeframeLengthMs()*i);{const a=this.endDate(),n=he(this.timeframe.rawStart(),r),l=(a.getTime()-n.getTime())*(i-1);return he(new Date(this.timeframe.rawStart().getTime()-l),r)}}granularitySeconds(){return Math.floor(this.granularityMs()/1e3)}granularityDruid(){return Pe(this.granularityMs(),this.startDate().toISOString())}startSeconds(){return pe(this.startDate())}endSeconds(){return pe(this.endDate())}startMs(){return Z(this.startDate())}endMs(){return Z(this.endDate())}withinFreeTier(){return this.startDate()>=je(new Date,{days:1})}}let ve=class extends J{startDate(){return this.calculateStartDate(this.timeframe.isRelative,this.timeframe.dataGranularity)}endDate(){return Ye(this.timeframe.rawEnd(),this.timeframe.dataGranularity)}granularityMs(){return this.endDate().getTime()-this.startDate().getTime()}},We=class extends ve{startDate(){return this.calculateStartDate(this.timeframe.isRelative,this.timeframe.dataGranularity,2)}granularityMs(){return this.endDate().getTime()-super.startDate().getTime()}};class I{constructor(t){C(this,"timeframeText"),C(this,"key"),C(this,"display"),C(this,"timeframeLength"),C(this,"allowedTiers"),C(this,"defaultResponseGranularity"),C(this,"dataGranularity"),C(this,"isRelative"),C(this,"_startCustom"),C(this,"_endCustom"),this.display=t.display,this.timeframeText=t.timeframeText,this.key=t.key,this.timeframeLength=t.timeframeLength,this.allowedTiers=t.allowedTiers,this.defaultResponseGranularity=t.defaultResponseGranularity,this.dataGranularity=t.dataGranularity,this.isRelative=t.isRelative,this._startCustom=t.startCustom,this._endCustom=t.endCustom}rawEnd(){return this._endCustom||new Date}rawStart(){return this._startCustom||new Date(this.rawEnd().getTime()-this.timeframeLengthMs())}timeframeLengthMs(){return this.timeframeLength()*1e3}maximumTimeframeLength(){return this.timeframeLength()}allowedGranularities(){const t=new Set,r=this.maximumTimeframeLength()/3600;return r<=6&&t.add(y.MINUTELY),r>=2&&r<=7*24&&t.add(y.HOURLY),r>=2*24&&t.add(y.DAILY),r>=2*24*14&&t.add(y.WEEKLY),t}}class Qe extends I{rawStart(){return z(new Date,{weekStartsOn:1})}maximumTimeframeLength(){return 60*60*24*7}}let Ze=class extends I{rawStart(){return V(new Date)}maximumTimeframeLength(){return 60*60*24*31}},Je=class extends I{rawEnd(){return z(new Date,{weekStartsOn:1})}rawStart(){return z(new Date().setDate(new Date().getDate()-7),{weekStartsOn:1})}},Xe=class extends I{rawEnd(){return V(new Date)}rawStart(){return V(new Date().setMonth(new Date().getMonth()-1))}};const Te=new Map([[T.FIFTEEN_MIN,new I({key:T.FIFTEEN_MIN,display:"Last 15 minutes",timeframeText:"15 minutes",timeframeLength:()=>60*15,defaultResponseGranularity:y.MINUTELY,dataGranularity:y.MINUTELY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[T.ONE_HOUR,new I({key:T.ONE_HOUR,display:"Last hour",timeframeText:"One hour",timeframeLength:()=>60*60*1,defaultResponseGranularity:y.MINUTELY,dataGranularity:y.MINUTELY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[T.SIX_HOUR,new I({key:T.SIX_HOUR,display:"Last 6 hours",timeframeText:"6 hours",timeframeLength:()=>60*60*6,defaultResponseGranularity:y.HOURLY,dataGranularity:y.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[T.TWELVE_HOUR,new I({key:T.TWELVE_HOUR,display:"Last 12 hours",timeframeText:"12 hours",timeframeLength:()=>60*60*12,defaultResponseGranularity:y.HOURLY,dataGranularity:y.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[T.ONE_DAY,new I({key:T.ONE_DAY,display:"Last 24 hours",timeframeText:"24 hours",timeframeLength:()=>60*60*24,defaultResponseGranularity:y.HOURLY,dataGranularity:y.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[T.SEVEN_DAY,new I({key:T.SEVEN_DAY,display:"Last 7 days",timeframeText:"7 days",timeframeLength:()=>60*60*24*7,defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!0,allowedTiers:["trial","plus","enterprise"]})],[T.THIRTY_DAY,new I({key:T.THIRTY_DAY,display:"Last 30 days",timeframeText:"30 days",timeframeLength:()=>60*60*24*30,defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!0,allowedTiers:["trial","plus","enterprise"]})],[T.CURRENT_WEEK,new Qe({key:T.CURRENT_WEEK,display:"This week",timeframeText:"Week",timeframeLength:()=>{const e=z(new Date,{weekStartsOn:1});return(ye(Q(new Date,1)).getTime()-e.getTime())/1e3},defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[T.CURRENT_MONTH,new Ze({key:T.CURRENT_MONTH,display:"This month",timeframeText:"Month",timeframeLength:()=>{const e=V(new Date);return(ye(Q(new Date,1)).getTime()-e.getTime())/1e3},defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[T.PREVIOUS_WEEK,new Je({key:T.PREVIOUS_WEEK,display:"Previous week",timeframeText:"Week",timeframeLength:()=>60*60*24*7,defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[T.PREVIOUS_MONTH,new Xe({key:T.PREVIOUS_MONTH,display:"Previous month",timeframeText:"Month",timeframeLength:()=>{let e=0;const t=V(new Date),r=V(ge(new Date,1));return t.getTimezoneOffset()!==r.getTimezoneOffset()&&(e=et(t,r)),60*60*24*Ge(new Date().setMonth(new Date().getMonth()-1))+ze(e)},defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})]]);function et(e,t){return qe(e.getTimezoneOffset()-t.getTimezoneOffset())}const tt={general:{notAvailable:"N/A"},metricCard:{short:{traffic:"Requests",errorRate:"Error Rate",latency:"P99 Latency"},long:{traffic:"Number of Requests",errorRate:"Average Error Rate",latency:"P99 Latency"}}};function rt(){const e=de.createI18n("en-us",tt);return{i18n:e,i18nT:de.i18nTComponent(e)}}var N=(e=>(e.API_PRODUCT="API_PRODUCT",e.API_PRODUCT_VERSION="API_PRODUCT_VERSION",e.RUNTIME_GROUP="RUNTIME_GROUP",e.GATEWAY_INSTANCE_ID="GATEWAY_INSTANCE_ID",e.GATEWAY_SERVICE="GATEWAY_SERVICE",e.ROUTE="ROUTE",e.APPLICATION="APPLICATION",e.STATUS_CODE="STATUS_CODE",e.STATUS_CODE_GROUPED="STATUS_CODE_GROUPED",e.TIME="TIME",e.ORGANIZATION="ORGANIZATION",e))(N||{}),K=(e=>(e.REQUEST_COUNT="REQUEST_COUNT",e.REQUEST_PER_MINUTE="REQUEST_PER_MINUTE",e.RESPONSE_LATENCY_P99="RESPONSE_LATENCY_P99",e.RESPONSE_LATENCY_P95="RESPONSE_LATENCY_P95",e.RESPONSE_LATENCY_P50="RESPONSE_LATENCY_P50",e.RESPONSE_SIZE_P99="RESPONSE_SIZE_P99",e.RESPONSE_SIZE_P95="RESPONSE_SIZE_P95",e.RESPONSE_SIZE_P50="RESPONSE_SIZE_P50",e.REQUEST_SIZE_P99="REQUEST_SIZE_P99",e.REQUEST_SIZE_P95="REQUEST_SIZE_P95",e.REQUEST_SIZE_P50="REQUEST_SIZE_P50",e))(K||{}),X=(e=>(e.IN="IN",e.NOT_IN="NOT_IN",e))(X||{});const nt=2,B=["1XX","2XX","3XX","4XX","5XX"],Ee=["4XX","5XX"];var Se=(e=>(e.VALIDATING="VALIDATING",e.VALIDATING_HAS_DATA="VALIDATING_HAS_DATA",e.PENDING="PENDING",e.SUCCESS="SUCCESS",e.SUCCESS_HAS_DATA="SUCCESS_HAS_DATA",e.ERROR="ERROR",e.STALE_IF_ERROR="STALE_IF_ERROR",e))(Se||{});const at=e=>{var t,r,i,a,n;return e?!!((t=Object.keys(e))!=null&&t.length||(r=e.data)!=null&&r.length||(a=(i=e.data)==null?void 0:i.data)!=null&&a.length||!((n=e.data)!=null&&n.data)&&typeof e.data=="object"&&Object.keys(e==null?void 0:e.data).length):!1};function it(e=o.ref({}),t,r,i=at){const a=o.ref("PENDING");return o.watchEffect(()=>{const n=i(e.value);if(e.value&&n&&r.value){a.value="VALIDATING_HAS_DATA";return}if(e.value&&r.value){a.value="VALIDATING";return}if(e.value&&t.value){a.value="STALE_IF_ERROR";return}if(e.value===void 0&&!t.value){a.value="PENDING";return}if(e.value&&!t.value&&n){a.value="SUCCESS_HAS_DATA";return}if(e.value&&!t.value){a.value="SUCCESS";return}e.value===void 0&&t&&(a.value="ERROR")}),{state:a,swrvState:Se}}const k=Symbol("default"),ee=N.STATUS_CODE_GROUPED,Re=(e,t,r,i,a)=>{e[t][r]||(e[t][r]={}),e[t][r][i]=a};function ot(e,t,r){var f;const i=((f=e.meta.metricNames)==null?void 0:f[0])||"",a=Object.keys(e.meta.dimensions||{}),n=!!a.find(d=>d===ee),l=a.find(d=>d!==ee);return a.length>2||a.length>1&&!n?(console.error("Don't know how to work with provided dimensions:",a),{previous:{[k]:{[k]:0}},current:{[k]:{[k]:0}}}):e.records.reduce((d,s)=>{const u=s.event[i],c=l?s.event[l]:k,m=n?s.event[ee]:k;return new Date(s.timestamp).getTime()===t.startDate().getTime()&&r?Re(d,"previous",c,m,u):Re(d,"current",c,m,u),d},{previous:{},current:{}})}function st(e){e.queryReady===void 0&&(e.queryReady=o.computed(()=>!0));const t=o.computed(()=>e.withTrend?new We(e.timeframe.value):new ve(e.timeframe.value)),r=o.computed(()=>{var c,m;return{metrics:e.metrics,dimensions:[...(c=e.dimensions)!=null&&c.length?[...e.dimensions]:[],...e.withTrend?[N.TIME]:[]],granularityMs:t.value.granularityMs(),...(m=e.filter.value)!=null&&m.length?{filter:e.filter.value}:{}}}),i=o.computed(()=>`${t.value.endDate().toString()}-${t.value.startDate().toString()}`),a=o.computed(()=>{var m,h,p,g;if(!((m=e.queryReady)!=null&&m.value)||e.featureFlags&&!e.featureFlags.every(S=>S))return null;const c=(h=e.filter)!=null&&h.value?JSON.stringify(e.filter.value):"";return`metric-fetcher-${i.value}-${(p=e.dimensions)==null?void 0:p.join("-")}-${(g=e.metrics)==null?void 0:g.join("-")}-${c}`}),{response:n,error:l,isValidating:f}=x.useRequest(()=>a.value,()=>e.dataFetcher(t.value,r.value),{refreshInterval:e.refreshInterval,revalidateOnFocus:!1,errorRetryCount:nt}),{state:d,swrvState:s}=it(n,l,f),u=o.computed(()=>{var c,m,h,p,g,S,A,E,v,M;return!((h=(m=(c=n.value)==null?void 0:c.data)==null?void 0:m.records)!=null&&h.length)||!((S=(g=(p=n.value)==null?void 0:p.data)==null?void 0:g.meta)!=null&&S.dimensions)||!((M=(v=(E=(A=n.value)==null?void 0:A.data)==null?void 0:E.meta)==null?void 0:v.metricNames)!=null&&M.length)?{current:{},previous:{}}:ot(n.value.data,t.value,!!e.withTrend)});return{isLoading:o.computed(()=>s.PENDING===d.value),hasError:o.computed(()=>s.ERROR===d.value),raw:n,mapped:u}}const P=(e,t,r=k,i)=>(i??[k]).reduce((n,l)=>{const f=e[t][r];return f?n+(f[l]||0):n},0);function lt(e){const{title:t,record:r,hasError:i,increaseIsBad:a,formatValueFn:n}=e;return o.computed(()=>{let l=0,f=0;if(r!=null&&r.value)try{l=P(r.value,"current",e.lookupKey,e.sumGroupedValues),f=P(r.value,"previous",e.lookupKey,e.sumGroupedValues)}catch(d){console.error("Metric card data doesn't have the expected structure:",d)}return{hasError:i.value,currentValue:l,previousValue:f,title:t.value,increaseIsBad:!!a,formatValueFn:n}})}var te=new WeakMap,we=0;function ut(e){if(!e.length)return"";for(var t="arg",r=0;r<e.length;++r){var i=void 0;e[r]===null||typeof e[r]!="object"&&typeof e[r]!="function"?typeof e[r]=="string"?i='"'+e[r]+'"':i=String(e[r]):te.has(e[r])?i=te.get(e[r]):(i=we,te.set(e[r],we++)),t+="@"+i}return t}function ct(e){if(typeof e=="function")try{e=e()}catch{e=""}return Array.isArray(e)?e=ut(e):e=String(e||""),e}var re=function(){function e(t){t===void 0&&(t=0),this.items=new Map,this.ttl=t}return e.prototype.serializeKey=function(t){return ct(t)},e.prototype.get=function(t){var r=this.serializeKey(t);return this.items.get(r)},e.prototype.set=function(t,r,i){var a=this.serializeKey(t),n=i||this.ttl,l=Date.now(),f={data:r,createdAt:l,expiresAt:n?l+n:1/0};this.dispatchExpire(n,f,a),this.items.set(a,f)},e.prototype.dispatchExpire=function(t,r,i){var a=this;t&&setTimeout(function(){var n=Date.now(),l=n>=r.expiresAt;l&&a.delete(i)},t)},e.prototype.delete=function(t){this.items.delete(t)},e}();function dt(){return typeof navigator.onLine<"u"?navigator.onLine:!0}function ft(){return typeof document<"u"&&typeof document.visibilityState<"u"?document.visibilityState!=="hidden":!0}var mt=function(e){return fetch(e).then(function(t){return t.json()})};const ne={isOnline:dt,isDocumentVisible:ft,fetcher:mt};var O=globalThis&&globalThis.__assign||function(){return O=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++){t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},O.apply(this,arguments)},Y=globalThis&&globalThis.__awaiter||function(e,t,r,i){function a(n){return n instanceof r?n:new r(function(l){l(n)})}return new(r||(r=Promise))(function(n,l){function f(u){try{s(i.next(u))}catch(c){l(c)}}function d(u){try{s(i.throw(u))}catch(c){l(c)}}function s(u){u.done?n(u.value):a(u.value).then(f,d)}s((i=i.apply(e,t||[])).next())})},F=globalThis&&globalThis.__generator||function(e,t){var r={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},i,a,n,l;return l={next:f(0),throw:f(1),return:f(2)},typeof Symbol=="function"&&(l[Symbol.iterator]=function(){return this}),l;function f(s){return function(u){return d([s,u])}}function d(s){if(i)throw new TypeError("Generator is already executing.");for(;r;)try{if(i=1,a&&(n=s[0]&2?a.return:s[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,s[1])).done)return n;switch(a=0,n&&(s=[s[0]&2,n.value]),s[0]){case 0:case 1:n=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,a=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(n=r.trys,!(n=n.length>0&&n[n.length-1])&&(s[0]===6||s[0]===2)){r=0;continue}if(s[0]===3&&(!n||s[1]>n[0]&&s[1]<n[3])){r.label=s[1];break}if(s[0]===6&&r.label<n[1]){r.label=n[1],n=s;break}if(n&&r.label<n[2]){r.label=n[2],r.ops.push(s);break}n[2]&&r.ops.pop(),r.trys.pop();continue}s=t.call(e,r)}catch(u){s=[6,u],a=0}finally{i=n=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},ht=globalThis&&globalThis.__read||function(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var i=r.call(e),a,n=[],l;try{for(;(t===void 0||t-- >0)&&!(a=i.next()).done;)n.push(a.value)}catch(f){l={error:f}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}finally{if(l)throw l.error}}return n},yt=globalThis&&globalThis.__spreadArray||function(e,t,r){if(r||arguments.length===2)for(var i=0,a=t.length,n;i<a;i++)(n||!(i in t))&&(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))},De=new re,q=new re,ae=new re,_e={cache:De,refreshInterval:0,ttl:0,serverTTL:1e3,dedupingInterval:2e3,revalidateOnFocus:!0,revalidateDebounce:0,shouldRetryOnError:!0,errorRetryInterval:5e3,errorRetryCount:5,fetcher:ne.fetcher,isOnline:ne.isOnline,isDocumentVisible:ne.isDocumentVisible};function pt(e,t,r){var i=q.get(e);if(i)i.data.push(t);else{var a=5e3;q.set(e,[t],r>0?r+a:r)}}function gt(e,t,r){if(r.isDocumentVisible()&&!(r.errorRetryCount!==void 0&&t>r.errorRetryCount)){var i=Math.min(t||0,r.errorRetryCount),a=i*r.errorRetryInterval;setTimeout(function(){e(null,{errorRetryCount:i+1,shouldRetryOnError:!0})},a)}}var Ce=function(e,t,r,i){return r===void 0&&(r=De),i===void 0&&(i=_e.ttl),Y(void 0,void 0,void 0,function(){var a,n,l,f,d,s,u;return F(this,function(c){switch(c.label){case 0:if(!Tt(t))return[3,5];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,t];case 2:return a=c.sent(),[3,4];case 3:return f=c.sent(),n=f,[3,4];case 4:return[3,6];case 5:a=t,c.label=6;case 6:if(l=!1,d={data:a,error:n,isValidating:l},typeof a<"u")try{r.set(e,d,i)}catch(m){console.error("swrv(mutate): failed to set cache",m)}return s=q.get(e),s&&s.data.length&&(u=s.data.filter(function(m){return m.key===e}),u.forEach(function(m,h){typeof d.data<"u"&&(m.data=d.data),m.error=d.error,m.isValidating=d.isValidating;var p=h===u.length-1;p||delete u[h]}),u=u.filter(Boolean)),[2,d]}})})};function vt(){for(var e=this,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var i,a,n=O({},_e),l=!1,f=!1,d=o.getCurrentInstance(),s=(d==null?void 0:d.proxy)||d;if(!s)return console.error("Could not get current instance, check to make sure that `useSwrv` is declared in the top level of the setup function."),null;var u=(s==null?void 0:s.$isServer)||!1;t.length>=1&&(i=t[0]),t.length>=2&&(a=t[1]),t.length>2&&(n=O(O({},n),t[2]));var c=u?n.serverTTL:n.ttl,m=typeof i=="function"?i:o.ref(i);typeof a>"u"&&(a=n.fetcher);var h=null;h||(h=o.reactive({data:void 0,error:void 0,isValidating:!0,key:null}));var p=function(E,v){return Y(e,void 0,void 0,function(){var M,D,H,$,se,Ne,le,ke=this;return F(this,function(ue){switch(ue.label){case 0:return M=h.data===void 0,D=m.value,D?(H=n.cache.get(D),$=H&&H.data,h.isValidating=!0,$&&(h.data=$.data,h.error=$.error),se=E||a,!se||!n.isDocumentVisible()&&!M||(v==null?void 0:v.forceRevalidate)!==void 0&&!(v!=null&&v.forceRevalidate)?(h.isValidating=!1,[2]):H&&(Ne=!!(Date.now()-H.createdAt>=n.dedupingInterval||v!=null&&v.forceRevalidate),!Ne)?(h.isValidating=!1,[2]):(le=function(){return Y(ke,void 0,void 0,function(){var U,Le,ce,Me;return F(this,function(W){switch(W.label){case 0:return U=ae.get(D),U?[3,2]:(Le=Array.isArray(D)?D:[D],ce=se.apply(void 0,yt([],ht(Le),!1)),ae.set(D,ce,n.dedupingInterval),[4,Ce(D,ce,n.cache,c)]);case 1:return W.sent(),[3,4];case 2:return[4,Ce(D,U.data,n.cache,c)];case 3:W.sent(),W.label=4;case 4:return h.isValidating=!1,ae.delete(D),h.error!==void 0&&(Me=!l&&n.shouldRetryOnError&&(v?v.shouldRetryOnError:!0),Me&&gt(p,v?v.errorRetryCount:1,n)),[2]}})})},$&&n.revalidateDebounce?(setTimeout(function(){return Y(ke,void 0,void 0,function(){return F(this,function(U){switch(U.label){case 0:return l?[3,2]:[4,le()];case 1:U.sent(),U.label=2;case 2:return[2]}})})},n.revalidateDebounce),[3,3]):[3,1])):[2];case 1:return[4,le()];case 2:ue.sent(),ue.label=3;case 3:return[2]}})})},g=function(){return Y(e,void 0,void 0,function(){return F(this,function(E){return[2,p(null,{shouldRetryOnError:!1})]})})},S=null;o.onMounted(function(){var E=function(){return Y(e,void 0,void 0,function(){return F(this,function(v){switch(v.label){case 0:return!h.error&&n.isOnline()?[4,p()]:[3,2];case 1:return v.sent(),[3,3];case 2:S&&clearTimeout(S),v.label=3;case 3:return n.refreshInterval&&!l&&(S=setTimeout(E,n.refreshInterval)),[2]}})})};n.refreshInterval&&(S=setTimeout(E,n.refreshInterval)),n.revalidateOnFocus&&(document.addEventListener("visibilitychange",g,!1),window.addEventListener("focus",g,!1))}),o.onUnmounted(function(){l=!0,S&&clearTimeout(S),n.revalidateOnFocus&&(document.removeEventListener("visibilitychange",g,!1),window.removeEventListener("focus",g,!1));var E=q.get(m.value);E&&(E.data=E.data.filter(function(v){return v!==h}))});try{o.watch(m,function(E){o.isReadonly(m)||(m.value=E),h.key=E,h.isValidating=!!E,pt(m.value,h,c),!u&&!f&&m.value&&p(),f=!1},{immediate:!0})}catch{}var A=O(O({},o.toRefs(h)),{mutate:function(E,v){return p(E,O(O({},v),{forceRevalidate:!0}))}});return A}function Tt(e){return e!==null&&typeof e=="object"&&typeof e.then=="function"}function Et(e,t,r){const{data:i,error:a,isValidating:n,mutate:l}=vt(e,t,{revalidateDebounce:500,revalidateOnFocus:!1,dedupingInterval:100,...r});return{data:o.computed(()=>{var d;return(d=i.value)==null?void 0:d.data}),response:i,error:a,isValidating:n,revalidate:l}}const x={useI18n:rt,useMetricCardBuilder:lt,useMetricFetcher:st,useRequest:Et},Ie=Symbol("METRICS_PROVIDER_KEY"),St=e=>{const{dimension:t,dimensionFilterValue:r,additionalFilter:i,queryReady:a,timeframe:n,hasTrendAccess:l,refreshInterval:f,dataFetcher:d}=e;if(r&&!t)throw new Error("Must provide a dimension if filtering by a value");const s=!!(t&&r),u=!!(t&&!r),c=o.computed(()=>{const S=[];return s&&S.push({dimension:t,type:X.IN,values:[r]}),i.value&&S.push(...i.value),S}),m={metrics:[K.REQUEST_COUNT],dimensions:[...t&&!s?[t]:[],N.STATUS_CODE_GROUPED],filter:c,queryReady:a,timeframe:n,withTrend:l&&!u,refreshInterval:f,dataFetcher:d},h={metrics:[K.RESPONSE_LATENCY_P99],...t&&!s?{dimensions:[t]}:{},filter:c,queryReady:a,timeframe:n,withTrend:l&&!u,refreshInterval:f,dataFetcher:d},p=x.useMetricFetcher(m),g=x.useMetricFetcher(h);return{trafficData:p,latencyData:g}},Rt=o.defineComponent({__name:"MetricsProviderInternal",props:{maxTimeframe:{default:T.THIRTY_DAY},overrideTimeframe:{default:void 0},dimension:{default:void 0},filterValue:{default:void 0},additionalFilter:{default:void 0},queryReady:{type:Boolean,default:!0},dataFetcher:{},hasTrendAccess:{type:Boolean},refreshInterval:{},longCardTitles:{type:Boolean,default:!1}},setup(e){const t=e;if(t.dimension&&!{}.hasOwnProperty.call(N,t.dimension))throw new Error(`Attempted to use MetricsProvider with an invalid dimension: ${t.dimension}`);const r=o.computed(()=>{if(t.overrideTimeframe)return t.overrideTimeframe;const n=t.hasTrendAccess?Te.get(t.maxTimeframe):Te.get(T.ONE_DAY);if(!n)throw new Error("Metrics provider failed to resolve fallback timeframe.");return n}),{trafficData:i,latencyData:a}=St({dimension:t.dimension,dimensionFilterValue:t.filterValue,additionalFilter:o.toRef(t,"additionalFilter"),queryReady:o.toRef(t,"queryReady"),timeframe:r,hasTrendAccess:t.hasTrendAccess,refreshInterval:t.refreshInterval,dataFetcher:t.dataFetcher});return o.provide(Ie,{data:{traffic:i,latency:a},hasTrendAccess:t.hasTrendAccess,longCardTitles:t.longCardTitles}),(n,l)=>o.renderSlot(n.$slots,"default",{hasTrendAccess:t.hasTrendAccess,timeframe:r.value})}});function wt(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ae={exports:{}};(function(e){(function(){function t(s,u){if(u.separator===!1||s<1e3)return s.toString();var c=typeof u.separator=="string"?u.separator:",",m=[],h=Math.round(s).toString().split("");return h.reverse().forEach(function(p,g){g&&g%3===0&&m.push(c),m.push(p)}),m.reverse().join("")}function r(s,u,c){var m=s/u,h=c.round?"round":"floor";return c.decimal===!1?(s=Math[h](m),s.toString()):(c.precision?s=m:s=m<10?Math[h](m*10)/10:Math[h](m),s=s.toString(),typeof c.decimal=="string"&&(s=s.replace(".",c.decimal)),s)}var i=1e3,a=1e4,n=1e6,l=1e9,f=1e12;function d(s,u){var c;u=u||{};var m=s<0;m&&(s=Math.abs(s)),u.precision&&(s=parseFloat(s.toPrecision(u.precision)));var h=u.min10k?a:i;return s<h||u.precision&&u.precision>Math.log10(s)?c=t(r(s,1,u),u):s<n?c=r(s,i,u)+"k":s<l?c=r(s,n,u)+"m":s<f?c=t(r(s,l,u),u)+"b":c=t(r(s,f,u),u)+"t",m&&(c="-"+c),u.capital&&(c=c.toUpperCase()),u.prefix&&(c=u.prefix+c),u.suffix&&(c=c+u.suffix),c}d.addCommas=t,e.exports=d})()})(Ae);var Dt=Ae.exports;const _t=wt(Dt);var b=(e=>(e.Small="sm",e.Medium="md",e.Large="lg",e.ExtraLarge="xl",e))(b||{});const ie=2,Oe=ie+2,Ct=(e,t,r=!1)=>{let i=!t||Number(e.toFixed(Oe))===0?0:Number(e.toFixed(Oe))>0?1:-1;return r&&(i*=-1),i},It=(e,t,r)=>t?`${Math.abs(e*100).toFixed(ie)}%`:r,At=(e,t)=>t===0?0:e/t-1,Ot=(e,t=!1)=>(t&&(e*=-1),e>0?"arrowUp":e<0?"arrowDown":"noData"),bt={class:"metricscard"},Nt={key:0,class:"metricscard-error"},kt={key:1,class:"metricscard-value"},Lt=o.defineComponent({__name:"MetricsCard",props:{title:{type:String,default:"0%",required:!0},tooltip:{type:String,required:!1,default:""},timeframe:{type:String,required:!1,default:""},metricValue:{type:String,default:""},metricChange:{type:String,required:!0},changePolarity:{type:Number,required:!0},icon:{type:String,default:""},hasError:{type:Boolean,default:!1},errorMessage:{type:String,default:"Vitals data error"},cardSize:{type:String,required:!1,default:()=>"lg"}},setup(e){const t=e,r=l=>{const f={red:"var(--kong-ui-metric-card-trend-negative, var(--red-500, '#d44324'))",green:"var(--kong-ui-metric-card-trend-positive, var(--green-500, '#07a88d'))",grey:"var(--kong-ui-metric-card-trend-neutral, var(--grey-500, '#6f7787'))"};return l>0?f.green:l<0?f.red:f.grey},i=l=>l>0?"positive":l<0?"negative":"neutral",a=[b.Medium,b.Large].includes(t.cardSize),n=t.cardSize===b.ExtraLarge?"48px":[b.Medium,b.Large].includes(t.cardSize)?"22px":"16px";return(l,f)=>{const d=o.resolveComponent("KIcon"),s=o.resolveComponent("KTooltip");return o.openBlock(),o.createElementBlock("div",bt,[o.createElementVNode("div",{class:o.normalizeClass(["metricscard-title",e.cardSize])},[o.createElementVNode("span",null,o.toDisplayString(e.title),1),e.tooltip?(o.openBlock(),o.createBlock(s,{key:0,class:"metricscard-tooltip",label:e.tooltip,placement:"right"},{default:o.withCtx(()=>[o.createVNode(d,{icon:"info",size:"12"})]),_:1},8,["label"])):o.createCommentVNode("",!0)],2),e.hasError?(o.openBlock(),o.createElementBlock("div",Nt,[o.createVNode(d,{icon:"warning",size:"20"}),o.createElementVNode("div",null,o.toDisplayString(e.errorMessage),1)])):(o.openBlock(),o.createElementBlock("div",kt,[o.createElementVNode("div",{style:o.normalizeStyle(`font-size:${o.unref(n)}`)},o.toDisplayString(e.metricValue),5),o.unref(a)?(o.openBlock(),o.createElementBlock("div",{key:0,class:o.normalizeClass(["metricscard-value-trend",i(e.changePolarity)])},[e.changePolarity!==0?(o.openBlock(),o.createBlock(d,{key:0,color:r(e.changePolarity),icon:e.icon,size:"18"},null,8,["color","icon"])):o.createCommentVNode("",!0),o.createElementVNode("div",null,o.toDisplayString(e.metricChange),1)],2)):o.createCommentVNode("",!0)]))])}}}),oe=(e,t)=>{const r=e.__vccOpts||e;for(const[i,a]of t)r[i]=a;return r},Mt=oe(Lt,[["__scopeId","data-v-ee980c4c"]]),Ut={},Vt={class:"loading-tabs"};function Pt(e,t){const r=o.resolveComponent("KSkeletonBox");return o.openBlock(),o.createElementBlock("div",Vt,[o.createVNode(r,{width:"100"}),o.createVNode(r,{width:"75"})])}const Yt=oe(Ut,[["render",Pt],["__scopeId","data-v-e4239529"]]),Ft={key:0,class:"error-display"},xt={key:0,class:"error-display-message"},Bt=oe(o.defineComponent({__name:"MetricCardContainer",props:{fallbackDisplayText:{type:String,required:!0},cards:{type:Array,required:!0},errorMessage:{type:String,required:!1,default:""},loading:{type:Boolean,required:!1,default:!1},hasTrendAccess:{type:Boolean,required:!1,default:!0},cardSize:{type:String,required:!1,default:()=>b.Large}},setup(e){const t=e,r=o.computed(()=>t.cards.every(a=>(a==null?void 0:a.hasError)===!0)),i=a=>{const n=At(a.currentValue,a.previousValue)||0,l=Ct(n,t.hasTrendAccess,a.increaseIsBad);return{metricValue:a.formatValueFn?a.formatValueFn(a.currentValue):_t(a.currentValue,{capital:!0,round:!0})||"0",metricChange:a.formatChangeFn?a.formatChangeFn(n):It(n,t.hasTrendAccess,t.fallbackDisplayText),changePolarity:l,icon:Ot(l,a.increaseIsBad),cardSize:t.cardSize}};return(a,n)=>{const l=o.resolveComponent("KIcon");return o.openBlock(),o.createElementBlock("div",{class:o.normalizeClass(["kong-ui-public-metric-card-container",e.cardSize])},[o.unref(r)?(o.openBlock(),o.createElementBlock("div",Ft,[o.createVNode(l,{class:"error-display-icon",icon:"warning",size:"24"}),e.errorMessage?(o.openBlock(),o.createElementBlock("div",xt,o.toDisplayString(e.errorMessage),1)):o.createCommentVNode("",!0)])):(o.openBlock(!0),o.createElementBlock(o.Fragment,{key:1},o.renderList(e.cards,(f,d)=>(o.openBlock(),o.createElementBlock(o.Fragment,null,[e.loading?(o.openBlock(),o.createBlock(Yt,{key:`skeleton-${d}`,class:o.normalizeClass(e.cardSize===o.unref(b).Small?"loading-tabs-small":"loading-tabs-large")},null,8,["class"])):(o.openBlock(),o.createBlock(Mt,o.mergeProps({key:d},i(f),{"card-size":e.cardSize,"error-message":e.errorMessage,"has-error":f.hasError,title:f.title,tooltip:f.tooltip}),null,16,["card-size","error-message","has-error","title","tooltip"]))],64))),256))],2)}}}),[["__scopeId","data-v-390af84f"]]),qt="",Ht=o.defineComponent({__name:"MetricsConsumer",props:{lookupKey:{default:void 0},cardSize:{default:b.Large},cardToDisplay:{default:void 0}},setup(e){const t=e,r=o.inject(Ie);if(!r)throw new Error("MetricsConsumer must be nested inside a MetricsProvider instance.");const{traffic:i,latency:a}=r.data,{i18n:n}=x.useI18n(),l=x.useMetricCardBuilder({title:o.computed(()=>r.longCardTitles?n.t("metricCard.long.traffic"):n.t("metricCard.short.traffic")),record:i.mapped,hasError:i.hasError,lookupKey:t.lookupKey,sumGroupedValues:B}),f=g=>`${g.toFixed(ie)}%`,d=o.computed(()=>{const g=i.mapped.value,S=P(g,"current",t.lookupKey,Ee),A=P(g,"current",t.lookupKey,B),E=S/A*100||0,v=P(g,"previous",t.lookupKey,Ee),M=P(g,"previous",t.lookupKey,B),D=v/M*100||0;return{hasError:i.hasError.value,currentValue:E,previousValue:D,formatValueFn:f,title:r.longCardTitles?n.t("metricCard.long.errorRate"):n.t("metricCard.short.errorRate"),increaseIsBad:!0}}),s=g=>`${g}ms`,u=x.useMetricCardBuilder({title:o.computed(()=>r.longCardTitles?n.t("metricCard.long.latency"):n.t("metricCard.short.latency")),hasError:a.hasError,record:a.mapped,lookupKey:t.lookupKey,increaseIsBad:!0,formatValueFn:s}),c=o.computed(()=>t.cardToDisplay==="TRAFFIC"?[l.value]:t.cardToDisplay==="ERROR_RATE"?[d.value]:t.cardToDisplay==="LATENCY"?[u.value]:[l.value,d.value,u.value]),m=o.computed(()=>t.cardToDisplay==="TRAFFIC"||t.cardToDisplay==="ERROR_RATE"?i.isLoading.value:t.cardToDisplay==="LATENCY"?a.isLoading.value:i.isLoading.value||a.isLoading.value),h=o.computed(()=>({cards:c.value,loading:m.value,hasTrendAccess:r.hasTrendAccess,fallbackDisplayText:n.t("general.notAvailable"),cardSize:t.cardSize,hideTitle:!0})),p=o.computed(()=>({loading:h.value.loading,trafficCard:l.value,errorRateCard:d.value,latencyCard:u.value,errorRateFormatted:f(d.value.currentValue),latencyFormatted:s(u.value.currentValue)}));return(g,S)=>o.renderSlot(g.$slots,"default",{cardValues:p.value},()=>[o.createVNode(o.unref(Bt),o.normalizeProps(o.guardReactiveProps(h.value)),null,16)])}}),j=e=>new Date(e),$t=(e,t)=>{const r=e.body,{startMs:i,endMs:a}=e.query,n=typeof i!="number"?parseInt(i,10):i,l=typeof a!="number"?parseInt(a,10):a;e.reply({statusCode:200,body:be(r,n,l,t)})},be=(e,t,r,i)=>{var c,m;const a=e.granularityMs||0,n=a?(r-t)/a:1;if(n!==1&&n!==2)throw new Error("Query did not request 1 or 2 records. Perhaps there's a chart query on the same page interfering with the stub?");if((e.dimensions??[]).length>2)throw new Error(`Explore only supports 0-2 dimensions; got: ${JSON.stringify(e.dimensions)}`);const l=(e.dimensions??[]).find(h=>h!=="TIME"),f=(i==null?void 0:i.dimensionNames)??[],d=Math.max(f.length,1),s=[];for(let h=0;h<n;h++)for(let p=0;p<d;p++){const g=l?{[l]:f[p]}:{};(c=e.dimensions)!=null&&c.includes(N.STATUS_CODE_GROUPED)?B.forEach(S=>{const A=e.metrics.reduce((E,v)=>(E[v]=(n-h)*1e3+100*p+1,E),{...g,STATUS_CODE_GROUPED:S});s.push({version:"v1",timestamp:h===0?j(t).toISOString():j(t+a).toISOString(),event:A})}):s.push({version:"v1",timestamp:h===0?j(t).toISOString():j(t+a).toISOString(),event:e.metrics.reduce((S,A)=>(S[A]=(n-h)*1e3+100*p+1,S),{...g})})}const u={start:t,end:r,granularity:a,dimensions:l?{[l]:f,...(m=e.dimensions)!=null&&m.includes(N.STATUS_CODE_GROUPED)?{STATUS_CODE_GROUPED:B}:{}}:{},metricNames:e.metrics};return{records:s,meta:u}};R.EXPLORE_V2_AGGREGATIONS=K,R.EXPLORE_V2_DIMENSIONS=N,R.EXPLORE_V2_FILTER_TYPES=X,R.MetricsConsumer=Ht,R.MetricsProviderInternal=Rt,R.mockExploreResponse=be,R.mockExploreResponseFromCypress=$t,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});
1
+ (function(R,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue"),require("@kong-ui-public/i18n")):typeof define=="function"&&define.amd?define(["exports","vue","@kong-ui-public/i18n"],s):(R=typeof globalThis<"u"?globalThis:R||self,s(R["kong-ui-public-vitals-metric-provider"]={},R.Vue,R["kong-ui-public-i18n"]))})(this,function(R,s,fe){"use strict";var Me=Object.defineProperty,Ve=(e,t,r)=>t in e?Me(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,C=(e,t,r)=>(Ve(e,typeof t!="symbol"?t+"":t,r),r),y=(e=>(e.MINUTELY="Minutely",e.HOURLY="Hourly",e.DAILY="Daily",e.WEEKLY="Weekly",e))(y||{}),T=(e=>(e.FIFTEEN_MIN="15m",e.ONE_HOUR="1h",e.SIX_HOUR="6h",e.TWELVE_HOUR="12h",e.ONE_DAY="24h",e.SEVEN_DAY="7d",e.THIRTY_DAY="30d",e.CURRENT_WEEK="current_week",e.CURRENT_MONTH="current_month",e.CURRENT_QUARTER="current_quarter",e.PREVIOUS_WEEK="previous_week",e.PREVIOUS_MONTH="previous_month",e.PREVIOUS_QUARTER="previous_quarter",e))(T||{});const me={[y.MINUTELY]:60*1e3,[y.HOURLY]:60*60*1e3,[y.DAILY]:60*60*24*1e3,[y.WEEKLY]:60*60*24*7*1e3};function Pe(e,t){return e?{duration:e,type:"duration",origin:t}:null}function he(e,t,r){const i=me[r],a=i>=me[y.DAILY]?t.getTimezoneOffset()*60*1e3:0;return new Date(e((t.getTime()-a)/i)*i+a)}function ye(e,t){return he(Math.floor,e,t)}function Ye(e,t){return he(Math.ceil,e,t)}function G(e){"@babel/helpers - typeof";return G=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},G(e)}function _(e){if(e===null||e===!0||e===!1)return NaN;var t=Number(e);return isNaN(t)?t:t<0?Math.ceil(t):Math.floor(t)}function w(e,t){if(t.length<e)throw new TypeError(e+" argument"+(e>1?"s":"")+" required, but only "+t.length+" present")}function L(e){w(1,arguments);var t=Object.prototype.toString.call(e);return e instanceof Date||G(e)==="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):((typeof e=="string"||t==="[object String]")&&typeof console<"u"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function Q(e,t){w(2,arguments);var r=L(e),i=_(t);return isNaN(i)?new Date(NaN):(i&&r.setDate(r.getDate()+i),r)}function Fe(e,t){w(2,arguments);var r=L(e),i=_(t);if(isNaN(i))return new Date(NaN);if(!i)return r;var a=r.getDate(),n=new Date(r.getTime());n.setMonth(r.getMonth()+i+1,0);var l=n.getDate();return a>=l?n:(r.setFullYear(n.getFullYear(),n.getMonth(),a),r)}var xe={};function Be(){return xe}function z(e,t){var r,i,a,n,l,f,d,o;w(1,arguments);var u=Be(),c=_((r=(i=(a=(n=t==null?void 0:t.weekStartsOn)!==null&&n!==void 0?n:t==null||(l=t.locale)===null||l===void 0||(f=l.options)===null||f===void 0?void 0:f.weekStartsOn)!==null&&a!==void 0?a:u.weekStartsOn)!==null&&i!==void 0?i:(d=u.locale)===null||d===void 0||(o=d.options)===null||o===void 0?void 0:o.weekStartsOn)!==null&&r!==void 0?r:0);if(!(c>=0&&c<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var m=L(e),h=m.getDay(),p=(h<c?7:0)+h-c;return m.setDate(m.getDate()-p),m.setHours(0,0,0,0),m}function pe(e){w(1,arguments);var t=L(e);return t.setHours(0,0,0,0),t}var He=60,$e=3600;function V(e){w(1,arguments);var t=L(e);return t.setDate(1),t.setHours(0,0,0,0),t}function Ge(e){w(1,arguments);var t=L(e),r=t.getFullYear(),i=t.getMonth(),a=new Date(0);return a.setFullYear(r,i+1,0),a.setHours(0,0,0,0),a.getDate()}function Z(e){w(1,arguments);var t=L(e),r=t.getTime();return r}function ge(e){return w(1,arguments),Math.floor(Z(e)/1e3)}function ze(e){return w(1,arguments),Math.floor(e*$e)}function Ke(e,t){w(2,arguments);var r=_(t);return Q(e,-r)}function qe(e){w(1,arguments);var t=e/He;return Math.floor(t)}function J(e,t){w(2,arguments);var r=_(t);return Fe(e,-r)}function je(e,t){if(w(2,arguments),!t||G(t)!=="object")return new Date(NaN);var r=t.years?_(t.years):0,i=t.months?_(t.months):0,a=t.weeks?_(t.weeks):0,n=t.days?_(t.days):0,l=t.hours?_(t.hours):0,f=t.minutes?_(t.minutes):0,d=t.seconds?_(t.seconds):0,o=J(e,i+r*12),u=Ke(o,n+a*7),c=f+l*60,m=d+c*60,h=m*1e3,p=new Date(u.getTime()-h);return p}class X{constructor(t){if(C(this,"timeframe"),this.constructor===X)throw new Error("BaseQueryTime is not meant to be used directly.");this.timeframe=t}calculateStartDate(t,r,i=1){if(t)return new Date(this.endDate().getTime()-this.timeframe.timeframeLengthMs()*i);{const a=this.endDate(),n=ye(this.timeframe.rawStart(),r),l=(a.getTime()-n.getTime())*(i-1);return ye(new Date(this.timeframe.rawStart().getTime()-l),r)}}granularitySeconds(){return Math.floor(this.granularityMs()/1e3)}granularityDruid(){return Pe(this.granularityMs(),this.startDate().toISOString())}startSeconds(){return ge(this.startDate())}endSeconds(){return ge(this.endDate())}startMs(){return Z(this.startDate())}endMs(){return Z(this.endDate())}withinFreeTier(){return this.startDate()>=je(new Date,{days:1})}}let ve=class extends X{startDate(){return this.calculateStartDate(this.timeframe.isRelative,this.timeframe.dataGranularity)}endDate(){return Ye(this.timeframe.rawEnd(),this.timeframe.dataGranularity)}granularityMs(){return this.endDate().getTime()-this.startDate().getTime()}},We=class extends ve{startDate(){return this.calculateStartDate(this.timeframe.isRelative,this.timeframe.dataGranularity,2)}granularityMs(){return this.endDate().getTime()-super.startDate().getTime()}};class I{constructor(t){C(this,"timeframeText"),C(this,"key"),C(this,"display"),C(this,"timeframeLength"),C(this,"allowedTiers"),C(this,"defaultResponseGranularity"),C(this,"dataGranularity"),C(this,"isRelative"),C(this,"_startCustom"),C(this,"_endCustom"),this.display=t.display,this.timeframeText=t.timeframeText,this.key=t.key,this.timeframeLength=t.timeframeLength,this.allowedTiers=t.allowedTiers,this.defaultResponseGranularity=t.defaultResponseGranularity,this.dataGranularity=t.dataGranularity,this.isRelative=t.isRelative,this._startCustom=t.startCustom,this._endCustom=t.endCustom}rawEnd(){return this._endCustom||new Date}rawStart(){return this._startCustom||new Date(this.rawEnd().getTime()-this.timeframeLengthMs())}timeframeLengthMs(){return this.timeframeLength()*1e3}maximumTimeframeLength(){return this.timeframeLength()}allowedGranularities(){const t=new Set,r=this.maximumTimeframeLength()/3600;return r<=6&&t.add(y.MINUTELY),r>=2&&r<=7*24&&t.add(y.HOURLY),r>=2*24&&t.add(y.DAILY),r>=2*24*14&&t.add(y.WEEKLY),t}}class Qe extends I{rawStart(){return z(new Date,{weekStartsOn:1})}maximumTimeframeLength(){return 60*60*24*7}}let Ze=class extends I{rawStart(){return V(new Date)}maximumTimeframeLength(){return 60*60*24*31}},Je=class extends I{rawEnd(){return z(new Date,{weekStartsOn:1})}rawStart(){return z(new Date().setDate(new Date().getDate()-7),{weekStartsOn:1})}},Xe=class extends I{rawEnd(){return V(new Date)}rawStart(){return V(J(new Date,1))}};const Te=new Map([[T.FIFTEEN_MIN,new I({key:T.FIFTEEN_MIN,display:"Last 15 minutes",timeframeText:"15 minutes",timeframeLength:()=>60*15,defaultResponseGranularity:y.MINUTELY,dataGranularity:y.MINUTELY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[T.ONE_HOUR,new I({key:T.ONE_HOUR,display:"Last hour",timeframeText:"One hour",timeframeLength:()=>60*60*1,defaultResponseGranularity:y.MINUTELY,dataGranularity:y.MINUTELY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[T.SIX_HOUR,new I({key:T.SIX_HOUR,display:"Last 6 hours",timeframeText:"6 hours",timeframeLength:()=>60*60*6,defaultResponseGranularity:y.HOURLY,dataGranularity:y.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[T.TWELVE_HOUR,new I({key:T.TWELVE_HOUR,display:"Last 12 hours",timeframeText:"12 hours",timeframeLength:()=>60*60*12,defaultResponseGranularity:y.HOURLY,dataGranularity:y.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[T.ONE_DAY,new I({key:T.ONE_DAY,display:"Last 24 hours",timeframeText:"24 hours",timeframeLength:()=>60*60*24,defaultResponseGranularity:y.HOURLY,dataGranularity:y.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[T.SEVEN_DAY,new I({key:T.SEVEN_DAY,display:"Last 7 days",timeframeText:"7 days",timeframeLength:()=>60*60*24*7,defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!0,allowedTiers:["trial","plus","enterprise"]})],[T.THIRTY_DAY,new I({key:T.THIRTY_DAY,display:"Last 30 days",timeframeText:"30 days",timeframeLength:()=>60*60*24*30,defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!0,allowedTiers:["trial","plus","enterprise"]})],[T.CURRENT_WEEK,new Qe({key:T.CURRENT_WEEK,display:"This week",timeframeText:"Week",timeframeLength:()=>{const e=z(new Date,{weekStartsOn:1});return(pe(Q(new Date,1)).getTime()-e.getTime())/1e3},defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[T.CURRENT_MONTH,new Ze({key:T.CURRENT_MONTH,display:"This month",timeframeText:"Month",timeframeLength:()=>{const e=V(new Date);return(pe(Q(new Date,1)).getTime()-e.getTime())/1e3},defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[T.PREVIOUS_WEEK,new Je({key:T.PREVIOUS_WEEK,display:"Previous week",timeframeText:"Week",timeframeLength:()=>60*60*24*7,defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[T.PREVIOUS_MONTH,new Xe({key:T.PREVIOUS_MONTH,display:"Previous month",timeframeText:"Month",timeframeLength:()=>{let e=0;const t=V(new Date),r=V(J(new Date,1));return t.getTimezoneOffset()!==r.getTimezoneOffset()&&(e=et(t,r)),60*60*24*Ge(new Date().setMonth(new Date().getMonth()-1))+ze(e)},defaultResponseGranularity:y.DAILY,dataGranularity:y.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})]]);function et(e,t){return qe(e.getTimezoneOffset()-t.getTimezoneOffset())}const tt={general:{notAvailable:"N/A"},metricCard:{short:{traffic:"Requests",errorRate:"Error Rate",latency:"P99 Latency"},long:{traffic:"Number of Requests",errorRate:"Average Error Rate",latency:"P99 Latency"}}};function rt(){const e=fe.createI18n("en-us",tt);return{i18n:e,i18nT:fe.i18nTComponent(e)}}var N=(e=>(e.API_PRODUCT="API_PRODUCT",e.API_PRODUCT_VERSION="API_PRODUCT_VERSION",e.RUNTIME_GROUP="RUNTIME_GROUP",e.GATEWAY_INSTANCE_ID="GATEWAY_INSTANCE_ID",e.GATEWAY_SERVICE="GATEWAY_SERVICE",e.ROUTE="ROUTE",e.APPLICATION="APPLICATION",e.STATUS_CODE="STATUS_CODE",e.STATUS_CODE_GROUPED="STATUS_CODE_GROUPED",e.TIME="TIME",e.ORGANIZATION="ORGANIZATION",e))(N||{}),K=(e=>(e.REQUEST_COUNT="REQUEST_COUNT",e.REQUEST_PER_MINUTE="REQUEST_PER_MINUTE",e.RESPONSE_LATENCY_P99="RESPONSE_LATENCY_P99",e.RESPONSE_LATENCY_P95="RESPONSE_LATENCY_P95",e.RESPONSE_LATENCY_P50="RESPONSE_LATENCY_P50",e.RESPONSE_SIZE_P99="RESPONSE_SIZE_P99",e.RESPONSE_SIZE_P95="RESPONSE_SIZE_P95",e.RESPONSE_SIZE_P50="RESPONSE_SIZE_P50",e.REQUEST_SIZE_P99="REQUEST_SIZE_P99",e.REQUEST_SIZE_P95="REQUEST_SIZE_P95",e.REQUEST_SIZE_P50="REQUEST_SIZE_P50",e))(K||{}),ee=(e=>(e.IN="IN",e.NOT_IN="NOT_IN",e))(ee||{});const nt=2,B=["1XX","2XX","3XX","4XX","5XX"],Ee=["4XX","5XX"];var Se=(e=>(e.VALIDATING="VALIDATING",e.VALIDATING_HAS_DATA="VALIDATING_HAS_DATA",e.PENDING="PENDING",e.SUCCESS="SUCCESS",e.SUCCESS_HAS_DATA="SUCCESS_HAS_DATA",e.ERROR="ERROR",e.STALE_IF_ERROR="STALE_IF_ERROR",e))(Se||{});const at=e=>{var t,r,i,a,n;return e?!!((t=Object.keys(e))!=null&&t.length||(r=e.data)!=null&&r.length||(a=(i=e.data)==null?void 0:i.data)!=null&&a.length||!((n=e.data)!=null&&n.data)&&typeof e.data=="object"&&Object.keys(e==null?void 0:e.data).length):!1};function it(e=s.ref({}),t,r,i=at){const a=s.ref("PENDING");return s.watchEffect(()=>{const n=i(e.value);if(e.value&&n&&r.value){a.value="VALIDATING_HAS_DATA";return}if(e.value&&r.value){a.value="VALIDATING";return}if(e.value&&t.value){a.value="STALE_IF_ERROR";return}if(e.value===void 0&&!t.value){a.value="PENDING";return}if(e.value&&!t.value&&n){a.value="SUCCESS_HAS_DATA";return}if(e.value&&!t.value){a.value="SUCCESS";return}e.value===void 0&&t&&(a.value="ERROR")}),{state:a,swrvState:Se}}const k=Symbol("default"),te=N.STATUS_CODE_GROUPED,Re=(e,t,r,i,a)=>{e[t][r]||(e[t][r]={}),e[t][r][i]=a};function st(e,t,r){var f;const i=((f=e.meta.metricNames)==null?void 0:f[0])||"",a=Object.keys(e.meta.dimensions||{}),n=!!a.find(d=>d===te),l=a.find(d=>d!==te);return a.length>2||a.length>1&&!n?(console.error("Don't know how to work with provided dimensions:",a),{previous:{[k]:{[k]:0}},current:{[k]:{[k]:0}}}):e.records.reduce((d,o)=>{const u=o.event[i],c=l?o.event[l]:k,m=n?o.event[te]:k;return new Date(o.timestamp).getTime()===t.startDate().getTime()&&r?Re(d,"previous",c,m,u):Re(d,"current",c,m,u),d},{previous:{},current:{}})}function ot(e){e.queryReady===void 0&&(e.queryReady=s.computed(()=>!0));const t=s.computed(()=>e.withTrend?new We(e.timeframe.value):new ve(e.timeframe.value)),r=s.computed(()=>{var c,m;return{metrics:e.metrics,dimensions:[...(c=e.dimensions)!=null&&c.length?[...e.dimensions]:[],...e.withTrend?[N.TIME]:[]],granularityMs:t.value.granularityMs(),...(m=e.filter.value)!=null&&m.length?{filter:e.filter.value}:{}}}),i=s.computed(()=>`${t.value.endDate().toString()}-${t.value.startDate().toString()}`),a=s.computed(()=>{var m,h,p,g;if(!((m=e.queryReady)!=null&&m.value)||e.featureFlags&&!e.featureFlags.every(S=>S))return null;const c=(h=e.filter)!=null&&h.value?JSON.stringify(e.filter.value):"";return`metric-fetcher-${i.value}-${(p=e.dimensions)==null?void 0:p.join("-")}-${(g=e.metrics)==null?void 0:g.join("-")}-${c}`}),{response:n,error:l,isValidating:f}=x.useRequest(()=>a.value,()=>e.dataFetcher(t.value,r.value),{refreshInterval:e.refreshInterval,revalidateOnFocus:!1,errorRetryCount:nt}),{state:d,swrvState:o}=it(n,l,f),u=s.computed(()=>{var c,m,h,p,g,S,A,E,v,U;return!((h=(m=(c=n.value)==null?void 0:c.data)==null?void 0:m.records)!=null&&h.length)||!((S=(g=(p=n.value)==null?void 0:p.data)==null?void 0:g.meta)!=null&&S.dimensions)||!((U=(v=(E=(A=n.value)==null?void 0:A.data)==null?void 0:E.meta)==null?void 0:v.metricNames)!=null&&U.length)?{current:{},previous:{}}:st(n.value.data,t.value,!!e.withTrend)});return{isLoading:s.computed(()=>o.PENDING===d.value),hasError:s.computed(()=>o.ERROR===d.value),raw:n,mapped:u}}const P=(e,t,r=k,i)=>(i??[k]).reduce((n,l)=>{const f=e[t][r];return f?n+(f[l]||0):n},0);function lt(e){const{title:t,record:r,hasError:i,increaseIsBad:a,formatValueFn:n}=e;return s.computed(()=>{let l=0,f=0;if(r!=null&&r.value)try{l=P(r.value,"current",e.lookupKey,e.sumGroupedValues),f=P(r.value,"previous",e.lookupKey,e.sumGroupedValues)}catch(d){console.error("Metric card data doesn't have the expected structure:",d)}return{hasError:i.value,currentValue:l,previousValue:f,title:t.value,increaseIsBad:!!a,formatValueFn:n}})}var re=new WeakMap,we=0;function ut(e){if(!e.length)return"";for(var t="arg",r=0;r<e.length;++r){var i=void 0;e[r]===null||typeof e[r]!="object"&&typeof e[r]!="function"?typeof e[r]=="string"?i='"'+e[r]+'"':i=String(e[r]):re.has(e[r])?i=re.get(e[r]):(i=we,re.set(e[r],we++)),t+="@"+i}return t}function ct(e){if(typeof e=="function")try{e=e()}catch{e=""}return Array.isArray(e)?e=ut(e):e=String(e||""),e}var ne=function(){function e(t){t===void 0&&(t=0),this.items=new Map,this.ttl=t}return e.prototype.serializeKey=function(t){return ct(t)},e.prototype.get=function(t){var r=this.serializeKey(t);return this.items.get(r)},e.prototype.set=function(t,r,i){var a=this.serializeKey(t),n=i||this.ttl,l=Date.now(),f={data:r,createdAt:l,expiresAt:n?l+n:1/0};this.dispatchExpire(n,f,a),this.items.set(a,f)},e.prototype.dispatchExpire=function(t,r,i){var a=this;t&&setTimeout(function(){var n=Date.now(),l=n>=r.expiresAt;l&&a.delete(i)},t)},e.prototype.delete=function(t){this.items.delete(t)},e}();function dt(){return typeof navigator.onLine<"u"?navigator.onLine:!0}function ft(){return typeof document<"u"&&typeof document.visibilityState<"u"?document.visibilityState!=="hidden":!0}var mt=function(e){return fetch(e).then(function(t){return t.json()})};const ae={isOnline:dt,isDocumentVisible:ft,fetcher:mt};var O=globalThis&&globalThis.__assign||function(){return O=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++){t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},O.apply(this,arguments)},Y=globalThis&&globalThis.__awaiter||function(e,t,r,i){function a(n){return n instanceof r?n:new r(function(l){l(n)})}return new(r||(r=Promise))(function(n,l){function f(u){try{o(i.next(u))}catch(c){l(c)}}function d(u){try{o(i.throw(u))}catch(c){l(c)}}function o(u){u.done?n(u.value):a(u.value).then(f,d)}o((i=i.apply(e,t||[])).next())})},F=globalThis&&globalThis.__generator||function(e,t){var r={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},i,a,n,l;return l={next:f(0),throw:f(1),return:f(2)},typeof Symbol=="function"&&(l[Symbol.iterator]=function(){return this}),l;function f(o){return function(u){return d([o,u])}}function d(o){if(i)throw new TypeError("Generator is already executing.");for(;r;)try{if(i=1,a&&(n=o[0]&2?a.return:o[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,o[1])).done)return n;switch(a=0,n&&(o=[o[0]&2,n.value]),o[0]){case 0:case 1:n=o;break;case 4:return r.label++,{value:o[1],done:!1};case 5:r.label++,a=o[1],o=[0];continue;case 7:o=r.ops.pop(),r.trys.pop();continue;default:if(n=r.trys,!(n=n.length>0&&n[n.length-1])&&(o[0]===6||o[0]===2)){r=0;continue}if(o[0]===3&&(!n||o[1]>n[0]&&o[1]<n[3])){r.label=o[1];break}if(o[0]===6&&r.label<n[1]){r.label=n[1],n=o;break}if(n&&r.label<n[2]){r.label=n[2],r.ops.push(o);break}n[2]&&r.ops.pop(),r.trys.pop();continue}o=t.call(e,r)}catch(u){o=[6,u],a=0}finally{i=n=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}},ht=globalThis&&globalThis.__read||function(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var i=r.call(e),a,n=[],l;try{for(;(t===void 0||t-- >0)&&!(a=i.next()).done;)n.push(a.value)}catch(f){l={error:f}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}finally{if(l)throw l.error}}return n},yt=globalThis&&globalThis.__spreadArray||function(e,t,r){if(r||arguments.length===2)for(var i=0,a=t.length,n;i<a;i++)(n||!(i in t))&&(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))},De=new ne,q=new ne,ie=new ne,_e={cache:De,refreshInterval:0,ttl:0,serverTTL:1e3,dedupingInterval:2e3,revalidateOnFocus:!0,revalidateDebounce:0,shouldRetryOnError:!0,errorRetryInterval:5e3,errorRetryCount:5,fetcher:ae.fetcher,isOnline:ae.isOnline,isDocumentVisible:ae.isDocumentVisible};function pt(e,t,r){var i=q.get(e);if(i)i.data.push(t);else{var a=5e3;q.set(e,[t],r>0?r+a:r)}}function gt(e,t,r){if(r.isDocumentVisible()&&!(r.errorRetryCount!==void 0&&t>r.errorRetryCount)){var i=Math.min(t||0,r.errorRetryCount),a=i*r.errorRetryInterval;setTimeout(function(){e(null,{errorRetryCount:i+1,shouldRetryOnError:!0})},a)}}var Ce=function(e,t,r,i){return r===void 0&&(r=De),i===void 0&&(i=_e.ttl),Y(void 0,void 0,void 0,function(){var a,n,l,f,d,o,u;return F(this,function(c){switch(c.label){case 0:if(!Tt(t))return[3,5];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,t];case 2:return a=c.sent(),[3,4];case 3:return f=c.sent(),n=f,[3,4];case 4:return[3,6];case 5:a=t,c.label=6;case 6:if(l=!1,d={data:a,error:n,isValidating:l},typeof a<"u")try{r.set(e,d,i)}catch(m){console.error("swrv(mutate): failed to set cache",m)}return o=q.get(e),o&&o.data.length&&(u=o.data.filter(function(m){return m.key===e}),u.forEach(function(m,h){typeof d.data<"u"&&(m.data=d.data),m.error=d.error,m.isValidating=d.isValidating;var p=h===u.length-1;p||delete u[h]}),u=u.filter(Boolean)),[2,d]}})})};function vt(){for(var e=this,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var i,a,n=O({},_e),l=!1,f=!1,d=s.getCurrentInstance(),o=(d==null?void 0:d.proxy)||d;if(!o)return console.error("Could not get current instance, check to make sure that `useSwrv` is declared in the top level of the setup function."),null;var u=(o==null?void 0:o.$isServer)||!1;t.length>=1&&(i=t[0]),t.length>=2&&(a=t[1]),t.length>2&&(n=O(O({},n),t[2]));var c=u?n.serverTTL:n.ttl,m=typeof i=="function"?i:s.ref(i);typeof a>"u"&&(a=n.fetcher);var h=null;h||(h=s.reactive({data:void 0,error:void 0,isValidating:!0,key:null}));var p=function(E,v){return Y(e,void 0,void 0,function(){var U,D,H,$,le,Ne,ue,ke=this;return F(this,function(ce){switch(ce.label){case 0:return U=h.data===void 0,D=m.value,D?(H=n.cache.get(D),$=H&&H.data,h.isValidating=!0,$&&(h.data=$.data,h.error=$.error),le=E||a,!le||!n.isDocumentVisible()&&!U||(v==null?void 0:v.forceRevalidate)!==void 0&&!(v!=null&&v.forceRevalidate)?(h.isValidating=!1,[2]):H&&(Ne=!!(Date.now()-H.createdAt>=n.dedupingInterval||v!=null&&v.forceRevalidate),!Ne)?(h.isValidating=!1,[2]):(ue=function(){return Y(ke,void 0,void 0,function(){var M,Le,de,Ue;return F(this,function(W){switch(W.label){case 0:return M=ie.get(D),M?[3,2]:(Le=Array.isArray(D)?D:[D],de=le.apply(void 0,yt([],ht(Le),!1)),ie.set(D,de,n.dedupingInterval),[4,Ce(D,de,n.cache,c)]);case 1:return W.sent(),[3,4];case 2:return[4,Ce(D,M.data,n.cache,c)];case 3:W.sent(),W.label=4;case 4:return h.isValidating=!1,ie.delete(D),h.error!==void 0&&(Ue=!l&&n.shouldRetryOnError&&(v?v.shouldRetryOnError:!0),Ue&&gt(p,v?v.errorRetryCount:1,n)),[2]}})})},$&&n.revalidateDebounce?(setTimeout(function(){return Y(ke,void 0,void 0,function(){return F(this,function(M){switch(M.label){case 0:return l?[3,2]:[4,ue()];case 1:M.sent(),M.label=2;case 2:return[2]}})})},n.revalidateDebounce),[3,3]):[3,1])):[2];case 1:return[4,ue()];case 2:ce.sent(),ce.label=3;case 3:return[2]}})})},g=function(){return Y(e,void 0,void 0,function(){return F(this,function(E){return[2,p(null,{shouldRetryOnError:!1})]})})},S=null;s.onMounted(function(){var E=function(){return Y(e,void 0,void 0,function(){return F(this,function(v){switch(v.label){case 0:return!h.error&&n.isOnline()?[4,p()]:[3,2];case 1:return v.sent(),[3,3];case 2:S&&clearTimeout(S),v.label=3;case 3:return n.refreshInterval&&!l&&(S=setTimeout(E,n.refreshInterval)),[2]}})})};n.refreshInterval&&(S=setTimeout(E,n.refreshInterval)),n.revalidateOnFocus&&(document.addEventListener("visibilitychange",g,!1),window.addEventListener("focus",g,!1))}),s.onUnmounted(function(){l=!0,S&&clearTimeout(S),n.revalidateOnFocus&&(document.removeEventListener("visibilitychange",g,!1),window.removeEventListener("focus",g,!1));var E=q.get(m.value);E&&(E.data=E.data.filter(function(v){return v!==h}))});try{s.watch(m,function(E){s.isReadonly(m)||(m.value=E),h.key=E,h.isValidating=!!E,pt(m.value,h,c),!u&&!f&&m.value&&p(),f=!1},{immediate:!0})}catch{}var A=O(O({},s.toRefs(h)),{mutate:function(E,v){return p(E,O(O({},v),{forceRevalidate:!0}))}});return A}function Tt(e){return e!==null&&typeof e=="object"&&typeof e.then=="function"}function Et(e,t,r){const{data:i,error:a,isValidating:n,mutate:l}=vt(e,t,{revalidateDebounce:500,revalidateOnFocus:!1,dedupingInterval:100,...r});return{data:s.computed(()=>{var d;return(d=i.value)==null?void 0:d.data}),response:i,error:a,isValidating:n,revalidate:l}}const x={useI18n:rt,useMetricCardBuilder:lt,useMetricFetcher:ot,useRequest:Et},Ie=Symbol("METRICS_PROVIDER_KEY"),St=e=>{const{dimension:t,dimensionFilterValue:r,additionalFilter:i,queryReady:a,timeframe:n,hasTrendAccess:l,refreshInterval:f,dataFetcher:d}=e;if(r&&!t)throw new Error("Must provide a dimension if filtering by a value");const o=!!(t&&r),u=!!(t&&!r),c=s.computed(()=>{const S=[];return o&&S.push({dimension:t,type:ee.IN,values:[r]}),i.value&&S.push(...i.value),S}),m={metrics:[K.REQUEST_COUNT],dimensions:[...t&&!o?[t]:[],N.STATUS_CODE_GROUPED],filter:c,queryReady:a,timeframe:n,withTrend:l&&!u,refreshInterval:f,dataFetcher:d},h={metrics:[K.RESPONSE_LATENCY_P99],...t&&!o?{dimensions:[t]}:{},filter:c,queryReady:a,timeframe:n,withTrend:l&&!u,refreshInterval:f,dataFetcher:d},p=x.useMetricFetcher(m),g=x.useMetricFetcher(h);return{trafficData:p,latencyData:g}},Rt=s.defineComponent({__name:"MetricsProviderInternal",props:{maxTimeframe:{default:T.THIRTY_DAY},overrideTimeframe:{default:void 0},dimension:{default:void 0},filterValue:{default:void 0},additionalFilter:{default:void 0},queryReady:{type:Boolean,default:!0},dataFetcher:{},hasTrendAccess:{type:Boolean},refreshInterval:{},longCardTitles:{type:Boolean,default:!1}},setup(e){const t=e;if(t.dimension&&!{}.hasOwnProperty.call(N,t.dimension))throw new Error(`Attempted to use MetricsProvider with an invalid dimension: ${t.dimension}`);const r=s.computed(()=>{if(t.overrideTimeframe)return t.overrideTimeframe;const n=t.hasTrendAccess?Te.get(t.maxTimeframe):Te.get(T.ONE_DAY);if(!n)throw new Error("Metrics provider failed to resolve fallback timeframe.");return n}),{trafficData:i,latencyData:a}=St({dimension:t.dimension,dimensionFilterValue:t.filterValue,additionalFilter:s.toRef(t,"additionalFilter"),queryReady:s.toRef(t,"queryReady"),timeframe:r,hasTrendAccess:t.hasTrendAccess,refreshInterval:t.refreshInterval,dataFetcher:t.dataFetcher});return s.provide(Ie,{data:{traffic:i,latency:a},hasTrendAccess:t.hasTrendAccess,longCardTitles:t.longCardTitles}),(n,l)=>s.renderSlot(n.$slots,"default",{hasTrendAccess:t.hasTrendAccess,timeframe:r.value})}});function wt(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ae={exports:{}};(function(e){(function(){function t(o,u){if(u.separator===!1||o<1e3)return o.toString();var c=typeof u.separator=="string"?u.separator:",",m=[],h=Math.round(o).toString().split("");return h.reverse().forEach(function(p,g){g&&g%3===0&&m.push(c),m.push(p)}),m.reverse().join("")}function r(o,u,c){var m=o/u,h=c.round?"round":"floor";return c.decimal===!1?(o=Math[h](m),o.toString()):(c.precision?o=m:o=m<10?Math[h](m*10)/10:Math[h](m),o=o.toString(),typeof c.decimal=="string"&&(o=o.replace(".",c.decimal)),o)}var i=1e3,a=1e4,n=1e6,l=1e9,f=1e12;function d(o,u){var c;u=u||{};var m=o<0;m&&(o=Math.abs(o)),u.precision&&(o=parseFloat(o.toPrecision(u.precision)));var h=u.min10k?a:i;return o<h||u.precision&&u.precision>Math.log10(o)?c=t(r(o,1,u),u):o<n?c=r(o,i,u)+"k":o<l?c=r(o,n,u)+"m":o<f?c=t(r(o,l,u),u)+"b":c=t(r(o,f,u),u)+"t",m&&(c="-"+c),u.capital&&(c=c.toUpperCase()),u.prefix&&(c=u.prefix+c),u.suffix&&(c=c+u.suffix),c}d.addCommas=t,e.exports=d})()})(Ae);var Dt=Ae.exports;const _t=wt(Dt);var b=(e=>(e.Small="sm",e.Medium="md",e.Large="lg",e.ExtraLarge="xl",e))(b||{});const se=2,Oe=se+2,Ct=(e,t,r=!1)=>{let i=!t||Number(e.toFixed(Oe))===0?0:Number(e.toFixed(Oe))>0?1:-1;return r&&(i*=-1),i},It=(e,t,r)=>t?`${Math.abs(e*100).toFixed(se)}%`:r,At=(e,t)=>t===0?0:e/t-1,Ot=(e,t=!1)=>(t&&(e*=-1),e>0?"arrowUp":e<0?"arrowDown":"noData"),bt={class:"metricscard"},Nt={key:0,class:"metricscard-error"},kt={key:1,class:"metricscard-value"},Lt=s.defineComponent({__name:"MetricsCard",props:{title:{type:String,default:"0%",required:!0},tooltip:{type:String,required:!1,default:""},timeframe:{type:String,required:!1,default:""},metricValue:{type:String,default:""},metricChange:{type:String,required:!0},changePolarity:{type:Number,required:!0},icon:{type:String,default:""},hasError:{type:Boolean,default:!1},errorMessage:{type:String,default:"Vitals data error"},cardSize:{type:String,required:!1,default:()=>"lg"}},setup(e){const t=e,r=l=>{const f={red:"var(--kong-ui-metric-card-trend-negative, var(--red-500, '#d44324'))",green:"var(--kong-ui-metric-card-trend-positive, var(--green-500, '#07a88d'))",grey:"var(--kong-ui-metric-card-trend-neutral, var(--grey-500, '#6f7787'))"};return l>0?f.green:l<0?f.red:f.grey},i=l=>l>0?"positive":l<0?"negative":"neutral",a=[b.Medium,b.Large].includes(t.cardSize),n=t.cardSize===b.ExtraLarge?"48px":[b.Medium,b.Large].includes(t.cardSize)?"22px":"16px";return(l,f)=>{const d=s.resolveComponent("KIcon"),o=s.resolveComponent("KTooltip");return s.openBlock(),s.createElementBlock("div",bt,[s.createElementVNode("div",{class:s.normalizeClass(["metricscard-title",e.cardSize])},[s.createElementVNode("span",null,s.toDisplayString(e.title),1),e.tooltip?(s.openBlock(),s.createBlock(o,{key:0,class:"metricscard-tooltip",label:e.tooltip,placement:"right"},{default:s.withCtx(()=>[s.createVNode(d,{icon:"info",size:"12"})]),_:1},8,["label"])):s.createCommentVNode("",!0)],2),e.hasError?(s.openBlock(),s.createElementBlock("div",Nt,[s.createVNode(d,{icon:"warning",size:"20"}),s.createElementVNode("div",null,s.toDisplayString(e.errorMessage),1)])):(s.openBlock(),s.createElementBlock("div",kt,[s.createElementVNode("div",{style:s.normalizeStyle(`font-size:${s.unref(n)}`)},s.toDisplayString(e.metricValue),5),s.unref(a)?(s.openBlock(),s.createElementBlock("div",{key:0,class:s.normalizeClass(["metricscard-value-trend",i(e.changePolarity)])},[e.changePolarity!==0?(s.openBlock(),s.createBlock(d,{key:0,color:r(e.changePolarity),icon:e.icon,size:"18"},null,8,["color","icon"])):s.createCommentVNode("",!0),s.createElementVNode("div",null,s.toDisplayString(e.metricChange),1)],2)):s.createCommentVNode("",!0)]))])}}}),oe=(e,t)=>{const r=e.__vccOpts||e;for(const[i,a]of t)r[i]=a;return r},Ut=oe(Lt,[["__scopeId","data-v-ee980c4c"]]),Mt={},Vt={class:"loading-tabs"};function Pt(e,t){const r=s.resolveComponent("KSkeletonBox");return s.openBlock(),s.createElementBlock("div",Vt,[s.createVNode(r,{width:"100"}),s.createVNode(r,{width:"75"})])}const Yt=oe(Mt,[["render",Pt],["__scopeId","data-v-e4239529"]]),Ft={key:0,class:"error-display"},xt={key:0,class:"error-display-message"},Bt=oe(s.defineComponent({__name:"MetricCardContainer",props:{fallbackDisplayText:{type:String,required:!0},cards:{type:Array,required:!0},errorMessage:{type:String,required:!1,default:""},loading:{type:Boolean,required:!1,default:!1},hasTrendAccess:{type:Boolean,required:!1,default:!0},cardSize:{type:String,required:!1,default:()=>b.Large}},setup(e){const t=e,r=s.computed(()=>t.cards.every(a=>(a==null?void 0:a.hasError)===!0)),i=a=>{const n=At(a.currentValue,a.previousValue)||0,l=Ct(n,t.hasTrendAccess,a.increaseIsBad);return{metricValue:a.formatValueFn?a.formatValueFn(a.currentValue):_t(a.currentValue,{capital:!0,round:!0})||"0",metricChange:a.formatChangeFn?a.formatChangeFn(n):It(n,t.hasTrendAccess,t.fallbackDisplayText),changePolarity:l,icon:Ot(l,a.increaseIsBad),cardSize:t.cardSize}};return(a,n)=>{const l=s.resolveComponent("KIcon");return s.openBlock(),s.createElementBlock("div",{class:s.normalizeClass(["kong-ui-public-metric-card-container",e.cardSize])},[s.unref(r)?(s.openBlock(),s.createElementBlock("div",Ft,[s.createVNode(l,{class:"error-display-icon",icon:"warning",size:"24"}),e.errorMessage?(s.openBlock(),s.createElementBlock("div",xt,s.toDisplayString(e.errorMessage),1)):s.createCommentVNode("",!0)])):(s.openBlock(!0),s.createElementBlock(s.Fragment,{key:1},s.renderList(e.cards,(f,d)=>(s.openBlock(),s.createElementBlock(s.Fragment,null,[e.loading?(s.openBlock(),s.createBlock(Yt,{key:`skeleton-${d}`,class:s.normalizeClass(e.cardSize===s.unref(b).Small?"loading-tabs-small":"loading-tabs-large")},null,8,["class"])):(s.openBlock(),s.createBlock(Ut,s.mergeProps({key:d},i(f),{"card-size":e.cardSize,"error-message":e.errorMessage,"has-error":f.hasError,title:f.title,tooltip:f.tooltip}),null,16,["card-size","error-message","has-error","title","tooltip"]))],64))),256))],2)}}}),[["__scopeId","data-v-390af84f"]]),qt="",Ht=s.defineComponent({__name:"MetricsConsumer",props:{lookupKey:{default:void 0},cardSize:{default:b.Large},cardToDisplay:{default:void 0}},setup(e){const t=e,r=s.inject(Ie);if(!r)throw new Error("MetricsConsumer must be nested inside a MetricsProvider instance.");const{traffic:i,latency:a}=r.data,{i18n:n}=x.useI18n(),l=x.useMetricCardBuilder({title:s.computed(()=>r.longCardTitles?n.t("metricCard.long.traffic"):n.t("metricCard.short.traffic")),record:i.mapped,hasError:i.hasError,lookupKey:t.lookupKey,sumGroupedValues:B}),f=g=>`${g.toFixed(se)}%`,d=s.computed(()=>{const g=i.mapped.value,S=P(g,"current",t.lookupKey,Ee),A=P(g,"current",t.lookupKey,B),E=S/A*100||0,v=P(g,"previous",t.lookupKey,Ee),U=P(g,"previous",t.lookupKey,B),D=v/U*100||0;return{hasError:i.hasError.value,currentValue:E,previousValue:D,formatValueFn:f,title:r.longCardTitles?n.t("metricCard.long.errorRate"):n.t("metricCard.short.errorRate"),increaseIsBad:!0}}),o=g=>`${g}ms`,u=x.useMetricCardBuilder({title:s.computed(()=>r.longCardTitles?n.t("metricCard.long.latency"):n.t("metricCard.short.latency")),hasError:a.hasError,record:a.mapped,lookupKey:t.lookupKey,increaseIsBad:!0,formatValueFn:o}),c=s.computed(()=>t.cardToDisplay==="TRAFFIC"?[l.value]:t.cardToDisplay==="ERROR_RATE"?[d.value]:t.cardToDisplay==="LATENCY"?[u.value]:[l.value,d.value,u.value]),m=s.computed(()=>t.cardToDisplay==="TRAFFIC"||t.cardToDisplay==="ERROR_RATE"?i.isLoading.value:t.cardToDisplay==="LATENCY"?a.isLoading.value:i.isLoading.value||a.isLoading.value),h=s.computed(()=>({cards:c.value,loading:m.value,hasTrendAccess:r.hasTrendAccess,fallbackDisplayText:n.t("general.notAvailable"),cardSize:t.cardSize,hideTitle:!0})),p=s.computed(()=>({loading:h.value.loading,trafficCard:l.value,errorRateCard:d.value,latencyCard:u.value,errorRateFormatted:f(d.value.currentValue),latencyFormatted:o(u.value.currentValue)}));return(g,S)=>s.renderSlot(g.$slots,"default",{cardValues:p.value},()=>[s.createVNode(s.unref(Bt),s.normalizeProps(s.guardReactiveProps(h.value)),null,16)])}}),j=e=>new Date(e),$t=(e,t)=>{const r=e.body,{startMs:i,endMs:a}=e.query,n=typeof i!="number"?parseInt(i,10):i,l=typeof a!="number"?parseInt(a,10):a;e.reply({statusCode:200,body:be(r,n,l,t)})},be=(e,t,r,i)=>{var c,m;const a=e.granularityMs||0,n=a?(r-t)/a:1;if(n!==1&&n!==2)throw new Error("Query did not request 1 or 2 records. Perhaps there's a chart query on the same page interfering with the stub?");if((e.dimensions??[]).length>2)throw new Error(`Explore only supports 0-2 dimensions; got: ${JSON.stringify(e.dimensions)}`);const l=(e.dimensions??[]).find(h=>h!=="TIME"),f=(i==null?void 0:i.dimensionNames)??[],d=Math.max(f.length,1),o=[];for(let h=0;h<n;h++)for(let p=0;p<d;p++){const g=l?{[l]:f[p]}:{};(c=e.dimensions)!=null&&c.includes(N.STATUS_CODE_GROUPED)?B.forEach(S=>{const A=e.metrics.reduce((E,v)=>(E[v]=(n-h)*1e3+100*p+1,E),{...g,STATUS_CODE_GROUPED:S});o.push({version:"v1",timestamp:h===0?j(t).toISOString():j(t+a).toISOString(),event:A})}):o.push({version:"v1",timestamp:h===0?j(t).toISOString():j(t+a).toISOString(),event:e.metrics.reduce((S,A)=>(S[A]=(n-h)*1e3+100*p+1,S),{...g})})}const u={start:t,end:r,granularity:a,dimensions:l?{[l]:f,...(m=e.dimensions)!=null&&m.includes(N.STATUS_CODE_GROUPED)?{STATUS_CODE_GROUPED:B}:{}}:{},metricNames:e.metrics};return{records:o,meta:u}};R.EXPLORE_V2_AGGREGATIONS=K,R.EXPLORE_V2_DIMENSIONS=N,R.EXPLORE_V2_FILTER_TYPES=ee,R.MetricsConsumer=Ht,R.MetricsProviderInternal=Rt,R.mockExploreResponse=be,R.mockExploreResponseFromCypress=$t,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=vitals-metric-provider.umd.js.map