New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-native-flagsmith

Package Overview
Dependencies
Maintainers
1
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-flagsmith - npm Package Compare versions

Comparing version
9.2.2
to
9.3.0
+1
-1
index.js

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).index={})}(this,(function(t){"use strict";var e=function(){return e=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},e.apply(this,arguments)};function n(t,e,n,i){return new(n||(n=Promise))((function(a,o){function r(t){try{l(i.next(t))}catch(t){o(t)}}function s(t){try{l(i.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,s)}l((i=i.apply(t,e||[])).next())}))}function i(t,e){var n,i,a,o,r={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,i&&(a=2&o[0]?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return r.label++,{value:o[1],done:!1};case 5:r.label++,i=o[1],o=[0];continue;case 7:o=r.ops.pop(),r.trys.pop();continue;default:if(!(a=r.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){r=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){r.label=o[1];break}if(6===o[0]&&r.label<a[1]){r.label=a[1],a=o;break}if(a&&r.label<a[2]){r.label=a[2],r.ops.push(o);break}a[2]&&r.ops.pop(),r.trys.pop();continue}o=e.call(t,r)}catch(t){o=[6,t],i=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function a(t,e,n){if(n||2===arguments.length)for(var i,a=0,o=e.length;a<o;a++)!i&&a in e||(i||(i=Array.prototype.slice.call(e,0,a)),i[a]=e[a]);return t.concat(i||Array.prototype.slice.call(e))}function o(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})})),e}var r=function t(e,n){if(e===n)return!0;if(e&&n&&"object"==typeof e&&"object"==typeof n){if(e.constructor!==n.constructor)return!1;var i,a,o;if(Array.isArray(e)){if((i=e.length)!=n.length)return!1;for(a=i;0!=a--;)if(!t(e[a],n[a]))return!1;return!0}if(e.constructor===RegExp)return e.source===n.source&&e.flags===n.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===n.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===n.toString();if((i=(o=Object.keys(e)).length)!==Object.keys(n).length)return!1;for(a=i;0!=a--;)if(!Object.prototype.hasOwnProperty.call(n,o[a]))return!1;for(a=i;0!=a--;){var r=o[a];if(!t(e[r],n[r]))return!1}return!0}return e!=e&&n!=n};function s(t,e){var n=Object.keys(e||{}).filter((function(n){var i=null==t?void 0:t[n],a=null==e?void 0:e[n];return!r(i,a)}));return Object.keys(t||{}).filter((function(t){Object.keys(e||{}).includes(t)||n.push(t)})),Object.keys(n).length?n:null}var l,u;function h(t,e,n){var i="shortString",a=!0;"number"==typeof n&&(i="javaDouble",a=!1),t[i]=t[i]||{},t[i][e]=a?n+"":n}function c(t){return!!t&&"object"==typeof t&&void 0!==t.value}function d(t){return Object.fromEntries(Object.entries(t).map((function(t){var e=t[0],n=t[1];return[e,c(n)?n:{value:n}]})))}function v(t){return e(e({},t),{identity:t.identity?e(e({},t.identity),{traits:d(t.identity.traits||{})}):void 0})}!function(t){t.NONE="NONE",t.DEFAULT_FLAGS="DEFAULT_FLAGS",t.CACHE="CACHE",t.SERVER="SERVER"}(l||(l={}));var g,f=null,p="FLAGSMITH_EVENT",y=p,m="https://edge.api.flagsmith.com/api/v1/",S="flagsmith_value_",_="flagsmith_enabled_",E="flagsmith_trait_",C=function(){function t(t){var n=this;this._trigger=null,this._triggerLoadingState=null,this.timestamp=null,this.isLoading=!1,this.eventSource=null,this.getFlags=function(){var t=n,i=t.api,a=t.evaluationContext;n.log("Get Flags"),n.isLoading=!0,n.loadingState.isFetching||n.setLoadingState(e(e({},n.loadingState),{isFetching:!0}));var o="".concat(n.getContext().identity),r=function(t){var i,a,r,u;if(t&&o==="".concat(n.getContext().identity)){var c=t.flags,d=t.traits,v=t.identifier;n.isLoading=!1;var g={},f={};d=d||[],(c=c||[]).forEach((function(t){g[t.feature.name.toLowerCase().replace(/ /g,"_")]={id:t.feature.id,enabled:t.enabled,value:t.feature_state_value}})),d.forEach((function(t){f[t.trait_key.toLowerCase().replace(/ /g,"_")]={transient:t.transient,value:t.trait_value}})),n.oldFlags=e({},n.flags);var p=s(n.oldFlags,g),y=s(null===(i=n.evaluationContext.identity)||void 0===i?void 0:i.traits,f);if((v||Object.keys(f).length)&&(n.evaluationContext.identity=e(e({},n.evaluationContext.identity),{traits:f}),v&&(n.evaluationContext.identity.identifier=v,n.identity=v)),n.flags=g,n.updateStorage(),n._onChange(n.oldFlags,{isFromServer:!0,flagsChanged:p,traitsChanged:y},n._loadedState(null,l.SERVER)),n.datadogRum)try{if(n.datadogRum.trackTraits){var m={};Object.keys((null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.traits)||{}).map((function(t){m[E+t]=n.getTrait(t)}));var C=e(e(e({},n.datadogRum.client.getUser()),{id:n.datadogRum.client.getUser().id||(null===(r=n.evaluationContext.identity)||void 0===r?void 0:r.identifier)}),m);n.log("Setting Datadog user",C),n.datadogRum.client.setUser(C)}}catch(t){console.error(t)}if(n.dtrum)try{var x={javaDouble:{},date:{},shortString:{},javaLongOrObject:{}};Object.keys(n.flags).map((function(t){h(x,S+t,n.getValue(t,{skipAnalytics:!0})),h(x,_+t,n.hasFeature(t,{skipAnalytics:!0}))})),Object.keys((null===(u=n.evaluationContext.identity)||void 0===u?void 0:u.traits)||{}).map((function(t){h(x,E+t,n.getTrait(t))})),n.log("Sending javaLongOrObject traits to dynatrace",x.javaLongOrObject),n.log("Sending date traits to dynatrace",x.date),n.log("Sending shortString traits to dynatrace",x.shortString),n.log("Sending javaDouble to dynatrace",x.javaDouble),n.dtrum.sendSessionProperties(x.javaLongOrObject,x.date,x.shortString,x.javaDouble)}catch(t){console.error(t)}}};return a.identity?Promise.all([a.identity.traits&&Object.keys(a.identity.traits).length||!a.identity.identifier?n.getJSON(i+"identities/","POST",JSON.stringify({identifier:a.identity.identifier,transient:a.identity.transient,traits:Object.entries(a.identity.traits).map((function(t){var e=t[0],n=t[1];return{trait_key:e,trait_value:null==n?void 0:n.value,transient:null==n?void 0:n.transient}})).filter((function(t){return void 0!==t.trait_value||(n.log("Warning - attempted to set an undefined trait value for key",t.trait_key),!1)}))})):n.getJSON(i+"identities/?identifier="+encodeURIComponent(a.identity.identifier)+(a.identity.transient?"&transient=true":""))]).then((function(t){return n.evaluationContext.identity=e(e({},n.evaluationContext.identity),{traits:{}}),r(null==t?void 0:t[0])})).catch((function(t){var e=t.message,n=new Error(e);return Promise.reject(n)})):n.getJSON(i+"flags/").then((function(t){return r({flags:t,traits:void 0})}))},this.analyticsFlags=function(){var t=n.api;if(n.evaluationEvent&&n.evaluationContext.environment&&n.evaluationEvent[n.evaluationContext.environment.apiKey])return n.evaluationEvent&&0!==Object.getOwnPropertyNames(n.evaluationEvent).length&&0!==Object.getOwnPropertyNames(n.evaluationEvent[n.evaluationContext.environment.apiKey]).length?n.getJSON(t+"analytics/flags/","POST",JSON.stringify(n.evaluationEvent[n.evaluationContext.environment.apiKey])).then((function(t){if(n.evaluationContext.environment){var i=n.getState();n.evaluationEvent||(n.evaluationEvent={}),n.evaluationEvent[n.evaluationContext.environment.apiKey]={},n.setState(e(e({},i),{evaluationEvent:n.evaluationEvent})),n.updateEventStorage()}})).catch((function(t){n.log("Exception fetching evaluationEvent",t)})):void 0},this.datadogRum=null,this.loadingState={isLoading:!0,isFetching:!0,error:null,source:l.NONE},this.canUseStorage=!1,this.analyticsInterval=null,this.api=null,this.cacheFlags=!1,this.enableAnalytics=!1,this.enableLogs=!1,this.evaluationContext={},this.evaluationEvent=null,this.flags=null,this.getFlagInterval=null,this.headers=null,this.identity=null,this.initialised=!1,this.oldFlags=null,this.onChange=null,this.onError=null,this.ticks=null,this.timer=null,this.dtrum=null,this.withTraits=null,this.cacheOptions={ttl:0,skipAPI:!1,loadStale:!1,storageKey:void 0},this.getValue=function(t,e,i){var a=n.flags&&n.flags[t.toLowerCase().replace(/ /g,"_")],o=null;if(a&&(o=a.value),(null==e?void 0:e.skipAnalytics)||i||n.evaluateFlag(t,"VALUE"),null===o&&void 0!==(null==e?void 0:e.fallback))return e.fallback;if(null==e?void 0:e.json)try{return null===o?(n.log("Tried to parse null flag as JSON: "+t),null):JSON.parse(o)}catch(t){return e.fallback}return o},this.getTrait=function(t){var e,i;return(null===(e=n.evaluationContext.identity)||void 0===e?void 0:e.traits)&&(null===(i=n.evaluationContext.identity.traits[t.toLowerCase().replace(/ /g,"_")])||void 0===i?void 0:i.value)},this.getAllTraits=function(){var t;return Object.fromEntries(Object.entries((null===(t=n.evaluationContext.identity)||void 0===t?void 0:t.traits)||{}).map((function(t){var e=t[0],n=t[1];return[e,null==n?void 0:n.value]})))},this.setContext=function(t){var i,a,o=v(t);return n.evaluationContext=e(e({},o),{environment:o.environment||n.evaluationContext.environment}),n.identity=null===(a=null===(i=n.getContext())||void 0===i?void 0:i.identity)||void 0===a?void 0:a.identifier,n.initialised?n.getFlags():Promise.resolve()},this.getContext=function(){return n.evaluationContext},this.updateContext=function(t){return n.setContext(e(e({},n.getContext()),t))},this.setTrait=function(t,i){var a;if(n.api)return n.setContext(e(e({},n.evaluationContext),{identity:e(e({},n.evaluationContext.identity),{traits:e(e({},null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.traits),d(Object.fromEntries([[t,i]])))})}))},this.setTraits=function(t){var i;if(n.api)return n.setContext(e(e({},n.evaluationContext),{identity:e(e({},n.evaluationContext.identity),{traits:e(e({},null===(i=n.evaluationContext.identity)||void 0===i?void 0:i.traits),Object.fromEntries(Object.entries(t).map((function(t){var e=t[0],n=t[1];return[e,c(n)?n:{value:n}]}))))})}));console.error("Attempted to "+"setTraits"+" a user before calling flagsmith.init. Call flagsmith.init first, if you wish to prevent it sending a request for flags, call init with preventFetch:true.")},this.hasFeature=function(t,e){var i="object"==typeof e,a=n.flags&&n.flags[t.toLowerCase().replace(/ /g,"_")],o=!1;return!a&&i&&void 0!==e.fallback?o=null==e?void 0:e.fallback:a&&a.enabled&&(o=!0),(i&&!e.skipAnalytics||!e)&&n.evaluateFlag(t,"ENABLED"),o},this.getStorageKey=function(){var t,e;return(null===(t=n.cacheOptions)||void 0===t?void 0:t.storageKey)||"FLAGSMITH_DB_"+(null===(e=n.evaluationContext.environment)||void 0===e?void 0:e.apiKey)},this.getJSON=function(t,e,i){var a,o,r,s=n.headers,l={method:e||"GET",body:i,cache:"no-cache",headers:{}};n.evaluationContext.environment&&(l.headers["X-Environment-Key"]=n.evaluationContext.environment.apiKey),e&&"GET"!==e&&(l.headers["Content-Type"]="application/json; charset=utf-8"),(null===(a=n.applicationMetadata)||void 0===a?void 0:a.name)&&(l.headers["Flagsmith-Application-Name"]=n.applicationMetadata.name),(null===(o=n.applicationMetadata)||void 0===o?void 0:o.version)&&(l.headers["Flagsmith-Application-Version"]=n.applicationMetadata.version),s&&Object.assign(l.headers,s),u||console.error("Flagsmith: fetch is undefined, please specify a fetch implementation into flagsmith.init to support SSR.");var h="".concat(null===(r=n.evaluationContext.identity)||void 0===r?void 0:r.identifier);return u(t,l).then((function(i){var a,o,r="".concat(null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.identifier);if(h===r){var s=null===(o=i.headers)||void 0===o?void 0:o.get("x-flagsmith-document-updated-at");if(s)try{var l=parseFloat(s);if(isNaN(l))return Promise.reject("Failed to parse x-flagsmith-document-updated-at");n.timestamp=l}catch(t){n.log(t,"Failed to parse x-flagsmith-document-updated-at",s)}return n.log("Fetch response: "+i.status+" "+(e||"GET")+0+t),i.text().then((function(t){var e=t;try{e=JSON.parse(t)}catch(t){}return!e&&i.status&&(e="API Response: ".concat(i.status)),i.status&&i.status>=200&&i.status<300?e:Promise.reject(new Error(e))}))}n.log("Received response with identity mismatch, ignoring response. Requested: ".concat(h,", Current: ").concat(r))}))},this.evaluateFlag=function(t,e){if(n.datadogRum&&(n.datadogRum.client.addFeatureFlagEvaluation?"VALUE"===e?n.datadogRum.client.addFeatureFlagEvaluation(S+t,n.getValue(t,{},!0)):n.datadogRum.client.addFeatureFlagEvaluation(_+t,n.hasFeature(t,!0)):console.error("Flagsmith: Your datadog RUM client does not support the function addFeatureFlagEvaluation, please update it.")),n.enableAnalytics){if(!n.evaluationEvent||!n.evaluationContext.environment)return;n.evaluationEvent[n.evaluationContext.environment.apiKey]||(n.evaluationEvent[n.evaluationContext.environment.apiKey]={}),void 0===n.evaluationEvent[n.evaluationContext.environment.apiKey][t]&&(n.evaluationEvent[n.evaluationContext.environment.apiKey][t]=0),n.evaluationEvent[n.evaluationContext.environment.apiKey][t]+=1}n.updateEventStorage()},this._onChange=function(t,e,i){var a,o;n.setLoadingState(i),null===(a=n.onChange)||void 0===a||a.call(n,t,e,n.loadingState),null===(o=n._trigger)||void 0===o||o.call(n)},u=t.fetch?t.fetch:"undefined"!=typeof fetch?fetch:null===global||void 0===global?void 0:global.fetch,this.canUseStorage="undefined"!=typeof window||!!t.browserlessStorage,this.applicationMetadata=t.applicationMetadata,this.log("Constructing flagsmith instance "+t),t.eventSource&&(g=t.eventSource),t.AsyncStorage&&(f=t.AsyncStorage)}return t.prototype.init=function(t){var a,o,r;return n(this,void 0,void 0,(function(){var h,c,d,g,p,S,_,E,C,x,b,O,F,I,w,L,j,A,R,N,T,k,P,D,H,K,M,G,U,J,q,V,X,W=this;return i(this,(function($){switch($.label){case 0:h=v(t.evaluationContext||this.evaluationContext),$.label=1;case 1:if($.trys.push([1,13,,14]),c=t.environmentID,d=t.api,g=void 0===d?m:d,p=t.headers,S=t.onChange,_=t.cacheFlags,E=t.datadogRum,C=t.onError,x=t.defaultFlags,b=t.fetch,O=t.preventFetch,F=t.enableLogs,I=t.enableDynatrace,w=t.enableAnalytics,L=t.realtime,j=t.eventSourceUrl,A=void 0===j?"https://realtime.flagsmith.com/":j,R=t.AsyncStorage,N=t.identity,T=t.traits,k=t.state,P=t.cacheOptions,D=t.angularHttpClient,H=t._trigger,K=t._triggerLoadingState,M=t.applicationMetadata,h.environment=c?{apiKey:c}:h.environment,!h.environment||!h.environment.apiKey)throw new Error("Please provide `evaluationContext.environment` with non-empty `apiKey`");if(h.identity=N||T?{identifier:N,traits:T?Object.fromEntries(Object.entries(T).map((function(t){return[t[0],{value:t[1]}]}))):{}}:h.identity,this.evaluationContext=h,this.api=(B=g).endsWith("/")?B:B+"/",this.headers=p,this.getFlagInterval=null,this.analyticsInterval=null,this.onChange=S,G="Wrong Flagsmith Configuration: preventFetch is true and no defaulFlags provided",this._trigger=H||this._trigger,this._triggerLoadingState=K||this._triggerLoadingState,this.onError=function(t){W.setLoadingState(e(e({},W.loadingState),{isFetching:!1,isLoading:!1,error:t})),null==C||C(t)},this.enableLogs=F||!1,this.cacheOptions=P?{skipAPI:!!P.skipAPI,ttl:P.ttl||0,storageKey:P.storageKey,loadStale:!!P.loadStale}:this.cacheOptions,!this.cacheOptions.ttl&&this.cacheOptions.skipAPI&&console.warn("Flagsmith: you have set a cache ttl of 0 and are skipping API calls, this means the API will not be hit unless you clear local storage."),b&&(u=b),this.enableAnalytics=w||!1,this.flags=Object.assign({},x)||{},this.datadogRum=E||null,this.initialised=!0,this.ticks=1e4,this.timer=this.enableLogs?(new Date).valueOf():null,this.cacheFlags=void 0!==f&&!!_,this.applicationMetadata=M,y="FLAGSMITH_EVENT_"+h.environment.apiKey,R&&(f=R),L&&"undefined"!=typeof window&&this.setupRealtime(A,h.environment.apiKey),Object.keys(this.flags).length&&(this.loadingState=e(e({},this.loadingState),{isLoading:!1,source:l.DEFAULT_FLAGS})),this.setState(k),this.log("Initialising with properties",t,this),I&&("undefined"==typeof dtrum?console.error("You have attempted to enable dynatrace but dtrum is undefined, please check you have the Dynatrace RUM JavaScript API installed."):this.dtrum=dtrum),D&&(u=function(t){return function(e,n){var i=n.headers,a=n.method,o=n.body;return new Promise((function(n){switch(a){case"GET":return t.get(e,{headers:i}).subscribe((function(t){n({ok:!0,text:function(){return Promise.resolve(t)}})}));case"POST":case"PUT":return t.post(e,o,{headers:i}).subscribe((function(t){n({ok:!0,text:function(){return Promise.resolve(t)}})}))}}))}}(D)),f&&this.canUseStorage&&f.getItem(y).then((function(t){try{W.evaluationEvent=JSON.parse(t)||{}}catch(t){W.evaluationEvent={}}W.analyticsInterval=setInterval(W.analyticsFlags,W.ticks)})),this.enableAnalytics&&(this.analyticsInterval&&clearInterval(this.analyticsInterval),f&&this.canUseStorage&&f.getItem(y,(function(t,n){if(n&&W.evaluationContext.environment){var i=JSON.parse(n);if(i[W.evaluationContext.environment.apiKey]){var a=W.getState();W.log("Retrieved events from cache",n),W.setState(e(e({},a),{evaluationEvent:i[W.evaluationContext.environment.apiKey]}))}}}))),!_)return[3,9];if(!f||!this.canUseStorage)return[3,8];U=function(t,a){return n(W,void 0,void 0,(function(){var t,n,o,r,u,h,c,d,g,f,p,y,m,S,_,E,C,b,F,I=this;return i(this,(function(i){switch(i.label){case 0:if(!a)return[3,7];t=null,n=null,i.label=1;case 1:return i.trys.push([1,5,,6]),o=JSON.parse(a),r=!1,u=!1,o&&o.api===this.api&&(null===(f=null===(g=o.evaluationContext)||void 0===g?void 0:g.environment)||void 0===f?void 0:f.apiKey)===(null===(p=this.evaluationContext.environment)||void 0===p?void 0:p.apiKey)&&(h=!0,this.evaluationContext.identity&&(null===(m=null===(y=o.evaluationContext)||void 0===y?void 0:y.identity)||void 0===m?void 0:m.identifier)!==this.evaluationContext.identity.identifier&&(this.log("Ignoring cache, identity has changed from "+(null===(_=null===(S=o.evaluationContext)||void 0===S?void 0:S.identity)||void 0===_?void 0:_.identifier)+" to "+this.evaluationContext.identity.identifier),h=!1),this.cacheOptions.ttl&&(!o.ts||(new Date).valueOf()-o.ts>this.cacheOptions.ttl)&&(o.ts&&!this.cacheOptions.loadStale?(this.log("Ignoring cache, timestamp is too old ts:"+o.ts+" ttl: "+this.cacheOptions.ttl+" time elapsed since cache: "+((new Date).valueOf()-o.ts)+"ms"),h=!1):o.ts&&this.cacheOptions.loadStale&&(this.log("Loading stale cache, timestamp ts:"+o.ts+" ttl: "+this.cacheOptions.ttl+" time elapsed since cache: "+((new Date).valueOf()-o.ts)+"ms"),u=!0,h=!0)),h&&(r=!0,t=s(this.flags,o.flags),this.setState(e(e({},o),{evaluationContext:v(e(e({},o.evaluationContext),{identity:(null===(E=o.evaluationContext)||void 0===E?void 0:E.identity)?e(e({},null===(C=o.evaluationContext)||void 0===C?void 0:C.identity),{traits:e({},T||{})}):void 0}))})),this.log("Retrieved flags from cache",o))),r?(c=!O&&(!this.cacheOptions.skipAPI||u),this._onChange(null,{isFromServer:!1,flagsChanged:t,traitsChanged:n},this._loadedState(null,l.CACHE,c)),this.oldFlags=this.flags,this.cacheOptions.skipAPI&&r&&!u&&this.log("Skipping API, using cache"),c&&this.getFlags().catch((function(t){var e;null===(e=I.onError)||void 0===e||e.call(I,t)})),[3,4]):[3,2];case 2:return O?[3,4]:[4,this.getFlags()];case 3:i.sent(),i.label=4;case 4:return[3,6];case 5:return d=i.sent(),this.log("Exception fetching cached logs",d),[3,6];case 6:return[3,10];case 7:return O?[3,9]:[4,this.getFlags()];case 8:return i.sent(),[3,10];case 9:if(x)this._onChange(null,{isFromServer:!1,flagsChanged:s({},this.flags),traitsChanged:s({},null===(b=this.evaluationContext.identity)||void 0===b?void 0:b.traits)},this._loadedState(null,l.DEFAULT_FLAGS));else{if(!this.flags)throw new Error(G);this._onChange(null,{isFromServer:!1,flagsChanged:s({},this.flags),traitsChanged:s({},null===(F=this.evaluationContext.identity)||void 0===F?void 0:F.traits)},this._loadedState(null,l.DEFAULT_FLAGS))}i.label=10;case 10:return[2]}}))}))},$.label=2;case 2:return $.trys.push([2,7,,8]),f.getItemSync?(J=f.getItemSync(this.getStorageKey()),[3,5]):[3,3];case 3:return[4,f.getItem(this.getStorageKey())];case 4:J=$.sent(),$.label=5;case 5:return[4,U(null,J)];case 6:case 7:return $.sent(),[3,8];case 8:return[3,12];case 9:return O?[3,11]:[4,this.getFlags()];case 10:return $.sent(),[3,12];case 11:if(x)this._onChange(null,{isFromServer:!1,flagsChanged:s({},x),traitsChanged:s({},null===(a=h.identity)||void 0===a?void 0:a.traits)},this._loadedState(null,l.DEFAULT_FLAGS));else if(this.flags&&(q=null,0===Object.keys(this.flags).length&&(q=G),this._onChange(null,{isFromServer:!1,flagsChanged:s({},this.flags),traitsChanged:s({},null===(o=h.identity)||void 0===o?void 0:o.traits)},this._loadedState(q,l.DEFAULT_FLAGS)),q))throw new Error(q);$.label=12;case 12:return[3,14];case 13:throw V=$.sent(),this.log("Error during initialisation ",V),X=V instanceof Error?V:new Error("".concat(V)),null===(r=this.onError)||void 0===r||r.call(this,X),V;case 14:return[2]}var B}))}))},t.prototype.getAllFlags=function(){return this.flags},t.prototype.identify=function(t,e,n){return this.identity=t,this.evaluationContext.identity={identifier:t,transient:n,traits:this.evaluationContext.identity&&this.evaluationContext.identity.identifier==t?this.evaluationContext.identity.traits:{}},this.evaluationContext.identity.identifier=t,this.log("Identify: "+this.evaluationContext.identity.identifier),e&&(this.evaluationContext.identity.traits=Object.fromEntries(Object.entries(e).map((function(t){var e=t[0],n=t[1];return[e,c(n)?n:{value:n}]})))),this.initialised?this.getFlags():Promise.resolve()},t.prototype.getState=function(){return{api:this.api,flags:this.flags,ts:this.ts,evaluationContext:this.evaluationContext,identity:this.identity,evaluationEvent:this.evaluationEvent}},t.prototype.setState=function(t){var e,n;t&&(this.initialised=!0,this.api=t.api||this.api||m,this.flags=t.flags||this.flags,this.evaluationContext=t.evaluationContext||this.evaluationContext,this.evaluationEvent=t.evaluationEvent||this.evaluationEvent,this.identity=null===(n=null===(e=this.getContext())||void 0===e?void 0:e.identity)||void 0===n?void 0:n.identifier,this.log("setState called",this))},t.prototype.logout=function(){return this.identity=null,this.evaluationContext.identity=null,this.initialised?this.getFlags():Promise.resolve()},t.prototype.startListening=function(t){void 0===t&&(t=1e3),this.getFlagInterval&&clearInterval(this.getFlagInterval),this.getFlagInterval=setInterval(this.getFlags,t)},t.prototype.stopListening=function(){this.getFlagInterval&&(clearInterval(this.getFlagInterval),this.getFlagInterval=null)},t.prototype._loadedState=function(t,e,n){return void 0===t&&(t=null),void 0===n&&(n=!1),{error:t,isFetching:n,isLoading:!1,source:e}},t.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.enableLogs&&console.log.apply(this,a(["FLAGSMITH:",(new Date).valueOf()-(this.timer||0),"ms"],t,!0))},t.prototype.updateStorage=function(){if(this.cacheFlags){this.ts=(new Date).valueOf();var t=JSON.stringify(this.getState());this.log("Setting storage",t),f.setItem(this.getStorageKey(),t)}},t.prototype.updateEventStorage=function(){if(this.enableAnalytics){var t=JSON.stringify(this.getState().evaluationEvent);f.setItem(y,t).catch((function(t){return console.error("Flagsmith: Error setting item in async storage",t)}))}},t.prototype.setLoadingState=function(t){var n;r(t,this.loadingState)||(this.loadingState=e({},t),this.log("Loading state changed",t),null===(n=this._triggerLoadingState)||void 0===n||n.call(this))},t.prototype.setupRealtime=function(t,e){var n=this,i=t+"sse/environments/"+e+"/stream";g?this.eventSource||(this.log("Creating event source with url "+i),this.eventSource=new g(i),this.eventSource.addEventListener("environment_updated",(function(t){var e;try{e=JSON.parse(t.data).updated_at}catch(t){n.log("Could not parse sse event",t)}e?!n.timestamp||e>n.timestamp?n.isLoading?n.log("updated_at is new, but flags are loading",t.data,n.timestamp):(n.log("updated_at is new, fetching flags",t.data,n.timestamp),n.getFlags()):n.log("updated_at is outdated, skipping get flags",t.data,n.timestamp):n.log("No updated_at received, fetching flags",t)}))):this.log("Error, EventSource is undefined")},t}();function x(t){var e=t.fetch,n=t.AsyncStorage,i=t.eventSource;return new C({fetch:e,AsyncStorage:n,eventSource:i})}var b,O=o(Object.freeze({__proto__:null,default:class{ERROR=-1;CONNECTING=0;OPEN=1;CLOSED=2;constructor(t,e={}){if(this.interval=e.pollingInterval||5e3,this.lastEventId=null,this.lastIndexProcessed=0,this.eventType=void 0,this.status=this.CONNECTING,this.eventHandlers={open:[],message:[],error:[],close:[]},this.method=e.method||"GET",this.timeout=e.timeOut||0,this.headers=e.headers||{},this.body=e.body||void 0,this.debug=e.debug||!1,this._xhr=null,this._pollTimer=null,!t||"string"!=typeof t&&"function"!=typeof t.toString)throw new SyntaxError("[EventSource] Invalid URL argument.");"function"==typeof t.toString?this.url=t.toString():this.url=t,this._pollAgain(500)}_pollAgain(t){this._pollTimer=setTimeout((()=>{this.open()}),t)}open(){try{if(this.lastIndexProcessed=0,this.status=this.CONNECTING,this._xhr=new XMLHttpRequest,this._xhr.open(this.method,this.url,!0),this.headers)for(const[t,e]of Object.entries(this.headers))this._xhr.setRequestHeader(t,e);this._xhr.setRequestHeader("Accept","text/event-stream"),this._xhr.setRequestHeader("Cache-Control","no-cache"),this._xhr.setRequestHeader("X-Requested-With","XMLHttpRequest"),null!==this.lastEventId&&this._xhr.setRequestHeader("Last-Event-ID",this.lastEventId),this._xhr.timeout=this.timeout,this._xhr.onreadystatechange=()=>{const t=this._xhr;this.debug&&console.debug(`[EventSource][onreadystatechange] ReadyState: ${t.readyState}, status: ${t.status}`),[XMLHttpRequest.DONE,XMLHttpRequest.LOADING].includes(t.readyState)&&(t.status>=200&&t.status<400?(this.status===this.CONNECTING&&(this.status=this.OPEN,this.dispatch("open",{type:"open"})),this._handleEvent(t.responseText||""),t.readyState===XMLHttpRequest.DONE&&(this.debug&&console.debug("[EventSource][onreadystatechange][DONE] Operation done. Reconnecting..."),this._pollAgain(this.interval))):this.status!==this.CLOSED&&(0!==this._xhr.status&&this.dispatch("error",{type:"error",message:t.responseText,xhrStatus:t.status,xhrState:t.readyState}),[XMLHttpRequest.DONE,XMLHttpRequest.UNSENT].includes(t.readyState)&&(this.debug&&console.debug("[EventSource][onreadystatechange][ERROR] Response status error. Reconnecting..."),this._pollAgain(this.interval))))},this._xhr.onerror=t=>{this.status,this.ERROR,this.dispatch("error",{type:"error",message:this._xhr.responseText,xhrStatus:this._xhr.status,xhrState:this._xhr.readyState})},this.body?this._xhr.send(this.body):this._xhr.send(),this.timeout>0&&setTimeout((()=>{this._xhr.readyState===XMLHttpRequest.LOADING&&(this.dispatch("error",{type:"timeout"}),this.close())}),this.timeout)}catch(t){this.status=this.ERROR,this.dispatch("error",{type:"exception",message:t.message,error:t})}}_handleEvent(t){const e=t.substr(this.lastIndexProcessed).split("\n");this.lastIndexProcessed=t.lastIndexOf("\n\n")+2;let n=[],i=0,a="";for(let t=0;t<e.length;t++)if(a=e[t].replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g,""),0===a.indexOf("event"))this.eventType=a.replace(/event:?\s*/,"");else if(0===a.indexOf("retry"))i=parseInt(a.replace(/retry:?\s*/,""),10),isNaN(i)||(this.interval=i);else if(0===a.indexOf("data"))n.push(a.replace(/data:?\s*/,""));else if(0===a.indexOf("id:"))this.lastEventId=a.replace(/id:?\s*/,"");else if(0===a.indexOf("id"))this.lastEventId=null;else if(""===a&&n.length>0){const t=this.eventType||"message",e={type:t,data:n.join("\n"),url:this.url,lastEventId:this.lastEventId};this.dispatch(t,e),n=[],this.eventType=void 0}}addEventListener(t,e){void 0===this.eventHandlers[t]&&(this.eventHandlers[t]=[]),this.eventHandlers[t].push(e)}removeEventListener(t,e){void 0!==this.eventHandlers[t]&&(this.eventHandlers[t]=this.eventHandlers[t].filter((t=>t!==e)))}removeAllEventListeners(t){const e=Object.keys(this.eventHandlers);if(void 0===t)for(const t of e)this.eventHandlers[t]=[];else{if(!e.includes(t))throw Error(`[EventSource] '${t}' type is not supported event type.`);this.eventHandlers[t]=[]}}dispatch(t,e){if(Object.keys(this.eventHandlers).includes(t))for(const n of Object.values(this.eventHandlers[t]))n(e)}close(){this.status=this.CLOSED,clearTimeout(this._pollTimer),this._xhr&&this._xhr.abort(),this.dispatch("close",{type:"close"})}}})),F=(b=function(t,e){return b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},b(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}b(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),I=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],i=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},w=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,a,o=n.call(t),r=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)r.push(i.value)}catch(t){a={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return r},L=function(t,e,n){if(n||2===arguments.length)for(var i,a=0,o=e.length;a<o;a++)!i&&a in e||(i||(i=Array.prototype.slice.call(e,0,a)),i[a]=e[a]);return t.concat(i||Array.prototype.slice.call(e))},j=function(t){function e(){return t.call(this,"EventSource not available.\nConsider loading an EventSource polyfill and making it available globally as EventSource, or passing one in as eventSourceClass to the ReconnectingEventSource constructor.")||this}return F(e,t),e}(Error),A=function(){function t(t,e){var n=this;if(this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,this._configuration=null!=e?Object.assign({},e):void 0,this.withCredentials=!1,this._eventSource=null,this._lastEventId=null,this._timer=null,this._listeners={open:[],error:[],message:[]},this.url=t.toString(),this.readyState=this.CONNECTING,this.max_retry_time=3e3,this.eventSourceClass=globalThis.FlagsmithEventSource,null!=this._configuration&&(this._configuration.lastEventId&&(this._lastEventId=this._configuration.lastEventId,delete this._configuration.lastEventId),this._configuration.max_retry_time&&(this.max_retry_time=this._configuration.max_retry_time,delete this._configuration.max_retry_time),this._configuration.eventSourceClass&&(this.eventSourceClass=this._configuration.eventSourceClass,delete this._configuration.eventSourceClass)),null==this.eventSourceClass||"function"!=typeof this.eventSourceClass)throw new j;this._onevent_wrapped=function(t){n._onevent(t)},this._start()}return t.prototype.dispatchEvent=function(t){throw new Error("Method not implemented.")},t.prototype._start=function(){var t,e,n=this,i=this.url;this._lastEventId&&(-1===i.indexOf("?")?i+="?":i+="&",i+="lastEventId="+encodeURIComponent(this._lastEventId)),this._eventSource=new this.eventSourceClass(i,this._configuration),this._eventSource.onopen=function(t){n._onopen(t)},this._eventSource.onerror=function(t){n._onerror(t)},this._eventSource.onmessage=function(t){n.onmessage(t)};try{for(var a=I(Object.keys(this._listeners)),o=a.next();!o.done;o=a.next()){var r=o.value;this._eventSource.addEventListener(r,this._onevent_wrapped)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}},t.prototype._onopen=function(t){0===this.readyState&&(this.readyState=1,this.onopen(t))},t.prototype._onerror=function(t){var e=this;if(1===this.readyState&&(this.readyState=0,this.onerror(t)),this._eventSource){this._eventSource.close(),this._eventSource=null;var n=Math.round(this.max_retry_time*Math.random());this._timer=setTimeout((function(){return e._start()}),n)}},t.prototype._onevent=function(t){var e,n;t&&t.lastEventId&&(this._lastEventId=t.lastEventId);var i=this._listeners[t.type];if(null!=i)try{for(var a=I(L([],w(i),!1)),o=a.next();!o.done;o=a.next()){o.value.call(this,t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}"message"===t.type&&this.onmessage(t)},t.prototype.onopen=function(t){},t.prototype.onerror=function(t){},t.prototype.onmessage=function(t){},t.prototype.close=function(){this._timer&&(clearTimeout(this._timer),this._timer=null),this._eventSource&&(this._eventSource.close(),this._eventSource=null),this.readyState=2},t.prototype.addEventListener=function(t,e,n){null==this._listeners[t]&&(this._listeners[t]=[],null!=this._eventSource&&this._eventSource.addEventListener(t,this._onevent_wrapped));var i=this._listeners[t];i.includes(e)||(this._listeners[t]=L(L([],w(i),!1),[e],!1))},t.prototype.removeEventListener=function(t,e,n){var i=this._listeners[t];this._listeners[t]=i.filter((function(t){return t!==e}))},t}();global.FlagsmithEventSource=O.default;var R=x({browserlessStorage:!0,eventSource:A});t.createFlagsmithInstance=()=>x({browserlessStorage:!0,eventSource:A}),t.default=R,Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).index={})}(this,(function(t){"use strict";var e=function(){return e=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},e.apply(this,arguments)};function n(t,e,n,i){return new(n||(n=Promise))((function(a,o){function r(t){try{l(i.next(t))}catch(t){o(t)}}function s(t){try{l(i.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,s)}l((i=i.apply(t,e||[])).next())}))}function i(t,e){var n,i,a,o,r={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,i&&(a=2&o[0]?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return r.label++,{value:o[1],done:!1};case 5:r.label++,i=o[1],o=[0];continue;case 7:o=r.ops.pop(),r.trys.pop();continue;default:if(!(a=r.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){r=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){r.label=o[1];break}if(6===o[0]&&r.label<a[1]){r.label=a[1],a=o;break}if(a&&r.label<a[2]){r.label=a[2],r.ops.push(o);break}a[2]&&r.ops.pop(),r.trys.pop();continue}o=e.call(t,r)}catch(t){o=[6,t],i=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function a(t,e,n){if(n||2===arguments.length)for(var i,a=0,o=e.length;a<o;a++)!i&&a in e||(i||(i=Array.prototype.slice.call(e,0,a)),i[a]=e[a]);return t.concat(i||Array.prototype.slice.call(e))}function o(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})})),e}var r=function t(e,n){if(e===n)return!0;if(e&&n&&"object"==typeof e&&"object"==typeof n){if(e.constructor!==n.constructor)return!1;var i,a,o;if(Array.isArray(e)){if((i=e.length)!=n.length)return!1;for(a=i;0!=a--;)if(!t(e[a],n[a]))return!1;return!0}if(e.constructor===RegExp)return e.source===n.source&&e.flags===n.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===n.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===n.toString();if((i=(o=Object.keys(e)).length)!==Object.keys(n).length)return!1;for(a=i;0!=a--;)if(!Object.prototype.hasOwnProperty.call(n,o[a]))return!1;for(a=i;0!=a--;){var r=o[a];if(!t(e[r],n[r]))return!1}return!0}return e!=e&&n!=n};function s(t,e){var n=Object.keys(e||{}).filter((function(n){var i=null==t?void 0:t[n],a=null==e?void 0:e[n];return!r(i,a)}));return Object.keys(t||{}).filter((function(t){Object.keys(e||{}).includes(t)||n.push(t)})),Object.keys(n).length?n:null}var l,u;function h(t,e,n){var i="shortString",a=!0;"number"==typeof n&&(i="javaDouble",a=!1),t[i]=t[i]||{},t[i][e]=a?n+"":n}function c(t){return!!t&&"object"==typeof t&&void 0!==t.value}function d(t){return Object.fromEntries(Object.entries(t).map((function(t){var e=t[0],n=t[1];return[e,c(n)?n:{value:n}]})))}function v(t){return e(e({},t),{identity:t.identity?e(e({},t.identity),{traits:d(t.identity.traits||{})}):void 0})}!function(t){t.NONE="NONE",t.DEFAULT_FLAGS="DEFAULT_FLAGS",t.CACHE="CACHE",t.SERVER="SERVER"}(l||(l={}));var g,f=null,p="FLAGSMITH_EVENT",y=p,m="https://edge.api.flagsmith.com/api/v1/",S="flagsmith_value_",_="flagsmith_enabled_",E="flagsmith_trait_",C=function(){function t(t){var n=this;this._trigger=null,this._triggerLoadingState=null,this.timestamp=null,this.isLoading=!1,this.eventSource=null,this.getFlags=function(){var t=n,i=t.api,a=t.evaluationContext;n.log("Get Flags"),n.isLoading=!0,n.loadingState.isFetching||n.setLoadingState(e(e({},n.loadingState),{isFetching:!0}));var o="".concat(n.getContext().identity),r=function(t){var i,a,r,u;if(t&&o==="".concat(n.getContext().identity)){var c=t.flags,d=t.traits,v=t.identifier;n.isLoading=!1;var g={},f={};d=d||[],(c=c||[]).forEach((function(t){g[t.feature.name.toLowerCase().replace(/ /g,"_")]={id:t.feature.id,enabled:t.enabled,value:t.feature_state_value}})),d.forEach((function(t){f[t.trait_key.toLowerCase().replace(/ /g,"_")]={transient:t.transient,value:t.trait_value}})),n.oldFlags=e({},n.flags);var p=s(n.oldFlags,g),y=s(null===(i=n.evaluationContext.identity)||void 0===i?void 0:i.traits,f);if((v||Object.keys(f).length)&&(n.evaluationContext.identity=e(e({},n.evaluationContext.identity),{traits:f}),v&&(n.evaluationContext.identity.identifier=v,n.identity=v)),n.flags=g,n.updateStorage(),n._onChange(n.oldFlags,{isFromServer:!0,flagsChanged:p,traitsChanged:y},n._loadedState(null,l.SERVER)),n.datadogRum)try{if(n.datadogRum.trackTraits){var m={};Object.keys((null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.traits)||{}).map((function(t){m[E+t]=n.getTrait(t)}));var C=e(e(e({},n.datadogRum.client.getUser()),{id:n.datadogRum.client.getUser().id||(null===(r=n.evaluationContext.identity)||void 0===r?void 0:r.identifier)}),m);n.log("Setting Datadog user",C),n.datadogRum.client.setUser(C)}}catch(t){console.error(t)}if(n.dtrum)try{var x={javaDouble:{},date:{},shortString:{},javaLongOrObject:{}};Object.keys(n.flags).map((function(t){h(x,S+t,n.getValue(t,{skipAnalytics:!0})),h(x,_+t,n.hasFeature(t,{skipAnalytics:!0}))})),Object.keys((null===(u=n.evaluationContext.identity)||void 0===u?void 0:u.traits)||{}).map((function(t){h(x,E+t,n.getTrait(t))})),n.log("Sending javaLongOrObject traits to dynatrace",x.javaLongOrObject),n.log("Sending date traits to dynatrace",x.date),n.log("Sending shortString traits to dynatrace",x.shortString),n.log("Sending javaDouble to dynatrace",x.javaDouble),n.dtrum.sendSessionProperties(x.javaLongOrObject,x.date,x.shortString,x.javaDouble)}catch(t){console.error(t)}}};return a.identity?Promise.all([a.identity.traits&&Object.keys(a.identity.traits).length||!a.identity.identifier?n.getJSON(i+"identities/","POST",JSON.stringify({identifier:a.identity.identifier,transient:a.identity.transient,traits:Object.entries(a.identity.traits).map((function(t){var e=t[0],n=t[1];return{trait_key:e,trait_value:null==n?void 0:n.value,transient:null==n?void 0:n.transient}})).filter((function(t){return void 0!==t.trait_value||(n.log("Warning - attempted to set an undefined trait value for key",t.trait_key),!1)}))})):n.getJSON(i+"identities/?identifier="+encodeURIComponent(a.identity.identifier)+(a.identity.transient?"&transient=true":""))]).then((function(t){return n.evaluationContext.identity=e(e({},n.evaluationContext.identity),{traits:{}}),r(null==t?void 0:t[0])})).catch((function(t){var e=t.message,n=new Error(e);return Promise.reject(n)})):n.getJSON(i+"flags/").then((function(t){return r({flags:t,traits:void 0})}))},this.analyticsFlags=function(){var t=n.api;if(n.evaluationEvent&&n.evaluationContext.environment&&n.evaluationEvent[n.evaluationContext.environment.apiKey])return n.evaluationEvent&&0!==Object.getOwnPropertyNames(n.evaluationEvent).length&&0!==Object.getOwnPropertyNames(n.evaluationEvent[n.evaluationContext.environment.apiKey]).length?n.getJSON(t+"analytics/flags/","POST",JSON.stringify(n.evaluationEvent[n.evaluationContext.environment.apiKey])).then((function(t){if(n.evaluationContext.environment){var i=n.getState();n.evaluationEvent||(n.evaluationEvent={}),n.evaluationEvent[n.evaluationContext.environment.apiKey]={},n.setState(e(e({},i),{evaluationEvent:n.evaluationEvent})),n.updateEventStorage()}})).catch((function(t){n.log("Exception fetching evaluationEvent",t)})):void 0},this.datadogRum=null,this.loadingState={isLoading:!0,isFetching:!0,error:null,source:l.NONE},this.canUseStorage=!1,this.analyticsInterval=null,this.api=null,this.cacheFlags=!1,this.enableAnalytics=!1,this.enableLogs=!1,this.evaluationContext={},this.evaluationEvent=null,this.flags=null,this.getFlagInterval=null,this.headers=null,this.identity=null,this.initialised=!1,this.oldFlags=null,this.onChange=null,this.onError=null,this.ticks=null,this.timer=null,this.dtrum=null,this.sentryClient=null,this.withTraits=null,this.cacheOptions={ttl:0,skipAPI:!1,loadStale:!1,storageKey:void 0},this.getValue=function(t,e,i){var a=n.flags&&n.flags[t.toLowerCase().replace(/ /g,"_")],o=null;if(a&&(o=a.value),(null==e?void 0:e.skipAnalytics)||i||n.evaluateFlag(t,"VALUE"),null===o&&void 0!==(null==e?void 0:e.fallback))return e.fallback;if(null==e?void 0:e.json)try{return null===o?(n.log("Tried to parse null flag as JSON: "+t),null):JSON.parse(o)}catch(t){return e.fallback}return o},this.getTrait=function(t){var e,i;return(null===(e=n.evaluationContext.identity)||void 0===e?void 0:e.traits)&&(null===(i=n.evaluationContext.identity.traits[t.toLowerCase().replace(/ /g,"_")])||void 0===i?void 0:i.value)},this.getAllTraits=function(){var t;return Object.fromEntries(Object.entries((null===(t=n.evaluationContext.identity)||void 0===t?void 0:t.traits)||{}).map((function(t){var e=t[0],n=t[1];return[e,null==n?void 0:n.value]})))},this.setContext=function(t){var i,a,o=v(t);return n.evaluationContext=e(e({},o),{environment:o.environment||n.evaluationContext.environment}),n.identity=null===(a=null===(i=n.getContext())||void 0===i?void 0:i.identity)||void 0===a?void 0:a.identifier,n.initialised?n.getFlags():Promise.resolve()},this.getContext=function(){return n.evaluationContext},this.updateContext=function(t){return n.setContext(e(e({},n.getContext()),t))},this.setTrait=function(t,i){var a;if(n.api)return n.setContext(e(e({},n.evaluationContext),{identity:e(e({},n.evaluationContext.identity),{traits:e(e({},null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.traits),d(Object.fromEntries([[t,i]])))})}))},this.setTraits=function(t){var i;if(n.api)return n.setContext(e(e({},n.evaluationContext),{identity:e(e({},n.evaluationContext.identity),{traits:e(e({},null===(i=n.evaluationContext.identity)||void 0===i?void 0:i.traits),Object.fromEntries(Object.entries(t).map((function(t){var e=t[0],n=t[1];return[e,c(n)?n:{value:n}]}))))})}));console.error("Attempted to "+"setTraits"+" a user before calling flagsmith.init. Call flagsmith.init first, if you wish to prevent it sending a request for flags, call init with preventFetch:true.")},this.hasFeature=function(t,e){var i,a,o="object"==typeof e,r=n.flags&&n.flags[t.toLowerCase().replace(/ /g,"_")],s=!1;if(!r&&o&&void 0!==e.fallback?s=null==e?void 0:e.fallback:r&&r.enabled&&(s=!0),(o&&!e.skipAnalytics||!e)&&n.evaluateFlag(t,"ENABLED"),n.sentryClient)try{null===(a=null===(i=n.sentryClient.getIntegrationByName("FeatureFlags"))||void 0===i?void 0:i.addFeatureFlag)||void 0===a||a.call(i,t,s)}catch(t){console.error(t)}return s},this.getStorageKey=function(){var t,e;return(null===(t=n.cacheOptions)||void 0===t?void 0:t.storageKey)||"FLAGSMITH_DB_"+(null===(e=n.evaluationContext.environment)||void 0===e?void 0:e.apiKey)},this.getJSON=function(t,e,i){var a,o,r,s=n.headers,l={method:e||"GET",body:i,cache:"no-cache",headers:{}};n.evaluationContext.environment&&(l.headers["X-Environment-Key"]=n.evaluationContext.environment.apiKey),e&&"GET"!==e&&(l.headers["Content-Type"]="application/json; charset=utf-8"),(null===(a=n.applicationMetadata)||void 0===a?void 0:a.name)&&(l.headers["Flagsmith-Application-Name"]=n.applicationMetadata.name),(null===(o=n.applicationMetadata)||void 0===o?void 0:o.version)&&(l.headers["Flagsmith-Application-Version"]=n.applicationMetadata.version),s&&Object.assign(l.headers,s),u||console.error("Flagsmith: fetch is undefined, please specify a fetch implementation into flagsmith.init to support SSR.");var h="".concat(null===(r=n.evaluationContext.identity)||void 0===r?void 0:r.identifier);return u(t,l).then((function(i){var a,o,r="".concat(null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.identifier);if(h===r){var s=null===(o=i.headers)||void 0===o?void 0:o.get("x-flagsmith-document-updated-at");if(s)try{var l=parseFloat(s);if(isNaN(l))return Promise.reject("Failed to parse x-flagsmith-document-updated-at");n.timestamp=l}catch(t){n.log(t,"Failed to parse x-flagsmith-document-updated-at",s)}return n.log("Fetch response: "+i.status+" "+(e||"GET")+0+t),i.text().then((function(t){var e=t;try{e=JSON.parse(t)}catch(t){}return!e&&i.status&&(e="API Response: ".concat(i.status)),i.status&&i.status>=200&&i.status<300?e:Promise.reject(new Error(e))}))}n.log("Received response with identity mismatch, ignoring response. Requested: ".concat(h,", Current: ").concat(r))}))},this.evaluateFlag=function(t,e){if(n.datadogRum&&(n.datadogRum.client.addFeatureFlagEvaluation?"VALUE"===e?n.datadogRum.client.addFeatureFlagEvaluation(S+t,n.getValue(t,{},!0)):n.datadogRum.client.addFeatureFlagEvaluation(_+t,n.hasFeature(t,!0)):console.error("Flagsmith: Your datadog RUM client does not support the function addFeatureFlagEvaluation, please update it.")),n.enableAnalytics){if(!n.evaluationEvent||!n.evaluationContext.environment)return;n.evaluationEvent[n.evaluationContext.environment.apiKey]||(n.evaluationEvent[n.evaluationContext.environment.apiKey]={}),void 0===n.evaluationEvent[n.evaluationContext.environment.apiKey][t]&&(n.evaluationEvent[n.evaluationContext.environment.apiKey][t]=0),n.evaluationEvent[n.evaluationContext.environment.apiKey][t]+=1}n.updateEventStorage()},this._onChange=function(t,e,i){var a,o;n.setLoadingState(i),null===(a=n.onChange)||void 0===a||a.call(n,t,e,n.loadingState),null===(o=n._trigger)||void 0===o||o.call(n)},u=t.fetch?t.fetch:"undefined"!=typeof fetch?fetch:null===global||void 0===global?void 0:global.fetch,this.canUseStorage="undefined"!=typeof window||!!t.browserlessStorage,this.applicationMetadata=t.applicationMetadata,this.log("Constructing flagsmith instance "+t),t.eventSource&&(g=t.eventSource),t.AsyncStorage&&(f=t.AsyncStorage)}return t.prototype.init=function(t){var a,o,r;return n(this,void 0,void 0,(function(){var h,c,d,g,p,S,_,E,C,x,b,O,F,I,w,L,j,A,N,R,T,k,P,D,H,K,M,G,U,J,q,V,X,W,$=this;return i(this,(function(B){switch(B.label){case 0:h=v(t.evaluationContext||this.evaluationContext),B.label=1;case 1:if(B.trys.push([1,13,,14]),c=t.AsyncStorage,d=t._trigger,g=t._triggerLoadingState,p=t.angularHttpClient,S=t.api,_=void 0===S?m:S,E=t.applicationMetadata,C=t.cacheFlags,x=t.cacheOptions,b=t.datadogRum,O=t.defaultFlags,F=t.enableAnalytics,I=t.enableDynatrace,w=t.enableLogs,L=t.environmentID,j=t.eventSourceUrl,A=void 0===j?"https://realtime.flagsmith.com/":j,N=t.fetch,R=t.headers,T=t.identity,k=t.onChange,P=t.onError,D=t.preventFetch,H=t.realtime,K=t.sentryClient,M=t.state,G=t.traits,h.environment=L?{apiKey:L}:h.environment,!h.environment||!h.environment.apiKey)throw new Error("Please provide `evaluationContext.environment` with non-empty `apiKey`");if(h.identity=T||G?{identifier:T,traits:G?Object.fromEntries(Object.entries(G).map((function(t){return[t[0],{value:t[1]}]}))):{}}:h.identity,this.evaluationContext=h,this.api=(Y=_).endsWith("/")?Y:Y+"/",this.headers=R,this.getFlagInterval=null,this.analyticsInterval=null,this.onChange=k,U="Wrong Flagsmith Configuration: preventFetch is true and no defaulFlags provided",this._trigger=d||this._trigger,this._triggerLoadingState=g||this._triggerLoadingState,this.onError=function(t){$.setLoadingState(e(e({},$.loadingState),{isFetching:!1,isLoading:!1,error:t})),null==P||P(t)},this.enableLogs=w||!1,this.cacheOptions=x?{skipAPI:!!x.skipAPI,ttl:x.ttl||0,storageKey:x.storageKey,loadStale:!!x.loadStale}:this.cacheOptions,!this.cacheOptions.ttl&&this.cacheOptions.skipAPI&&console.warn("Flagsmith: you have set a cache ttl of 0 and are skipping API calls, this means the API will not be hit unless you clear local storage."),N&&(u=N),this.enableAnalytics=F||!1,this.flags=Object.assign({},O)||{},this.datadogRum=b||null,this.initialised=!0,this.ticks=1e4,this.timer=this.enableLogs?(new Date).valueOf():null,this.cacheFlags=void 0!==f&&!!C,this.applicationMetadata=E,y="FLAGSMITH_EVENT_"+h.environment.apiKey,c&&(f=c),H&&"undefined"!=typeof window&&this.setupRealtime(A,h.environment.apiKey),Object.keys(this.flags).length&&(this.loadingState=e(e({},this.loadingState),{isLoading:!1,source:l.DEFAULT_FLAGS})),this.setState(M),this.log("Initialising with properties",t,this),I&&("undefined"==typeof dtrum?console.error("You have attempted to enable dynatrace but dtrum is undefined, please check you have the Dynatrace RUM JavaScript API installed."):this.dtrum=dtrum),K&&(this.sentryClient=K),p&&(u=function(t){return function(e,n){var i=n.headers,a=n.method,o=n.body;return new Promise((function(n){switch(a){case"GET":return t.get(e,{headers:i}).subscribe((function(t){n({ok:!0,text:function(){return Promise.resolve(t)}})}));case"POST":case"PUT":return t.post(e,o,{headers:i}).subscribe((function(t){n({ok:!0,text:function(){return Promise.resolve(t)}})}))}}))}}(p)),f&&this.canUseStorage&&f.getItem(y).then((function(t){try{$.evaluationEvent=JSON.parse(t)||{}}catch(t){$.evaluationEvent={}}$.analyticsInterval=setInterval($.analyticsFlags,$.ticks)})),this.enableAnalytics&&(this.analyticsInterval&&clearInterval(this.analyticsInterval),f&&this.canUseStorage&&f.getItem(y,(function(t,n){if(n&&$.evaluationContext.environment){var i=JSON.parse(n);if(i[$.evaluationContext.environment.apiKey]){var a=$.getState();$.log("Retrieved events from cache",n),$.setState(e(e({},a),{evaluationEvent:i[$.evaluationContext.environment.apiKey]}))}}}))),!C)return[3,9];if(!f||!this.canUseStorage)return[3,8];J=function(t,a){return n($,void 0,void 0,(function(){var t,n,o,r,u,h,c,d,g,f,p,y,m,S,_,E,C,x,b,F=this;return i(this,(function(i){switch(i.label){case 0:if(!a)return[3,7];t=null,n=null,i.label=1;case 1:return i.trys.push([1,5,,6]),o=JSON.parse(a),r=!1,u=!1,o&&o.api===this.api&&(null===(f=null===(g=o.evaluationContext)||void 0===g?void 0:g.environment)||void 0===f?void 0:f.apiKey)===(null===(p=this.evaluationContext.environment)||void 0===p?void 0:p.apiKey)&&(h=!0,this.evaluationContext.identity&&(null===(m=null===(y=o.evaluationContext)||void 0===y?void 0:y.identity)||void 0===m?void 0:m.identifier)!==this.evaluationContext.identity.identifier&&(this.log("Ignoring cache, identity has changed from "+(null===(_=null===(S=o.evaluationContext)||void 0===S?void 0:S.identity)||void 0===_?void 0:_.identifier)+" to "+this.evaluationContext.identity.identifier),h=!1),this.cacheOptions.ttl&&(!o.ts||(new Date).valueOf()-o.ts>this.cacheOptions.ttl)&&(o.ts&&!this.cacheOptions.loadStale?(this.log("Ignoring cache, timestamp is too old ts:"+o.ts+" ttl: "+this.cacheOptions.ttl+" time elapsed since cache: "+((new Date).valueOf()-o.ts)+"ms"),h=!1):o.ts&&this.cacheOptions.loadStale&&(this.log("Loading stale cache, timestamp ts:"+o.ts+" ttl: "+this.cacheOptions.ttl+" time elapsed since cache: "+((new Date).valueOf()-o.ts)+"ms"),u=!0,h=!0)),h&&(r=!0,t=s(this.flags,o.flags),this.setState(e(e({},o),{evaluationContext:v(e(e({},o.evaluationContext),{identity:(null===(E=o.evaluationContext)||void 0===E?void 0:E.identity)?e(e({},null===(C=o.evaluationContext)||void 0===C?void 0:C.identity),{traits:e({},G||{})}):void 0}))})),this.log("Retrieved flags from cache",o))),r?(c=!D&&(!this.cacheOptions.skipAPI||u),this._onChange(null,{isFromServer:!1,flagsChanged:t,traitsChanged:n},this._loadedState(null,l.CACHE,c)),this.oldFlags=this.flags,this.cacheOptions.skipAPI&&r&&!u&&this.log("Skipping API, using cache"),c&&this.getFlags().catch((function(t){var e;null===(e=F.onError)||void 0===e||e.call(F,t)})),[3,4]):[3,2];case 2:return D?[3,4]:[4,this.getFlags()];case 3:i.sent(),i.label=4;case 4:return[3,6];case 5:return d=i.sent(),this.log("Exception fetching cached logs",d),[3,6];case 6:return[3,10];case 7:return D?[3,9]:[4,this.getFlags()];case 8:return i.sent(),[3,10];case 9:if(O)this._onChange(null,{isFromServer:!1,flagsChanged:s({},this.flags),traitsChanged:s({},null===(x=this.evaluationContext.identity)||void 0===x?void 0:x.traits)},this._loadedState(null,l.DEFAULT_FLAGS));else{if(!this.flags)throw new Error(U);this._onChange(null,{isFromServer:!1,flagsChanged:s({},this.flags),traitsChanged:s({},null===(b=this.evaluationContext.identity)||void 0===b?void 0:b.traits)},this._loadedState(null,l.DEFAULT_FLAGS))}i.label=10;case 10:return[2]}}))}))},B.label=2;case 2:return B.trys.push([2,7,,8]),f.getItemSync?(q=f.getItemSync(this.getStorageKey()),[3,5]):[3,3];case 3:return[4,f.getItem(this.getStorageKey())];case 4:q=B.sent(),B.label=5;case 5:return[4,J(null,q)];case 6:case 7:return B.sent(),[3,8];case 8:return[3,12];case 9:return D?[3,11]:[4,this.getFlags()];case 10:return B.sent(),[3,12];case 11:if(O)this._onChange(null,{isFromServer:!1,flagsChanged:s({},O),traitsChanged:s({},null===(a=h.identity)||void 0===a?void 0:a.traits)},this._loadedState(null,l.DEFAULT_FLAGS));else if(this.flags&&(V=null,0===Object.keys(this.flags).length&&(V=U),this._onChange(null,{isFromServer:!1,flagsChanged:s({},this.flags),traitsChanged:s({},null===(o=h.identity)||void 0===o?void 0:o.traits)},this._loadedState(V,l.DEFAULT_FLAGS)),V))throw new Error(V);B.label=12;case 12:return[3,14];case 13:throw X=B.sent(),this.log("Error during initialisation ",X),W=X instanceof Error?X:new Error("".concat(X)),null===(r=this.onError)||void 0===r||r.call(this,W),X;case 14:return[2]}var Y}))}))},t.prototype.getAllFlags=function(){return this.flags},t.prototype.identify=function(t,e,n){return this.identity=t,this.evaluationContext.identity={identifier:t,transient:n,traits:this.evaluationContext.identity&&this.evaluationContext.identity.identifier==t?this.evaluationContext.identity.traits:{}},this.evaluationContext.identity.identifier=t,this.log("Identify: "+this.evaluationContext.identity.identifier),e&&(this.evaluationContext.identity.traits=Object.fromEntries(Object.entries(e).map((function(t){var e=t[0],n=t[1];return[e,c(n)?n:{value:n}]})))),this.initialised?this.getFlags():Promise.resolve()},t.prototype.getState=function(){return{api:this.api,flags:this.flags,ts:this.ts,evaluationContext:this.evaluationContext,identity:this.identity,evaluationEvent:this.evaluationEvent}},t.prototype.setState=function(t){var e,n;t&&(this.initialised=!0,this.api=t.api||this.api||m,this.flags=t.flags||this.flags,this.evaluationContext=t.evaluationContext||this.evaluationContext,this.evaluationEvent=t.evaluationEvent||this.evaluationEvent,this.identity=null===(n=null===(e=this.getContext())||void 0===e?void 0:e.identity)||void 0===n?void 0:n.identifier,this.log("setState called",this))},t.prototype.logout=function(){return this.identity=null,this.evaluationContext.identity=null,this.initialised?this.getFlags():Promise.resolve()},t.prototype.startListening=function(t){void 0===t&&(t=1e3),this.getFlagInterval&&clearInterval(this.getFlagInterval),this.getFlagInterval=setInterval(this.getFlags,t)},t.prototype.stopListening=function(){this.getFlagInterval&&(clearInterval(this.getFlagInterval),this.getFlagInterval=null)},t.prototype._loadedState=function(t,e,n){return void 0===t&&(t=null),void 0===n&&(n=!1),{error:t,isFetching:n,isLoading:!1,source:e}},t.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.enableLogs&&console.log.apply(this,a(["FLAGSMITH:",(new Date).valueOf()-(this.timer||0),"ms"],t,!0))},t.prototype.updateStorage=function(){if(this.cacheFlags){this.ts=(new Date).valueOf();var t=JSON.stringify(this.getState());this.log("Setting storage",t),f.setItem(this.getStorageKey(),t)}},t.prototype.updateEventStorage=function(){if(this.enableAnalytics){var t=JSON.stringify(this.getState().evaluationEvent);f.setItem(y,t).catch((function(t){return console.error("Flagsmith: Error setting item in async storage",t)}))}},t.prototype.setLoadingState=function(t){var n;r(t,this.loadingState)||(this.loadingState=e({},t),this.log("Loading state changed",t),null===(n=this._triggerLoadingState)||void 0===n||n.call(this))},t.prototype.setupRealtime=function(t,e){var n=this,i=t+"sse/environments/"+e+"/stream";g?this.eventSource||(this.log("Creating event source with url "+i),this.eventSource=new g(i),this.eventSource.addEventListener("environment_updated",(function(t){var e;try{e=JSON.parse(t.data).updated_at}catch(t){n.log("Could not parse sse event",t)}e?!n.timestamp||e>n.timestamp?n.isLoading?n.log("updated_at is new, but flags are loading",t.data,n.timestamp):(n.log("updated_at is new, fetching flags",t.data,n.timestamp),n.getFlags()):n.log("updated_at is outdated, skipping get flags",t.data,n.timestamp):n.log("No updated_at received, fetching flags",t)}))):this.log("Error, EventSource is undefined")},t}();function x(t){var e=t.fetch,n=t.AsyncStorage,i=t.eventSource;return new C({fetch:e,AsyncStorage:n,eventSource:i})}var b,O=o(Object.freeze({__proto__:null,default:class{ERROR=-1;CONNECTING=0;OPEN=1;CLOSED=2;constructor(t,e={}){if(this.interval=e.pollingInterval||5e3,this.lastEventId=null,this.lastIndexProcessed=0,this.eventType=void 0,this.status=this.CONNECTING,this.eventHandlers={open:[],message:[],error:[],close:[]},this.method=e.method||"GET",this.timeout=e.timeOut||0,this.headers=e.headers||{},this.body=e.body||void 0,this.debug=e.debug||!1,this._xhr=null,this._pollTimer=null,!t||"string"!=typeof t&&"function"!=typeof t.toString)throw new SyntaxError("[EventSource] Invalid URL argument.");"function"==typeof t.toString?this.url=t.toString():this.url=t,this._pollAgain(500)}_pollAgain(t){this._pollTimer=setTimeout((()=>{this.open()}),t)}open(){try{if(this.lastIndexProcessed=0,this.status=this.CONNECTING,this._xhr=new XMLHttpRequest,this._xhr.open(this.method,this.url,!0),this.headers)for(const[t,e]of Object.entries(this.headers))this._xhr.setRequestHeader(t,e);this._xhr.setRequestHeader("Accept","text/event-stream"),this._xhr.setRequestHeader("Cache-Control","no-cache"),this._xhr.setRequestHeader("X-Requested-With","XMLHttpRequest"),null!==this.lastEventId&&this._xhr.setRequestHeader("Last-Event-ID",this.lastEventId),this._xhr.timeout=this.timeout,this._xhr.onreadystatechange=()=>{const t=this._xhr;this.debug&&console.debug(`[EventSource][onreadystatechange] ReadyState: ${t.readyState}, status: ${t.status}`),[XMLHttpRequest.DONE,XMLHttpRequest.LOADING].includes(t.readyState)&&(t.status>=200&&t.status<400?(this.status===this.CONNECTING&&(this.status=this.OPEN,this.dispatch("open",{type:"open"})),this._handleEvent(t.responseText||""),t.readyState===XMLHttpRequest.DONE&&(this.debug&&console.debug("[EventSource][onreadystatechange][DONE] Operation done. Reconnecting..."),this._pollAgain(this.interval))):this.status!==this.CLOSED&&(0!==this._xhr.status&&this.dispatch("error",{type:"error",message:t.responseText,xhrStatus:t.status,xhrState:t.readyState}),[XMLHttpRequest.DONE,XMLHttpRequest.UNSENT].includes(t.readyState)&&(this.debug&&console.debug("[EventSource][onreadystatechange][ERROR] Response status error. Reconnecting..."),this._pollAgain(this.interval))))},this._xhr.onerror=t=>{this.status,this.ERROR,this.dispatch("error",{type:"error",message:this._xhr.responseText,xhrStatus:this._xhr.status,xhrState:this._xhr.readyState})},this.body?this._xhr.send(this.body):this._xhr.send(),this.timeout>0&&setTimeout((()=>{this._xhr.readyState===XMLHttpRequest.LOADING&&(this.dispatch("error",{type:"timeout"}),this.close())}),this.timeout)}catch(t){this.status=this.ERROR,this.dispatch("error",{type:"exception",message:t.message,error:t})}}_handleEvent(t){const e=t.substr(this.lastIndexProcessed).split("\n");this.lastIndexProcessed=t.lastIndexOf("\n\n")+2;let n=[],i=0,a="";for(let t=0;t<e.length;t++)if(a=e[t].replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g,""),0===a.indexOf("event"))this.eventType=a.replace(/event:?\s*/,"");else if(0===a.indexOf("retry"))i=parseInt(a.replace(/retry:?\s*/,""),10),isNaN(i)||(this.interval=i);else if(0===a.indexOf("data"))n.push(a.replace(/data:?\s*/,""));else if(0===a.indexOf("id:"))this.lastEventId=a.replace(/id:?\s*/,"");else if(0===a.indexOf("id"))this.lastEventId=null;else if(""===a&&n.length>0){const t=this.eventType||"message",e={type:t,data:n.join("\n"),url:this.url,lastEventId:this.lastEventId};this.dispatch(t,e),n=[],this.eventType=void 0}}addEventListener(t,e){void 0===this.eventHandlers[t]&&(this.eventHandlers[t]=[]),this.eventHandlers[t].push(e)}removeEventListener(t,e){void 0!==this.eventHandlers[t]&&(this.eventHandlers[t]=this.eventHandlers[t].filter((t=>t!==e)))}removeAllEventListeners(t){const e=Object.keys(this.eventHandlers);if(void 0===t)for(const t of e)this.eventHandlers[t]=[];else{if(!e.includes(t))throw Error(`[EventSource] '${t}' type is not supported event type.`);this.eventHandlers[t]=[]}}dispatch(t,e){if(Object.keys(this.eventHandlers).includes(t))for(const n of Object.values(this.eventHandlers[t]))n(e)}close(){this.status=this.CLOSED,clearTimeout(this._pollTimer),this._xhr&&this._xhr.abort(),this.dispatch("close",{type:"close"})}}})),F=(b=function(t,e){return b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},b(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}b(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),I=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],i=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},w=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,a,o=n.call(t),r=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)r.push(i.value)}catch(t){a={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return r},L=function(t,e,n){if(n||2===arguments.length)for(var i,a=0,o=e.length;a<o;a++)!i&&a in e||(i||(i=Array.prototype.slice.call(e,0,a)),i[a]=e[a]);return t.concat(i||Array.prototype.slice.call(e))},j=function(t){function e(){return t.call(this,"EventSource not available.\nConsider loading an EventSource polyfill and making it available globally as EventSource, or passing one in as eventSourceClass to the ReconnectingEventSource constructor.")||this}return F(e,t),e}(Error),A=function(){function t(t,e){var n=this;if(this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,this._configuration=null!=e?Object.assign({},e):void 0,this.withCredentials=!1,this._eventSource=null,this._lastEventId=null,this._timer=null,this._listeners={open:[],error:[],message:[]},this.url=t.toString(),this.readyState=this.CONNECTING,this.max_retry_time=3e3,this.eventSourceClass=globalThis.FlagsmithEventSource,null!=this._configuration&&(this._configuration.lastEventId&&(this._lastEventId=this._configuration.lastEventId,delete this._configuration.lastEventId),this._configuration.max_retry_time&&(this.max_retry_time=this._configuration.max_retry_time,delete this._configuration.max_retry_time),this._configuration.eventSourceClass&&(this.eventSourceClass=this._configuration.eventSourceClass,delete this._configuration.eventSourceClass)),null==this.eventSourceClass||"function"!=typeof this.eventSourceClass)throw new j;this._onevent_wrapped=function(t){n._onevent(t)},this._start()}return t.prototype.dispatchEvent=function(t){throw new Error("Method not implemented.")},t.prototype._start=function(){var t,e,n=this,i=this.url;this._lastEventId&&(-1===i.indexOf("?")?i+="?":i+="&",i+="lastEventId="+encodeURIComponent(this._lastEventId)),this._eventSource=new this.eventSourceClass(i,this._configuration),this._eventSource.onopen=function(t){n._onopen(t)},this._eventSource.onerror=function(t){n._onerror(t)},this._eventSource.onmessage=function(t){n.onmessage(t)};try{for(var a=I(Object.keys(this._listeners)),o=a.next();!o.done;o=a.next()){var r=o.value;this._eventSource.addEventListener(r,this._onevent_wrapped)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}},t.prototype._onopen=function(t){0===this.readyState&&(this.readyState=1,this.onopen(t))},t.prototype._onerror=function(t){var e=this;if(1===this.readyState&&(this.readyState=0,this.onerror(t)),this._eventSource){this._eventSource.close(),this._eventSource=null;var n=Math.round(this.max_retry_time*Math.random());this._timer=setTimeout((function(){return e._start()}),n)}},t.prototype._onevent=function(t){var e,n;t&&t.lastEventId&&(this._lastEventId=t.lastEventId);var i=this._listeners[t.type];if(null!=i)try{for(var a=I(L([],w(i),!1)),o=a.next();!o.done;o=a.next()){o.value.call(this,t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}"message"===t.type&&this.onmessage(t)},t.prototype.onopen=function(t){},t.prototype.onerror=function(t){},t.prototype.onmessage=function(t){},t.prototype.close=function(){this._timer&&(clearTimeout(this._timer),this._timer=null),this._eventSource&&(this._eventSource.close(),this._eventSource=null),this.readyState=2},t.prototype.addEventListener=function(t,e,n){null==this._listeners[t]&&(this._listeners[t]=[],null!=this._eventSource&&this._eventSource.addEventListener(t,this._onevent_wrapped));var i=this._listeners[t];i.includes(e)||(this._listeners[t]=L(L([],w(i),!1),[e],!1))},t.prototype.removeEventListener=function(t,e,n){var i=this._listeners[t];this._listeners[t]=i.filter((function(t){return t!==e}))},t}();global.FlagsmithEventSource=O.default;var N=x({browserlessStorage:!0,eventSource:A});t.createFlagsmithInstance=()=>x({browserlessStorage:!0,eventSource:A}),t.default=N,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

var t=function(){return t=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},t.apply(this,arguments)};function e(t,e,n,i){return new(n||(n=Promise))((function(a,o){function r(t){try{l(i.next(t))}catch(t){o(t)}}function s(t){try{l(i.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,s)}l((i=i.apply(t,e||[])).next())}))}function n(t,e){var n,i,a,o,r={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,i&&(a=2&o[0]?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return r.label++,{value:o[1],done:!1};case 5:r.label++,i=o[1],o=[0];continue;case 7:o=r.ops.pop(),r.trys.pop();continue;default:if(!(a=r.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){r=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){r.label=o[1];break}if(6===o[0]&&r.label<a[1]){r.label=a[1],a=o;break}if(a&&r.label<a[2]){r.label=a[2],r.ops.push(o);break}a[2]&&r.ops.pop(),r.trys.pop();continue}o=e.call(t,r)}catch(t){o=[6,t],i=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function i(t,e,n){if(n||2===arguments.length)for(var i,a=0,o=e.length;a<o;a++)!i&&a in e||(i||(i=Array.prototype.slice.call(e,0,a)),i[a]=e[a]);return t.concat(i||Array.prototype.slice.call(e))}function a(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})})),e}var o=function t(e,n){if(e===n)return!0;if(e&&n&&"object"==typeof e&&"object"==typeof n){if(e.constructor!==n.constructor)return!1;var i,a,o;if(Array.isArray(e)){if((i=e.length)!=n.length)return!1;for(a=i;0!=a--;)if(!t(e[a],n[a]))return!1;return!0}if(e.constructor===RegExp)return e.source===n.source&&e.flags===n.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===n.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===n.toString();if((i=(o=Object.keys(e)).length)!==Object.keys(n).length)return!1;for(a=i;0!=a--;)if(!Object.prototype.hasOwnProperty.call(n,o[a]))return!1;for(a=i;0!=a--;){var r=o[a];if(!t(e[r],n[r]))return!1}return!0}return e!=e&&n!=n};function r(t,e){var n=Object.keys(e||{}).filter((function(n){var i=null==t?void 0:t[n],a=null==e?void 0:e[n];return!o(i,a)}));return Object.keys(t||{}).filter((function(t){Object.keys(e||{}).includes(t)||n.push(t)})),Object.keys(n).length?n:null}var s,l;function u(t,e,n){var i="shortString",a=!0;"number"==typeof n&&(i="javaDouble",a=!1),t[i]=t[i]||{},t[i][e]=a?n+"":n}function h(t){return!!t&&"object"==typeof t&&void 0!==t.value}function c(t){return Object.fromEntries(Object.entries(t).map((function(t){var e=t[0],n=t[1];return[e,h(n)?n:{value:n}]})))}function d(e){return t(t({},e),{identity:e.identity?t(t({},e.identity),{traits:c(e.identity.traits||{})}):void 0})}!function(t){t.NONE="NONE",t.DEFAULT_FLAGS="DEFAULT_FLAGS",t.CACHE="CACHE",t.SERVER="SERVER"}(s||(s={}));var v,g=null,f="FLAGSMITH_EVENT",p="https://edge.api.flagsmith.com/api/v1/",y=function(){function a(e){var n=this;this._trigger=null,this._triggerLoadingState=null,this.timestamp=null,this.isLoading=!1,this.eventSource=null,this.getFlags=function(){var e=n,i=e.api,a=e.evaluationContext;n.log("Get Flags"),n.isLoading=!0,n.loadingState.isFetching||n.setLoadingState(t(t({},n.loadingState),{isFetching:!0}));var o="".concat(n.getContext().identity),l=function(e){var i,a,l,h;if(e&&o==="".concat(n.getContext().identity)){var c=e.flags,d=e.traits,v=e.identifier;n.isLoading=!1;var g={},f={};d=d||[],(c=c||[]).forEach((function(t){g[t.feature.name.toLowerCase().replace(/ /g,"_")]={id:t.feature.id,enabled:t.enabled,value:t.feature_state_value}})),d.forEach((function(t){f[t.trait_key.toLowerCase().replace(/ /g,"_")]={transient:t.transient,value:t.trait_value}})),n.oldFlags=t({},n.flags);var p=r(n.oldFlags,g),y=r(null===(i=n.evaluationContext.identity)||void 0===i?void 0:i.traits,f);if((v||Object.keys(f).length)&&(n.evaluationContext.identity=t(t({},n.evaluationContext.identity),{traits:f}),v&&(n.evaluationContext.identity.identifier=v,n.identity=v)),n.flags=g,n.updateStorage(),n._onChange(n.oldFlags,{isFromServer:!0,flagsChanged:p,traitsChanged:y},n._loadedState(null,s.SERVER)),n.datadogRum)try{if(n.datadogRum.trackTraits){var m={};Object.keys((null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.traits)||{}).map((function(t){m["flagsmith_trait_"+t]=n.getTrait(t)}));var S=t(t(t({},n.datadogRum.client.getUser()),{id:n.datadogRum.client.getUser().id||(null===(l=n.evaluationContext.identity)||void 0===l?void 0:l.identifier)}),m);n.log("Setting Datadog user",S),n.datadogRum.client.setUser(S)}}catch(t){console.error(t)}if(n.dtrum)try{var _={javaDouble:{},date:{},shortString:{},javaLongOrObject:{}};Object.keys(n.flags).map((function(t){u(_,"flagsmith_value_"+t,n.getValue(t,{skipAnalytics:!0})),u(_,"flagsmith_enabled_"+t,n.hasFeature(t,{skipAnalytics:!0}))})),Object.keys((null===(h=n.evaluationContext.identity)||void 0===h?void 0:h.traits)||{}).map((function(t){u(_,"flagsmith_trait_"+t,n.getTrait(t))})),n.log("Sending javaLongOrObject traits to dynatrace",_.javaLongOrObject),n.log("Sending date traits to dynatrace",_.date),n.log("Sending shortString traits to dynatrace",_.shortString),n.log("Sending javaDouble to dynatrace",_.javaDouble),n.dtrum.sendSessionProperties(_.javaLongOrObject,_.date,_.shortString,_.javaDouble)}catch(t){console.error(t)}}};return a.identity?Promise.all([a.identity.traits&&Object.keys(a.identity.traits).length||!a.identity.identifier?n.getJSON(i+"identities/","POST",JSON.stringify({identifier:a.identity.identifier,transient:a.identity.transient,traits:Object.entries(a.identity.traits).map((function(t){var e=t[0],n=t[1];return{trait_key:e,trait_value:null==n?void 0:n.value,transient:null==n?void 0:n.transient}})).filter((function(t){return void 0!==t.trait_value||(n.log("Warning - attempted to set an undefined trait value for key",t.trait_key),!1)}))})):n.getJSON(i+"identities/?identifier="+encodeURIComponent(a.identity.identifier)+(a.identity.transient?"&transient=true":""))]).then((function(e){return n.evaluationContext.identity=t(t({},n.evaluationContext.identity),{traits:{}}),l(null==e?void 0:e[0])})).catch((function(t){var e=t.message,n=new Error(e);return Promise.reject(n)})):n.getJSON(i+"flags/").then((function(t){return l({flags:t,traits:void 0})}))},this.analyticsFlags=function(){var e=n.api;if(n.evaluationEvent&&n.evaluationContext.environment&&n.evaluationEvent[n.evaluationContext.environment.apiKey])return n.evaluationEvent&&0!==Object.getOwnPropertyNames(n.evaluationEvent).length&&0!==Object.getOwnPropertyNames(n.evaluationEvent[n.evaluationContext.environment.apiKey]).length?n.getJSON(e+"analytics/flags/","POST",JSON.stringify(n.evaluationEvent[n.evaluationContext.environment.apiKey])).then((function(e){if(n.evaluationContext.environment){var i=n.getState();n.evaluationEvent||(n.evaluationEvent={}),n.evaluationEvent[n.evaluationContext.environment.apiKey]={},n.setState(t(t({},i),{evaluationEvent:n.evaluationEvent})),n.updateEventStorage()}})).catch((function(t){n.log("Exception fetching evaluationEvent",t)})):void 0},this.datadogRum=null,this.loadingState={isLoading:!0,isFetching:!0,error:null,source:s.NONE},this.canUseStorage=!1,this.analyticsInterval=null,this.api=null,this.cacheFlags=!1,this.enableAnalytics=!1,this.enableLogs=!1,this.evaluationContext={},this.evaluationEvent=null,this.flags=null,this.getFlagInterval=null,this.headers=null,this.identity=null,this.initialised=!1,this.oldFlags=null,this.onChange=null,this.onError=null,this.ticks=null,this.timer=null,this.dtrum=null,this.withTraits=null,this.cacheOptions={ttl:0,skipAPI:!1,loadStale:!1,storageKey:void 0},this.getValue=function(t,e,i){var a=n.flags&&n.flags[t.toLowerCase().replace(/ /g,"_")],o=null;if(a&&(o=a.value),(null==e?void 0:e.skipAnalytics)||i||n.evaluateFlag(t,"VALUE"),null===o&&void 0!==(null==e?void 0:e.fallback))return e.fallback;if(null==e?void 0:e.json)try{return null===o?(n.log("Tried to parse null flag as JSON: "+t),null):JSON.parse(o)}catch(t){return e.fallback}return o},this.getTrait=function(t){var e,i;return(null===(e=n.evaluationContext.identity)||void 0===e?void 0:e.traits)&&(null===(i=n.evaluationContext.identity.traits[t.toLowerCase().replace(/ /g,"_")])||void 0===i?void 0:i.value)},this.getAllTraits=function(){var t;return Object.fromEntries(Object.entries((null===(t=n.evaluationContext.identity)||void 0===t?void 0:t.traits)||{}).map((function(t){var e=t[0],n=t[1];return[e,null==n?void 0:n.value]})))},this.setContext=function(e){var i,a,o=d(e);return n.evaluationContext=t(t({},o),{environment:o.environment||n.evaluationContext.environment}),n.identity=null===(a=null===(i=n.getContext())||void 0===i?void 0:i.identity)||void 0===a?void 0:a.identifier,n.initialised?n.getFlags():Promise.resolve()},this.getContext=function(){return n.evaluationContext},this.updateContext=function(e){return n.setContext(t(t({},n.getContext()),e))},this.setTrait=function(e,i){var a;if(n.api)return n.setContext(t(t({},n.evaluationContext),{identity:t(t({},n.evaluationContext.identity),{traits:t(t({},null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.traits),c(Object.fromEntries([[e,i]])))})}))},this.setTraits=function(e){var i;if(n.api)return n.setContext(t(t({},n.evaluationContext),{identity:t(t({},n.evaluationContext.identity),{traits:t(t({},null===(i=n.evaluationContext.identity)||void 0===i?void 0:i.traits),Object.fromEntries(Object.entries(e).map((function(t){var e=t[0],n=t[1];return[e,h(n)?n:{value:n}]}))))})}));console.error("Attempted to "+"setTraits"+" a user before calling flagsmith.init. Call flagsmith.init first, if you wish to prevent it sending a request for flags, call init with preventFetch:true.")},this.hasFeature=function(t,e){var i="object"==typeof e,a=n.flags&&n.flags[t.toLowerCase().replace(/ /g,"_")],o=!1;return!a&&i&&void 0!==e.fallback?o=null==e?void 0:e.fallback:a&&a.enabled&&(o=!0),(i&&!e.skipAnalytics||!e)&&n.evaluateFlag(t,"ENABLED"),o},this.getStorageKey=function(){var t,e;return(null===(t=n.cacheOptions)||void 0===t?void 0:t.storageKey)||"FLAGSMITH_DB_"+(null===(e=n.evaluationContext.environment)||void 0===e?void 0:e.apiKey)},this.getJSON=function(t,e,i){var a,o,r,s=n.headers,u={method:e||"GET",body:i,cache:"no-cache",headers:{}};n.evaluationContext.environment&&(u.headers["X-Environment-Key"]=n.evaluationContext.environment.apiKey),e&&"GET"!==e&&(u.headers["Content-Type"]="application/json; charset=utf-8"),(null===(a=n.applicationMetadata)||void 0===a?void 0:a.name)&&(u.headers["Flagsmith-Application-Name"]=n.applicationMetadata.name),(null===(o=n.applicationMetadata)||void 0===o?void 0:o.version)&&(u.headers["Flagsmith-Application-Version"]=n.applicationMetadata.version),s&&Object.assign(u.headers,s),l||console.error("Flagsmith: fetch is undefined, please specify a fetch implementation into flagsmith.init to support SSR.");var h="".concat(null===(r=n.evaluationContext.identity)||void 0===r?void 0:r.identifier);return l(t,u).then((function(i){var a,o,r="".concat(null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.identifier);if(h===r){var s=null===(o=i.headers)||void 0===o?void 0:o.get("x-flagsmith-document-updated-at");if(s)try{var l=parseFloat(s);if(isNaN(l))return Promise.reject("Failed to parse x-flagsmith-document-updated-at");n.timestamp=l}catch(t){n.log(t,"Failed to parse x-flagsmith-document-updated-at",s)}return n.log("Fetch response: "+i.status+" "+(e||"GET")+0+t),i.text().then((function(t){var e=t;try{e=JSON.parse(t)}catch(t){}return!e&&i.status&&(e="API Response: ".concat(i.status)),i.status&&i.status>=200&&i.status<300?e:Promise.reject(new Error(e))}))}n.log("Received response with identity mismatch, ignoring response. Requested: ".concat(h,", Current: ").concat(r))}))},this.evaluateFlag=function(t,e){if(n.datadogRum&&(n.datadogRum.client.addFeatureFlagEvaluation?"VALUE"===e?n.datadogRum.client.addFeatureFlagEvaluation("flagsmith_value_"+t,n.getValue(t,{},!0)):n.datadogRum.client.addFeatureFlagEvaluation("flagsmith_enabled_"+t,n.hasFeature(t,!0)):console.error("Flagsmith: Your datadog RUM client does not support the function addFeatureFlagEvaluation, please update it.")),n.enableAnalytics){if(!n.evaluationEvent||!n.evaluationContext.environment)return;n.evaluationEvent[n.evaluationContext.environment.apiKey]||(n.evaluationEvent[n.evaluationContext.environment.apiKey]={}),void 0===n.evaluationEvent[n.evaluationContext.environment.apiKey][t]&&(n.evaluationEvent[n.evaluationContext.environment.apiKey][t]=0),n.evaluationEvent[n.evaluationContext.environment.apiKey][t]+=1}n.updateEventStorage()},this._onChange=function(t,e,i){var a,o;n.setLoadingState(i),null===(a=n.onChange)||void 0===a||a.call(n,t,e,n.loadingState),null===(o=n._trigger)||void 0===o||o.call(n)},l=e.fetch?e.fetch:"undefined"!=typeof fetch?fetch:null===global||void 0===global?void 0:global.fetch,this.canUseStorage="undefined"!=typeof window||!!e.browserlessStorage,this.applicationMetadata=e.applicationMetadata,this.log("Constructing flagsmith instance "+e),e.eventSource&&(v=e.eventSource),e.AsyncStorage&&(g=e.AsyncStorage)}return a.prototype.init=function(i){var a,o,u;return e(this,void 0,void 0,(function(){var h,c,v,y,m,S,_,E,C,x,b,O,F,w,I,L,j,A,R,N,T,k,P,D,H,K,M,G,U,J,q,V,X,W=this;return n(this,(function($){switch($.label){case 0:h=d(i.evaluationContext||this.evaluationContext),$.label=1;case 1:if($.trys.push([1,13,,14]),c=i.environmentID,v=i.api,y=void 0===v?p:v,m=i.headers,S=i.onChange,_=i.cacheFlags,E=i.datadogRum,C=i.onError,x=i.defaultFlags,b=i.fetch,O=i.preventFetch,F=i.enableLogs,w=i.enableDynatrace,I=i.enableAnalytics,L=i.realtime,j=i.eventSourceUrl,A=void 0===j?"https://realtime.flagsmith.com/":j,R=i.AsyncStorage,N=i.identity,T=i.traits,k=i.state,P=i.cacheOptions,D=i.angularHttpClient,H=i._trigger,K=i._triggerLoadingState,M=i.applicationMetadata,h.environment=c?{apiKey:c}:h.environment,!h.environment||!h.environment.apiKey)throw new Error("Please provide `evaluationContext.environment` with non-empty `apiKey`");if(h.identity=N||T?{identifier:N,traits:T?Object.fromEntries(Object.entries(T).map((function(t){return[t[0],{value:t[1]}]}))):{}}:h.identity,this.evaluationContext=h,this.api=(B=y).endsWith("/")?B:B+"/",this.headers=m,this.getFlagInterval=null,this.analyticsInterval=null,this.onChange=S,G="Wrong Flagsmith Configuration: preventFetch is true and no defaulFlags provided",this._trigger=H||this._trigger,this._triggerLoadingState=K||this._triggerLoadingState,this.onError=function(e){W.setLoadingState(t(t({},W.loadingState),{isFetching:!1,isLoading:!1,error:e})),null==C||C(e)},this.enableLogs=F||!1,this.cacheOptions=P?{skipAPI:!!P.skipAPI,ttl:P.ttl||0,storageKey:P.storageKey,loadStale:!!P.loadStale}:this.cacheOptions,!this.cacheOptions.ttl&&this.cacheOptions.skipAPI&&console.warn("Flagsmith: you have set a cache ttl of 0 and are skipping API calls, this means the API will not be hit unless you clear local storage."),b&&(l=b),this.enableAnalytics=I||!1,this.flags=Object.assign({},x)||{},this.datadogRum=E||null,this.initialised=!0,this.ticks=1e4,this.timer=this.enableLogs?(new Date).valueOf():null,this.cacheFlags=void 0!==g&&!!_,this.applicationMetadata=M,f="FLAGSMITH_EVENT_"+h.environment.apiKey,R&&(g=R),L&&"undefined"!=typeof window&&this.setupRealtime(A,h.environment.apiKey),Object.keys(this.flags).length&&(this.loadingState=t(t({},this.loadingState),{isLoading:!1,source:s.DEFAULT_FLAGS})),this.setState(k),this.log("Initialising with properties",i,this),w&&("undefined"==typeof dtrum?console.error("You have attempted to enable dynatrace but dtrum is undefined, please check you have the Dynatrace RUM JavaScript API installed."):this.dtrum=dtrum),D&&(l=function(t){return function(e,n){var i=n.headers,a=n.method,o=n.body;return new Promise((function(n){switch(a){case"GET":return t.get(e,{headers:i}).subscribe((function(t){n({ok:!0,text:function(){return Promise.resolve(t)}})}));case"POST":case"PUT":return t.post(e,o,{headers:i}).subscribe((function(t){n({ok:!0,text:function(){return Promise.resolve(t)}})}))}}))}}(D)),g&&this.canUseStorage&&g.getItem(f).then((function(t){try{W.evaluationEvent=JSON.parse(t)||{}}catch(t){W.evaluationEvent={}}W.analyticsInterval=setInterval(W.analyticsFlags,W.ticks)})),this.enableAnalytics&&(this.analyticsInterval&&clearInterval(this.analyticsInterval),g&&this.canUseStorage&&g.getItem(f,(function(e,n){if(n&&W.evaluationContext.environment){var i=JSON.parse(n);if(i[W.evaluationContext.environment.apiKey]){var a=W.getState();W.log("Retrieved events from cache",n),W.setState(t(t({},a),{evaluationEvent:i[W.evaluationContext.environment.apiKey]}))}}}))),!_)return[3,9];if(!g||!this.canUseStorage)return[3,8];U=function(i,a){return e(W,void 0,void 0,(function(){var e,i,o,l,u,h,c,v,g,f,p,y,m,S,_,E,C,b,F,w=this;return n(this,(function(n){switch(n.label){case 0:if(!a)return[3,7];e=null,i=null,n.label=1;case 1:return n.trys.push([1,5,,6]),o=JSON.parse(a),l=!1,u=!1,o&&o.api===this.api&&(null===(f=null===(g=o.evaluationContext)||void 0===g?void 0:g.environment)||void 0===f?void 0:f.apiKey)===(null===(p=this.evaluationContext.environment)||void 0===p?void 0:p.apiKey)&&(h=!0,this.evaluationContext.identity&&(null===(m=null===(y=o.evaluationContext)||void 0===y?void 0:y.identity)||void 0===m?void 0:m.identifier)!==this.evaluationContext.identity.identifier&&(this.log("Ignoring cache, identity has changed from "+(null===(_=null===(S=o.evaluationContext)||void 0===S?void 0:S.identity)||void 0===_?void 0:_.identifier)+" to "+this.evaluationContext.identity.identifier),h=!1),this.cacheOptions.ttl&&(!o.ts||(new Date).valueOf()-o.ts>this.cacheOptions.ttl)&&(o.ts&&!this.cacheOptions.loadStale?(this.log("Ignoring cache, timestamp is too old ts:"+o.ts+" ttl: "+this.cacheOptions.ttl+" time elapsed since cache: "+((new Date).valueOf()-o.ts)+"ms"),h=!1):o.ts&&this.cacheOptions.loadStale&&(this.log("Loading stale cache, timestamp ts:"+o.ts+" ttl: "+this.cacheOptions.ttl+" time elapsed since cache: "+((new Date).valueOf()-o.ts)+"ms"),u=!0,h=!0)),h&&(l=!0,e=r(this.flags,o.flags),this.setState(t(t({},o),{evaluationContext:d(t(t({},o.evaluationContext),{identity:(null===(E=o.evaluationContext)||void 0===E?void 0:E.identity)?t(t({},null===(C=o.evaluationContext)||void 0===C?void 0:C.identity),{traits:t({},T||{})}):void 0}))})),this.log("Retrieved flags from cache",o))),l?(c=!O&&(!this.cacheOptions.skipAPI||u),this._onChange(null,{isFromServer:!1,flagsChanged:e,traitsChanged:i},this._loadedState(null,s.CACHE,c)),this.oldFlags=this.flags,this.cacheOptions.skipAPI&&l&&!u&&this.log("Skipping API, using cache"),c&&this.getFlags().catch((function(t){var e;null===(e=w.onError)||void 0===e||e.call(w,t)})),[3,4]):[3,2];case 2:return O?[3,4]:[4,this.getFlags()];case 3:n.sent(),n.label=4;case 4:return[3,6];case 5:return v=n.sent(),this.log("Exception fetching cached logs",v),[3,6];case 6:return[3,10];case 7:return O?[3,9]:[4,this.getFlags()];case 8:return n.sent(),[3,10];case 9:if(x)this._onChange(null,{isFromServer:!1,flagsChanged:r({},this.flags),traitsChanged:r({},null===(b=this.evaluationContext.identity)||void 0===b?void 0:b.traits)},this._loadedState(null,s.DEFAULT_FLAGS));else{if(!this.flags)throw new Error(G);this._onChange(null,{isFromServer:!1,flagsChanged:r({},this.flags),traitsChanged:r({},null===(F=this.evaluationContext.identity)||void 0===F?void 0:F.traits)},this._loadedState(null,s.DEFAULT_FLAGS))}n.label=10;case 10:return[2]}}))}))},$.label=2;case 2:return $.trys.push([2,7,,8]),g.getItemSync?(J=g.getItemSync(this.getStorageKey()),[3,5]):[3,3];case 3:return[4,g.getItem(this.getStorageKey())];case 4:J=$.sent(),$.label=5;case 5:return[4,U(null,J)];case 6:case 7:return $.sent(),[3,8];case 8:return[3,12];case 9:return O?[3,11]:[4,this.getFlags()];case 10:return $.sent(),[3,12];case 11:if(x)this._onChange(null,{isFromServer:!1,flagsChanged:r({},x),traitsChanged:r({},null===(a=h.identity)||void 0===a?void 0:a.traits)},this._loadedState(null,s.DEFAULT_FLAGS));else if(this.flags&&(q=null,0===Object.keys(this.flags).length&&(q=G),this._onChange(null,{isFromServer:!1,flagsChanged:r({},this.flags),traitsChanged:r({},null===(o=h.identity)||void 0===o?void 0:o.traits)},this._loadedState(q,s.DEFAULT_FLAGS)),q))throw new Error(q);$.label=12;case 12:return[3,14];case 13:throw V=$.sent(),this.log("Error during initialisation ",V),X=V instanceof Error?V:new Error("".concat(V)),null===(u=this.onError)||void 0===u||u.call(this,X),V;case 14:return[2]}var B}))}))},a.prototype.getAllFlags=function(){return this.flags},a.prototype.identify=function(t,e,n){return this.identity=t,this.evaluationContext.identity={identifier:t,transient:n,traits:this.evaluationContext.identity&&this.evaluationContext.identity.identifier==t?this.evaluationContext.identity.traits:{}},this.evaluationContext.identity.identifier=t,this.log("Identify: "+this.evaluationContext.identity.identifier),e&&(this.evaluationContext.identity.traits=Object.fromEntries(Object.entries(e).map((function(t){var e=t[0],n=t[1];return[e,h(n)?n:{value:n}]})))),this.initialised?this.getFlags():Promise.resolve()},a.prototype.getState=function(){return{api:this.api,flags:this.flags,ts:this.ts,evaluationContext:this.evaluationContext,identity:this.identity,evaluationEvent:this.evaluationEvent}},a.prototype.setState=function(t){var e,n;t&&(this.initialised=!0,this.api=t.api||this.api||p,this.flags=t.flags||this.flags,this.evaluationContext=t.evaluationContext||this.evaluationContext,this.evaluationEvent=t.evaluationEvent||this.evaluationEvent,this.identity=null===(n=null===(e=this.getContext())||void 0===e?void 0:e.identity)||void 0===n?void 0:n.identifier,this.log("setState called",this))},a.prototype.logout=function(){return this.identity=null,this.evaluationContext.identity=null,this.initialised?this.getFlags():Promise.resolve()},a.prototype.startListening=function(t){void 0===t&&(t=1e3),this.getFlagInterval&&clearInterval(this.getFlagInterval),this.getFlagInterval=setInterval(this.getFlags,t)},a.prototype.stopListening=function(){this.getFlagInterval&&(clearInterval(this.getFlagInterval),this.getFlagInterval=null)},a.prototype._loadedState=function(t,e,n){return void 0===t&&(t=null),void 0===n&&(n=!1),{error:t,isFetching:n,isLoading:!1,source:e}},a.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.enableLogs&&console.log.apply(this,i(["FLAGSMITH:",(new Date).valueOf()-(this.timer||0),"ms"],t,!0))},a.prototype.updateStorage=function(){if(this.cacheFlags){this.ts=(new Date).valueOf();var t=JSON.stringify(this.getState());this.log("Setting storage",t),g.setItem(this.getStorageKey(),t)}},a.prototype.updateEventStorage=function(){if(this.enableAnalytics){var t=JSON.stringify(this.getState().evaluationEvent);g.setItem(f,t).catch((function(t){return console.error("Flagsmith: Error setting item in async storage",t)}))}},a.prototype.setLoadingState=function(e){var n;o(e,this.loadingState)||(this.loadingState=t({},e),this.log("Loading state changed",e),null===(n=this._triggerLoadingState)||void 0===n||n.call(this))},a.prototype.setupRealtime=function(t,e){var n=this,i=t+"sse/environments/"+e+"/stream";v?this.eventSource||(this.log("Creating event source with url "+i),this.eventSource=new v(i),this.eventSource.addEventListener("environment_updated",(function(t){var e;try{e=JSON.parse(t.data).updated_at}catch(t){n.log("Could not parse sse event",t)}e?!n.timestamp||e>n.timestamp?n.isLoading?n.log("updated_at is new, but flags are loading",t.data,n.timestamp):(n.log("updated_at is new, fetching flags",t.data,n.timestamp),n.getFlags()):n.log("updated_at is outdated, skipping get flags",t.data,n.timestamp):n.log("No updated_at received, fetching flags",t)}))):this.log("Error, EventSource is undefined")},a}();function m(t){var e=t.fetch,n=t.AsyncStorage,i=t.eventSource;return new y({fetch:e,AsyncStorage:n,eventSource:i})}var S,_=a(Object.freeze({__proto__:null,default:class{ERROR=-1;CONNECTING=0;OPEN=1;CLOSED=2;constructor(t,e={}){if(this.interval=e.pollingInterval||5e3,this.lastEventId=null,this.lastIndexProcessed=0,this.eventType=void 0,this.status=this.CONNECTING,this.eventHandlers={open:[],message:[],error:[],close:[]},this.method=e.method||"GET",this.timeout=e.timeOut||0,this.headers=e.headers||{},this.body=e.body||void 0,this.debug=e.debug||!1,this._xhr=null,this._pollTimer=null,!t||"string"!=typeof t&&"function"!=typeof t.toString)throw new SyntaxError("[EventSource] Invalid URL argument.");"function"==typeof t.toString?this.url=t.toString():this.url=t,this._pollAgain(500)}_pollAgain(t){this._pollTimer=setTimeout((()=>{this.open()}),t)}open(){try{if(this.lastIndexProcessed=0,this.status=this.CONNECTING,this._xhr=new XMLHttpRequest,this._xhr.open(this.method,this.url,!0),this.headers)for(const[t,e]of Object.entries(this.headers))this._xhr.setRequestHeader(t,e);this._xhr.setRequestHeader("Accept","text/event-stream"),this._xhr.setRequestHeader("Cache-Control","no-cache"),this._xhr.setRequestHeader("X-Requested-With","XMLHttpRequest"),null!==this.lastEventId&&this._xhr.setRequestHeader("Last-Event-ID",this.lastEventId),this._xhr.timeout=this.timeout,this._xhr.onreadystatechange=()=>{const t=this._xhr;this.debug&&console.debug(`[EventSource][onreadystatechange] ReadyState: ${t.readyState}, status: ${t.status}`),[XMLHttpRequest.DONE,XMLHttpRequest.LOADING].includes(t.readyState)&&(t.status>=200&&t.status<400?(this.status===this.CONNECTING&&(this.status=this.OPEN,this.dispatch("open",{type:"open"})),this._handleEvent(t.responseText||""),t.readyState===XMLHttpRequest.DONE&&(this.debug&&console.debug("[EventSource][onreadystatechange][DONE] Operation done. Reconnecting..."),this._pollAgain(this.interval))):this.status!==this.CLOSED&&(0!==this._xhr.status&&this.dispatch("error",{type:"error",message:t.responseText,xhrStatus:t.status,xhrState:t.readyState}),[XMLHttpRequest.DONE,XMLHttpRequest.UNSENT].includes(t.readyState)&&(this.debug&&console.debug("[EventSource][onreadystatechange][ERROR] Response status error. Reconnecting..."),this._pollAgain(this.interval))))},this._xhr.onerror=t=>{this.status,this.ERROR,this.dispatch("error",{type:"error",message:this._xhr.responseText,xhrStatus:this._xhr.status,xhrState:this._xhr.readyState})},this.body?this._xhr.send(this.body):this._xhr.send(),this.timeout>0&&setTimeout((()=>{this._xhr.readyState===XMLHttpRequest.LOADING&&(this.dispatch("error",{type:"timeout"}),this.close())}),this.timeout)}catch(t){this.status=this.ERROR,this.dispatch("error",{type:"exception",message:t.message,error:t})}}_handleEvent(t){const e=t.substr(this.lastIndexProcessed).split("\n");this.lastIndexProcessed=t.lastIndexOf("\n\n")+2;let n=[],i=0,a="";for(let t=0;t<e.length;t++)if(a=e[t].replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g,""),0===a.indexOf("event"))this.eventType=a.replace(/event:?\s*/,"");else if(0===a.indexOf("retry"))i=parseInt(a.replace(/retry:?\s*/,""),10),isNaN(i)||(this.interval=i);else if(0===a.indexOf("data"))n.push(a.replace(/data:?\s*/,""));else if(0===a.indexOf("id:"))this.lastEventId=a.replace(/id:?\s*/,"");else if(0===a.indexOf("id"))this.lastEventId=null;else if(""===a&&n.length>0){const t=this.eventType||"message",e={type:t,data:n.join("\n"),url:this.url,lastEventId:this.lastEventId};this.dispatch(t,e),n=[],this.eventType=void 0}}addEventListener(t,e){void 0===this.eventHandlers[t]&&(this.eventHandlers[t]=[]),this.eventHandlers[t].push(e)}removeEventListener(t,e){void 0!==this.eventHandlers[t]&&(this.eventHandlers[t]=this.eventHandlers[t].filter((t=>t!==e)))}removeAllEventListeners(t){const e=Object.keys(this.eventHandlers);if(void 0===t)for(const t of e)this.eventHandlers[t]=[];else{if(!e.includes(t))throw Error(`[EventSource] '${t}' type is not supported event type.`);this.eventHandlers[t]=[]}}dispatch(t,e){if(Object.keys(this.eventHandlers).includes(t))for(const n of Object.values(this.eventHandlers[t]))n(e)}close(){this.status=this.CLOSED,clearTimeout(this._pollTimer),this._xhr&&this._xhr.abort(),this.dispatch("close",{type:"close"})}}})),E=(S=function(t,e){return S=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},S(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}S(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),C=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],i=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},x=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,a,o=n.call(t),r=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)r.push(i.value)}catch(t){a={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return r},b=function(t,e,n){if(n||2===arguments.length)for(var i,a=0,o=e.length;a<o;a++)!i&&a in e||(i||(i=Array.prototype.slice.call(e,0,a)),i[a]=e[a]);return t.concat(i||Array.prototype.slice.call(e))},O=function(t){function e(){return t.call(this,"EventSource not available.\nConsider loading an EventSource polyfill and making it available globally as EventSource, or passing one in as eventSourceClass to the ReconnectingEventSource constructor.")||this}return E(e,t),e}(Error),F=function(){function t(t,e){var n=this;if(this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,this._configuration=null!=e?Object.assign({},e):void 0,this.withCredentials=!1,this._eventSource=null,this._lastEventId=null,this._timer=null,this._listeners={open:[],error:[],message:[]},this.url=t.toString(),this.readyState=this.CONNECTING,this.max_retry_time=3e3,this.eventSourceClass=globalThis.FlagsmithEventSource,null!=this._configuration&&(this._configuration.lastEventId&&(this._lastEventId=this._configuration.lastEventId,delete this._configuration.lastEventId),this._configuration.max_retry_time&&(this.max_retry_time=this._configuration.max_retry_time,delete this._configuration.max_retry_time),this._configuration.eventSourceClass&&(this.eventSourceClass=this._configuration.eventSourceClass,delete this._configuration.eventSourceClass)),null==this.eventSourceClass||"function"!=typeof this.eventSourceClass)throw new O;this._onevent_wrapped=function(t){n._onevent(t)},this._start()}return t.prototype.dispatchEvent=function(t){throw new Error("Method not implemented.")},t.prototype._start=function(){var t,e,n=this,i=this.url;this._lastEventId&&(-1===i.indexOf("?")?i+="?":i+="&",i+="lastEventId="+encodeURIComponent(this._lastEventId)),this._eventSource=new this.eventSourceClass(i,this._configuration),this._eventSource.onopen=function(t){n._onopen(t)},this._eventSource.onerror=function(t){n._onerror(t)},this._eventSource.onmessage=function(t){n.onmessage(t)};try{for(var a=C(Object.keys(this._listeners)),o=a.next();!o.done;o=a.next()){var r=o.value;this._eventSource.addEventListener(r,this._onevent_wrapped)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}},t.prototype._onopen=function(t){0===this.readyState&&(this.readyState=1,this.onopen(t))},t.prototype._onerror=function(t){var e=this;if(1===this.readyState&&(this.readyState=0,this.onerror(t)),this._eventSource){this._eventSource.close(),this._eventSource=null;var n=Math.round(this.max_retry_time*Math.random());this._timer=setTimeout((function(){return e._start()}),n)}},t.prototype._onevent=function(t){var e,n;t&&t.lastEventId&&(this._lastEventId=t.lastEventId);var i=this._listeners[t.type];if(null!=i)try{for(var a=C(b([],x(i),!1)),o=a.next();!o.done;o=a.next()){o.value.call(this,t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}"message"===t.type&&this.onmessage(t)},t.prototype.onopen=function(t){},t.prototype.onerror=function(t){},t.prototype.onmessage=function(t){},t.prototype.close=function(){this._timer&&(clearTimeout(this._timer),this._timer=null),this._eventSource&&(this._eventSource.close(),this._eventSource=null),this.readyState=2},t.prototype.addEventListener=function(t,e,n){null==this._listeners[t]&&(this._listeners[t]=[],null!=this._eventSource&&this._eventSource.addEventListener(t,this._onevent_wrapped));var i=this._listeners[t];i.includes(e)||(this._listeners[t]=b(b([],x(i),!1),[e],!1))},t.prototype.removeEventListener=function(t,e,n){var i=this._listeners[t];this._listeners[t]=i.filter((function(t){return t!==e}))},t}();global.FlagsmithEventSource=_.default;var w=m({browserlessStorage:!0,eventSource:F});const I=()=>m({browserlessStorage:!0,eventSource:F});export{I as createFlagsmithInstance,w as default};
var t=function(){return t=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},t.apply(this,arguments)};function e(t,e,n,i){return new(n||(n=Promise))((function(a,o){function r(t){try{l(i.next(t))}catch(t){o(t)}}function s(t){try{l(i.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,s)}l((i=i.apply(t,e||[])).next())}))}function n(t,e){var n,i,a,o,r={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,i&&(a=2&o[0]?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return r.label++,{value:o[1],done:!1};case 5:r.label++,i=o[1],o=[0];continue;case 7:o=r.ops.pop(),r.trys.pop();continue;default:if(!(a=r.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){r=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){r.label=o[1];break}if(6===o[0]&&r.label<a[1]){r.label=a[1],a=o;break}if(a&&r.label<a[2]){r.label=a[2],r.ops.push(o);break}a[2]&&r.ops.pop(),r.trys.pop();continue}o=e.call(t,r)}catch(t){o=[6,t],i=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function i(t,e,n){if(n||2===arguments.length)for(var i,a=0,o=e.length;a<o;a++)!i&&a in e||(i||(i=Array.prototype.slice.call(e,0,a)),i[a]=e[a]);return t.concat(i||Array.prototype.slice.call(e))}function a(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})})),e}var o=function t(e,n){if(e===n)return!0;if(e&&n&&"object"==typeof e&&"object"==typeof n){if(e.constructor!==n.constructor)return!1;var i,a,o;if(Array.isArray(e)){if((i=e.length)!=n.length)return!1;for(a=i;0!=a--;)if(!t(e[a],n[a]))return!1;return!0}if(e.constructor===RegExp)return e.source===n.source&&e.flags===n.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===n.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===n.toString();if((i=(o=Object.keys(e)).length)!==Object.keys(n).length)return!1;for(a=i;0!=a--;)if(!Object.prototype.hasOwnProperty.call(n,o[a]))return!1;for(a=i;0!=a--;){var r=o[a];if(!t(e[r],n[r]))return!1}return!0}return e!=e&&n!=n};function r(t,e){var n=Object.keys(e||{}).filter((function(n){var i=null==t?void 0:t[n],a=null==e?void 0:e[n];return!o(i,a)}));return Object.keys(t||{}).filter((function(t){Object.keys(e||{}).includes(t)||n.push(t)})),Object.keys(n).length?n:null}var s,l;function u(t,e,n){var i="shortString",a=!0;"number"==typeof n&&(i="javaDouble",a=!1),t[i]=t[i]||{},t[i][e]=a?n+"":n}function h(t){return!!t&&"object"==typeof t&&void 0!==t.value}function c(t){return Object.fromEntries(Object.entries(t).map((function(t){var e=t[0],n=t[1];return[e,h(n)?n:{value:n}]})))}function d(e){return t(t({},e),{identity:e.identity?t(t({},e.identity),{traits:c(e.identity.traits||{})}):void 0})}!function(t){t.NONE="NONE",t.DEFAULT_FLAGS="DEFAULT_FLAGS",t.CACHE="CACHE",t.SERVER="SERVER"}(s||(s={}));var v,g=null,f="FLAGSMITH_EVENT",p="https://edge.api.flagsmith.com/api/v1/",y=function(){function a(e){var n=this;this._trigger=null,this._triggerLoadingState=null,this.timestamp=null,this.isLoading=!1,this.eventSource=null,this.getFlags=function(){var e=n,i=e.api,a=e.evaluationContext;n.log("Get Flags"),n.isLoading=!0,n.loadingState.isFetching||n.setLoadingState(t(t({},n.loadingState),{isFetching:!0}));var o="".concat(n.getContext().identity),l=function(e){var i,a,l,h;if(e&&o==="".concat(n.getContext().identity)){var c=e.flags,d=e.traits,v=e.identifier;n.isLoading=!1;var g={},f={};d=d||[],(c=c||[]).forEach((function(t){g[t.feature.name.toLowerCase().replace(/ /g,"_")]={id:t.feature.id,enabled:t.enabled,value:t.feature_state_value}})),d.forEach((function(t){f[t.trait_key.toLowerCase().replace(/ /g,"_")]={transient:t.transient,value:t.trait_value}})),n.oldFlags=t({},n.flags);var p=r(n.oldFlags,g),y=r(null===(i=n.evaluationContext.identity)||void 0===i?void 0:i.traits,f);if((v||Object.keys(f).length)&&(n.evaluationContext.identity=t(t({},n.evaluationContext.identity),{traits:f}),v&&(n.evaluationContext.identity.identifier=v,n.identity=v)),n.flags=g,n.updateStorage(),n._onChange(n.oldFlags,{isFromServer:!0,flagsChanged:p,traitsChanged:y},n._loadedState(null,s.SERVER)),n.datadogRum)try{if(n.datadogRum.trackTraits){var m={};Object.keys((null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.traits)||{}).map((function(t){m["flagsmith_trait_"+t]=n.getTrait(t)}));var S=t(t(t({},n.datadogRum.client.getUser()),{id:n.datadogRum.client.getUser().id||(null===(l=n.evaluationContext.identity)||void 0===l?void 0:l.identifier)}),m);n.log("Setting Datadog user",S),n.datadogRum.client.setUser(S)}}catch(t){console.error(t)}if(n.dtrum)try{var _={javaDouble:{},date:{},shortString:{},javaLongOrObject:{}};Object.keys(n.flags).map((function(t){u(_,"flagsmith_value_"+t,n.getValue(t,{skipAnalytics:!0})),u(_,"flagsmith_enabled_"+t,n.hasFeature(t,{skipAnalytics:!0}))})),Object.keys((null===(h=n.evaluationContext.identity)||void 0===h?void 0:h.traits)||{}).map((function(t){u(_,"flagsmith_trait_"+t,n.getTrait(t))})),n.log("Sending javaLongOrObject traits to dynatrace",_.javaLongOrObject),n.log("Sending date traits to dynatrace",_.date),n.log("Sending shortString traits to dynatrace",_.shortString),n.log("Sending javaDouble to dynatrace",_.javaDouble),n.dtrum.sendSessionProperties(_.javaLongOrObject,_.date,_.shortString,_.javaDouble)}catch(t){console.error(t)}}};return a.identity?Promise.all([a.identity.traits&&Object.keys(a.identity.traits).length||!a.identity.identifier?n.getJSON(i+"identities/","POST",JSON.stringify({identifier:a.identity.identifier,transient:a.identity.transient,traits:Object.entries(a.identity.traits).map((function(t){var e=t[0],n=t[1];return{trait_key:e,trait_value:null==n?void 0:n.value,transient:null==n?void 0:n.transient}})).filter((function(t){return void 0!==t.trait_value||(n.log("Warning - attempted to set an undefined trait value for key",t.trait_key),!1)}))})):n.getJSON(i+"identities/?identifier="+encodeURIComponent(a.identity.identifier)+(a.identity.transient?"&transient=true":""))]).then((function(e){return n.evaluationContext.identity=t(t({},n.evaluationContext.identity),{traits:{}}),l(null==e?void 0:e[0])})).catch((function(t){var e=t.message,n=new Error(e);return Promise.reject(n)})):n.getJSON(i+"flags/").then((function(t){return l({flags:t,traits:void 0})}))},this.analyticsFlags=function(){var e=n.api;if(n.evaluationEvent&&n.evaluationContext.environment&&n.evaluationEvent[n.evaluationContext.environment.apiKey])return n.evaluationEvent&&0!==Object.getOwnPropertyNames(n.evaluationEvent).length&&0!==Object.getOwnPropertyNames(n.evaluationEvent[n.evaluationContext.environment.apiKey]).length?n.getJSON(e+"analytics/flags/","POST",JSON.stringify(n.evaluationEvent[n.evaluationContext.environment.apiKey])).then((function(e){if(n.evaluationContext.environment){var i=n.getState();n.evaluationEvent||(n.evaluationEvent={}),n.evaluationEvent[n.evaluationContext.environment.apiKey]={},n.setState(t(t({},i),{evaluationEvent:n.evaluationEvent})),n.updateEventStorage()}})).catch((function(t){n.log("Exception fetching evaluationEvent",t)})):void 0},this.datadogRum=null,this.loadingState={isLoading:!0,isFetching:!0,error:null,source:s.NONE},this.canUseStorage=!1,this.analyticsInterval=null,this.api=null,this.cacheFlags=!1,this.enableAnalytics=!1,this.enableLogs=!1,this.evaluationContext={},this.evaluationEvent=null,this.flags=null,this.getFlagInterval=null,this.headers=null,this.identity=null,this.initialised=!1,this.oldFlags=null,this.onChange=null,this.onError=null,this.ticks=null,this.timer=null,this.dtrum=null,this.sentryClient=null,this.withTraits=null,this.cacheOptions={ttl:0,skipAPI:!1,loadStale:!1,storageKey:void 0},this.getValue=function(t,e,i){var a=n.flags&&n.flags[t.toLowerCase().replace(/ /g,"_")],o=null;if(a&&(o=a.value),(null==e?void 0:e.skipAnalytics)||i||n.evaluateFlag(t,"VALUE"),null===o&&void 0!==(null==e?void 0:e.fallback))return e.fallback;if(null==e?void 0:e.json)try{return null===o?(n.log("Tried to parse null flag as JSON: "+t),null):JSON.parse(o)}catch(t){return e.fallback}return o},this.getTrait=function(t){var e,i;return(null===(e=n.evaluationContext.identity)||void 0===e?void 0:e.traits)&&(null===(i=n.evaluationContext.identity.traits[t.toLowerCase().replace(/ /g,"_")])||void 0===i?void 0:i.value)},this.getAllTraits=function(){var t;return Object.fromEntries(Object.entries((null===(t=n.evaluationContext.identity)||void 0===t?void 0:t.traits)||{}).map((function(t){var e=t[0],n=t[1];return[e,null==n?void 0:n.value]})))},this.setContext=function(e){var i,a,o=d(e);return n.evaluationContext=t(t({},o),{environment:o.environment||n.evaluationContext.environment}),n.identity=null===(a=null===(i=n.getContext())||void 0===i?void 0:i.identity)||void 0===a?void 0:a.identifier,n.initialised?n.getFlags():Promise.resolve()},this.getContext=function(){return n.evaluationContext},this.updateContext=function(e){return n.setContext(t(t({},n.getContext()),e))},this.setTrait=function(e,i){var a;if(n.api)return n.setContext(t(t({},n.evaluationContext),{identity:t(t({},n.evaluationContext.identity),{traits:t(t({},null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.traits),c(Object.fromEntries([[e,i]])))})}))},this.setTraits=function(e){var i;if(n.api)return n.setContext(t(t({},n.evaluationContext),{identity:t(t({},n.evaluationContext.identity),{traits:t(t({},null===(i=n.evaluationContext.identity)||void 0===i?void 0:i.traits),Object.fromEntries(Object.entries(e).map((function(t){var e=t[0],n=t[1];return[e,h(n)?n:{value:n}]}))))})}));console.error("Attempted to "+"setTraits"+" a user before calling flagsmith.init. Call flagsmith.init first, if you wish to prevent it sending a request for flags, call init with preventFetch:true.")},this.hasFeature=function(t,e){var i,a,o="object"==typeof e,r=n.flags&&n.flags[t.toLowerCase().replace(/ /g,"_")],s=!1;if(!r&&o&&void 0!==e.fallback?s=null==e?void 0:e.fallback:r&&r.enabled&&(s=!0),(o&&!e.skipAnalytics||!e)&&n.evaluateFlag(t,"ENABLED"),n.sentryClient)try{null===(a=null===(i=n.sentryClient.getIntegrationByName("FeatureFlags"))||void 0===i?void 0:i.addFeatureFlag)||void 0===a||a.call(i,t,s)}catch(t){console.error(t)}return s},this.getStorageKey=function(){var t,e;return(null===(t=n.cacheOptions)||void 0===t?void 0:t.storageKey)||"FLAGSMITH_DB_"+(null===(e=n.evaluationContext.environment)||void 0===e?void 0:e.apiKey)},this.getJSON=function(t,e,i){var a,o,r,s=n.headers,u={method:e||"GET",body:i,cache:"no-cache",headers:{}};n.evaluationContext.environment&&(u.headers["X-Environment-Key"]=n.evaluationContext.environment.apiKey),e&&"GET"!==e&&(u.headers["Content-Type"]="application/json; charset=utf-8"),(null===(a=n.applicationMetadata)||void 0===a?void 0:a.name)&&(u.headers["Flagsmith-Application-Name"]=n.applicationMetadata.name),(null===(o=n.applicationMetadata)||void 0===o?void 0:o.version)&&(u.headers["Flagsmith-Application-Version"]=n.applicationMetadata.version),s&&Object.assign(u.headers,s),l||console.error("Flagsmith: fetch is undefined, please specify a fetch implementation into flagsmith.init to support SSR.");var h="".concat(null===(r=n.evaluationContext.identity)||void 0===r?void 0:r.identifier);return l(t,u).then((function(i){var a,o,r="".concat(null===(a=n.evaluationContext.identity)||void 0===a?void 0:a.identifier);if(h===r){var s=null===(o=i.headers)||void 0===o?void 0:o.get("x-flagsmith-document-updated-at");if(s)try{var l=parseFloat(s);if(isNaN(l))return Promise.reject("Failed to parse x-flagsmith-document-updated-at");n.timestamp=l}catch(t){n.log(t,"Failed to parse x-flagsmith-document-updated-at",s)}return n.log("Fetch response: "+i.status+" "+(e||"GET")+0+t),i.text().then((function(t){var e=t;try{e=JSON.parse(t)}catch(t){}return!e&&i.status&&(e="API Response: ".concat(i.status)),i.status&&i.status>=200&&i.status<300?e:Promise.reject(new Error(e))}))}n.log("Received response with identity mismatch, ignoring response. Requested: ".concat(h,", Current: ").concat(r))}))},this.evaluateFlag=function(t,e){if(n.datadogRum&&(n.datadogRum.client.addFeatureFlagEvaluation?"VALUE"===e?n.datadogRum.client.addFeatureFlagEvaluation("flagsmith_value_"+t,n.getValue(t,{},!0)):n.datadogRum.client.addFeatureFlagEvaluation("flagsmith_enabled_"+t,n.hasFeature(t,!0)):console.error("Flagsmith: Your datadog RUM client does not support the function addFeatureFlagEvaluation, please update it.")),n.enableAnalytics){if(!n.evaluationEvent||!n.evaluationContext.environment)return;n.evaluationEvent[n.evaluationContext.environment.apiKey]||(n.evaluationEvent[n.evaluationContext.environment.apiKey]={}),void 0===n.evaluationEvent[n.evaluationContext.environment.apiKey][t]&&(n.evaluationEvent[n.evaluationContext.environment.apiKey][t]=0),n.evaluationEvent[n.evaluationContext.environment.apiKey][t]+=1}n.updateEventStorage()},this._onChange=function(t,e,i){var a,o;n.setLoadingState(i),null===(a=n.onChange)||void 0===a||a.call(n,t,e,n.loadingState),null===(o=n._trigger)||void 0===o||o.call(n)},l=e.fetch?e.fetch:"undefined"!=typeof fetch?fetch:null===global||void 0===global?void 0:global.fetch,this.canUseStorage="undefined"!=typeof window||!!e.browserlessStorage,this.applicationMetadata=e.applicationMetadata,this.log("Constructing flagsmith instance "+e),e.eventSource&&(v=e.eventSource),e.AsyncStorage&&(g=e.AsyncStorage)}return a.prototype.init=function(i){var a,o,u;return e(this,void 0,void 0,(function(){var h,c,v,y,m,S,_,E,C,x,b,O,F,I,w,L,j,A,N,R,T,k,P,D,H,K,M,G,U,J,q,V,X,W,$=this;return n(this,(function(B){switch(B.label){case 0:h=d(i.evaluationContext||this.evaluationContext),B.label=1;case 1:if(B.trys.push([1,13,,14]),c=i.AsyncStorage,v=i._trigger,y=i._triggerLoadingState,m=i.angularHttpClient,S=i.api,_=void 0===S?p:S,E=i.applicationMetadata,C=i.cacheFlags,x=i.cacheOptions,b=i.datadogRum,O=i.defaultFlags,F=i.enableAnalytics,I=i.enableDynatrace,w=i.enableLogs,L=i.environmentID,j=i.eventSourceUrl,A=void 0===j?"https://realtime.flagsmith.com/":j,N=i.fetch,R=i.headers,T=i.identity,k=i.onChange,P=i.onError,D=i.preventFetch,H=i.realtime,K=i.sentryClient,M=i.state,G=i.traits,h.environment=L?{apiKey:L}:h.environment,!h.environment||!h.environment.apiKey)throw new Error("Please provide `evaluationContext.environment` with non-empty `apiKey`");if(h.identity=T||G?{identifier:T,traits:G?Object.fromEntries(Object.entries(G).map((function(t){return[t[0],{value:t[1]}]}))):{}}:h.identity,this.evaluationContext=h,this.api=(Y=_).endsWith("/")?Y:Y+"/",this.headers=R,this.getFlagInterval=null,this.analyticsInterval=null,this.onChange=k,U="Wrong Flagsmith Configuration: preventFetch is true and no defaulFlags provided",this._trigger=v||this._trigger,this._triggerLoadingState=y||this._triggerLoadingState,this.onError=function(e){$.setLoadingState(t(t({},$.loadingState),{isFetching:!1,isLoading:!1,error:e})),null==P||P(e)},this.enableLogs=w||!1,this.cacheOptions=x?{skipAPI:!!x.skipAPI,ttl:x.ttl||0,storageKey:x.storageKey,loadStale:!!x.loadStale}:this.cacheOptions,!this.cacheOptions.ttl&&this.cacheOptions.skipAPI&&console.warn("Flagsmith: you have set a cache ttl of 0 and are skipping API calls, this means the API will not be hit unless you clear local storage."),N&&(l=N),this.enableAnalytics=F||!1,this.flags=Object.assign({},O)||{},this.datadogRum=b||null,this.initialised=!0,this.ticks=1e4,this.timer=this.enableLogs?(new Date).valueOf():null,this.cacheFlags=void 0!==g&&!!C,this.applicationMetadata=E,f="FLAGSMITH_EVENT_"+h.environment.apiKey,c&&(g=c),H&&"undefined"!=typeof window&&this.setupRealtime(A,h.environment.apiKey),Object.keys(this.flags).length&&(this.loadingState=t(t({},this.loadingState),{isLoading:!1,source:s.DEFAULT_FLAGS})),this.setState(M),this.log("Initialising with properties",i,this),I&&("undefined"==typeof dtrum?console.error("You have attempted to enable dynatrace but dtrum is undefined, please check you have the Dynatrace RUM JavaScript API installed."):this.dtrum=dtrum),K&&(this.sentryClient=K),m&&(l=function(t){return function(e,n){var i=n.headers,a=n.method,o=n.body;return new Promise((function(n){switch(a){case"GET":return t.get(e,{headers:i}).subscribe((function(t){n({ok:!0,text:function(){return Promise.resolve(t)}})}));case"POST":case"PUT":return t.post(e,o,{headers:i}).subscribe((function(t){n({ok:!0,text:function(){return Promise.resolve(t)}})}))}}))}}(m)),g&&this.canUseStorage&&g.getItem(f).then((function(t){try{$.evaluationEvent=JSON.parse(t)||{}}catch(t){$.evaluationEvent={}}$.analyticsInterval=setInterval($.analyticsFlags,$.ticks)})),this.enableAnalytics&&(this.analyticsInterval&&clearInterval(this.analyticsInterval),g&&this.canUseStorage&&g.getItem(f,(function(e,n){if(n&&$.evaluationContext.environment){var i=JSON.parse(n);if(i[$.evaluationContext.environment.apiKey]){var a=$.getState();$.log("Retrieved events from cache",n),$.setState(t(t({},a),{evaluationEvent:i[$.evaluationContext.environment.apiKey]}))}}}))),!C)return[3,9];if(!g||!this.canUseStorage)return[3,8];J=function(i,a){return e($,void 0,void 0,(function(){var e,i,o,l,u,h,c,v,g,f,p,y,m,S,_,E,C,x,b,F=this;return n(this,(function(n){switch(n.label){case 0:if(!a)return[3,7];e=null,i=null,n.label=1;case 1:return n.trys.push([1,5,,6]),o=JSON.parse(a),l=!1,u=!1,o&&o.api===this.api&&(null===(f=null===(g=o.evaluationContext)||void 0===g?void 0:g.environment)||void 0===f?void 0:f.apiKey)===(null===(p=this.evaluationContext.environment)||void 0===p?void 0:p.apiKey)&&(h=!0,this.evaluationContext.identity&&(null===(m=null===(y=o.evaluationContext)||void 0===y?void 0:y.identity)||void 0===m?void 0:m.identifier)!==this.evaluationContext.identity.identifier&&(this.log("Ignoring cache, identity has changed from "+(null===(_=null===(S=o.evaluationContext)||void 0===S?void 0:S.identity)||void 0===_?void 0:_.identifier)+" to "+this.evaluationContext.identity.identifier),h=!1),this.cacheOptions.ttl&&(!o.ts||(new Date).valueOf()-o.ts>this.cacheOptions.ttl)&&(o.ts&&!this.cacheOptions.loadStale?(this.log("Ignoring cache, timestamp is too old ts:"+o.ts+" ttl: "+this.cacheOptions.ttl+" time elapsed since cache: "+((new Date).valueOf()-o.ts)+"ms"),h=!1):o.ts&&this.cacheOptions.loadStale&&(this.log("Loading stale cache, timestamp ts:"+o.ts+" ttl: "+this.cacheOptions.ttl+" time elapsed since cache: "+((new Date).valueOf()-o.ts)+"ms"),u=!0,h=!0)),h&&(l=!0,e=r(this.flags,o.flags),this.setState(t(t({},o),{evaluationContext:d(t(t({},o.evaluationContext),{identity:(null===(E=o.evaluationContext)||void 0===E?void 0:E.identity)?t(t({},null===(C=o.evaluationContext)||void 0===C?void 0:C.identity),{traits:t({},G||{})}):void 0}))})),this.log("Retrieved flags from cache",o))),l?(c=!D&&(!this.cacheOptions.skipAPI||u),this._onChange(null,{isFromServer:!1,flagsChanged:e,traitsChanged:i},this._loadedState(null,s.CACHE,c)),this.oldFlags=this.flags,this.cacheOptions.skipAPI&&l&&!u&&this.log("Skipping API, using cache"),c&&this.getFlags().catch((function(t){var e;null===(e=F.onError)||void 0===e||e.call(F,t)})),[3,4]):[3,2];case 2:return D?[3,4]:[4,this.getFlags()];case 3:n.sent(),n.label=4;case 4:return[3,6];case 5:return v=n.sent(),this.log("Exception fetching cached logs",v),[3,6];case 6:return[3,10];case 7:return D?[3,9]:[4,this.getFlags()];case 8:return n.sent(),[3,10];case 9:if(O)this._onChange(null,{isFromServer:!1,flagsChanged:r({},this.flags),traitsChanged:r({},null===(x=this.evaluationContext.identity)||void 0===x?void 0:x.traits)},this._loadedState(null,s.DEFAULT_FLAGS));else{if(!this.flags)throw new Error(U);this._onChange(null,{isFromServer:!1,flagsChanged:r({},this.flags),traitsChanged:r({},null===(b=this.evaluationContext.identity)||void 0===b?void 0:b.traits)},this._loadedState(null,s.DEFAULT_FLAGS))}n.label=10;case 10:return[2]}}))}))},B.label=2;case 2:return B.trys.push([2,7,,8]),g.getItemSync?(q=g.getItemSync(this.getStorageKey()),[3,5]):[3,3];case 3:return[4,g.getItem(this.getStorageKey())];case 4:q=B.sent(),B.label=5;case 5:return[4,J(null,q)];case 6:case 7:return B.sent(),[3,8];case 8:return[3,12];case 9:return D?[3,11]:[4,this.getFlags()];case 10:return B.sent(),[3,12];case 11:if(O)this._onChange(null,{isFromServer:!1,flagsChanged:r({},O),traitsChanged:r({},null===(a=h.identity)||void 0===a?void 0:a.traits)},this._loadedState(null,s.DEFAULT_FLAGS));else if(this.flags&&(V=null,0===Object.keys(this.flags).length&&(V=U),this._onChange(null,{isFromServer:!1,flagsChanged:r({},this.flags),traitsChanged:r({},null===(o=h.identity)||void 0===o?void 0:o.traits)},this._loadedState(V,s.DEFAULT_FLAGS)),V))throw new Error(V);B.label=12;case 12:return[3,14];case 13:throw X=B.sent(),this.log("Error during initialisation ",X),W=X instanceof Error?X:new Error("".concat(X)),null===(u=this.onError)||void 0===u||u.call(this,W),X;case 14:return[2]}var Y}))}))},a.prototype.getAllFlags=function(){return this.flags},a.prototype.identify=function(t,e,n){return this.identity=t,this.evaluationContext.identity={identifier:t,transient:n,traits:this.evaluationContext.identity&&this.evaluationContext.identity.identifier==t?this.evaluationContext.identity.traits:{}},this.evaluationContext.identity.identifier=t,this.log("Identify: "+this.evaluationContext.identity.identifier),e&&(this.evaluationContext.identity.traits=Object.fromEntries(Object.entries(e).map((function(t){var e=t[0],n=t[1];return[e,h(n)?n:{value:n}]})))),this.initialised?this.getFlags():Promise.resolve()},a.prototype.getState=function(){return{api:this.api,flags:this.flags,ts:this.ts,evaluationContext:this.evaluationContext,identity:this.identity,evaluationEvent:this.evaluationEvent}},a.prototype.setState=function(t){var e,n;t&&(this.initialised=!0,this.api=t.api||this.api||p,this.flags=t.flags||this.flags,this.evaluationContext=t.evaluationContext||this.evaluationContext,this.evaluationEvent=t.evaluationEvent||this.evaluationEvent,this.identity=null===(n=null===(e=this.getContext())||void 0===e?void 0:e.identity)||void 0===n?void 0:n.identifier,this.log("setState called",this))},a.prototype.logout=function(){return this.identity=null,this.evaluationContext.identity=null,this.initialised?this.getFlags():Promise.resolve()},a.prototype.startListening=function(t){void 0===t&&(t=1e3),this.getFlagInterval&&clearInterval(this.getFlagInterval),this.getFlagInterval=setInterval(this.getFlags,t)},a.prototype.stopListening=function(){this.getFlagInterval&&(clearInterval(this.getFlagInterval),this.getFlagInterval=null)},a.prototype._loadedState=function(t,e,n){return void 0===t&&(t=null),void 0===n&&(n=!1),{error:t,isFetching:n,isLoading:!1,source:e}},a.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.enableLogs&&console.log.apply(this,i(["FLAGSMITH:",(new Date).valueOf()-(this.timer||0),"ms"],t,!0))},a.prototype.updateStorage=function(){if(this.cacheFlags){this.ts=(new Date).valueOf();var t=JSON.stringify(this.getState());this.log("Setting storage",t),g.setItem(this.getStorageKey(),t)}},a.prototype.updateEventStorage=function(){if(this.enableAnalytics){var t=JSON.stringify(this.getState().evaluationEvent);g.setItem(f,t).catch((function(t){return console.error("Flagsmith: Error setting item in async storage",t)}))}},a.prototype.setLoadingState=function(e){var n;o(e,this.loadingState)||(this.loadingState=t({},e),this.log("Loading state changed",e),null===(n=this._triggerLoadingState)||void 0===n||n.call(this))},a.prototype.setupRealtime=function(t,e){var n=this,i=t+"sse/environments/"+e+"/stream";v?this.eventSource||(this.log("Creating event source with url "+i),this.eventSource=new v(i),this.eventSource.addEventListener("environment_updated",(function(t){var e;try{e=JSON.parse(t.data).updated_at}catch(t){n.log("Could not parse sse event",t)}e?!n.timestamp||e>n.timestamp?n.isLoading?n.log("updated_at is new, but flags are loading",t.data,n.timestamp):(n.log("updated_at is new, fetching flags",t.data,n.timestamp),n.getFlags()):n.log("updated_at is outdated, skipping get flags",t.data,n.timestamp):n.log("No updated_at received, fetching flags",t)}))):this.log("Error, EventSource is undefined")},a}();function m(t){var e=t.fetch,n=t.AsyncStorage,i=t.eventSource;return new y({fetch:e,AsyncStorage:n,eventSource:i})}var S,_=a(Object.freeze({__proto__:null,default:class{ERROR=-1;CONNECTING=0;OPEN=1;CLOSED=2;constructor(t,e={}){if(this.interval=e.pollingInterval||5e3,this.lastEventId=null,this.lastIndexProcessed=0,this.eventType=void 0,this.status=this.CONNECTING,this.eventHandlers={open:[],message:[],error:[],close:[]},this.method=e.method||"GET",this.timeout=e.timeOut||0,this.headers=e.headers||{},this.body=e.body||void 0,this.debug=e.debug||!1,this._xhr=null,this._pollTimer=null,!t||"string"!=typeof t&&"function"!=typeof t.toString)throw new SyntaxError("[EventSource] Invalid URL argument.");"function"==typeof t.toString?this.url=t.toString():this.url=t,this._pollAgain(500)}_pollAgain(t){this._pollTimer=setTimeout((()=>{this.open()}),t)}open(){try{if(this.lastIndexProcessed=0,this.status=this.CONNECTING,this._xhr=new XMLHttpRequest,this._xhr.open(this.method,this.url,!0),this.headers)for(const[t,e]of Object.entries(this.headers))this._xhr.setRequestHeader(t,e);this._xhr.setRequestHeader("Accept","text/event-stream"),this._xhr.setRequestHeader("Cache-Control","no-cache"),this._xhr.setRequestHeader("X-Requested-With","XMLHttpRequest"),null!==this.lastEventId&&this._xhr.setRequestHeader("Last-Event-ID",this.lastEventId),this._xhr.timeout=this.timeout,this._xhr.onreadystatechange=()=>{const t=this._xhr;this.debug&&console.debug(`[EventSource][onreadystatechange] ReadyState: ${t.readyState}, status: ${t.status}`),[XMLHttpRequest.DONE,XMLHttpRequest.LOADING].includes(t.readyState)&&(t.status>=200&&t.status<400?(this.status===this.CONNECTING&&(this.status=this.OPEN,this.dispatch("open",{type:"open"})),this._handleEvent(t.responseText||""),t.readyState===XMLHttpRequest.DONE&&(this.debug&&console.debug("[EventSource][onreadystatechange][DONE] Operation done. Reconnecting..."),this._pollAgain(this.interval))):this.status!==this.CLOSED&&(0!==this._xhr.status&&this.dispatch("error",{type:"error",message:t.responseText,xhrStatus:t.status,xhrState:t.readyState}),[XMLHttpRequest.DONE,XMLHttpRequest.UNSENT].includes(t.readyState)&&(this.debug&&console.debug("[EventSource][onreadystatechange][ERROR] Response status error. Reconnecting..."),this._pollAgain(this.interval))))},this._xhr.onerror=t=>{this.status,this.ERROR,this.dispatch("error",{type:"error",message:this._xhr.responseText,xhrStatus:this._xhr.status,xhrState:this._xhr.readyState})},this.body?this._xhr.send(this.body):this._xhr.send(),this.timeout>0&&setTimeout((()=>{this._xhr.readyState===XMLHttpRequest.LOADING&&(this.dispatch("error",{type:"timeout"}),this.close())}),this.timeout)}catch(t){this.status=this.ERROR,this.dispatch("error",{type:"exception",message:t.message,error:t})}}_handleEvent(t){const e=t.substr(this.lastIndexProcessed).split("\n");this.lastIndexProcessed=t.lastIndexOf("\n\n")+2;let n=[],i=0,a="";for(let t=0;t<e.length;t++)if(a=e[t].replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g,""),0===a.indexOf("event"))this.eventType=a.replace(/event:?\s*/,"");else if(0===a.indexOf("retry"))i=parseInt(a.replace(/retry:?\s*/,""),10),isNaN(i)||(this.interval=i);else if(0===a.indexOf("data"))n.push(a.replace(/data:?\s*/,""));else if(0===a.indexOf("id:"))this.lastEventId=a.replace(/id:?\s*/,"");else if(0===a.indexOf("id"))this.lastEventId=null;else if(""===a&&n.length>0){const t=this.eventType||"message",e={type:t,data:n.join("\n"),url:this.url,lastEventId:this.lastEventId};this.dispatch(t,e),n=[],this.eventType=void 0}}addEventListener(t,e){void 0===this.eventHandlers[t]&&(this.eventHandlers[t]=[]),this.eventHandlers[t].push(e)}removeEventListener(t,e){void 0!==this.eventHandlers[t]&&(this.eventHandlers[t]=this.eventHandlers[t].filter((t=>t!==e)))}removeAllEventListeners(t){const e=Object.keys(this.eventHandlers);if(void 0===t)for(const t of e)this.eventHandlers[t]=[];else{if(!e.includes(t))throw Error(`[EventSource] '${t}' type is not supported event type.`);this.eventHandlers[t]=[]}}dispatch(t,e){if(Object.keys(this.eventHandlers).includes(t))for(const n of Object.values(this.eventHandlers[t]))n(e)}close(){this.status=this.CLOSED,clearTimeout(this._pollTimer),this._xhr&&this._xhr.abort(),this.dispatch("close",{type:"close"})}}})),E=(S=function(t,e){return S=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},S(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}S(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),C=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],i=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},x=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,a,o=n.call(t),r=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)r.push(i.value)}catch(t){a={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return r},b=function(t,e,n){if(n||2===arguments.length)for(var i,a=0,o=e.length;a<o;a++)!i&&a in e||(i||(i=Array.prototype.slice.call(e,0,a)),i[a]=e[a]);return t.concat(i||Array.prototype.slice.call(e))},O=function(t){function e(){return t.call(this,"EventSource not available.\nConsider loading an EventSource polyfill and making it available globally as EventSource, or passing one in as eventSourceClass to the ReconnectingEventSource constructor.")||this}return E(e,t),e}(Error),F=function(){function t(t,e){var n=this;if(this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,this._configuration=null!=e?Object.assign({},e):void 0,this.withCredentials=!1,this._eventSource=null,this._lastEventId=null,this._timer=null,this._listeners={open:[],error:[],message:[]},this.url=t.toString(),this.readyState=this.CONNECTING,this.max_retry_time=3e3,this.eventSourceClass=globalThis.FlagsmithEventSource,null!=this._configuration&&(this._configuration.lastEventId&&(this._lastEventId=this._configuration.lastEventId,delete this._configuration.lastEventId),this._configuration.max_retry_time&&(this.max_retry_time=this._configuration.max_retry_time,delete this._configuration.max_retry_time),this._configuration.eventSourceClass&&(this.eventSourceClass=this._configuration.eventSourceClass,delete this._configuration.eventSourceClass)),null==this.eventSourceClass||"function"!=typeof this.eventSourceClass)throw new O;this._onevent_wrapped=function(t){n._onevent(t)},this._start()}return t.prototype.dispatchEvent=function(t){throw new Error("Method not implemented.")},t.prototype._start=function(){var t,e,n=this,i=this.url;this._lastEventId&&(-1===i.indexOf("?")?i+="?":i+="&",i+="lastEventId="+encodeURIComponent(this._lastEventId)),this._eventSource=new this.eventSourceClass(i,this._configuration),this._eventSource.onopen=function(t){n._onopen(t)},this._eventSource.onerror=function(t){n._onerror(t)},this._eventSource.onmessage=function(t){n.onmessage(t)};try{for(var a=C(Object.keys(this._listeners)),o=a.next();!o.done;o=a.next()){var r=o.value;this._eventSource.addEventListener(r,this._onevent_wrapped)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}},t.prototype._onopen=function(t){0===this.readyState&&(this.readyState=1,this.onopen(t))},t.prototype._onerror=function(t){var e=this;if(1===this.readyState&&(this.readyState=0,this.onerror(t)),this._eventSource){this._eventSource.close(),this._eventSource=null;var n=Math.round(this.max_retry_time*Math.random());this._timer=setTimeout((function(){return e._start()}),n)}},t.prototype._onevent=function(t){var e,n;t&&t.lastEventId&&(this._lastEventId=t.lastEventId);var i=this._listeners[t.type];if(null!=i)try{for(var a=C(b([],x(i),!1)),o=a.next();!o.done;o=a.next()){o.value.call(this,t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}"message"===t.type&&this.onmessage(t)},t.prototype.onopen=function(t){},t.prototype.onerror=function(t){},t.prototype.onmessage=function(t){},t.prototype.close=function(){this._timer&&(clearTimeout(this._timer),this._timer=null),this._eventSource&&(this._eventSource.close(),this._eventSource=null),this.readyState=2},t.prototype.addEventListener=function(t,e,n){null==this._listeners[t]&&(this._listeners[t]=[],null!=this._eventSource&&this._eventSource.addEventListener(t,this._onevent_wrapped));var i=this._listeners[t];i.includes(e)||(this._listeners[t]=b(b([],x(i),!1),[e],!1))},t.prototype.removeEventListener=function(t,e,n){var i=this._listeners[t];this._listeners[t]=i.filter((function(t){return t!==e}))},t}();global.FlagsmithEventSource=_.default;var I=m({browserlessStorage:!0,eventSource:F});const w=()=>m({browserlessStorage:!0,eventSource:F});export{w as createFlagsmithInstance,I as default};
//# sourceMappingURL=index.mjs.map
{
"name": "react-native-flagsmith",
"version": "9.2.2",
"version": "9.3.0",
"description": "Feature flagging to support continuous development",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -9,3 +9,3 @@ import React, { FC } from 'react';

serverState?: IState;
children: React.ReactElement[] | React.ReactElement;
children: React.ReactNode;
};

@@ -12,0 +12,0 @@ type UseFlagsReturn<

@@ -12,2 +12,3 @@ import {

IInitConfig,
ISentry,
IState,

@@ -171,3 +172,2 @@ ITraits,

}
if (this.dtrum) {

@@ -291,2 +291,3 @@ try {

dtrum= null
sentryClient: ISentry | null = null
withTraits?: ITraits|null= null

@@ -298,26 +299,27 @@ cacheOptions = {ttl:0, skipAPI: false, loadStale: false, storageKey: undefined as string|undefined}

const {
environmentID,
AsyncStorage: _AsyncStorage,
_trigger,
_triggerLoadingState,
angularHttpClient,
api = defaultAPI,
headers,
onChange,
applicationMetadata,
cacheFlags,
cacheOptions,
datadogRum,
onError,
defaultFlags,
enableAnalytics,
enableDynatrace,
enableLogs,
environmentID,
eventSourceUrl= "https://realtime.flagsmith.com/",
fetch: fetchImplementation,
headers,
identity,
onChange,
onError,
preventFetch,
enableLogs,
enableDynatrace,
enableAnalytics,
realtime,
eventSourceUrl= "https://realtime.flagsmith.com/",
AsyncStorage: _AsyncStorage,
identity,
sentryClient,
state,
traits,
state,
cacheOptions,
angularHttpClient,
_trigger,
_triggerLoadingState,
applicationMetadata,
} = config;

@@ -403,2 +405,5 @@ evaluationContext.environment = environmentID ? {apiKey: environmentID} : evaluationContext.environment;

if(sentryClient) {
this.sentryClient = sentryClient
}
if (angularHttpClient) {

@@ -767,2 +772,11 @@ // @ts-expect-error

}
if(this.sentryClient) {
try {
this.sentryClient.getIntegrationByName(
"FeatureFlags",
)?.addFeatureFlag?.(key, res);
} catch (e) {
console.error(e)
}
}

@@ -769,0 +783,0 @@ return res;

@@ -79,2 +79,10 @@ import { EvaluationContext, IdentityEvaluationContext, TraitEvaluationContext } from "./evaluation-context";

export type ISentry = {
getIntegrationByName(name:"FeatureFlags"): {
addFeatureFlag(flag: string, enabled: boolean): void;
} | undefined;
} | undefined;
export declare enum FlagSource {

@@ -108,2 +116,3 @@ "NONE" = "NONE",

datadogRum?: IDatadogRum;
sentryClient?: ISentryClient;
defaultFlags?: IFlags<FKey<F>>;

@@ -153,3 +162,3 @@ fetch?: any;

: IFlagsmithValue;
/**

@@ -156,0 +165,0 @@ * Example usage:

@@ -79,2 +79,10 @@ import { EvaluationContext, IdentityEvaluationContext, TraitEvaluationContext } from "./evaluation-context";

export type ISentry = {
getIntegrationByName(name:"FeatureFlags"): {
addFeatureFlag(flag: string, enabled: boolean): void;
} | undefined;
} | undefined;
export declare enum FlagSource {

@@ -108,2 +116,3 @@ "NONE" = "NONE",

datadogRum?: IDatadogRum;
sentryClient?: ISentryClient;
defaultFlags?: IFlags<FKey<F>>;

@@ -153,3 +162,3 @@ fetch?: any;

: IFlagsmithValue;
/**

@@ -156,0 +165,0 @@ * Example usage:

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display