UNPKG

firstlog

Version:

Modern middleware based logger for Express.js

2 lines (1 loc) 36.8 kB
import e from"path";import n from"fs";import{nanoid as r}from"nanoid";var t,o,i={exports:{}},s={},u={},a={},l={};function c(){if(t)return l;t=1;var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");return l.encode=function(n){if(0<=n&&n<e.length)return e[n];throw new TypeError("Must be between 0 and 63: "+n)},l.decode=function(e){return 65<=e&&e<=90?e-65:97<=e&&e<=122?e-97+26:48<=e&&e<=57?e-48+52:43==e?62:47==e?63:-1},l}function p(){if(o)return a;o=1;var e=c();return a.encode=function(n){var r,t="",o=function(e){return e<0?1+(-e<<1):0+(e<<1)}(n);do{r=31&o,(o>>>=5)>0&&(r|=32),t+=e.encode(r)}while(o>0);return t},a.decode=function(n,r,t){var o,i,s,u,a=n.length,l=0,c=0;do{if(r>=a)throw Error("Expected more digits in base 64 VLQ value.");if(-1===(i=e.decode(n.charCodeAt(r++))))throw Error("Invalid base64 digit: "+n.charAt(r-1));o=!!(32&i),l+=(i&=31)<<c,c+=5}while(o);t.value=(u=(s=l)>>1,1&~s?u:-u),t.rest=r},a}var g,f={};function h(){return g||(g=1,function(e){e.getArg=function(e,n,r){if(n in e)return e[n];if(3===arguments.length)return r;throw Error('"'+n+'" is a required argument.')};var n=/^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/,r=/^data:.+\,.+$/;function t(e){var r=e.match(n);return r?{scheme:r[1],auth:r[2],host:r[3],port:r[4],path:r[5]}:null}function o(e){var n="";return e.scheme&&(n+=e.scheme+":"),n+="//",e.auth&&(n+=e.auth+"@"),e.host&&(n+=e.host),e.port&&(n+=":"+e.port),e.path&&(n+=e.path),n}function i(n){var r=n,i=t(n);if(i){if(!i.path)return n;r=i.path}for(var s,u=e.isAbsolute(r),a=r.split(/\/+/),l=0,c=a.length-1;c>=0;c--)"."===(s=a[c])?a.splice(c,1):".."===s?l++:l>0&&(""===s?(a.splice(c+1,l),l=0):(a.splice(c,2),l--));return""===(r=a.join("/"))&&(r=u?"/":"."),i?(i.path=r,o(i)):r}function s(e,n){""===e&&(e="."),""===n&&(n=".");var s=t(n),u=t(e);if(u&&(e=u.path||"/"),s&&!s.scheme)return u&&(s.scheme=u.scheme),o(s);if(s||n.match(r))return n;if(u&&!u.host&&!u.path)return u.host=n,o(u);var a="/"===n.charAt(0)?n:i(e.replace(/\/+$/,"")+"/"+n);return u?(u.path=a,o(u)):a}e.urlParse=t,e.urlGenerate=o,e.normalize=i,e.join=s,e.isAbsolute=function(e){return"/"===e.charAt(0)||n.test(e)},e.relative=function(e,n){""===e&&(e="."),e=e.replace(/\/$/,"");for(var r=0;0!==n.indexOf(e+"/");){var t=e.lastIndexOf("/");if(t<0)return n;if((e=e.slice(0,t)).match(/^([^\/]+:\/)?\/*$/))return n;++r}return Array(r+1).join("../")+n.substr(e.length+1)};var u=!("__proto__"in Object.create(null));function a(e){return e}function l(e){if(!e)return!1;var n=e.length;if(n<9)return!1;if(95!==e.charCodeAt(n-1)||95!==e.charCodeAt(n-2)||111!==e.charCodeAt(n-3)||116!==e.charCodeAt(n-4)||111!==e.charCodeAt(n-5)||114!==e.charCodeAt(n-6)||112!==e.charCodeAt(n-7)||95!==e.charCodeAt(n-8)||95!==e.charCodeAt(n-9))return!1;for(var r=n-10;r>=0;r--)if(36!==e.charCodeAt(r))return!1;return!0}function c(e,n){return e===n?0:null===e?1:null===n?-1:e>n?1:-1}e.toSetString=u?a:function(e){return l(e)?"$"+e:e},e.fromSetString=u?a:function(e){return l(e)?e.slice(1):e},e.compareByOriginalPositions=function(e,n,r){var t=c(e.source,n.source);return 0!==t||0!==(t=e.originalLine-n.originalLine)||0!==(t=e.originalColumn-n.originalColumn)||r||0!==(t=e.generatedColumn-n.generatedColumn)||0!==(t=e.generatedLine-n.generatedLine)?t:c(e.name,n.name)},e.compareByGeneratedPositionsDeflated=function(e,n,r){var t=e.generatedLine-n.generatedLine;return 0!==t||0!==(t=e.generatedColumn-n.generatedColumn)||r||0!==(t=c(e.source,n.source))||0!==(t=e.originalLine-n.originalLine)||0!==(t=e.originalColumn-n.originalColumn)?t:c(e.name,n.name)},e.compareByGeneratedPositionsInflated=function(e,n){var r=e.generatedLine-n.generatedLine;return 0!==r||0!==(r=e.generatedColumn-n.generatedColumn)||0!==(r=c(e.source,n.source))||0!==(r=e.originalLine-n.originalLine)||0!==(r=e.originalColumn-n.originalColumn)?r:c(e.name,n.name)},e.parseSourceMapInput=function(e){return JSON.parse(e.replace(/^\)]}'[^\n]*\n/,""))},e.computeSourceURL=function(e,n,r){if(n=n||"",e&&("/"!==e[e.length-1]&&"/"!==n[0]&&(e+="/"),n=e+n),r){var u=t(r);if(!u)throw Error("sourceMapURL could not be parsed");if(u.path){var a=u.path.lastIndexOf("/");a>=0&&(u.path=u.path.substring(0,a+1))}n=s(o(u),n)}return i(n)}}(f)),f}var d,m={};function _(){if(d)return m;d=1;var e=h(),n=Object.prototype.hasOwnProperty,r="undefined"!=typeof Map;function t(){this._array=[],this._set=r?new Map:Object.create(null)}return t.fromArray=function(e,n){for(var r=new t,o=0,i=e.length;o<i;o++)r.add(e[o],n);return r},t.prototype.size=function(){return r?this._set.size:Object.getOwnPropertyNames(this._set).length},t.prototype.add=function(t,o){var i=r?t:e.toSetString(t),s=r?this.has(t):n.call(this._set,i),u=this._array.length;s&&!o||this._array.push(t),s||(r?this._set.set(t,u):this._set[i]=u)},t.prototype.has=function(t){if(r)return this._set.has(t);var o=e.toSetString(t);return n.call(this._set,o)},t.prototype.indexOf=function(t){if(r){var o=this._set.get(t);if(o>=0)return o}else{var i=e.toSetString(t);if(n.call(this._set,i))return this._set[i]}throw Error('"'+t+'" is not in the set.')},t.prototype.at=function(e){if(e>=0&&e<this._array.length)return this._array[e];throw Error("No element indexed by "+e)},t.prototype.toArray=function(){return this._array.slice()},m.ArraySet=t,m}var v,y,C={};function S(){if(y)return u;y=1;var e=p(),n=h(),r=_().ArraySet,t=function(){if(v)return C;v=1;var e=h();function n(){this._array=[],this._sorted=!0,this._last={generatedLine:-1,generatedColumn:0}}return n.prototype.unsortedForEach=function(e,n){this._array.forEach(e,n)},n.prototype.add=function(n){var r,t,o,i,s,u;t=n,o=(r=this._last).generatedLine,i=t.generatedLine,s=r.generatedColumn,u=t.generatedColumn,i>o||i==o&&u>=s||e.compareByGeneratedPositionsInflated(r,t)<=0?(this._last=n,this._array.push(n)):(this._sorted=!1,this._array.push(n))},n.prototype.toArray=function(){return this._sorted||(this._array.sort(e.compareByGeneratedPositionsInflated),this._sorted=!0),this._array},C.MappingList=n,C}().MappingList;function o(e){e||(e={}),this._file=n.getArg(e,"file",null),this._sourceRoot=n.getArg(e,"sourceRoot",null),this._skipValidation=n.getArg(e,"skipValidation",!1),this._sources=new r,this._names=new r,this._mappings=new t,this._sourcesContents=null}return o.prototype._version=3,o.fromSourceMap=function(e){var r=e.sourceRoot,t=new o({file:e.file,sourceRoot:r});return e.eachMapping(function(e){var o={generated:{line:e.generatedLine,column:e.generatedColumn}};null!=e.source&&(o.source=e.source,null!=r&&(o.source=n.relative(r,o.source)),o.original={line:e.originalLine,column:e.originalColumn},null!=e.name&&(o.name=e.name)),t.addMapping(o)}),e.sources.forEach(function(o){var i=o;null!==r&&(i=n.relative(r,o)),t._sources.has(i)||t._sources.add(i);var s=e.sourceContentFor(o);null!=s&&t.setSourceContent(o,s)}),t},o.prototype.addMapping=function(e){var r=n.getArg(e,"generated"),t=n.getArg(e,"original",null),o=n.getArg(e,"source",null),i=n.getArg(e,"name",null);this._skipValidation||this._validateMapping(r,t,o,i),null!=o&&(o+="",this._sources.has(o)||this._sources.add(o)),null!=i&&(i+="",this._names.has(i)||this._names.add(i)),this._mappings.add({generatedLine:r.line,generatedColumn:r.column,originalLine:null!=t&&t.line,originalColumn:null!=t&&t.column,source:o,name:i})},o.prototype.setSourceContent=function(e,r){var t=e;null!=this._sourceRoot&&(t=n.relative(this._sourceRoot,t)),null!=r?(this._sourcesContents||(this._sourcesContents=Object.create(null)),this._sourcesContents[n.toSetString(t)]=r):this._sourcesContents&&(delete this._sourcesContents[n.toSetString(t)],0===Object.keys(this._sourcesContents).length&&(this._sourcesContents=null))},o.prototype.applySourceMap=function(e,t,o){var i=t;if(null==t){if(null==e.file)throw Error('SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map\'s "file" property. Both were omitted.');i=e.file}var s=this._sourceRoot;null!=s&&(i=n.relative(s,i));var u=new r,a=new r;this._mappings.unsortedForEach(function(r){if(r.source===i&&null!=r.originalLine){var t=e.originalPositionFor({line:r.originalLine,column:r.originalColumn});null!=t.source&&(r.source=t.source,null!=o&&(r.source=n.join(o,r.source)),null!=s&&(r.source=n.relative(s,r.source)),r.originalLine=t.line,r.originalColumn=t.column,null!=t.name&&(r.name=t.name))}var l=r.source;null==l||u.has(l)||u.add(l);var c=r.name;null==c||a.has(c)||a.add(c)},this),this._sources=u,this._names=a,e.sources.forEach(function(r){var t=e.sourceContentFor(r);null!=t&&(null!=o&&(r=n.join(o,r)),null!=s&&(r=n.relative(s,r)),this.setSourceContent(r,t))},this)},o.prototype._validateMapping=function(e,n,r,t){if(n&&"number"!=typeof n.line&&"number"!=typeof n.column)throw Error("original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.");if((!(e&&"line"in e&&"column"in e&&e.line>0&&e.column>=0)||n||r||t)&&!(e&&"line"in e&&"column"in e&&n&&"line"in n&&"column"in n&&e.line>0&&e.column>=0&&n.line>0&&n.column>=0&&r))throw Error("Invalid mapping: "+JSON.stringify({generated:e,source:r,original:n,name:t}))},o.prototype._serializeMappings=function(){for(var r,t,o,i,s=0,u=1,a=0,l=0,c=0,p=0,g="",f=this._mappings.toArray(),h=0,d=f.length;h<d;h++){if(r="",(t=f[h]).generatedLine!==u)for(s=0;t.generatedLine!==u;)r+=";",u++;else if(h>0){if(!n.compareByGeneratedPositionsInflated(t,f[h-1]))continue;r+=","}r+=e.encode(t.generatedColumn-s),s=t.generatedColumn,null!=t.source&&(i=this._sources.indexOf(t.source),r+=e.encode(i-p),p=i,r+=e.encode(t.originalLine-1-l),l=t.originalLine-1,r+=e.encode(t.originalColumn-a),a=t.originalColumn,null!=t.name&&(o=this._names.indexOf(t.name),r+=e.encode(o-c),c=o)),g+=r}return g},o.prototype._generateSourcesContent=function(e,r){return e.map(function(e){if(!this._sourcesContents)return null;null!=r&&(e=n.relative(r,e));var t=n.toSetString(e);return Object.prototype.hasOwnProperty.call(this._sourcesContents,t)?this._sourcesContents[t]:null},this)},o.prototype.toJSON=function(){var e={version:this._version,sources:this._sources.toArray(),names:this._names.toArray(),mappings:this._serializeMappings()};return null!=this._file&&(e.file=this._file),null!=this._sourceRoot&&(e.sourceRoot=this._sourceRoot),this._sourcesContents&&(e.sourcesContent=this._generateSourcesContent(e.sources,e.sourceRoot)),e},o.prototype.toString=function(){return JSON.stringify(this.toJSON())},u.SourceMapGenerator=o,u}var w,L={},A={};function M(){return w||(w=1,function(e){function n(r,t,o,i,s,u){var a=Math.floor((t-r)/2)+r,l=s(o,i[a],!0);return 0===l?a:l>0?t-a>1?n(a,t,o,i,s,u):u==e.LEAST_UPPER_BOUND?t<i.length?t:-1:a:a-r>1?n(r,a,o,i,s,u):u==e.LEAST_UPPER_BOUND?a:r<0?-1:r}e.GREATEST_LOWER_BOUND=1,e.LEAST_UPPER_BOUND=2,e.search=function(r,t,o,i){if(0===t.length)return-1;var s=n(-1,t.length,r,t,o,i||e.GREATEST_LOWER_BOUND);if(s<0)return-1;for(;s-1>=0&&0===o(t[s],t[s-1],!0);)--s;return s}}(A)),A}var O,b,E={};function R(){if(O)return E;function e(e,n,r){var t=e[n];e[n]=e[r],e[r]=t}function n(r,t,o,i){if(o<i){var s=o-1;e(r,(p=i,Math.round((c=o)+Math.random()*(p-c))),i);for(var u=r[i],a=o;a<i;a++)t(r[a],u)<=0&&e(r,s+=1,a);e(r,s+1,a);var l=s+1;n(r,t,o,l-1),n(r,t,l+1,i)}var c,p}return O=1,E.quickSort=function(e,r){n(e,r,0,e.length-1)},E}var P,x,N,B,U,j,k={};function G(t){const{logFile:o,maskFields:i=["password","token"],captureBody:s=!0,trackQuery:u=!1,onlyLogOnError:a=!1,maxBodySize:l=1024,trackUser:c=()=>"anonymous",trackOrigin:p=!1,onLog:g,enableGeoIP:f=!1,slowThresholdMs:h=1e3,trackSlow:d=!1,requestIdHeader:m="x-request-id",prettyPrint:_=!1,logHeaders:v=!1,logParams:y=!1,logResponseBody:C=!1,excludePaths:S=[]}=t;let w;if(f)try{w=require("geoip-lite")}catch(e){w=null}return(t,L,A)=>{if(S.includes(t.path))return A();const M=process.hrtime.bigint(),O=[],b=L.send,E=Array.isArray(t.headers[m])?t.headers[m][0]:t.headers[m]||r();t.requestId=E,p&&(t._logwiseOrigin=null),L.send=function(n){return p&&!t._logwiseOrigin&&(t._logwiseOrigin=function(){const n=Error().stack?.split("\n");if(!n)return{};for(let r=1;r<n.length;r++){const t=n[r];if(!t||t.includes("node:internal")||t.includes("internal/")||t.includes("node_modules")||t.includes("getOriginInfo")||t.includes("logwise")||t.includes("res.send")||t.includes("ServerResponse.send"))continue;const o=/at (?:(.*)\s+\()?(?:file:\/\/)?(.+?):(\d+):\d+\)?$/.exec(t.trim());if(o){const[n,r,t]=o,i=r?r.trim():"anonymous";return{file:e.basename(t),func:i}}}return{}}()),C&&n&&O.push(Buffer.isBuffer(n)?n:Buffer.from(n)),b.apply(this,arguments)},L.on("finish",()=>{if(a&&L.statusCode<400)return;const r=function(e){const n=process.hrtime.bigint();return Math.round(100*(Number(n-e)/1e6))/100}(M),m=F(t.body,i),S=C?Buffer.concat(O).toString("utf8").substring(0,200):void 0,A=function(e){const n=e.ip||e.socket.remoteAddress||e.headers["x-forwarded-for"]||e.headers["x-real-ip"]||e.headers["cf-connecting-ip"]||e.headers["x-client-ip"]||"unknown";return"::1"===n||"::ffff:127.0.0.1"===n?"127.0.0.1":"string"==typeof n&&n.startsWith("::ffff:")?n.replace("::ffff:",""):"string"==typeof n&&n.includes(",")?n.split(",")[0].trim():n}(t),b={requestId:E,timestamp:(new Date).toISOString(),method:t.method,route:t.originalUrl,status:L.statusCode,ip:A,durationMs:r,user:c(t),body:s?T(m,l):void 0,responseSnippet:S};if(d&&r>h&&(b.slow=!0),u&&(b.query=F(t.query,i)),p&&t._logwiseOrigin&&(b.origin=t._logwiseOrigin),f)if(w)if(A&&"127.0.0.1"!==A&&"unknown"!==A){const e=w.lookup(A);e&&(b.location={country:e.country,region:e.region,city:e.city})}else b.location={country:"Not available for local/unknown IP",region:"",city:""};else b.location={country:"Install `geoip-lite` for location data",region:"",city:""};v&&(b.headers=F(t.headers,i)),y&&t.params&&Object.keys(t.params).length>0&&(b.params=t.params),g&&g(b),function(r,t,o){const i=e.dirname(r);n.existsSync(i)||n.mkdirSync(i,{recursive:!0});const s=JSON.stringify(t,null,o?2:0)+"\n";n.appendFile(r,s,e=>{})}(o,b,_)}),A()}}function F(e,n){if(!e||"object"!=typeof e)return e;const r=JSON.parse(JSON.stringify(e));for(const e of n)e in r&&(r[e]="****");return r}function T(e,n){const r=JSON.stringify(e);return Buffer.byteLength(r,"utf8")>n?{message:"Body too large to log"}:e}j||(j=1,(U||(U=1,function(n,r){var t,o=(x||(x=1,s.SourceMapGenerator=S().SourceMapGenerator,s.SourceMapConsumer=function(){if(b)return L;b=1;var e=h(),n=M(),r=_().ArraySet,t=p(),o=R().quickSort;function i(n,r){var t=n;return"string"==typeof n&&(t=e.parseSourceMapInput(n)),null!=t.sections?new a(t,r):new s(t,r)}function s(n,t){var o=n;"string"==typeof n&&(o=e.parseSourceMapInput(n));var i=e.getArg(o,"version"),s=e.getArg(o,"sources"),u=e.getArg(o,"names",[]),a=e.getArg(o,"sourceRoot",null),l=e.getArg(o,"sourcesContent",null),c=e.getArg(o,"mappings"),p=e.getArg(o,"file",null);if(i!=this._version)throw Error("Unsupported version: "+i);a&&(a=e.normalize(a)),s=s.map(String).map(e.normalize).map(function(n){return a&&e.isAbsolute(a)&&e.isAbsolute(n)?e.relative(a,n):n}),this._names=r.fromArray(u.map(String),!0),this._sources=r.fromArray(s,!0),this._absoluteSources=this._sources.toArray().map(function(n){return e.computeSourceURL(a,n,t)}),this.sourceRoot=a,this.sourcesContent=l,this._mappings=c,this._sourceMapURL=t,this.file=p}function u(){this.generatedLine=0,this.generatedColumn=0,this.source=null,this.originalLine=null,this.originalColumn=null,this.name=null}function a(n,t){var o=n;"string"==typeof n&&(o=e.parseSourceMapInput(n));var s=e.getArg(o,"version"),u=e.getArg(o,"sections");if(s!=this._version)throw Error("Unsupported version: "+s);this._sources=new r,this._names=new r;var a={line:-1,column:0};this._sections=u.map(function(n){if(n.url)throw Error("Support for url field in sections not implemented.");var r=e.getArg(n,"offset"),o=e.getArg(r,"line"),s=e.getArg(r,"column");if(o<a.line||o===a.line&&s<a.column)throw Error("Section offsets must be ordered and non-overlapping.");return a=r,{generatedOffset:{generatedLine:o+1,generatedColumn:s+1},consumer:new i(e.getArg(n,"map"),t)}})}return i.fromSourceMap=function(e,n){return s.fromSourceMap(e,n)},i.prototype._version=3,i.prototype.__generatedMappings=null,Object.defineProperty(i.prototype,"_generatedMappings",{configurable:!0,enumerable:!0,get:function(){return this.__generatedMappings||this._parseMappings(this._mappings,this.sourceRoot),this.__generatedMappings}}),i.prototype.__originalMappings=null,Object.defineProperty(i.prototype,"_originalMappings",{configurable:!0,enumerable:!0,get:function(){return this.__originalMappings||this._parseMappings(this._mappings,this.sourceRoot),this.__originalMappings}}),i.prototype._charIsMappingSeparator=function(e,n){var r=e.charAt(n);return";"===r||","===r},i.prototype._parseMappings=function(e,n){throw Error("Subclasses must implement _parseMappings")},i.GENERATED_ORDER=1,i.ORIGINAL_ORDER=2,i.GREATEST_LOWER_BOUND=1,i.LEAST_UPPER_BOUND=2,i.prototype.eachMapping=function(n,r,t){var o,s=r||null;switch(t||i.GENERATED_ORDER){case i.GENERATED_ORDER:o=this._generatedMappings;break;case i.ORIGINAL_ORDER:o=this._originalMappings;break;default:throw Error("Unknown order of iteration.")}var u=this.sourceRoot;o.map(function(n){var r=null===n.source?null:this._sources.at(n.source);return{source:r=e.computeSourceURL(u,r,this._sourceMapURL),generatedLine:n.generatedLine,generatedColumn:n.generatedColumn,originalLine:n.originalLine,originalColumn:n.originalColumn,name:null===n.name?null:this._names.at(n.name)}},this).forEach(n,s)},i.prototype.allGeneratedPositionsFor=function(r){var t=e.getArg(r,"line"),o={source:e.getArg(r,"source"),originalLine:t,originalColumn:e.getArg(r,"column",0)};if(o.source=this._findSourceIndex(o.source),o.source<0)return[];var i=[],s=this._findMapping(o,this._originalMappings,"originalLine","originalColumn",e.compareByOriginalPositions,n.LEAST_UPPER_BOUND);if(s>=0){var u=this._originalMappings[s];if(void 0===r.column)for(var a=u.originalLine;u&&u.originalLine===a;)i.push({line:e.getArg(u,"generatedLine",null),column:e.getArg(u,"generatedColumn",null),lastColumn:e.getArg(u,"lastGeneratedColumn",null)}),u=this._originalMappings[++s];else for(var l=u.originalColumn;u&&u.originalLine===t&&u.originalColumn==l;)i.push({line:e.getArg(u,"generatedLine",null),column:e.getArg(u,"generatedColumn",null),lastColumn:e.getArg(u,"lastGeneratedColumn",null)}),u=this._originalMappings[++s]}return i},L.SourceMapConsumer=i,s.prototype=Object.create(i.prototype),s.prototype.consumer=i,s.prototype._findSourceIndex=function(n){var r,t=n;if(null!=this.sourceRoot&&(t=e.relative(this.sourceRoot,t)),this._sources.has(t))return this._sources.indexOf(t);for(r=0;r<this._absoluteSources.length;++r)if(this._absoluteSources[r]==n)return r;return-1},s.fromSourceMap=function(n,t){var i=Object.create(s.prototype),a=i._names=r.fromArray(n._names.toArray(),!0),l=i._sources=r.fromArray(n._sources.toArray(),!0);i.sourceRoot=n._sourceRoot,i.sourcesContent=n._generateSourcesContent(i._sources.toArray(),i.sourceRoot),i.file=n._file,i._sourceMapURL=t,i._absoluteSources=i._sources.toArray().map(function(n){return e.computeSourceURL(i.sourceRoot,n,t)});for(var c=n._mappings.toArray().slice(),p=i.__generatedMappings=[],g=i.__originalMappings=[],f=0,h=c.length;f<h;f++){var d=c[f],m=new u;m.generatedLine=d.generatedLine,m.generatedColumn=d.generatedColumn,d.source&&(m.source=l.indexOf(d.source),m.originalLine=d.originalLine,m.originalColumn=d.originalColumn,d.name&&(m.name=a.indexOf(d.name)),g.push(m)),p.push(m)}return o(i.__originalMappings,e.compareByOriginalPositions),i},s.prototype._version=3,Object.defineProperty(s.prototype,"sources",{get:function(){return this._absoluteSources.slice()}}),s.prototype._parseMappings=function(n,r){for(var i,s,a,l,c,p=1,g=0,f=0,h=0,d=0,m=0,_=n.length,v=0,y={},C={},S=[],w=[];v<_;)if(";"===n.charAt(v))p++,v++,g=0;else if(","===n.charAt(v))v++;else{for((i=new u).generatedLine=p,l=v;l<_&&!this._charIsMappingSeparator(n,l);l++);if(a=y[s=n.slice(v,l)])v+=s.length;else{for(a=[];v<l;)t.decode(n,v,C),c=C.value,v=C.rest,a.push(c);if(2===a.length)throw Error("Found a source, but no line and column");if(3===a.length)throw Error("Found a source and line, but no column");y[s]=a}i.generatedColumn=g+a[0],g=i.generatedColumn,a.length>1&&(i.source=d+a[1],d+=a[1],i.originalLine=f+a[2],f=i.originalLine,i.originalLine+=1,i.originalColumn=h+a[3],h=i.originalColumn,a.length>4&&(i.name=m+a[4],m+=a[4])),w.push(i),"number"==typeof i.originalLine&&S.push(i)}o(w,e.compareByGeneratedPositionsDeflated),this.__generatedMappings=w,o(S,e.compareByOriginalPositions),this.__originalMappings=S},s.prototype._findMapping=function(e,r,t,o,i,s){if(e[t]<=0)throw new TypeError("Line must be greater than or equal to 1, got "+e[t]);if(e[o]<0)throw new TypeError("Column must be greater than or equal to 0, got "+e[o]);return n.search(e,r,i,s)},s.prototype.computeColumnSpans=function(){for(var e=0;e<this._generatedMappings.length;++e){var n=this._generatedMappings[e];if(e+1<this._generatedMappings.length){var r=this._generatedMappings[e+1];if(n.generatedLine===r.generatedLine){n.lastGeneratedColumn=r.generatedColumn-1;continue}}n.lastGeneratedColumn=1/0}},s.prototype.originalPositionFor=function(n){var r={generatedLine:e.getArg(n,"line"),generatedColumn:e.getArg(n,"column")},t=this._findMapping(r,this._generatedMappings,"generatedLine","generatedColumn",e.compareByGeneratedPositionsDeflated,e.getArg(n,"bias",i.GREATEST_LOWER_BOUND));if(t>=0){var o=this._generatedMappings[t];if(o.generatedLine===r.generatedLine){var s=e.getArg(o,"source",null);null!==s&&(s=this._sources.at(s),s=e.computeSourceURL(this.sourceRoot,s,this._sourceMapURL));var u=e.getArg(o,"name",null);return null!==u&&(u=this._names.at(u)),{source:s,line:e.getArg(o,"originalLine",null),column:e.getArg(o,"originalColumn",null),name:u}}}return{source:null,line:null,column:null,name:null}},s.prototype.hasContentsOfAllSources=function(){return!!this.sourcesContent&&this.sourcesContent.length>=this._sources.size()&&!this.sourcesContent.some(function(e){return null==e})},s.prototype.sourceContentFor=function(n,r){if(!this.sourcesContent)return null;var t=this._findSourceIndex(n);if(t>=0)return this.sourcesContent[t];var o,i=n;if(null!=this.sourceRoot&&(i=e.relative(this.sourceRoot,i)),null!=this.sourceRoot&&(o=e.urlParse(this.sourceRoot))){var s=i.replace(/^file:\/\//,"");if("file"==o.scheme&&this._sources.has(s))return this.sourcesContent[this._sources.indexOf(s)];if((!o.path||"/"==o.path)&&this._sources.has("/"+i))return this.sourcesContent[this._sources.indexOf("/"+i)]}if(r)return null;throw Error('"'+i+'" is not in the SourceMap.')},s.prototype.generatedPositionFor=function(n){var r=e.getArg(n,"source");if((r=this._findSourceIndex(r))<0)return{line:null,column:null,lastColumn:null};var t={source:r,originalLine:e.getArg(n,"line"),originalColumn:e.getArg(n,"column")},o=this._findMapping(t,this._originalMappings,"originalLine","originalColumn",e.compareByOriginalPositions,e.getArg(n,"bias",i.GREATEST_LOWER_BOUND));if(o>=0){var s=this._originalMappings[o];if(s.source===t.source)return{line:e.getArg(s,"generatedLine",null),column:e.getArg(s,"generatedColumn",null),lastColumn:e.getArg(s,"lastGeneratedColumn",null)}}return{line:null,column:null,lastColumn:null}},L.BasicSourceMapConsumer=s,a.prototype=Object.create(i.prototype),a.prototype.constructor=i,a.prototype._version=3,Object.defineProperty(a.prototype,"sources",{get:function(){for(var e=[],n=0;n<this._sections.length;n++)for(var r=0;r<this._sections[n].consumer.sources.length;r++)e.push(this._sections[n].consumer.sources[r]);return e}}),a.prototype.originalPositionFor=function(r){var t={generatedLine:e.getArg(r,"line"),generatedColumn:e.getArg(r,"column")},o=n.search(t,this._sections,function(e,n){return e.generatedLine-n.generatedOffset.generatedLine||e.generatedColumn-n.generatedOffset.generatedColumn}),i=this._sections[o];return i?i.consumer.originalPositionFor({line:t.generatedLine-(i.generatedOffset.generatedLine-1),column:t.generatedColumn-(i.generatedOffset.generatedLine===t.generatedLine?i.generatedOffset.generatedColumn-1:0),bias:r.bias}):{source:null,line:null,column:null,name:null}},a.prototype.hasContentsOfAllSources=function(){return this._sections.every(function(e){return e.consumer.hasContentsOfAllSources()})},a.prototype.sourceContentFor=function(e,n){for(var r=0;r<this._sections.length;r++){var t=this._sections[r].consumer.sourceContentFor(e,!0);if(t)return t}if(n)return null;throw Error('"'+e+'" is not in the SourceMap.')},a.prototype.generatedPositionFor=function(n){for(var r=0;r<this._sections.length;r++){var t=this._sections[r];if(-1!==t.consumer._findSourceIndex(e.getArg(n,"source"))){var o=t.consumer.generatedPositionFor(n);if(o)return{line:o.line+(t.generatedOffset.generatedLine-1),column:o.column+(t.generatedOffset.generatedLine===o.line?t.generatedOffset.generatedColumn-1:0)}}}return{line:null,column:null}},a.prototype._parseMappings=function(n,r){this.__generatedMappings=[],this.__originalMappings=[];for(var t=0;t<this._sections.length;t++)for(var i=this._sections[t],s=i.consumer._generatedMappings,u=0;u<s.length;u++){var a=s[u],l=i.consumer._sources.at(a.source);l=e.computeSourceURL(i.consumer.sourceRoot,l,this._sourceMapURL),this._sources.add(l),l=this._sources.indexOf(l);var c=null;a.name&&(c=i.consumer._names.at(a.name),this._names.add(c),c=this._names.indexOf(c));var p={source:l,generatedLine:a.generatedLine+(i.generatedOffset.generatedLine-1),generatedColumn:a.generatedColumn+(i.generatedOffset.generatedLine===a.generatedLine?i.generatedOffset.generatedColumn-1:0),originalLine:a.originalLine,originalColumn:a.originalColumn,name:c};this.__generatedMappings.push(p),"number"==typeof p.originalLine&&this.__originalMappings.push(p)}o(this.__generatedMappings,e.compareByGeneratedPositionsDeflated),o(this.__originalMappings,e.compareByOriginalPositions)},L.IndexedSourceMapConsumer=a,L}().SourceMapConsumer,s.SourceNode=function(){if(P)return k;P=1;var e=S().SourceMapGenerator,n=h(),r=/(\r?\n)/,t="$$$isSourceNode$$$";function o(e,n,r,o,i){this.children=[],this.sourceContents={},this.line=null==e?null:e,this.column=null==n?null:n,this.source=null==r?null:r,this.name=null==i?null:i,this[t]=!0,null!=o&&this.add(o)}return o.fromStringWithSourceMap=function(e,t,i){var s=new o,u=e.split(r),a=0,l=function(){return e()+(e()||"");function e(){return a<u.length?u[a++]:void 0}},c=1,p=0,g=null;return t.eachMapping(function(e){if(null!==g){if(!(c<e.generatedLine)){var n=(r=u[a]||"").substr(0,e.generatedColumn-p);return u[a]=r.substr(e.generatedColumn-p),p=e.generatedColumn,f(g,n),void(g=e)}f(g,l()),c++,p=0}for(;c<e.generatedLine;)s.add(l()),c++;if(p<e.generatedColumn){var r=u[a]||"";s.add(r.substr(0,e.generatedColumn)),u[a]=r.substr(e.generatedColumn),p=e.generatedColumn}g=e},this),a<u.length&&(g&&f(g,l()),s.add(u.splice(a).join(""))),t.sources.forEach(function(e){var r=t.sourceContentFor(e);null!=r&&(null!=i&&(e=n.join(i,e)),s.setSourceContent(e,r))}),s;function f(e,r){if(null===e||void 0===e.source)s.add(r);else{var t=i?n.join(i,e.source):e.source;s.add(new o(e.originalLine,e.originalColumn,t,r,e.name))}}},o.prototype.add=function(e){if(Array.isArray(e))e.forEach(function(e){this.add(e)},this);else{if(!e[t]&&"string"!=typeof e)throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+e);e&&this.children.push(e)}return this},o.prototype.prepend=function(e){if(Array.isArray(e))for(var n=e.length-1;n>=0;n--)this.prepend(e[n]);else{if(!e[t]&&"string"!=typeof e)throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+e);this.children.unshift(e)}return this},o.prototype.walk=function(e){for(var n,r=0,o=this.children.length;r<o;r++)(n=this.children[r])[t]?n.walk(e):""!==n&&e(n,{source:this.source,line:this.line,column:this.column,name:this.name})},o.prototype.join=function(e){var n,r,t=this.children.length;if(t>0){for(n=[],r=0;r<t-1;r++)n.push(this.children[r]),n.push(e);n.push(this.children[r]),this.children=n}return this},o.prototype.replaceRight=function(e,n){var r=this.children[this.children.length-1];return r[t]?r.replaceRight(e,n):"string"==typeof r?this.children[this.children.length-1]=r.replace(e,n):this.children.push("".replace(e,n)),this},o.prototype.setSourceContent=function(e,r){this.sourceContents[n.toSetString(e)]=r},o.prototype.walkSourceContents=function(e){for(var r=0,o=this.children.length;r<o;r++)this.children[r][t]&&this.children[r].walkSourceContents(e);var i=Object.keys(this.sourceContents);for(r=0,o=i.length;r<o;r++)e(n.fromSetString(i[r]),this.sourceContents[i[r]])},o.prototype.toString=function(){var e="";return this.walk(function(n){e+=n}),e},o.prototype.toStringWithSourceMap=function(n){var r={code:"",line:1,column:0},t=new e(n),o=!1,i=null,s=null,u=null,a=null;return this.walk(function(e,n){r.code+=e,null!==n.source&&null!==n.line&&null!==n.column?(i===n.source&&s===n.line&&u===n.column&&a===n.name||t.addMapping({source:n.source,original:{line:n.line,column:n.column},generated:{line:r.line,column:r.column},name:n.name}),i=n.source,s=n.line,u=n.column,a=n.name,o=!0):o&&(t.addMapping({generated:{line:r.line,column:r.column}}),i=null,o=!1);for(var l=0,c=e.length;l<c;l++)10===e.charCodeAt(l)?(r.line++,r.column=0,l+1===c?(i=null,o=!1):o&&t.addMapping({source:n.source,original:{line:n.line,column:n.column},generated:{line:r.line,column:r.column},name:n.name})):r.column++}),this.walkSourceContents(function(e,n){t.setSourceContent(e,n)}),{code:r.code,map:t}},k.SourceNode=o,k}().SourceNode),s).SourceMapConsumer,i=e;try{(t=require("fs")).existsSync&&t.readFileSync||(t=null)}catch(e){}var u=function(){if(B)return N;B=1;var e=Object.prototype.toString,n="undefined"!=typeof Buffer&&"function"==typeof Buffer.alloc&&"function"==typeof Buffer.allocUnsafe&&"function"==typeof Buffer.from;return N=function(r,t,o){if("number"==typeof r)throw new TypeError('"value" argument must not be a number');return i=r,"ArrayBuffer"===e.call(i).slice(8,-1)?function(e,r,t){r>>>=0;var o=e.byteLength-r;if(o<0)throw new RangeError("'offset' is out of bounds");if(void 0===t)t=o;else if((t>>>=0)>o)throw new RangeError("'length' is out of bounds");return n?Buffer.from(e.slice(r,r+t)):new Buffer(new Uint8Array(e.slice(r,r+t)))}(r,t,o):"string"==typeof r?function(e,r){if("string"==typeof r&&""!==r||(r="utf8"),!Buffer.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');return n?Buffer.from(e,r):new Buffer(e,r)}(r,t):n?Buffer.from(r):new Buffer(r);var i}}();function a(e,n){return e.require(n)}var l=!1,c=!1,g=!1,f="auto",d={},m={},v=/^data:application\/json[^,]+base64,/,y=[],C=[];function w(){return"browser"===f||"node"!==f&&"undefined"!=typeof window&&"function"==typeof XMLHttpRequest&&!(window.require&&window.module&&window.process&&"renderer"===window.process.type)}function A(e){return function(n){for(var r=0;r<e.length;r++){var t=e[r](n);if(t)return t}return null}}var O=A(y);function E(e,n){if(!e)return n;var r=i.dirname(e),t=/^\w+:\/\/[^\/]*/.exec(r),o=t?t[0]:"",s=r.slice(o.length);return o&&/^\/\w\:/.test(s)?(o+="/")+i.resolve(r.slice(o.length),n).replace(/\\/g,"/"):o+i.resolve(r.slice(o.length),n)}y.push(function(e){if(e=e.trim(),/^file:/.test(e)&&(e=e.replace(/file:\/\/\/(\w:)?/,function(e,n){return n?"":"/"})),e in d)return d[e];var n="";try{if(t)t.existsSync(e)&&(n=t.readFileSync(e,"utf8"));else{var r=new XMLHttpRequest;r.open("GET",e,!1),r.send(null),4===r.readyState&&200===r.status&&(n=r.responseText)}}catch(e){}return d[e]=n});var U=A(C);function j(e){var n=m[e.source];if(!n){var r=U(e.source);r?(n=m[e.source]={url:r.url,map:new o(r.map)}).map.sourcesContent&&n.map.sources.forEach(function(e,r){var t=n.map.sourcesContent[r];if(t){var o=E(n.url,e);d[o]=t}}):n=m[e.source]={url:null,map:null}}if(n&&n.map&&"function"==typeof n.map.originalPositionFor){var t=n.map.originalPositionFor(e);if(null!==t.source)return t.source=E(n.url,t.source),t}return e}function G(e){var n=/^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(e);if(n){var r=j({source:n[2],line:+n[3],column:n[4]-1});return"eval at "+n[1]+" ("+r.source+":"+r.line+":"+(r.column+1)+")"}return(n=/^eval at ([^(]+) \((.+)\)$/.exec(e))?"eval at "+n[1]+" ("+G(n[2])+")":e}function F(){var e,n="";if(this.isNative())n="native";else{!(e=this.getScriptNameOrSourceURL())&&this.isEval()&&(n=this.getEvalOrigin(),n+=", "),n+=e||"<anonymous>";var r=this.getLineNumber();if(null!=r){n+=":"+r;var t=this.getColumnNumber();t&&(n+=":"+t)}}var o="",i=this.getFunctionName(),s=!0,u=this.isConstructor();if(this.isToplevel()||u)u?o+="new "+(i||"<anonymous>"):i?o+=i:(o+=n,s=!1);else{var a=this.getTypeName();"[object Object]"===a&&(a="null");var l=this.getMethodName();i?(a&&0!=i.indexOf(a)&&(o+=a+"."),o+=i,l&&i.indexOf("."+l)!=i.length-l.length-1&&(o+=" [as "+l+"]")):o+=a+"."+(l||"<anonymous>")}return s&&(o+=" ("+n+")"),o}function T(e){var n={};return Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach(function(r){n[r]=/^(?:is|get)/.test(r)?function(){return e[r].call(e)}:e[r]}),n.toString=F,n}function I(e,n){if(void 0===n&&(n={nextPosition:null,curPosition:null}),e.isNative())return n.curPosition=null,e;var r=e.getFileName()||e.getScriptNameOrSourceURL();if(r){var t=e.getLineNumber(),o=e.getColumnNumber()-1,i=/^v(10\.1[6-9]|10\.[2-9][0-9]|10\.[0-9]{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/.test("object"==typeof process&&null!==process?process.version:"")?0:62;1===t&&o>i&&!w()&&!e.isEval()&&(o-=i);var s=j({source:r,line:t,column:o});n.curPosition=s;var u=(e=T(e)).getFunctionName;return e.getFunctionName=function(){return null==n.nextPosition?u():n.nextPosition.name||u()},e.getFileName=function(){return s.source},e.getLineNumber=function(){return s.line},e.getColumnNumber=function(){return s.column+1},e.getScriptNameOrSourceURL=function(){return s.source},e}var a=e.isEval()&&e.getEvalOrigin();return a?(a=G(a),(e=T(e)).getEvalOrigin=function(){return a},e):e}function D(e,n){g&&(d={},m={});for(var r=(e.name||"Error")+": "+(e.message||""),t={nextPosition:null,curPosition:null},o=[],i=n.length-1;i>=0;i--)o.push("\n at "+I(n[i],t)),t.nextPosition=t.curPosition;return t.curPosition=t.nextPosition=null,r+o.reverse().join("")}function q(e){var n=/\n at [^(]+ \((.*):(\d+):(\d+)\)/.exec(e.stack);if(n){var r=n[1],o=+n[2],i=+n[3],s=d[r];if(!s&&t&&t.existsSync(r))try{s=t.readFileSync(r,"utf8")}catch(e){s=""}if(s){var u=s.split(/(?:\r\n|\r|\n)/)[o-1];if(u)return r+":"+o+"\n"+u+"\n"+Array(i).join(" ")+"^"}}return null}C.push(function(e){var n,r=function(e){var n;if(w())try{var r=new XMLHttpRequest;r.open("GET",e,!1),r.send(null),n=4===r.readyState?r.responseText:null;var t=r.getResponseHeader("SourceMap")||r.getResponseHeader("X-SourceMap");if(t)return t}catch(e){}n=O(e);for(var o,i,s=/(?:\/\/[@#][\s]*sourceMappingURL=([^\s'"]+)[\s]*$)|(?:\/\*[@#][\s]*sourceMappingURL=([^\s*'"]+)[\s]*(?:\*\/)[\s]*$)/gm;i=s.exec(n);)o=i;return o?o[1]:null}(e);if(!r)return null;if(v.test(r)){var t=r.slice(r.indexOf(",")+1);n=u(t,"base64").toString(),r=e}else r=E(e,r),n=O(r);return n?{url:r,map:n}:null});var $=y.slice(0),z=C.slice(0);r.wrapCallSite=I,r.getErrorSource=q,r.mapSourcePosition=j,r.retrieveSourceMap=U,r.install=function(e){if((e=e||{}).environment&&(f=e.environment,-1===["node","browser","auto"].indexOf(f)))throw Error("environment "+f+" was unknown. Available options are {auto, browser, node}");if(e.retrieveFile&&(e.overrideRetrieveFile&&(y.length=0),y.unshift(e.retrieveFile)),e.retrieveSourceMap&&(e.overrideRetrieveSourceMap&&(C.length=0),C.unshift(e.retrieveSourceMap)),e.hookRequire&&!w()){var r=a(n,"module"),t=r.prototype._compile;t.__sourceMapSupport||(r.prototype._compile=function(e,n){return d[n]=e,m[n]=void 0,t.call(this,e,n)},r.prototype._compile.__sourceMapSupport=!0)}if(g||(g="emptyCacheBetweenOperations"in e&&e.emptyCacheBetweenOperations),l||(l=!0,Error.prepareStackTrace=D),!c){var o=!("handleUncaughtExceptions"in e)||e.handleUncaughtExceptions;try{!1===a(n,"worker_threads").isMainThread&&(o=!1)}catch(e){}o&&"object"==typeof process&&null!==process&&"function"==typeof process.on&&(c=!0,i=process.emit,process.emit=function(e){if("uncaughtException"===e){var n=arguments[1]&&arguments[1].stack,r=this.listeners(e).length>0;if(n&&!r)return function(e){q(e);var n=function(){if("object"==typeof process&&null!==process)return process.stderr}();n&&n._handle&&n._handle.setBlocking&&n._handle.setBlocking(!0),"object"==typeof process&&null!==process&&"function"==typeof process.exit&&process.exit(1)}(arguments[1])}return i.apply(this,arguments)})}var i},r.resetRetrieveHandlers=function(){y.length=0,C.length=0,y=$.slice(0),C=z.slice(0),U=A(C),O=A(y)}}(i,i.exports)),i.exports).install());export{G as logger};