New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

statful-client-javascript

Package Overview
Dependencies
Maintainers
5
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

statful-client-javascript - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

2

bower.json
{
"name": "statful-client-javascript",
"version": "2.0.4",
"version": "2.1.1",
"description": "Statful client for Javascript applications",

@@ -5,0 +5,0 @@ "main": "dist/statful.js",

/**
* statful-client-javascript 2.1.0
* Copyright 2017 Statful <https://www.statful.com/>
* statful-client-javascript 2.1.1
* Copyright 2018 Statful <https://www.statful.com/>
*/

@@ -5,0 +5,0 @@

/**
* statful-client-javascript 2.1.0
* Copyright 2017 Statful <https://www.statful.com/>
* statful-client-javascript 2.1.1
* Copyright 2018 Statful <https://www.statful.com/>
*/
var statful=function(){"use strict";var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),i=function(){function e(r){t(this,e),this.debugEnabled=r||!1}return r(e,[{key:"info",value:function(){this.debugEnabled&&console.info.apply(console,Array.prototype.slice.call(arguments))}},{key:"debug",value:function(){this.debugEnabled&&console.debug.apply(console,Array.prototype.slice.call(arguments))}},{key:"error",value:function(){this.debugEnabled&&console.error.apply(console,Array.prototype.slice.call(arguments))}}]),e}(),n=function(){function e(r){t(this,e),this.config={},Object.assign(this.config,r),this.logger=new i(this.config.debug),this.config&&this.config.flushInterval&&this.registerQueue(this.config.flushInterval)}return r(e,[{key:"sendData",value:function(e){var t=this,r=this.config.apiAddress+"/beacon/metrics",i=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var n=new XMLHttpRequest;n.open("POST",r,!0),n.timeout=this.config.timeout,n.setRequestHeader("Content-type","application/json"),n.send(i),n.onreadystatechange=function(){200==n.status||201==n.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",r,n.status)}}}},{key:"registerQueue",value:function(e){var t=this,r=void 0;return this.metricsQueue=[],"number"==typeof e&&e>0&&(r=setInterval(function(){t.metricsQueue.length>0&&(t.sendData(t.metricsQueue),t.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(r)}),!0)}},{key:"addMetric",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e&&"function"==typeof e.isValid&&e.isValid()?this.shouldAddMetric(e)?t?this.metricsQueue.push(e):this.sendData([e]):this.logger.debug("Metric was discarded due to sample rate."):this.logger.error("Invalid metric.")}},{key:"shouldAddMetric",value:function(){var e=((arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).sampleRate||this.config.sampleRate||100)/100;return Math.random()<=e}}]),e}(),a=["avg","count","sum","first","last","p90","p95","min","max"],s=[10,30,60,120,180,300],o=function(){function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};t(this,e),this.name=r,this.type=i,this.value=n;var o=[],u=[],g=0;s[i]&&(o=s[i].tags,u=s[i].aggregations,g=s[i].aggregationFrequency),this.tags=this.buildTags(a.tags,s.tags,o,s.app),this.aggregations=this.buildAggregations(a.aggregations,s.aggregations,u),this.aggregationFrequency=this.buildAggregationFrequency(a.aggregationFrequency,s.aggregationFrequency,g),this.namespace=a.namespace||s.namespace,this.sampleRate=a.sampleRate||s.sampleRate}return r(e,[{key:"buildTags",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments[3],n={};return Object.assign(n,t),Object.assign(n,r),Object.assign(n,e),!n.app&&i&&(n.app=i),n}},{key:"buildAggregations",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],i=[];return i=i.concat(t),i=i.concat(r).filter(this.uniq),i=i.concat(e).filter(this.uniq),this.filterAggregations(i)}},{key:"uniq",value:function(e,t,r){return e&&r.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,r){var i=e||r||t;return this.filterAggregationFrequency(i)}},{key:"filterAggregations",value:function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return a.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return s.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),e}(),u={dryrun:!1,debug:!1,app:void 0,namespace:"web",tags:{},aggregations:[],aggregationFrequency:10,timer:{tags:{unit:"ms"},aggregations:["avg","p90","count"]},counter:{tags:{},aggregations:["sum","count"]},gauge:{tags:{},aggregations:["last"]},timeout:2e3,flushInterval:1e4,sampleRate:100};return function(){function a(){t(this,a)}return r(a,null,[{key:"initialize",value:function(t){this.config={apiAddress:"https://beacon.statful.com"},"object"===(void 0===t?"undefined":e(t))&&null!==t||(t={}),Object.assign(this.config,u),Object.assign(this.config,t),this.logger=new i(this.config.debug),this.util=new n(this.config)}},{key:"measureTimeUserTiming",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=window.performance.getEntriesByName(e).filter(function(e){return"measure"===e.entryType}),r=void 0;return t.length>0?r=t[t.length-1].duration:this.logger.debug("Measure "+e+" not found"),r}},{key:"clearMarks",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMarks(e)}):window.performance.clearMarks()}catch(e){this.logger.error(e)}}},{key:"clearMeasures",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMeasures(e)}):window.performance.clearMeasures()}catch(e){this.logger.error(e)}}},{key:"registerMark",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";try{this.logger.debug("Register Mark",e),e?window.performance.mark(e):this.logger.error("Undefined resource name to register as a mark")}catch(e){this.logger.error(e)}}},{key:"registerMeasure",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,r),e){var i={clearMarks:!1,clearMeasures:!1};Object.assign(i,r),i.endMark||(this.registerMark(e),i.endMark=e),window.performance.measure(e,i.startMark,i.endMark);var n=this.measureTimeUserTiming(e);if(n){var a=new o(t,"timer",n,i,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");i.clearMarks&&this.clearMarks([i.startMark,i.endMark]),i.clearMeasures&&this.clearMeasures([e])}else this.logger.error("Undefined resource name to register as a measure")}catch(e){this.logger.error(e)}}},{key:"timer",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,r);var i=new o(e,"timer",t,r,this.config);this.util.addMetric(i,!0)}},{key:"counter",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,r);var i=new o(e,"counter",t,r,this.config);i.value=Math.abs(parseInt(i.value,10)),this.util.addMetric(i,!0)}},{key:"gauge",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,r);var i=new o(e,"gauge",t,r,this.config);this.util.addMetric(i,!0)}},{key:"sendMetric",value:function(e,t,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=new o(t,e,r,i,this.config);this.util.addMetric(n,!1)}}]),a}()}();
var statful=function(){"use strict";var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function i(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),e}}(),i=function(){function t(e){g(this,t),this.debugEnabled=e||!1}return r(t,[{key:"info",value:function(){this.debugEnabled&&console.info.apply(console,Array.prototype.slice.call(arguments))}},{key:"debug",value:function(){this.debugEnabled&&console.debug.apply(console,Array.prototype.slice.call(arguments))}},{key:"error",value:function(){this.debugEnabled&&console.error.apply(console,Array.prototype.slice.call(arguments))}}]),t}(),n=function(){function t(e){g(this,t),this.config={},Object.assign(this.config,e),this.logger=new i(this.config.debug),this.config&&this.config.flushInterval&&this.registerQueue(this.config.flushInterval)}return r(t,[{key:"sendData",value:function(e){var t=this,r=this.config.apiAddress+"/beacon/metrics",i=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var n=new XMLHttpRequest;n.open("POST",r,!0),n.timeout=this.config.timeout,n.setRequestHeader("Content-type","application/json"),n.send(i),n.onreadystatechange=function(){200==n.status||201==n.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",r,n.status)}}}},{key:"registerQueue",value:function(e){var t=this,r=void 0;return this.metricsQueue=[],"number"==typeof e&&0<e&&(r=setInterval(function(){0<t.metricsQueue.length&&(t.sendData(t.metricsQueue),t.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(r)}),!0)}},{key:"addMetric",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];e&&"function"==typeof e.isValid&&e.isValid()?this.shouldAddMetric(e)?t?this.metricsQueue.push(e):this.sendData([e]):this.logger.debug("Metric was discarded due to sample rate."):this.logger.error("Invalid metric.")}},{key:"shouldAddMetric",value:function(){var e=((0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).sampleRate||this.config.sampleRate||100)/100;return Math.random()<=e}}]),t}(),a=["avg","count","sum","first","last","p90","p95","min","max"],s=[10,30,60,120,180,300],o=function(){function u(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"",i=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},n=4<arguments.length&&void 0!==arguments[4]?arguments[4]:{};g(this,u),this.name=e,this.type=t,this.value=r;var a=[],s=[],o=0;n[t]&&(a=n[t].tags,s=n[t].aggregations,o=n[t].aggregationFrequency),this.tags=this.buildTags(i.tags,n.tags,a,n.app),this.aggregations=this.buildAggregations(i.aggregations,n.aggregations,s),this.aggregationFrequency=this.buildAggregationFrequency(i.aggregationFrequency,n.aggregationFrequency,o),this.namespace=i.namespace||n.namespace,this.sampleRate=i.sampleRate||n.sampleRate}return r(u,[{key:"buildTags",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},i=arguments[3],n={};return Object.assign(n,t),Object.assign(n,r),Object.assign(n,e),!n.app&&i&&(n.app=i),n}},{key:"buildAggregations",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[],i=[];return i=(i=(i=i.concat(t)).concat(r).filter(this.uniq)).concat(e).filter(this.uniq),this.filterAggregations(i)}},{key:"uniq",value:function(e,t,r){return e&&r.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,r){var i=e||r||t;return this.filterAggregationFrequency(i)}},{key:"filterAggregations",value:function(){return(0<arguments.length&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return a.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return s.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),u}(),u={dryrun:!1,debug:!1,app:void 0,namespace:"web",tags:{},aggregations:[],aggregationFrequency:10,timer:{tags:{unit:"ms"},aggregations:["avg","p90","count"]},counter:{tags:{},aggregations:["sum","count"]},gauge:{tags:{},aggregations:["last"]},timeout:2e3,flushInterval:1e4,sampleRate:100};return function(){function e(){g(this,e)}return r(e,null,[{key:"initialize",value:function(e){this.config={apiAddress:"https://beacon.statful.com"},"object"===(void 0===e?"undefined":t(e))&&null!==e||(e={}),Object.assign(this.config,u),Object.assign(this.config,e),this.logger=new i(this.config.debug),this.util=new n(this.config)}},{key:"measureTimeUserTiming",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=window.performance.getEntriesByName(e).filter(function(e){return"measure"===e.entryType}),r=void 0;return 0<t.length?r=t[t.length-1].duration:this.logger.debug("Measure "+e+" not found"),r}},{key:"clearMarks",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMarks(e)}):window.performance.clearMarks()}catch(e){this.logger.error(e)}}},{key:"clearMeasures",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMeasures(e)}):window.performance.clearMeasures()}catch(e){this.logger.error(e)}}},{key:"registerMark",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";try{this.logger.debug("Register Mark",e),e?window.performance.mark(e):this.logger.error("Undefined resource name to register as a mark")}catch(e){this.logger.error(e)}}},{key:"registerMeasure",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,r),e){var i={clearMarks:!1,clearMeasures:!1};Object.assign(i,r),i.endMark||(this.registerMark(e),i.endMark=e),window.performance.measure(e,i.startMark,i.endMark);var n=this.measureTimeUserTiming(e);if(n){var a=new o(t,"timer",n,i,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");i.clearMarks&&this.clearMarks([i.startMark,i.endMark]),i.clearMeasures&&this.clearMeasures([e])}else this.logger.error("Undefined resource name to register as a measure")}catch(e){this.logger.error(e)}}},{key:"timer",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,r);var i=new o(e,"timer",t,r,this.config);this.util.addMetric(i,!0)}},{key:"counter",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1,r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,r);var i=new o(e,"counter",t,r,this.config);i.value=Math.abs(parseInt(i.value,10)),this.util.addMetric(i,!0)}},{key:"gauge",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,r);var i=new o(e,"gauge",t,r,this.config);this.util.addMetric(i,!0)}},{key:"sendMetric",value:function(e,t,r){var i=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},n=new o(t,e,r,i,this.config);this.util.addMetric(n,!1)}}]),e}()}();
/**
* statful-client-javascript 2.1.0
* Copyright 2017 Statful <https://www.statful.com/>
* statful-client-javascript 2.1.1
* Copyright 2018 Statful <https://www.statful.com/>
*/

@@ -5,0 +5,0 @@

/**
* statful-client-javascript 2.1.0
* Copyright 2017 Statful <https://www.statful.com/>
* statful-client-javascript 2.1.1
* Copyright 2018 Statful <https://www.statful.com/>
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.statful=t()}(this,function(){"use strict";var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),i=function(){function e(r){t(this,e),this.debugEnabled=r||!1}return r(e,[{key:"info",value:function(){this.debugEnabled&&console.info.apply(console,Array.prototype.slice.call(arguments))}},{key:"debug",value:function(){this.debugEnabled&&console.debug.apply(console,Array.prototype.slice.call(arguments))}},{key:"error",value:function(){this.debugEnabled&&console.error.apply(console,Array.prototype.slice.call(arguments))}}]),e}(),n=function(){function e(r){t(this,e),this.config={},Object.assign(this.config,r),this.logger=new i(this.config.debug),this.config&&this.config.flushInterval&&this.registerQueue(this.config.flushInterval)}return r(e,[{key:"sendData",value:function(e){var t=this,r=this.config.apiAddress+"/beacon/metrics",i=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var n=new XMLHttpRequest;n.open("POST",r,!0),n.timeout=this.config.timeout,n.setRequestHeader("Content-type","application/json"),n.send(i),n.onreadystatechange=function(){200==n.status||201==n.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",r,n.status)}}}},{key:"registerQueue",value:function(e){var t=this,r=void 0;return this.metricsQueue=[],"number"==typeof e&&e>0&&(r=setInterval(function(){t.metricsQueue.length>0&&(t.sendData(t.metricsQueue),t.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(r)}),!0)}},{key:"addMetric",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e&&"function"==typeof e.isValid&&e.isValid()?this.shouldAddMetric(e)?t?this.metricsQueue.push(e):this.sendData([e]):this.logger.debug("Metric was discarded due to sample rate."):this.logger.error("Invalid metric.")}},{key:"shouldAddMetric",value:function(){var e=((arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).sampleRate||this.config.sampleRate||100)/100;return Math.random()<=e}}]),e}(),a=["avg","count","sum","first","last","p90","p95","min","max"],o=[10,30,60,120,180,300],s=function(){function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};t(this,e),this.name=r,this.type=i,this.value=n;var s=[],u=[],g=0;o[i]&&(s=o[i].tags,u=o[i].aggregations,g=o[i].aggregationFrequency),this.tags=this.buildTags(a.tags,o.tags,s,o.app),this.aggregations=this.buildAggregations(a.aggregations,o.aggregations,u),this.aggregationFrequency=this.buildAggregationFrequency(a.aggregationFrequency,o.aggregationFrequency,g),this.namespace=a.namespace||o.namespace,this.sampleRate=a.sampleRate||o.sampleRate}return r(e,[{key:"buildTags",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments[3],n={};return Object.assign(n,t),Object.assign(n,r),Object.assign(n,e),!n.app&&i&&(n.app=i),n}},{key:"buildAggregations",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],i=[];return i=i.concat(t),i=i.concat(r).filter(this.uniq),i=i.concat(e).filter(this.uniq),this.filterAggregations(i)}},{key:"uniq",value:function(e,t,r){return e&&r.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,r){var i=e||r||t;return this.filterAggregationFrequency(i)}},{key:"filterAggregations",value:function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return a.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return o.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),e}(),u={dryrun:!1,debug:!1,app:void 0,namespace:"web",tags:{},aggregations:[],aggregationFrequency:10,timer:{tags:{unit:"ms"},aggregations:["avg","p90","count"]},counter:{tags:{},aggregations:["sum","count"]},gauge:{tags:{},aggregations:["last"]},timeout:2e3,flushInterval:1e4,sampleRate:100};return function(){function a(){t(this,a)}return r(a,null,[{key:"initialize",value:function(t){this.config={apiAddress:"https://beacon.statful.com"},"object"===(void 0===t?"undefined":e(t))&&null!==t||(t={}),Object.assign(this.config,u),Object.assign(this.config,t),this.logger=new i(this.config.debug),this.util=new n(this.config)}},{key:"measureTimeUserTiming",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=window.performance.getEntriesByName(e).filter(function(e){return"measure"===e.entryType}),r=void 0;return t.length>0?r=t[t.length-1].duration:this.logger.debug("Measure "+e+" not found"),r}},{key:"clearMarks",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMarks(e)}):window.performance.clearMarks()}catch(e){this.logger.error(e)}}},{key:"clearMeasures",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMeasures(e)}):window.performance.clearMeasures()}catch(e){this.logger.error(e)}}},{key:"registerMark",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";try{this.logger.debug("Register Mark",e),e?window.performance.mark(e):this.logger.error("Undefined resource name to register as a mark")}catch(e){this.logger.error(e)}}},{key:"registerMeasure",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,r),e){var i={clearMarks:!1,clearMeasures:!1};Object.assign(i,r),i.endMark||(this.registerMark(e),i.endMark=e),window.performance.measure(e,i.startMark,i.endMark);var n=this.measureTimeUserTiming(e);if(n){var a=new s(t,"timer",n,i,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");i.clearMarks&&this.clearMarks([i.startMark,i.endMark]),i.clearMeasures&&this.clearMeasures([e])}else this.logger.error("Undefined resource name to register as a measure")}catch(e){this.logger.error(e)}}},{key:"timer",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,r);var i=new s(e,"timer",t,r,this.config);this.util.addMetric(i,!0)}},{key:"counter",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,r);var i=new s(e,"counter",t,r,this.config);i.value=Math.abs(parseInt(i.value,10)),this.util.addMetric(i,!0)}},{key:"gauge",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,r);var i=new s(e,"gauge",t,r,this.config);this.util.addMetric(i,!0)}},{key:"sendMetric",value:function(e,t,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=new s(t,e,r,i,this.config);this.util.addMetric(n,!1)}}]),a}()});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.statful=t()}(this,function(){"use strict";var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function i(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),e}}(),i=function(){function t(e){g(this,t),this.debugEnabled=e||!1}return r(t,[{key:"info",value:function(){this.debugEnabled&&console.info.apply(console,Array.prototype.slice.call(arguments))}},{key:"debug",value:function(){this.debugEnabled&&console.debug.apply(console,Array.prototype.slice.call(arguments))}},{key:"error",value:function(){this.debugEnabled&&console.error.apply(console,Array.prototype.slice.call(arguments))}}]),t}(),n=function(){function t(e){g(this,t),this.config={},Object.assign(this.config,e),this.logger=new i(this.config.debug),this.config&&this.config.flushInterval&&this.registerQueue(this.config.flushInterval)}return r(t,[{key:"sendData",value:function(e){var t=this,r=this.config.apiAddress+"/beacon/metrics",i=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var n=new XMLHttpRequest;n.open("POST",r,!0),n.timeout=this.config.timeout,n.setRequestHeader("Content-type","application/json"),n.send(i),n.onreadystatechange=function(){200==n.status||201==n.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",r,n.status)}}}},{key:"registerQueue",value:function(e){var t=this,r=void 0;return this.metricsQueue=[],"number"==typeof e&&0<e&&(r=setInterval(function(){0<t.metricsQueue.length&&(t.sendData(t.metricsQueue),t.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(r)}),!0)}},{key:"addMetric",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];e&&"function"==typeof e.isValid&&e.isValid()?this.shouldAddMetric(e)?t?this.metricsQueue.push(e):this.sendData([e]):this.logger.debug("Metric was discarded due to sample rate."):this.logger.error("Invalid metric.")}},{key:"shouldAddMetric",value:function(){var e=((0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).sampleRate||this.config.sampleRate||100)/100;return Math.random()<=e}}]),t}(),a=["avg","count","sum","first","last","p90","p95","min","max"],o=[10,30,60,120,180,300],s=function(){function u(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"",i=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},n=4<arguments.length&&void 0!==arguments[4]?arguments[4]:{};g(this,u),this.name=e,this.type=t,this.value=r;var a=[],o=[],s=0;n[t]&&(a=n[t].tags,o=n[t].aggregations,s=n[t].aggregationFrequency),this.tags=this.buildTags(i.tags,n.tags,a,n.app),this.aggregations=this.buildAggregations(i.aggregations,n.aggregations,o),this.aggregationFrequency=this.buildAggregationFrequency(i.aggregationFrequency,n.aggregationFrequency,s),this.namespace=i.namespace||n.namespace,this.sampleRate=i.sampleRate||n.sampleRate}return r(u,[{key:"buildTags",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},i=arguments[3],n={};return Object.assign(n,t),Object.assign(n,r),Object.assign(n,e),!n.app&&i&&(n.app=i),n}},{key:"buildAggregations",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[],i=[];return i=(i=(i=i.concat(t)).concat(r).filter(this.uniq)).concat(e).filter(this.uniq),this.filterAggregations(i)}},{key:"uniq",value:function(e,t,r){return e&&r.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,r){var i=e||r||t;return this.filterAggregationFrequency(i)}},{key:"filterAggregations",value:function(){return(0<arguments.length&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return a.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return o.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),u}(),u={dryrun:!1,debug:!1,app:void 0,namespace:"web",tags:{},aggregations:[],aggregationFrequency:10,timer:{tags:{unit:"ms"},aggregations:["avg","p90","count"]},counter:{tags:{},aggregations:["sum","count"]},gauge:{tags:{},aggregations:["last"]},timeout:2e3,flushInterval:1e4,sampleRate:100};return function(){function e(){g(this,e)}return r(e,null,[{key:"initialize",value:function(e){this.config={apiAddress:"https://beacon.statful.com"},"object"===(void 0===e?"undefined":t(e))&&null!==e||(e={}),Object.assign(this.config,u),Object.assign(this.config,e),this.logger=new i(this.config.debug),this.util=new n(this.config)}},{key:"measureTimeUserTiming",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",t=window.performance.getEntriesByName(e).filter(function(e){return"measure"===e.entryType}),r=void 0;return 0<t.length?r=t[t.length-1].duration:this.logger.debug("Measure "+e+" not found"),r}},{key:"clearMarks",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMarks(e)}):window.performance.clearMarks()}catch(e){this.logger.error(e)}}},{key:"clearMeasures",value:function(e){try{Array.isArray(e)?e.forEach(function(e){e&&window.performance.clearMeasures(e)}):window.performance.clearMeasures()}catch(e){this.logger.error(e)}}},{key:"registerMark",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";try{this.logger.debug("Register Mark",e),e?window.performance.mark(e):this.logger.error("Undefined resource name to register as a mark")}catch(e){this.logger.error(e)}}},{key:"registerMeasure",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,r),e){var i={clearMarks:!1,clearMeasures:!1};Object.assign(i,r),i.endMark||(this.registerMark(e),i.endMark=e),window.performance.measure(e,i.startMark,i.endMark);var n=this.measureTimeUserTiming(e);if(n){var a=new s(t,"timer",n,i,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");i.clearMarks&&this.clearMarks([i.startMark,i.endMark]),i.clearMeasures&&this.clearMeasures([e])}else this.logger.error("Undefined resource name to register as a measure")}catch(e){this.logger.error(e)}}},{key:"timer",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,r);var i=new s(e,"timer",t,r,this.config);this.util.addMetric(i,!0)}},{key:"counter",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1,r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,r);var i=new s(e,"counter",t,r,this.config);i.value=Math.abs(parseInt(i.value,10)),this.util.addMetric(i,!0)}},{key:"gauge",value:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,r);var i=new s(e,"gauge",t,r,this.config);this.util.addMetric(i,!0)}},{key:"sendMetric",value:function(e,t,r){var i=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},n=new s(t,e,r,i,this.config);this.util.addMetric(n,!1)}}]),e}()});
{
"name": "statful-client-javascript",
"version": "2.1.0",
"version": "2.1.1",
"description": "Statful client for Javascript applications",
"banner": "/**\n* <%= pkg.name %> <%= pkg.version %>\n* Copyright 2017 Statful <https://www.statful.com/>\n*/\n",
"banner": "/**\n* <%= pkg.name %> <%= pkg.version %>\n* Copyright 2018 Statful <https://www.statful.com/>\n*/\n",
"scripts": {

@@ -29,8 +29,8 @@ "build": "NODE_ENV=production rollup -c",

"babel-preset-env": "^1.6.1",
"eslint": "^4.11.0",
"eslint": "^4.19.1",
"jasmine-ajax": "^3.3.1",
"jasmine-core": "^2.8.0",
"karma": "^1.7.1",
"jasmine-core": "^3.1.0",
"karma": "^2.0.2",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.0",
"karma-jasmine": "^1.1.1",
"karma-phantomjs-launcher": "^1.0.4",

@@ -37,0 +37,0 @@ "karma-rollup-preprocessor": "^4.0.3",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc