1
Fork 0
blog/bundle.js

9 lines
57 KiB
JavaScript
Raw Normal View History

2022-01-22 16:30:49 +00:00
"use strict";(()=>{var u;(function(e){e.Debug="debug",e.Info="info",e.Warn="warn",e.Error="error",e.Trace="trace"})(u||(u={}));function l(e,t,r=u.Debug){let n=`(Glean.${e})`;Array.isArray(t)?console[r](n,...t):console[r](n,t)}var Ze=1e4,Ye;(function(e){e[e.RecoverableFailure=0]="RecoverableFailure",e[e.UnrecoverableFailure=1]="UnrecoverableFailure",e[e.Success=2]="Success"})(Ye||(Ye={}));var ot=class{constructor(t,r){this.result=t,this.status=r}},Qe=class{},qt=Qe;var me="platform.browser.Uploader",tr=class extends qt{async post(t,r,n={}){let i=new AbortController,s=setTimeout(()=>i.abort(),Ze),c;try{c=await fetch(t.toString(),{headers:n,method:"POST",body:r,keepalive:!0,credentials:"omit",signal:i.signal,redirect:"error"})}catch(o){return o instanceof DOMException?l(me,[`Timeout while attempting to upload ping.
`,o],u.Error):o instanceof TypeError?l(me,[`Network error while attempting to upload ping.
`,o],u.Error):l(me,[`Unknown error while attempting to upload ping.
`,o],u.Error),clearTimeout(s),new ot(0)}return clearTimeout(s),new ot(2,c.status)}},er=new tr;var Tn={os(){let e=navigator.userAgent;return e.includes("Windows")?Promise.resolve("Windows"):/tvOS/i.test(e)?Promise.resolve("TvOS"):/Watch( OS)?/i.test(e)?Promise.resolve("WatchOS"):/iPhone|iPad|iOS/i.test(e)?Promise.resolve("iOS"):/Mac OS X|macOS/i.test(e)?Promise.resolve("Darwin"):/Android/i.test(e)?Promise.resolve("Android"):/CrOS/i.test(e)?Promise.resolve("ChromeOS"):/WebOS/i.test(e)?Promise.resolve("WebOS"):/Linux/i.test(e)?Promise.resolve("Linux"):/OpenBSD/i.test(e)?Promise.resolve("OpenBSD"):/FreeBSD/i.test(e)?Promise.resolve("FreeBSD"):/NetBSD/i.test(e)?Promise.resolve("NetBSD"):/SunOS/i.test(e)?Promise.resolve("SunOS"):/AIX/i.test(e)?Promise.resolve("IBM_AIX"):Promise.resolve("Unknown")},async osVersion(){return Promise.resolve("Unknown")},async arch(){return Promise.resolve("Unknown")},async locale(){return Promise.resolve(navigator.language||"und")}},rr=Tn;var Wt,En=new Uint8Array(16);function ge(){if(!Wt&&(Wt=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!="undefined"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!Wt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Wt(En)}var nr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function In(e){return typeof e=="string"&&nr.test(e)}var ir=In;var U=[];for(Xt=0;Xt<256;++Xt)U.push((Xt+256).toString(16).substr(1));var Xt;function Sn(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,r=(U[e[t+0]]+U[e[t+1]]+U[e[t+2]]+U[e[t+3]]+"-"+U[e[t+4]]+U[e[t+5]]+"-"+U[e[t+6]]+U[e[t+7]]+"-"+U[e[t+8]]+U[e[t+9]]+"-"+U[e[t+10]]+U[e[t+11]]+U[e[t+12]]+U[e[t+13]]+U[e[t+14]]+U[e[t+15]]).toLowerCase();if(!ir(r))throw TypeError("Stringified UUID is invalid");return r}var ar=Sn;function _n(e,t,r){e=e||{};var n=e.random||(e.rng||ge)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(var i=0;i<16;++i)t[r+i]=n[i];return t}return ar(n)}var ve=_n;var Mn="core.Dispatcher",sr;(function(e){e.Uninitialized="Uninitialized",e.Idle="Idle",e.Processing="Processing",e.Stopped="Stopped",e.Shutdown="Shutdown"})(sr||(sr={}));var or;(function(e){e.Task="Task",e.PersistentTask="PersistentTask",e.InitTask="InitTask",e.Stop="Stop",e.Clear="Clear",e.Shutdown="Shutdown",e.TestTask="TestTask"})(or||(or={}));var cr=class{constructor(t=100,r=Mn){this.maxPreInitQueueSize=t,this.logTag=r,this.shuttingDown=!1,this.currentJob=Promise.resolve(),this.queue=[],this.state="Uninitialized"}getNextCommand(){return this.queue.shift()}async executeTask(t){try{return await t(),!0}catch(r){return l(this.logTag,`Error executing Glean task${r?`: ${r}`:". There might be more error logs above."}`,u.Error),!1}}unblockTestResolvers(){this.queue.forEach(t=>{t.command==="TestTask"&&t.resolver()})}async execute(){let t=this.getNextCommand();for(;t;){switch(t.command){case"Stop":this.state="Stopped";return;case"Shutdown":this.unblockTestResolvers(),this.queue=[],this.state="Shutdown",this.shuttingDown=!1;return;case"Clear":this.unblockTestResolvers(),this.queue=this.queue.filter(n=>["PersistentTask","Shutdown"].includes(n.command));break;case"TestTask":await this.executeTask(t.task),t.resolver();break;case"InitTask":await this.executeTask(t.task)||(l(this.logTag,["Error initializing dispatcher, won't execute anything further.","There might be more error logs above."],u.Error),this.clear(),this.shutdown());break;case"PersistentTask":case"Task":await this.executeTask(t.task);break}t=this.getNextCommand()}}triggerExecution(){this.state==="Idle"&&this.queue.length>0&&(this.state="Processing",this.currentJob=this.execute(),this.currentJob.then(()=>{let t=this;this.state==="Processing"&&(t.state="Idle")}).catch(t=>{l(this.logTag,["IMPOSSIBLE: Something went wrong while the dispatcher was executing the tasks queue.",t],u.Error)}))}launchInternal(t,r=!1){return this.state==="Shutdown"?(l(thi
`,o],u.Error);return}a.config.logPings&&l(Mt,JSON.stringify(n,null,2),u.Info);let s=i||n,c=Ei();return a.pingsDatabase.recordPing(Si(e,t),e,s,c)}var an=_i;var Dt="core.Pings.PingType",gt=class{constructor(t){var r;this.name=t.name,this.includeClientId=t.includeClientId,this.sendIfEmpty=t.sendIfEmpty,this.reasonCodes=(r=t.reasonCodes)!==null&&r!==void 0?r:[]}isDeletionRequest(){return this.name===Tt}submit(t){this.testCallback?this.testCallback(t).then(()=>{gt._private_internalSubmit(this,t,this.resolveTestPromiseFunction)}).catch(r=>{l(Dt,[`There was an error validating "${this.name}" (${t??"no reason"}):`,r],u.Error),gt._private_internalSubmit(this,t,this.rejectTestPromiseFunction)}):gt._private_internalSubmit(this,t)}static async _private_submitUndispatched(t,r,n){if(!a.initialized){l(Dt,"Glean must be initialized before submitting pings.",u.Info);return}if(!a.uploadEnabled&&!t.isDeletionRequest()){l(Dt,"Glean disabled: not submitting pings. Glean may still submit the deletion-request ping.",u.Info);return}let i=r;r&&!t.reasonCodes.includes(r)&&(l(Dt,`Invalid reason code ${r} from ${this.name}. Ignoring.`,u.Warn),i=void 0);let s=ht();await an(s,t,i),n&&(n(),t.resolveTestPromiseFunction=void 0,t.rejectTestPromiseFunction=void 0,t.testCallback=void 0)}static _private_internalSubmit(t,r,n){a.dispatcher.launch(async()=>{await gt._private_submitUndispatched(t,r,n)})}async testBeforeNextSubmit(t){if(_("testBeforeNextSubmit",Dt)){if(this.testCallback){l(Dt,`There is an existing test call for ping "${this.name}". Ignoring.`,u.Error);return}return new Promise((r,n)=>{this.resolveTestPromiseFunction=r,this.rejectTestPromiseFunction=n,this.testCallback=t})}}},Pt=gt;var sn=class{constructor(){this.deletionRequest=new Pt({name:Tt,includeClientId:!0,sendIfEmpty:!0})}},on=sn;var Mi="core.Events.Utils";function cn(e){let t=e.event;if(t in ut){ut[t].registerPlugin(e);return}l(Mi,[`Attempted to register plugin '${e.name}', which listens to the event '${e.event}'.`,"That is not a valid Glean event. Ignoring"],u.Error)}function ln(){for(let e in ut)ut[e].deregisterPlugin()}function Di(e){return`core.Metrics.${e.type.charAt(0).toUpperCase()+e.type.slice(1)}`}function un(e,t){let r=e.baseIdentifier(),n=yr(r);return new Z({name:Yt(t,n),category:"glean.error",lifetime:"ping",sendInPings:e.sendInPings,disabled:!1})}var fe=class{async record(t,r,n,i=1){let s=un(t,r);l(Di(t),[`${t.baseIdentifier()}:`,n]),i>0&&await Z._private_addUndispatched(s,i)}async testGetNumRecordedErrors(t,r,n){return await un(t,r).testGetValue(n)||0}};var Pi="plaftom.test.Storage",Bt={},fn=class{constructor(t){this.rootKey=t}get(t=[]){try{let r=Kt(Bt,[this.rootKey,...t]);return Promise.resolve(r)}catch(r){return Promise.reject(r)}}update(t,r){try{return Bt=Ht(Bt,[this.rootKey,...t],r),Promise.resolve()}catch(n){return Promise.reject(n)}}delete(t){try{Bt=Zt(Bt,[this.rootKey,...t])}catch(r){l(Pi,[`Error attempting to delete key ${t.toString()} from storage. Ignoring.`,r],u.Warn)}return Promise.resolve()}},hn=fn;var pn=class extends qt{post(t,r,n){let i=new ot(2,200);return Promise.resolve(i)}},Ai={os(){return Promise.resolve("Unknown")},osVersion(){return Promise.resolve("Unknown")},arch(){return Promise.resolve("Unknown")},locale(){return Promise.resolve("Unknown")}},Ui=typeof setTimeout!="undefined"?setTimeout:()=>{throw new Error},Oi=typeof clearTimeout!="undefined"?clearTimeout:()=>{},Li={Storage:hn,uploader:new pn,info:Ai,timer:{setTimeout:Ui,clearTimeout:Oi},name:"test"},dn=Li;var nt="core.Glean",We;(function(e){e.coreMetrics=new je,e.corePings=new on;async function t(){a.uploadEnabled=!0,await e.coreMetrics.initialize()}async function r(){a.uploadEnabled=!1,await Pt._private_submitUndispatched(e.corePings.deletionRequest),await n()}async function n(){await e.pingUploader.clearPendingPingsQueue();let d;try{d=new $(await a.metricsDatabase.getMetric(lt,e.coreMetrics.firstRunDate)).date}catch{d=new Date}await a.eventsDatabase.clearAll(),await a.metricsDatabase.clearAll(),await a.pingsDatabase.clearAll(),a.uploadEnabled=!0,await zt._private_setUndispatched(e.coreMetrics.
`,"Pass the correct state into `initialize`.\n","See documentation at https://mozilla.github.io/glean/book/user/general-api.html#initializing-the-glean-sdk`"],u.Error);return}if(!bt(d)){l(nt,"Unable to change upload state, new value must be a boolean. Ignoring.",u.Error);return}a.dispatcher.launch(async()=>{a.uploadEnabled!==d&&(d?await t():await r())})}e.setUploadEnabled=s;function c(d){a.dispatcher.launch(()=>(a.config.logPings=d,Promise.resolve()))}e.setLogPings=c;function o(d){a.dispatcher.launch(()=>(a.config.debugViewTag=d,Promise.resolve()))}e.setDebugViewTag=o;function p(d){a.dispatcher.launch(()=>(a.config.sourceTags=d,Promise.resolve()))}e.setSourceTags=p;async function h(){if(!a.initialized){l(nt,"Attempted to shutdown Glean, but Glean is not initialized. Ignoring.");return}await a.dispatcher.shutdown(),await e.pingUploader.blockOnOngoingUploads()}e.shutdown=h;function f(d){a.initialized||(a.isPlatformSet()&&a.platform.name!==d.name&&!a.testing&&l(nt,[`IMPOSSIBLE: Attempted to change Glean's targeted platform",
"from "${a.platform.name}" to "${d.name}". Ignoring.`],u.Error),a.platform=d)}e.setPlatform=f;async function g(d,y=!0,I){a.testing=!0,f(dn),i(d,y,I),await a.dispatcher.testBlockOnQueue()}e.testInitialize=g;async function m(d=!0){a.initialized&&(await h(),d&&(await a.eventsDatabase.clearAll(),await a.metricsDatabase.clearAll(),await a.pingsDatabase.clearAll()),a.testUninitialize(),ln())}e.testUninitialize=m;async function b(d,y=!0,I,L=!0){await m(L),await g(d,y,I)}e.testResetGlean=b})(We||(We={}));var it=We;var mn=e=>({initialize(t,r,n){it.setPlatform(e),it.initialize(t,r,n)},setUploadEnabled(t){it.setUploadEnabled(t)},setLogPings(t){it.setLogPings(t)},setDebugViewTag(t){it.setDebugViewTag(t)},shutdown(){return it.shutdown()},setSourceTags(t){it.setSourceTags(t)},async testResetGlean(t,r=!0,n){return it.testResetGlean(t,r,n)}});var gn=mn(dr);var vn=new Pt({includeClientId:!0,sendIfEmpty:!1,name:"visit",reasonCodes:[]});var wn=new Y({category:"page",name:"loaded",sendInPings:["visit"],lifetime:"ping",disabled:!1},"millisecond"),yn=new O({category:"page",name:"path",sendInPings:["visit"],lifetime:"ping",disabled:!1});function Gi(e){document.readyState!="loading"?e():document.addEventListener("DOMContentLoaded",e)}Gi(()=>{let e={serverEndpoint:"https://telemetry-ingestion.fly.dev/"};gn.initialize("net-rediger-jer",!0,e),wn.set(),yn.set(location.pathname),vn.submit()});})();