!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Cabin=e()}}((function(){!function(e){"use strict";e.console||(e.console={});for(var t,r,n=e.console,o=function(){},i=["memory"],s="assert,clear,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn".split(",");t=i.pop();)n[t]||(n[t]={});for(;r=s.pop();)n[r]||(n[r]=o)}("undefined"==typeof window?this:window);var e={hostname:function(){return"undefined"!=typeof location?location.hostname:""}},t=function(e){var t=Array.prototype.slice.call(arguments,1);return t.length&&(e=e.toString().replace(/(%?)(%([jds]))/g,(function(e,r,n,o){var i=t.shift();switch(o){case"s":i=""+i;break;case"d":i=Number(i);break;case"j":i=JSON.stringify(i)}return r?(t.unshift(i),e):i}))),t.length&&(e=e.toString()+" "+t.join(" ")),""+e.toString().replace(/%{2,2}/g,"%")},r=["%s","%d","%i","%f","%j","%o","%O","%%"],n=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:".";if(n=e,"[object Object]"!==Object.prototype.toString.call(n)||!t)return e;var n;const o=Array.isArray(t)?t:String(t).split(r),{length:i}=o;return i<2?e[o[0]]:((e,t,r)=>{for(let n=0;n{if("[object Object]"!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype};const{hasOwnProperty:u}=Object.prototype,{propertyIsEnumerable:g}=Object,p=(e,t,r)=>Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0}),y=this,h={concatArrays:!1,ignoreUndefined:!1},d=e=>{const t=[];for(const r in e)u.call(e,r)&&t.push(r);if(Object.getOwnPropertySymbols){const r=Object.getOwnPropertySymbols(e);for(const n of r)g.call(e,n)&&t.push(n)}return t};function b(e){return Array.isArray(e)?function(e){const t=e.slice(0,0);return d(e).forEach(r=>{p(t,r,b(e[r]))}),t}(e):l(e)?function(e){const t=null===Object.getPrototypeOf(e)?Object.create(null):{};return d(e).forEach(r=>{p(t,r,b(e[r]))}),t}(e):e}const m=(e,t,r,n)=>(r.forEach(r=>{void 0===t[r]&&n.ignoreUndefined||(r in e&&e[r]!==Object.getPrototypeOf(e)?p(e,r,v(e[r],t[r],n)):p(e,r,b(t[r])))}),e);function v(e,t,r){return r.concatArrays&&Array.isArray(e)&&Array.isArray(t)?((e,t,r)=>{let n=e.slice(0,0),o=0;return[e,t].forEach(t=>{const i=[];for(let r=0;r!i.includes(e)),r)}),n})(e,t,r):l(t)&&l(e)?m(e,t,d(t),r):b(t)}var A=function(){const e=v(b(h),this!==y&&this||{},h);let t={_:{}};for(var r=arguments.length,n=new Array(r),o=0;o{const r=[];let n=0;for(const o of e)r.push(await t(await o,n++));return r};(O=w).default=w;var j={};function S(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return E(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?E(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){c=!0,i=e},f:function(){try{s||null==r.return||r.return()}finally{if(c)throw i}}}}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r1&&void 0!==arguments[1]?arguments[1]:[];if(!o(t))throw new Error("`err` must be an Error");if(!Array.isArray(r))throw new TypeError("`fields` must be an Array");const n={};var i,s=S(new Set([...Object.getOwnPropertyNames(Object.getPrototypeOf(t)),...Object.getOwnPropertyNames(t)]));try{for(s.s();!(i=s.n()).done;){const e=i.value;"function"!=typeof t[e]&&(n[e]=t[e])}}catch(t){s.e(t)}finally{s.f()}return!n.name&&t.constructor.name&&(n.name=t.constructor.name),Array.isArray(t.errors)&&(n.errors=t.errors.map(t=>o(t)?e(t,r):t)),Array.isArray(r)&&r.length>0?n.filter(e=>r.includes(e)):n};const T=e=>"object"==typeof e||"function"==typeof e,P=(e,t)=>"__proto__"==e||"constructor"==e&&"function"==typeof t.constructor;var k=function(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:".";if(!T(e)||!t||!t.length)return e;const o=Array.isArray(t)?t:String(t).split(n);if(P(o[0],e))return e;const{length:i}=o;return 1===i?(e[o[0]]=r,e):((e,t,r,n)=>{let o=e,i=0;for(;i{if((e=>"__proto__"===e||"constructor"===e||"prototype"===e)(e))throw new Error(`Cannot set unsafe key: "${e}"`)};var B=function(e,t){if(null==(r=e)||"object"!=typeof r||!1!==Array.isArray(r))throw new TypeError("expected an object.");var r,n=Array.isArray(t);if(!n&&e.hasOwnProperty(t))return delete e[t],!0;if(D(e,t)){for(var o=n?t.slice():t.split("."),i=o.pop();o.length&&"\\"===o[o.length-1].slice(-1);)i=o.pop().slice(0,-1)+"."+i;for(;o.length;)t=o.shift(),U(t),e=e[t];return delete e[i]}return!0},X={};Object.defineProperty(X,"__esModule",{value:!0}),X.boolean=void 0,X.boolean=function(e){switch(Object.prototype.toString.call(e)){case"[object String]":return["true","t","yes","y","on","1"].includes(e.trim().toLowerCase());case"[object Number]":return 1===e.valueOf();case"[object Boolean]":return e.valueOf();default:return!1}};var R={};Object.defineProperty(R,"__esModule",{value:!0}),R.isBooleanable=void 0,R.isBooleanable=function(e){switch(Object.prototype.toString.call(e)){case"[object String]":return["true","t","yes","y","on","1","false","f","no","n","off","0"].includes(e.trim().toLowerCase());case"[object Number]":return[0,1].includes(e.valueOf());case"[object Boolean]":return!0;default:return!1}};var H={};Object.defineProperty(H,"__esModule",{value:!0}),H.boolean=void 0,Object.defineProperty(H,"boolean",{enumerable:!0,get:function(){return X.boolean}}),Object.defineProperty(H,"isBooleanable",{enumerable:!0,get:function(){return R.isBooleanable}});var K,W,z,$="13.0.0",V=K={};function q(){throw new Error("setTimeout has not been defined")}function G(){throw new Error("clearTimeout has not been defined")}function J(e){if(W===setTimeout)return setTimeout(e,0);if((W===q||!W)&&setTimeout)return W=setTimeout,setTimeout(e,0);try{return W(e,0)}catch(t){try{return W.call(null,e,0)}catch(t){return W.call(this,e,0)}}}!function(){try{W="function"==typeof setTimeout?setTimeout:q}catch(e){W=q}try{z="function"==typeof clearTimeout?clearTimeout:G}catch(e){z=G}}();var Q,Y=[],Z=!1,ee=-1;function te(){Z&&Q&&(Z=!1,Q.length?Y=Q.concat(Y):ee=-1,Y.length&&re())}function re(){if(!Z){var e=J(te);Z=!0;for(var t=Y.length;t;){for(Q=Y,Y=[];++ee1)for(var r=1;r0&&void 0!==arguments[0]?arguments[0]:{};const r={};if(i.env.AXE_REMAPPED_META_FIELDS){const e=i.env.AXE_REMAPPED_META_FIELDS.split(",").map(e=>e.split(":"));for(const[t,n]of e)r[t]=n}let n=i.env.AXE_OMIT_META_FIELDS;"string"==typeof n&&(n=n.split(",").map(e=>e.trim())),Array.isArray(n)||(n=[]);let o=i.env.AXE_PICK_META_FIELDS;"string"==typeof o&&(o=o.split(",").map(e=>e.trim())),Array.isArray(o)||(o=[]),this.config=A({showStack:!i.env.AXE_SHOW_STACK||c(i.env.AXE_SHOW_STACK),meta:Object.assign({show:!i.env.AXE_SHOW_META||c(i.env.AXE_SHOW_META),remappedFields:r,omittedFields:n,pickedFields:o,cleanupRemapping:!0,hideHTTP:"is_http",hideMeta:"hide_meta"},"object"==typeof t.meta?t.meta:{}),version:$,silent:!1,logger:console,name:p,level:"info",levels:["info","warn","error","fatal"],appInfo:!i.env.AXE_APP_INFO||c(i.env.AXE_APP_INFO),hooks:Object.assign({pre:[],post:[]},"object"==typeof t.hooks?t.hooks:{})},t),this.appInfo=!!this.config.appInfo&&!!v(j)&&j(),this.log=this.log.bind(this);const s=Object.keys(this.config.logger).filter(e=>!a.has(e));for(const i of s)this[i]=this.config.logger[i];for(const i of l){if("fatal"===i?this.config.logger.fatal=w(this.config.logger[i])||w(this.config.logger.error)||w(this.config.logger.info)||w(this.config.logger.log):this.config.logger[i]=w(this.config.logger[i])||w(this.config.logger.info)||w(this.config.logger.log),!v(this.config.logger[i]))throw new Error(`\`${i}\` must be a function on the logger.`);this[i]=function(){for(var t=arguments.length,r=new Array(t),n=0;n1?n-1:0),i=1;i1?n-1:0),i=1;i3?w-3:0),S=3;S=3+E?t(...g.slice(2+E)):e}if(d(i)&&(i=e),1!==g.slice(1+E).length||m(i)||o(i))if(!P&&g.length>=4+E){i=void 0,a={};const r=[];for(const e of g.slice(A&&0===E?1:0))o(e)?p.push(e):r.push(e);r.length>0&&(i=t(...r),v=!0),p.length>0&&"log"===e&&(e="error")}else if(!P&&g.length===3+E&&m(i)&&r.some(e=>-1!==i.indexOf(e)))i=t(i,a),a={};else if(o(i)){if(o(a)){p.push(a);const r=[];o(i)&&(p.unshift(i),i=void 0);for(const e of g.slice(2+E))a!==e&&(o(e)?p.push(e):r.push(e),r.length>0&&(i=t(...r),v=!0));"log"===e&&(e="error"),a={}}}else o(a)?(p.push(a),a={}):b(a)||d(a)||null===a?m(i)||(i=t(i)):(i=t(i,a),a={});else a={message:i},i=e;d(a)||b(a)?b(a)||(a={}):a={original_meta:a},o(i)&&(p.unshift(i),i=void 0),b(a.err)&&(o(a.err)&&p.push(a.err),a.original_err=o(a.err)?_(a.err):a.err),p.length>0&&(1===p.length?T=p[0]:((T=new Error([...new Set(p.map(e=>e.message).filter(Boolean))].join("; "))).stack=[...new Set(p.map(e=>e.stack).filter(Boolean))].join("\n\n"),T.errors=p),a.err=_(T),m(i)||(i=T.message)),a.level=e,this.appInfo&&(a.app=this.appInfo);const x=-1===E?"log":e;for(const t of this.config.hooks.pre)[T,i,a]=t(x,T,i,a);const I=c(a[f]);if(!h(this.config.meta.remappedFields))for(const t of Reflect.ownKeys(this.config.meta.remappedFields))if(k(a,this.config.meta.remappedFields[t],n(a,t)),B(a,t),this.config.meta.cleanupRemapping){const e=t.lastIndexOf(".");if(-1===e)continue;const r=t.slice(0,e);h(n(a,r))&&B(a,r)}if(!h(this.config.meta.omittedFields)||!h(this.config.meta.pickedFields)){const e=function(e){const t=[];return function e(r,n){if(!(function(e){return null!=e&&null!=e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}(r)||r.constructor&&"Uint8Array"===r.constructor.name||Array.isArray(r)))for(const o of Reflect.ownKeys(r)){const i=r[o],c=s(o)?Symbol.keyFor(o)||o.description:o,f=n?n+"."+c:c;y(i)&&-1===t.indexOf(c)?(t.push(c),e(i,f)):-1===t.indexOf(f)&&t.push(f)}}(e),t}(a);if(!h(this.config.meta.omittedFields))for(const r of this.config.meta.omittedFields){let t=e.length;for(;t--;)(e[t]===r||!s(e[t])&&0===e[t].indexOf(r+"."))&&e.splice(t,1)}const t=[];if(!h(this.config.meta.pickedFields))for(const r of this.config.meta.pickedFields){if(s(r))a[r]&&t.push([r,a[r]]);else{const t=r.indexOf("."),n=r.slice(0,t+1);if(-1!==t){let t=e.length;for(;t--;)(e[t]===n.slice(0,-1)||0===e[t].indexOf(n))&&e.splice(t,1)}}-1===e.indexOf(r)&&e.push(r)}for(const r of e)s(r)?void 0!==a[r]&&t.push([r,a[r]]):void 0!==a[Symbol.for(r)]&&t.push([Symbol.for(r),a[Symbol.for(r)]]);try{a=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:".";if(o=e,"[object Object]"!==Object.prototype.toString.call(o)||!t||!Array.isArray(t)&&"string"!=typeof t)return{};var o;const{length:i}=t;if("string"==typeof t||i<2){const o="string"==typeof t?t:t[0],i=n(e,o,r);return void 0!==i?k({},o,i,r):{}}return((e,t,r,o)=>{const i={};for(let s=0;s0)for(const[r,n]of t)a[r]=n}return this.config.silent||I||(o(T)&&this.config.showStack?!this.config.meta.show||h(a)||this.config.meta.hideMeta&&a[this.config.meta.hideMeta]?this.config.logger[x](...v?[i,T]:[T]):this.config.logger[x](...v?[i,T,a]:[T,a]):!this.config.meta.show||h(a)||this.config.meta.hideMeta&&a[this.config.meta.hideMeta]||this.config.meta.hideHTTP&&a[this.config.meta.hideHTTP]?this.config.logger[x](i):this.config.logger[x](i,a)),0===this.config.hooks.post.length?{method:x,err:T,message:i,meta:a}:O(this.config.hooks.post,e=>e(x,T,i,a)).then().catch(e=>{this.config.logger.error(e)})}}}).call(this)}).call(this,K);var se="14.0.0",ce={isNull:function(e){return null===e},isUndefined:function(e){return void 0===e},isObject:function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)},isString:function(e){return"string"==typeof e},isFunction:function(e){return"function"==typeof e}};const{isNull:fe,isUndefined:ae,isObject:le,isString:ue,isFunction:ge}=ce;return class{constructor(e){var n=this;if(this.config=A({logger:console,meta:{},parseRequest:{},errorProps:[],message:j,version:se},e),!le(this.config.logger))throw new Error("Logger option must be a logger object such as `console` or an instance of Axe");this.config.logger instanceof ie||(this.config.logger=new ie({logger:this.config.logger})),this.parseArg=this.parseArg.bind(this);for(const o of Object.keys(this.config.logger).filter(e=>ge(this.config.logger[e])))this[o]=function(){for(var e=arguments.length,i=new Array(e),s=0;si[0].includes(e))&&i[1]?(i[0]=t(i[0],i[1]),delete i[1]):i[1]&&(i[1]=n.parseArg(i[1])),n.config.logger[o](...Array.prototype.slice.call(i))};this.err=this.error,this.warning=this.warn,this.setMeta=this.setMeta.bind(this),this.setUser=this.setUser.bind(this),ge(j)&&(this.middleware=j.bind(this))}parseArg(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return le(e)?(Object.assign(e,this.config.meta),e):(e=ae(e)||fe(e)?{}:o(e)?{err:_(e,this.config.errorProps)}:Array.isArray(e)||ue(e)||"number"==typeof e?{value:e}:ge(e)?{value:e.toString()}:{},Object.assign(e,this.config.meta),e)}setMeta(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.config.meta=e}setUser(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.config.meta.user=e}}}));