beaver-logger
Advanced tools
Comparing version 4.0.3 to 4.0.4
@@ -783,3 +783,3 @@ !function(root, factory) { | ||
} | ||
Object(belter_src.safeInterval)(flush, flushInterval); | ||
Object(belter_src.isBrowser)() && Object(belter_src.safeInterval)(flush, flushInterval); | ||
return { | ||
@@ -786,0 +786,0 @@ debug: function(event, payload) { |
@@ -1,3 +0,3 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("beaver",[],t):"object"==typeof exports?exports.beaver=t():e.beaver=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get: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=4)}([function(e,t,n){"use strict";t.a=o,t.b=i,t.d=function(){},t.k=function(){var e="0123456789abcdef";return"xxxxxxxxxx".replace(/./g,function(){return e.charAt(Math.floor(Math.random()*e.length))})+"_"+u((new Date).toISOString().slice(11,19).replace("T",".")).replace(/[^a-zA-Z0-9]/g,"").toLowerCase()},t.c=function e(){return i(e,function(){try{if("undefined"==typeof window)return!1;if(window.localStorage){var e=Math.random().toString();window.localStorage.setItem("__test__localStorage__",e);var t=window.localStorage.getItem("__test__localStorage__");if(window.localStorage.removeItem("__test__localStorage__"),e===t)return!0}}catch(e){}return!1})},t.g=function(e,t,n){var r=[];return e.replace(t,function(){r.push(n.apply(null,arguments))}),r},t.j=function(e){return"data:image/svg+xml;base64,"+u(e)},t.e=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Boolean,n={};for(var r in e)e.hasOwnProperty(r)&&t(e[r],r)&&(n[r]=e[r]);return n},t.h=function(e,t){var n=[];return e.replace(t,function(e){return n.push(e),""}),n},t.f=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:50,n=void 0,o=void 0;return function(){o&&clearTimeout(o);var i=n=n||new r.a;return o=setTimeout(function(){n=null,o=null,r.a.try(e).then(function(e){return i.resolve(e)},function(e){return i.reject(e)})},t),i}},t.i=function(e,t){var n=void 0;return function r(){n=setTimeout(function(){e(),r()},t)}(),{cancel:function(){clearTimeout(n)}}};var r=n(1);function o(){if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("No global found")}function i(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return e.__memoized__||(e.__memoized__=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e.__memoized__)return e.__memoized__;var n={};return e.__memoized__=function(){for(var r=arguments.length,i=Array(r),u=0;u<r;u++)i[u]=arguments[u];if(e.__memoized__&&e.__memoized__.__calling__)throw new Error("Can not call memoized method recursively");var s=void 0;try{s=JSON.stringify(Array.prototype.slice.call(arguments))}catch(e){throw new Error("Arguments not serializable -- can not be used to memoize")}var a=t.time;n[s]&&a&&Date.now()-n[s].time<a&&delete n[s];var c=o();if(c.__CACHE_START_TIME__&&n[s]&&n[s].time<c.__CACHE_START_TIME__&&delete n[s],n[s])return n[s].value;e.__memoized__.__calling__=!0;var l=Date.now(),f=e.apply(this,arguments);return e.__memoized__.__calling__=!1,n[s]={time:l,value:f},n[s].value},e.__memoized__}(t)),e.__memoized__.apply(e,n)}function u(e){return window.btoa(e)}},function(e,t,n){"use strict";function r(e){try{if(!e)return!1;if("undefined"!=typeof Promise&&e instanceof Promise)return!0;if("undefined"!=typeof window&&window.Window&&e instanceof window.Window)return!1;if("undefined"!=typeof window&&window.constructor&&e instanceof window.constructor)return!1;var t={}.toString;if(t){var n=t.call(e);if("[object Window]"===n||"[object global]"===n||"[object DOMWindow]"===n)return!1}if("function"==typeof e.then)return!0}catch(e){return!1}return!1}function o(){var e=void 0;if("undefined"!=typeof window)e=window;else{if("undefined"==typeof global)throw new TypeError("Can not find global");e=global}var t=e.__zalgopromise__=e.__zalgopromise__||{};return t.flushPromises=t.flushPromises||[],t.activeCount=t.activeCount||0,t.possiblyUnhandledPromiseHandlers=t.possiblyUnhandledPromiseHandlers||[],t.dispatchedErrors=t.dispatchedErrors||[],t}var i=function(){function e(t){var n=this;if(function(t,n){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this),this.resolved=!1,this.rejected=!1,this.errorHandled=!1,this.handlers=[],t){var r=void 0,o=void 0,i=!1,u=!1,s=!1;try{t(function(e){s?n.resolve(e):(i=!0,r=e)},function(e){s?n.reject(e):(u=!0,o=e)})}catch(e){return void this.reject(e)}s=!0,i?this.resolve(r):u&&this.reject(o)}}return e.prototype.resolve=function(e){if(this.resolved||this.rejected)return this;if(r(e))throw new Error("Can not resolve promise with another promise");return this.resolved=!0,this.value=e,this.dispatch(),this},e.prototype.reject=function(e){var t=this;if(this.resolved||this.rejected)return this;if(r(e))throw new Error("Can not reject promise with another promise");if(!e){var n=e&&"function"==typeof e.toString?e.toString():Object.prototype.toString.call(e);e=new Error("Expected reject to be called with Error, got "+n)}return this.rejected=!0,this.error=e,this.errorHandled||setTimeout(function(){t.errorHandled||function(e){if(-1===o().dispatchedErrors.indexOf(e)){o().dispatchedErrors.push(e),setTimeout(function(){throw e},1);for(var t=0;t<o().possiblyUnhandledPromiseHandlers.length;t++)o().possiblyUnhandledPromiseHandlers[t](e)}}(e)},1),this.dispatch(),this},e.prototype.asyncReject=function(e){this.errorHandled=!0,this.reject(e)},e.prototype.dispatch=function(){var t=this,n=this.dispatching,i=this.resolved,u=this.rejected,s=this.handlers;if(!n&&(i||u)){this.dispatching=!0,o().activeCount+=1;for(var a=function(n){var o=s[n],a=o.onSuccess,c=o.onError,l=o.promise,f=void 0;if(i)try{f=a?a(t.value):t.value}catch(e){return l.reject(e),"continue"}else if(u){if(!c)return l.reject(t.error),"continue";try{f=c(t.error)}catch(e){return l.reject(e),"continue"}}f instanceof e&&(f.resolved||f.rejected)?(f.resolved?l.resolve(f.value):l.reject(f.error),f.errorHandled=!0):r(f)?f instanceof e&&(f.resolved||f.rejected)?f.resolved?l.resolve(f.value):l.reject(f.error):f.then(function(e){l.resolve(e)},function(e){l.reject(e)}):l.resolve(f)},c=0;c<s.length;c++)a(c);s.length=0,this.dispatching=!1,o().activeCount-=1,0===o().activeCount&&e.flushQueue()}},e.prototype.then=function(t,n){if(t&&"function"!=typeof t&&!t.call)throw new Error("Promise.then expected a function for success handler");if(n&&"function"!=typeof n&&!n.call)throw new Error("Promise.then expected a function for error handler");var r=new e;return this.handlers.push({promise:r,onSuccess:t,onError:n}),this.errorHandled=!0,this.dispatch(),r},e.prototype.catch=function(e){return this.then(void 0,e)},e.prototype.finally=function(t){return this.then(function(n){return e.try(t).then(function(){return n})},function(n){return e.try(t).then(function(){throw n})})},e.prototype.timeout=function(e,t){var n=this;if(this.resolved||this.rejected)return this;var r=setTimeout(function(){n.resolved||n.rejected||n.reject(t||new Error("Promise timed out after "+e+"ms"))},e);return this.then(function(e){return clearTimeout(r),e})},e.prototype.toPromise=function(){if("undefined"==typeof Promise)throw new TypeError("Could not find Promise");return Promise.resolve(this)},e.resolve=function(t){return t instanceof e?t:r(t)?new e(function(e,n){return t.then(e,n)}):(new e).resolve(t)},e.reject=function(t){return(new e).reject(t)},e.all=function(t){var n=new e,o=t.length,i=[];if(!o)return n.resolve(i),n;for(var u=function(u){var s=t[u];if(s instanceof e){if(s.resolved)return i[u]=s.value,o-=1,"continue"}else if(!r(s))return i[u]=s,o-=1,"continue";e.resolve(s).then(function(e){i[u]=e,0==(o-=1)&&n.resolve(i)},function(e){n.reject(e)})},s=0;s<t.length;s++)u(s);return 0===o&&n.resolve(i),n},e.hash=function(t){var n={};return e.all(Object.keys(t).map(function(r){return e.resolve(t[r]).then(function(e){n[r]=e})})).then(function(){return n})},e.map=function(t,n){return e.all(t.map(n))},e.onPossiblyUnhandledException=function(e){return function(e){return o().possiblyUnhandledPromiseHandlers.push(e),{cancel:function(){o().possiblyUnhandledPromiseHandlers.splice(o().possiblyUnhandledPromiseHandlers.indexOf(e),1)}}}(e)},e.try=function(t,n,r){var o=void 0;try{o=t.apply(n,r||[])}catch(t){return e.reject(t)}return e.resolve(o)},e.delay=function(t){return new e(function(e){setTimeout(e,t)})},e.isPromise=function(t){return!!(t&&t instanceof e)||r(t)},e.flush=function(){var t=new e;return o().flushPromises.push(t),0===o().activeCount&&e.flushQueue(),t},e.flushQueue=function(){var e=o().flushPromises;o().flushPromises=[];for(var t=0,n=null==e?0:e.length;t<n;t++)e[t].resolve()},e}();n.d(t,"a",function(){return i})},function(e,t,n){"use strict";t.a=function(){return!!(window.navigator.mockUserAgent||window.navigator.userAgent).match(/Android|webOS|iPhone|iPad|iPod|bada|Symbian|Palm|CriOS|BlackBerry|IEMobile|WindowsMobile|Opera Mini/i)}},function(e,t,n){"use strict";t.a=function(e){var t=e.name,n=e.version,o=void 0===n?"latest":n,i=e.lifetime,u=void 0===i?3e5:i,s="__"+t+"_"+o+"_storage__",a=void 0;function c(e){var t=Object(r.c)(),n=void 0;if(a&&(n=a),!n&&t){var o=window.localStorage.getItem(s);o&&(n=JSON.parse(o))}n||(n=Object(r.a)()[s]),n||(n={id:Object(r.k)()}),n.id||(n.id=Object(r.k)()),a=n;var i=e(n);return t?window.localStorage.setItem(s,JSON.stringify(n)):Object(r.a)()[s]=n,a=null,i}function l(e){return c(function(t){var n=t.__session__,o=Date.now();return n&&o-n.created>u&&(n=null),n||(n={guid:Object(r.k)(),created:o}),t.__session__=n,e(n)})}return{getState:c,getID:function(){return c(function(e){return e.id})},getSessionState:function(e){return l(function(t){return t.state=t.state||{},e(t.state)})},getSessionID:function(){return l(function(e){return e.guid})}}};var r=n(0)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),o=n(5),i={DEBUG:"debug",INFO:"info",WARN:"warn",ERROR:"error"},u=[i.WARN,i.ERROR],s=[i.ERROR,i.WARN,i.INFO,i.DEBUG],a=6e4,c=i.WARN,l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e};function f(e){var t=e.url,n=e.method,r=e.headers,i=e.json;return Object(o.request)({url:t,method:n,headers:r,json:i}).then(o.noop)}function d(e,t){for(var n in t)t.hasOwnProperty(n)&&t[n]&&(e[n]=t[n])}function h(e){var t=e.url,n=e.prefix,h=e.logLevel,p=void 0===h?c:h,v=e.transport,w=void 0===v?f:v,m=e.flushInterval,_=void 0===m?a:m,y=[],g=[],b=[],j=[],O=[],E=[];function T(e,t,n){if(Object(o.isBrowser)()&&window.console&&window.console.log){var r=p;if(window.LOG_LEVEL&&-1!==s.indexOf(window.LOG_LEVEL)&&(r=window.LOG_LEVEL),!(s.indexOf(e)>s.indexOf(r))){var i=[t];i.push(n),(n.error||n.warning)&&i.push("\n\n",n.error||n.warning);try{window.console[e]&&window.console[e].apply?window.console[e].apply(window.console,i):window.console.log&&window.console.log.apply&&window.console.log.apply(window.console,i)}catch(e){}}}}function S(){return r.a.try(function(){if(Object(o.isBrowser)()&&(y.length||g.length)){for(var e={},n=0,r=null==j?0:j.length;n<r;n++)d(e,(0,j[n])(e));for(var i={},u=0,s=null==E?0:E.length;u<s;u++)d(i,(0,E[u])(i));var a=w({method:"POST",url:t,headers:i,json:{events:y,meta:e,tracking:g}});return y=[],g=[],a.then(o.noop)}})}var P=Object(o.promiseDebounce)(S);function x(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(Object(o.isBrowser)()){n&&(t=n+"_"+t);for(var i=l({},Object(o.objFilter)(r),{timestamp:Date.now().toString()}),s=0,a=null==b?0:b.length;s<a;s++)d(i,(0,b[s])(i));!function(e,t,n){y.push({level:e,event:t,payload:n}),-1!==u.indexOf(e)&&P()}(e,t,i),T(e,t,i)}}return Object(o.safeInterval)(P,_),{debug:function(e,t){x(i.DEBUG,e,t)},info:function(e,t){x(i.INFO,e,t)},warn:function(e,t){x(i.WARN,e,t)},error:function(e,t){x(i.ERROR,e,t)},track:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(Object(o.isBrowser)()){for(var t=Object(o.objFilter)(e),n=0,r=null==O?0:O.length;n<r;n++)d(t,(0,O[n])(t));T(i.DEBUG,"track",t),g.push(t)}},flush:P,immediateFlush:S,addPayloadBuilder:function(e){b.push(e)},addMetaBuilder:function(e){j.push(e)},addTrackingBuilder:function(e){O.push(e)},addHeaderBuilder:function(e){E.push(e)},setTransport:function(e){w=e}}}n.d(t,"Logger",function(){return h}),n.d(t,"LOG_LEVEL",function(){return i})},function(e,t,n){"use strict";n(2);var r=n(6);n.d(t,"isBrowser",function(){return r.a}),n(7),n(8),n(9),n(3);var o=n(0);n.d(t,"noop",function(){return o.d}),n.d(t,"objFilter",function(){return o.e}),n.d(t,"promiseDebounce",function(){return o.f}),n.d(t,"safeInterval",function(){return o.i});var i=n(10);n.d(t,"request",function(){return i.a});var u=n(14);n.n(u)},function(e,t,n){"use strict";t.a=function(){return"undefined"!=typeof window},n(1),n(0),n(2)},function(e,t,n){"use strict";n(0),n(3)},function(e,t,n){"use strict";n(0)},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")}n(0),Object.assign,function(e){function t(n){return r(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,"",{},n))}(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)})(t,e),t.prototype.toString=function(){return this.childrenToString()}}(function(){function e(t,n,o){r(this,e),this.name=t,this.props=n,this.children=o}return e.prototype.toString=function(){return"<"+this.name+(this.props?" ":"")+(this.props?this.propsToString():"")+">"+this.childrenToString()+"</"+this.name+">"},e.prototype.propsToString=function(){var e=this.props;return e?Object.keys(e).filter(function(t){return"innerHTML"!==t&&e&&!1!==e[t]}).map(function(t){if(e){var n=e[t];if(!0===n)return""+o(t);if("string"==typeof n)return o(t)+'="'+o(n)+'"'}return""}).filter(Boolean).join(" "):""},e.prototype.childrenToString=function(){if(this.props&&this.props.innerHTML)return this.props.innerHTML;if(!this.children)return"";var t="";return function n(r){for(var i=0,u=null==r?0:r.length;i<u;i++){var s=r[i];null!==s&&void 0!==s&&(Array.isArray(s)?n(s):t+=s instanceof e?s.toString():o(s))}}(this.children),t},e}())},function(e,t,n){"use strict";t.a=function(e){var t=e.url,n=e.method,s=void 0===n?"get":n,a=e.headers,c=void 0===a?{}:a,l=e.json,f=e.data,d=e.body,h=e.win,p=void 0===h?window:h,v=e.timeout,w=void 0===v?0:v;return new r.a(function(e,n){if(l&&f||l&&d||f&&l)throw new Error("Only options.json or options.data or options.body should be passed");for(var r={},a=0,h=Object.keys(c),v=null==h?0:h.length;a<v;a++){var m=h[a];r[m.toLowerCase()]=c[m]}l?r[i.CONTENT_TYPE]=r[i.CONTENT_TYPE]||"application/json":(f||d)&&(r[i.CONTENT_TYPE]=r[i.CONTENT_TYPE]||"application/x-www-form-urlencoded; charset=utf-8"),r[i.ACCEPT]=r[i.ACCEPT]||"application/json";for(var _=0,y=null==u?0:u.length;_<y;_++)for(var g=(0,u[_])(),b=0,j=Object.keys(g),O=null==j?0:j.length;b<O;b++){var E=j[b];r[E.toLowerCase()]=g[E]}var T=new p.XMLHttpRequest;for(var S in T.addEventListener("load",function(){var r=function(){for(var e={},t=0,n=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().split("\n"),r=null==n?0:n.length;t<r;t++){var o=n[t].split(":"),i=o[0],u=o.slice(1);e[i.toLowerCase()]=u.join(":").trim()}return e}(this.getAllResponseHeaders());if(!this.status)return n(new Error("Request to "+s.toLowerCase()+" "+t+" failed: no response status code."));var i=r["content-type"],u=i&&(0===i.indexOf("application/json")||0===i.indexOf("text/json")),a=this.responseText;try{a=JSON.parse(this.responseText)}catch(e){if(u)return n(new Error("Invalid json: "+this.responseText+"."))}if(this.status>=400){var c="Request to "+s.toLowerCase()+" "+t+" failed with "+this.status+" error.";return a&&("object"===(void 0===a?"undefined":o(a))&&null!==a&&(a=JSON.stringify(a,null,4)),c=c+"\n\n"+a+"\n"),n(new Error(c))}return e(a)},!1),T.addEventListener("error",function(e){n(new Error("Request to "+s.toLowerCase()+" "+t+" failed: "+e.toString()+"."))},!1),T.open(s,t,!0),r)r.hasOwnProperty(S)&&T.setRequestHeader(S,r[S]);l?d=JSON.stringify(l):f&&(d=Object.keys(f).map(function(e){return encodeURIComponent(e)+"="+(f?encodeURIComponent(f[e]):"")}).join("&")),T.timeout=w,T.ontimeout=function(){n(new Error("Request to "+s.toLowerCase()+" "+t+" has timed out"))},T.send(d)})};var r=n(1),o=(n(11),"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}),i={CONTENT_TYPE:"content-type",ACCEPT:"accept"},u=[]},function(e,t,n){"use strict";n(12);var r=n(13);n.n(r)},function(e,t,n){"use strict"},function(e,t){},function(e,t){}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("beaver",[],t):"object"==typeof exports?exports.beaver=t():e.beaver=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get: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=4)}([function(e,t,n){"use strict";t.a=o,t.b=i,t.d=function(){},t.k=function(){var e="0123456789abcdef";return"xxxxxxxxxx".replace(/./g,function(){return e.charAt(Math.floor(Math.random()*e.length))})+"_"+u((new Date).toISOString().slice(11,19).replace("T",".")).replace(/[^a-zA-Z0-9]/g,"").toLowerCase()},t.c=function e(){return i(e,function(){try{if("undefined"==typeof window)return!1;if(window.localStorage){var e=Math.random().toString();window.localStorage.setItem("__test__localStorage__",e);var t=window.localStorage.getItem("__test__localStorage__");if(window.localStorage.removeItem("__test__localStorage__"),e===t)return!0}}catch(e){}return!1})},t.g=function(e,t,n){var r=[];return e.replace(t,function(){r.push(n.apply(null,arguments))}),r},t.j=function(e){return"data:image/svg+xml;base64,"+u(e)},t.e=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Boolean,n={};for(var r in e)e.hasOwnProperty(r)&&t(e[r],r)&&(n[r]=e[r]);return n},t.h=function(e,t){var n=[];return e.replace(t,function(e){return n.push(e),""}),n},t.f=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:50,n=void 0,o=void 0;return function(){o&&clearTimeout(o);var i=n=n||new r.a;return o=setTimeout(function(){n=null,o=null,r.a.try(e).then(function(e){return i.resolve(e)},function(e){return i.reject(e)})},t),i}},t.i=function(e,t){var n=void 0;return function r(){n=setTimeout(function(){e(),r()},t)}(),{cancel:function(){clearTimeout(n)}}};var r=n(1);function o(){if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("No global found")}function i(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return e.__memoized__||(e.__memoized__=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e.__memoized__)return e.__memoized__;var n={};return e.__memoized__=function(){for(var r=arguments.length,i=Array(r),u=0;u<r;u++)i[u]=arguments[u];if(e.__memoized__&&e.__memoized__.__calling__)throw new Error("Can not call memoized method recursively");var s=void 0;try{s=JSON.stringify(Array.prototype.slice.call(arguments))}catch(e){throw new Error("Arguments not serializable -- can not be used to memoize")}var c=t.time;n[s]&&c&&Date.now()-n[s].time<c&&delete n[s];var a=o();if(a.__CACHE_START_TIME__&&n[s]&&n[s].time<a.__CACHE_START_TIME__&&delete n[s],n[s])return n[s].value;e.__memoized__.__calling__=!0;var l=Date.now(),f=e.apply(this,arguments);return e.__memoized__.__calling__=!1,n[s]={time:l,value:f},n[s].value},e.__memoized__}(t)),e.__memoized__.apply(e,n)}function u(e){return window.btoa(e)}},function(e,t,n){"use strict";function r(e){try{if(!e)return!1;if("undefined"!=typeof Promise&&e instanceof Promise)return!0;if("undefined"!=typeof window&&window.Window&&e instanceof window.Window)return!1;if("undefined"!=typeof window&&window.constructor&&e instanceof window.constructor)return!1;var t={}.toString;if(t){var n=t.call(e);if("[object Window]"===n||"[object global]"===n||"[object DOMWindow]"===n)return!1}if("function"==typeof e.then)return!0}catch(e){return!1}return!1}function o(){var e=void 0;if("undefined"!=typeof window)e=window;else{if("undefined"==typeof global)throw new TypeError("Can not find global");e=global}var t=e.__zalgopromise__=e.__zalgopromise__||{};return t.flushPromises=t.flushPromises||[],t.activeCount=t.activeCount||0,t.possiblyUnhandledPromiseHandlers=t.possiblyUnhandledPromiseHandlers||[],t.dispatchedErrors=t.dispatchedErrors||[],t}var i=function(){function e(t){var n=this;if(function(t,n){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this),this.resolved=!1,this.rejected=!1,this.errorHandled=!1,this.handlers=[],t){var r=void 0,o=void 0,i=!1,u=!1,s=!1;try{t(function(e){s?n.resolve(e):(i=!0,r=e)},function(e){s?n.reject(e):(u=!0,o=e)})}catch(e){return void this.reject(e)}s=!0,i?this.resolve(r):u&&this.reject(o)}}return e.prototype.resolve=function(e){if(this.resolved||this.rejected)return this;if(r(e))throw new Error("Can not resolve promise with another promise");return this.resolved=!0,this.value=e,this.dispatch(),this},e.prototype.reject=function(e){var t=this;if(this.resolved||this.rejected)return this;if(r(e))throw new Error("Can not reject promise with another promise");if(!e){var n=e&&"function"==typeof e.toString?e.toString():Object.prototype.toString.call(e);e=new Error("Expected reject to be called with Error, got "+n)}return this.rejected=!0,this.error=e,this.errorHandled||setTimeout(function(){t.errorHandled||function(e){if(-1===o().dispatchedErrors.indexOf(e)){o().dispatchedErrors.push(e),setTimeout(function(){throw e},1);for(var t=0;t<o().possiblyUnhandledPromiseHandlers.length;t++)o().possiblyUnhandledPromiseHandlers[t](e)}}(e)},1),this.dispatch(),this},e.prototype.asyncReject=function(e){this.errorHandled=!0,this.reject(e)},e.prototype.dispatch=function(){var t=this,n=this.dispatching,i=this.resolved,u=this.rejected,s=this.handlers;if(!n&&(i||u)){this.dispatching=!0,o().activeCount+=1;for(var c=function(n){var o=s[n],c=o.onSuccess,a=o.onError,l=o.promise,f=void 0;if(i)try{f=c?c(t.value):t.value}catch(e){return l.reject(e),"continue"}else if(u){if(!a)return l.reject(t.error),"continue";try{f=a(t.error)}catch(e){return l.reject(e),"continue"}}f instanceof e&&(f.resolved||f.rejected)?(f.resolved?l.resolve(f.value):l.reject(f.error),f.errorHandled=!0):r(f)?f instanceof e&&(f.resolved||f.rejected)?f.resolved?l.resolve(f.value):l.reject(f.error):f.then(function(e){l.resolve(e)},function(e){l.reject(e)}):l.resolve(f)},a=0;a<s.length;a++)c(a);s.length=0,this.dispatching=!1,o().activeCount-=1,0===o().activeCount&&e.flushQueue()}},e.prototype.then=function(t,n){if(t&&"function"!=typeof t&&!t.call)throw new Error("Promise.then expected a function for success handler");if(n&&"function"!=typeof n&&!n.call)throw new Error("Promise.then expected a function for error handler");var r=new e;return this.handlers.push({promise:r,onSuccess:t,onError:n}),this.errorHandled=!0,this.dispatch(),r},e.prototype.catch=function(e){return this.then(void 0,e)},e.prototype.finally=function(t){return this.then(function(n){return e.try(t).then(function(){return n})},function(n){return e.try(t).then(function(){throw n})})},e.prototype.timeout=function(e,t){var n=this;if(this.resolved||this.rejected)return this;var r=setTimeout(function(){n.resolved||n.rejected||n.reject(t||new Error("Promise timed out after "+e+"ms"))},e);return this.then(function(e){return clearTimeout(r),e})},e.prototype.toPromise=function(){if("undefined"==typeof Promise)throw new TypeError("Could not find Promise");return Promise.resolve(this)},e.resolve=function(t){return t instanceof e?t:r(t)?new e(function(e,n){return t.then(e,n)}):(new e).resolve(t)},e.reject=function(t){return(new e).reject(t)},e.all=function(t){var n=new e,o=t.length,i=[];if(!o)return n.resolve(i),n;for(var u=function(u){var s=t[u];if(s instanceof e){if(s.resolved)return i[u]=s.value,o-=1,"continue"}else if(!r(s))return i[u]=s,o-=1,"continue";e.resolve(s).then(function(e){i[u]=e,0==(o-=1)&&n.resolve(i)},function(e){n.reject(e)})},s=0;s<t.length;s++)u(s);return 0===o&&n.resolve(i),n},e.hash=function(t){var n={};return e.all(Object.keys(t).map(function(r){return e.resolve(t[r]).then(function(e){n[r]=e})})).then(function(){return n})},e.map=function(t,n){return e.all(t.map(n))},e.onPossiblyUnhandledException=function(e){return function(e){return o().possiblyUnhandledPromiseHandlers.push(e),{cancel:function(){o().possiblyUnhandledPromiseHandlers.splice(o().possiblyUnhandledPromiseHandlers.indexOf(e),1)}}}(e)},e.try=function(t,n,r){var o=void 0;try{o=t.apply(n,r||[])}catch(t){return e.reject(t)}return e.resolve(o)},e.delay=function(t){return new e(function(e){setTimeout(e,t)})},e.isPromise=function(t){return!!(t&&t instanceof e)||r(t)},e.flush=function(){var t=new e;return o().flushPromises.push(t),0===o().activeCount&&e.flushQueue(),t},e.flushQueue=function(){var e=o().flushPromises;o().flushPromises=[];for(var t=0,n=null==e?0:e.length;t<n;t++)e[t].resolve()},e}();n.d(t,"a",function(){return i})},function(e,t,n){"use strict";t.a=function(){return!!(window.navigator.mockUserAgent||window.navigator.userAgent).match(/Android|webOS|iPhone|iPad|iPod|bada|Symbian|Palm|CriOS|BlackBerry|IEMobile|WindowsMobile|Opera Mini/i)}},function(e,t,n){"use strict";t.a=function(e){var t=e.name,n=e.version,o=void 0===n?"latest":n,i=e.lifetime,u=void 0===i?3e5:i,s="__"+t+"_"+o+"_storage__",c=void 0;function a(e){var t=Object(r.c)(),n=void 0;if(c&&(n=c),!n&&t){var o=window.localStorage.getItem(s);o&&(n=JSON.parse(o))}n||(n=Object(r.a)()[s]),n||(n={id:Object(r.k)()}),n.id||(n.id=Object(r.k)()),c=n;var i=e(n);return t?window.localStorage.setItem(s,JSON.stringify(n)):Object(r.a)()[s]=n,c=null,i}function l(e){return a(function(t){var n=t.__session__,o=Date.now();return n&&o-n.created>u&&(n=null),n||(n={guid:Object(r.k)(),created:o}),t.__session__=n,e(n)})}return{getState:a,getID:function(){return a(function(e){return e.id})},getSessionState:function(e){return l(function(t){return t.state=t.state||{},e(t.state)})},getSessionID:function(){return l(function(e){return e.guid})}}};var r=n(0)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),o=n(5),i={DEBUG:"debug",INFO:"info",WARN:"warn",ERROR:"error"},u=[i.WARN,i.ERROR],s=[i.ERROR,i.WARN,i.INFO,i.DEBUG],c=6e4,a=i.WARN,l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e};function f(e){var t=e.url,n=e.method,r=e.headers,i=e.json;return Object(o.request)({url:t,method:n,headers:r,json:i}).then(o.noop)}function d(e,t){for(var n in t)t.hasOwnProperty(n)&&t[n]&&(e[n]=t[n])}function h(e){var t=e.url,n=e.prefix,h=e.logLevel,p=void 0===h?a:h,v=e.transport,w=void 0===v?f:v,m=e.flushInterval,_=void 0===m?c:m,y=[],g=[],b=[],j=[],O=[],E=[];function T(e,t,n){if(Object(o.isBrowser)()&&window.console&&window.console.log){var r=p;if(window.LOG_LEVEL&&-1!==s.indexOf(window.LOG_LEVEL)&&(r=window.LOG_LEVEL),!(s.indexOf(e)>s.indexOf(r))){var i=[t];i.push(n),(n.error||n.warning)&&i.push("\n\n",n.error||n.warning);try{window.console[e]&&window.console[e].apply?window.console[e].apply(window.console,i):window.console.log&&window.console.log.apply&&window.console.log.apply(window.console,i)}catch(e){}}}}function S(){return r.a.try(function(){if(Object(o.isBrowser)()&&(y.length||g.length)){for(var e={},n=0,r=null==j?0:j.length;n<r;n++)d(e,(0,j[n])(e));for(var i={},u=0,s=null==E?0:E.length;u<s;u++)d(i,(0,E[u])(i));var c=w({method:"POST",url:t,headers:i,json:{events:y,meta:e,tracking:g}});return y=[],g=[],c.then(o.noop)}})}var P=Object(o.promiseDebounce)(S);function x(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(Object(o.isBrowser)()){n&&(t=n+"_"+t);for(var i=l({},Object(o.objFilter)(r),{timestamp:Date.now().toString()}),s=0,c=null==b?0:b.length;s<c;s++)d(i,(0,b[s])(i));!function(e,t,n){y.push({level:e,event:t,payload:n}),-1!==u.indexOf(e)&&P()}(e,t,i),T(e,t,i)}}return Object(o.isBrowser)()&&Object(o.safeInterval)(P,_),{debug:function(e,t){x(i.DEBUG,e,t)},info:function(e,t){x(i.INFO,e,t)},warn:function(e,t){x(i.WARN,e,t)},error:function(e,t){x(i.ERROR,e,t)},track:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(Object(o.isBrowser)()){for(var t=Object(o.objFilter)(e),n=0,r=null==O?0:O.length;n<r;n++)d(t,(0,O[n])(t));T(i.DEBUG,"track",t),g.push(t)}},flush:P,immediateFlush:S,addPayloadBuilder:function(e){b.push(e)},addMetaBuilder:function(e){j.push(e)},addTrackingBuilder:function(e){O.push(e)},addHeaderBuilder:function(e){E.push(e)},setTransport:function(e){w=e}}}n.d(t,"Logger",function(){return h}),n.d(t,"LOG_LEVEL",function(){return i})},function(e,t,n){"use strict";n(2);var r=n(6);n.d(t,"isBrowser",function(){return r.a}),n(7),n(8),n(9),n(3);var o=n(0);n.d(t,"noop",function(){return o.d}),n.d(t,"objFilter",function(){return o.e}),n.d(t,"promiseDebounce",function(){return o.f}),n.d(t,"safeInterval",function(){return o.i});var i=n(10);n.d(t,"request",function(){return i.a});var u=n(14);n.n(u)},function(e,t,n){"use strict";t.a=function(){return"undefined"!=typeof window},n(1),n(0),n(2)},function(e,t,n){"use strict";n(0),n(3)},function(e,t,n){"use strict";n(0)},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")}n(0),Object.assign,function(e){function t(n){return r(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,"",{},n))}(function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)})(t,e),t.prototype.toString=function(){return this.childrenToString()}}(function(){function e(t,n,o){r(this,e),this.name=t,this.props=n,this.children=o}return e.prototype.toString=function(){return"<"+this.name+(this.props?" ":"")+(this.props?this.propsToString():"")+">"+this.childrenToString()+"</"+this.name+">"},e.prototype.propsToString=function(){var e=this.props;return e?Object.keys(e).filter(function(t){return"innerHTML"!==t&&e&&!1!==e[t]}).map(function(t){if(e){var n=e[t];if(!0===n)return""+o(t);if("string"==typeof n)return o(t)+'="'+o(n)+'"'}return""}).filter(Boolean).join(" "):""},e.prototype.childrenToString=function(){if(this.props&&this.props.innerHTML)return this.props.innerHTML;if(!this.children)return"";var t="";return function n(r){for(var i=0,u=null==r?0:r.length;i<u;i++){var s=r[i];null!==s&&void 0!==s&&(Array.isArray(s)?n(s):t+=s instanceof e?s.toString():o(s))}}(this.children),t},e}())},function(e,t,n){"use strict";t.a=function(e){var t=e.url,n=e.method,s=void 0===n?"get":n,c=e.headers,a=void 0===c?{}:c,l=e.json,f=e.data,d=e.body,h=e.win,p=void 0===h?window:h,v=e.timeout,w=void 0===v?0:v;return new r.a(function(e,n){if(l&&f||l&&d||f&&l)throw new Error("Only options.json or options.data or options.body should be passed");for(var r={},c=0,h=Object.keys(a),v=null==h?0:h.length;c<v;c++){var m=h[c];r[m.toLowerCase()]=a[m]}l?r[i.CONTENT_TYPE]=r[i.CONTENT_TYPE]||"application/json":(f||d)&&(r[i.CONTENT_TYPE]=r[i.CONTENT_TYPE]||"application/x-www-form-urlencoded; charset=utf-8"),r[i.ACCEPT]=r[i.ACCEPT]||"application/json";for(var _=0,y=null==u?0:u.length;_<y;_++)for(var g=(0,u[_])(),b=0,j=Object.keys(g),O=null==j?0:j.length;b<O;b++){var E=j[b];r[E.toLowerCase()]=g[E]}var T=new p.XMLHttpRequest;for(var S in T.addEventListener("load",function(){var r=function(){for(var e={},t=0,n=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().split("\n"),r=null==n?0:n.length;t<r;t++){var o=n[t].split(":"),i=o[0],u=o.slice(1);e[i.toLowerCase()]=u.join(":").trim()}return e}(this.getAllResponseHeaders());if(!this.status)return n(new Error("Request to "+s.toLowerCase()+" "+t+" failed: no response status code."));var i=r["content-type"],u=i&&(0===i.indexOf("application/json")||0===i.indexOf("text/json")),c=this.responseText;try{c=JSON.parse(this.responseText)}catch(e){if(u)return n(new Error("Invalid json: "+this.responseText+"."))}if(this.status>=400){var a="Request to "+s.toLowerCase()+" "+t+" failed with "+this.status+" error.";return c&&("object"===(void 0===c?"undefined":o(c))&&null!==c&&(c=JSON.stringify(c,null,4)),a=a+"\n\n"+c+"\n"),n(new Error(a))}return e(c)},!1),T.addEventListener("error",function(e){n(new Error("Request to "+s.toLowerCase()+" "+t+" failed: "+e.toString()+"."))},!1),T.open(s,t,!0),r)r.hasOwnProperty(S)&&T.setRequestHeader(S,r[S]);l?d=JSON.stringify(l):f&&(d=Object.keys(f).map(function(e){return encodeURIComponent(e)+"="+(f?encodeURIComponent(f[e]):"")}).join("&")),T.timeout=w,T.ontimeout=function(){n(new Error("Request to "+s.toLowerCase()+" "+t+" has timed out"))},T.send(d)})};var r=n(1),o=(n(11),"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}),i={CONTENT_TYPE:"content-type",ACCEPT:"accept"},u=[]},function(e,t,n){"use strict";n(12);var r=n(13);n.n(r)},function(e,t,n){"use strict"},function(e,t){},function(e,t){}])}); | ||
//# sourceMappingURL=beaver-logger.min.js.map | ||
//# sourceMappingURL=beaver-logger.min.js.map |
@@ -216,3 +216,5 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
safeInterval(flush, flushInterval); | ||
if (isBrowser()) { | ||
safeInterval(flush, flushInterval); | ||
} | ||
@@ -219,0 +221,0 @@ return { |
{ | ||
"name": "beaver-logger", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"description": "Client side logger.", | ||
@@ -13,2 +13,3 @@ "main": "dist/beaver-logger.js", | ||
"babel": "babel src/ --out-dir dist/module", | ||
"babel-server": "babel server/**/*.js --exclude=node_modules --out-dir .", | ||
"webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress", | ||
@@ -22,3 +23,5 @@ "test": "npm run lint && npm run flow-typed && npm run flow && npm run karma", | ||
"clean": "rimraf dist coverage", | ||
"reinstall": "rimraf flow-typed && rimraf node_modules && npm install && flow-typed install" | ||
"reinstall": "rimraf flow-typed && rimraf node_modules && npm install && flow-typed install", | ||
"prepublish": "in-publish && npm run babel-server || not-in-publish", | ||
"postpublish": "git checkout server" | ||
}, | ||
@@ -25,0 +28,0 @@ "repository": { |
@@ -1,25 +0,23 @@ | ||
/* @flow */ | ||
export const LOG_LEVEL = { | ||
DEBUG: ('debug' : 'debug'), | ||
INFO: ('info' : 'info'), | ||
WARN: ('warn' : 'warn'), | ||
ERROR: ('error' : 'error') | ||
export var LOG_LEVEL = { | ||
DEBUG: 'debug', | ||
INFO: 'info', | ||
WARN: 'warn', | ||
ERROR: 'error' | ||
}; | ||
export const HTTP_HEADER = { | ||
ORIGIN: ('origin' : 'origin'), | ||
ACCESS_CONTROL_ALLOW_ORIGIN: ('access-control-allow-origin' : 'access-control-allow-origin'), | ||
ACCESS_CONTROL_ALLOW_HEADERS: ('access-control-allow-headers' : 'access-control-allow-headers'), | ||
ACCESS_CONTROL_ALLOW_METHODS: ('access-control-allow-methods' : 'access-control-allow-methods'), | ||
ACCESS_CONTROL_REQUEST_HEADERS: ('access-control-request-headers' : 'access-control-request-headers'), | ||
ACCESS_CONTROL_REQUEST_METHOD: ('access-control-request-method' : 'access-control-request-method') | ||
export var HTTP_HEADER = { | ||
ORIGIN: 'origin', | ||
ACCESS_CONTROL_ALLOW_ORIGIN: 'access-control-allow-origin', | ||
ACCESS_CONTROL_ALLOW_HEADERS: 'access-control-allow-headers', | ||
ACCESS_CONTROL_ALLOW_METHODS: 'access-control-allow-methods', | ||
ACCESS_CONTROL_REQUEST_HEADERS: 'access-control-request-headers', | ||
ACCESS_CONTROL_REQUEST_METHOD: 'access-control-request-method' | ||
}; | ||
export const HTTP_METHOD = { | ||
GET: ('get' : 'get'), | ||
POST: ('post' : 'post'), | ||
OPTIONS: ('options' : 'options') | ||
export var HTTP_METHOD = { | ||
GET: 'get', | ||
POST: 'post', | ||
OPTIONS: 'options' | ||
}; | ||
export const WILDCARD = '*'; | ||
export var WILDCARD = '*'; |
@@ -1,3 +0,1 @@ | ||
/* @flow */ | ||
export * from './server'; | ||
export * from './server'; |
@@ -1,2 +0,3 @@ | ||
/* @flow */ | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
/* eslint no-console: 0 */ | ||
@@ -6,78 +7,45 @@ | ||
import { LOG_LEVEL, HTTP_HEADER, HTTP_METHOD, WILDCARD } from './constants'; | ||
import { LOG_LEVEL, HTTP_HEADER, HTTP_METHOD, WILDCARD } from './constants'; // eslint-disable-line no-undef | ||
// eslint-disable-line no-undef | ||
type ExpressRequest = express$Request; // eslint-disable-line no-undef | ||
type ExpressResponse = express$Response; // eslint-disable-line no-undef | ||
var defaultLogger = { | ||
log: function log(req, level, name, payload) { | ||
var date = payload.timestamp ? new Date(payload.timestamp).toString() : new Date().toString(); | ||
type Logger = { | ||
log : (req : ExpressRequest, level : $Values<typeof LOG_LEVEL>, name : string, payload : { [string] : string }) => void, | ||
track : (req : ExpressRequest, payload : { [string] : string }) => void, | ||
meta : (req : ExpressRequest, meta : { [string] : string }) => void | ||
}; | ||
var str = [name, '\t[ ', date, ' ]\n', Object.keys(payload).map(function (key) { | ||
return '\t' + key + ': ' + payload[key]; | ||
}).join('\n'), '\n'].join(''); | ||
type Event = { | ||
event : string, | ||
payload : { [string] : string }, | ||
level : $Values<typeof LOG_LEVEL> | ||
}; | ||
type Tracking = { [string] : string }; | ||
type Meta = { [string] : string }; | ||
let defaultLogger : Logger = { | ||
log(req, level, name, payload) { | ||
let date = payload.timestamp | ||
? new Date(payload.timestamp).toString() | ||
: new Date().toString(); | ||
let str = [ | ||
name, | ||
'\t[ ', | ||
date, | ||
' ]\n', | ||
Object.keys(payload) | ||
.map((key) => { | ||
return `\t${ key }: ${ payload[key] }`; | ||
}) | ||
.join('\n'), | ||
'\n' | ||
].join(''); | ||
console[level](str); | ||
}, | ||
track(req, tracking) { | ||
console.log( | ||
'[track]\n', | ||
Object.keys(tracking) | ||
.map((key) => { | ||
return `\t${ key }: ${ tracking[key] }`; | ||
}) | ||
.join('\n'), | ||
'\n' | ||
); | ||
track: function track(req, tracking) { | ||
console.log('[track]\n', Object.keys(tracking).map(function (key) { | ||
return '\t' + key + ': ' + tracking[key]; | ||
}).join('\n'), '\n'); | ||
}, | ||
meta: function (_meta) { | ||
function meta(_x, _x2) { | ||
return _meta.apply(this, arguments); | ||
} | ||
meta(req, meta) { | ||
console.log( | ||
'[meta]\n', | ||
Object.keys(meta) | ||
.map((key) => { | ||
return `\t${ key }: ${ meta[key] }`; | ||
}) | ||
.join('\n'), | ||
'\n' | ||
); | ||
} | ||
meta.toString = function () { | ||
return _meta.toString(); | ||
}; | ||
return meta; | ||
}(function (req, meta) { | ||
console.log('[meta]\n', Object.keys(meta).map(function (key) { | ||
return '\t' + key + ': ' + meta[key]; | ||
}).join('\n'), '\n'); | ||
}) | ||
}; | ||
export function log(req : ExpressRequest, logger : Logger, logs : { events : Array<Event>, tracking? : Array<Tracking>, meta? : Meta }) { | ||
export function log(req, logger, logs) { | ||
let events = logs.events || []; | ||
let tracking = logs.tracking || []; | ||
let meta = logs.meta || {}; | ||
var events = logs.events || []; | ||
var tracking = logs.tracking || []; | ||
var meta = logs.meta || {}; | ||
if (logger.log) { | ||
events.forEach((event) => { | ||
events.forEach(function (event) { | ||
if (!event.event) { | ||
@@ -99,3 +67,3 @@ return; | ||
if (logger.track) { | ||
tracking.forEach(track => { | ||
tracking.forEach(function (track) { | ||
logger.track(req, track); | ||
@@ -106,40 +74,31 @@ }); | ||
type Query = { | ||
event : string, | ||
level? : $Values<typeof LOG_LEVEL>, | ||
[string] : string | ||
}; | ||
export function handleRequest(req, logger) { | ||
type Body = { | ||
events : Array<Event>, | ||
tracking? : Array<Tracking>, | ||
meta : Meta | ||
}; | ||
export function handleRequest(req : ExpressRequest, logger : Logger) { | ||
// $FlowFixMe | ||
let method : $Values<typeof HTTP_METHOD> = req.method || HTTP_METHOD.GET; | ||
var method = req.method || HTTP_METHOD.GET; | ||
// $FlowFixMe | ||
let query : Query = req.query; | ||
var query = req.query; | ||
// $FlowFixMe | ||
let body : Body = req.body; | ||
var body = req.body; | ||
if (method.toLowerCase() === 'post') { | ||
let { events, tracking, meta } = body; | ||
log(req, logger, { events, tracking, meta }); | ||
var _events = body.events, | ||
_tracking = body.tracking, | ||
_meta2 = body.meta; | ||
log(req, logger, { events: _events, tracking: _tracking, meta: _meta2 }); | ||
} else { | ||
let { event, level = LOG_LEVEL.INFO, ...payload } = query; | ||
var _event = query.event, | ||
_query$level = query.level, | ||
_level = _query$level === undefined ? LOG_LEVEL.INFO : _query$level, | ||
_payload = _objectWithoutProperties(query, ['event', 'level']); | ||
log(req, logger, { | ||
events: [ | ||
{ | ||
level, | ||
event, | ||
payload | ||
} | ||
] | ||
events: [{ | ||
level: _level, | ||
event: _event, | ||
payload: _payload | ||
}] | ||
}); | ||
@@ -149,13 +108,7 @@ } | ||
type ExpressEndpointOptions = { | ||
uri? : string, | ||
logger? : Logger, | ||
enableCors? : boolean | ||
}; | ||
function sendCorsHeaders(req, res) { | ||
var origin = req.get(HTTP_HEADER.ORIGIN); | ||
function sendCorsHeaders(req : ExpressRequest, res : ExpressResponse) { | ||
let origin = req.get(HTTP_HEADER.ORIGIN); | ||
if (origin) { | ||
let parsedUrl = url.parse(origin) || {}; | ||
var parsedUrl = url.parse(origin) || {}; | ||
@@ -165,5 +118,4 @@ if (!parsedUrl.protocol || !parsedUrl.host) { | ||
} else { | ||
res.header(HTTP_HEADER.ACCESS_CONTROL_ALLOW_ORIGIN, `${ parsedUrl.protocol }//${ parsedUrl.host }`); | ||
res.header(HTTP_HEADER.ACCESS_CONTROL_ALLOW_ORIGIN, parsedUrl.protocol + '//' + parsedUrl.host); | ||
} | ||
} else { | ||
@@ -173,3 +125,3 @@ res.header(HTTP_HEADER.ACCESS_CONTROL_ALLOW_ORIGIN, WILDCARD); | ||
let corsRequestHeaders = req.headers[HTTP_HEADER.ACCESS_CONTROL_REQUEST_HEADERS]; | ||
var corsRequestHeaders = req.headers[HTTP_HEADER.ACCESS_CONTROL_REQUEST_HEADERS]; | ||
@@ -180,3 +132,3 @@ if (corsRequestHeaders) { | ||
let corsRequestMethod = req.headers[HTTP_HEADER.ACCESS_CONTROL_REQUEST_METHOD]; | ||
var corsRequestMethod = req.headers[HTTP_HEADER.ACCESS_CONTROL_REQUEST_METHOD]; | ||
@@ -188,8 +140,15 @@ if (corsRequestMethod) { | ||
export function expressEndpoint({ uri = '/', logger = defaultLogger, enableCors = false } : ExpressEndpointOptions = {}) : mixed { | ||
export function expressEndpoint() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$uri = _ref.uri, | ||
uri = _ref$uri === undefined ? '/' : _ref$uri, | ||
_ref$logger = _ref.logger, | ||
logger = _ref$logger === undefined ? defaultLogger : _ref$logger, | ||
_ref$enableCors = _ref.enableCors, | ||
enableCors = _ref$enableCors === undefined ? false : _ref$enableCors; | ||
// $FlowFixMe | ||
let app = require('express')(); | ||
var app = require('express')(); | ||
app.all(uri, (req : ExpressRequest, res : ExpressResponse) => { | ||
app.all(uri, function (req, res) { | ||
if (enableCors) { | ||
@@ -213,2 +172,2 @@ sendCorsHeaders(req, res); | ||
return app; | ||
} | ||
} |
@@ -230,3 +230,5 @@ /* @flow */ | ||
safeInterval(flush, flushInterval); | ||
if (isBrowser()) { | ||
safeInterval(flush, flushInterval); | ||
} | ||
@@ -233,0 +235,0 @@ return { |
94452
1450