@harnessio/ff-javascript-client-sdk
Advanced tools
Comparing version 1.4.3 to 1.4.4
@@ -1,7 +0,7 @@ | ||
var Ze=Object.create,Re=Object.defineProperty,et=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty,rt=Object.getOwnPropertyNames,nt=Object.getOwnPropertyDescriptor;var ie=Object.assign,ke=a=>Re(a,"__esModule",{value:!0});var at=(a,c)=>()=>(c||(c={exports:{}},a(c.exports,c)),c.exports),it=(a,c)=>{for(var w in c)Re(a,w,{get:c[w],enumerable:!0})},ot=(a,c,w)=>{if(c&&typeof c=="object"||typeof c=="function")for(let g of rt(c))!tt.call(a,g)&&g!=="default"&&Re(a,g,{get:()=>c[g],enumerable:!(w=nt(c,g))||w.enumerable});return a},He=a=>ot(ke(Re(a!=null?Ze(et(a)):{},"default",a&&a.__esModule&&"default"in a?{get:()=>a.default,enumerable:!0}:{value:a,enumerable:!0})),a);var Ie=(a,c,w)=>new Promise((g,W)=>{var q=A=>{try{O(w.next(A))}catch(G){W(G)}},B=A=>{try{O(w.throw(A))}catch(G){W(G)}},O=A=>A.done?g(A.value):Promise.resolve(A.value).then(q,B);O((w=w.apply(a,c)).next())});var Ue=at((Le,Ae)=>{(function(a){"use strict";var c=a.setTimeout,w=a.clearTimeout,g=a.XMLHttpRequest,W=a.XDomainRequest,q=a.ActiveXObject,B=a.EventSource,O=a.document,A=a.Promise,G=a.fetch,ue=a.Response,R=a.TextDecoder,N=a.TextEncoder,K=a.AbortController;if(typeof window!="undefined"&&typeof O!="undefined"&&!("readyState"in O)&&O.body==null&&(O.readyState="loading",window.addEventListener("load",function(e){O.readyState="complete"},!1)),g==null&&q!=null&&(g=function(){return new q("Microsoft.XMLHTTP")}),Object.create==null&&(Object.create=function(e){function r(){}return r.prototype=e,new r}),Date.now||(Date.now=function(){return new Date().getTime()}),K==null){var F=G;G=function(e,r){var n=r.signal;return F(e,{headers:r.headers,credentials:r.credentials,cache:r.cache}).then(function(t){var f=t.body.getReader();return n._reader=f,n._aborted&&n._reader.cancel(),{status:t.status,statusText:t.statusText,headers:t.headers,body:{getReader:function(){return f}}}})},K=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){this.signal._reader!=null&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function re(){this.bitsNeeded=0,this.codePoint=0}re.prototype.decode=function(e){function r(p,y,d){if(d===1)return p>=128>>y&&p<<y<=2047;if(d===2)return p>=2048>>y&&p<<y<=55295||p>=57344>>y&&p<<y<=65535;if(d===3)return p>=65536>>y&&p<<y<=1114111;throw new Error}function n(p,y){if(p===6*1)return y>>6>15?3:y>31?2:1;if(p===6*2)return y>15?3:2;if(p===6*3)return 3;throw new Error}for(var t=65533,f="",i=this.bitsNeeded,u=this.codePoint,E=0;E<e.length;E+=1){var v=e[E];i!==0&&(v<128||v>191||!r(u<<6|v&63,i-6,n(i,u)))&&(i=0,u=t,f+=String.fromCharCode(u)),i===0?(v>=0&&v<=127?(i=0,u=v):v>=192&&v<=223?(i=6*1,u=v&31):v>=224&&v<=239?(i=6*2,u=v&15):v>=240&&v<=247?(i=6*3,u=v&7):(i=0,u=t),i!==0&&!r(u,i,n(i,u))&&(i=0,u=t)):(i-=6,u=u<<6|v&63),i===0&&(u<=65535?f+=String.fromCharCode(u):(f+=String.fromCharCode(55296+(u-65535-1>>10)),f+=String.fromCharCode(56320+(u-65535-1&1023))))}return this.bitsNeeded=i,this.codePoint=u,f};var _e=function(){try{return new R().decode(new N().encode("test"),{stream:!0})==="test"}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1};(R==null||N==null||!_e())&&(R=re);var x=function(){};function b(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=x,this.onload=x,this.onerror=x,this.onreadystatechange=x,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=x}b.prototype.open=function(e,r){this._abort(!0);var n=this,t=this._xhr,f=1,i=0;this._abort=function(d){n._sendTimeout!==0&&(w(n._sendTimeout),n._sendTimeout=0),(f===1||f===2||f===3)&&(f=4,t.onload=x,t.onerror=x,t.onabort=x,t.onprogress=x,t.onreadystatechange=x,t.abort(),i!==0&&(w(i),i=0),d||(n.readyState=4,n.onabort(null),n.onreadystatechange())),f=0};var u=function(){if(f===1){var d=0,m="",Y=void 0;if("contentType"in t)d=200,m="OK",Y=t.contentType;else try{d=t.status,m=t.statusText,Y=t.getResponseHeader("Content-Type")}catch(ge){d=0,m="",Y=void 0}d!==0&&(f=2,n.readyState=2,n.status=d,n.statusText=m,n._contentType=Y,n.onreadystatechange())}},E=function(){if(u(),f===2||f===3){f=3;var d="";try{d=t.responseText}catch(m){}n.readyState=3,n.responseText=d,n.onprogress()}},v=function(d,m){if((m==null||m.preventDefault==null)&&(m={preventDefault:x}),E(),f===1||f===2||f===3){if(f=4,i!==0&&(w(i),i=0),n.readyState=4,d==="load")n.onload(m);else if(d==="error")n.onerror(m);else if(d==="abort")n.onabort(m);else throw new TypeError;n.onreadystatechange()}},p=function(d){t!=null&&(t.readyState===4?(!("onload"in t)||!("onerror"in t)||!("onabort"in t))&&v(t.responseText===""?"error":"load",d):t.readyState===3?"onprogress"in t||E():t.readyState===2&&u())},y=function(){i=c(function(){y()},500),t.readyState===3&&E()};"onload"in t&&(t.onload=function(d){v("load",d)}),"onerror"in t&&(t.onerror=function(d){v("error",d)}),"onabort"in t&&(t.onabort=function(d){v("abort",d)}),"onprogress"in t&&(t.onprogress=E),"onreadystatechange"in t&&(t.onreadystatechange=function(d){p(d)}),("contentType"in t||!("ontimeout"in g.prototype))&&(r+=(r.indexOf("?")===-1?"?":"&")+"padding=true"),t.open(e,r,!0),"readyState"in t&&(i=c(function(){y()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(e){return this._contentType},b.prototype.setRequestHeader=function(e,r){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,r)},b.prototype.getAllResponseHeaders=function(){return this._xhr.getAllResponseHeaders!=null&&this._xhr.getAllResponseHeaders()||""},b.prototype.send=function(){if((!("ontimeout"in g.prototype)||!("sendAsBinary"in g.prototype)&&!("mozAnon"in g.prototype))&&O!=null&&O.readyState!=null&&O.readyState!=="complete"){var e=this;e._sendTimeout=c(function(){e._sendTimeout=0,e.send()},4);return}var r=this._xhr;"withCredentials"in r&&(r.withCredentials=this.withCredentials);try{r.send(void 0)}catch(n){throw n}};function le(e){return e.replace(/[A-Z]/g,function(r){return String.fromCharCode(r.charCodeAt(0)+32)})}function P(e){for(var r=Object.create(null),n=e.split(`\r | ||
`),t=0;t<n.length;t+=1){var f=n[t],i=f.split(": "),u=i.shift(),E=i.join(": ");r[le(u)]=E}this._map=r}P.prototype.get=function(e){return this._map[le(e)]},g!=null&&g.HEADERS_RECEIVED==null&&(g.HEADERS_RECEIVED=2);function me(){}me.prototype.open=function(e,r,n,t,f,i,u){e.open("GET",f);var E=0;e.onprogress=function(){var p=e.responseText,y=p.slice(E);E+=y.length,n(y)},e.onerror=function(p){p.preventDefault(),t(new Error("NetworkError"))},e.onload=function(){t(null)},e.onabort=function(){t(null)},e.onreadystatechange=function(){if(e.readyState===g.HEADERS_RECEIVED){var p=e.status,y=e.statusText,d=e.getResponseHeader("Content-Type"),m=e.getAllResponseHeaders();r(p,y,d,new P(m))}},e.withCredentials=i;for(var v in u)Object.prototype.hasOwnProperty.call(u,v)&&e.setRequestHeader(v,u[v]);return e.send(),e};function ve(e){this._headers=e}ve.prototype.get=function(e){return this._headers.get(e)};function be(){}be.prototype.open=function(e,r,n,t,f,i,u){var E=null,v=new K,p=v.signal,y=new R;return G(f,{headers:u,credentials:i?"include":"same-origin",signal:p,cache:"no-store"}).then(function(d){return E=d.body.getReader(),r(d.status,d.statusText,d.headers.get("Content-Type"),new ve(d.headers)),new A(function(m,Y){var ge=function(){E.read().then(function(k){if(k.done)m(void 0);else{var M=y.decode(k.value,{stream:!0});n(M),ge()}}).catch(function(k){Y(k)})};ge()})}).catch(function(d){if(d.name!=="AbortError")return d}).then(function(d){t(d)}),{abort:function(){E!=null&&E.cancel(),v.abort()}}};function ne(){this._listeners=Object.create(null)}function Se(e){c(function(){throw e},0)}ne.prototype.dispatchEvent=function(e){e.target=this;var r=this._listeners[e.type];if(r!=null)for(var n=r.length,t=0;t<n;t+=1){var f=r[t];try{typeof f.handleEvent=="function"?f.handleEvent(e):f.call(this,e)}catch(i){Se(i)}}},ne.prototype.addEventListener=function(e,r){e=String(e);var n=this._listeners,t=n[e];t==null&&(t=[],n[e]=t);for(var f=!1,i=0;i<t.length;i+=1)t[i]===r&&(f=!0);f||t.push(r)},ne.prototype.removeEventListener=function(e,r){e=String(e);var n=this._listeners,t=n[e];if(t!=null){for(var f=[],i=0;i<t.length;i+=1)t[i]!==r&&f.push(t[i]);f.length===0?delete n[e]:n[e]=f}};function te(e){this.type=e,this.target=void 0}function he(e,r){te.call(this,e),this.data=r.data,this.lastEventId=r.lastEventId}he.prototype=Object.create(te.prototype);function o(e,r){te.call(this,e),this.status=r.status,this.statusText=r.statusText,this.headers=r.headers}o.prototype=Object.create(te.prototype);function s(e,r){te.call(this,e),this.error=r.error}s.prototype=Object.create(te.prototype);var h=-1,l=0,V=1,S=2,T=-1,C=0,z=1,oe=2,pe=3,we=/^text\/event\-stream(;.*)?$/i,Ge=1e3,Ke=18e6,Fe=function(e,r){var n=e==null?r:parseInt(e,10);return n!==n&&(n=r),xe(n)},xe=function(e){return Math.min(Math.max(e,Ge),Ke)},se=function(e,r,n){try{typeof r=="function"&&r.call(e,n)}catch(t){Se(t)}};function J(e,r){ne.call(this),r=r||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,We(this,e,r)}function ze(){return g!=null&&"withCredentials"in g.prototype||W==null?new g:new W}var Je=G!=null&&ue!=null&&"body"in ue.prototype;function We(e,r,n){r=String(r);var t=Boolean(n.withCredentials),f=n.lastEventIdQueryParameterName||"lastEventId",i=xe(1e3),u=Fe(n.heartbeatTimeout,45e3),E="",v=i,p=!1,y=0,d=n.headers||{},m=n.Transport,Y=Je&&m==null?void 0:new b(m!=null?new m:ze()),ge=m!=null&&typeof m!="string"?new m:Y==null?new be:new me,k=void 0,M=0,X=h,fe="",Te="",Q="",Ce="",H=C,Ve=0,ae=0,Ye=function(D,I,U,$){if(X===l)if(D===200&&U!=null&&we.test(U)){X=V,p=Date.now(),v=i,e.readyState=V;var L=new o("open",{status:D,statusText:I,headers:$});e.dispatchEvent(L),se(e,e.onopen,L)}else{var _="";D!==200?(I&&(I=I.replace(/\s+/g," ")),_="EventSource's response has a status "+D+" "+I+" that is not 200. Aborting the connection."):_="EventSource's response has a Content-Type specifying an unsupported type: "+(U==null?"-":U.replace(/\s+/g," "))+". Aborting the connection.",Me();var L=new o("error",{status:D,statusText:I,headers:$});e.dispatchEvent(L),se(e,e.onerror,L),console.error(_)}},Qe=function(D){if(X===V){for(var I=-1,U=0;U<D.length;U+=1){var $=D.charCodeAt(U);($===` | ||
`.charCodeAt(0)||$==="\r".charCodeAt(0))&&(I=U)}var L=(I!==-1?Ce:"")+D.slice(0,I+1);Ce=(I===-1?Ce:"")+D.slice(I+1),D!==""&&(p=Date.now(),y+=D.length);for(var _=0;_<L.length;_+=1){var $=L.charCodeAt(_);if(H===T&&$===` | ||
`.charCodeAt(0))H=C;else if(H===T&&(H=C),$==="\r".charCodeAt(0)||$===` | ||
`.charCodeAt(0)){if(H!==C){H===z&&(ae=_+1);var Z=L.slice(Ve,ae-1),ee=L.slice(ae+(ae<_&&L.charCodeAt(ae)===" ".charCodeAt(0)?1:0),_);Z==="data"?(fe+=` | ||
`,fe+=ee):Z==="id"?Te=ee:Z==="event"?Q=ee:Z==="retry"?(i=Fe(ee,i),v=i):Z==="heartbeatTimeout"&&(u=Fe(ee,u),M!==0&&(w(M),M=c(function(){ye()},u)))}if(H===C){if(fe!==""){E=Te,Q===""&&(Q="message");var de=new he(Q,{data:fe.slice(1),lastEventId:Te});if(e.dispatchEvent(de),Q==="open"?se(e,e.onopen,de):Q==="message"?se(e,e.onmessage,de):Q==="error"&&se(e,e.onerror,de),X===S)return}fe="",Q=""}H=$==="\r".charCodeAt(0)?T:C}else H===C&&(Ve=_,H=z),H===z?$===":".charCodeAt(0)&&(ae=_+1,H=oe):H===oe&&(H=pe)}}},je=function(D){if(X===V||X===l)X=h,M!==0&&(w(M),M=0),M=c(function(){ye()},v),v=xe(Math.min(i*16,v*2)),e.readyState=l;else if(X===S&&D!=null){console.error(D);var I=new s("error",{error:D});e.dispatchEvent(I),se(e,e.onerror,I)}},Me=function(){X=S,k!=null&&(k.abort(),k=void 0),M!==0&&(w(M),M=0),e.readyState=S},ye=function(){if(M=0,X!==h){if(!p&&k!=null)je(new Error("No activity within "+u+" milliseconds. "+(X===l?"No response received.":y+" chars received.")+" Reconnecting.")),k!=null&&(k.abort(),k=void 0);else{var D=Math.max((p||Date.now())+u-Date.now(),1);p=!1,M=c(function(){ye()},D)}return}p=!1,y=0,M=c(function(){ye()},u),X=l,fe="",Q="",Te=E,Ce="",Ve=0,ae=0,H=C;var I=r;if(r.slice(0,5)!=="data:"&&r.slice(0,5)!=="blob:"&&E!==""){var U=r.indexOf("?");I=U===-1?r:r.slice(0,U+1)+r.slice(U+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(ee,de){return de===f?"":ee}),I+=(r.indexOf("?")===-1?"?":"&")+f+"="+encodeURIComponent(E)}var $=e.withCredentials,L={};L.Accept="text/event-stream";var _=e.headers;if(_!=null)for(var Z in _)Object.prototype.hasOwnProperty.call(_,Z)&&(L[Z]=_[Z]);try{k=ge.open(Y,Ye,Qe,je,I,$,L)}catch(ee){throw Me(),ee}};e.url=r,e.readyState=l,e.withCredentials=t,e.headers=d,e._close=Me,ye()}J.prototype=Object.create(ne.prototype),J.prototype.CONNECTING=l,J.prototype.OPEN=V,J.prototype.CLOSED=S,J.prototype.close=function(){this._close()},J.CONNECTING=l,J.OPEN=V,J.CLOSED=S,J.prototype.withCredentials=void 0;var Pe=B;g!=null&&(B==null||!("withCredentials"in B.prototype))&&(Pe=J),function(e){if(typeof Ae=="object"&&typeof Ae.exports=="object"){var r=e(Le);r!==void 0&&(Ae.exports=r)}else typeof define=="function"&&define.amd?define(["exports"],e):e(a)}(function(e){e.EventSourcePolyfill=J,e.NativeEventSource=B,e.EventSource=Pe})})(typeof globalThis=="undefined"?typeof window!="undefined"?window:typeof self!="undefined"?self:Le:globalThis)});ke(exports);it(exports,{Event:()=>j,initialize:()=>ct});var Be=He(require("jwt-decode")),Xe=He(require("mitt")),qe=He(Ue());var j;(function(a){a.READY="ready",a.CONNECTED="connected",a.DISCONNECTED="disconnected",a.RECONNECTED="reconnected",a.CHANGED="changed",a.ERROR="error"})(j||(j={}));var $e={debug:!1,baseUrl:"https://config.ff.harness.io/api/1.0",eventUrl:"https://events.ff.harness.io/api/1.0",streamEnabled:!0,allAttributesPrivate:!1,privateAttributeNames:[]},ce=(a,...c)=>console.error(`[FF-SDK] ${a}`,...c),De=30*1e3;var st="1.4.3",ft=500,Oe=globalThis.fetch,dt=qe.EventSourcePolyfill,Ee=!!globalThis.Proxy,Ne=a=>{let{value:c}=a;try{switch(a.kind.toLowerCase()){case"int":case"number":c=Number(c);break;case"boolean":c=c.toString().toLowerCase()==="true";break;case"json":c=JSON.parse(c);break}}catch(w){ce(w)}return c},ct=(a,c,w)=>{let g,W,q,B,O,A=!0,G=()=>{A=!1},ue=()=>{A=!0},R=[],N=(0,Xe.default)(),K=ie(ie({},$e),w),F=(o,...s)=>{K.debug&&console.debug(`[FF-SDK] ${o}`,...s)},re=o=>{if(A){let s=Date.now();s-o.lastAccessed>ft&&(o.count++,o.lastAccessed=s)}};globalThis.onbeforeunload=()=>{R.length&&globalThis.localStorage&&(G(),globalThis.localStorage.HARNESS_FF_METRICS=JSON.stringify(R),ue())};let _e=(o,s)=>Ie(void 0,null,function*(){return(yield(yield Oe(`${s.baseUrl}/client/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:o,target:c})})).json()).authToken}),x=()=>{if(R.length){F("Sending metrics...",{metrics:R,evaluations:b});let o={metricsData:R.map(s=>({timestamp:Date.now(),count:s.count,metricsType:"FFMETRICS",attributes:[{key:"featureIdentifier",value:s.featureIdentifier},{key:"featureName",value:s.featureIdentifier},{key:"variationIdentifier",value:s.variationIdentifier},{key:"target",value:c.identifier},{key:"SDK_NAME",value:"JavaScript"},{key:"SDK_TYPE",value:"client"},{key:"SDK_VERSION",value:st}]}))};Oe(`${K.eventUrl}/metrics/${g}?cluster=${W}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${B}`},body:JSON.stringify(o)}).then(()=>{R=[]}).catch(s=>{F(s)}).finally(()=>{O=window.setTimeout(x,De)})}else O=window.setTimeout(x,De)},b={},le=function(){return Ee?new Proxy({},{get(o,s){var l,V,S;let h=o[s];if(o.hasOwnProperty(s)){let T=o[s],C=R.find(z=>z.featureIdentifier===s&&T===z.featureValue);C?(C.variationIdentifier=((l=b[s])==null?void 0:l.identifier)||"",re(C)):R.push({featureIdentifier:s,featureValue:T,variationIdentifier:((V=b[s])==null?void 0:V.identifier)||"",count:A?1:0,lastAccessed:Date.now()}),F("Metrics event: Flag:",s,"has been read with value:",T,"variationIdentifier:",(S=b[s])==null?void 0:S.identifier)}return h}}):{}},P=le();_e(a,K).then(o=>{B=o;let s=(0,Be.default)(o);if(F("Authenticated",s),globalThis.localStorage&&globalThis.localStorage.HARNESS_FF_METRICS)try{delete globalThis.localStorage.HARNESS_FF_METRICS,F("Picking up metrics from previous session")}catch(h){}O=window.setTimeout(x,De),g=s.environment,W=s.clusterIdentifier,me().then(()=>{F("Fetch all flags ok",P)}).then(()=>{be()}).then(()=>{F("Event stream ready",{storage:P}),N.emit(j.READY,P),Ee||Object.keys(P).forEach(h=>{var l;R.push({featureIdentifier:h,featureValue:P[h],variationIdentifier:((l=b[h])==null?void 0:l.identifier)||"",count:A?1:0,lastAccessed:Date.now()})})}).catch(h=>{N.emit(j.ERROR,h)})}).catch(o=>{ce("Authentication error: ",o),N.emit(j.ERROR,o)});let me=()=>Ie(void 0,null,function*(){try{(yield(yield Oe(`${K.baseUrl}/client/env/${g}/target/${c.identifier}/evaluations?cluster=${W}`,{headers:{Authorization:`Bearer ${B}`}})).json()).forEach(h=>{let l=Ne(h);P[h.flag]=l,b[h.flag]=ie(ie({},h),{value:l})})}catch(o){return ce("Features fetch operation error: ",o),N.emit(j.ERROR,o),o}}),ve=o=>Ie(void 0,null,function*(){var s;try{let h=yield Oe(`${K.baseUrl}/client/env/${g}/target/${c.identifier}/evaluations/${o}?cluster=${W}`,{headers:{Authorization:`Bearer ${B}`}});if(h.ok){let l=yield h.json(),V=Ne(l);if(G(),P[o]=V,b[o]=ie(ie({},l),{value:V}),ue(),N.emit(j.CHANGED,Ee?new Proxy(l,{get(S,T){var C;if(S.hasOwnProperty(T)&&T==="value"){let z=S.flag,oe=l.value,pe=R.find(we=>we.featureIdentifier===z&&we.featureValue===oe);pe?(re(pe),pe.variationIdentifier=((C=b[z])==null?void 0:C.identifier)||""):R.push({featureIdentifier:z,featureValue:String(oe),variationIdentifier:b[z].identifier||"",count:A?1:0,lastAccessed:Date.now()}),F("Metrics event: Flag",T,"has been read with value via stream update",oe)}return T==="value"?Ne(l):l[T]}}):{deleted:l.deleted,flag:l.flag,value:Ne(l)}),!Ee){let S=l.flag,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===l.value);T?(re(T),T.variationIdentifier=((s=b[S])==null?void 0:s.identifier)||""):R.push({featureIdentifier:S,featureValue:String(l.value),variationIdentifier:b[S].identifier||"",count:A?1:0,lastAccessed:Date.now()})}}else N.emit(j.ERROR,h)}catch(h){ce("Feature fetch operation error: ",h),N.emit(j.ERROR,h)}}),be=()=>{if(!K.streamEnabled){F("Stream is disabled by configuration. Note: Polling is not yet supported");return}q=new dt(`${K.baseUrl}/stream`,{headers:{Authorization:`Bearer ${B}`,"API-Key":a}}),q.onopen=o=>{F("Stream connected",o),N.emit(j.CONNECTED)},q.onclose=o=>{F("Stream disconnected"),N.emit(j.DISCONNECTED)},q.onerror=o=>{ce("Stream has issue",o),N.emit("error",o)},q.addEventListener("*",o=>{let s=JSON.parse(o.data);switch(F("Received event from stream: ",s),s.event){case"create":setTimeout(()=>ve(s.identifier),1e3);break;case"patch":ve(s.identifier);break;case"delete":delete P[s.identifier],N.emit(j.CHANGED,{flag:s.identifier,value:void 0,deleted:!0}),F("Evaluation deleted",{message:s,storage:P});break}})},ne=(o,s)=>N.on(o,s),Se=(o,s)=>{o?N.off(o,s):he()},te=(o,s)=>{var l;let h=P[o];if(!Ee&&h!==void 0){let V=h,S=o,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===V);T?(re(T),T.variationIdentifier=((l=b[S])==null?void 0:l.identifier)||""):R.push({featureIdentifier:S,featureValue:V,count:A?1:0,variationIdentifier:b[S].identifier||"",lastAccessed:Date.now()})}return h!==void 0?h:s},he=()=>{F("Closing event stream"),P=le(),b={},clearTimeout(O),N.all.clear(),q.close()};return{on:ne,off:Se,variation:te,close:he}}; | ||
var Ze=Object.create,Re=Object.defineProperty,et=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty,rt=Object.getOwnPropertyNames,nt=Object.getOwnPropertyDescriptor;var ie=Object.assign,$e=a=>Re(a,"__esModule",{value:!0});var at=(a,c)=>()=>(c||(c={exports:{}},a(c.exports,c)),c.exports),it=(a,c)=>{for(var w in c)Re(a,w,{get:c[w],enumerable:!0})},ot=(a,c,w)=>{if(c&&typeof c=="object"||typeof c=="function")for(let g of rt(c))!tt.call(a,g)&&g!=="default"&&Re(a,g,{get:()=>c[g],enumerable:!(w=nt(c,g))||w.enumerable});return a},He=a=>ot($e(Re(a!=null?Ze(et(a)):{},"default",a&&a.__esModule&&"default"in a?{get:()=>a.default,enumerable:!0}:{value:a,enumerable:!0})),a);var Ie=(a,c,w)=>new Promise((g,q)=>{var G=A=>{try{O(w.next(A))}catch(K){q(K)}},B=A=>{try{O(w.throw(A))}catch(K){q(K)}},O=A=>A.done?g(A.value):Promise.resolve(A.value).then(G,B);O((w=w.apply(a,c)).next())});var ke=at((Le,Ae)=>{(function(a){"use strict";var c=a.setTimeout,w=a.clearTimeout,g=a.XMLHttpRequest,q=a.XDomainRequest,G=a.ActiveXObject,B=a.EventSource,O=a.document,A=a.Promise,K=a.fetch,ue=a.Response,R=a.TextDecoder,N=a.TextEncoder,z=a.AbortController;if(typeof window!="undefined"&&typeof O!="undefined"&&!("readyState"in O)&&O.body==null&&(O.readyState="loading",window.addEventListener("load",function(e){O.readyState="complete"},!1)),g==null&&G!=null&&(g=function(){return new G("Microsoft.XMLHTTP")}),Object.create==null&&(Object.create=function(e){function r(){}return r.prototype=e,new r}),Date.now||(Date.now=function(){return new Date().getTime()}),z==null){var F=K;K=function(e,r){var n=r.signal;return F(e,{headers:r.headers,credentials:r.credentials,cache:r.cache}).then(function(t){var f=t.body.getReader();return n._reader=f,n._aborted&&n._reader.cancel(),{status:t.status,statusText:t.statusText,headers:t.headers,body:{getReader:function(){return f}}}})},z=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){this.signal._reader!=null&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function re(){this.bitsNeeded=0,this.codePoint=0}re.prototype.decode=function(e){function r(p,y,d){if(d===1)return p>=128>>y&&p<<y<=2047;if(d===2)return p>=2048>>y&&p<<y<=55295||p>=57344>>y&&p<<y<=65535;if(d===3)return p>=65536>>y&&p<<y<=1114111;throw new Error}function n(p,y){if(p===6*1)return y>>6>15?3:y>31?2:1;if(p===6*2)return y>15?3:2;if(p===6*3)return 3;throw new Error}for(var t=65533,f="",i=this.bitsNeeded,u=this.codePoint,E=0;E<e.length;E+=1){var v=e[E];i!==0&&(v<128||v>191||!r(u<<6|v&63,i-6,n(i,u)))&&(i=0,u=t,f+=String.fromCharCode(u)),i===0?(v>=0&&v<=127?(i=0,u=v):v>=192&&v<=223?(i=6*1,u=v&31):v>=224&&v<=239?(i=6*2,u=v&15):v>=240&&v<=247?(i=6*3,u=v&7):(i=0,u=t),i!==0&&!r(u,i,n(i,u))&&(i=0,u=t)):(i-=6,u=u<<6|v&63),i===0&&(u<=65535?f+=String.fromCharCode(u):(f+=String.fromCharCode(55296+(u-65535-1>>10)),f+=String.fromCharCode(56320+(u-65535-1&1023))))}return this.bitsNeeded=i,this.codePoint=u,f};var _e=function(){try{return new R().decode(new N().encode("test"),{stream:!0})==="test"}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1};(R==null||N==null||!_e())&&(R=re);var x=function(){};function b(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=x,this.onload=x,this.onerror=x,this.onreadystatechange=x,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=x}b.prototype.open=function(e,r){this._abort(!0);var n=this,t=this._xhr,f=1,i=0;this._abort=function(d){n._sendTimeout!==0&&(w(n._sendTimeout),n._sendTimeout=0),(f===1||f===2||f===3)&&(f=4,t.onload=x,t.onerror=x,t.onabort=x,t.onprogress=x,t.onreadystatechange=x,t.abort(),i!==0&&(w(i),i=0),d||(n.readyState=4,n.onabort(null),n.onreadystatechange())),f=0};var u=function(){if(f===1){var d=0,m="",Y=void 0;if("contentType"in t)d=200,m="OK",Y=t.contentType;else try{d=t.status,m=t.statusText,Y=t.getResponseHeader("Content-Type")}catch(ge){d=0,m="",Y=void 0}d!==0&&(f=2,n.readyState=2,n.status=d,n.statusText=m,n._contentType=Y,n.onreadystatechange())}},E=function(){if(u(),f===2||f===3){f=3;var d="";try{d=t.responseText}catch(m){}n.readyState=3,n.responseText=d,n.onprogress()}},v=function(d,m){if((m==null||m.preventDefault==null)&&(m={preventDefault:x}),E(),f===1||f===2||f===3){if(f=4,i!==0&&(w(i),i=0),n.readyState=4,d==="load")n.onload(m);else if(d==="error")n.onerror(m);else if(d==="abort")n.onabort(m);else throw new TypeError;n.onreadystatechange()}},p=function(d){t!=null&&(t.readyState===4?(!("onload"in t)||!("onerror"in t)||!("onabort"in t))&&v(t.responseText===""?"error":"load",d):t.readyState===3?"onprogress"in t||E():t.readyState===2&&u())},y=function(){i=c(function(){y()},500),t.readyState===3&&E()};"onload"in t&&(t.onload=function(d){v("load",d)}),"onerror"in t&&(t.onerror=function(d){v("error",d)}),"onabort"in t&&(t.onabort=function(d){v("abort",d)}),"onprogress"in t&&(t.onprogress=E),"onreadystatechange"in t&&(t.onreadystatechange=function(d){p(d)}),("contentType"in t||!("ontimeout"in g.prototype))&&(r+=(r.indexOf("?")===-1?"?":"&")+"padding=true"),t.open(e,r,!0),"readyState"in t&&(i=c(function(){y()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(e){return this._contentType},b.prototype.setRequestHeader=function(e,r){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,r)},b.prototype.getAllResponseHeaders=function(){return this._xhr.getAllResponseHeaders!=null&&this._xhr.getAllResponseHeaders()||""},b.prototype.send=function(){if((!("ontimeout"in g.prototype)||!("sendAsBinary"in g.prototype)&&!("mozAnon"in g.prototype))&&O!=null&&O.readyState!=null&&O.readyState!=="complete"){var e=this;e._sendTimeout=c(function(){e._sendTimeout=0,e.send()},4);return}var r=this._xhr;"withCredentials"in r&&(r.withCredentials=this.withCredentials);try{r.send(void 0)}catch(n){throw n}};function le(e){return e.replace(/[A-Z]/g,function(r){return String.fromCharCode(r.charCodeAt(0)+32)})}function P(e){for(var r=Object.create(null),n=e.split(`\r | ||
`),t=0;t<n.length;t+=1){var f=n[t],i=f.split(": "),u=i.shift(),E=i.join(": ");r[le(u)]=E}this._map=r}P.prototype.get=function(e){return this._map[le(e)]},g!=null&&g.HEADERS_RECEIVED==null&&(g.HEADERS_RECEIVED=2);function me(){}me.prototype.open=function(e,r,n,t,f,i,u){e.open("GET",f);var E=0;e.onprogress=function(){var p=e.responseText,y=p.slice(E);E+=y.length,n(y)},e.onerror=function(p){p.preventDefault(),t(new Error("NetworkError"))},e.onload=function(){t(null)},e.onabort=function(){t(null)},e.onreadystatechange=function(){if(e.readyState===g.HEADERS_RECEIVED){var p=e.status,y=e.statusText,d=e.getResponseHeader("Content-Type"),m=e.getAllResponseHeaders();r(p,y,d,new P(m))}},e.withCredentials=i;for(var v in u)Object.prototype.hasOwnProperty.call(u,v)&&e.setRequestHeader(v,u[v]);return e.send(),e};function ve(e){this._headers=e}ve.prototype.get=function(e){return this._headers.get(e)};function be(){}be.prototype.open=function(e,r,n,t,f,i,u){var E=null,v=new z,p=v.signal,y=new R;return K(f,{headers:u,credentials:i?"include":"same-origin",signal:p,cache:"no-store"}).then(function(d){return E=d.body.getReader(),r(d.status,d.statusText,d.headers.get("Content-Type"),new ve(d.headers)),new A(function(m,Y){var ge=function(){E.read().then(function($){if($.done)m(void 0);else{var M=y.decode($.value,{stream:!0});n(M),ge()}}).catch(function($){Y($)})};ge()})}).catch(function(d){if(d.name!=="AbortError")return d}).then(function(d){t(d)}),{abort:function(){E!=null&&E.cancel(),v.abort()}}};function ne(){this._listeners=Object.create(null)}function Se(e){c(function(){throw e},0)}ne.prototype.dispatchEvent=function(e){e.target=this;var r=this._listeners[e.type];if(r!=null)for(var n=r.length,t=0;t<n;t+=1){var f=r[t];try{typeof f.handleEvent=="function"?f.handleEvent(e):f.call(this,e)}catch(i){Se(i)}}},ne.prototype.addEventListener=function(e,r){e=String(e);var n=this._listeners,t=n[e];t==null&&(t=[],n[e]=t);for(var f=!1,i=0;i<t.length;i+=1)t[i]===r&&(f=!0);f||t.push(r)},ne.prototype.removeEventListener=function(e,r){e=String(e);var n=this._listeners,t=n[e];if(t!=null){for(var f=[],i=0;i<t.length;i+=1)t[i]!==r&&f.push(t[i]);f.length===0?delete n[e]:n[e]=f}};function te(e){this.type=e,this.target=void 0}function he(e,r){te.call(this,e),this.data=r.data,this.lastEventId=r.lastEventId}he.prototype=Object.create(te.prototype);function o(e,r){te.call(this,e),this.status=r.status,this.statusText=r.statusText,this.headers=r.headers}o.prototype=Object.create(te.prototype);function s(e,r){te.call(this,e),this.error=r.error}s.prototype=Object.create(te.prototype);var h=-1,l=0,V=1,S=2,T=-1,C=0,J=1,oe=2,pe=3,we=/^text\/event\-stream(;.*)?$/i,Ge=1e3,Ke=18e6,Fe=function(e,r){var n=e==null?r:parseInt(e,10);return n!==n&&(n=r),xe(n)},xe=function(e){return Math.min(Math.max(e,Ge),Ke)},se=function(e,r,n){try{typeof r=="function"&&r.call(e,n)}catch(t){Se(t)}};function W(e,r){ne.call(this),r=r||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,We(this,e,r)}function ze(){return g!=null&&"withCredentials"in g.prototype||q==null?new g:new q}var Je=K!=null&&ue!=null&&"body"in ue.prototype;function We(e,r,n){r=String(r);var t=Boolean(n.withCredentials),f=n.lastEventIdQueryParameterName||"lastEventId",i=xe(1e3),u=Fe(n.heartbeatTimeout,45e3),E="",v=i,p=!1,y=0,d=n.headers||{},m=n.Transport,Y=Je&&m==null?void 0:new b(m!=null?new m:ze()),ge=m!=null&&typeof m!="string"?new m:Y==null?new be:new me,$=void 0,M=0,X=h,fe="",Te="",Q="",Ce="",H=C,Ve=0,ae=0,Ye=function(D,I,k,U){if(X===l)if(D===200&&k!=null&&we.test(k)){X=V,p=Date.now(),v=i,e.readyState=V;var L=new o("open",{status:D,statusText:I,headers:U});e.dispatchEvent(L),se(e,e.onopen,L)}else{var _="";D!==200?(I&&(I=I.replace(/\s+/g," ")),_="EventSource's response has a status "+D+" "+I+" that is not 200. Aborting the connection."):_="EventSource's response has a Content-Type specifying an unsupported type: "+(k==null?"-":k.replace(/\s+/g," "))+". Aborting the connection.",Me();var L=new o("error",{status:D,statusText:I,headers:U});e.dispatchEvent(L),se(e,e.onerror,L),console.error(_)}},Qe=function(D){if(X===V){for(var I=-1,k=0;k<D.length;k+=1){var U=D.charCodeAt(k);(U===` | ||
`.charCodeAt(0)||U==="\r".charCodeAt(0))&&(I=k)}var L=(I!==-1?Ce:"")+D.slice(0,I+1);Ce=(I===-1?Ce:"")+D.slice(I+1),D!==""&&(p=Date.now(),y+=D.length);for(var _=0;_<L.length;_+=1){var U=L.charCodeAt(_);if(H===T&&U===` | ||
`.charCodeAt(0))H=C;else if(H===T&&(H=C),U==="\r".charCodeAt(0)||U===` | ||
`.charCodeAt(0)){if(H!==C){H===J&&(ae=_+1);var Z=L.slice(Ve,ae-1),ee=L.slice(ae+(ae<_&&L.charCodeAt(ae)===" ".charCodeAt(0)?1:0),_);Z==="data"?(fe+=` | ||
`,fe+=ee):Z==="id"?Te=ee:Z==="event"?Q=ee:Z==="retry"?(i=Fe(ee,i),v=i):Z==="heartbeatTimeout"&&(u=Fe(ee,u),M!==0&&(w(M),M=c(function(){ye()},u)))}if(H===C){if(fe!==""){E=Te,Q===""&&(Q="message");var de=new he(Q,{data:fe.slice(1),lastEventId:Te});if(e.dispatchEvent(de),Q==="open"?se(e,e.onopen,de):Q==="message"?se(e,e.onmessage,de):Q==="error"&&se(e,e.onerror,de),X===S)return}fe="",Q=""}H=U==="\r".charCodeAt(0)?T:C}else H===C&&(Ve=_,H=J),H===J?U===":".charCodeAt(0)&&(ae=_+1,H=oe):H===oe&&(H=pe)}}},je=function(D){if(X===V||X===l)X=h,M!==0&&(w(M),M=0),M=c(function(){ye()},v),v=xe(Math.min(i*16,v*2)),e.readyState=l;else if(X===S&&D!=null){console.error(D);var I=new s("error",{error:D});e.dispatchEvent(I),se(e,e.onerror,I)}},Me=function(){X=S,$!=null&&($.abort(),$=void 0),M!==0&&(w(M),M=0),e.readyState=S},ye=function(){if(M=0,X!==h){if(!p&&$!=null)je(new Error("No activity within "+u+" milliseconds. "+(X===l?"No response received.":y+" chars received.")+" Reconnecting.")),$!=null&&($.abort(),$=void 0);else{var D=Math.max((p||Date.now())+u-Date.now(),1);p=!1,M=c(function(){ye()},D)}return}p=!1,y=0,M=c(function(){ye()},u),X=l,fe="",Q="",Te=E,Ce="",Ve=0,ae=0,H=C;var I=r;if(r.slice(0,5)!=="data:"&&r.slice(0,5)!=="blob:"&&E!==""){var k=r.indexOf("?");I=k===-1?r:r.slice(0,k+1)+r.slice(k+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(ee,de){return de===f?"":ee}),I+=(r.indexOf("?")===-1?"?":"&")+f+"="+encodeURIComponent(E)}var U=e.withCredentials,L={};L.Accept="text/event-stream";var _=e.headers;if(_!=null)for(var Z in _)Object.prototype.hasOwnProperty.call(_,Z)&&(L[Z]=_[Z]);try{$=ge.open(Y,Ye,Qe,je,I,U,L)}catch(ee){throw Me(),ee}};e.url=r,e.readyState=l,e.withCredentials=t,e.headers=d,e._close=Me,ye()}W.prototype=Object.create(ne.prototype),W.prototype.CONNECTING=l,W.prototype.OPEN=V,W.prototype.CLOSED=S,W.prototype.close=function(){this._close()},W.CONNECTING=l,W.OPEN=V,W.CLOSED=S,W.prototype.withCredentials=void 0;var Pe=B;g!=null&&(B==null||!("withCredentials"in B.prototype))&&(Pe=W),function(e){if(typeof Ae=="object"&&typeof Ae.exports=="object"){var r=e(Le);r!==void 0&&(Ae.exports=r)}else typeof define=="function"&&define.amd?define(["exports"],e):e(a)}(function(e){e.EventSourcePolyfill=W,e.NativeEventSource=B,e.EventSource=Pe})})(typeof globalThis=="undefined"?typeof window!="undefined"?window:typeof self!="undefined"?self:Le:globalThis)});$e(exports);it(exports,{Event:()=>j,initialize:()=>ct});var Be=He(require("jwt-decode")),Xe=He(require("mitt")),qe=He(ke());var j;(function(a){a.READY="ready",a.CONNECTED="connected",a.DISCONNECTED="disconnected",a.RECONNECTED="reconnected",a.CHANGED="changed",a.ERROR="error"})(j||(j={}));var Ue={debug:!1,baseUrl:"https://config.ff.harness.io/api/1.0",eventUrl:"https://events.ff.harness.io/api/1.0",streamEnabled:!0,allAttributesPrivate:!1,privateAttributeNames:[]},ce=(a,...c)=>console.error(`[FF-SDK] ${a}`,...c),De=30*1e3;var st="1.4.4",ft=500,Oe=globalThis.fetch,dt=qe.EventSourcePolyfill,Ee=!!globalThis.Proxy,Ne=a=>{let{value:c}=a;try{switch(a.kind.toLowerCase()){case"int":case"number":c=Number(c);break;case"boolean":c=c.toString().toLowerCase()==="true";break;case"json":c=JSON.parse(c);break}}catch(w){ce(w)}return c},ct=(a,c,w)=>{let g,q,G,B,O,A=!0,K=()=>{A=!1},ue=()=>{A=!0},R=[],N=(0,Xe.default)(),z=ie(ie({},Ue),w),F=(o,...s)=>{z.debug&&console.debug(`[FF-SDK] ${o}`,...s)},re=o=>{if(A){let s=Date.now();s-o.lastAccessed>ft&&(o.count++,o.lastAccessed=s)}};globalThis.onbeforeunload=()=>{R.length&&globalThis.localStorage&&(K(),globalThis.localStorage.HARNESS_FF_METRICS=JSON.stringify(R),ue())};let _e=(o,s)=>Ie(void 0,null,function*(){return(yield(yield Oe(`${s.baseUrl}/client/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:o,target:c})})).json()).authToken}),x=()=>{if(R.length){F("Sending metrics...",{metrics:R,evaluations:b});let o={metricsData:R.map(s=>({timestamp:Date.now(),count:s.count,metricsType:"FFMETRICS",attributes:[{key:"featureIdentifier",value:s.featureIdentifier},{key:"featureName",value:s.featureIdentifier},{key:"variationIdentifier",value:s.variationIdentifier},{key:"target",value:c.identifier},{key:"SDK_NAME",value:"JavaScript"},{key:"SDK_TYPE",value:"client"},{key:"SDK_VERSION",value:st}]}))};Oe(`${z.eventUrl}/metrics/${g}?cluster=${q}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${B}`},body:JSON.stringify(o)}).then(()=>{R=[]}).catch(s=>{F(s)}).finally(()=>{O=window.setTimeout(x,De)})}else O=window.setTimeout(x,De)},b={},le=function(){return Ee?new Proxy({},{get(o,s){var l,V,S;let h=o[s];if(o.hasOwnProperty(s)){let T=o[s],C=R.find(J=>J.featureIdentifier===s&&T===J.featureValue);C?(C.variationIdentifier=((l=b[s])==null?void 0:l.identifier)||"",re(C)):R.push({featureIdentifier:s,featureValue:T,variationIdentifier:((V=b[s])==null?void 0:V.identifier)||"",count:A?1:0,lastAccessed:Date.now()}),F("Metrics event: Flag:",s,"has been read with value:",T,"variationIdentifier:",(S=b[s])==null?void 0:S.identifier)}return h}}):{}},P=le();_e(a,z).then(o=>{B=o;let s=(0,Be.default)(o);if(F("Authenticated",s),globalThis.localStorage&&globalThis.localStorage.HARNESS_FF_METRICS)try{delete globalThis.localStorage.HARNESS_FF_METRICS,F("Picking up metrics from previous session")}catch(h){}O=window.setTimeout(x,De),g=s.environment,q=s.clusterIdentifier,me().then(()=>{F("Fetch all flags ok",P)}).then(()=>{be()}).then(()=>{F("Event stream ready",{storage:P}),N.emit(j.READY,P),Ee||Object.keys(P).forEach(h=>{var l;R.push({featureIdentifier:h,featureValue:P[h],variationIdentifier:((l=b[h])==null?void 0:l.identifier)||"",count:A?1:0,lastAccessed:Date.now()})})}).catch(h=>{N.emit(j.ERROR,h)})}).catch(o=>{ce("Authentication error: ",o),N.emit(j.ERROR,o)});let me=()=>Ie(void 0,null,function*(){try{(yield(yield Oe(`${z.baseUrl}/client/env/${g}/target/${c.identifier}/evaluations?cluster=${q}`,{headers:{Authorization:`Bearer ${B}`}})).json()).forEach(h=>{let l=Ne(h);P[h.flag]=l,b[h.flag]=ie(ie({},h),{value:l})})}catch(o){return ce("Features fetch operation error: ",o),N.emit(j.ERROR,o),o}}),ve=o=>Ie(void 0,null,function*(){var s;try{let h=yield Oe(`${z.baseUrl}/client/env/${g}/target/${c.identifier}/evaluations/${o}?cluster=${q}`,{headers:{Authorization:`Bearer ${B}`}});if(h.ok){let l=yield h.json(),V=Ne(l);if(K(),P[o]=V,b[o]=ie(ie({},l),{value:V}),ue(),N.emit(j.CHANGED,Ee?new Proxy(l,{get(S,T){var C;if(S.hasOwnProperty(T)&&T==="value"){let J=S.flag,oe=l.value,pe=R.find(we=>we.featureIdentifier===J&&we.featureValue===oe);pe?(re(pe),pe.variationIdentifier=((C=b[J])==null?void 0:C.identifier)||""):R.push({featureIdentifier:J,featureValue:String(oe),variationIdentifier:b[J].identifier||"",count:A?1:0,lastAccessed:Date.now()}),F("Metrics event: Flag",T,"has been read with value via stream update",oe)}return T==="value"?Ne(l):l[T]}}):{deleted:l.deleted,flag:l.flag,value:Ne(l)}),!Ee){let S=l.flag,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===l.value);T?(re(T),T.variationIdentifier=((s=b[S])==null?void 0:s.identifier)||""):R.push({featureIdentifier:S,featureValue:String(l.value),variationIdentifier:b[S].identifier||"",count:A?1:0,lastAccessed:Date.now()})}}else N.emit(j.ERROR,h)}catch(h){ce("Feature fetch operation error: ",h),N.emit(j.ERROR,h)}}),be=()=>{if(!z.streamEnabled){F("Stream is disabled by configuration. Note: Polling is not yet supported");return}G=new dt(`${z.baseUrl}/stream?cluster=${q}`,{headers:{Authorization:`Bearer ${B}`,"API-Key":a}}),G.onopen=o=>{F("Stream connected",o),N.emit(j.CONNECTED)},G.onclose=o=>{F("Stream disconnected"),N.emit(j.DISCONNECTED)},G.onerror=o=>{ce("Stream has issue",o),N.emit("error",o)},G.addEventListener("*",o=>{let s=JSON.parse(o.data);switch(F("Received event from stream: ",s),s.event){case"create":setTimeout(()=>ve(s.identifier),1e3);break;case"patch":ve(s.identifier);break;case"delete":delete P[s.identifier],N.emit(j.CHANGED,{flag:s.identifier,value:void 0,deleted:!0}),F("Evaluation deleted",{message:s,storage:P});break}})},ne=(o,s)=>N.on(o,s),Se=(o,s)=>{o?N.off(o,s):he()},te=(o,s)=>{var l;let h=P[o];if(!Ee&&h!==void 0){let V=h,S=o,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===V);T?(re(T),T.variationIdentifier=((l=b[S])==null?void 0:l.identifier)||""):R.push({featureIdentifier:S,featureValue:V,count:A?1:0,variationIdentifier:b[S].identifier||"",lastAccessed:Date.now()})}return h!==void 0?h:s},he=()=>{F("Closing event stream"),P=le(),b={},clearTimeout(O),N.all.clear(),G.close()};return{on:ne,off:Se,variation:te,close:he}}; | ||
/** @license | ||
@@ -8,0 +8,0 @@ * eventsource.js |
@@ -1,7 +0,7 @@ | ||
var HarnessFFSDK=(()=>{var tt=Object.create,Re=Object.defineProperty,rt=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty,at=Object.getOwnPropertyNames,it=Object.getOwnPropertyDescriptor;var ie=Object.assign,ot=t=>Re(t,"__esModule",{value:!0});var st=(t,a)=>()=>(a||(a={exports:{}},t(a.exports,a)),a.exports),ft=(t,a)=>{for(var l in a)Re(t,l,{get:a[l],enumerable:!0})},dt=(t,a,l)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of at(a))!nt.call(t,s)&&s!=="default"&&Re(t,s,{get:()=>a[s],enumerable:!(l=it(a,s))||l.enumerable});return t},ct=t=>dt(ot(Re(t!=null?tt(rt(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var Ie=(t,a,l)=>new Promise((s,x)=>{var A=O=>{try{N(l.next(O))}catch(K){x(K)}},V=O=>{try{N(l.throw(O))}catch(K){x(K)}},N=O=>O.done?s(O.value):Promise.resolve(O.value).then(A,V);N((l=l.apply(t,a)).next())});var Xe=st((ke,Oe)=>{(function(t){"use strict";var a=t.setTimeout,l=t.clearTimeout,s=t.XMLHttpRequest,x=t.XDomainRequest,A=t.ActiveXObject,V=t.EventSource,N=t.document,O=t.Promise,K=t.fetch,ue=t.Response,R=t.TextDecoder,_=t.TextEncoder,J=t.AbortController;if(typeof window!="undefined"&&typeof N!="undefined"&&!("readyState"in N)&&N.body==null&&(N.readyState="loading",window.addEventListener("load",function(e){N.readyState="complete"},!1)),s==null&&A!=null&&(s=function(){return new A("Microsoft.XMLHTTP")}),Object.create==null&&(Object.create=function(e){function n(){}return n.prototype=e,new n}),Date.now||(Date.now=function(){return new Date().getTime()}),J==null){var M=K;K=function(e,n){var i=n.signal;return M(e,{headers:n.headers,credentials:n.credentials,cache:n.cache}).then(function(r){var c=r.body.getReader();return i._reader=c,i._aborted&&i._reader.cancel(),{status:r.status,statusText:r.statusText,headers:r.headers,body:{getReader:function(){return c}}}})},J=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){this.signal._reader!=null&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function re(){this.bitsNeeded=0,this.codePoint=0}re.prototype.decode=function(e){function n(y,m,u){if(u===1)return y>=128>>m&&y<<m<=2047;if(u===2)return y>=2048>>m&&y<<m<=55295||y>=57344>>m&&y<<m<=65535;if(u===3)return y>=65536>>m&&y<<m<=1114111;throw new Error}function i(y,m){if(y===6*1)return m>>6>15?3:m>31?2:1;if(y===6*2)return m>15?3:2;if(y===6*3)return 3;throw new Error}for(var r=65533,c="",o=this.bitsNeeded,v=this.codePoint,E=0;E<e.length;E+=1){var p=e[E];o!==0&&(p<128||p>191||!n(v<<6|p&63,o-6,i(o,v)))&&(o=0,v=r,c+=String.fromCharCode(v)),o===0?(p>=0&&p<=127?(o=0,v=p):p>=192&&p<=223?(o=6*1,v=p&31):p>=224&&p<=239?(o=6*2,v=p&15):p>=240&&p<=247?(o=6*3,v=p&7):(o=0,v=r),o!==0&&!n(v,o,i(o,v))&&(o=0,v=r)):(o-=6,v=v<<6|p&63),o===0&&(v<=65535?c+=String.fromCharCode(v):(c+=String.fromCharCode(55296+(v-65535-1>>10)),c+=String.fromCharCode(56320+(v-65535-1&1023))))}return this.bitsNeeded=o,this.codePoint=v,c};var Fe=function(){try{return new R().decode(new _().encode("test"),{stream:!0})==="test"}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1};(R==null||_==null||!Fe())&&(R=re);var H=function(){};function b(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=H,this.onload=H,this.onerror=H,this.onreadystatechange=H,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=H}b.prototype.open=function(e,n){this._abort(!0);var i=this,r=this._xhr,c=1,o=0;this._abort=function(u){i._sendTimeout!==0&&(l(i._sendTimeout),i._sendTimeout=0),(c===1||c===2||c===3)&&(c=4,r.onload=H,r.onerror=H,r.onabort=H,r.onprogress=H,r.onreadystatechange=H,r.abort(),o!==0&&(l(o),o=0),u||(i.readyState=4,i.onabort(null),i.onreadystatechange())),c=0};var v=function(){if(c===1){var u=0,w="",Y=void 0;if("contentType"in r)u=200,w="OK",Y=r.contentType;else try{u=r.status,w=r.statusText,Y=r.getResponseHeader("Content-Type")}catch(ge){u=0,w="",Y=void 0}u!==0&&(c=2,i.readyState=2,i.status=u,i.statusText=w,i._contentType=Y,i.onreadystatechange())}},E=function(){if(v(),c===2||c===3){c=3;var u="";try{u=r.responseText}catch(w){}i.readyState=3,i.responseText=u,i.onprogress()}},p=function(u,w){if((w==null||w.preventDefault==null)&&(w={preventDefault:H}),E(),c===1||c===2||c===3){if(c=4,o!==0&&(l(o),o=0),i.readyState=4,u==="load")i.onload(w);else if(u==="error")i.onerror(w);else if(u==="abort")i.onabort(w);else throw new TypeError;i.onreadystatechange()}},y=function(u){r!=null&&(r.readyState===4?(!("onload"in r)||!("onerror"in r)||!("onabort"in r))&&p(r.responseText===""?"error":"load",u):r.readyState===3?"onprogress"in r||E():r.readyState===2&&v())},m=function(){o=a(function(){m()},500),r.readyState===3&&E()};"onload"in r&&(r.onload=function(u){p("load",u)}),"onerror"in r&&(r.onerror=function(u){p("error",u)}),"onabort"in r&&(r.onabort=function(u){p("abort",u)}),"onprogress"in r&&(r.onprogress=E),"onreadystatechange"in r&&(r.onreadystatechange=function(u){y(u)}),("contentType"in r||!("ontimeout"in s.prototype))&&(n+=(n.indexOf("?")===-1?"?":"&")+"padding=true"),r.open(e,n,!0),"readyState"in r&&(o=a(function(){m()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(e){return this._contentType},b.prototype.setRequestHeader=function(e,n){var i=this._xhr;"setRequestHeader"in i&&i.setRequestHeader(e,n)},b.prototype.getAllResponseHeaders=function(){return this._xhr.getAllResponseHeaders!=null&&this._xhr.getAllResponseHeaders()||""},b.prototype.send=function(){if((!("ontimeout"in s.prototype)||!("sendAsBinary"in s.prototype)&&!("mozAnon"in s.prototype))&&N!=null&&N.readyState!=null&&N.readyState!=="complete"){var e=this;e._sendTimeout=a(function(){e._sendTimeout=0,e.send()},4);return}var n=this._xhr;"withCredentials"in n&&(n.withCredentials=this.withCredentials);try{n.send(void 0)}catch(i){throw i}};function le(e){return e.replace(/[A-Z]/g,function(n){return String.fromCharCode(n.charCodeAt(0)+32)})}function $(e){for(var n=Object.create(null),i=e.split(`\r | ||
`),r=0;r<i.length;r+=1){var c=i[r],o=c.split(": "),v=o.shift(),E=o.join(": ");n[le(v)]=E}this._map=n}$.prototype.get=function(e){return this._map[le(e)]},s!=null&&s.HEADERS_RECEIVED==null&&(s.HEADERS_RECEIVED=2);function Ee(){}Ee.prototype.open=function(e,n,i,r,c,o,v){e.open("GET",c);var E=0;e.onprogress=function(){var y=e.responseText,m=y.slice(E);E+=m.length,i(m)},e.onerror=function(y){y.preventDefault(),r(new Error("NetworkError"))},e.onload=function(){r(null)},e.onabort=function(){r(null)},e.onreadystatechange=function(){if(e.readyState===s.HEADERS_RECEIVED){var y=e.status,m=e.statusText,u=e.getResponseHeader("Content-Type"),w=e.getAllResponseHeaders();n(y,m,u,new $(w))}},e.withCredentials=o;for(var p in v)Object.prototype.hasOwnProperty.call(v,p)&&e.setRequestHeader(p,v[p]);return e.send(),e};function ve(e){this._headers=e}ve.prototype.get=function(e){return this._headers.get(e)};function we(){}we.prototype.open=function(e,n,i,r,c,o,v){var E=null,p=new J,y=p.signal,m=new R;return K(c,{headers:v,credentials:o?"include":"same-origin",signal:y,cache:"no-store"}).then(function(u){return E=u.body.getReader(),n(u.status,u.statusText,u.headers.get("Content-Type"),new ve(u.headers)),new O(function(w,Y){var ge=function(){E.read().then(function(B){if(B.done)w(void 0);else{var k=m.decode(B.value,{stream:!0});i(k),ge()}}).catch(function(B){Y(B)})};ge()})}).catch(function(u){if(u.name!=="AbortError")return u}).then(function(u){r(u)}),{abort:function(){E!=null&&E.cancel(),p.abort()}}};function ne(){this._listeners=Object.create(null)}function be(e){a(function(){throw e},0)}ne.prototype.dispatchEvent=function(e){e.target=this;var n=this._listeners[e.type];if(n!=null)for(var i=n.length,r=0;r<i;r+=1){var c=n[r];try{typeof c.handleEvent=="function"?c.handleEvent(e):c.call(this,e)}catch(o){be(o)}}},ne.prototype.addEventListener=function(e,n){e=String(e);var i=this._listeners,r=i[e];r==null&&(r=[],i[e]=r);for(var c=!1,o=0;o<r.length;o+=1)r[o]===n&&(c=!0);c||r.push(n)},ne.prototype.removeEventListener=function(e,n){e=String(e);var i=this._listeners,r=i[e];if(r!=null){for(var c=[],o=0;o<r.length;o+=1)r[o]!==n&&c.push(r[o]);c.length===0?delete i[e]:i[e]=c}};function te(e){this.type=e,this.target=void 0}function he(e,n){te.call(this,e),this.data=n.data,this.lastEventId=n.lastEventId}he.prototype=Object.create(te.prototype);function f(e,n){te.call(this,e),this.status=n.status,this.statusText=n.statusText,this.headers=n.headers}f.prototype=Object.create(te.prototype);function d(e,n){te.call(this,e),this.error=n.error}d.prototype=Object.create(te.prototype);var g=-1,h=0,L=1,S=2,T=-1,C=0,z=1,oe=2,pe=3,Se=/^text\/event\-stream(;.*)?$/i,Je=1e3,ze=18e6,xe=function(e,n){var i=e==null?n:parseInt(e,10);return i!==i&&(i=n),Me(i)},Me=function(e){return Math.min(Math.max(e,Je),ze)},se=function(e,n,i){try{typeof n=="function"&&n.call(e,i)}catch(r){be(r)}};function W(e,n){ne.call(this),n=n||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,Qe(this,e,n)}function We(){return s!=null&&"withCredentials"in s.prototype||x==null?new s:new x}var Ye=K!=null&&ue!=null&&"body"in ue.prototype;function Qe(e,n,i){n=String(n);var r=Boolean(i.withCredentials),c=i.lastEventIdQueryParameterName||"lastEventId",o=Me(1e3),v=xe(i.heartbeatTimeout,45e3),E="",p=o,y=!1,m=0,u=i.headers||{},w=i.Transport,Y=Ye&&w==null?void 0:new b(w!=null?new w:We()),ge=w!=null&&typeof w!="string"?new w:Y==null?new we:new Ee,B=void 0,k=0,G=g,fe="",Te="",Q="",Ce="",P=C,Ve=0,ae=0,Ze=function(D,I,X,q){if(G===h)if(D===200&&X!=null&&Se.test(X)){G=L,y=Date.now(),p=o,e.readyState=L;var j=new f("open",{status:D,statusText:I,headers:q});e.dispatchEvent(j),se(e,e.onopen,j)}else{var F="";D!==200?(I&&(I=I.replace(/\s+/g," ")),F="EventSource's response has a status "+D+" "+I+" that is not 200. Aborting the connection."):F="EventSource's response has a Content-Type specifying an unsupported type: "+(X==null?"-":X.replace(/\s+/g," "))+". Aborting the connection.",He();var j=new f("error",{status:D,statusText:I,headers:q});e.dispatchEvent(j),se(e,e.onerror,j),console.error(F)}},et=function(D){if(G===L){for(var I=-1,X=0;X<D.length;X+=1){var q=D.charCodeAt(X);(q===` | ||
`.charCodeAt(0)||q==="\r".charCodeAt(0))&&(I=X)}var j=(I!==-1?Ce:"")+D.slice(0,I+1);Ce=(I===-1?Ce:"")+D.slice(I+1),D!==""&&(y=Date.now(),m+=D.length);for(var F=0;F<j.length;F+=1){var q=j.charCodeAt(F);if(P===T&&q===` | ||
var HarnessFFSDK=(()=>{var tt=Object.create,Re=Object.defineProperty,rt=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty,at=Object.getOwnPropertyNames,it=Object.getOwnPropertyDescriptor;var ie=Object.assign,ot=t=>Re(t,"__esModule",{value:!0});var st=(t,a)=>()=>(a||(a={exports:{}},t(a.exports,a)),a.exports),ft=(t,a)=>{for(var l in a)Re(t,l,{get:a[l],enumerable:!0})},dt=(t,a,l)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of at(a))!nt.call(t,s)&&s!=="default"&&Re(t,s,{get:()=>a[s],enumerable:!(l=it(a,s))||l.enumerable});return t},ct=t=>dt(ot(Re(t!=null?tt(rt(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var Ie=(t,a,l)=>new Promise((s,N)=>{var A=O=>{try{_(l.next(O))}catch(K){N(K)}},V=O=>{try{_(l.throw(O))}catch(K){N(K)}},_=O=>O.done?s(O.value):Promise.resolve(O.value).then(A,V);_((l=l.apply(t,a)).next())});var Xe=st((ke,Oe)=>{(function(t){"use strict";var a=t.setTimeout,l=t.clearTimeout,s=t.XMLHttpRequest,N=t.XDomainRequest,A=t.ActiveXObject,V=t.EventSource,_=t.document,O=t.Promise,K=t.fetch,ue=t.Response,R=t.TextDecoder,F=t.TextEncoder,J=t.AbortController;if(typeof window!="undefined"&&typeof _!="undefined"&&!("readyState"in _)&&_.body==null&&(_.readyState="loading",window.addEventListener("load",function(e){_.readyState="complete"},!1)),s==null&&A!=null&&(s=function(){return new A("Microsoft.XMLHTTP")}),Object.create==null&&(Object.create=function(e){function n(){}return n.prototype=e,new n}),Date.now||(Date.now=function(){return new Date().getTime()}),J==null){var M=K;K=function(e,n){var i=n.signal;return M(e,{headers:n.headers,credentials:n.credentials,cache:n.cache}).then(function(r){var c=r.body.getReader();return i._reader=c,i._aborted&&i._reader.cancel(),{status:r.status,statusText:r.statusText,headers:r.headers,body:{getReader:function(){return c}}}})},J=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){this.signal._reader!=null&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function re(){this.bitsNeeded=0,this.codePoint=0}re.prototype.decode=function(e){function n(y,m,u){if(u===1)return y>=128>>m&&y<<m<=2047;if(u===2)return y>=2048>>m&&y<<m<=55295||y>=57344>>m&&y<<m<=65535;if(u===3)return y>=65536>>m&&y<<m<=1114111;throw new Error}function i(y,m){if(y===6*1)return m>>6>15?3:m>31?2:1;if(y===6*2)return m>15?3:2;if(y===6*3)return 3;throw new Error}for(var r=65533,c="",o=this.bitsNeeded,v=this.codePoint,E=0;E<e.length;E+=1){var p=e[E];o!==0&&(p<128||p>191||!n(v<<6|p&63,o-6,i(o,v)))&&(o=0,v=r,c+=String.fromCharCode(v)),o===0?(p>=0&&p<=127?(o=0,v=p):p>=192&&p<=223?(o=6*1,v=p&31):p>=224&&p<=239?(o=6*2,v=p&15):p>=240&&p<=247?(o=6*3,v=p&7):(o=0,v=r),o!==0&&!n(v,o,i(o,v))&&(o=0,v=r)):(o-=6,v=v<<6|p&63),o===0&&(v<=65535?c+=String.fromCharCode(v):(c+=String.fromCharCode(55296+(v-65535-1>>10)),c+=String.fromCharCode(56320+(v-65535-1&1023))))}return this.bitsNeeded=o,this.codePoint=v,c};var Fe=function(){try{return new R().decode(new F().encode("test"),{stream:!0})==="test"}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1};(R==null||F==null||!Fe())&&(R=re);var H=function(){};function b(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=H,this.onload=H,this.onerror=H,this.onreadystatechange=H,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=H}b.prototype.open=function(e,n){this._abort(!0);var i=this,r=this._xhr,c=1,o=0;this._abort=function(u){i._sendTimeout!==0&&(l(i._sendTimeout),i._sendTimeout=0),(c===1||c===2||c===3)&&(c=4,r.onload=H,r.onerror=H,r.onabort=H,r.onprogress=H,r.onreadystatechange=H,r.abort(),o!==0&&(l(o),o=0),u||(i.readyState=4,i.onabort(null),i.onreadystatechange())),c=0};var v=function(){if(c===1){var u=0,w="",Y=void 0;if("contentType"in r)u=200,w="OK",Y=r.contentType;else try{u=r.status,w=r.statusText,Y=r.getResponseHeader("Content-Type")}catch(ge){u=0,w="",Y=void 0}u!==0&&(c=2,i.readyState=2,i.status=u,i.statusText=w,i._contentType=Y,i.onreadystatechange())}},E=function(){if(v(),c===2||c===3){c=3;var u="";try{u=r.responseText}catch(w){}i.readyState=3,i.responseText=u,i.onprogress()}},p=function(u,w){if((w==null||w.preventDefault==null)&&(w={preventDefault:H}),E(),c===1||c===2||c===3){if(c=4,o!==0&&(l(o),o=0),i.readyState=4,u==="load")i.onload(w);else if(u==="error")i.onerror(w);else if(u==="abort")i.onabort(w);else throw new TypeError;i.onreadystatechange()}},y=function(u){r!=null&&(r.readyState===4?(!("onload"in r)||!("onerror"in r)||!("onabort"in r))&&p(r.responseText===""?"error":"load",u):r.readyState===3?"onprogress"in r||E():r.readyState===2&&v())},m=function(){o=a(function(){m()},500),r.readyState===3&&E()};"onload"in r&&(r.onload=function(u){p("load",u)}),"onerror"in r&&(r.onerror=function(u){p("error",u)}),"onabort"in r&&(r.onabort=function(u){p("abort",u)}),"onprogress"in r&&(r.onprogress=E),"onreadystatechange"in r&&(r.onreadystatechange=function(u){y(u)}),("contentType"in r||!("ontimeout"in s.prototype))&&(n+=(n.indexOf("?")===-1?"?":"&")+"padding=true"),r.open(e,n,!0),"readyState"in r&&(o=a(function(){m()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(e){return this._contentType},b.prototype.setRequestHeader=function(e,n){var i=this._xhr;"setRequestHeader"in i&&i.setRequestHeader(e,n)},b.prototype.getAllResponseHeaders=function(){return this._xhr.getAllResponseHeaders!=null&&this._xhr.getAllResponseHeaders()||""},b.prototype.send=function(){if((!("ontimeout"in s.prototype)||!("sendAsBinary"in s.prototype)&&!("mozAnon"in s.prototype))&&_!=null&&_.readyState!=null&&_.readyState!=="complete"){var e=this;e._sendTimeout=a(function(){e._sendTimeout=0,e.send()},4);return}var n=this._xhr;"withCredentials"in n&&(n.withCredentials=this.withCredentials);try{n.send(void 0)}catch(i){throw i}};function le(e){return e.replace(/[A-Z]/g,function(n){return String.fromCharCode(n.charCodeAt(0)+32)})}function $(e){for(var n=Object.create(null),i=e.split(`\r | ||
`),r=0;r<i.length;r+=1){var c=i[r],o=c.split(": "),v=o.shift(),E=o.join(": ");n[le(v)]=E}this._map=n}$.prototype.get=function(e){return this._map[le(e)]},s!=null&&s.HEADERS_RECEIVED==null&&(s.HEADERS_RECEIVED=2);function Ee(){}Ee.prototype.open=function(e,n,i,r,c,o,v){e.open("GET",c);var E=0;e.onprogress=function(){var y=e.responseText,m=y.slice(E);E+=m.length,i(m)},e.onerror=function(y){y.preventDefault(),r(new Error("NetworkError"))},e.onload=function(){r(null)},e.onabort=function(){r(null)},e.onreadystatechange=function(){if(e.readyState===s.HEADERS_RECEIVED){var y=e.status,m=e.statusText,u=e.getResponseHeader("Content-Type"),w=e.getAllResponseHeaders();n(y,m,u,new $(w))}},e.withCredentials=o;for(var p in v)Object.prototype.hasOwnProperty.call(v,p)&&e.setRequestHeader(p,v[p]);return e.send(),e};function ve(e){this._headers=e}ve.prototype.get=function(e){return this._headers.get(e)};function we(){}we.prototype.open=function(e,n,i,r,c,o,v){var E=null,p=new J,y=p.signal,m=new R;return K(c,{headers:v,credentials:o?"include":"same-origin",signal:y,cache:"no-store"}).then(function(u){return E=u.body.getReader(),n(u.status,u.statusText,u.headers.get("Content-Type"),new ve(u.headers)),new O(function(w,Y){var ge=function(){E.read().then(function(B){if(B.done)w(void 0);else{var k=m.decode(B.value,{stream:!0});i(k),ge()}}).catch(function(B){Y(B)})};ge()})}).catch(function(u){if(u.name!=="AbortError")return u}).then(function(u){r(u)}),{abort:function(){E!=null&&E.cancel(),p.abort()}}};function ne(){this._listeners=Object.create(null)}function be(e){a(function(){throw e},0)}ne.prototype.dispatchEvent=function(e){e.target=this;var n=this._listeners[e.type];if(n!=null)for(var i=n.length,r=0;r<i;r+=1){var c=n[r];try{typeof c.handleEvent=="function"?c.handleEvent(e):c.call(this,e)}catch(o){be(o)}}},ne.prototype.addEventListener=function(e,n){e=String(e);var i=this._listeners,r=i[e];r==null&&(r=[],i[e]=r);for(var c=!1,o=0;o<r.length;o+=1)r[o]===n&&(c=!0);c||r.push(n)},ne.prototype.removeEventListener=function(e,n){e=String(e);var i=this._listeners,r=i[e];if(r!=null){for(var c=[],o=0;o<r.length;o+=1)r[o]!==n&&c.push(r[o]);c.length===0?delete i[e]:i[e]=c}};function te(e){this.type=e,this.target=void 0}function he(e,n){te.call(this,e),this.data=n.data,this.lastEventId=n.lastEventId}he.prototype=Object.create(te.prototype);function f(e,n){te.call(this,e),this.status=n.status,this.statusText=n.statusText,this.headers=n.headers}f.prototype=Object.create(te.prototype);function d(e,n){te.call(this,e),this.error=n.error}d.prototype=Object.create(te.prototype);var g=-1,h=0,L=1,S=2,T=-1,C=0,z=1,oe=2,pe=3,Se=/^text\/event\-stream(;.*)?$/i,Je=1e3,ze=18e6,xe=function(e,n){var i=e==null?n:parseInt(e,10);return i!==i&&(i=n),Me(i)},Me=function(e){return Math.min(Math.max(e,Je),ze)},se=function(e,n,i){try{typeof n=="function"&&n.call(e,i)}catch(r){be(r)}};function W(e,n){ne.call(this),n=n||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,Qe(this,e,n)}function We(){return s!=null&&"withCredentials"in s.prototype||N==null?new s:new N}var Ye=K!=null&&ue!=null&&"body"in ue.prototype;function Qe(e,n,i){n=String(n);var r=Boolean(i.withCredentials),c=i.lastEventIdQueryParameterName||"lastEventId",o=Me(1e3),v=xe(i.heartbeatTimeout,45e3),E="",p=o,y=!1,m=0,u=i.headers||{},w=i.Transport,Y=Ye&&w==null?void 0:new b(w!=null?new w:We()),ge=w!=null&&typeof w!="string"?new w:Y==null?new we:new Ee,B=void 0,k=0,G=g,fe="",Te="",Q="",Ce="",P=C,Ve=0,ae=0,Ze=function(D,I,X,q){if(G===h)if(D===200&&X!=null&&Se.test(X)){G=L,y=Date.now(),p=o,e.readyState=L;var j=new f("open",{status:D,statusText:I,headers:q});e.dispatchEvent(j),se(e,e.onopen,j)}else{var x="";D!==200?(I&&(I=I.replace(/\s+/g," ")),x="EventSource's response has a status "+D+" "+I+" that is not 200. Aborting the connection."):x="EventSource's response has a Content-Type specifying an unsupported type: "+(X==null?"-":X.replace(/\s+/g," "))+". Aborting the connection.",He();var j=new f("error",{status:D,statusText:I,headers:q});e.dispatchEvent(j),se(e,e.onerror,j),console.error(x)}},et=function(D){if(G===L){for(var I=-1,X=0;X<D.length;X+=1){var q=D.charCodeAt(X);(q===` | ||
`.charCodeAt(0)||q==="\r".charCodeAt(0))&&(I=X)}var j=(I!==-1?Ce:"")+D.slice(0,I+1);Ce=(I===-1?Ce:"")+D.slice(I+1),D!==""&&(y=Date.now(),m+=D.length);for(var x=0;x<j.length;x+=1){var q=j.charCodeAt(x);if(P===T&&q===` | ||
`.charCodeAt(0))P=C;else if(P===T&&(P=C),q==="\r".charCodeAt(0)||q===` | ||
`.charCodeAt(0)){if(P!==C){P===z&&(ae=F+1);var Z=j.slice(Ve,ae-1),ee=j.slice(ae+(ae<F&&j.charCodeAt(ae)===" ".charCodeAt(0)?1:0),F);Z==="data"?(fe+=` | ||
`,fe+=ee):Z==="id"?Te=ee:Z==="event"?Q=ee:Z==="retry"?(o=xe(ee,o),p=o):Z==="heartbeatTimeout"&&(v=xe(ee,v),k!==0&&(l(k),k=a(function(){ye()},v)))}if(P===C){if(fe!==""){E=Te,Q===""&&(Q="message");var de=new he(Q,{data:fe.slice(1),lastEventId:Te});if(e.dispatchEvent(de),Q==="open"?se(e,e.onopen,de):Q==="message"?se(e,e.onmessage,de):Q==="error"&&se(e,e.onerror,de),G===S)return}fe="",Q=""}P=q==="\r".charCodeAt(0)?T:C}else P===C&&(Ve=F,P=z),P===z?q===":".charCodeAt(0)&&(ae=F+1,P=oe):P===oe&&(P=pe)}}},je=function(D){if(G===L||G===h)G=g,k!==0&&(l(k),k=0),k=a(function(){ye()},p),p=Me(Math.min(o*16,p*2)),e.readyState=h;else if(G===S&&D!=null){console.error(D);var I=new d("error",{error:D});e.dispatchEvent(I),se(e,e.onerror,I)}},He=function(){G=S,B!=null&&(B.abort(),B=void 0),k!==0&&(l(k),k=0),e.readyState=S},ye=function(){if(k=0,G!==g){if(!y&&B!=null)je(new Error("No activity within "+v+" milliseconds. "+(G===h?"No response received.":m+" chars received.")+" Reconnecting.")),B!=null&&(B.abort(),B=void 0);else{var D=Math.max((y||Date.now())+v-Date.now(),1);y=!1,k=a(function(){ye()},D)}return}y=!1,m=0,k=a(function(){ye()},v),G=h,fe="",Q="",Te=E,Ce="",Ve=0,ae=0,P=C;var I=n;if(n.slice(0,5)!=="data:"&&n.slice(0,5)!=="blob:"&&E!==""){var X=n.indexOf("?");I=X===-1?n:n.slice(0,X+1)+n.slice(X+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(ee,de){return de===c?"":ee}),I+=(n.indexOf("?")===-1?"?":"&")+c+"="+encodeURIComponent(E)}var q=e.withCredentials,j={};j.Accept="text/event-stream";var F=e.headers;if(F!=null)for(var Z in F)Object.prototype.hasOwnProperty.call(F,Z)&&(j[Z]=F[Z]);try{B=ge.open(Y,Ze,et,je,I,q,j)}catch(ee){throw He(),ee}};e.url=n,e.readyState=h,e.withCredentials=r,e.headers=u,e._close=He,ye()}W.prototype=Object.create(ne.prototype),W.prototype.CONNECTING=h,W.prototype.OPEN=L,W.prototype.CLOSED=S,W.prototype.close=function(){this._close()},W.CONNECTING=h,W.OPEN=L,W.CLOSED=S,W.prototype.withCredentials=void 0;var Pe=V;s!=null&&(V==null||!("withCredentials"in V.prototype))&&(Pe=W),function(e){if(typeof Oe=="object"&&typeof Oe.exports=="object"){var n=e(ke);n!==void 0&&(Oe.exports=n)}else typeof define=="function"&&define.amd?define(["exports"],e):e(t)}(function(e){e.EventSourcePolyfill=W,e.NativeEventSource=V,e.EventSource=Pe})})(typeof globalThis=="undefined"?typeof window!="undefined"?window:typeof self!="undefined"?self:ke:globalThis)});var vt={};ft(vt,{Event:()=>U,initialize:()=>Ke});function Le(t){this.message=t}Le.prototype=new Error,Le.prototype.name="InvalidCharacterError";var Ue=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(t){var a=String(t).replace(/=+$/,"");if(a.length%4==1)throw new Le("'atob' failed: The string to be decoded is not correctly encoded.");for(var l,s,x=0,A=0,V="";s=a.charAt(A++);~s&&(l=x%4?64*l+s:s,x++%4)?V+=String.fromCharCode(255&l>>(-2*x&6)):0)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(s);return V};function ut(t){var a=t.replace(/-/g,"+").replace(/_/g,"/");switch(a.length%4){case 0:break;case 2:a+="==";break;case 3:a+="=";break;default:throw"Illegal base64url string!"}try{return function(l){return decodeURIComponent(Ue(l).replace(/(.)/g,function(s,x){var A=x.charCodeAt(0).toString(16).toUpperCase();return A.length<2&&(A="0"+A),"%"+A}))}(a)}catch(l){return Ue(a)}}function Ae(t){this.message=t}function lt(t,a){if(typeof t!="string")throw new Ae("Invalid token specified");var l=(a=a||{}).header===!0?0:1;try{return JSON.parse(ut(t.split(".")[l]))}catch(s){throw new Ae("Invalid token specified: "+s.message)}}Ae.prototype=new Error,Ae.prototype.name="InvalidTokenError";var $e=lt;function Be(t){return{all:t=t||new Map,on:function(a,l){var s=t.get(a);s&&s.push(l)||t.set(a,[l])},off:function(a,l){var s=t.get(a);s&&s.splice(s.indexOf(l)>>>0,1)},emit:function(a,l){(t.get(a)||[]).slice().map(function(s){s(l)}),(t.get("*")||[]).slice().map(function(s){s(a,l)})}}}var Ge=ct(Xe());var U;(function(t){t.READY="ready",t.CONNECTED="connected",t.DISCONNECTED="disconnected",t.RECONNECTED="reconnected",t.CHANGED="changed",t.ERROR="error"})(U||(U={}));var qe={debug:!1,baseUrl:"https://config.ff.harness.io/api/1.0",eventUrl:"https://events.ff.harness.io/api/1.0",streamEnabled:!0,allAttributesPrivate:!1,privateAttributeNames:[]},ce=(t,...a)=>console.error(`[FF-SDK] ${t}`,...a),De=30*1e3;var ht="1.4.3",pt=500,Ne=globalThis.fetch,gt=Ge.EventSourcePolyfill,me=!!globalThis.Proxy,_e=t=>{let{value:a}=t;try{switch(t.kind.toLowerCase()){case"int":case"number":a=Number(a);break;case"boolean":a=a.toString().toLowerCase()==="true";break;case"json":a=JSON.parse(a);break}}catch(l){ce(l)}return a},Ke=(t,a,l)=>{let s,x,A,V,N,O=!0,K=()=>{O=!1},ue=()=>{O=!0},R=[],_=Be(),J=ie(ie({},qe),l),M=(f,...d)=>{J.debug&&console.debug(`[FF-SDK] ${f}`,...d)},re=f=>{if(O){let d=Date.now();d-f.lastAccessed>pt&&(f.count++,f.lastAccessed=d)}};globalThis.onbeforeunload=()=>{R.length&&globalThis.localStorage&&(K(),globalThis.localStorage.HARNESS_FF_METRICS=JSON.stringify(R),ue())};let Fe=(f,d)=>Ie(void 0,null,function*(){return(yield(yield Ne(`${d.baseUrl}/client/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:f,target:a})})).json()).authToken}),H=()=>{if(R.length){M("Sending metrics...",{metrics:R,evaluations:b});let f={metricsData:R.map(d=>({timestamp:Date.now(),count:d.count,metricsType:"FFMETRICS",attributes:[{key:"featureIdentifier",value:d.featureIdentifier},{key:"featureName",value:d.featureIdentifier},{key:"variationIdentifier",value:d.variationIdentifier},{key:"target",value:a.identifier},{key:"SDK_NAME",value:"JavaScript"},{key:"SDK_TYPE",value:"client"},{key:"SDK_VERSION",value:ht}]}))};Ne(`${J.eventUrl}/metrics/${s}?cluster=${x}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${V}`},body:JSON.stringify(f)}).then(()=>{R=[]}).catch(d=>{M(d)}).finally(()=>{N=window.setTimeout(H,De)})}else N=window.setTimeout(H,De)},b={},le=function(){return me?new Proxy({},{get(f,d){var h,L,S;let g=f[d];if(f.hasOwnProperty(d)){let T=f[d],C=R.find(z=>z.featureIdentifier===d&&T===z.featureValue);C?(C.variationIdentifier=((h=b[d])==null?void 0:h.identifier)||"",re(C)):R.push({featureIdentifier:d,featureValue:T,variationIdentifier:((L=b[d])==null?void 0:L.identifier)||"",count:O?1:0,lastAccessed:Date.now()}),M("Metrics event: Flag:",d,"has been read with value:",T,"variationIdentifier:",(S=b[d])==null?void 0:S.identifier)}return g}}):{}},$=le();Fe(t,J).then(f=>{V=f;let d=$e(f);if(M("Authenticated",d),globalThis.localStorage&&globalThis.localStorage.HARNESS_FF_METRICS)try{delete globalThis.localStorage.HARNESS_FF_METRICS,M("Picking up metrics from previous session")}catch(g){}N=window.setTimeout(H,De),s=d.environment,x=d.clusterIdentifier,Ee().then(()=>{M("Fetch all flags ok",$)}).then(()=>{we()}).then(()=>{M("Event stream ready",{storage:$}),_.emit(U.READY,$),me||Object.keys($).forEach(g=>{var h;R.push({featureIdentifier:g,featureValue:$[g],variationIdentifier:((h=b[g])==null?void 0:h.identifier)||"",count:O?1:0,lastAccessed:Date.now()})})}).catch(g=>{_.emit(U.ERROR,g)})}).catch(f=>{ce("Authentication error: ",f),_.emit(U.ERROR,f)});let Ee=()=>Ie(void 0,null,function*(){try{(yield(yield Ne(`${J.baseUrl}/client/env/${s}/target/${a.identifier}/evaluations?cluster=${x}`,{headers:{Authorization:`Bearer ${V}`}})).json()).forEach(g=>{let h=_e(g);$[g.flag]=h,b[g.flag]=ie(ie({},g),{value:h})})}catch(f){return ce("Features fetch operation error: ",f),_.emit(U.ERROR,f),f}}),ve=f=>Ie(void 0,null,function*(){var d;try{let g=yield Ne(`${J.baseUrl}/client/env/${s}/target/${a.identifier}/evaluations/${f}?cluster=${x}`,{headers:{Authorization:`Bearer ${V}`}});if(g.ok){let h=yield g.json(),L=_e(h);if(K(),$[f]=L,b[f]=ie(ie({},h),{value:L}),ue(),_.emit(U.CHANGED,me?new Proxy(h,{get(S,T){var C;if(S.hasOwnProperty(T)&&T==="value"){let z=S.flag,oe=h.value,pe=R.find(Se=>Se.featureIdentifier===z&&Se.featureValue===oe);pe?(re(pe),pe.variationIdentifier=((C=b[z])==null?void 0:C.identifier)||""):R.push({featureIdentifier:z,featureValue:String(oe),variationIdentifier:b[z].identifier||"",count:O?1:0,lastAccessed:Date.now()}),M("Metrics event: Flag",T,"has been read with value via stream update",oe)}return T==="value"?_e(h):h[T]}}):{deleted:h.deleted,flag:h.flag,value:_e(h)}),!me){let S=h.flag,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===h.value);T?(re(T),T.variationIdentifier=((d=b[S])==null?void 0:d.identifier)||""):R.push({featureIdentifier:S,featureValue:String(h.value),variationIdentifier:b[S].identifier||"",count:O?1:0,lastAccessed:Date.now()})}}else _.emit(U.ERROR,g)}catch(g){ce("Feature fetch operation error: ",g),_.emit(U.ERROR,g)}}),we=()=>{if(!J.streamEnabled){M("Stream is disabled by configuration. Note: Polling is not yet supported");return}A=new gt(`${J.baseUrl}/stream`,{headers:{Authorization:`Bearer ${V}`,"API-Key":t}}),A.onopen=f=>{M("Stream connected",f),_.emit(U.CONNECTED)},A.onclose=f=>{M("Stream disconnected"),_.emit(U.DISCONNECTED)},A.onerror=f=>{ce("Stream has issue",f),_.emit("error",f)},A.addEventListener("*",f=>{let d=JSON.parse(f.data);switch(M("Received event from stream: ",d),d.event){case"create":setTimeout(()=>ve(d.identifier),1e3);break;case"patch":ve(d.identifier);break;case"delete":delete $[d.identifier],_.emit(U.CHANGED,{flag:d.identifier,value:void 0,deleted:!0}),M("Evaluation deleted",{message:d,storage:$});break}})},ne=(f,d)=>_.on(f,d),be=(f,d)=>{f?_.off(f,d):he()},te=(f,d)=>{var h;let g=$[f];if(!me&&g!==void 0){let L=g,S=f,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===L);T?(re(T),T.variationIdentifier=((h=b[S])==null?void 0:h.identifier)||""):R.push({featureIdentifier:S,featureValue:L,count:O?1:0,variationIdentifier:b[S].identifier||"",lastAccessed:Date.now()})}return g!==void 0?g:d},he=()=>{M("Closing event stream"),$=le(),b={},clearTimeout(N),_.all.clear(),A.close()};return{on:ne,off:be,variation:te,close:he}};return vt;})(); | ||
`.charCodeAt(0)){if(P!==C){P===z&&(ae=x+1);var Z=j.slice(Ve,ae-1),ee=j.slice(ae+(ae<x&&j.charCodeAt(ae)===" ".charCodeAt(0)?1:0),x);Z==="data"?(fe+=` | ||
`,fe+=ee):Z==="id"?Te=ee:Z==="event"?Q=ee:Z==="retry"?(o=xe(ee,o),p=o):Z==="heartbeatTimeout"&&(v=xe(ee,v),k!==0&&(l(k),k=a(function(){ye()},v)))}if(P===C){if(fe!==""){E=Te,Q===""&&(Q="message");var de=new he(Q,{data:fe.slice(1),lastEventId:Te});if(e.dispatchEvent(de),Q==="open"?se(e,e.onopen,de):Q==="message"?se(e,e.onmessage,de):Q==="error"&&se(e,e.onerror,de),G===S)return}fe="",Q=""}P=q==="\r".charCodeAt(0)?T:C}else P===C&&(Ve=x,P=z),P===z?q===":".charCodeAt(0)&&(ae=x+1,P=oe):P===oe&&(P=pe)}}},je=function(D){if(G===L||G===h)G=g,k!==0&&(l(k),k=0),k=a(function(){ye()},p),p=Me(Math.min(o*16,p*2)),e.readyState=h;else if(G===S&&D!=null){console.error(D);var I=new d("error",{error:D});e.dispatchEvent(I),se(e,e.onerror,I)}},He=function(){G=S,B!=null&&(B.abort(),B=void 0),k!==0&&(l(k),k=0),e.readyState=S},ye=function(){if(k=0,G!==g){if(!y&&B!=null)je(new Error("No activity within "+v+" milliseconds. "+(G===h?"No response received.":m+" chars received.")+" Reconnecting.")),B!=null&&(B.abort(),B=void 0);else{var D=Math.max((y||Date.now())+v-Date.now(),1);y=!1,k=a(function(){ye()},D)}return}y=!1,m=0,k=a(function(){ye()},v),G=h,fe="",Q="",Te=E,Ce="",Ve=0,ae=0,P=C;var I=n;if(n.slice(0,5)!=="data:"&&n.slice(0,5)!=="blob:"&&E!==""){var X=n.indexOf("?");I=X===-1?n:n.slice(0,X+1)+n.slice(X+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(ee,de){return de===c?"":ee}),I+=(n.indexOf("?")===-1?"?":"&")+c+"="+encodeURIComponent(E)}var q=e.withCredentials,j={};j.Accept="text/event-stream";var x=e.headers;if(x!=null)for(var Z in x)Object.prototype.hasOwnProperty.call(x,Z)&&(j[Z]=x[Z]);try{B=ge.open(Y,Ze,et,je,I,q,j)}catch(ee){throw He(),ee}};e.url=n,e.readyState=h,e.withCredentials=r,e.headers=u,e._close=He,ye()}W.prototype=Object.create(ne.prototype),W.prototype.CONNECTING=h,W.prototype.OPEN=L,W.prototype.CLOSED=S,W.prototype.close=function(){this._close()},W.CONNECTING=h,W.OPEN=L,W.CLOSED=S,W.prototype.withCredentials=void 0;var Pe=V;s!=null&&(V==null||!("withCredentials"in V.prototype))&&(Pe=W),function(e){if(typeof Oe=="object"&&typeof Oe.exports=="object"){var n=e(ke);n!==void 0&&(Oe.exports=n)}else typeof define=="function"&&define.amd?define(["exports"],e):e(t)}(function(e){e.EventSourcePolyfill=W,e.NativeEventSource=V,e.EventSource=Pe})})(typeof globalThis=="undefined"?typeof window!="undefined"?window:typeof self!="undefined"?self:ke:globalThis)});var vt={};ft(vt,{Event:()=>U,initialize:()=>Ke});function Le(t){this.message=t}Le.prototype=new Error,Le.prototype.name="InvalidCharacterError";var Ue=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(t){var a=String(t).replace(/=+$/,"");if(a.length%4==1)throw new Le("'atob' failed: The string to be decoded is not correctly encoded.");for(var l,s,N=0,A=0,V="";s=a.charAt(A++);~s&&(l=N%4?64*l+s:s,N++%4)?V+=String.fromCharCode(255&l>>(-2*N&6)):0)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(s);return V};function ut(t){var a=t.replace(/-/g,"+").replace(/_/g,"/");switch(a.length%4){case 0:break;case 2:a+="==";break;case 3:a+="=";break;default:throw"Illegal base64url string!"}try{return function(l){return decodeURIComponent(Ue(l).replace(/(.)/g,function(s,N){var A=N.charCodeAt(0).toString(16).toUpperCase();return A.length<2&&(A="0"+A),"%"+A}))}(a)}catch(l){return Ue(a)}}function Ae(t){this.message=t}function lt(t,a){if(typeof t!="string")throw new Ae("Invalid token specified");var l=(a=a||{}).header===!0?0:1;try{return JSON.parse(ut(t.split(".")[l]))}catch(s){throw new Ae("Invalid token specified: "+s.message)}}Ae.prototype=new Error,Ae.prototype.name="InvalidTokenError";var $e=lt;function Be(t){return{all:t=t||new Map,on:function(a,l){var s=t.get(a);s&&s.push(l)||t.set(a,[l])},off:function(a,l){var s=t.get(a);s&&s.splice(s.indexOf(l)>>>0,1)},emit:function(a,l){(t.get(a)||[]).slice().map(function(s){s(l)}),(t.get("*")||[]).slice().map(function(s){s(a,l)})}}}var Ge=ct(Xe());var U;(function(t){t.READY="ready",t.CONNECTED="connected",t.DISCONNECTED="disconnected",t.RECONNECTED="reconnected",t.CHANGED="changed",t.ERROR="error"})(U||(U={}));var qe={debug:!1,baseUrl:"https://config.ff.harness.io/api/1.0",eventUrl:"https://events.ff.harness.io/api/1.0",streamEnabled:!0,allAttributesPrivate:!1,privateAttributeNames:[]},ce=(t,...a)=>console.error(`[FF-SDK] ${t}`,...a),De=30*1e3;var ht="1.4.4",pt=500,Ne=globalThis.fetch,gt=Ge.EventSourcePolyfill,me=!!globalThis.Proxy,_e=t=>{let{value:a}=t;try{switch(t.kind.toLowerCase()){case"int":case"number":a=Number(a);break;case"boolean":a=a.toString().toLowerCase()==="true";break;case"json":a=JSON.parse(a);break}}catch(l){ce(l)}return a},Ke=(t,a,l)=>{let s,N,A,V,_,O=!0,K=()=>{O=!1},ue=()=>{O=!0},R=[],F=Be(),J=ie(ie({},qe),l),M=(f,...d)=>{J.debug&&console.debug(`[FF-SDK] ${f}`,...d)},re=f=>{if(O){let d=Date.now();d-f.lastAccessed>pt&&(f.count++,f.lastAccessed=d)}};globalThis.onbeforeunload=()=>{R.length&&globalThis.localStorage&&(K(),globalThis.localStorage.HARNESS_FF_METRICS=JSON.stringify(R),ue())};let Fe=(f,d)=>Ie(void 0,null,function*(){return(yield(yield Ne(`${d.baseUrl}/client/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:f,target:a})})).json()).authToken}),H=()=>{if(R.length){M("Sending metrics...",{metrics:R,evaluations:b});let f={metricsData:R.map(d=>({timestamp:Date.now(),count:d.count,metricsType:"FFMETRICS",attributes:[{key:"featureIdentifier",value:d.featureIdentifier},{key:"featureName",value:d.featureIdentifier},{key:"variationIdentifier",value:d.variationIdentifier},{key:"target",value:a.identifier},{key:"SDK_NAME",value:"JavaScript"},{key:"SDK_TYPE",value:"client"},{key:"SDK_VERSION",value:ht}]}))};Ne(`${J.eventUrl}/metrics/${s}?cluster=${N}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${V}`},body:JSON.stringify(f)}).then(()=>{R=[]}).catch(d=>{M(d)}).finally(()=>{_=window.setTimeout(H,De)})}else _=window.setTimeout(H,De)},b={},le=function(){return me?new Proxy({},{get(f,d){var h,L,S;let g=f[d];if(f.hasOwnProperty(d)){let T=f[d],C=R.find(z=>z.featureIdentifier===d&&T===z.featureValue);C?(C.variationIdentifier=((h=b[d])==null?void 0:h.identifier)||"",re(C)):R.push({featureIdentifier:d,featureValue:T,variationIdentifier:((L=b[d])==null?void 0:L.identifier)||"",count:O?1:0,lastAccessed:Date.now()}),M("Metrics event: Flag:",d,"has been read with value:",T,"variationIdentifier:",(S=b[d])==null?void 0:S.identifier)}return g}}):{}},$=le();Fe(t,J).then(f=>{V=f;let d=$e(f);if(M("Authenticated",d),globalThis.localStorage&&globalThis.localStorage.HARNESS_FF_METRICS)try{delete globalThis.localStorage.HARNESS_FF_METRICS,M("Picking up metrics from previous session")}catch(g){}_=window.setTimeout(H,De),s=d.environment,N=d.clusterIdentifier,Ee().then(()=>{M("Fetch all flags ok",$)}).then(()=>{we()}).then(()=>{M("Event stream ready",{storage:$}),F.emit(U.READY,$),me||Object.keys($).forEach(g=>{var h;R.push({featureIdentifier:g,featureValue:$[g],variationIdentifier:((h=b[g])==null?void 0:h.identifier)||"",count:O?1:0,lastAccessed:Date.now()})})}).catch(g=>{F.emit(U.ERROR,g)})}).catch(f=>{ce("Authentication error: ",f),F.emit(U.ERROR,f)});let Ee=()=>Ie(void 0,null,function*(){try{(yield(yield Ne(`${J.baseUrl}/client/env/${s}/target/${a.identifier}/evaluations?cluster=${N}`,{headers:{Authorization:`Bearer ${V}`}})).json()).forEach(g=>{let h=_e(g);$[g.flag]=h,b[g.flag]=ie(ie({},g),{value:h})})}catch(f){return ce("Features fetch operation error: ",f),F.emit(U.ERROR,f),f}}),ve=f=>Ie(void 0,null,function*(){var d;try{let g=yield Ne(`${J.baseUrl}/client/env/${s}/target/${a.identifier}/evaluations/${f}?cluster=${N}`,{headers:{Authorization:`Bearer ${V}`}});if(g.ok){let h=yield g.json(),L=_e(h);if(K(),$[f]=L,b[f]=ie(ie({},h),{value:L}),ue(),F.emit(U.CHANGED,me?new Proxy(h,{get(S,T){var C;if(S.hasOwnProperty(T)&&T==="value"){let z=S.flag,oe=h.value,pe=R.find(Se=>Se.featureIdentifier===z&&Se.featureValue===oe);pe?(re(pe),pe.variationIdentifier=((C=b[z])==null?void 0:C.identifier)||""):R.push({featureIdentifier:z,featureValue:String(oe),variationIdentifier:b[z].identifier||"",count:O?1:0,lastAccessed:Date.now()}),M("Metrics event: Flag",T,"has been read with value via stream update",oe)}return T==="value"?_e(h):h[T]}}):{deleted:h.deleted,flag:h.flag,value:_e(h)}),!me){let S=h.flag,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===h.value);T?(re(T),T.variationIdentifier=((d=b[S])==null?void 0:d.identifier)||""):R.push({featureIdentifier:S,featureValue:String(h.value),variationIdentifier:b[S].identifier||"",count:O?1:0,lastAccessed:Date.now()})}}else F.emit(U.ERROR,g)}catch(g){ce("Feature fetch operation error: ",g),F.emit(U.ERROR,g)}}),we=()=>{if(!J.streamEnabled){M("Stream is disabled by configuration. Note: Polling is not yet supported");return}A=new gt(`${J.baseUrl}/stream?cluster=${N}`,{headers:{Authorization:`Bearer ${V}`,"API-Key":t}}),A.onopen=f=>{M("Stream connected",f),F.emit(U.CONNECTED)},A.onclose=f=>{M("Stream disconnected"),F.emit(U.DISCONNECTED)},A.onerror=f=>{ce("Stream has issue",f),F.emit("error",f)},A.addEventListener("*",f=>{let d=JSON.parse(f.data);switch(M("Received event from stream: ",d),d.event){case"create":setTimeout(()=>ve(d.identifier),1e3);break;case"patch":ve(d.identifier);break;case"delete":delete $[d.identifier],F.emit(U.CHANGED,{flag:d.identifier,value:void 0,deleted:!0}),M("Evaluation deleted",{message:d,storage:$});break}})},ne=(f,d)=>F.on(f,d),be=(f,d)=>{f?F.off(f,d):he()},te=(f,d)=>{var h;let g=$[f];if(!me&&g!==void 0){let L=g,S=f,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===L);T?(re(T),T.variationIdentifier=((h=b[S])==null?void 0:h.identifier)||""):R.push({featureIdentifier:S,featureValue:L,count:O?1:0,variationIdentifier:b[S].identifier||"",lastAccessed:Date.now()})}return g!==void 0?g:d},he=()=>{M("Closing event stream"),$=le(),b={},clearTimeout(_),F.all.clear(),A.close()};return{on:ne,off:be,variation:te,close:he}};return vt;})(); | ||
/** @license | ||
@@ -8,0 +8,0 @@ * eventsource.js |
@@ -1,7 +0,7 @@ | ||
var et=Object.create,He=Object.defineProperty,tt=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty,nt=Object.getOwnPropertyNames,at=Object.getOwnPropertyDescriptor;var ie=Object.assign,it=r=>He(r,"__esModule",{value:!0});var ot=(r,i)=>()=>(i||(i={exports:{}},r(i.exports,i)),i.exports);var st=(r,i,v)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of nt(i))!rt.call(r,s)&&s!=="default"&&He(r,s,{get:()=>i[s],enumerable:!(v=at(i,s))||v.enumerable});return r},ft=r=>st(it(He(r!=null?et(tt(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var Re=(r,i,v)=>new Promise((s,x)=>{var A=O=>{try{N(v.next(O))}catch(K){x(K)}},V=O=>{try{N(v.throw(O))}catch(K){x(K)}},N=O=>O.done?s(O.value):Promise.resolve(O.value).then(A,V);N((v=v.apply(r,i)).next())});var Xe=ot((ke,Ae)=>{(function(r){"use strict";var i=r.setTimeout,v=r.clearTimeout,s=r.XMLHttpRequest,x=r.XDomainRequest,A=r.ActiveXObject,V=r.EventSource,N=r.document,O=r.Promise,K=r.fetch,ue=r.Response,R=r.TextDecoder,_=r.TextEncoder,J=r.AbortController;if(typeof window!="undefined"&&typeof N!="undefined"&&!("readyState"in N)&&N.body==null&&(N.readyState="loading",window.addEventListener("load",function(e){N.readyState="complete"},!1)),s==null&&A!=null&&(s=function(){return new A("Microsoft.XMLHTTP")}),Object.create==null&&(Object.create=function(e){function n(){}return n.prototype=e,new n}),Date.now||(Date.now=function(){return new Date().getTime()}),J==null){var M=K;K=function(e,n){var a=n.signal;return M(e,{headers:n.headers,credentials:n.credentials,cache:n.cache}).then(function(t){var c=t.body.getReader();return a._reader=c,a._aborted&&a._reader.cancel(),{status:t.status,statusText:t.statusText,headers:t.headers,body:{getReader:function(){return c}}}})},J=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){this.signal._reader!=null&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function re(){this.bitsNeeded=0,this.codePoint=0}re.prototype.decode=function(e){function n(y,m,u){if(u===1)return y>=128>>m&&y<<m<=2047;if(u===2)return y>=2048>>m&&y<<m<=55295||y>=57344>>m&&y<<m<=65535;if(u===3)return y>=65536>>m&&y<<m<=1114111;throw new Error}function a(y,m){if(y===6*1)return m>>6>15?3:m>31?2:1;if(y===6*2)return m>15?3:2;if(y===6*3)return 3;throw new Error}for(var t=65533,c="",o=this.bitsNeeded,l=this.codePoint,E=0;E<e.length;E+=1){var p=e[E];o!==0&&(p<128||p>191||!n(l<<6|p&63,o-6,a(o,l)))&&(o=0,l=t,c+=String.fromCharCode(l)),o===0?(p>=0&&p<=127?(o=0,l=p):p>=192&&p<=223?(o=6*1,l=p&31):p>=224&&p<=239?(o=6*2,l=p&15):p>=240&&p<=247?(o=6*3,l=p&7):(o=0,l=t),o!==0&&!n(l,o,a(o,l))&&(o=0,l=t)):(o-=6,l=l<<6|p&63),o===0&&(l<=65535?c+=String.fromCharCode(l):(c+=String.fromCharCode(55296+(l-65535-1>>10)),c+=String.fromCharCode(56320+(l-65535-1&1023))))}return this.bitsNeeded=o,this.codePoint=l,c};var _e=function(){try{return new R().decode(new _().encode("test"),{stream:!0})==="test"}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1};(R==null||_==null||!_e())&&(R=re);var H=function(){};function b(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=H,this.onload=H,this.onerror=H,this.onreadystatechange=H,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=H}b.prototype.open=function(e,n){this._abort(!0);var a=this,t=this._xhr,c=1,o=0;this._abort=function(u){a._sendTimeout!==0&&(v(a._sendTimeout),a._sendTimeout=0),(c===1||c===2||c===3)&&(c=4,t.onload=H,t.onerror=H,t.onabort=H,t.onprogress=H,t.onreadystatechange=H,t.abort(),o!==0&&(v(o),o=0),u||(a.readyState=4,a.onabort(null),a.onreadystatechange())),c=0};var l=function(){if(c===1){var u=0,w="",Y=void 0;if("contentType"in t)u=200,w="OK",Y=t.contentType;else try{u=t.status,w=t.statusText,Y=t.getResponseHeader("Content-Type")}catch(ge){u=0,w="",Y=void 0}u!==0&&(c=2,a.readyState=2,a.status=u,a.statusText=w,a._contentType=Y,a.onreadystatechange())}},E=function(){if(l(),c===2||c===3){c=3;var u="";try{u=t.responseText}catch(w){}a.readyState=3,a.responseText=u,a.onprogress()}},p=function(u,w){if((w==null||w.preventDefault==null)&&(w={preventDefault:H}),E(),c===1||c===2||c===3){if(c=4,o!==0&&(v(o),o=0),a.readyState=4,u==="load")a.onload(w);else if(u==="error")a.onerror(w);else if(u==="abort")a.onabort(w);else throw new TypeError;a.onreadystatechange()}},y=function(u){t!=null&&(t.readyState===4?(!("onload"in t)||!("onerror"in t)||!("onabort"in t))&&p(t.responseText===""?"error":"load",u):t.readyState===3?"onprogress"in t||E():t.readyState===2&&l())},m=function(){o=i(function(){m()},500),t.readyState===3&&E()};"onload"in t&&(t.onload=function(u){p("load",u)}),"onerror"in t&&(t.onerror=function(u){p("error",u)}),"onabort"in t&&(t.onabort=function(u){p("abort",u)}),"onprogress"in t&&(t.onprogress=E),"onreadystatechange"in t&&(t.onreadystatechange=function(u){y(u)}),("contentType"in t||!("ontimeout"in s.prototype))&&(n+=(n.indexOf("?")===-1?"?":"&")+"padding=true"),t.open(e,n,!0),"readyState"in t&&(o=i(function(){m()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(e){return this._contentType},b.prototype.setRequestHeader=function(e,n){var a=this._xhr;"setRequestHeader"in a&&a.setRequestHeader(e,n)},b.prototype.getAllResponseHeaders=function(){return this._xhr.getAllResponseHeaders!=null&&this._xhr.getAllResponseHeaders()||""},b.prototype.send=function(){if((!("ontimeout"in s.prototype)||!("sendAsBinary"in s.prototype)&&!("mozAnon"in s.prototype))&&N!=null&&N.readyState!=null&&N.readyState!=="complete"){var e=this;e._sendTimeout=i(function(){e._sendTimeout=0,e.send()},4);return}var n=this._xhr;"withCredentials"in n&&(n.withCredentials=this.withCredentials);try{n.send(void 0)}catch(a){throw a}};function le(e){return e.replace(/[A-Z]/g,function(n){return String.fromCharCode(n.charCodeAt(0)+32)})}function U(e){for(var n=Object.create(null),a=e.split(`\r | ||
`),t=0;t<a.length;t+=1){var c=a[t],o=c.split(": "),l=o.shift(),E=o.join(": ");n[le(l)]=E}this._map=n}U.prototype.get=function(e){return this._map[le(e)]},s!=null&&s.HEADERS_RECEIVED==null&&(s.HEADERS_RECEIVED=2);function Ee(){}Ee.prototype.open=function(e,n,a,t,c,o,l){e.open("GET",c);var E=0;e.onprogress=function(){var y=e.responseText,m=y.slice(E);E+=m.length,a(m)},e.onerror=function(y){y.preventDefault(),t(new Error("NetworkError"))},e.onload=function(){t(null)},e.onabort=function(){t(null)},e.onreadystatechange=function(){if(e.readyState===s.HEADERS_RECEIVED){var y=e.status,m=e.statusText,u=e.getResponseHeader("Content-Type"),w=e.getAllResponseHeaders();n(y,m,u,new U(w))}},e.withCredentials=o;for(var p in l)Object.prototype.hasOwnProperty.call(l,p)&&e.setRequestHeader(p,l[p]);return e.send(),e};function ve(e){this._headers=e}ve.prototype.get=function(e){return this._headers.get(e)};function we(){}we.prototype.open=function(e,n,a,t,c,o,l){var E=null,p=new J,y=p.signal,m=new R;return K(c,{headers:l,credentials:o?"include":"same-origin",signal:y,cache:"no-store"}).then(function(u){return E=u.body.getReader(),n(u.status,u.statusText,u.headers.get("Content-Type"),new ve(u.headers)),new O(function(w,Y){var ge=function(){E.read().then(function(B){if(B.done)w(void 0);else{var k=m.decode(B.value,{stream:!0});a(k),ge()}}).catch(function(B){Y(B)})};ge()})}).catch(function(u){if(u.name!=="AbortError")return u}).then(function(u){t(u)}),{abort:function(){E!=null&&E.cancel(),p.abort()}}};function ne(){this._listeners=Object.create(null)}function be(e){i(function(){throw e},0)}ne.prototype.dispatchEvent=function(e){e.target=this;var n=this._listeners[e.type];if(n!=null)for(var a=n.length,t=0;t<a;t+=1){var c=n[t];try{typeof c.handleEvent=="function"?c.handleEvent(e):c.call(this,e)}catch(o){be(o)}}},ne.prototype.addEventListener=function(e,n){e=String(e);var a=this._listeners,t=a[e];t==null&&(t=[],a[e]=t);for(var c=!1,o=0;o<t.length;o+=1)t[o]===n&&(c=!0);c||t.push(n)},ne.prototype.removeEventListener=function(e,n){e=String(e);var a=this._listeners,t=a[e];if(t!=null){for(var c=[],o=0;o<t.length;o+=1)t[o]!==n&&c.push(t[o]);c.length===0?delete a[e]:a[e]=c}};function te(e){this.type=e,this.target=void 0}function he(e,n){te.call(this,e),this.data=n.data,this.lastEventId=n.lastEventId}he.prototype=Object.create(te.prototype);function f(e,n){te.call(this,e),this.status=n.status,this.statusText=n.statusText,this.headers=n.headers}f.prototype=Object.create(te.prototype);function d(e,n){te.call(this,e),this.error=n.error}d.prototype=Object.create(te.prototype);var g=-1,h=0,L=1,S=2,T=-1,C=0,z=1,oe=2,pe=3,Se=/^text\/event\-stream(;.*)?$/i,Ke=1e3,Je=18e6,Fe=function(e,n){var a=e==null?n:parseInt(e,10);return a!==a&&(a=n),xe(a)},xe=function(e){return Math.min(Math.max(e,Ke),Je)},se=function(e,n,a){try{typeof n=="function"&&n.call(e,a)}catch(t){be(t)}};function W(e,n){ne.call(this),n=n||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,Ye(this,e,n)}function ze(){return s!=null&&"withCredentials"in s.prototype||x==null?new s:new x}var We=K!=null&&ue!=null&&"body"in ue.prototype;function Ye(e,n,a){n=String(n);var t=Boolean(a.withCredentials),c=a.lastEventIdQueryParameterName||"lastEventId",o=xe(1e3),l=Fe(a.heartbeatTimeout,45e3),E="",p=o,y=!1,m=0,u=a.headers||{},w=a.Transport,Y=We&&w==null?void 0:new b(w!=null?new w:ze()),ge=w!=null&&typeof w!="string"?new w:Y==null?new we:new Ee,B=void 0,k=0,G=g,fe="",Te="",Q="",Ce="",P=C,Me=0,ae=0,Qe=function(D,I,X,q){if(G===h)if(D===200&&X!=null&&Se.test(X)){G=L,y=Date.now(),p=o,e.readyState=L;var j=new f("open",{status:D,statusText:I,headers:q});e.dispatchEvent(j),se(e,e.onopen,j)}else{var F="";D!==200?(I&&(I=I.replace(/\s+/g," ")),F="EventSource's response has a status "+D+" "+I+" that is not 200. Aborting the connection."):F="EventSource's response has a Content-Type specifying an unsupported type: "+(X==null?"-":X.replace(/\s+/g," "))+". Aborting the connection.",Ve();var j=new f("error",{status:D,statusText:I,headers:q});e.dispatchEvent(j),se(e,e.onerror,j),console.error(F)}},Ze=function(D){if(G===L){for(var I=-1,X=0;X<D.length;X+=1){var q=D.charCodeAt(X);(q===` | ||
`.charCodeAt(0)||q==="\r".charCodeAt(0))&&(I=X)}var j=(I!==-1?Ce:"")+D.slice(0,I+1);Ce=(I===-1?Ce:"")+D.slice(I+1),D!==""&&(y=Date.now(),m+=D.length);for(var F=0;F<j.length;F+=1){var q=j.charCodeAt(F);if(P===T&&q===` | ||
var et=Object.create,He=Object.defineProperty,tt=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty,nt=Object.getOwnPropertyNames,at=Object.getOwnPropertyDescriptor;var ie=Object.assign,it=r=>He(r,"__esModule",{value:!0});var ot=(r,i)=>()=>(i||(i={exports:{}},r(i.exports,i)),i.exports);var st=(r,i,v)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of nt(i))!rt.call(r,s)&&s!=="default"&&He(r,s,{get:()=>i[s],enumerable:!(v=at(i,s))||v.enumerable});return r},ft=r=>st(it(He(r!=null?et(tt(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var Re=(r,i,v)=>new Promise((s,N)=>{var A=O=>{try{_(v.next(O))}catch(K){N(K)}},V=O=>{try{_(v.throw(O))}catch(K){N(K)}},_=O=>O.done?s(O.value):Promise.resolve(O.value).then(A,V);_((v=v.apply(r,i)).next())});var Xe=ot((ke,Ae)=>{(function(r){"use strict";var i=r.setTimeout,v=r.clearTimeout,s=r.XMLHttpRequest,N=r.XDomainRequest,A=r.ActiveXObject,V=r.EventSource,_=r.document,O=r.Promise,K=r.fetch,ue=r.Response,R=r.TextDecoder,F=r.TextEncoder,J=r.AbortController;if(typeof window!="undefined"&&typeof _!="undefined"&&!("readyState"in _)&&_.body==null&&(_.readyState="loading",window.addEventListener("load",function(e){_.readyState="complete"},!1)),s==null&&A!=null&&(s=function(){return new A("Microsoft.XMLHTTP")}),Object.create==null&&(Object.create=function(e){function n(){}return n.prototype=e,new n}),Date.now||(Date.now=function(){return new Date().getTime()}),J==null){var M=K;K=function(e,n){var a=n.signal;return M(e,{headers:n.headers,credentials:n.credentials,cache:n.cache}).then(function(t){var c=t.body.getReader();return a._reader=c,a._aborted&&a._reader.cancel(),{status:t.status,statusText:t.statusText,headers:t.headers,body:{getReader:function(){return c}}}})},J=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){this.signal._reader!=null&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function re(){this.bitsNeeded=0,this.codePoint=0}re.prototype.decode=function(e){function n(y,m,u){if(u===1)return y>=128>>m&&y<<m<=2047;if(u===2)return y>=2048>>m&&y<<m<=55295||y>=57344>>m&&y<<m<=65535;if(u===3)return y>=65536>>m&&y<<m<=1114111;throw new Error}function a(y,m){if(y===6*1)return m>>6>15?3:m>31?2:1;if(y===6*2)return m>15?3:2;if(y===6*3)return 3;throw new Error}for(var t=65533,c="",o=this.bitsNeeded,l=this.codePoint,E=0;E<e.length;E+=1){var p=e[E];o!==0&&(p<128||p>191||!n(l<<6|p&63,o-6,a(o,l)))&&(o=0,l=t,c+=String.fromCharCode(l)),o===0?(p>=0&&p<=127?(o=0,l=p):p>=192&&p<=223?(o=6*1,l=p&31):p>=224&&p<=239?(o=6*2,l=p&15):p>=240&&p<=247?(o=6*3,l=p&7):(o=0,l=t),o!==0&&!n(l,o,a(o,l))&&(o=0,l=t)):(o-=6,l=l<<6|p&63),o===0&&(l<=65535?c+=String.fromCharCode(l):(c+=String.fromCharCode(55296+(l-65535-1>>10)),c+=String.fromCharCode(56320+(l-65535-1&1023))))}return this.bitsNeeded=o,this.codePoint=l,c};var _e=function(){try{return new R().decode(new F().encode("test"),{stream:!0})==="test"}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1};(R==null||F==null||!_e())&&(R=re);var H=function(){};function b(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=H,this.onload=H,this.onerror=H,this.onreadystatechange=H,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=H}b.prototype.open=function(e,n){this._abort(!0);var a=this,t=this._xhr,c=1,o=0;this._abort=function(u){a._sendTimeout!==0&&(v(a._sendTimeout),a._sendTimeout=0),(c===1||c===2||c===3)&&(c=4,t.onload=H,t.onerror=H,t.onabort=H,t.onprogress=H,t.onreadystatechange=H,t.abort(),o!==0&&(v(o),o=0),u||(a.readyState=4,a.onabort(null),a.onreadystatechange())),c=0};var l=function(){if(c===1){var u=0,w="",Y=void 0;if("contentType"in t)u=200,w="OK",Y=t.contentType;else try{u=t.status,w=t.statusText,Y=t.getResponseHeader("Content-Type")}catch(ge){u=0,w="",Y=void 0}u!==0&&(c=2,a.readyState=2,a.status=u,a.statusText=w,a._contentType=Y,a.onreadystatechange())}},E=function(){if(l(),c===2||c===3){c=3;var u="";try{u=t.responseText}catch(w){}a.readyState=3,a.responseText=u,a.onprogress()}},p=function(u,w){if((w==null||w.preventDefault==null)&&(w={preventDefault:H}),E(),c===1||c===2||c===3){if(c=4,o!==0&&(v(o),o=0),a.readyState=4,u==="load")a.onload(w);else if(u==="error")a.onerror(w);else if(u==="abort")a.onabort(w);else throw new TypeError;a.onreadystatechange()}},y=function(u){t!=null&&(t.readyState===4?(!("onload"in t)||!("onerror"in t)||!("onabort"in t))&&p(t.responseText===""?"error":"load",u):t.readyState===3?"onprogress"in t||E():t.readyState===2&&l())},m=function(){o=i(function(){m()},500),t.readyState===3&&E()};"onload"in t&&(t.onload=function(u){p("load",u)}),"onerror"in t&&(t.onerror=function(u){p("error",u)}),"onabort"in t&&(t.onabort=function(u){p("abort",u)}),"onprogress"in t&&(t.onprogress=E),"onreadystatechange"in t&&(t.onreadystatechange=function(u){y(u)}),("contentType"in t||!("ontimeout"in s.prototype))&&(n+=(n.indexOf("?")===-1?"?":"&")+"padding=true"),t.open(e,n,!0),"readyState"in t&&(o=i(function(){m()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(e){return this._contentType},b.prototype.setRequestHeader=function(e,n){var a=this._xhr;"setRequestHeader"in a&&a.setRequestHeader(e,n)},b.prototype.getAllResponseHeaders=function(){return this._xhr.getAllResponseHeaders!=null&&this._xhr.getAllResponseHeaders()||""},b.prototype.send=function(){if((!("ontimeout"in s.prototype)||!("sendAsBinary"in s.prototype)&&!("mozAnon"in s.prototype))&&_!=null&&_.readyState!=null&&_.readyState!=="complete"){var e=this;e._sendTimeout=i(function(){e._sendTimeout=0,e.send()},4);return}var n=this._xhr;"withCredentials"in n&&(n.withCredentials=this.withCredentials);try{n.send(void 0)}catch(a){throw a}};function le(e){return e.replace(/[A-Z]/g,function(n){return String.fromCharCode(n.charCodeAt(0)+32)})}function U(e){for(var n=Object.create(null),a=e.split(`\r | ||
`),t=0;t<a.length;t+=1){var c=a[t],o=c.split(": "),l=o.shift(),E=o.join(": ");n[le(l)]=E}this._map=n}U.prototype.get=function(e){return this._map[le(e)]},s!=null&&s.HEADERS_RECEIVED==null&&(s.HEADERS_RECEIVED=2);function Ee(){}Ee.prototype.open=function(e,n,a,t,c,o,l){e.open("GET",c);var E=0;e.onprogress=function(){var y=e.responseText,m=y.slice(E);E+=m.length,a(m)},e.onerror=function(y){y.preventDefault(),t(new Error("NetworkError"))},e.onload=function(){t(null)},e.onabort=function(){t(null)},e.onreadystatechange=function(){if(e.readyState===s.HEADERS_RECEIVED){var y=e.status,m=e.statusText,u=e.getResponseHeader("Content-Type"),w=e.getAllResponseHeaders();n(y,m,u,new U(w))}},e.withCredentials=o;for(var p in l)Object.prototype.hasOwnProperty.call(l,p)&&e.setRequestHeader(p,l[p]);return e.send(),e};function ve(e){this._headers=e}ve.prototype.get=function(e){return this._headers.get(e)};function we(){}we.prototype.open=function(e,n,a,t,c,o,l){var E=null,p=new J,y=p.signal,m=new R;return K(c,{headers:l,credentials:o?"include":"same-origin",signal:y,cache:"no-store"}).then(function(u){return E=u.body.getReader(),n(u.status,u.statusText,u.headers.get("Content-Type"),new ve(u.headers)),new O(function(w,Y){var ge=function(){E.read().then(function(B){if(B.done)w(void 0);else{var k=m.decode(B.value,{stream:!0});a(k),ge()}}).catch(function(B){Y(B)})};ge()})}).catch(function(u){if(u.name!=="AbortError")return u}).then(function(u){t(u)}),{abort:function(){E!=null&&E.cancel(),p.abort()}}};function ne(){this._listeners=Object.create(null)}function be(e){i(function(){throw e},0)}ne.prototype.dispatchEvent=function(e){e.target=this;var n=this._listeners[e.type];if(n!=null)for(var a=n.length,t=0;t<a;t+=1){var c=n[t];try{typeof c.handleEvent=="function"?c.handleEvent(e):c.call(this,e)}catch(o){be(o)}}},ne.prototype.addEventListener=function(e,n){e=String(e);var a=this._listeners,t=a[e];t==null&&(t=[],a[e]=t);for(var c=!1,o=0;o<t.length;o+=1)t[o]===n&&(c=!0);c||t.push(n)},ne.prototype.removeEventListener=function(e,n){e=String(e);var a=this._listeners,t=a[e];if(t!=null){for(var c=[],o=0;o<t.length;o+=1)t[o]!==n&&c.push(t[o]);c.length===0?delete a[e]:a[e]=c}};function te(e){this.type=e,this.target=void 0}function he(e,n){te.call(this,e),this.data=n.data,this.lastEventId=n.lastEventId}he.prototype=Object.create(te.prototype);function f(e,n){te.call(this,e),this.status=n.status,this.statusText=n.statusText,this.headers=n.headers}f.prototype=Object.create(te.prototype);function d(e,n){te.call(this,e),this.error=n.error}d.prototype=Object.create(te.prototype);var g=-1,h=0,L=1,S=2,T=-1,C=0,z=1,oe=2,pe=3,Se=/^text\/event\-stream(;.*)?$/i,Ke=1e3,Je=18e6,Fe=function(e,n){var a=e==null?n:parseInt(e,10);return a!==a&&(a=n),xe(a)},xe=function(e){return Math.min(Math.max(e,Ke),Je)},se=function(e,n,a){try{typeof n=="function"&&n.call(e,a)}catch(t){be(t)}};function W(e,n){ne.call(this),n=n||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,Ye(this,e,n)}function ze(){return s!=null&&"withCredentials"in s.prototype||N==null?new s:new N}var We=K!=null&&ue!=null&&"body"in ue.prototype;function Ye(e,n,a){n=String(n);var t=Boolean(a.withCredentials),c=a.lastEventIdQueryParameterName||"lastEventId",o=xe(1e3),l=Fe(a.heartbeatTimeout,45e3),E="",p=o,y=!1,m=0,u=a.headers||{},w=a.Transport,Y=We&&w==null?void 0:new b(w!=null?new w:ze()),ge=w!=null&&typeof w!="string"?new w:Y==null?new we:new Ee,B=void 0,k=0,G=g,fe="",Te="",Q="",Ce="",P=C,Me=0,ae=0,Qe=function(D,I,X,q){if(G===h)if(D===200&&X!=null&&Se.test(X)){G=L,y=Date.now(),p=o,e.readyState=L;var j=new f("open",{status:D,statusText:I,headers:q});e.dispatchEvent(j),se(e,e.onopen,j)}else{var x="";D!==200?(I&&(I=I.replace(/\s+/g," ")),x="EventSource's response has a status "+D+" "+I+" that is not 200. Aborting the connection."):x="EventSource's response has a Content-Type specifying an unsupported type: "+(X==null?"-":X.replace(/\s+/g," "))+". Aborting the connection.",Ve();var j=new f("error",{status:D,statusText:I,headers:q});e.dispatchEvent(j),se(e,e.onerror,j),console.error(x)}},Ze=function(D){if(G===L){for(var I=-1,X=0;X<D.length;X+=1){var q=D.charCodeAt(X);(q===` | ||
`.charCodeAt(0)||q==="\r".charCodeAt(0))&&(I=X)}var j=(I!==-1?Ce:"")+D.slice(0,I+1);Ce=(I===-1?Ce:"")+D.slice(I+1),D!==""&&(y=Date.now(),m+=D.length);for(var x=0;x<j.length;x+=1){var q=j.charCodeAt(x);if(P===T&&q===` | ||
`.charCodeAt(0))P=C;else if(P===T&&(P=C),q==="\r".charCodeAt(0)||q===` | ||
`.charCodeAt(0)){if(P!==C){P===z&&(ae=F+1);var Z=j.slice(Me,ae-1),ee=j.slice(ae+(ae<F&&j.charCodeAt(ae)===" ".charCodeAt(0)?1:0),F);Z==="data"?(fe+=` | ||
`,fe+=ee):Z==="id"?Te=ee:Z==="event"?Q=ee:Z==="retry"?(o=Fe(ee,o),p=o):Z==="heartbeatTimeout"&&(l=Fe(ee,l),k!==0&&(v(k),k=i(function(){ye()},l)))}if(P===C){if(fe!==""){E=Te,Q===""&&(Q="message");var de=new he(Q,{data:fe.slice(1),lastEventId:Te});if(e.dispatchEvent(de),Q==="open"?se(e,e.onopen,de):Q==="message"?se(e,e.onmessage,de):Q==="error"&&se(e,e.onerror,de),G===S)return}fe="",Q=""}P=q==="\r".charCodeAt(0)?T:C}else P===C&&(Me=F,P=z),P===z?q===":".charCodeAt(0)&&(ae=F+1,P=oe):P===oe&&(P=pe)}}},je=function(D){if(G===L||G===h)G=g,k!==0&&(v(k),k=0),k=i(function(){ye()},p),p=xe(Math.min(o*16,p*2)),e.readyState=h;else if(G===S&&D!=null){console.error(D);var I=new d("error",{error:D});e.dispatchEvent(I),se(e,e.onerror,I)}},Ve=function(){G=S,B!=null&&(B.abort(),B=void 0),k!==0&&(v(k),k=0),e.readyState=S},ye=function(){if(k=0,G!==g){if(!y&&B!=null)je(new Error("No activity within "+l+" milliseconds. "+(G===h?"No response received.":m+" chars received.")+" Reconnecting.")),B!=null&&(B.abort(),B=void 0);else{var D=Math.max((y||Date.now())+l-Date.now(),1);y=!1,k=i(function(){ye()},D)}return}y=!1,m=0,k=i(function(){ye()},l),G=h,fe="",Q="",Te=E,Ce="",Me=0,ae=0,P=C;var I=n;if(n.slice(0,5)!=="data:"&&n.slice(0,5)!=="blob:"&&E!==""){var X=n.indexOf("?");I=X===-1?n:n.slice(0,X+1)+n.slice(X+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(ee,de){return de===c?"":ee}),I+=(n.indexOf("?")===-1?"?":"&")+c+"="+encodeURIComponent(E)}var q=e.withCredentials,j={};j.Accept="text/event-stream";var F=e.headers;if(F!=null)for(var Z in F)Object.prototype.hasOwnProperty.call(F,Z)&&(j[Z]=F[Z]);try{B=ge.open(Y,Qe,Ze,je,I,q,j)}catch(ee){throw Ve(),ee}};e.url=n,e.readyState=h,e.withCredentials=t,e.headers=u,e._close=Ve,ye()}W.prototype=Object.create(ne.prototype),W.prototype.CONNECTING=h,W.prototype.OPEN=L,W.prototype.CLOSED=S,W.prototype.close=function(){this._close()},W.CONNECTING=h,W.OPEN=L,W.CLOSED=S,W.prototype.withCredentials=void 0;var Pe=V;s!=null&&(V==null||!("withCredentials"in V.prototype))&&(Pe=W),function(e){if(typeof Ae=="object"&&typeof Ae.exports=="object"){var n=e(ke);n!==void 0&&(Ae.exports=n)}else typeof define=="function"&&define.amd?define(["exports"],e):e(r)}(function(e){e.EventSourcePolyfill=W,e.NativeEventSource=V,e.EventSource=Pe})})(typeof globalThis=="undefined"?typeof window!="undefined"?window:typeof self!="undefined"?self:ke:globalThis)});function Le(r){this.message=r}Le.prototype=new Error,Le.prototype.name="InvalidCharacterError";var Ue=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(r){var i=String(r).replace(/=+$/,"");if(i.length%4==1)throw new Le("'atob' failed: The string to be decoded is not correctly encoded.");for(var v,s,x=0,A=0,V="";s=i.charAt(A++);~s&&(v=x%4?64*v+s:s,x++%4)?V+=String.fromCharCode(255&v>>(-2*x&6)):0)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(s);return V};function dt(r){var i=r.replace(/-/g,"+").replace(/_/g,"/");switch(i.length%4){case 0:break;case 2:i+="==";break;case 3:i+="=";break;default:throw"Illegal base64url string!"}try{return function(v){return decodeURIComponent(Ue(v).replace(/(.)/g,function(s,x){var A=x.charCodeAt(0).toString(16).toUpperCase();return A.length<2&&(A="0"+A),"%"+A}))}(i)}catch(v){return Ue(i)}}function Ie(r){this.message=r}function ct(r,i){if(typeof r!="string")throw new Ie("Invalid token specified");var v=(i=i||{}).header===!0?0:1;try{return JSON.parse(dt(r.split(".")[v]))}catch(s){throw new Ie("Invalid token specified: "+s.message)}}Ie.prototype=new Error,Ie.prototype.name="InvalidTokenError";var $e=ct;function Be(r){return{all:r=r||new Map,on:function(i,v){var s=r.get(i);s&&s.push(v)||r.set(i,[v])},off:function(i,v){var s=r.get(i);s&&s.splice(s.indexOf(v)>>>0,1)},emit:function(i,v){(r.get(i)||[]).slice().map(function(s){s(v)}),(r.get("*")||[]).slice().map(function(s){s(i,v)})}}}var Ge=ft(Xe());var $;(function(r){r.READY="ready",r.CONNECTED="connected",r.DISCONNECTED="disconnected",r.RECONNECTED="reconnected",r.CHANGED="changed",r.ERROR="error"})($||($={}));var qe={debug:!1,baseUrl:"https://config.ff.harness.io/api/1.0",eventUrl:"https://events.ff.harness.io/api/1.0",streamEnabled:!0,allAttributesPrivate:!1,privateAttributeNames:[]},ce=(r,...i)=>console.error(`[FF-SDK] ${r}`,...i),Oe=30*1e3;var ut="1.4.3",lt=500,De=globalThis.fetch,vt=Ge.EventSourcePolyfill,me=!!globalThis.Proxy,Ne=r=>{let{value:i}=r;try{switch(r.kind.toLowerCase()){case"int":case"number":i=Number(i);break;case"boolean":i=i.toString().toLowerCase()==="true";break;case"json":i=JSON.parse(i);break}}catch(v){ce(v)}return i},ht=(r,i,v)=>{let s,x,A,V,N,O=!0,K=()=>{O=!1},ue=()=>{O=!0},R=[],_=Be(),J=ie(ie({},qe),v),M=(f,...d)=>{J.debug&&console.debug(`[FF-SDK] ${f}`,...d)},re=f=>{if(O){let d=Date.now();d-f.lastAccessed>lt&&(f.count++,f.lastAccessed=d)}};globalThis.onbeforeunload=()=>{R.length&&globalThis.localStorage&&(K(),globalThis.localStorage.HARNESS_FF_METRICS=JSON.stringify(R),ue())};let _e=(f,d)=>Re(void 0,null,function*(){return(yield(yield De(`${d.baseUrl}/client/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:f,target:i})})).json()).authToken}),H=()=>{if(R.length){M("Sending metrics...",{metrics:R,evaluations:b});let f={metricsData:R.map(d=>({timestamp:Date.now(),count:d.count,metricsType:"FFMETRICS",attributes:[{key:"featureIdentifier",value:d.featureIdentifier},{key:"featureName",value:d.featureIdentifier},{key:"variationIdentifier",value:d.variationIdentifier},{key:"target",value:i.identifier},{key:"SDK_NAME",value:"JavaScript"},{key:"SDK_TYPE",value:"client"},{key:"SDK_VERSION",value:ut}]}))};De(`${J.eventUrl}/metrics/${s}?cluster=${x}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${V}`},body:JSON.stringify(f)}).then(()=>{R=[]}).catch(d=>{M(d)}).finally(()=>{N=window.setTimeout(H,Oe)})}else N=window.setTimeout(H,Oe)},b={},le=function(){return me?new Proxy({},{get(f,d){var h,L,S;let g=f[d];if(f.hasOwnProperty(d)){let T=f[d],C=R.find(z=>z.featureIdentifier===d&&T===z.featureValue);C?(C.variationIdentifier=((h=b[d])==null?void 0:h.identifier)||"",re(C)):R.push({featureIdentifier:d,featureValue:T,variationIdentifier:((L=b[d])==null?void 0:L.identifier)||"",count:O?1:0,lastAccessed:Date.now()}),M("Metrics event: Flag:",d,"has been read with value:",T,"variationIdentifier:",(S=b[d])==null?void 0:S.identifier)}return g}}):{}},U=le();_e(r,J).then(f=>{V=f;let d=$e(f);if(M("Authenticated",d),globalThis.localStorage&&globalThis.localStorage.HARNESS_FF_METRICS)try{delete globalThis.localStorage.HARNESS_FF_METRICS,M("Picking up metrics from previous session")}catch(g){}N=window.setTimeout(H,Oe),s=d.environment,x=d.clusterIdentifier,Ee().then(()=>{M("Fetch all flags ok",U)}).then(()=>{we()}).then(()=>{M("Event stream ready",{storage:U}),_.emit($.READY,U),me||Object.keys(U).forEach(g=>{var h;R.push({featureIdentifier:g,featureValue:U[g],variationIdentifier:((h=b[g])==null?void 0:h.identifier)||"",count:O?1:0,lastAccessed:Date.now()})})}).catch(g=>{_.emit($.ERROR,g)})}).catch(f=>{ce("Authentication error: ",f),_.emit($.ERROR,f)});let Ee=()=>Re(void 0,null,function*(){try{(yield(yield De(`${J.baseUrl}/client/env/${s}/target/${i.identifier}/evaluations?cluster=${x}`,{headers:{Authorization:`Bearer ${V}`}})).json()).forEach(g=>{let h=Ne(g);U[g.flag]=h,b[g.flag]=ie(ie({},g),{value:h})})}catch(f){return ce("Features fetch operation error: ",f),_.emit($.ERROR,f),f}}),ve=f=>Re(void 0,null,function*(){var d;try{let g=yield De(`${J.baseUrl}/client/env/${s}/target/${i.identifier}/evaluations/${f}?cluster=${x}`,{headers:{Authorization:`Bearer ${V}`}});if(g.ok){let h=yield g.json(),L=Ne(h);if(K(),U[f]=L,b[f]=ie(ie({},h),{value:L}),ue(),_.emit($.CHANGED,me?new Proxy(h,{get(S,T){var C;if(S.hasOwnProperty(T)&&T==="value"){let z=S.flag,oe=h.value,pe=R.find(Se=>Se.featureIdentifier===z&&Se.featureValue===oe);pe?(re(pe),pe.variationIdentifier=((C=b[z])==null?void 0:C.identifier)||""):R.push({featureIdentifier:z,featureValue:String(oe),variationIdentifier:b[z].identifier||"",count:O?1:0,lastAccessed:Date.now()}),M("Metrics event: Flag",T,"has been read with value via stream update",oe)}return T==="value"?Ne(h):h[T]}}):{deleted:h.deleted,flag:h.flag,value:Ne(h)}),!me){let S=h.flag,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===h.value);T?(re(T),T.variationIdentifier=((d=b[S])==null?void 0:d.identifier)||""):R.push({featureIdentifier:S,featureValue:String(h.value),variationIdentifier:b[S].identifier||"",count:O?1:0,lastAccessed:Date.now()})}}else _.emit($.ERROR,g)}catch(g){ce("Feature fetch operation error: ",g),_.emit($.ERROR,g)}}),we=()=>{if(!J.streamEnabled){M("Stream is disabled by configuration. Note: Polling is not yet supported");return}A=new vt(`${J.baseUrl}/stream`,{headers:{Authorization:`Bearer ${V}`,"API-Key":r}}),A.onopen=f=>{M("Stream connected",f),_.emit($.CONNECTED)},A.onclose=f=>{M("Stream disconnected"),_.emit($.DISCONNECTED)},A.onerror=f=>{ce("Stream has issue",f),_.emit("error",f)},A.addEventListener("*",f=>{let d=JSON.parse(f.data);switch(M("Received event from stream: ",d),d.event){case"create":setTimeout(()=>ve(d.identifier),1e3);break;case"patch":ve(d.identifier);break;case"delete":delete U[d.identifier],_.emit($.CHANGED,{flag:d.identifier,value:void 0,deleted:!0}),M("Evaluation deleted",{message:d,storage:U});break}})},ne=(f,d)=>_.on(f,d),be=(f,d)=>{f?_.off(f,d):he()},te=(f,d)=>{var h;let g=U[f];if(!me&&g!==void 0){let L=g,S=f,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===L);T?(re(T),T.variationIdentifier=((h=b[S])==null?void 0:h.identifier)||""):R.push({featureIdentifier:S,featureValue:L,count:O?1:0,variationIdentifier:b[S].identifier||"",lastAccessed:Date.now()})}return g!==void 0?g:d},he=()=>{M("Closing event stream"),U=le(),b={},clearTimeout(N),_.all.clear(),A.close()};return{on:ne,off:be,variation:te,close:he}};export{$ as Event,ht as initialize}; | ||
`.charCodeAt(0)){if(P!==C){P===z&&(ae=x+1);var Z=j.slice(Me,ae-1),ee=j.slice(ae+(ae<x&&j.charCodeAt(ae)===" ".charCodeAt(0)?1:0),x);Z==="data"?(fe+=` | ||
`,fe+=ee):Z==="id"?Te=ee:Z==="event"?Q=ee:Z==="retry"?(o=Fe(ee,o),p=o):Z==="heartbeatTimeout"&&(l=Fe(ee,l),k!==0&&(v(k),k=i(function(){ye()},l)))}if(P===C){if(fe!==""){E=Te,Q===""&&(Q="message");var de=new he(Q,{data:fe.slice(1),lastEventId:Te});if(e.dispatchEvent(de),Q==="open"?se(e,e.onopen,de):Q==="message"?se(e,e.onmessage,de):Q==="error"&&se(e,e.onerror,de),G===S)return}fe="",Q=""}P=q==="\r".charCodeAt(0)?T:C}else P===C&&(Me=x,P=z),P===z?q===":".charCodeAt(0)&&(ae=x+1,P=oe):P===oe&&(P=pe)}}},je=function(D){if(G===L||G===h)G=g,k!==0&&(v(k),k=0),k=i(function(){ye()},p),p=xe(Math.min(o*16,p*2)),e.readyState=h;else if(G===S&&D!=null){console.error(D);var I=new d("error",{error:D});e.dispatchEvent(I),se(e,e.onerror,I)}},Ve=function(){G=S,B!=null&&(B.abort(),B=void 0),k!==0&&(v(k),k=0),e.readyState=S},ye=function(){if(k=0,G!==g){if(!y&&B!=null)je(new Error("No activity within "+l+" milliseconds. "+(G===h?"No response received.":m+" chars received.")+" Reconnecting.")),B!=null&&(B.abort(),B=void 0);else{var D=Math.max((y||Date.now())+l-Date.now(),1);y=!1,k=i(function(){ye()},D)}return}y=!1,m=0,k=i(function(){ye()},l),G=h,fe="",Q="",Te=E,Ce="",Me=0,ae=0,P=C;var I=n;if(n.slice(0,5)!=="data:"&&n.slice(0,5)!=="blob:"&&E!==""){var X=n.indexOf("?");I=X===-1?n:n.slice(0,X+1)+n.slice(X+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(ee,de){return de===c?"":ee}),I+=(n.indexOf("?")===-1?"?":"&")+c+"="+encodeURIComponent(E)}var q=e.withCredentials,j={};j.Accept="text/event-stream";var x=e.headers;if(x!=null)for(var Z in x)Object.prototype.hasOwnProperty.call(x,Z)&&(j[Z]=x[Z]);try{B=ge.open(Y,Qe,Ze,je,I,q,j)}catch(ee){throw Ve(),ee}};e.url=n,e.readyState=h,e.withCredentials=t,e.headers=u,e._close=Ve,ye()}W.prototype=Object.create(ne.prototype),W.prototype.CONNECTING=h,W.prototype.OPEN=L,W.prototype.CLOSED=S,W.prototype.close=function(){this._close()},W.CONNECTING=h,W.OPEN=L,W.CLOSED=S,W.prototype.withCredentials=void 0;var Pe=V;s!=null&&(V==null||!("withCredentials"in V.prototype))&&(Pe=W),function(e){if(typeof Ae=="object"&&typeof Ae.exports=="object"){var n=e(ke);n!==void 0&&(Ae.exports=n)}else typeof define=="function"&&define.amd?define(["exports"],e):e(r)}(function(e){e.EventSourcePolyfill=W,e.NativeEventSource=V,e.EventSource=Pe})})(typeof globalThis=="undefined"?typeof window!="undefined"?window:typeof self!="undefined"?self:ke:globalThis)});function Le(r){this.message=r}Le.prototype=new Error,Le.prototype.name="InvalidCharacterError";var Ue=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(r){var i=String(r).replace(/=+$/,"");if(i.length%4==1)throw new Le("'atob' failed: The string to be decoded is not correctly encoded.");for(var v,s,N=0,A=0,V="";s=i.charAt(A++);~s&&(v=N%4?64*v+s:s,N++%4)?V+=String.fromCharCode(255&v>>(-2*N&6)):0)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(s);return V};function dt(r){var i=r.replace(/-/g,"+").replace(/_/g,"/");switch(i.length%4){case 0:break;case 2:i+="==";break;case 3:i+="=";break;default:throw"Illegal base64url string!"}try{return function(v){return decodeURIComponent(Ue(v).replace(/(.)/g,function(s,N){var A=N.charCodeAt(0).toString(16).toUpperCase();return A.length<2&&(A="0"+A),"%"+A}))}(i)}catch(v){return Ue(i)}}function Ie(r){this.message=r}function ct(r,i){if(typeof r!="string")throw new Ie("Invalid token specified");var v=(i=i||{}).header===!0?0:1;try{return JSON.parse(dt(r.split(".")[v]))}catch(s){throw new Ie("Invalid token specified: "+s.message)}}Ie.prototype=new Error,Ie.prototype.name="InvalidTokenError";var $e=ct;function Be(r){return{all:r=r||new Map,on:function(i,v){var s=r.get(i);s&&s.push(v)||r.set(i,[v])},off:function(i,v){var s=r.get(i);s&&s.splice(s.indexOf(v)>>>0,1)},emit:function(i,v){(r.get(i)||[]).slice().map(function(s){s(v)}),(r.get("*")||[]).slice().map(function(s){s(i,v)})}}}var Ge=ft(Xe());var $;(function(r){r.READY="ready",r.CONNECTED="connected",r.DISCONNECTED="disconnected",r.RECONNECTED="reconnected",r.CHANGED="changed",r.ERROR="error"})($||($={}));var qe={debug:!1,baseUrl:"https://config.ff.harness.io/api/1.0",eventUrl:"https://events.ff.harness.io/api/1.0",streamEnabled:!0,allAttributesPrivate:!1,privateAttributeNames:[]},ce=(r,...i)=>console.error(`[FF-SDK] ${r}`,...i),Oe=30*1e3;var ut="1.4.4",lt=500,De=globalThis.fetch,vt=Ge.EventSourcePolyfill,me=!!globalThis.Proxy,Ne=r=>{let{value:i}=r;try{switch(r.kind.toLowerCase()){case"int":case"number":i=Number(i);break;case"boolean":i=i.toString().toLowerCase()==="true";break;case"json":i=JSON.parse(i);break}}catch(v){ce(v)}return i},ht=(r,i,v)=>{let s,N,A,V,_,O=!0,K=()=>{O=!1},ue=()=>{O=!0},R=[],F=Be(),J=ie(ie({},qe),v),M=(f,...d)=>{J.debug&&console.debug(`[FF-SDK] ${f}`,...d)},re=f=>{if(O){let d=Date.now();d-f.lastAccessed>lt&&(f.count++,f.lastAccessed=d)}};globalThis.onbeforeunload=()=>{R.length&&globalThis.localStorage&&(K(),globalThis.localStorage.HARNESS_FF_METRICS=JSON.stringify(R),ue())};let _e=(f,d)=>Re(void 0,null,function*(){return(yield(yield De(`${d.baseUrl}/client/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:f,target:i})})).json()).authToken}),H=()=>{if(R.length){M("Sending metrics...",{metrics:R,evaluations:b});let f={metricsData:R.map(d=>({timestamp:Date.now(),count:d.count,metricsType:"FFMETRICS",attributes:[{key:"featureIdentifier",value:d.featureIdentifier},{key:"featureName",value:d.featureIdentifier},{key:"variationIdentifier",value:d.variationIdentifier},{key:"target",value:i.identifier},{key:"SDK_NAME",value:"JavaScript"},{key:"SDK_TYPE",value:"client"},{key:"SDK_VERSION",value:ut}]}))};De(`${J.eventUrl}/metrics/${s}?cluster=${N}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${V}`},body:JSON.stringify(f)}).then(()=>{R=[]}).catch(d=>{M(d)}).finally(()=>{_=window.setTimeout(H,Oe)})}else _=window.setTimeout(H,Oe)},b={},le=function(){return me?new Proxy({},{get(f,d){var h,L,S;let g=f[d];if(f.hasOwnProperty(d)){let T=f[d],C=R.find(z=>z.featureIdentifier===d&&T===z.featureValue);C?(C.variationIdentifier=((h=b[d])==null?void 0:h.identifier)||"",re(C)):R.push({featureIdentifier:d,featureValue:T,variationIdentifier:((L=b[d])==null?void 0:L.identifier)||"",count:O?1:0,lastAccessed:Date.now()}),M("Metrics event: Flag:",d,"has been read with value:",T,"variationIdentifier:",(S=b[d])==null?void 0:S.identifier)}return g}}):{}},U=le();_e(r,J).then(f=>{V=f;let d=$e(f);if(M("Authenticated",d),globalThis.localStorage&&globalThis.localStorage.HARNESS_FF_METRICS)try{delete globalThis.localStorage.HARNESS_FF_METRICS,M("Picking up metrics from previous session")}catch(g){}_=window.setTimeout(H,Oe),s=d.environment,N=d.clusterIdentifier,Ee().then(()=>{M("Fetch all flags ok",U)}).then(()=>{we()}).then(()=>{M("Event stream ready",{storage:U}),F.emit($.READY,U),me||Object.keys(U).forEach(g=>{var h;R.push({featureIdentifier:g,featureValue:U[g],variationIdentifier:((h=b[g])==null?void 0:h.identifier)||"",count:O?1:0,lastAccessed:Date.now()})})}).catch(g=>{F.emit($.ERROR,g)})}).catch(f=>{ce("Authentication error: ",f),F.emit($.ERROR,f)});let Ee=()=>Re(void 0,null,function*(){try{(yield(yield De(`${J.baseUrl}/client/env/${s}/target/${i.identifier}/evaluations?cluster=${N}`,{headers:{Authorization:`Bearer ${V}`}})).json()).forEach(g=>{let h=Ne(g);U[g.flag]=h,b[g.flag]=ie(ie({},g),{value:h})})}catch(f){return ce("Features fetch operation error: ",f),F.emit($.ERROR,f),f}}),ve=f=>Re(void 0,null,function*(){var d;try{let g=yield De(`${J.baseUrl}/client/env/${s}/target/${i.identifier}/evaluations/${f}?cluster=${N}`,{headers:{Authorization:`Bearer ${V}`}});if(g.ok){let h=yield g.json(),L=Ne(h);if(K(),U[f]=L,b[f]=ie(ie({},h),{value:L}),ue(),F.emit($.CHANGED,me?new Proxy(h,{get(S,T){var C;if(S.hasOwnProperty(T)&&T==="value"){let z=S.flag,oe=h.value,pe=R.find(Se=>Se.featureIdentifier===z&&Se.featureValue===oe);pe?(re(pe),pe.variationIdentifier=((C=b[z])==null?void 0:C.identifier)||""):R.push({featureIdentifier:z,featureValue:String(oe),variationIdentifier:b[z].identifier||"",count:O?1:0,lastAccessed:Date.now()}),M("Metrics event: Flag",T,"has been read with value via stream update",oe)}return T==="value"?Ne(h):h[T]}}):{deleted:h.deleted,flag:h.flag,value:Ne(h)}),!me){let S=h.flag,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===h.value);T?(re(T),T.variationIdentifier=((d=b[S])==null?void 0:d.identifier)||""):R.push({featureIdentifier:S,featureValue:String(h.value),variationIdentifier:b[S].identifier||"",count:O?1:0,lastAccessed:Date.now()})}}else F.emit($.ERROR,g)}catch(g){ce("Feature fetch operation error: ",g),F.emit($.ERROR,g)}}),we=()=>{if(!J.streamEnabled){M("Stream is disabled by configuration. Note: Polling is not yet supported");return}A=new vt(`${J.baseUrl}/stream?cluster=${N}`,{headers:{Authorization:`Bearer ${V}`,"API-Key":r}}),A.onopen=f=>{M("Stream connected",f),F.emit($.CONNECTED)},A.onclose=f=>{M("Stream disconnected"),F.emit($.DISCONNECTED)},A.onerror=f=>{ce("Stream has issue",f),F.emit("error",f)},A.addEventListener("*",f=>{let d=JSON.parse(f.data);switch(M("Received event from stream: ",d),d.event){case"create":setTimeout(()=>ve(d.identifier),1e3);break;case"patch":ve(d.identifier);break;case"delete":delete U[d.identifier],F.emit($.CHANGED,{flag:d.identifier,value:void 0,deleted:!0}),M("Evaluation deleted",{message:d,storage:U});break}})},ne=(f,d)=>F.on(f,d),be=(f,d)=>{f?F.off(f,d):he()},te=(f,d)=>{var h;let g=U[f];if(!me&&g!==void 0){let L=g,S=f,T=R.find(C=>C.featureIdentifier===S&&C.featureValue===L);T?(re(T),T.variationIdentifier=((h=b[S])==null?void 0:h.identifier)||""):R.push({featureIdentifier:S,featureValue:L,count:O?1:0,variationIdentifier:b[S].identifier||"",lastAccessed:Date.now()})}return g!==void 0?g:d},he=()=>{M("Closing event stream"),U=le(),b={},clearTimeout(_),F.all.clear(),A.close()};return{on:ne,off:be,variation:te,close:he}};export{$ as Event,ht as initialize}; | ||
/** @license | ||
@@ -8,0 +8,0 @@ * eventsource.js |
@@ -1,7 +0,7 @@ | ||
var Je=Object.create,Me=Object.defineProperty,We=Object.getPrototypeOf,Ye=Object.prototype.hasOwnProperty,Qe=Object.getOwnPropertyNames,Ze=Object.getOwnPropertyDescriptor;var ie=Object.assign,et=a=>Me(a,"__esModule",{value:!0});var tt=(a,c)=>()=>(c||(c={exports:{}},a(c.exports,c)),c.exports);var rt=(a,c,I)=>{if(c&&typeof c=="object"||typeof c=="function")for(let g of Qe(c))!Ye.call(a,g)&&g!=="default"&&Me(a,g,{get:()=>c[g],enumerable:!(I=Ze(c,g))||I.enumerable});return a},nt=a=>rt(et(Me(a!=null?Je(We(a)):{},"default",a&&a.__esModule&&"default"in a?{get:()=>a.default,enumerable:!0}:{value:a,enumerable:!0})),a);var Re=(a,c,I)=>new Promise((g,W)=>{var q=A=>{try{O(I.next(A))}catch(G){W(G)}},B=A=>{try{O(I.throw(A))}catch(G){W(G)}},O=A=>A.done?g(A.value):Promise.resolve(A.value).then(q,B);O((I=I.apply(a,c)).next())});var je=tt((He,Ie)=>{(function(a){"use strict";var c=a.setTimeout,I=a.clearTimeout,g=a.XMLHttpRequest,W=a.XDomainRequest,q=a.ActiveXObject,B=a.EventSource,O=a.document,A=a.Promise,G=a.fetch,ue=a.Response,C=a.TextDecoder,N=a.TextEncoder,K=a.AbortController;if(typeof window!="undefined"&&typeof O!="undefined"&&!("readyState"in O)&&O.body==null&&(O.readyState="loading",window.addEventListener("load",function(e){O.readyState="complete"},!1)),g==null&&q!=null&&(g=function(){return new q("Microsoft.XMLHTTP")}),Object.create==null&&(Object.create=function(e){function r(){}return r.prototype=e,new r}),Date.now||(Date.now=function(){return new Date().getTime()}),K==null){var F=G;G=function(e,r){var n=r.signal;return F(e,{headers:r.headers,credentials:r.credentials,cache:r.cache}).then(function(t){var f=t.body.getReader();return n._reader=f,n._aborted&&n._reader.cancel(),{status:t.status,statusText:t.statusText,headers:t.headers,body:{getReader:function(){return f}}}})},K=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){this.signal._reader!=null&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function re(){this.bitsNeeded=0,this.codePoint=0}re.prototype.decode=function(e){function r(p,y,d){if(d===1)return p>=128>>y&&p<<y<=2047;if(d===2)return p>=2048>>y&&p<<y<=55295||p>=57344>>y&&p<<y<=65535;if(d===3)return p>=65536>>y&&p<<y<=1114111;throw new Error}function n(p,y){if(p===6*1)return y>>6>15?3:y>31?2:1;if(p===6*2)return y>15?3:2;if(p===6*3)return 3;throw new Error}for(var t=65533,f="",i=this.bitsNeeded,u=this.codePoint,E=0;E<e.length;E+=1){var v=e[E];i!==0&&(v<128||v>191||!r(u<<6|v&63,i-6,n(i,u)))&&(i=0,u=t,f+=String.fromCharCode(u)),i===0?(v>=0&&v<=127?(i=0,u=v):v>=192&&v<=223?(i=6*1,u=v&31):v>=224&&v<=239?(i=6*2,u=v&15):v>=240&&v<=247?(i=6*3,u=v&7):(i=0,u=t),i!==0&&!r(u,i,n(i,u))&&(i=0,u=t)):(i-=6,u=u<<6|v&63),i===0&&(u<=65535?f+=String.fromCharCode(u):(f+=String.fromCharCode(55296+(u-65535-1>>10)),f+=String.fromCharCode(56320+(u-65535-1&1023))))}return this.bitsNeeded=i,this.codePoint=u,f};var Ne=function(){try{return new C().decode(new N().encode("test"),{stream:!0})==="test"}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1};(C==null||N==null||!Ne())&&(C=re);var x=function(){};function b(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=x,this.onload=x,this.onerror=x,this.onreadystatechange=x,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=x}b.prototype.open=function(e,r){this._abort(!0);var n=this,t=this._xhr,f=1,i=0;this._abort=function(d){n._sendTimeout!==0&&(I(n._sendTimeout),n._sendTimeout=0),(f===1||f===2||f===3)&&(f=4,t.onload=x,t.onerror=x,t.onabort=x,t.onprogress=x,t.onreadystatechange=x,t.abort(),i!==0&&(I(i),i=0),d||(n.readyState=4,n.onabort(null),n.onreadystatechange())),f=0};var u=function(){if(f===1){var d=0,m="",Y=void 0;if("contentType"in t)d=200,m="OK",Y=t.contentType;else try{d=t.status,m=t.statusText,Y=t.getResponseHeader("Content-Type")}catch(ge){d=0,m="",Y=void 0}d!==0&&(f=2,n.readyState=2,n.status=d,n.statusText=m,n._contentType=Y,n.onreadystatechange())}},E=function(){if(u(),f===2||f===3){f=3;var d="";try{d=t.responseText}catch(m){}n.readyState=3,n.responseText=d,n.onprogress()}},v=function(d,m){if((m==null||m.preventDefault==null)&&(m={preventDefault:x}),E(),f===1||f===2||f===3){if(f=4,i!==0&&(I(i),i=0),n.readyState=4,d==="load")n.onload(m);else if(d==="error")n.onerror(m);else if(d==="abort")n.onabort(m);else throw new TypeError;n.onreadystatechange()}},p=function(d){t!=null&&(t.readyState===4?(!("onload"in t)||!("onerror"in t)||!("onabort"in t))&&v(t.responseText===""?"error":"load",d):t.readyState===3?"onprogress"in t||E():t.readyState===2&&u())},y=function(){i=c(function(){y()},500),t.readyState===3&&E()};"onload"in t&&(t.onload=function(d){v("load",d)}),"onerror"in t&&(t.onerror=function(d){v("error",d)}),"onabort"in t&&(t.onabort=function(d){v("abort",d)}),"onprogress"in t&&(t.onprogress=E),"onreadystatechange"in t&&(t.onreadystatechange=function(d){p(d)}),("contentType"in t||!("ontimeout"in g.prototype))&&(r+=(r.indexOf("?")===-1?"?":"&")+"padding=true"),t.open(e,r,!0),"readyState"in t&&(i=c(function(){y()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(e){return this._contentType},b.prototype.setRequestHeader=function(e,r){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,r)},b.prototype.getAllResponseHeaders=function(){return this._xhr.getAllResponseHeaders!=null&&this._xhr.getAllResponseHeaders()||""},b.prototype.send=function(){if((!("ontimeout"in g.prototype)||!("sendAsBinary"in g.prototype)&&!("mozAnon"in g.prototype))&&O!=null&&O.readyState!=null&&O.readyState!=="complete"){var e=this;e._sendTimeout=c(function(){e._sendTimeout=0,e.send()},4);return}var r=this._xhr;"withCredentials"in r&&(r.withCredentials=this.withCredentials);try{r.send(void 0)}catch(n){throw n}};function le(e){return e.replace(/[A-Z]/g,function(r){return String.fromCharCode(r.charCodeAt(0)+32)})}function P(e){for(var r=Object.create(null),n=e.split(`\r | ||
`),t=0;t<n.length;t+=1){var f=n[t],i=f.split(": "),u=i.shift(),E=i.join(": ");r[le(u)]=E}this._map=r}P.prototype.get=function(e){return this._map[le(e)]},g!=null&&g.HEADERS_RECEIVED==null&&(g.HEADERS_RECEIVED=2);function me(){}me.prototype.open=function(e,r,n,t,f,i,u){e.open("GET",f);var E=0;e.onprogress=function(){var p=e.responseText,y=p.slice(E);E+=y.length,n(y)},e.onerror=function(p){p.preventDefault(),t(new Error("NetworkError"))},e.onload=function(){t(null)},e.onabort=function(){t(null)},e.onreadystatechange=function(){if(e.readyState===g.HEADERS_RECEIVED){var p=e.status,y=e.statusText,d=e.getResponseHeader("Content-Type"),m=e.getAllResponseHeaders();r(p,y,d,new P(m))}},e.withCredentials=i;for(var v in u)Object.prototype.hasOwnProperty.call(u,v)&&e.setRequestHeader(v,u[v]);return e.send(),e};function ve(e){this._headers=e}ve.prototype.get=function(e){return this._headers.get(e)};function be(){}be.prototype.open=function(e,r,n,t,f,i,u){var E=null,v=new K,p=v.signal,y=new C;return G(f,{headers:u,credentials:i?"include":"same-origin",signal:p,cache:"no-store"}).then(function(d){return E=d.body.getReader(),r(d.status,d.statusText,d.headers.get("Content-Type"),new ve(d.headers)),new A(function(m,Y){var ge=function(){E.read().then(function(k){if(k.done)m(void 0);else{var M=y.decode(k.value,{stream:!0});n(M),ge()}}).catch(function(k){Y(k)})};ge()})}).catch(function(d){if(d.name!=="AbortError")return d}).then(function(d){t(d)}),{abort:function(){E!=null&&E.cancel(),v.abort()}}};function ne(){this._listeners=Object.create(null)}function Se(e){c(function(){throw e},0)}ne.prototype.dispatchEvent=function(e){e.target=this;var r=this._listeners[e.type];if(r!=null)for(var n=r.length,t=0;t<n;t+=1){var f=r[t];try{typeof f.handleEvent=="function"?f.handleEvent(e):f.call(this,e)}catch(i){Se(i)}}},ne.prototype.addEventListener=function(e,r){e=String(e);var n=this._listeners,t=n[e];t==null&&(t=[],n[e]=t);for(var f=!1,i=0;i<t.length;i+=1)t[i]===r&&(f=!0);f||t.push(r)},ne.prototype.removeEventListener=function(e,r){e=String(e);var n=this._listeners,t=n[e];if(t!=null){for(var f=[],i=0;i<t.length;i+=1)t[i]!==r&&f.push(t[i]);f.length===0?delete n[e]:n[e]=f}};function te(e){this.type=e,this.target=void 0}function he(e,r){te.call(this,e),this.data=r.data,this.lastEventId=r.lastEventId}he.prototype=Object.create(te.prototype);function o(e,r){te.call(this,e),this.status=r.status,this.statusText=r.statusText,this.headers=r.headers}o.prototype=Object.create(te.prototype);function s(e,r){te.call(this,e),this.error=r.error}s.prototype=Object.create(te.prototype);var h=-1,l=0,V=1,S=2,w=-1,T=0,z=1,oe=2,pe=3,we=/^text\/event\-stream(;.*)?$/i,$e=1e3,Be=18e6,_e=function(e,r){var n=e==null?r:parseInt(e,10);return n!==n&&(n=r),Fe(n)},Fe=function(e){return Math.min(Math.max(e,$e),Be)},se=function(e,r,n){try{typeof r=="function"&&r.call(e,n)}catch(t){Se(t)}};function J(e,r){ne.call(this),r=r||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,Ge(this,e,r)}function Xe(){return g!=null&&"withCredentials"in g.prototype||W==null?new g:new W}var qe=G!=null&&ue!=null&&"body"in ue.prototype;function Ge(e,r,n){r=String(r);var t=Boolean(n.withCredentials),f=n.lastEventIdQueryParameterName||"lastEventId",i=Fe(1e3),u=_e(n.heartbeatTimeout,45e3),E="",v=i,p=!1,y=0,d=n.headers||{},m=n.Transport,Y=qe&&m==null?void 0:new b(m!=null?new m:Xe()),ge=m!=null&&typeof m!="string"?new m:Y==null?new be:new me,k=void 0,M=0,X=h,fe="",Te="",Q="",Ce="",H=T,xe=0,ae=0,Ke=function(D,R,U,$){if(X===l)if(D===200&&U!=null&&we.test(U)){X=V,p=Date.now(),v=i,e.readyState=V;var L=new o("open",{status:D,statusText:R,headers:$});e.dispatchEvent(L),se(e,e.onopen,L)}else{var _="";D!==200?(R&&(R=R.replace(/\s+/g," ")),_="EventSource's response has a status "+D+" "+R+" that is not 200. Aborting the connection."):_="EventSource's response has a Content-Type specifying an unsupported type: "+(U==null?"-":U.replace(/\s+/g," "))+". Aborting the connection.",Ve();var L=new o("error",{status:D,statusText:R,headers:$});e.dispatchEvent(L),se(e,e.onerror,L),console.error(_)}},ze=function(D){if(X===V){for(var R=-1,U=0;U<D.length;U+=1){var $=D.charCodeAt(U);($===` | ||
`.charCodeAt(0)||$==="\r".charCodeAt(0))&&(R=U)}var L=(R!==-1?Ce:"")+D.slice(0,R+1);Ce=(R===-1?Ce:"")+D.slice(R+1),D!==""&&(p=Date.now(),y+=D.length);for(var _=0;_<L.length;_+=1){var $=L.charCodeAt(_);if(H===w&&$===` | ||
`.charCodeAt(0))H=T;else if(H===w&&(H=T),$==="\r".charCodeAt(0)||$===` | ||
`.charCodeAt(0)){if(H!==T){H===z&&(ae=_+1);var Z=L.slice(xe,ae-1),ee=L.slice(ae+(ae<_&&L.charCodeAt(ae)===" ".charCodeAt(0)?1:0),_);Z==="data"?(fe+=` | ||
`,fe+=ee):Z==="id"?Te=ee:Z==="event"?Q=ee:Z==="retry"?(i=_e(ee,i),v=i):Z==="heartbeatTimeout"&&(u=_e(ee,u),M!==0&&(I(M),M=c(function(){ye()},u)))}if(H===T){if(fe!==""){E=Te,Q===""&&(Q="message");var de=new he(Q,{data:fe.slice(1),lastEventId:Te});if(e.dispatchEvent(de),Q==="open"?se(e,e.onopen,de):Q==="message"?se(e,e.onmessage,de):Q==="error"&&se(e,e.onerror,de),X===S)return}fe="",Q=""}H=$==="\r".charCodeAt(0)?w:T}else H===T&&(xe=_,H=z),H===z?$===":".charCodeAt(0)&&(ae=_+1,H=oe):H===oe&&(H=pe)}}},Pe=function(D){if(X===V||X===l)X=h,M!==0&&(I(M),M=0),M=c(function(){ye()},v),v=Fe(Math.min(i*16,v*2)),e.readyState=l;else if(X===S&&D!=null){console.error(D);var R=new s("error",{error:D});e.dispatchEvent(R),se(e,e.onerror,R)}},Ve=function(){X=S,k!=null&&(k.abort(),k=void 0),M!==0&&(I(M),M=0),e.readyState=S},ye=function(){if(M=0,X!==h){if(!p&&k!=null)Pe(new Error("No activity within "+u+" milliseconds. "+(X===l?"No response received.":y+" chars received.")+" Reconnecting.")),k!=null&&(k.abort(),k=void 0);else{var D=Math.max((p||Date.now())+u-Date.now(),1);p=!1,M=c(function(){ye()},D)}return}p=!1,y=0,M=c(function(){ye()},u),X=l,fe="",Q="",Te=E,Ce="",xe=0,ae=0,H=T;var R=r;if(r.slice(0,5)!=="data:"&&r.slice(0,5)!=="blob:"&&E!==""){var U=r.indexOf("?");R=U===-1?r:r.slice(0,U+1)+r.slice(U+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(ee,de){return de===f?"":ee}),R+=(r.indexOf("?")===-1?"?":"&")+f+"="+encodeURIComponent(E)}var $=e.withCredentials,L={};L.Accept="text/event-stream";var _=e.headers;if(_!=null)for(var Z in _)Object.prototype.hasOwnProperty.call(_,Z)&&(L[Z]=_[Z]);try{k=ge.open(Y,Ke,ze,Pe,R,$,L)}catch(ee){throw Ve(),ee}};e.url=r,e.readyState=l,e.withCredentials=t,e.headers=d,e._close=Ve,ye()}J.prototype=Object.create(ne.prototype),J.prototype.CONNECTING=l,J.prototype.OPEN=V,J.prototype.CLOSED=S,J.prototype.close=function(){this._close()},J.CONNECTING=l,J.OPEN=V,J.CLOSED=S,J.prototype.withCredentials=void 0;var Le=B;g!=null&&(B==null||!("withCredentials"in B.prototype))&&(Le=J),function(e){if(typeof Ie=="object"&&typeof Ie.exports=="object"){var r=e(He);r!==void 0&&(Ie.exports=r)}else typeof define=="function"&&define.amd?define(["exports"],e):e(a)}(function(e){e.EventSourcePolyfill=J,e.NativeEventSource=B,e.EventSource=Le})})(typeof globalThis=="undefined"?typeof window!="undefined"?window:typeof self!="undefined"?self:He:globalThis)});var Ue=nt(je());import at from"jwt-decode";import it from"mitt";var j;(function(a){a.READY="ready",a.CONNECTED="connected",a.DISCONNECTED="disconnected",a.RECONNECTED="reconnected",a.CHANGED="changed",a.ERROR="error"})(j||(j={}));var ke={debug:!1,baseUrl:"https://config.ff.harness.io/api/1.0",eventUrl:"https://events.ff.harness.io/api/1.0",streamEnabled:!0,allAttributesPrivate:!1,privateAttributeNames:[]},ce=(a,...c)=>console.error(`[FF-SDK] ${a}`,...c),Ae=30*1e3;var ot="1.4.3",st=500,De=globalThis.fetch,ft=Ue.EventSourcePolyfill,Ee=!!globalThis.Proxy,Oe=a=>{let{value:c}=a;try{switch(a.kind.toLowerCase()){case"int":case"number":c=Number(c);break;case"boolean":c=c.toString().toLowerCase()==="true";break;case"json":c=JSON.parse(c);break}}catch(I){ce(I)}return c},dt=(a,c,I)=>{let g,W,q,B,O,A=!0,G=()=>{A=!1},ue=()=>{A=!0},C=[],N=it(),K=ie(ie({},ke),I),F=(o,...s)=>{K.debug&&console.debug(`[FF-SDK] ${o}`,...s)},re=o=>{if(A){let s=Date.now();s-o.lastAccessed>st&&(o.count++,o.lastAccessed=s)}};globalThis.onbeforeunload=()=>{C.length&&globalThis.localStorage&&(G(),globalThis.localStorage.HARNESS_FF_METRICS=JSON.stringify(C),ue())};let Ne=(o,s)=>Re(void 0,null,function*(){return(yield(yield De(`${s.baseUrl}/client/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:o,target:c})})).json()).authToken}),x=()=>{if(C.length){F("Sending metrics...",{metrics:C,evaluations:b});let o={metricsData:C.map(s=>({timestamp:Date.now(),count:s.count,metricsType:"FFMETRICS",attributes:[{key:"featureIdentifier",value:s.featureIdentifier},{key:"featureName",value:s.featureIdentifier},{key:"variationIdentifier",value:s.variationIdentifier},{key:"target",value:c.identifier},{key:"SDK_NAME",value:"JavaScript"},{key:"SDK_TYPE",value:"client"},{key:"SDK_VERSION",value:ot}]}))};De(`${K.eventUrl}/metrics/${g}?cluster=${W}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${B}`},body:JSON.stringify(o)}).then(()=>{C=[]}).catch(s=>{F(s)}).finally(()=>{O=window.setTimeout(x,Ae)})}else O=window.setTimeout(x,Ae)},b={},le=function(){return Ee?new Proxy({},{get(o,s){var l,V,S;let h=o[s];if(o.hasOwnProperty(s)){let w=o[s],T=C.find(z=>z.featureIdentifier===s&&w===z.featureValue);T?(T.variationIdentifier=((l=b[s])==null?void 0:l.identifier)||"",re(T)):C.push({featureIdentifier:s,featureValue:w,variationIdentifier:((V=b[s])==null?void 0:V.identifier)||"",count:A?1:0,lastAccessed:Date.now()}),F("Metrics event: Flag:",s,"has been read with value:",w,"variationIdentifier:",(S=b[s])==null?void 0:S.identifier)}return h}}):{}},P=le();Ne(a,K).then(o=>{B=o;let s=at(o);if(F("Authenticated",s),globalThis.localStorage&&globalThis.localStorage.HARNESS_FF_METRICS)try{delete globalThis.localStorage.HARNESS_FF_METRICS,F("Picking up metrics from previous session")}catch(h){}O=window.setTimeout(x,Ae),g=s.environment,W=s.clusterIdentifier,me().then(()=>{F("Fetch all flags ok",P)}).then(()=>{be()}).then(()=>{F("Event stream ready",{storage:P}),N.emit(j.READY,P),Ee||Object.keys(P).forEach(h=>{var l;C.push({featureIdentifier:h,featureValue:P[h],variationIdentifier:((l=b[h])==null?void 0:l.identifier)||"",count:A?1:0,lastAccessed:Date.now()})})}).catch(h=>{N.emit(j.ERROR,h)})}).catch(o=>{ce("Authentication error: ",o),N.emit(j.ERROR,o)});let me=()=>Re(void 0,null,function*(){try{(yield(yield De(`${K.baseUrl}/client/env/${g}/target/${c.identifier}/evaluations?cluster=${W}`,{headers:{Authorization:`Bearer ${B}`}})).json()).forEach(h=>{let l=Oe(h);P[h.flag]=l,b[h.flag]=ie(ie({},h),{value:l})})}catch(o){return ce("Features fetch operation error: ",o),N.emit(j.ERROR,o),o}}),ve=o=>Re(void 0,null,function*(){var s;try{let h=yield De(`${K.baseUrl}/client/env/${g}/target/${c.identifier}/evaluations/${o}?cluster=${W}`,{headers:{Authorization:`Bearer ${B}`}});if(h.ok){let l=yield h.json(),V=Oe(l);if(G(),P[o]=V,b[o]=ie(ie({},l),{value:V}),ue(),N.emit(j.CHANGED,Ee?new Proxy(l,{get(S,w){var T;if(S.hasOwnProperty(w)&&w==="value"){let z=S.flag,oe=l.value,pe=C.find(we=>we.featureIdentifier===z&&we.featureValue===oe);pe?(re(pe),pe.variationIdentifier=((T=b[z])==null?void 0:T.identifier)||""):C.push({featureIdentifier:z,featureValue:String(oe),variationIdentifier:b[z].identifier||"",count:A?1:0,lastAccessed:Date.now()}),F("Metrics event: Flag",w,"has been read with value via stream update",oe)}return w==="value"?Oe(l):l[w]}}):{deleted:l.deleted,flag:l.flag,value:Oe(l)}),!Ee){let S=l.flag,w=C.find(T=>T.featureIdentifier===S&&T.featureValue===l.value);w?(re(w),w.variationIdentifier=((s=b[S])==null?void 0:s.identifier)||""):C.push({featureIdentifier:S,featureValue:String(l.value),variationIdentifier:b[S].identifier||"",count:A?1:0,lastAccessed:Date.now()})}}else N.emit(j.ERROR,h)}catch(h){ce("Feature fetch operation error: ",h),N.emit(j.ERROR,h)}}),be=()=>{if(!K.streamEnabled){F("Stream is disabled by configuration. Note: Polling is not yet supported");return}q=new ft(`${K.baseUrl}/stream`,{headers:{Authorization:`Bearer ${B}`,"API-Key":a}}),q.onopen=o=>{F("Stream connected",o),N.emit(j.CONNECTED)},q.onclose=o=>{F("Stream disconnected"),N.emit(j.DISCONNECTED)},q.onerror=o=>{ce("Stream has issue",o),N.emit("error",o)},q.addEventListener("*",o=>{let s=JSON.parse(o.data);switch(F("Received event from stream: ",s),s.event){case"create":setTimeout(()=>ve(s.identifier),1e3);break;case"patch":ve(s.identifier);break;case"delete":delete P[s.identifier],N.emit(j.CHANGED,{flag:s.identifier,value:void 0,deleted:!0}),F("Evaluation deleted",{message:s,storage:P});break}})},ne=(o,s)=>N.on(o,s),Se=(o,s)=>{o?N.off(o,s):he()},te=(o,s)=>{var l;let h=P[o];if(!Ee&&h!==void 0){let V=h,S=o,w=C.find(T=>T.featureIdentifier===S&&T.featureValue===V);w?(re(w),w.variationIdentifier=((l=b[S])==null?void 0:l.identifier)||""):C.push({featureIdentifier:S,featureValue:V,count:A?1:0,variationIdentifier:b[S].identifier||"",lastAccessed:Date.now()})}return h!==void 0?h:s},he=()=>{F("Closing event stream"),P=le(),b={},clearTimeout(O),N.all.clear(),q.close()};return{on:ne,off:Se,variation:te,close:he}};export{j as Event,dt as initialize}; | ||
var Je=Object.create,Me=Object.defineProperty,We=Object.getPrototypeOf,Ye=Object.prototype.hasOwnProperty,Qe=Object.getOwnPropertyNames,Ze=Object.getOwnPropertyDescriptor;var ie=Object.assign,et=a=>Me(a,"__esModule",{value:!0});var tt=(a,c)=>()=>(c||(c={exports:{}},a(c.exports,c)),c.exports);var rt=(a,c,I)=>{if(c&&typeof c=="object"||typeof c=="function")for(let g of Qe(c))!Ye.call(a,g)&&g!=="default"&&Me(a,g,{get:()=>c[g],enumerable:!(I=Ze(c,g))||I.enumerable});return a},nt=a=>rt(et(Me(a!=null?Je(We(a)):{},"default",a&&a.__esModule&&"default"in a?{get:()=>a.default,enumerable:!0}:{value:a,enumerable:!0})),a);var Re=(a,c,I)=>new Promise((g,q)=>{var G=A=>{try{O(I.next(A))}catch(K){q(K)}},B=A=>{try{O(I.throw(A))}catch(K){q(K)}},O=A=>A.done?g(A.value):Promise.resolve(A.value).then(G,B);O((I=I.apply(a,c)).next())});var je=tt((He,Ie)=>{(function(a){"use strict";var c=a.setTimeout,I=a.clearTimeout,g=a.XMLHttpRequest,q=a.XDomainRequest,G=a.ActiveXObject,B=a.EventSource,O=a.document,A=a.Promise,K=a.fetch,ue=a.Response,C=a.TextDecoder,N=a.TextEncoder,z=a.AbortController;if(typeof window!="undefined"&&typeof O!="undefined"&&!("readyState"in O)&&O.body==null&&(O.readyState="loading",window.addEventListener("load",function(e){O.readyState="complete"},!1)),g==null&&G!=null&&(g=function(){return new G("Microsoft.XMLHTTP")}),Object.create==null&&(Object.create=function(e){function r(){}return r.prototype=e,new r}),Date.now||(Date.now=function(){return new Date().getTime()}),z==null){var F=K;K=function(e,r){var n=r.signal;return F(e,{headers:r.headers,credentials:r.credentials,cache:r.cache}).then(function(t){var f=t.body.getReader();return n._reader=f,n._aborted&&n._reader.cancel(),{status:t.status,statusText:t.statusText,headers:t.headers,body:{getReader:function(){return f}}}})},z=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){this.signal._reader!=null&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function re(){this.bitsNeeded=0,this.codePoint=0}re.prototype.decode=function(e){function r(p,y,d){if(d===1)return p>=128>>y&&p<<y<=2047;if(d===2)return p>=2048>>y&&p<<y<=55295||p>=57344>>y&&p<<y<=65535;if(d===3)return p>=65536>>y&&p<<y<=1114111;throw new Error}function n(p,y){if(p===6*1)return y>>6>15?3:y>31?2:1;if(p===6*2)return y>15?3:2;if(p===6*3)return 3;throw new Error}for(var t=65533,f="",i=this.bitsNeeded,u=this.codePoint,E=0;E<e.length;E+=1){var v=e[E];i!==0&&(v<128||v>191||!r(u<<6|v&63,i-6,n(i,u)))&&(i=0,u=t,f+=String.fromCharCode(u)),i===0?(v>=0&&v<=127?(i=0,u=v):v>=192&&v<=223?(i=6*1,u=v&31):v>=224&&v<=239?(i=6*2,u=v&15):v>=240&&v<=247?(i=6*3,u=v&7):(i=0,u=t),i!==0&&!r(u,i,n(i,u))&&(i=0,u=t)):(i-=6,u=u<<6|v&63),i===0&&(u<=65535?f+=String.fromCharCode(u):(f+=String.fromCharCode(55296+(u-65535-1>>10)),f+=String.fromCharCode(56320+(u-65535-1&1023))))}return this.bitsNeeded=i,this.codePoint=u,f};var Ne=function(){try{return new C().decode(new N().encode("test"),{stream:!0})==="test"}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1};(C==null||N==null||!Ne())&&(C=re);var x=function(){};function b(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=x,this.onload=x,this.onerror=x,this.onreadystatechange=x,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=x}b.prototype.open=function(e,r){this._abort(!0);var n=this,t=this._xhr,f=1,i=0;this._abort=function(d){n._sendTimeout!==0&&(I(n._sendTimeout),n._sendTimeout=0),(f===1||f===2||f===3)&&(f=4,t.onload=x,t.onerror=x,t.onabort=x,t.onprogress=x,t.onreadystatechange=x,t.abort(),i!==0&&(I(i),i=0),d||(n.readyState=4,n.onabort(null),n.onreadystatechange())),f=0};var u=function(){if(f===1){var d=0,m="",Y=void 0;if("contentType"in t)d=200,m="OK",Y=t.contentType;else try{d=t.status,m=t.statusText,Y=t.getResponseHeader("Content-Type")}catch(ge){d=0,m="",Y=void 0}d!==0&&(f=2,n.readyState=2,n.status=d,n.statusText=m,n._contentType=Y,n.onreadystatechange())}},E=function(){if(u(),f===2||f===3){f=3;var d="";try{d=t.responseText}catch(m){}n.readyState=3,n.responseText=d,n.onprogress()}},v=function(d,m){if((m==null||m.preventDefault==null)&&(m={preventDefault:x}),E(),f===1||f===2||f===3){if(f=4,i!==0&&(I(i),i=0),n.readyState=4,d==="load")n.onload(m);else if(d==="error")n.onerror(m);else if(d==="abort")n.onabort(m);else throw new TypeError;n.onreadystatechange()}},p=function(d){t!=null&&(t.readyState===4?(!("onload"in t)||!("onerror"in t)||!("onabort"in t))&&v(t.responseText===""?"error":"load",d):t.readyState===3?"onprogress"in t||E():t.readyState===2&&u())},y=function(){i=c(function(){y()},500),t.readyState===3&&E()};"onload"in t&&(t.onload=function(d){v("load",d)}),"onerror"in t&&(t.onerror=function(d){v("error",d)}),"onabort"in t&&(t.onabort=function(d){v("abort",d)}),"onprogress"in t&&(t.onprogress=E),"onreadystatechange"in t&&(t.onreadystatechange=function(d){p(d)}),("contentType"in t||!("ontimeout"in g.prototype))&&(r+=(r.indexOf("?")===-1?"?":"&")+"padding=true"),t.open(e,r,!0),"readyState"in t&&(i=c(function(){y()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(e){return this._contentType},b.prototype.setRequestHeader=function(e,r){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,r)},b.prototype.getAllResponseHeaders=function(){return this._xhr.getAllResponseHeaders!=null&&this._xhr.getAllResponseHeaders()||""},b.prototype.send=function(){if((!("ontimeout"in g.prototype)||!("sendAsBinary"in g.prototype)&&!("mozAnon"in g.prototype))&&O!=null&&O.readyState!=null&&O.readyState!=="complete"){var e=this;e._sendTimeout=c(function(){e._sendTimeout=0,e.send()},4);return}var r=this._xhr;"withCredentials"in r&&(r.withCredentials=this.withCredentials);try{r.send(void 0)}catch(n){throw n}};function le(e){return e.replace(/[A-Z]/g,function(r){return String.fromCharCode(r.charCodeAt(0)+32)})}function P(e){for(var r=Object.create(null),n=e.split(`\r | ||
`),t=0;t<n.length;t+=1){var f=n[t],i=f.split(": "),u=i.shift(),E=i.join(": ");r[le(u)]=E}this._map=r}P.prototype.get=function(e){return this._map[le(e)]},g!=null&&g.HEADERS_RECEIVED==null&&(g.HEADERS_RECEIVED=2);function me(){}me.prototype.open=function(e,r,n,t,f,i,u){e.open("GET",f);var E=0;e.onprogress=function(){var p=e.responseText,y=p.slice(E);E+=y.length,n(y)},e.onerror=function(p){p.preventDefault(),t(new Error("NetworkError"))},e.onload=function(){t(null)},e.onabort=function(){t(null)},e.onreadystatechange=function(){if(e.readyState===g.HEADERS_RECEIVED){var p=e.status,y=e.statusText,d=e.getResponseHeader("Content-Type"),m=e.getAllResponseHeaders();r(p,y,d,new P(m))}},e.withCredentials=i;for(var v in u)Object.prototype.hasOwnProperty.call(u,v)&&e.setRequestHeader(v,u[v]);return e.send(),e};function ve(e){this._headers=e}ve.prototype.get=function(e){return this._headers.get(e)};function be(){}be.prototype.open=function(e,r,n,t,f,i,u){var E=null,v=new z,p=v.signal,y=new C;return K(f,{headers:u,credentials:i?"include":"same-origin",signal:p,cache:"no-store"}).then(function(d){return E=d.body.getReader(),r(d.status,d.statusText,d.headers.get("Content-Type"),new ve(d.headers)),new A(function(m,Y){var ge=function(){E.read().then(function($){if($.done)m(void 0);else{var M=y.decode($.value,{stream:!0});n(M),ge()}}).catch(function($){Y($)})};ge()})}).catch(function(d){if(d.name!=="AbortError")return d}).then(function(d){t(d)}),{abort:function(){E!=null&&E.cancel(),v.abort()}}};function ne(){this._listeners=Object.create(null)}function Se(e){c(function(){throw e},0)}ne.prototype.dispatchEvent=function(e){e.target=this;var r=this._listeners[e.type];if(r!=null)for(var n=r.length,t=0;t<n;t+=1){var f=r[t];try{typeof f.handleEvent=="function"?f.handleEvent(e):f.call(this,e)}catch(i){Se(i)}}},ne.prototype.addEventListener=function(e,r){e=String(e);var n=this._listeners,t=n[e];t==null&&(t=[],n[e]=t);for(var f=!1,i=0;i<t.length;i+=1)t[i]===r&&(f=!0);f||t.push(r)},ne.prototype.removeEventListener=function(e,r){e=String(e);var n=this._listeners,t=n[e];if(t!=null){for(var f=[],i=0;i<t.length;i+=1)t[i]!==r&&f.push(t[i]);f.length===0?delete n[e]:n[e]=f}};function te(e){this.type=e,this.target=void 0}function he(e,r){te.call(this,e),this.data=r.data,this.lastEventId=r.lastEventId}he.prototype=Object.create(te.prototype);function o(e,r){te.call(this,e),this.status=r.status,this.statusText=r.statusText,this.headers=r.headers}o.prototype=Object.create(te.prototype);function s(e,r){te.call(this,e),this.error=r.error}s.prototype=Object.create(te.prototype);var h=-1,l=0,V=1,S=2,w=-1,T=0,J=1,oe=2,pe=3,we=/^text\/event\-stream(;.*)?$/i,Ue=1e3,Be=18e6,_e=function(e,r){var n=e==null?r:parseInt(e,10);return n!==n&&(n=r),Fe(n)},Fe=function(e){return Math.min(Math.max(e,Ue),Be)},se=function(e,r,n){try{typeof r=="function"&&r.call(e,n)}catch(t){Se(t)}};function W(e,r){ne.call(this),r=r||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,Ge(this,e,r)}function Xe(){return g!=null&&"withCredentials"in g.prototype||q==null?new g:new q}var qe=K!=null&&ue!=null&&"body"in ue.prototype;function Ge(e,r,n){r=String(r);var t=Boolean(n.withCredentials),f=n.lastEventIdQueryParameterName||"lastEventId",i=Fe(1e3),u=_e(n.heartbeatTimeout,45e3),E="",v=i,p=!1,y=0,d=n.headers||{},m=n.Transport,Y=qe&&m==null?void 0:new b(m!=null?new m:Xe()),ge=m!=null&&typeof m!="string"?new m:Y==null?new be:new me,$=void 0,M=0,X=h,fe="",Te="",Q="",Ce="",H=T,xe=0,ae=0,Ke=function(D,R,k,U){if(X===l)if(D===200&&k!=null&&we.test(k)){X=V,p=Date.now(),v=i,e.readyState=V;var L=new o("open",{status:D,statusText:R,headers:U});e.dispatchEvent(L),se(e,e.onopen,L)}else{var _="";D!==200?(R&&(R=R.replace(/\s+/g," ")),_="EventSource's response has a status "+D+" "+R+" that is not 200. Aborting the connection."):_="EventSource's response has a Content-Type specifying an unsupported type: "+(k==null?"-":k.replace(/\s+/g," "))+". Aborting the connection.",Ve();var L=new o("error",{status:D,statusText:R,headers:U});e.dispatchEvent(L),se(e,e.onerror,L),console.error(_)}},ze=function(D){if(X===V){for(var R=-1,k=0;k<D.length;k+=1){var U=D.charCodeAt(k);(U===` | ||
`.charCodeAt(0)||U==="\r".charCodeAt(0))&&(R=k)}var L=(R!==-1?Ce:"")+D.slice(0,R+1);Ce=(R===-1?Ce:"")+D.slice(R+1),D!==""&&(p=Date.now(),y+=D.length);for(var _=0;_<L.length;_+=1){var U=L.charCodeAt(_);if(H===w&&U===` | ||
`.charCodeAt(0))H=T;else if(H===w&&(H=T),U==="\r".charCodeAt(0)||U===` | ||
`.charCodeAt(0)){if(H!==T){H===J&&(ae=_+1);var Z=L.slice(xe,ae-1),ee=L.slice(ae+(ae<_&&L.charCodeAt(ae)===" ".charCodeAt(0)?1:0),_);Z==="data"?(fe+=` | ||
`,fe+=ee):Z==="id"?Te=ee:Z==="event"?Q=ee:Z==="retry"?(i=_e(ee,i),v=i):Z==="heartbeatTimeout"&&(u=_e(ee,u),M!==0&&(I(M),M=c(function(){ye()},u)))}if(H===T){if(fe!==""){E=Te,Q===""&&(Q="message");var de=new he(Q,{data:fe.slice(1),lastEventId:Te});if(e.dispatchEvent(de),Q==="open"?se(e,e.onopen,de):Q==="message"?se(e,e.onmessage,de):Q==="error"&&se(e,e.onerror,de),X===S)return}fe="",Q=""}H=U==="\r".charCodeAt(0)?w:T}else H===T&&(xe=_,H=J),H===J?U===":".charCodeAt(0)&&(ae=_+1,H=oe):H===oe&&(H=pe)}}},Pe=function(D){if(X===V||X===l)X=h,M!==0&&(I(M),M=0),M=c(function(){ye()},v),v=Fe(Math.min(i*16,v*2)),e.readyState=l;else if(X===S&&D!=null){console.error(D);var R=new s("error",{error:D});e.dispatchEvent(R),se(e,e.onerror,R)}},Ve=function(){X=S,$!=null&&($.abort(),$=void 0),M!==0&&(I(M),M=0),e.readyState=S},ye=function(){if(M=0,X!==h){if(!p&&$!=null)Pe(new Error("No activity within "+u+" milliseconds. "+(X===l?"No response received.":y+" chars received.")+" Reconnecting.")),$!=null&&($.abort(),$=void 0);else{var D=Math.max((p||Date.now())+u-Date.now(),1);p=!1,M=c(function(){ye()},D)}return}p=!1,y=0,M=c(function(){ye()},u),X=l,fe="",Q="",Te=E,Ce="",xe=0,ae=0,H=T;var R=r;if(r.slice(0,5)!=="data:"&&r.slice(0,5)!=="blob:"&&E!==""){var k=r.indexOf("?");R=k===-1?r:r.slice(0,k+1)+r.slice(k+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(ee,de){return de===f?"":ee}),R+=(r.indexOf("?")===-1?"?":"&")+f+"="+encodeURIComponent(E)}var U=e.withCredentials,L={};L.Accept="text/event-stream";var _=e.headers;if(_!=null)for(var Z in _)Object.prototype.hasOwnProperty.call(_,Z)&&(L[Z]=_[Z]);try{$=ge.open(Y,Ke,ze,Pe,R,U,L)}catch(ee){throw Ve(),ee}};e.url=r,e.readyState=l,e.withCredentials=t,e.headers=d,e._close=Ve,ye()}W.prototype=Object.create(ne.prototype),W.prototype.CONNECTING=l,W.prototype.OPEN=V,W.prototype.CLOSED=S,W.prototype.close=function(){this._close()},W.CONNECTING=l,W.OPEN=V,W.CLOSED=S,W.prototype.withCredentials=void 0;var Le=B;g!=null&&(B==null||!("withCredentials"in B.prototype))&&(Le=W),function(e){if(typeof Ie=="object"&&typeof Ie.exports=="object"){var r=e(He);r!==void 0&&(Ie.exports=r)}else typeof define=="function"&&define.amd?define(["exports"],e):e(a)}(function(e){e.EventSourcePolyfill=W,e.NativeEventSource=B,e.EventSource=Le})})(typeof globalThis=="undefined"?typeof window!="undefined"?window:typeof self!="undefined"?self:He:globalThis)});var ke=nt(je());import at from"jwt-decode";import it from"mitt";var j;(function(a){a.READY="ready",a.CONNECTED="connected",a.DISCONNECTED="disconnected",a.RECONNECTED="reconnected",a.CHANGED="changed",a.ERROR="error"})(j||(j={}));var $e={debug:!1,baseUrl:"https://config.ff.harness.io/api/1.0",eventUrl:"https://events.ff.harness.io/api/1.0",streamEnabled:!0,allAttributesPrivate:!1,privateAttributeNames:[]},ce=(a,...c)=>console.error(`[FF-SDK] ${a}`,...c),Ae=30*1e3;var ot="1.4.4",st=500,De=globalThis.fetch,ft=ke.EventSourcePolyfill,Ee=!!globalThis.Proxy,Oe=a=>{let{value:c}=a;try{switch(a.kind.toLowerCase()){case"int":case"number":c=Number(c);break;case"boolean":c=c.toString().toLowerCase()==="true";break;case"json":c=JSON.parse(c);break}}catch(I){ce(I)}return c},dt=(a,c,I)=>{let g,q,G,B,O,A=!0,K=()=>{A=!1},ue=()=>{A=!0},C=[],N=it(),z=ie(ie({},$e),I),F=(o,...s)=>{z.debug&&console.debug(`[FF-SDK] ${o}`,...s)},re=o=>{if(A){let s=Date.now();s-o.lastAccessed>st&&(o.count++,o.lastAccessed=s)}};globalThis.onbeforeunload=()=>{C.length&&globalThis.localStorage&&(K(),globalThis.localStorage.HARNESS_FF_METRICS=JSON.stringify(C),ue())};let Ne=(o,s)=>Re(void 0,null,function*(){return(yield(yield De(`${s.baseUrl}/client/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:o,target:c})})).json()).authToken}),x=()=>{if(C.length){F("Sending metrics...",{metrics:C,evaluations:b});let o={metricsData:C.map(s=>({timestamp:Date.now(),count:s.count,metricsType:"FFMETRICS",attributes:[{key:"featureIdentifier",value:s.featureIdentifier},{key:"featureName",value:s.featureIdentifier},{key:"variationIdentifier",value:s.variationIdentifier},{key:"target",value:c.identifier},{key:"SDK_NAME",value:"JavaScript"},{key:"SDK_TYPE",value:"client"},{key:"SDK_VERSION",value:ot}]}))};De(`${z.eventUrl}/metrics/${g}?cluster=${q}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${B}`},body:JSON.stringify(o)}).then(()=>{C=[]}).catch(s=>{F(s)}).finally(()=>{O=window.setTimeout(x,Ae)})}else O=window.setTimeout(x,Ae)},b={},le=function(){return Ee?new Proxy({},{get(o,s){var l,V,S;let h=o[s];if(o.hasOwnProperty(s)){let w=o[s],T=C.find(J=>J.featureIdentifier===s&&w===J.featureValue);T?(T.variationIdentifier=((l=b[s])==null?void 0:l.identifier)||"",re(T)):C.push({featureIdentifier:s,featureValue:w,variationIdentifier:((V=b[s])==null?void 0:V.identifier)||"",count:A?1:0,lastAccessed:Date.now()}),F("Metrics event: Flag:",s,"has been read with value:",w,"variationIdentifier:",(S=b[s])==null?void 0:S.identifier)}return h}}):{}},P=le();Ne(a,z).then(o=>{B=o;let s=at(o);if(F("Authenticated",s),globalThis.localStorage&&globalThis.localStorage.HARNESS_FF_METRICS)try{delete globalThis.localStorage.HARNESS_FF_METRICS,F("Picking up metrics from previous session")}catch(h){}O=window.setTimeout(x,Ae),g=s.environment,q=s.clusterIdentifier,me().then(()=>{F("Fetch all flags ok",P)}).then(()=>{be()}).then(()=>{F("Event stream ready",{storage:P}),N.emit(j.READY,P),Ee||Object.keys(P).forEach(h=>{var l;C.push({featureIdentifier:h,featureValue:P[h],variationIdentifier:((l=b[h])==null?void 0:l.identifier)||"",count:A?1:0,lastAccessed:Date.now()})})}).catch(h=>{N.emit(j.ERROR,h)})}).catch(o=>{ce("Authentication error: ",o),N.emit(j.ERROR,o)});let me=()=>Re(void 0,null,function*(){try{(yield(yield De(`${z.baseUrl}/client/env/${g}/target/${c.identifier}/evaluations?cluster=${q}`,{headers:{Authorization:`Bearer ${B}`}})).json()).forEach(h=>{let l=Oe(h);P[h.flag]=l,b[h.flag]=ie(ie({},h),{value:l})})}catch(o){return ce("Features fetch operation error: ",o),N.emit(j.ERROR,o),o}}),ve=o=>Re(void 0,null,function*(){var s;try{let h=yield De(`${z.baseUrl}/client/env/${g}/target/${c.identifier}/evaluations/${o}?cluster=${q}`,{headers:{Authorization:`Bearer ${B}`}});if(h.ok){let l=yield h.json(),V=Oe(l);if(K(),P[o]=V,b[o]=ie(ie({},l),{value:V}),ue(),N.emit(j.CHANGED,Ee?new Proxy(l,{get(S,w){var T;if(S.hasOwnProperty(w)&&w==="value"){let J=S.flag,oe=l.value,pe=C.find(we=>we.featureIdentifier===J&&we.featureValue===oe);pe?(re(pe),pe.variationIdentifier=((T=b[J])==null?void 0:T.identifier)||""):C.push({featureIdentifier:J,featureValue:String(oe),variationIdentifier:b[J].identifier||"",count:A?1:0,lastAccessed:Date.now()}),F("Metrics event: Flag",w,"has been read with value via stream update",oe)}return w==="value"?Oe(l):l[w]}}):{deleted:l.deleted,flag:l.flag,value:Oe(l)}),!Ee){let S=l.flag,w=C.find(T=>T.featureIdentifier===S&&T.featureValue===l.value);w?(re(w),w.variationIdentifier=((s=b[S])==null?void 0:s.identifier)||""):C.push({featureIdentifier:S,featureValue:String(l.value),variationIdentifier:b[S].identifier||"",count:A?1:0,lastAccessed:Date.now()})}}else N.emit(j.ERROR,h)}catch(h){ce("Feature fetch operation error: ",h),N.emit(j.ERROR,h)}}),be=()=>{if(!z.streamEnabled){F("Stream is disabled by configuration. Note: Polling is not yet supported");return}G=new ft(`${z.baseUrl}/stream?cluster=${q}`,{headers:{Authorization:`Bearer ${B}`,"API-Key":a}}),G.onopen=o=>{F("Stream connected",o),N.emit(j.CONNECTED)},G.onclose=o=>{F("Stream disconnected"),N.emit(j.DISCONNECTED)},G.onerror=o=>{ce("Stream has issue",o),N.emit("error",o)},G.addEventListener("*",o=>{let s=JSON.parse(o.data);switch(F("Received event from stream: ",s),s.event){case"create":setTimeout(()=>ve(s.identifier),1e3);break;case"patch":ve(s.identifier);break;case"delete":delete P[s.identifier],N.emit(j.CHANGED,{flag:s.identifier,value:void 0,deleted:!0}),F("Evaluation deleted",{message:s,storage:P});break}})},ne=(o,s)=>N.on(o,s),Se=(o,s)=>{o?N.off(o,s):he()},te=(o,s)=>{var l;let h=P[o];if(!Ee&&h!==void 0){let V=h,S=o,w=C.find(T=>T.featureIdentifier===S&&T.featureValue===V);w?(re(w),w.variationIdentifier=((l=b[S])==null?void 0:l.identifier)||""):C.push({featureIdentifier:S,featureValue:V,count:A?1:0,variationIdentifier:b[S].identifier||"",lastAccessed:Date.now()})}return h!==void 0?h:s},he=()=>{F("Closing event stream"),P=le(),b={},clearTimeout(O),N.all.clear(),G.close()};return{on:ne,off:Se,variation:te,close:he}};export{j as Event,dt as initialize}; | ||
/** @license | ||
@@ -8,0 +8,0 @@ * eventsource.js |
{ | ||
"name": "@harnessio/ff-javascript-client-sdk", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"author": "Harness", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -113,3 +113,3 @@ # Harness Feature Flags Client SDK for JavaScript | ||
<script type="module"> | ||
import { initialize, Event } from 'https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.4.3/dist/sdk.client.js' | ||
import { initialize, Event } from 'https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.4.4/dist/sdk.client.js' | ||
</script> | ||
@@ -121,3 +121,3 @@ ``` | ||
```html | ||
<script src="https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.4.3/dist/sdk.client.js"></script> | ||
<script src="https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.4.4/dist/sdk.client.js"></script> | ||
<script> | ||
@@ -129,3 +129,3 @@ var initialize = HarnessFFSDK.initialize | ||
Remember to change the version `1.4.3` in the unpkg url accordingly. | ||
Remember to change the version `1.4.4` in the unpkg url accordingly. | ||
@@ -132,0 +132,0 @@ ## License |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
98668
399
1