!function(){"use strict";!function(){const e={VERSION:"1.2.1",SERVICE_URL:"https://www.bloomberg.com/artemis/"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,e)}catch(e){}globalThis.process={env:e}}();const e=/\/+/g,t=/\/$/;const r="::";class s extends Error{}class i{abort(){var e;null==(e=this.abortController)||e.abort()}get signal(){return this.abortController=!this.abortController||this.abortController.signal.aborted?new AbortController:this.abortController,this.abortController.signal}onTokenExpire(){return e=this,t=null,r=function*(){var e,t;try{this.accessToken=yield null==(e=this.tokenExpireHandler)?void 0:e.call(this),this.authDisabled=!0===this.accessToken}catch(e){this.accessToken=void 0,this.authDisabled=!1,null==(t=this.errorHandler)||t.call(this,e)}},new Promise(((s,i)=>{var n=e=>{try{a(r.next(e))}catch(e){i(e)}},o=e=>{try{a(r.throw(e))}catch(e){i(e)}},a=e=>e.done?s(e.value):Promise.resolve(e.value).then(n,o);a((r=r.apply(e,t)).next())}));var e,t,r}get headers(){return!0===this.accessToken?{}:{"x-access-token":this.accessToken||""}}setup(e,t){var r;this.errorHandler=e.onError,this.messageHandler=e.onMessage,this.tokenExpireHandler=e.onTokenExpire,this.retryOnError=null==(r=e.retryOnError)||r,this.options=t}}function n(e){let t,r,s,i=!1;return function(n){void 0===t?(t=n,r=0,s=-1):t=function(e,t){const r=new Uint8Array(e.length+t.length);return r.set(e),r.set(t,e.length),r}(t,n);const o=t.length;let a=0;for(;r{const m=Object.assign({},s);let b;function w(){b.abort(),document.hidden||O()}m.accept||(m.accept=a),p||document.addEventListener("visibilitychange",w);let f=1e3,y=0;function _(){document.removeEventListener("visibilitychange",w),window.clearTimeout(y),b.abort()}null==r||r.addEventListener("abort",(()=>{_(),t()}));const E=null!=v?v:window.fetch,T=null!=i?i:h;async function O(){var r;b=new AbortController;try{const r=await E(e,Object.assign(Object.assign({},g),{headers:m,signal:b.signal}));await T(r),await async function(e,t){const r=e.getReader();let s;for(;!(s=await r.read()).done;)t(s.value)}(r.body,n(function(e,t,r){let s={data:"",event:"",id:"",retry:void 0};const i=new TextDecoder;return function(n,o){if(0===n.length)null==r||r(s),s={data:"",event:"",id:"",retry:void 0};else if(o>0){const r=i.decode(n.subarray(0,o)),a=o+(32===n[o+1]?2:1),l=i.decode(n.subarray(a));switch(r){case"data":s.data=s.data?s.data+"\n"+l:l;break;case"event":s.event=l;break;case"id":e(s.id=l);break;case"retry":const r=parseInt(l,10);isNaN(r)||t(s.retry=r)}}}}((e=>{e?m[l]=e:delete m[l]}),(e=>{f=e}),c))),null==d||d(),_(),t()}catch(e){if(!b.signal.aborted)try{const t=null!==(r=null==u?void 0:u(e))&&void 0!==r?r:f;window.clearTimeout(y),y=window.setTimeout(O,t)}catch(e){_(),o(e)}}}O()}))}function h(e){const t=e.headers.get("content-type");if(!(null==t?void 0:t.startsWith(a)))throw new Error(`Expected content-type to be ${a}, Actual: ${t}`)}const d=class e extends EventTarget{constructor(e){super(),this._shouldAlert=!0,this._duration=e,document.addEventListener("visibilitychange",(()=>{document.hidden?this.stop():this.monitor()}))}monitor(){void 0===this._watchdogTimer&&this._duration&&(this._watchdogTimer=setInterval((()=>{this._shouldAlert&&this.dispatchEvent(new CustomEvent(e.events.ON_WATCHDOG_ALERT)),this._shouldAlert=!0}),this._duration))}stop(){this._watchdogTimer&&(clearInterval(this._watchdogTimer),this._watchdogTimer=void 0)}reset(){this._shouldAlert=!1}};d.events={ON_WATCHDOG_ALERT:"onWatchdogAlert"};let u=d;var p=Object.defineProperty,v=Object.defineProperties,g=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,b=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable,f=(e,t,r)=>t in e?p(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,y=(e,t)=>{for(var r in t||(t={}))b.call(t,r)&&f(e,r,t[r]);if(m)for(var r of m(t))w.call(t,r)&&f(e,r,t[r]);return e},_=(e,t,r)=>new Promise(((s,i)=>{var n=e=>{try{a(r.next(e))}catch(e){i(e)}},o=e=>{try{a(r.throw(e))}catch(e){i(e)}},a=e=>e.done?s(e.value):Promise.resolve(e.value).then(n,o);a((r=r.apply(e,t)).next())}));class E extends Error{}class T extends Error{}class O extends Error{}const P=new class extends i{constructor(){super(),this._shouldRetry=this.retryOnError,this._watchdogTimer=new u(31e3),this._watchdogTimer.addEventListener(u.events.ON_WATCHDOG_ALERT,(()=>{var e;this.stop(),null==(e=this.errorHandler)||e.call(this,new E("SSE connect timed out after 31s"))}))}onOpen(e){return _(this,null,(function*(){if(!e.ok){const t=yield e.text();throw new s(t)}}))}restart(){this._lastUsedFetchOptions&&this._shouldRetry&&(this.abort(),this.start(this._lastUsedFetchOptions.url,this._lastUsedFetchOptions.options))}onClose(){throw new O("Connection to SSE stream was closed")}onMessage({event:e,data:t}){var r,s,i;if(!t)return;this._watchdogTimer.reset();const n="string"==typeof t?function(e,t){if(null==e)return t;try{return JSON.parse(e)}catch(e){return t}}(t):t,o=new CustomEvent("message",{detail:{provider:e,topic:(null==(r=n.data)?void 0:r.topic)||(null==(s=n.data)?void 0:s.name),data:n.data}});null==(i=this.messageHandler)||i.call(this,o)}onError(e){var t,r,s;if(!(e instanceof O)){if("Failed to fetch"===(null==e?void 0:e.message)){const e=new T("Failed to fetch SSE stream");throw null==(t=this.errorHandler)||t.call(this,e),e}if(this._shouldRetry)throw null==(r=this.errorHandler)||r.call(this,e),setTimeout((()=>this.restart()),0),e;throw null==(s=this.errorHandler)||s.call(this,e),e}}start(e,t){return _(this,null,(function*(){var r,s,i,n;if(yield this.onTokenExpire(),this.accessToken||this.authDisabled)return this._lastUsedFetchOptions={url:e,options:t},this._shouldRetry=this.retryOnError,this._watchdogTimer.monitor(),null==(s=c(e,(i=y({onclose:this.onClose.bind(this),onerror:this.onError.bind(this),onmessage:this.onMessage.bind(this),onopen:this.onOpen.bind(this),signal:this.signal},t),n={headers:y(y({},this.headers),null==t?void 0:t.headers)},v(i,g(n)))))?void 0:s.catch(null==(r=this.errorHandler)?void 0:r.bind(this))}))}stop(){this.abort(),this._shouldRetry=!1,this._watchdogTimer.stop()}},A=[s,O,T,E],S=(null==window?void 0:window.newrelic)||(null==window?void 0:window.NREUM),k=Boolean(S);k&&S&&"setErrorHandler"in S&&"function"==typeof S.setErrorHandler&&S.setErrorHandler((e=>{return t=e,A.some((e=>t instanceof e));var t}));const R={isDebug:!1,setDebug(e){this.isDebug=e},debug(e){this.isDebug&&console.info(e)},addPageAction:(e,t)=>{k&&(null==S?void 0:S.addPageAction)&&S.addPageAction(`Artemis.${e}`,t)},noticeError:(e,t)=>{k&&(null==S?void 0:S.noticeError)?S.noticeError(e):console.error(`[Artemis]: ${e.message}`,t)},setCustomAttribute:(e,t,r)=>{k&&(null==S?void 0:S.setCustomAttribute)&&S.setCustomAttribute(e,t,r)},setAnalyticsFlag(){var e;null==(e=null==window?void 0:window.dataLayer)||e.push({realTimeDataAvailable:!0})}};var x,U,C,j=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)},F=(e,t,r)=>(j(e,t,"read from private field"),r?r.call(e):t.get(e)),I=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)};class H{constructor(e){var t,r,s;this.version=process.env.VERSION,I(this,x,new Map),I(this,U,void 0),I(this,C,((e,t)=>{let r;return(...s)=>{clearTimeout(r),r=setTimeout((()=>e(...s)),t)}})((()=>F(this,U).subscribeToTopics(this.topics)),300)),s=e,j(t=this,r=U,"write to private field"),r.set(t,s),R.addPageAction("TopicFacadeInitialized"),e.addEventListener("message",(e=>{const{provider:t,topic:r,data:s}=e.detail;this.broadcast(t,r,s)}))}get topics(){return[...F(this,x).keys()]}get mode(){return F(this,U).mode}usePolling(){F(this,U).usePolling()}useStreaming(){F(this,U).useStreaming()}unsubscribeFromService(e){var t;const[s,i]=e.split(r);0===(null==(t=F(this,x).get(e))?void 0:t.length)&&F(this,U).unsubscribeFromTopic(s,i)}unsubscribeHandler(e,t){var r,s,i;const n=null==(r=F(this,x).get(e))?void 0:r.findIndex((e=>e===t));void 0===n||n<0||(null==(s=F(this,x).get(e))||s.splice(n),0===(null==(i=F(this,x).get(e))?void 0:i.length)&&F(this,x).delete(e))}subscribe(e,t,s){var i;if(!e||!t){const r=new Error("Missing required parameters!");throw R.noticeError(r,{provider:e,topic:t}),r}F(this,C).call(this);const n=`${e}${r}${t}`;return F(this,x).has(n)?(null==(i=F(this,x).get(n))||i.push(s),()=>{this.unsubscribeHandler(n,s),this.unsubscribeFromService(n)}):(F(this,x).set(n,[s]),()=>{this.unsubscribeHandler(n,s),this.unsubscribeFromService(n)})}broadcast(e,t,s){const i=`${e}${r}${t}`,n=F(this,x).get(i)||[];for(const r of n)null==r||r({provider:e,topic:t,data:s})}}x=new WeakMap,U=new WeakMap,C=new WeakMap;var D=(e=>(e[e.Success=200]="Success",e[e.Unauthorized=401]="Unauthorized",e[e.Forbidden=403]="Forbidden",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.InternalError=500]="InternalError",e))(D||{}),M=(e,t,r)=>new Promise(((s,i)=>{var n=e=>{try{a(r.next(e))}catch(e){i(e)}},o=e=>{try{a(r.throw(e))}catch(e){i(e)}},a=e=>e.done?s(e.value):Promise.resolve(e.value).then(n,o);a((r=r.apply(e,t)).next())}));const $=new Error("Not authorized! Stopping sync attempts."),L=new Error("Failed to obtain access token! Stopping sync attempts.");class N{constructor(e,t){this._sentryUrl=e,R.setDebug(Boolean(t))}getAccessToken(e){return M(this,null,(function*(){if(this._getAccessTokenPromise)return this._getAccessTokenPromise;const t=(e?this.assertSecurityResponse:this.negotiateAccessToken).bind(this);try{this._getAccessTokenPromise=t(e);const r=yield this._getAccessTokenPromise;return this._getAccessTokenPromise=void 0,r}catch(e){throw R.noticeError(e,{operation:"getToken"}),e}}))}negotiateAccessToken(){return M(this,null,(function*(){const e=yield this.requestAccessToken();if(e.status===D.PreconditionFailed||e.status>=D.InternalError)throw $;if(e.ok)return e.json().then((({token:e})=>e?(R.debug("Access token granted!"),e):(R.debug("Authentication disabled!"),!0)));const t=yield e.text();throw R.noticeError(L,{reason:t}),L}))}assertSecurityResponse(e){return e===D.Unauthorized?this.negotiateAccessToken():e===D.Forbidden?Promise.reject(new Error("Access is forbidden!")):Promise.reject(new Error("Failed to authorize!"))}requestAccessToken(){return fetch(this._sentryUrl,{mode:"cors",credentials:"include"})}}var W=Object.defineProperty,z=Object.defineProperties,B=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,J=(e,t,r)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,K=(e,t)=>{for(var r in t||(t={}))q.call(t,r)&&J(e,r,t[r]);if(V)for(var r of V(t))G.call(t,r)&&J(e,r,t[r]);return e},Q=(e,t,r)=>new Promise(((s,i)=>{var n=e=>{try{a(r.next(e))}catch(e){i(e)}},o=e=>{try{a(r.throw(e))}catch(e){i(e)}},a=e=>e.done?s(e.value):Promise.resolve(e.value).then(n,o);a((r=r.apply(e,t)).next())}));const X=new class extends i{constructor(){super(),this._started=!1,document.addEventListener("visibilitychange",(()=>{document.hidden?this.stop():this.resume()}))}start(e,t){var r;this.stop();const s=this.fetchData.bind(this,e,t);s(),this._pollTimer=setInterval(s,null==(r=this.options)?void 0:r.interval),this._started=!0}stop(){this._pollTimer&&(clearInterval(this._pollTimer),this._pollTimer=void 0)}resume(){this._lastUsedFetchOptions&&this._started&&this.start(this._lastUsedFetchOptions.url,this._lastUsedFetchOptions.options)}onMessage(e){return Q(this,null,(function*(){if(!e.ok){const t=yield e.text();throw new s(t)}((yield e.json())||[]).forEach((e=>{var t;const{providerName:r,topicsData:s}=e;for(const e of Object.keys(s)){const i=new CustomEvent("message",{detail:{provider:r,topic:e,data:s[e]}});null==(t=this.messageHandler)||t.call(this,i)}}))}))}onError(e){var t;null==(t=this.errorHandler)||t.call(this,e),this.retryOnError||this.stop()}fetchData(e,t){return Q(this,null,(function*(){var r,s;if(this._lastUsedFetchOptions={url:e,options:t},yield this.onTokenExpire(),this.accessToken||this.authDisabled)return fetch(e,(r=K({},t),s={headers:K(K({},this.headers),null==t?void 0:t.headers)},z(r,B(s)))).then(this.onMessage.bind(this)).catch(this.onError.bind(this))}))}};var Y=Object.defineProperty,Z=Object.defineProperties,ee=Object.getOwnPropertyDescriptors,te=Object.getOwnPropertySymbols,re=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable,ie=(e,t,r)=>t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ne=(e,t)=>{for(var r in t||(t={}))re.call(t,r)&&ie(e,r,t[r]);if(te)for(var r of te(t))se.call(t,r)&&ie(e,r,t[r]);return e},oe=(e,t)=>Z(e,ee(t));const ae={credentials:"include",mode:"cors"},{SERVICE_URL:le}=process.env,ce=/network error|Error in input stream|Load failed/;class he extends EventTarget{constructor(e={}){var t,r,s,i;if(super(),this._connectionRetries=0,this._isInitialCall=!0,this._mustReconnect=!0,this._sseRetries=0,this._providerTopics=new Map,R.setDebug(Boolean(e.debug)),this._pollingInterval=null!=(t=e.pollingInterval)?t:5e3,this._serviceUrl=null!=(r=e.serviceUrl)?r:le,this._sseRetryCount=e.sseRetryCount||3,this._usePolling=null!=(s=e.usePolling)&&s,this._topicOptions=null!=(i=e.topicOptions)?i:"",this._accessProvider=new N(this.sentryUrl,Boolean(e.debug)),!this._serviceUrl){const e=new Error("Service url was not provided!");throw R.noticeError(e),e}R.addPageAction("ServiceInterfaceInitialized",ne({},e));const n={onTokenExpire:()=>this._accessProvider.getAccessToken(),onMessage:e=>{this.dispatchEvent(e),this._connectionRetries=0,this._mustReconnect=!1,this._sseRetries=0},retryOnError:e.retryOnError};P.setup(oe(ne({},n),{onError:this.handleSSEErrors.bind(this)})),X.setup(oe(ne({},n),{onError:this.handlePollErrors.bind(this)}),{interval:this._pollingInterval})}get checksum(){return function(e,t=0){let r=3735928559^t,s=1103547991^t;for(let t,i=0;i>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),4294967296*(2097151&s)+(r>>>0)}(JSON.stringify(this.providerTopics))}get providerTopics(){return Array.from(this._providerTopics.keys()).sort().map((e=>{const t=this._providerTopics.get(e)||new Set;return{providerName:e,topics:Array.from(null==t?void 0:t.values()).sort()}}))}getServiceUrl(r,s=!1){return function(r){const{baseUrl:s=location.origin,hash:i,pathname:n="",searchParams:o,trailingSlash:a=!0}=r||{},l=new URL(s);let c="";l.pathname&&(c+=`${l.pathname}/`),c+=n,c=null==c?void 0:c.replace(e,"/");const h=new URL(c,l.origin);o&&new URLSearchParams(o).forEach(((e,t)=>{h.searchParams.append(t,e)}));const d=`${h.toString()}${i?`#${i}`:""}`;return a?d:d.replace(t,"")}({baseUrl:this._serviceUrl,pathname:`${r}${s?`/${this.checksum}`:""}`,trailingSlash:!1})}get pollUrl(){return this.getServiceUrl("/oscillator/poll",!0)}get streamUrl(){return this.getServiceUrl("/oscillator/stream")}get sentryUrl(){return this.getServiceUrl("/sentry")}get headers(){return{"x-artemis-topics":JSON.stringify(this.providerTopics),"x-artemis-options":this._topicOptions}}get mode(){return this._usePolling?"polling":"sse"}usePolling(){this._usePolling||(R.addPageAction("SwitchToPolling"),this._usePolling=!0,this.reconnect())}useStreaming(){this._usePolling&&(R.addPageAction("SwitchToStreaming"),this._usePolling=!1,this.reconnect())}subscribeToTopic(e,t){var r;let s;this._providerTopics.has(e)?(s=this._providerTopics.get(e),(null==s?void 0:s.has(t))||null==(r=this._providerTopics.get(e))||r.add(t),this._mustReconnect=!0):(s=new Set([t]),this._providerTopics.set(e,s),this._mustReconnect=!0)}subscribeToTopics(e){e.forEach((e=>{const[t,s]=e.split(r);this.subscribeToTopic(t,s)})),this._mustReconnect&&this.reconnect()}unsubscribeFromTopic(e,t){var r;const s=this._providerTopics.get(e);t&&(null==s?void 0:s.has(t))&&(null==(r=this._providerTopics.get(e))||r.delete(t),this._mustReconnect=!0)}reconnect(){P.stop(),X.stop(),this._isInitialCall&&(this._isInitialCall=!1,R.setAnalyticsFlag(),this._usePolling||X.fetchData(this.pollUrl,oe(ne({},ae),{headers:this.headers}))),this._usePolling?X.start(this.pollUrl,oe(ne({},ae),{headers:this.headers})):P.start(this.streamUrl,oe(ne({},ae),{headers:this.headers}))}handleSSEErrors(e){return R.debug(`Error occurred: ${e}`),e instanceof s||ce.test(e.message)||this._sseRetries++,this._sseRetries>=this._sseRetryCount||e instanceof E||e instanceof T?(R.addPageAction("SseConnectionError"),R.debug("Switching to polling"),this._usePolling=!0,void this.reconnect()):10==this._connectionRetries++?(P.stop(),R.debug("Connection retries exhausted"),void R.noticeError(e,{attempts:10,connectionMethod:"sse"})):void 0}handlePollErrors(e){if(R.debug(`Error occurred: ${e}`),10==this._connectionRetries++)return X.stop(),R.debug("Connection retries exhausted"),void R.noticeError(e,{attempts:10,connectionMethod:"poll"})}}var de;let ue;if(Object.defineProperty(window,"getArtemisClient",{value:function(e){if(void 0!==ue)return ue;const t=new he(e);return ue=new H(t),ue}}),Array.isArray(null==(de=null==window?void 0:window.artemis)?void 0:de.cmd)){let e=window.artemis.cmd.shift();for(;e;)e(),e=window.artemis.cmd.shift();window.artemis.cmd={push:e=>{e()}}}}();