beaver-logger
Advanced tools
Comparing version 4.0.21 to 4.0.22
@@ -713,32 +713,47 @@ !function(root, factory) { | ||
} | ||
var memoizedFunctions = []; | ||
function getEmptyObject() { | ||
return {}; | ||
} | ||
var memoizeGlobalIndex = 0; | ||
var memoizeGlobalIndexValidFrom = 0; | ||
function memoize(method, options) { | ||
var _this = this; | ||
void 0 === options && (options = {}); | ||
var cacheMap = new weakmap_CrossDomainSafeWeakMap; | ||
var _options$thisNamespac = options.thisNamespace, thisNamespace = void 0 !== _options$thisNamespac && _options$thisNamespac, cacheTime = options.time; | ||
var simpleCache; | ||
var thisCache; | ||
var memoizeIndex = memoizeGlobalIndex; | ||
memoizeGlobalIndex += 1; | ||
var memoizedFunction = function() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key]; | ||
var cache = cacheMap.getOrSet(options.thisNamespace ? this : method, (function() { | ||
return {}; | ||
})); | ||
var key = serializeArgs(args); | ||
var cacheTime = options.time; | ||
cache[key] && cacheTime && Date.now() - cache[key].time < cacheTime && delete cache[key]; | ||
if (cache[key]) return cache[key].value; | ||
if (memoizeIndex < memoizeGlobalIndexValidFrom) { | ||
simpleCache = null; | ||
thisCache = null; | ||
memoizeIndex = memoizeGlobalIndex; | ||
memoizeGlobalIndex += 1; | ||
} | ||
var cache; | ||
cache = thisNamespace ? (thisCache = thisCache || new weakmap_CrossDomainSafeWeakMap).getOrSet(this, getEmptyObject) : simpleCache = simpleCache || {}; | ||
var cacheKey = serializeArgs(args); | ||
var cacheResult = cache[cacheKey]; | ||
if (cacheResult && cacheTime && Date.now() - cacheResult.time < cacheTime) { | ||
delete cache[cacheKey]; | ||
cacheResult = null; | ||
} | ||
if (cacheResult) return cacheResult.value; | ||
var time = Date.now(); | ||
var value = method.apply(this, arguments); | ||
cache[key] = { | ||
cache[cacheKey] = { | ||
time: time, | ||
value: value | ||
}; | ||
return cache[key].value; | ||
return value; | ||
}; | ||
memoizedFunction.reset = function() { | ||
cacheMap.delete(options.thisNamespace ? _this : method); | ||
simpleCache = null; | ||
thisCache = null; | ||
}; | ||
memoizedFunctions.push(memoizedFunction); | ||
return setFunctionName(memoizedFunction, (options.name || getFunctionName(method)) + "::memoized"); | ||
} | ||
memoize.clear = function() { | ||
for (var _i2 = 0; _i2 < memoizedFunctions.length; _i2++) memoizedFunctions[_i2].reset(); | ||
memoizeGlobalIndexValidFrom = memoizeGlobalIndex; | ||
}; | ||
@@ -777,3 +792,3 @@ function src_util_noop() {} | ||
function dom_isBrowser() { | ||
return "undefined" != typeof window; | ||
return "undefined" != typeof window && void 0 !== window.location; | ||
} | ||
@@ -795,4 +810,4 @@ var currentScript = "undefined" != typeof document ? document.currentScript : null; | ||
if (!scriptLocation) return; | ||
for (var _i20 = 0, _Array$prototype$slic2 = [].slice.call(document.getElementsByTagName("script")).reverse(); _i20 < _Array$prototype$slic2.length; _i20++) { | ||
var script = _Array$prototype$slic2[_i20]; | ||
for (var _i22 = 0, _Array$prototype$slic2 = [].slice.call(document.getElementsByTagName("script")).reverse(); _i22 < _Array$prototype$slic2.length; _i22++) { | ||
var script = _Array$prototype$slic2[_i22]; | ||
if (script.src && script.src === scriptLocation) return script; | ||
@@ -814,7 +829,67 @@ } | ||
if (uid && "string" == typeof uid) return uid; | ||
if ((uid = script.getAttribute("data-uid-auto")) && "string" == typeof uid) return uid; | ||
uid = uniqueID(); | ||
script.setAttribute("data-uid", uid); | ||
script.setAttribute("data-uid-auto", uid); | ||
return uid; | ||
})); | ||
var http_headerBuilders = []; | ||
function request(_ref) { | ||
var url = _ref.url, _ref$method = _ref.method, method = void 0 === _ref$method ? "get" : _ref$method, _ref$headers = _ref.headers, headers = void 0 === _ref$headers ? {} : _ref$headers, json = _ref.json, data = _ref.data, body = _ref.body, _ref$win = _ref.win, win = void 0 === _ref$win ? window : _ref$win, _ref$timeout = _ref.timeout, timeout = void 0 === _ref$timeout ? 0 : _ref$timeout; | ||
return new promise_ZalgoPromise((function(resolve, reject) { | ||
if (json && data || json && body || data && json) throw new Error("Only options.json or options.data or options.body should be passed"); | ||
var normalizedHeaders = {}; | ||
for (var _i4 = 0, _Object$keys2 = Object.keys(headers); _i4 < _Object$keys2.length; _i4++) { | ||
var _key2 = _Object$keys2[_i4]; | ||
normalizedHeaders[_key2.toLowerCase()] = headers[_key2]; | ||
} | ||
json ? normalizedHeaders["content-type"] = normalizedHeaders["content-type"] || "application/json" : (data || body) && (normalizedHeaders["content-type"] = normalizedHeaders["content-type"] || "application/x-www-form-urlencoded; charset=utf-8"); | ||
normalizedHeaders.accept = normalizedHeaders.accept || "application/json"; | ||
for (var _i6 = 0; _i6 < http_headerBuilders.length; _i6++) { | ||
var builtHeaders = (0, http_headerBuilders[_i6])(); | ||
for (var _i8 = 0, _Object$keys4 = Object.keys(builtHeaders); _i8 < _Object$keys4.length; _i8++) { | ||
var _key3 = _Object$keys4[_i8]; | ||
normalizedHeaders[_key3.toLowerCase()] = builtHeaders[_key3]; | ||
} | ||
} | ||
var xhr = new win.XMLHttpRequest; | ||
xhr.addEventListener("load", (function() { | ||
var responseHeaders = function(rawHeaders) { | ||
void 0 === rawHeaders && (rawHeaders = ""); | ||
var result = {}; | ||
for (var _i2 = 0, _rawHeaders$trim$spli2 = rawHeaders.trim().split("\n"); _i2 < _rawHeaders$trim$spli2.length; _i2++) { | ||
var _line$split = _rawHeaders$trim$spli2[_i2].split(":"), _key = _line$split[0], values = _line$split.slice(1); | ||
result[_key.toLowerCase()] = values.join(":").trim(); | ||
} | ||
return result; | ||
}(this.getAllResponseHeaders()); | ||
if (!this.status) return reject(new Error("Request to " + method.toLowerCase() + " " + url + " failed: no response status code.")); | ||
var contentType = responseHeaders["content-type"]; | ||
var isJSON = contentType && (0 === contentType.indexOf("application/json") || 0 === contentType.indexOf("text/json")); | ||
var responseBody = this.responseText; | ||
try { | ||
responseBody = JSON.parse(responseBody); | ||
} catch (err) { | ||
if (isJSON) return reject(new Error("Invalid json: " + this.responseText + ".")); | ||
} | ||
return resolve({ | ||
status: this.status, | ||
headers: responseHeaders, | ||
body: responseBody | ||
}); | ||
}), !1); | ||
xhr.addEventListener("error", (function(evt) { | ||
reject(new Error("Request to " + method.toLowerCase() + " " + url + " failed: " + evt.toString() + ".")); | ||
}), !1); | ||
xhr.open(method, url, !0); | ||
for (var _key4 in normalizedHeaders) normalizedHeaders.hasOwnProperty(_key4) && xhr.setRequestHeader(_key4, normalizedHeaders[_key4]); | ||
json ? body = JSON.stringify(json) : data && (body = Object.keys(data).map((function(key) { | ||
return encodeURIComponent(key) + "=" + (data ? encodeURIComponent(data[key]) : ""); | ||
})).join("&")); | ||
xhr.timeout = timeout; | ||
xhr.ontimeout = function() { | ||
reject(new Error("Request to " + method.toLowerCase() + " " + url + " has timed out")); | ||
}; | ||
xhr.send(body); | ||
})); | ||
} | ||
var LOG_LEVEL = { | ||
@@ -839,62 +914,13 @@ DEBUG: "debug", | ||
}); | ||
resolve(window.navigator.sendBeacon(url, blob)); | ||
})) : function(_ref) { | ||
var url = _ref.url, _ref$method = _ref.method, method = void 0 === _ref$method ? "get" : _ref$method, _ref$headers = _ref.headers, headers = void 0 === _ref$headers ? {} : _ref$headers, json = _ref.json, data = _ref.data, body = _ref.body, _ref$win = _ref.win, win = void 0 === _ref$win ? window : _ref$win, _ref$timeout = _ref.timeout, timeout = void 0 === _ref$timeout ? 0 : _ref$timeout; | ||
return new promise_ZalgoPromise((function(resolve, reject) { | ||
if (json && data || json && body || data && json) throw new Error("Only options.json or options.data or options.body should be passed"); | ||
var normalizedHeaders = {}; | ||
for (var _i4 = 0, _Object$keys2 = Object.keys(headers); _i4 < _Object$keys2.length; _i4++) { | ||
var _key2 = _Object$keys2[_i4]; | ||
normalizedHeaders[_key2.toLowerCase()] = headers[_key2]; | ||
} | ||
json ? normalizedHeaders["content-type"] = normalizedHeaders["content-type"] || "application/json" : (data || body) && (normalizedHeaders["content-type"] = normalizedHeaders["content-type"] || "application/x-www-form-urlencoded; charset=utf-8"); | ||
normalizedHeaders.accept = normalizedHeaders.accept || "application/json"; | ||
for (var _i6 = 0; _i6 < http_headerBuilders.length; _i6++) { | ||
var builtHeaders = (0, http_headerBuilders[_i6])(); | ||
for (var _i8 = 0, _Object$keys4 = Object.keys(builtHeaders); _i8 < _Object$keys4.length; _i8++) { | ||
var _key3 = _Object$keys4[_i8]; | ||
normalizedHeaders[_key3.toLowerCase()] = builtHeaders[_key3]; | ||
} | ||
} | ||
var xhr = new win.XMLHttpRequest; | ||
xhr.addEventListener("load", (function() { | ||
var responseHeaders = function(rawHeaders) { | ||
void 0 === rawHeaders && (rawHeaders = ""); | ||
var result = {}; | ||
for (var _i2 = 0, _rawHeaders$trim$spli2 = rawHeaders.trim().split("\n"); _i2 < _rawHeaders$trim$spli2.length; _i2++) { | ||
var _line$split = _rawHeaders$trim$spli2[_i2].split(":"), _key = _line$split[0], values = _line$split.slice(1); | ||
result[_key.toLowerCase()] = values.join(":").trim(); | ||
} | ||
return result; | ||
}(this.getAllResponseHeaders()); | ||
if (!this.status) return reject(new Error("Request to " + method.toLowerCase() + " " + url + " failed: no response status code.")); | ||
var contentType = responseHeaders["content-type"]; | ||
var isJSON = contentType && (0 === contentType.indexOf("application/json") || 0 === contentType.indexOf("text/json")); | ||
var responseBody = this.responseText; | ||
try { | ||
responseBody = JSON.parse(responseBody); | ||
} catch (err) { | ||
if (isJSON) return reject(new Error("Invalid json: " + this.responseText + ".")); | ||
} | ||
return resolve({ | ||
status: this.status, | ||
headers: responseHeaders, | ||
body: responseBody | ||
}); | ||
}), !1); | ||
xhr.addEventListener("error", (function(evt) { | ||
reject(new Error("Request to " + method.toLowerCase() + " " + url + " failed: " + evt.toString() + ".")); | ||
}), !1); | ||
xhr.open(method, url, !0); | ||
for (var _key4 in normalizedHeaders) normalizedHeaders.hasOwnProperty(_key4) && xhr.setRequestHeader(_key4, normalizedHeaders[_key4]); | ||
json ? body = JSON.stringify(json) : data && (body = Object.keys(data).map((function(key) { | ||
return encodeURIComponent(key) + "=" + (data ? encodeURIComponent(data[key]) : ""); | ||
})).join("&")); | ||
xhr.timeout = timeout; | ||
xhr.ontimeout = function() { | ||
reject(new Error("Request to " + method.toLowerCase() + " " + url + " has timed out")); | ||
}; | ||
xhr.send(body); | ||
})); | ||
}({ | ||
try { | ||
resolve(window.navigator.sendBeacon(url, blob)); | ||
} catch (e) { | ||
return request({ | ||
url: url, | ||
method: method, | ||
headers: headers, | ||
json: json | ||
}).then(src_util_noop); | ||
} | ||
})) : request({ | ||
url: url, | ||
@@ -901,0 +927,0 @@ method: method, |
@@ -1,2 +0,2 @@ | ||
!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,{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 o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));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{}.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function o(e){try{if(!e)return!1;if("undefined"!=typeof Promise&&e instanceof Promise)return!0;if("undefined"!=typeof window&&"function"==typeof window.Window&&e instanceof window.Window)return!1;if("undefined"!=typeof window&&"function"==typeof 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}n.r(t),n.d(t,"Logger",(function(){return V})),n.d(t,"LOG_LEVEL",(function(){return H})),n.d(t,"PROTOCOL",(function(){return U}));var i,a=[],u=[],c=0;function s(){if(!c&&i){var e=i;i=null,e.resolve()}}function f(){c+=1}function d(){c-=1,s()}var l=function(){function e(e){var t=this;if(this.resolved=void 0,this.rejected=void 0,this.errorHandled=void 0,this.value=void 0,this.error=void 0,this.handlers=void 0,this.dispatching=void 0,this.stack=void 0,this.resolved=!1,this.rejected=!1,this.errorHandled=!1,this.handlers=[],e){var n,r,o=!1,i=!1,a=!1;f();try{e((function(e){a?t.resolve(e):(o=!0,n=e)}),(function(e){a?t.reject(e):(i=!0,r=e)}))}catch(e){return d(),void this.reject(e)}d(),a=!0,o?this.resolve(n):i&&this.reject(r)}}var t=e.prototype;return t.resolve=function(e){if(this.resolved||this.rejected)return this;if(o(e))throw new Error("Can not resolve promise with another promise");return this.resolved=!0,this.value=e,this.dispatch(),this},t.reject=function(e){var t=this;if(this.resolved||this.rejected)return this;if(o(e))throw new Error("Can not reject promise with another promise");if(!e){var n=e&&"function"==typeof e.toString?e.toString():{}.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,t){if(-1===a.indexOf(e)){a.push(e),setTimeout((function(){throw e}),1);for(var n=0;n<u.length;n++)u[n](e,t)}}(e,t)}),1),this.dispatch(),this},t.asyncReject=function(e){return this.errorHandled=!0,this.reject(e),this},t.dispatch=function(){var t=this.resolved,n=this.rejected,r=this.handlers;if(!this.dispatching&&(t||n)){this.dispatching=!0,f();for(var i=function(e,t){return e.then((function(e){t.resolve(e)}),(function(e){t.reject(e)}))},a=0;a<r.length;a++){var u=r[a],c=u.onSuccess,s=u.onError,l=u.promise,h=void 0;if(t)try{h=c?c(this.value):this.value}catch(e){l.reject(e);continue}else if(n){if(!s){l.reject(this.error);continue}try{h=s(this.error)}catch(e){l.reject(e);continue}}h instanceof e&&(h.resolved||h.rejected)?(h.resolved?l.resolve(h.value):l.reject(h.error),h.errorHandled=!0):o(h)?h instanceof e&&(h.resolved||h.rejected)?h.resolved?l.resolve(h.value):l.reject(h.error):i(h,l):l.resolve(h)}r.length=0,this.dispatching=!1,d()}},t.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},t.catch=function(e){return this.then(void 0,e)},t.finally=function(t){if(t&&"function"!=typeof t&&!t.call)throw new Error("Promise.finally expected a function");return this.then((function(n){return e.try(t).then((function(){return n}))}),(function(n){return e.try(t).then((function(){throw n}))}))},t.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}))},t.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:o(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.asyncReject=function(t){return(new e).asyncReject(t)},e.all=function(t){var n=new e,r=t.length,i=[];if(!r)return n.resolve(i),n;for(var a=function(e,t,o){return t.then((function(t){i[e]=t,0==(r-=1)&&n.resolve(i)}),(function(e){o.reject(e)}))},u=0;u<t.length;u++){var c=t[u];if(c instanceof e){if(c.resolved){i[u]=c.value,r-=1;continue}}else if(!o(c)){i[u]=c,r-=1;continue}a(u,e.resolve(c),n)}return 0===r&&n.resolve(i),n},e.hash=function(t){var n={},r=[],i=function(e){if(t.hasOwnProperty(e)){var i=t[e];o(i)?r.push(i.then((function(t){n[e]=t}))):n[e]=i}};for(var a in t)i(a);return e.all(r).then((function(){return n}))},e.map=function(t,n){return e.all(t.map(n))},e.onPossiblyUnhandledException=function(e){return function(e){return u.push(e),{cancel:function(){u.splice(u.indexOf(e),1)}}}(e)},e.try=function(t,n,r){if(t&&"function"!=typeof t&&!t.call)throw new Error("Promise.try expected a function");var o;f();try{o=t.apply(n,r||[])}catch(t){return d(),e.reject(t)}return d(),e.resolve(o)},e.delay=function(t){return new e((function(e){setTimeout(e,t)}))},e.isPromise=function(t){return!!(t&&t instanceof e)||o(t)},e.flush=function(){return t=i=i||new e,s(),t;var t},e}(),h="Call was rejected by callee.\r\n";function v(e){return void 0===e&&(e=window),"about:"===e.location.protocol}function p(e){try{return!0}catch(e){}return!1}function w(e){void 0===e&&(e=window);var t=e.location;if(!t)throw new Error("Can not read window location");var n=t.protocol;if(!n)throw new Error("Can not read window protocol");if("file:"===n)return"file://";if("about:"===n){var r=function(e){if(void 0===e&&(e=window),e)try{if(e.parent&&e.parent!==e)return e.parent}catch(e){}}(e);return r&&p()?w(r):"about://"}var o=t.host;if(!o)throw new Error("Can not read window host");return n+"//"+o}function y(e){void 0===e&&(e=window);var t=w(e);return t&&e.mockDomain&&0===e.mockDomain.indexOf("mock:")?e.mockDomain:t}var m=[],g=[];function j(e,t){void 0===t&&(t=!0);try{if(e===window)return!1}catch(e){return!0}try{if(!e)return!0}catch(e){return!0}try{if(e.closed)return!0}catch(e){return!e||e.message!==h}if(t&&function(e){if(!function(e){try{if(e===window)return!0}catch(e){}try{var t=Object.getOwnPropertyDescriptor(e,"location");if(t&&!1===t.enumerable)return!1}catch(e){}try{if(v(e)&&p())return!0}catch(e){}try{if(w(e)===w(window))return!0}catch(e){}return!1}(e))return!1;try{if(e===window)return!0;if(v(e)&&p())return!0;if(y(window)===y(e))return!0}catch(e){}return!1}(e))try{if(e.mockclosed)return!0}catch(e){}try{if(!e.parent||!e.top)return!0}catch(e){}var n=function(e,t){for(var n=0;n<e.length;n++)try{if(e[n]===t)return n}catch(e){}return-1}(m,e);if(-1!==n){var r=g[n];if(r&&function(e){if(!e.contentWindow)return!0;if(!e.parentNode)return!0;var t=e.ownerDocument;if(t&&t.documentElement&&!t.documentElement.contains(e)){for(var n=e;n.parentNode&&n.parentNode!==n;)n=n.parentNode;if(!n.host||!t.documentElement.contains(n.host))return!0}return!1}(r))return!0}return!1}function b(e){try{if(e===window)return!0}catch(e){if(e&&e.message===h)return!0}try{if("[object Window]"==={}.toString.call(e))return!0}catch(e){if(e&&e.message===h)return!0}try{if(window.Window&&e instanceof window.Window)return!0}catch(e){if(e&&e.message===h)return!0}try{if(e&&e.self===e)return!0}catch(e){if(e&&e.message===h)return!0}try{if(e&&e.parent===e)return!0}catch(e){if(e&&e.message===h)return!0}try{if(e&&e.top===e)return!0}catch(e){if(e&&e.message===h)return!0}try{if(e&&"__unlikely_value__"===e.__cross_domain_utils_window_check__)return!1}catch(e){return!0}try{if("postMessage"in e&&"self"in e&&"location"in e)return!0}catch(e){}return!1}function O(e,t){for(var n=0;n<e.length;n++)try{if(e[n]===t)return n}catch(e){}return-1}var E,_=function(){function e(){if(this.name=void 0,this.weakmap=void 0,this.keys=void 0,this.values=void 0,this.name="__weakmap_"+(1e9*Math.random()>>>0)+"__",function(){if("undefined"==typeof WeakMap)return!1;if(void 0===Object.freeze)return!1;try{var e=new WeakMap,t={};return Object.freeze(t),e.set(t,"__testvalue__"),"__testvalue__"===e.get(t)}catch(e){return!1}}())try{this.weakmap=new WeakMap}catch(e){}this.keys=[],this.values=[]}var t=e.prototype;return t._cleanupClosedWindows=function(){for(var e=this.weakmap,t=this.keys,n=0;n<t.length;n++){var r=t[n];if(b(r)&&j(r)){if(e)try{e.delete(r)}catch(e){}t.splice(n,1),this.values.splice(n,1),n-=1}}},t.isSafeToReadWrite=function(e){return!b(e)},t.set=function(e,t){if(!e)throw new Error("WeakMap expected key");var n=this.weakmap;if(n)try{n.set(e,t)}catch(e){delete this.weakmap}if(this.isSafeToReadWrite(e))try{var r=this.name,o=e[r];return void(o&&o[0]===e?o[1]=t:Object.defineProperty(e,r,{value:[e,t],writable:!0}))}catch(e){}this._cleanupClosedWindows();var i=this.keys,a=this.values,u=O(i,e);-1===u?(i.push(e),a.push(t)):a[u]=t},t.get=function(e){if(!e)throw new Error("WeakMap expected key");var t=this.weakmap;if(t)try{if(t.has(e))return t.get(e)}catch(e){delete this.weakmap}if(this.isSafeToReadWrite(e))try{var n=e[this.name];return n&&n[0]===e?n[1]:void 0}catch(e){}this._cleanupClosedWindows();var r=O(this.keys,e);if(-1!==r)return this.values[r]},t.delete=function(e){if(!e)throw new Error("WeakMap expected key");var t=this.weakmap;if(t)try{t.delete(e)}catch(e){delete this.weakmap}if(this.isSafeToReadWrite(e))try{var n=e[this.name];n&&n[0]===e&&(n[0]=n[1]=void 0)}catch(e){}this._cleanupClosedWindows();var r=this.keys,o=O(r,e);-1!==o&&(r.splice(o,1),this.values.splice(o,1))},t.has=function(e){if(!e)throw new Error("WeakMap expected key");var t=this.weakmap;if(t)try{if(t.has(e))return!0}catch(e){delete this.weakmap}if(this.isSafeToReadWrite(e))try{var n=e[this.name];return!(!n||n[0]!==e)}catch(e){}return this._cleanupClosedWindows(),-1!==O(this.keys,e)},t.getOrSet=function(e,t){if(this.has(e))return this.get(e);var n=t();return this.set(e,n),n},e}();function k(e){return e.name||e.__name__||e.displayName||"anonymous"}function x(e,t){try{delete e.name,e.name=t}catch(e){}return e.__name__=e.displayName=t,e}function S(){var e="0123456789abcdef";return"xxxxxxxxxx".replace(/./g,(function(){return e.charAt(Math.floor(Math.random()*e.length))}))+"_"+function(e){if("function"==typeof btoa)return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(parseInt(t,16))})));if("undefined"!=typeof Buffer)return Buffer.from(e,"utf8").toString("base64");throw new Error("Can not find window.btoa or Buffer")}((new Date).toISOString().slice(11,19).replace("T",".")).replace(/[^a-zA-Z0-9]/g,"").toLowerCase()}function R(e){try{return JSON.stringify([].slice.call(e),(function(e,t){return"function"==typeof t?"memoize["+function(e){if(E=E||new _,null==e||"object"!=typeof e&&"function"!=typeof e)throw new Error("Invalid object");var t=E.get(e);return t||(t=typeof e+":"+S(),E.set(e,t)),t}(t)+"]":t}))}catch(e){throw new Error("Arguments not serializable -- can not be used to memoize")}}var W=[];function P(e,t){var n=this;void 0===t&&(t={});var r=new _,o=function(){for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];var a=r.getOrSet(t.thisNamespace?this:e,(function(){return{}})),u=R(o),c=t.time;if(a[u]&&c&&Date.now()-a[u].time<c&&delete a[u],a[u])return a[u].value;var s=Date.now(),f=e.apply(this,arguments);return a[u]={time:s,value:f},a[u].value};return o.reset=function(){r.delete(t.thisNamespace?n:e)},W.push(o),x(o,(t.name||k(e))+"::memoized")}function C(){}function T(e,t){void 0===t&&(t=Boolean);var n={};for(var r in e)e.hasOwnProperty(r)&&t(e[r],r)&&(n[r]=e[r]);return n}function B(){return Boolean(document.body)&&"complete"===document.readyState}function N(){return Boolean(document.body)&&"interactive"===document.readyState}function L(){return"undefined"!=typeof window}P.clear=function(){for(var e=0;e<W.length;e++)W[e].reset()},P((function(e){if(Object.values)return Object.values(e);var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(e[n]);return t})),Error,P((function(){return new l((function(e){if(B()||N())return e();var t=setInterval((function(){if(B()||N())return clearInterval(t),e()}),10)}))}));var M="undefined"!=typeof document?document.currentScript:null,D=P((function(){if(M)return M;if(M=function(){try{var e=function(){try{throw new Error("_")}catch(e){return e.stack||""}}(),t=/.*at [^(]*\((.*):(.+):(.+)\)$/gi.exec(e),n=t&&t[1];if(!n)return;for(var r=0,o=[].slice.call(document.getElementsByTagName("script")).reverse();r<o.length;r++){var i=o[r];if(i.src&&i.src===n)return i}}catch(e){}}())return M;throw new Error("Can not determine current script")})),I=S();P((function(){var e;try{e=D()}catch(e){return I}var t=e.getAttribute("data-uid");return t&&"string"==typeof t||(t=S(),e.setAttribute("data-uid",t)),t}));var A=[],H={DEBUG:"debug",INFO:"info",WARN:"warn",ERROR:"error"},U={FILE:"file:"},z=[H.WARN,H.ERROR],F=[H.ERROR,H.WARN,H.INFO,H.DEBUG],q=H.WARN;function G(e){var t=e.url,n=e.method,r=e.headers,o=e.json,i=e.enableSendBeacon,a=void 0!==i&&i,u=r&&Object.keys(r).length;return window&&window.navigator.sendBeacon&&!u&&a&&window.Blob?new l((function(e){var n=new Blob([JSON.stringify(o)],{type:"application/json"});e(window.navigator.sendBeacon(t,n))})):function(e){var t=e.url,n=e.method,r=void 0===n?"get":n,o=e.headers,i=void 0===o?{}:o,a=e.json,u=e.data,c=e.body,s=e.win,f=void 0===s?window:s,d=e.timeout,h=void 0===d?0:d;return new l((function(e,n){if(a&&u||a&&c||u&&a)throw new Error("Only options.json or options.data or options.body should be passed");for(var o={},s=0,d=Object.keys(i);s<d.length;s++){var l=d[s];o[l.toLowerCase()]=i[l]}a?o["content-type"]=o["content-type"]||"application/json":(u||c)&&(o["content-type"]=o["content-type"]||"application/x-www-form-urlencoded; charset=utf-8"),o.accept=o.accept||"application/json";for(var v=0;v<A.length;v++)for(var p=(0,A[v])(),w=0,y=Object.keys(p);w<y.length;w++){var m=y[w];o[m.toLowerCase()]=p[m]}var g=new f.XMLHttpRequest;for(var j in g.addEventListener("load",(function(){var o=function(e){void 0===e&&(e="");for(var t={},n=0,r=e.trim().split("\n");n<r.length;n++){var o=r[n].split(":"),i=o[0],a=o.slice(1);t[i.toLowerCase()]=a.join(":").trim()}return t}(this.getAllResponseHeaders());if(!this.status)return n(new Error("Request to "+r.toLowerCase()+" "+t+" failed: no response status code."));var i=o["content-type"],a=i&&(0===i.indexOf("application/json")||0===i.indexOf("text/json")),u=this.responseText;try{u=JSON.parse(u)}catch(e){if(a)return n(new Error("Invalid json: "+this.responseText+"."))}return e({status:this.status,headers:o,body:u})}),!1),g.addEventListener("error",(function(e){n(new Error("Request to "+r.toLowerCase()+" "+t+" failed: "+e.toString()+"."))}),!1),g.open(r,t,!0),o)o.hasOwnProperty(j)&&g.setRequestHeader(j,o[j]);a?c=JSON.stringify(a):u&&(c=Object.keys(u).map((function(e){return encodeURIComponent(e)+"="+(u?encodeURIComponent(u[e]):"")})).join("&")),g.timeout=h,g.ontimeout=function(){n(new Error("Request to "+r.toLowerCase()+" "+t+" has timed out"))},g.send(c)}))}({url:t,method:n,headers:r,json:o}).then(C)}function J(e,t){for(var n in t)t.hasOwnProperty(n)&&t[n]&&!e[n]&&(e[n]=t[n])}function V(e){var t=e.url,n=e.prefix,o=e.logLevel,i=void 0===o?q:o,a=e.transport,u=void 0===a?G:a,c=e.flushInterval,s=void 0===c?6e4:c,f=e.enableSendBeacon,d=void 0!==f&&f,h=[],v=[],p=[],w=[],y=[],m=[];function g(e,t,n){if(L()&&window.console&&window.console.log&&!(F.indexOf(e)>F.indexOf(i))){var r=[t];r.push(n),(n.error||n.warning)&&r.push("\n\n",n.error||n.warning);try{window.console[e]&&window.console[e].apply?window.console[e].apply(window.console,r):window.console.log&&window.console.log.apply&&window.console.log.apply(window.console,r)}catch(e){}}}function j(){return l.try((function(){if(L()&&window.location.protocol!==U.FILE&&(h.length||v.length)){for(var e={},n=0;n<w.length;n++)J(e,(0,w[n])(e));for(var r={},o=0;o<m.length;o++)J(r,(0,m[o])(r));var i=u({method:"POST",url:t,headers:r,json:{events:h,meta:e,tracking:v},enableSendBeacon:d});return h=[],v=[],i.then(C)}}))}var b,O,E,_,S=(void 0===O&&(O=50),x((function(){_&&clearTimeout(_);var e=E=E||new l;return _=setTimeout((function(){E=null,_=null,l.try(b).then((function(t){e.resolve(t)}),(function(t){e.reject(t)}))}),O),e}),k(b=j)+"::promiseDebounced"));function R(e,t,o){if(void 0===o&&(o={}),!L())return P;n&&(t=n+"_"+t);for(var i=r({},T(o),{timestamp:Date.now().toString()}),a=0;a<p.length;a++)J(i,(0,p[a])(i));return function(e,t,n){h.push({level:e,event:t,payload:n}),-1!==z.indexOf(e)&&S()}(e,t,i),g(e,t,i),P}function W(e,t){return e.push(t),P}L()&&function(e,t){!function n(){setTimeout((function(){e(),n()}),t)}()}(S,s),"object"==typeof window&&(window.addEventListener("beforeunload",(function(){j()})),window.addEventListener("unload",(function(){j()})));var P={debug:function(e,t){return R(H.DEBUG,e,t)},info:function(e,t){return R(H.INFO,e,t)},warn:function(e,t){return R(H.WARN,e,t)},error:function(e,t){return R(H.ERROR,e,t)},track:function(e){if(void 0===e&&(e={}),!L())return P;for(var t=T(e),n=0;n<y.length;n++)J(t,(0,y[n])(t));return g(H.DEBUG,"track",t),v.push(t),P},flush:S,immediateFlush:j,addPayloadBuilder:function(e){return W(p,e)},addMetaBuilder:function(e){return W(w,e)},addTrackingBuilder:function(e){return W(y,e)},addHeaderBuilder:function(e){return W(m,e)},setTransport:function(e){return u=e,P}};return P}}])})); | ||
!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,{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 o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));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{}.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function o(e){try{if(!e)return!1;if("undefined"!=typeof Promise&&e instanceof Promise)return!0;if("undefined"!=typeof window&&"function"==typeof window.Window&&e instanceof window.Window)return!1;if("undefined"!=typeof window&&"function"==typeof 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}n.r(t),n.d(t,"Logger",(function(){return $})),n.d(t,"LOG_LEVEL",(function(){return F})),n.d(t,"PROTOCOL",(function(){return q}));var i,a=[],u=[],c=0;function s(){if(!c&&i){var e=i;i=null,e.resolve()}}function f(){c+=1}function d(){c-=1,s()}var l=function(){function e(e){var t=this;if(this.resolved=void 0,this.rejected=void 0,this.errorHandled=void 0,this.value=void 0,this.error=void 0,this.handlers=void 0,this.dispatching=void 0,this.stack=void 0,this.resolved=!1,this.rejected=!1,this.errorHandled=!1,this.handlers=[],e){var n,r,o=!1,i=!1,a=!1;f();try{e((function(e){a?t.resolve(e):(o=!0,n=e)}),(function(e){a?t.reject(e):(i=!0,r=e)}))}catch(e){return d(),void this.reject(e)}d(),a=!0,o?this.resolve(n):i&&this.reject(r)}}var t=e.prototype;return t.resolve=function(e){if(this.resolved||this.rejected)return this;if(o(e))throw new Error("Can not resolve promise with another promise");return this.resolved=!0,this.value=e,this.dispatch(),this},t.reject=function(e){var t=this;if(this.resolved||this.rejected)return this;if(o(e))throw new Error("Can not reject promise with another promise");if(!e){var n=e&&"function"==typeof e.toString?e.toString():{}.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,t){if(-1===a.indexOf(e)){a.push(e),setTimeout((function(){throw e}),1);for(var n=0;n<u.length;n++)u[n](e,t)}}(e,t)}),1),this.dispatch(),this},t.asyncReject=function(e){return this.errorHandled=!0,this.reject(e),this},t.dispatch=function(){var t=this.resolved,n=this.rejected,r=this.handlers;if(!this.dispatching&&(t||n)){this.dispatching=!0,f();for(var i=function(e,t){return e.then((function(e){t.resolve(e)}),(function(e){t.reject(e)}))},a=0;a<r.length;a++){var u=r[a],c=u.onSuccess,s=u.onError,l=u.promise,h=void 0;if(t)try{h=c?c(this.value):this.value}catch(e){l.reject(e);continue}else if(n){if(!s){l.reject(this.error);continue}try{h=s(this.error)}catch(e){l.reject(e);continue}}h instanceof e&&(h.resolved||h.rejected)?(h.resolved?l.resolve(h.value):l.reject(h.error),h.errorHandled=!0):o(h)?h instanceof e&&(h.resolved||h.rejected)?h.resolved?l.resolve(h.value):l.reject(h.error):i(h,l):l.resolve(h)}r.length=0,this.dispatching=!1,d()}},t.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},t.catch=function(e){return this.then(void 0,e)},t.finally=function(t){if(t&&"function"!=typeof t&&!t.call)throw new Error("Promise.finally expected a function");return this.then((function(n){return e.try(t).then((function(){return n}))}),(function(n){return e.try(t).then((function(){throw n}))}))},t.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}))},t.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:o(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.asyncReject=function(t){return(new e).asyncReject(t)},e.all=function(t){var n=new e,r=t.length,i=[];if(!r)return n.resolve(i),n;for(var a=function(e,t,o){return t.then((function(t){i[e]=t,0==(r-=1)&&n.resolve(i)}),(function(e){o.reject(e)}))},u=0;u<t.length;u++){var c=t[u];if(c instanceof e){if(c.resolved){i[u]=c.value,r-=1;continue}}else if(!o(c)){i[u]=c,r-=1;continue}a(u,e.resolve(c),n)}return 0===r&&n.resolve(i),n},e.hash=function(t){var n={},r=[],i=function(e){if(t.hasOwnProperty(e)){var i=t[e];o(i)?r.push(i.then((function(t){n[e]=t}))):n[e]=i}};for(var a in t)i(a);return e.all(r).then((function(){return n}))},e.map=function(t,n){return e.all(t.map(n))},e.onPossiblyUnhandledException=function(e){return function(e){return u.push(e),{cancel:function(){u.splice(u.indexOf(e),1)}}}(e)},e.try=function(t,n,r){if(t&&"function"!=typeof t&&!t.call)throw new Error("Promise.try expected a function");var o;f();try{o=t.apply(n,r||[])}catch(t){return d(),e.reject(t)}return d(),e.resolve(o)},e.delay=function(t){return new e((function(e){setTimeout(e,t)}))},e.isPromise=function(t){return!!(t&&t instanceof e)||o(t)},e.flush=function(){return t=i=i||new e,s(),t;var t},e}(),h="Call was rejected by callee.\r\n";function v(e){return void 0===e&&(e=window),"about:"===e.location.protocol}function w(e){try{return!0}catch(e){}return!1}function p(e){void 0===e&&(e=window);var t=e.location;if(!t)throw new Error("Can not read window location");var n=t.protocol;if(!n)throw new Error("Can not read window protocol");if("file:"===n)return"file://";if("about:"===n){var r=function(e){if(void 0===e&&(e=window),e)try{if(e.parent&&e.parent!==e)return e.parent}catch(e){}}(e);return r&&w()?p(r):"about://"}var o=t.host;if(!o)throw new Error("Can not read window host");return n+"//"+o}function y(e){void 0===e&&(e=window);var t=p(e);return t&&e.mockDomain&&0===e.mockDomain.indexOf("mock:")?e.mockDomain:t}var m=[],g=[];function j(e,t){void 0===t&&(t=!0);try{if(e===window)return!1}catch(e){return!0}try{if(!e)return!0}catch(e){return!0}try{if(e.closed)return!0}catch(e){return!e||e.message!==h}if(t&&function(e){if(!function(e){try{if(e===window)return!0}catch(e){}try{var t=Object.getOwnPropertyDescriptor(e,"location");if(t&&!1===t.enumerable)return!1}catch(e){}try{if(v(e)&&w())return!0}catch(e){}try{if(p(e)===p(window))return!0}catch(e){}return!1}(e))return!1;try{if(e===window)return!0;if(v(e)&&w())return!0;if(y(window)===y(e))return!0}catch(e){}return!1}(e))try{if(e.mockclosed)return!0}catch(e){}try{if(!e.parent||!e.top)return!0}catch(e){}var n=function(e,t){for(var n=0;n<e.length;n++)try{if(e[n]===t)return n}catch(e){}return-1}(m,e);if(-1!==n){var r=g[n];if(r&&function(e){if(!e.contentWindow)return!0;if(!e.parentNode)return!0;var t=e.ownerDocument;if(t&&t.documentElement&&!t.documentElement.contains(e)){for(var n=e;n.parentNode&&n.parentNode!==n;)n=n.parentNode;if(!n.host||!t.documentElement.contains(n.host))return!0}return!1}(r))return!0}return!1}function b(e){try{if(e===window)return!0}catch(e){if(e&&e.message===h)return!0}try{if("[object Window]"==={}.toString.call(e))return!0}catch(e){if(e&&e.message===h)return!0}try{if(window.Window&&e instanceof window.Window)return!0}catch(e){if(e&&e.message===h)return!0}try{if(e&&e.self===e)return!0}catch(e){if(e&&e.message===h)return!0}try{if(e&&e.parent===e)return!0}catch(e){if(e&&e.message===h)return!0}try{if(e&&e.top===e)return!0}catch(e){if(e&&e.message===h)return!0}try{if(e&&"__unlikely_value__"===e.__cross_domain_utils_window_check__)return!1}catch(e){return!0}try{if("postMessage"in e&&"self"in e&&"location"in e)return!0}catch(e){}return!1}function O(e,t){for(var n=0;n<e.length;n++)try{if(e[n]===t)return n}catch(e){}return-1}var E,_=function(){function e(){if(this.name=void 0,this.weakmap=void 0,this.keys=void 0,this.values=void 0,this.name="__weakmap_"+(1e9*Math.random()>>>0)+"__",function(){if("undefined"==typeof WeakMap)return!1;if(void 0===Object.freeze)return!1;try{var e=new WeakMap,t={};return Object.freeze(t),e.set(t,"__testvalue__"),"__testvalue__"===e.get(t)}catch(e){return!1}}())try{this.weakmap=new WeakMap}catch(e){}this.keys=[],this.values=[]}var t=e.prototype;return t._cleanupClosedWindows=function(){for(var e=this.weakmap,t=this.keys,n=0;n<t.length;n++){var r=t[n];if(b(r)&&j(r)){if(e)try{e.delete(r)}catch(e){}t.splice(n,1),this.values.splice(n,1),n-=1}}},t.isSafeToReadWrite=function(e){return!b(e)},t.set=function(e,t){if(!e)throw new Error("WeakMap expected key");var n=this.weakmap;if(n)try{n.set(e,t)}catch(e){delete this.weakmap}if(this.isSafeToReadWrite(e))try{var r=this.name,o=e[r];return void(o&&o[0]===e?o[1]=t:Object.defineProperty(e,r,{value:[e,t],writable:!0}))}catch(e){}this._cleanupClosedWindows();var i=this.keys,a=this.values,u=O(i,e);-1===u?(i.push(e),a.push(t)):a[u]=t},t.get=function(e){if(!e)throw new Error("WeakMap expected key");var t=this.weakmap;if(t)try{if(t.has(e))return t.get(e)}catch(e){delete this.weakmap}if(this.isSafeToReadWrite(e))try{var n=e[this.name];return n&&n[0]===e?n[1]:void 0}catch(e){}this._cleanupClosedWindows();var r=O(this.keys,e);if(-1!==r)return this.values[r]},t.delete=function(e){if(!e)throw new Error("WeakMap expected key");var t=this.weakmap;if(t)try{t.delete(e)}catch(e){delete this.weakmap}if(this.isSafeToReadWrite(e))try{var n=e[this.name];n&&n[0]===e&&(n[0]=n[1]=void 0)}catch(e){}this._cleanupClosedWindows();var r=this.keys,o=O(r,e);-1!==o&&(r.splice(o,1),this.values.splice(o,1))},t.has=function(e){if(!e)throw new Error("WeakMap expected key");var t=this.weakmap;if(t)try{if(t.has(e))return!0}catch(e){delete this.weakmap}if(this.isSafeToReadWrite(e))try{var n=e[this.name];return!(!n||n[0]!==e)}catch(e){}return this._cleanupClosedWindows(),-1!==O(this.keys,e)},t.getOrSet=function(e,t){if(this.has(e))return this.get(e);var n=t();return this.set(e,n),n},e}();function k(e){return e.name||e.__name__||e.displayName||"anonymous"}function x(e,t){try{delete e.name,e.name=t}catch(e){}return e.__name__=e.displayName=t,e}function S(){var e="0123456789abcdef";return"xxxxxxxxxx".replace(/./g,(function(){return e.charAt(Math.floor(Math.random()*e.length))}))+"_"+function(e){if("function"==typeof btoa)return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(parseInt(t,16))})));if("undefined"!=typeof Buffer)return Buffer.from(e,"utf8").toString("base64");throw new Error("Can not find window.btoa or Buffer")}((new Date).toISOString().slice(11,19).replace("T",".")).replace(/[^a-zA-Z0-9]/g,"").toLowerCase()}function R(e){try{return JSON.stringify([].slice.call(e),(function(e,t){return"function"==typeof t?"memoize["+function(e){if(E=E||new _,null==e||"object"!=typeof e&&"function"!=typeof e)throw new Error("Invalid object");var t=E.get(e);return t||(t=typeof e+":"+S(),E.set(e,t)),t}(t)+"]":t}))}catch(e){throw new Error("Arguments not serializable -- can not be used to memoize")}}function W(){return{}}var P=0,C=0;function T(e,t){void 0===t&&(t={});var n,r,o=t.thisNamespace,i=void 0!==o&&o,a=t.time,u=P;P+=1;var c=function(){for(var t=arguments.length,o=new Array(t),c=0;c<t;c++)o[c]=arguments[c];var s;u<C&&(n=null,r=null,u=P,P+=1),s=i?(r=r||new _).getOrSet(this,W):n=n||{};var f=R(o),d=s[f];if(d&&a&&Date.now()-d.time<a&&(delete s[f],d=null),d)return d.value;var l=Date.now(),h=e.apply(this,arguments);return s[f]={time:l,value:h},h};return c.reset=function(){n=null,r=null},x(c,(t.name||k(e))+"::memoized")}function B(){}function L(e,t){void 0===t&&(t=Boolean);var n={};for(var r in e)e.hasOwnProperty(r)&&t(e[r],r)&&(n[r]=e[r]);return n}function N(){return Boolean(document.body)&&"complete"===document.readyState}function M(){return Boolean(document.body)&&"interactive"===document.readyState}function D(){return"undefined"!=typeof window&&void 0!==window.location}T.clear=function(){C=P},T((function(e){if(Object.values)return Object.values(e);var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(e[n]);return t})),Error,T((function(){return new l((function(e){if(N()||M())return e();var t=setInterval((function(){if(N()||M())return clearInterval(t),e()}),10)}))}));var I="undefined"!=typeof document?document.currentScript:null,A=T((function(){if(I)return I;if(I=function(){try{var e=function(){try{throw new Error("_")}catch(e){return e.stack||""}}(),t=/.*at [^(]*\((.*):(.+):(.+)\)$/gi.exec(e),n=t&&t[1];if(!n)return;for(var r=0,o=[].slice.call(document.getElementsByTagName("script")).reverse();r<o.length;r++){var i=o[r];if(i.src&&i.src===n)return i}}catch(e){}}())return I;throw new Error("Can not determine current script")})),H=S();T((function(){var e;try{e=A()}catch(e){return H}var t=e.getAttribute("data-uid");return t&&"string"==typeof t||(t=e.getAttribute("data-uid-auto"))&&"string"==typeof t||(t=S(),e.setAttribute("data-uid-auto",t)),t}));var U=[];function z(e){var t=e.url,n=e.method,r=void 0===n?"get":n,o=e.headers,i=void 0===o?{}:o,a=e.json,u=e.data,c=e.body,s=e.win,f=void 0===s?window:s,d=e.timeout,h=void 0===d?0:d;return new l((function(e,n){if(a&&u||a&&c||u&&a)throw new Error("Only options.json or options.data or options.body should be passed");for(var o={},s=0,d=Object.keys(i);s<d.length;s++){var l=d[s];o[l.toLowerCase()]=i[l]}a?o["content-type"]=o["content-type"]||"application/json":(u||c)&&(o["content-type"]=o["content-type"]||"application/x-www-form-urlencoded; charset=utf-8"),o.accept=o.accept||"application/json";for(var v=0;v<U.length;v++)for(var w=(0,U[v])(),p=0,y=Object.keys(w);p<y.length;p++){var m=y[p];o[m.toLowerCase()]=w[m]}var g=new f.XMLHttpRequest;for(var j in g.addEventListener("load",(function(){var o=function(e){void 0===e&&(e="");for(var t={},n=0,r=e.trim().split("\n");n<r.length;n++){var o=r[n].split(":"),i=o[0],a=o.slice(1);t[i.toLowerCase()]=a.join(":").trim()}return t}(this.getAllResponseHeaders());if(!this.status)return n(new Error("Request to "+r.toLowerCase()+" "+t+" failed: no response status code."));var i=o["content-type"],a=i&&(0===i.indexOf("application/json")||0===i.indexOf("text/json")),u=this.responseText;try{u=JSON.parse(u)}catch(e){if(a)return n(new Error("Invalid json: "+this.responseText+"."))}return e({status:this.status,headers:o,body:u})}),!1),g.addEventListener("error",(function(e){n(new Error("Request to "+r.toLowerCase()+" "+t+" failed: "+e.toString()+"."))}),!1),g.open(r,t,!0),o)o.hasOwnProperty(j)&&g.setRequestHeader(j,o[j]);a?c=JSON.stringify(a):u&&(c=Object.keys(u).map((function(e){return encodeURIComponent(e)+"="+(u?encodeURIComponent(u[e]):"")})).join("&")),g.timeout=h,g.ontimeout=function(){n(new Error("Request to "+r.toLowerCase()+" "+t+" has timed out"))},g.send(c)}))}var F={DEBUG:"debug",INFO:"info",WARN:"warn",ERROR:"error"},q={FILE:"file:"},G=[F.WARN,F.ERROR],J=[F.ERROR,F.WARN,F.INFO,F.DEBUG],V=F.WARN;function X(e){var t=e.url,n=e.method,r=e.headers,o=e.json,i=e.enableSendBeacon,a=void 0!==i&&i,u=r&&Object.keys(r).length;return window&&window.navigator.sendBeacon&&!u&&a&&window.Blob?new l((function(e){var i=new Blob([JSON.stringify(o)],{type:"application/json"});try{e(window.navigator.sendBeacon(t,i))}catch(e){return z({url:t,method:n,headers:r,json:o}).then(B)}})):z({url:t,method:n,headers:r,json:o}).then(B)}function Z(e,t){for(var n in t)t.hasOwnProperty(n)&&t[n]&&!e[n]&&(e[n]=t[n])}function $(e){var t=e.url,n=e.prefix,o=e.logLevel,i=void 0===o?V:o,a=e.transport,u=void 0===a?X:a,c=e.flushInterval,s=void 0===c?6e4:c,f=e.enableSendBeacon,d=void 0!==f&&f,h=[],v=[],w=[],p=[],y=[],m=[];function g(e,t,n){if(D()&&window.console&&window.console.log&&!(J.indexOf(e)>J.indexOf(i))){var r=[t];r.push(n),(n.error||n.warning)&&r.push("\n\n",n.error||n.warning);try{window.console[e]&&window.console[e].apply?window.console[e].apply(window.console,r):window.console.log&&window.console.log.apply&&window.console.log.apply(window.console,r)}catch(e){}}}function j(){return l.try((function(){if(D()&&window.location.protocol!==q.FILE&&(h.length||v.length)){for(var e={},n=0;n<p.length;n++)Z(e,(0,p[n])(e));for(var r={},o=0;o<m.length;o++)Z(r,(0,m[o])(r));var i=u({method:"POST",url:t,headers:r,json:{events:h,meta:e,tracking:v},enableSendBeacon:d});return h=[],v=[],i.then(B)}}))}var b,O,E,_,S=(void 0===O&&(O=50),x((function(){_&&clearTimeout(_);var e=E=E||new l;return _=setTimeout((function(){E=null,_=null,l.try(b).then((function(t){e.resolve(t)}),(function(t){e.reject(t)}))}),O),e}),k(b=j)+"::promiseDebounced"));function R(e,t,o){if(void 0===o&&(o={}),!D())return P;n&&(t=n+"_"+t);for(var i=r({},L(o),{timestamp:Date.now().toString()}),a=0;a<w.length;a++)Z(i,(0,w[a])(i));return function(e,t,n){h.push({level:e,event:t,payload:n}),-1!==G.indexOf(e)&&S()}(e,t,i),g(e,t,i),P}function W(e,t){return e.push(t),P}D()&&function(e,t){!function n(){setTimeout((function(){e(),n()}),t)}()}(S,s),"object"==typeof window&&(window.addEventListener("beforeunload",(function(){j()})),window.addEventListener("unload",(function(){j()})));var P={debug:function(e,t){return R(F.DEBUG,e,t)},info:function(e,t){return R(F.INFO,e,t)},warn:function(e,t){return R(F.WARN,e,t)},error:function(e,t){return R(F.ERROR,e,t)},track:function(e){if(void 0===e&&(e={}),!D())return P;for(var t=L(e),n=0;n<y.length;n++)Z(t,(0,y[n])(t));return g(F.DEBUG,"track",t),v.push(t),P},flush:S,immediateFlush:j,addPayloadBuilder:function(e){return W(w,e)},addMetaBuilder:function(e){return W(p,e)},addTrackingBuilder:function(e){return W(y,e)},addHeaderBuilder:function(e){return W(m,e)},setTransport:function(e){return u=e,P}};return P}}])})); | ||
//# sourceMappingURL=beaver-logger.min.js.map |
@@ -21,3 +21,13 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
}); | ||
resolve(window.navigator.sendBeacon(url, blob)); | ||
try { | ||
resolve(window.navigator.sendBeacon(url, blob)); | ||
} catch (e) { | ||
return request({ | ||
url: url, | ||
method: method, | ||
headers: headers, | ||
json: json | ||
}).then(noop); | ||
} | ||
}); | ||
@@ -24,0 +34,0 @@ } else { |
{ | ||
"name": "beaver-logger", | ||
"version": "4.0.21", | ||
"version": "4.0.22", | ||
"description": "Client side logger.", | ||
@@ -51,3 +51,3 @@ "main": "dist/beaver-logger.js", | ||
"devDependencies": { | ||
"flow-bin": "^0.135.0", | ||
"flow-bin": "0.135.0", | ||
"grumbler-scripts": "^3", | ||
@@ -54,0 +54,0 @@ "mocha": "^3.5.3", |
@@ -9,3 +9,4 @@ "use strict"; | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _server[key]) return; | ||
exports[key] = _server[key]; | ||
}); |
@@ -60,3 +60,7 @@ /* @flow */ | ||
const blob = new Blob([ JSON.stringify(json) ], { type: 'application/json' }); | ||
resolve(window.navigator.sendBeacon(url, blob)); | ||
try { | ||
resolve(window.navigator.sendBeacon(url, blob)); | ||
} catch (e) { | ||
return request({ url, method, headers, json }).then(noop); | ||
} | ||
}); | ||
@@ -63,0 +67,0 @@ } else { |
Sorry, the diff of this file is not supported yet
976841
28
5893