statful-client-javascript
Advanced tools
Comparing version 2.1.7 to 2.2.0
/*! | ||
* statful-client-javascript 2.1.7 | ||
* statful-client-javascript 2.2.0 | ||
* Copyright 2018 Statful | ||
* https://www.statful.com | ||
*/!function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}r.r(t);var i=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.debugEnabled=t||!1}return function(e,t,r){t&&n(e.prototype,t),r&&n(e,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}();function a(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var o=["avg","count","sum","first","last","p90","p95","min","max"],u=[10,30,60,120,180,300],s=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name=t,this.type=r,this.value=n;var o=[],u=[],s=0;a[r]&&(o=a[r].tags,u=a[r].aggregations,s=a[r].aggregationFrequency),this.tags=this.buildTags(i.tags,a.tags,o,a.app),this.aggregations=this.buildAggregations(i.aggregations,a.aggregations,u),this.aggregationFrequency=this.buildAggregationFrequency(i.aggregationFrequency,a.aggregationFrequency,s),this.namespace=i.namespace||a.namespace,this.sampleRate=i.sampleRate||a.sampleRate}return function(e,t,r){t&&a(e.prototype,t),r&&a(e,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]:{},n=arguments.length>3?arguments[3]:void 0,i={};return Object.assign(i,t),Object.assign(i,r),Object.assign(i,e),!i.app&&n&&(i.app=n),i}},{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]:[],n=[];return n=(n=(n=n.concat(t)).concat(r).filter(this.uniq)).concat(e).filter(this.uniq),this.filterAggregations(n)}},{key:"uniq",value:function(e,t,r){return e&&r.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,r){var n=e||r||t;return this.filterAggregationFrequency(n)}},{key:"filterAggregations",value:function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return o.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return u.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),e}();function l(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var c=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config={},Object.assign(this.config,t),this.logger=new i(this.config.debug);var r=1e4;this.config&&this.config.flushInterval&&"number"==typeof this.config.flushInterval&&this.config.flushInterval>0&&(r=this.config.flushInterval),this.registerQueue(r)}return function(e,t,r){t&&l(e.prototype,t),r&&l(e,r)}(e,[{key:"sendData",value:function(e){var t=this,r="".concat(this.config.apiAddress,"/beacon/metrics"),n=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var i=new XMLHttpRequest;i.open("POST",r,!0),i.timeout=this.config.timeout,i.setRequestHeader("Content-type","application/json"),i.send(n),i.onreadystatechange=function(){200==i.status||201==i.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",r,i.status)}}}},{key:"registerQueue",value:function(e){var t,r=this;return this.metricsQueue=[],"number"==typeof e&&e>0&&(t=setInterval(function(){r.metricsQueue.length>0&&(r.sendData(r.metricsQueue),r.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(t)}),!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}();function g(e){return(g="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})(e)}function f(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}r.d(t,"default",function(){return h});var d={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,sampleRate:100},h=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return function(e,t,r){t&&f(e.prototype,t),r&&f(e,r)}(e,null,[{key:"initialize",value:function(e){this.config={apiAddress:"https://beacon.statful.com"},"object"===g(e)&&null!==e||(e={}),Object.assign(this.config,d),Object.assign(this.config,e),this.logger=new i(this.config.debug),this.util=new c(this.config)}},{key:"measureTimeUserTiming",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=window.performance.getEntriesByName(t).filter(function(e){return"measure"===e.entryType});return r.length>0?e=r[r.length-1].duration:this.logger.debug("Measure ".concat(t," not found")),e}},{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 n={clearMarks:!1,clearMeasures:!1};Object.assign(n,r),n.endMark||(this.registerMark(e),n.endMark=e),window.performance.measure(e,n.startMark,n.endMark);var i=this.measureTimeUserTiming(e);if(i){var a=new s(t,"timer",i,n,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");n.clearMarks&&this.clearMarks([n.startMark,n.endMark]),n.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 n=new s(e,"timer",t,r,this.config);this.util.addMetric(n,!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 n=new s(e,"counter",t,r,this.config);n.value=Math.abs(parseInt(n.value,10)),this.util.addMetric(n,!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 n=new s(e,"gauge",t,r,this.config);this.util.addMetric(n,!0)}},{key:"sendMetric",value:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=new s(t,e,r,n,this.config);this.util.addMetric(i,!1)}}]),e}()}]); | ||
*/!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n.r(t);var i=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.debugEnabled=t||!1}return function(e,t,n){t&&r(e.prototype,t),n&&r(e,n)}(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}();function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var o=["avg","count","sum","first","last","p90","p95","min","max"],s=[10,30,60,120,180,300],u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name=t,this.type=n,this.value=r;var o=[],s=[],u=0;a[n]&&(o=a[n].tags,s=a[n].aggregations,u=a[n].aggregationFrequency),this.tags=this.buildTags(i.tags,a.tags,o,a.plugins,a.app),this.aggregations=this.buildAggregations(i.aggregations,a.aggregations,s),this.aggregationFrequency=this.buildAggregationFrequency(i.aggregationFrequency,a.aggregationFrequency,u),this.namespace=i.namespace||a.namespace,this.sampleRate=i.sampleRate||a.sampleRate}return function(e,t,n){t&&a(e.prototype,t),n&&a(e,n)}(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]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],i=arguments.length>4?arguments[4]:void 0,a={};return Object.assign(a,t),Object.assign(a,n),Object.assign(a,e),r.forEach(function(e){e&&e.tags&&Object.assign(a,e.tags)}),!a.app&&i&&(a.app=i),a}},{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]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=[];return r=(r=(r=r.concat(t)).concat(n).filter(this.uniq)).concat(e).filter(this.uniq),this.filterAggregations(r)}},{key:"uniq",value:function(e,t,n){return e&&n.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,n){var r=e||n||t;return this.filterAggregationFrequency(r)}},{key:"filterAggregations",value:function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return o.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return s.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),e}();function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var l=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config={},Object.assign(this.config,t),this.logger=new i(this.config.debug);var n=1e4;this.config&&this.config.flushInterval&&"number"==typeof this.config.flushInterval&&this.config.flushInterval>0&&(n=this.config.flushInterval),this.registerQueue(n)}return function(e,t,n){t&&c(e.prototype,t),n&&c(e,n)}(e,[{key:"sendData",value:function(e){var t=this,n="".concat(this.config.apiAddress,"/beacon/metrics"),r=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var i=new XMLHttpRequest;i.open("POST",n,!0),i.timeout=this.config.timeout,i.setRequestHeader("Content-type","application/json"),i.send(r),i.onreadystatechange=function(){200==i.status||201==i.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",n,i.status)}}}},{key:"registerQueue",value:function(e){var t,n=this;return this.metricsQueue=[],"number"==typeof e&&e>0&&(t=setInterval(function(){n.metricsQueue.length>0&&(n.sendData(n.metricsQueue),n.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(t)}),!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}();function g(e){return(g="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})(e)}function f(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n.d(t,"default",function(){return h});var d={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,sampleRate:100,plugins:[]},h=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return function(e,t,n){t&&f(e.prototype,t),n&&f(e,n)}(e,null,[{key:"initialize",value:function(e){this.config={apiAddress:"https://beacon.statful.com"},"object"===g(e)&&null!==e||(e={}),Object.assign(this.config,d),Object.assign(this.config,e),this.logger=new i(this.config.debug),this.util=new l(this.config)}},{key:"measureTimeUserTiming",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=window.performance.getEntriesByName(t).filter(function(e){return"measure"===e.entryType});return n.length>0?e=n[n.length-1].duration:this.logger.debug("Measure ".concat(t," not found")),e}},{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 n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,n),e){var r={clearMarks:!1,clearMeasures:!1};Object.assign(r,n),r.endMark||(this.registerMark(e),r.endMark=e),window.performance.measure(e,r.startMark,r.endMark);var i=this.measureTimeUserTiming(e);if(i){var a=new u(t,"timer",i,r,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");r.clearMarks&&this.clearMarks([r.startMark,r.endMark]),r.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 n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,n);var r=new u(e,"timer",t,n,this.config);this.util.addMetric(r,!0)}},{key:"counter",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,n);var r=new u(e,"counter",t,n,this.config);r.value=Math.abs(parseInt(r.value,10)),this.util.addMetric(r,!0)}},{key:"gauge",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,n);var r=new u(e,"gauge",t,n,this.config);this.util.addMetric(r,!0)}},{key:"sendMetric",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=new u(t,e,n,r,this.config);this.util.addMetric(i,!1)}},{key:"use",value:function(e){"object"===g(e)&&(this.config.plugins.push(e),"function"==typeof e.onInit&&e.onInit())}}]),e}()}]); |
/*! | ||
* statful-client-javascript 2.1.7 | ||
* statful-client-javascript 2.2.0 | ||
* Copyright 2018 Statful | ||
* https://www.statful.com | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.statful=t():e.statful=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n.r(t);var i=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.debugEnabled=t||!1}return function(e,t,n){t&&r(e.prototype,t),n&&r(e,n)}(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}();function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var o=["avg","count","sum","first","last","p90","p95","min","max"],u=[10,30,60,120,180,300],s=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name=t,this.type=n,this.value=r;var o=[],u=[],s=0;a[n]&&(o=a[n].tags,u=a[n].aggregations,s=a[n].aggregationFrequency),this.tags=this.buildTags(i.tags,a.tags,o,a.app),this.aggregations=this.buildAggregations(i.aggregations,a.aggregations,u),this.aggregationFrequency=this.buildAggregationFrequency(i.aggregationFrequency,a.aggregationFrequency,s),this.namespace=i.namespace||a.namespace,this.sampleRate=i.sampleRate||a.sampleRate}return function(e,t,n){t&&a(e.prototype,t),n&&a(e,n)}(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]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3?arguments[3]:void 0,i={};return Object.assign(i,t),Object.assign(i,n),Object.assign(i,e),!i.app&&r&&(i.app=r),i}},{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]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=[];return r=(r=(r=r.concat(t)).concat(n).filter(this.uniq)).concat(e).filter(this.uniq),this.filterAggregations(r)}},{key:"uniq",value:function(e,t,n){return e&&n.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,n){var r=e||n||t;return this.filterAggregationFrequency(r)}},{key:"filterAggregations",value:function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return o.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return u.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),e}();function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var l=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config={},Object.assign(this.config,t),this.logger=new i(this.config.debug);var n=1e4;this.config&&this.config.flushInterval&&"number"==typeof this.config.flushInterval&&this.config.flushInterval>0&&(n=this.config.flushInterval),this.registerQueue(n)}return function(e,t,n){t&&c(e.prototype,t),n&&c(e,n)}(e,[{key:"sendData",value:function(e){var t=this,n="".concat(this.config.apiAddress,"/beacon/metrics"),r=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var i=new XMLHttpRequest;i.open("POST",n,!0),i.timeout=this.config.timeout,i.setRequestHeader("Content-type","application/json"),i.send(r),i.onreadystatechange=function(){200==i.status||201==i.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",n,i.status)}}}},{key:"registerQueue",value:function(e){var t,n=this;return this.metricsQueue=[],"number"==typeof e&&e>0&&(t=setInterval(function(){n.metricsQueue.length>0&&(n.sendData(n.metricsQueue),n.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(t)}),!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}();function g(e){return(g="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})(e)}function f(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n.d(t,"default",function(){return h});var d={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,sampleRate:100},h=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return function(e,t,n){t&&f(e.prototype,t),n&&f(e,n)}(e,null,[{key:"initialize",value:function(e){this.config={apiAddress:"https://beacon.statful.com"},"object"===g(e)&&null!==e||(e={}),Object.assign(this.config,d),Object.assign(this.config,e),this.logger=new i(this.config.debug),this.util=new l(this.config)}},{key:"measureTimeUserTiming",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=window.performance.getEntriesByName(t).filter(function(e){return"measure"===e.entryType});return n.length>0?e=n[n.length-1].duration:this.logger.debug("Measure ".concat(t," not found")),e}},{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 n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,n),e){var r={clearMarks:!1,clearMeasures:!1};Object.assign(r,n),r.endMark||(this.registerMark(e),r.endMark=e),window.performance.measure(e,r.startMark,r.endMark);var i=this.measureTimeUserTiming(e);if(i){var a=new s(t,"timer",i,r,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");r.clearMarks&&this.clearMarks([r.startMark,r.endMark]),r.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 n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,n);var r=new s(e,"timer",t,n,this.config);this.util.addMetric(r,!0)}},{key:"counter",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,n);var r=new s(e,"counter",t,n,this.config);r.value=Math.abs(parseInt(r.value,10)),this.util.addMetric(r,!0)}},{key:"gauge",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,n);var r=new s(e,"gauge",t,n,this.config);this.util.addMetric(r,!0)}},{key:"sendMetric",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=new s(t,e,n,r,this.config);this.util.addMetric(i,!1)}}]),e}()}]).default}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.statful=t():e.statful=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n.r(t);var i=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.debugEnabled=t||!1}return function(e,t,n){t&&r(e.prototype,t),n&&r(e,n)}(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}();function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var o=["avg","count","sum","first","last","p90","p95","min","max"],u=[10,30,60,120,180,300],s=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name=t,this.type=n,this.value=r;var o=[],u=[],s=0;a[n]&&(o=a[n].tags,u=a[n].aggregations,s=a[n].aggregationFrequency),this.tags=this.buildTags(i.tags,a.tags,o,a.plugins,a.app),this.aggregations=this.buildAggregations(i.aggregations,a.aggregations,u),this.aggregationFrequency=this.buildAggregationFrequency(i.aggregationFrequency,a.aggregationFrequency,s),this.namespace=i.namespace||a.namespace,this.sampleRate=i.sampleRate||a.sampleRate}return function(e,t,n){t&&a(e.prototype,t),n&&a(e,n)}(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]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],i=arguments.length>4?arguments[4]:void 0,a={};return Object.assign(a,t),Object.assign(a,n),Object.assign(a,e),r.forEach(function(e){e&&e.tags&&Object.assign(a,e.tags)}),!a.app&&i&&(a.app=i),a}},{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]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=[];return r=(r=(r=r.concat(t)).concat(n).filter(this.uniq)).concat(e).filter(this.uniq),this.filterAggregations(r)}},{key:"uniq",value:function(e,t,n){return e&&n.indexOf(e)===t}},{key:"buildAggregationFrequency",value:function(e,t,n){var r=e||n||t;return this.filterAggregationFrequency(r)}},{key:"filterAggregations",value:function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).filter(function(e){return o.includes(e)})}},{key:"filterAggregationFrequency",value:function(e){return u.includes(e)?e:10}},{key:"isValid",value:function(){return!(isNaN(this.value)||!this.name)}}]),e}();function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var l=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config={},Object.assign(this.config,t),this.logger=new i(this.config.debug);var n=1e4;this.config&&this.config.flushInterval&&"number"==typeof this.config.flushInterval&&this.config.flushInterval>0&&(n=this.config.flushInterval),this.registerQueue(n)}return function(e,t,n){t&&c(e.prototype,t),n&&c(e,n)}(e,[{key:"sendData",value:function(e){var t=this,n="".concat(this.config.apiAddress,"/beacon/metrics"),r=JSON.stringify(e);if(this.config.dryrun)this.logger.debug("Dryrun data",e);else{var i=new XMLHttpRequest;i.open("POST",n,!0),i.timeout=this.config.timeout,i.setRequestHeader("Content-type","application/json"),i.send(r),i.onreadystatechange=function(){200==i.status||201==i.status?t.logger.debug("Successfully send metric"):t.logger.debug("Error send metric",n,i.status)}}}},{key:"registerQueue",value:function(e){var t,n=this;return this.metricsQueue=[],"number"==typeof e&&e>0&&(t=setInterval(function(){n.metricsQueue.length>0&&(n.sendData(n.metricsQueue),n.metricsQueue=[])},e),window.addEventListener("beforeunload",function(){clearInterval(t)}),!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}();function g(e){return(g="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})(e)}function f(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n.d(t,"default",function(){return h});var d={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,sampleRate:100,plugins:[]},h=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return function(e,t,n){t&&f(e.prototype,t),n&&f(e,n)}(e,null,[{key:"initialize",value:function(e){this.config={apiAddress:"https://beacon.statful.com"},"object"===g(e)&&null!==e||(e={}),Object.assign(this.config,d),Object.assign(this.config,e),this.logger=new i(this.config.debug),this.util=new l(this.config)}},{key:"measureTimeUserTiming",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=window.performance.getEntriesByName(t).filter(function(e){return"measure"===e.entryType});return n.length>0?e=n[n.length-1].duration:this.logger.debug("Measure ".concat(t," not found")),e}},{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 n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{if(this.logger.debug("Register Measure",e,t,n),e){var r={clearMarks:!1,clearMeasures:!1};Object.assign(r,n),r.endMark||(this.registerMark(e),r.endMark=e),window.performance.measure(e,r.startMark,r.endMark);var i=this.measureTimeUserTiming(e);if(i){var a=new s(t,"timer",i,r,this.config);this.util.addMetric(a,!0)}else this.logger.error("Failed to get measure time to register as timer value");r.clearMarks&&this.clearMarks([r.startMark,r.endMark]),r.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 n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Timer",e,t,n);var r=new s(e,"timer",t,n,this.config);this.util.addMetric(r,!0)}},{key:"counter",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Counter",e,n);var r=new s(e,"counter",t,n,this.config);r.value=Math.abs(parseInt(r.value,10)),this.util.addMetric(r,!0)}},{key:"gauge",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.logger.debug("Register Gauge",e,t,n);var r=new s(e,"gauge",t,n,this.config);this.util.addMetric(r,!0)}},{key:"sendMetric",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=new s(t,e,n,r,this.config);this.util.addMetric(i,!1)}},{key:"use",value:function(e){"object"===g(e)&&(this.config.plugins.push(e),"function"==typeof e.onInit&&e.onInit())}}]),e}()}]).default}); |
@@ -88,6 +88,6 @@ /*global __dirname, module*/ | ||
// thresholds for all files | ||
statements: 92, | ||
branches: 82, | ||
functions: 92, | ||
lines: 95 | ||
statements: 90, | ||
branches: 80, | ||
functions: 90, | ||
lines: 90 | ||
} //, | ||
@@ -94,0 +94,0 @@ //each: { // thresholds per file |
{ | ||
"name": "statful-client-javascript", | ||
"version": "2.1.7", | ||
"version": "2.2.0", | ||
"description": "Statful client for Javascript applications", | ||
@@ -25,18 +25,18 @@ "banner": "/**\n* <%= pkg.name %> <%= pkg.version %>\n* Copyright 2018 Statful <https://www.statful.com/>\n*/\n", | ||
"devDependencies": { | ||
"@babel/core": "^7.1.2", | ||
"@babel/core": "^7.1.5", | ||
"@babel/polyfill": "^7.0.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"@babel/preset-env": "^7.1.5", | ||
"babel-loader": "^8.0.4", | ||
"babel-plugin-add-module-exports": "^1.0.0", | ||
"babel-plugin-transform-object-assign": "^6.22.0", | ||
"eslint": "^5.7.0", | ||
"eslint": "^5.9.0", | ||
"istanbul-instrumenter-loader": "^3.0.1", | ||
"jasmine-ajax": "^3.4.0", | ||
"jasmine-core": "^3.2.1", | ||
"jsdom": "^12.2.0", | ||
"karma": "^3.0.0", | ||
"jasmine-core": "^3.3.0", | ||
"jsdom": "^13.0.0", | ||
"karma": "^3.1.1", | ||
"karma-coverage": "^1.1.2", | ||
"karma-coverage-istanbul-reporter": "^2.0.4", | ||
"karma-jasmine": "^1.1.2", | ||
"karma-jsdom-launcher": "^6.1.3", | ||
"karma-jsdom-launcher": "^6.1.4", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
@@ -46,3 +46,3 @@ "karma-webpack": "^v4.0.0-beta.0", | ||
"usertiming": "^0.1.8", | ||
"webpack": "^4.21.0", | ||
"webpack": "^4.25.1", | ||
"webpack-cli": "^3.1.2" | ||
@@ -49,0 +49,0 @@ }, |
@@ -112,3 +112,6 @@ # statful-client-javascript | ||
### Plugins | ||
* [statful-browser-plugin](https://github.com/statful/statful-browser-plugin) - add browser tags | ||
### User Timing | ||
@@ -186,2 +189,2 @@ | ||
Statful Javascript Client is available under the MIT license. See the [LICENSE](https://raw.githubusercontent.com/statful/statful-client-objc/master/LICENSE) file for more information. | ||
Statful Javascript Client is available under the MIT license. See the [LICENSE](https://raw.githubusercontent.com/statful/statful-client-javascript/master/LICENSE) file for more information. |
@@ -34,2 +34,3 @@ const aggregationList = [ | ||
typeTags, | ||
config.plugins, | ||
config.app | ||
@@ -56,6 +57,13 @@ ); | ||
* @param {object} typeTags - list of type tags | ||
* @param {array} plugins - list of plugins | ||
* @param {string} app - app tag value | ||
* @returns {*} | ||
*/ | ||
buildTags(methodTags = {}, globalTags = {}, typeTags = {}, app) { | ||
buildTags( | ||
methodTags = {}, | ||
globalTags = {}, | ||
typeTags = {}, | ||
plugins = [], | ||
app | ||
) { | ||
let tags = {}; | ||
@@ -67,2 +75,8 @@ | ||
plugins.forEach(plugin => { | ||
if (plugin && plugin.tags) { | ||
Object.assign(tags, plugin.tags); | ||
} | ||
}); | ||
if (!tags.app && app) { | ||
@@ -69,0 +83,0 @@ tags.app = app; |
@@ -45,3 +45,4 @@ import StatfulLogger from './logger'; | ||
timeout: 2000, | ||
sampleRate: 100 | ||
sampleRate: 100, | ||
plugins: [] | ||
}; | ||
@@ -300,2 +301,15 @@ | ||
} | ||
/** | ||
* Use a specific plugin | ||
* @param plugin - plugin instance | ||
*/ | ||
static use(plugin) { | ||
if (typeof plugin === 'object') { | ||
this.config.plugins.push(plugin); | ||
if (typeof plugin.onInit === 'function') { | ||
plugin.onInit(); | ||
} | ||
} | ||
} | ||
} |
@@ -447,2 +447,16 @@ import Metric from '../src/metric.model'; | ||
}); | ||
it('should use a plugin', () => { | ||
statful.initialize(); | ||
const plugin = { | ||
onInit: () => {} | ||
}; | ||
spyOn(plugin, 'onInit'); | ||
statful.use(plugin); | ||
expect(statful.config.plugins.length).toEqual(1); | ||
expect(plugin.onInit).toHaveBeenCalled(); | ||
}); | ||
}); |
77422
1363
189