launchdarkly-js-client-sdk 2.20.0 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to the LaunchDarkly client-side JavaScript SDKs will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
4
4
 
5
+ ## [2.20.2] - 2022-02-18
6
+ ### Fixed:
7
+ - If the SDK receives invalid JSON data from a streaming connection (possibly as a result of the connection being cut off), it now uses its regular error-handling logic: the error is emitted as an `error` event or, if there are no `error` event listeners, it is logged. Previously, the error would be thrown as an unhandled exception.
8
+
9
+ ## [2.20.1] - 2022-02-02
10
+ ### Fixed:
11
+ - If the browser local storage mechanism throws an exception (for instance, if it is disabled or if storage is full), the SDK now correctly catches the exception and logs a message about the failure. It will only log this message once during the lifetime of the SDK client. ([#54](https://github.com/launchdarkly/js-sdk-common/issues/54))
12
+
5
13
  ## [2.20.0] - 2021-10-15
6
14
  ### Added:
7
15
  - New property `LDOptions.requestHeaderTransform` allows custom headers to be added to all HTTP requests. This may be necessary if you have an Internet gateway that uses a custom header for authentication. Note that custom headers may cause cross-origin browser requests to be rejected unless you have a way to ensure that the header name also appears in `Access-Control-Allow-Headers` for CORS preflight responses; if you are connecting to the LaunchDarkly Relay Proxy, it has a way to configure this.
package/README.md CHANGED
@@ -30,7 +30,7 @@ By default, the SDK sends log output to the browser console. There are four logg
30
30
 
31
31
  ## Learn more
32
32
 
33
- Check out our [documentation](https://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/docs/js-sdk-reference). Additionally, the authoritative full description of all properties, types, and methods is the [online TypeScript documentation](https://launchdarkly.github.io/js-client-sdk/). If you are not using TypeScript, then the types are only for your information and are not enforced, although the properties and methods are still the same as described in the documentation.
33
+ Check out our [documentation](https://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/client-side/javascript). Additionally, the authoritative full description of all properties, types, and methods is the [online TypeScript documentation](https://launchdarkly.github.io/js-client-sdk/). If you are not using TypeScript, then the types are only for your information and are not enforced, although the properties and methods are still the same as described in the documentation.
34
34
 
35
35
  For examples of using the SDK in a simple JavaScript application, see [`hello-js`](https://github.com/launchdarkly/hello-js) and [`hello-bootstrap`](https://github.com/launchdarkly/hello-bootstrap).
36
36
 
@@ -1,2 +1,2 @@
1
- "use strict";function e(n){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(n)}function n(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function t(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),t.push.apply(t,r)}return t}function r(r){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?t(o,!0).forEach(function(e){n(r,e,o[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):t(o).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))})}return r}function i(e){function n(e,n){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=n}return(n.prototype=new Error).name=e,n.prototype.constructor=n}Object.defineProperty(exports,"__esModule",{value:!0});var o=i("LaunchDarklyUnexpectedResponseError"),a=i("LaunchDarklyInvalidEnvironmentIdError"),u=i("LaunchDarklyInvalidUserError"),s=i("LaunchDarklyInvalidEventKeyError"),c=i("LaunchDarklyInvalidArgumentError"),l=i("LaunchDarklyFlagFetchError");function f(e){return!(400<=e&&e<500)||400===e||408===e||429===e}for(var v=Object.freeze({__proto__:null,LDUnexpectedResponseError:o,LDInvalidEnvironmentIdError:a,LDInvalidUserError:u,LDInvalidEventKeyError:s,LDInvalidArgumentError:c,LDFlagFetchError:l,isHttpErrorRecoverable:f}),d=function(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(b(e,i,a<i+16383?a:i+16383));return 1==r?(n=e[t-1],o.push(g[n>>2]+g[n<<4&63]+"==")):2==r&&(n=(e[t-2]<<8)+e[t-1],o.push(g[n>>10]+g[n>>4&63]+g[n<<2&63]+"=")),o.join("")},g=[],m=[],p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",y=0,h=p.length;y<h;++y)g[y]=p[y],m[p.charCodeAt(y)]=y;function b(e,n,t){for(var r,o,i=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),i.push(g[(o=r)>>18&63]+g[o>>12&63]+g[o>>6&63]+g[63&o]);return i.join("")}m["-".charCodeAt(0)]=62,m["_".charCodeAt(0)]=63;var k=Array.isArray,E=Object.keys,w=Object.prototype.hasOwnProperty,D=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function S(e){var n=unescape(encodeURIComponent(e));return d(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function O(e){return S(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function P(e){return JSON.parse(JSON.stringify(e))}function U(e,n){return function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,o,i,a=k(n),u=k(t);if(a&&u){if((o=n.length)!=t.length)return!1;for(r=o;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var s=n instanceof Date,c=t instanceof Date;if(s!=c)return!1;if(s&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var d=E(n);if((o=d.length)!==E(t).length)return!1;for(r=o;0!=r--;)if(!w.call(t,d[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=d[r]],t[i]))return!1;return!0}return n!=n&&t!=t}(e,n)}function I(e){setTimeout(e,0)}function j(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function R(e){var n={};for(var t in e)x(e,t)&&(n[t]={value:e[t],version:0});return n}function T(e){var n={};for(var t in e)x(e,t)&&(n[t]=e[t].value);return n}function N(e,n){for(var t,r=n.slice(0),o=[],i=e;0<r.length;){for(t=[];0<i;){var a=r.shift();if(!a)break;(i-=O(JSON.stringify(a)).length)<0&&0<t.length?r.unshift(a):t.push(a)}i=e,o.push(t)}return o}function F(e){var n=e.version||"3.4.0";return e.userAgent+"/"+n}function C(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":F(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function L(e,n){return n&&n.requestHeaderTransform?n.requestHeaderTransform(r({},e)):e}function A(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return r({},e,{},n)},{})}function x(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function q(e){if(!e)return e;var n;for(var t in D){var o=D[t],i=e[o];void 0!==i&&"string"!=typeof i&&((n=n||r({},e))[o]=String(i))}return n||e}for(var V=Object.freeze({__proto__:null,btoa:S,base64URLEncode:O,clone:P,deepEquals:U,onNextTick:I,wrapPromiseCallback:j,transformValuesToVersionedValues:R,transformVersionedValuesToValues:T,chunkUserEventsForUrl:N,getLDUserAgentString:F,getLDHeaders:C,transformHeaders:L,extend:A,objectHasOwnProperty:x,sanitizeUser:q}),_=function(e,n){return function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}(n={exports:{}}),n.exports}(),J=[],z=0;z<256;++z)J[z]=(z+256).toString(16).substr(1);var M,K,H=function(e,n){var t=n||0,r=J;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")},B=0,$=0,G=function(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||M,a=void 0!==e.clockseq?e.clockseq:K;if(null==i||null==a){var u=_();null==i&&(i=M=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=K=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:$+1,l=s-B+(c-$)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||B<s)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");B=s,K=a;var f=(1e4*(268435455&(s+=122192928e5))+($=c))%4294967296;o[r++]=f>>>24&255,o[r++]=f>>>16&255,o[r++]=f>>>8&255,o[r++]=255&f;var d=s/4294967296*1e4&268435455;o[r++]=d>>>8&255,o[r++]=255&d,o[r++]=d>>>24&15|16,o[r++]=d>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var v=0;v<6;++v)o[r+v]=i[v];return n||H(o)};function X(u,e,s){var t="/a/"+e+".gif",c=A({"Content-Type":"application/json"},C(u,s)),l=u.httpFallbackPing,d={sendChunk:function(e,r,o,n){var i=JSON.stringify(e),a=o?null:G();return n?function n(t){var e=o?c:A({},c,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":a});return u.httpRequest("POST",r,L(e,s),i).promise.then(function(e){if(e)return 400<=e.status&&f(e.status)&&t?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)}).catch(function(){return t?n(!1):Promise.reject()})}(!0).catch(function(){}):(l&&l(r+t+"?d="+O(i)),Promise.resolve())},sendEvents:function(e,n,t){if(!u.httpRequest)return Promise.resolve();var r,o=u.httpAllowsPost();r=o?[e]:N(2e3-n.length,e);for(var i=[],a=0;a<r.length;a++)i.push(d.sendChunk(r[a],n,t,o));return Promise.all(i)}};return d}function W(){var e={},a=0,u=0,s={};return e.summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=s[n];t?t.count=t.count+1:s[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>u&&(u=e.creationDate)}},e.getSummary=function(){var e={},n=!0;for(var t in s){var r=s[t],o=e[r.key];o||(o={default:r.default,counters:[]},e[r.key]=o);var i={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),n=!1}return n?null:{startDate:a,endDate:u,features:e}},e.clearSummary=function(){u=a=0,s={}},e}function Q(e){var n={},s=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},f={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;function n(o,i){return Object.keys(o).reduce(function(e,n){var t,r=e;return i(n)&&(l[t=n]||!s&&-1===a.indexOf(t)&&-1===c.indexOf(t)?r[0][n]=o[n]:r[1][n]=!0),r},[{},{}])}var a=e.privateAttributeNames||[],t=n(e,function(e){return f[e]}),r=t[0],o=t[1];if(e.custom){var i=n(e.custom,function(){return!0});r.custom=i[0],o=A({},o,i[1])}var u=Object.keys(o);return u.length&&(u.sort(),r.privateAttrs=u),r},n}function Y(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var Z=function(){return"LaunchDarkly client initialized"},ee=" Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initializing-the-client for instructions on SDK initialization.",ne=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},te=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"},re=function(e){return'Expected application/json content type but got "'+e+'"'},ie=function(){return"localStorage is unavailable"},oe=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},ae=function(e){return"network error"+(e?" ("+e+")":"")},ue=function(e){return'Custom event "'+e+'" does not exist'},se=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+ee},ce=function(){return"No environment/client-side ID was specified."+ee},le=function(e){return"Error fetching flag settings: "+Y(e)},fe=function(){return"No user specified."+ee},ve=function(){return"Invalid user specified."+ee},de=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+ee},ge=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},me=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},pe=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(f(e)?t:"giving up permanently")},ye=function(){return"Cannot make HTTP requests in this environment."+ee},he=function(){return"identify() has no effect here; it must be called on the main client instance"},be=function(){return"Closing stream connection"},ke=function(e){return"Opening stream connection to "+e},Ee=function(e,n){return"Error on stream connection: "+Y(e)+", will continue retrying every "+n+" milliseconds."},we=function(e){return'Ignoring unknown config option "'+e+'"'},De=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},Se=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},Oe=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},Pe=function(e){return"polling for feature flags at "+e},Ue=function(){return"received ping message from stream"},Ie=function(){return"received streaming update for all flags"},je=function(e){return'received streaming update for flag "'+e+'"'},Re=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},Te=function(e){return'received streaming deletion for flag "'+e+'"'},Ne=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},Fe=function(e){return'enqueueing "'+e+'" event'},Ce=function(e){return"sending "+e+" events"},Le=Object.freeze({__proto__:null,clientInitialized:Z,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:ne,eventWithoutUser:te,invalidContentType:re,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:ie,localStorageUnavailableForUserId:oe,networkError:ae,unknownCustomEventKey:ue,environmentNotFound:se,environmentNotSpecified:ce,errorFetchingFlags:le,userNotSpecified:fe,invalidUser:ve,bootstrapOldFormat:de,bootstrapInvalid:ge,deprecated:me,httpErrorMessage:pe,httpUnavailable:ye,identifyDisabled:he,streamClosing:be,streamConnecting:ke,streamError:Ee,unknownOption:we,wrongOptionType:De,wrongOptionTypeBoolean:Se,optionBelowMinimum:Oe,debugPolling:Pe,debugStreamPing:Ue,debugStreamPut:Ie,debugStreamPatch:je,debugStreamPatchIgnored:Re,debugStreamDelete:Te,debugStreamDeleteIgnored:Ne,debugEnqueueingEvent:Fe,debugPostingEvents:Ce,debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"}});function Ae(n){var e={},o={};return e.on=function(e,n,t){o[e]=o[e]||[],o[e]=o[e].concat({handler:n,context:t})},e.off=function(e,n,t){if(o[e])for(var r=0;r<o[e].length;r++)o[e][r].handler===n&&o[e][r].context===t&&(o[e]=o[e].slice(0,r).concat(o[e].slice(r+1)))},e.emit=function(e){if(o[e])for(var n=o[e].slice(0),t=0;t<n.length;t++)n[t].handler.apply(n[t].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(o)},e.getEventListenerCount=function(e){return o[e]?o[e].length:0},e.maybeReportError=function(e){e&&(o.error?this.emit("error",e):(n||console).error(e.message))},e}var xe=function(r){var n=!1,t=!1,o=null,e=null,i=new Promise(function(n){r.on("ready",function e(){r.off("ready",e),n()})}).catch(function(){});return{getInitializationPromise:function(){return e||(n?Promise.resolve():t?Promise.reject(o):e=new Promise(function(n,t){r.on("initialized",function e(){r.off("initialized",e),n()}),r.on("failed",function e(n){r.off("failed",e),t(n)})}))},getReadyPromise:function(){return i},signalSuccess:function(){n||t||(n=!0,r.emit("initialized"),r.emit("ready"))},signalFailure:function(e){n||t||(t=!0,o=e,r.emit("failed",e),r.emit("ready")),r.maybeReportError(e)}}};function qe(t,r,o,i,a){var u={};function s(){var e="",n=i.getUser();return n&&(e=o||S(JSON.stringify(n))),"ld:"+r+":"+e}return u.loadFlags=function(){return t.get(s()).then(function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var t=n.$schema;void 0===t||t<1?n=R(n):delete n.$schema}return n}catch(e){return u.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return a.warn("localStorage is unavailable"),Promise.reject(e)})},u.saveFlags=function(e){var n=A({},e,{$schema:1});return t.set(s(),JSON.stringify(n)).catch(function(e){return a.warn("localStorage is unavailable"),Promise.reject(e)})},u.clearFlags=function(){return t.clear(s()).catch(function(e){return a.warn("localStorage is unavailable"),Promise.reject(e)})},u}function Ve(o,i,a,n){var u,s=i.streamUrl,c=i.logger,e={},l=s+"/eval/"+a,f=i.useReport,d=i.evaluationReasons,t=i.streamReconnectDelay,v=C(o,i),g=!1,p=null,m=null,h=null,y=null,w=null;function b(e){g||(c.warn(Ee(e,t)),g=!0),S(!1),E(),k(t)}function k(e){m||(e?m=setTimeout(r,e):r())}function r(){var e;m=null;var n="",t={headers:v,readTimeoutMillis:3e5};if(o.eventSourceFactory){for(var r in null!=y&&(n="h="+y),f?o.eventSourceAllowsReport?(e=l,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(h)):(e=s+"/ping/"+a,n=""):e=l+"/"+O(JSON.stringify(h)),t.headers=L(t.headers,i),d&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,E(),c.info(ke(e)),u=(new Date).getTime(),p=o.eventSourceFactory(e,t),w)x(w,r)&&p.addEventListener(r,w[r]);p.onerror=b}}function E(){p&&(c.info("Closing stream connection"),p.close(),p=null)}function S(e){u&&n&&n.recordStreamInit(u,!e,(new Date).getTime()-u),u=null}return e.connect=function(e,n,t){h=e,y=n,w={};function r(n){w[n]=function(e){S(!(g=!1)),t[n]&&t[n](e)}}for(var o in t||{})r(o);k()},e.disconnect=function(){clearTimeout(m),m=null,E()},e.isConnected=function(){return!!(p&&o.eventSourceIsActive&&o.eventSourceIsActive(p))},e}function _e(p,m,u){var s=m.baseUrl,c=m.useReport,f=m.evaluationReasons,d=m.logger,e={},h={};function v(e,n){if(!p.httpRequest)return new Promise(function(e,n){n(new l(ye()))});var t=n?"REPORT":"GET",r=C(p,m);n&&(r["Content-Type"]="application/json");var o,i,u,s,c,f,d=h[e];d||(o=function(){delete h[e]},(f={addPromise:function(n,e){i=n,u&&u(),u=e,n.then(function(e){i===n&&(s(e),o())},function(e){i===n&&(c(e),o())})}}).resultPromise=new Promise(function(e,n){s=e,c=n}),d=f,h[e]=d);var v=p.httpRequest(t,e,L(r,m),n),g=v.promise.then(function(e){if(200!==e.status)return Promise.reject(404===(n=e).status?new a(se()):new l(le(n.statusText||String(n.status))));if(e.header("content-type")&&"application/json"===e.header("content-type").substring(0,"application/json".length))return JSON.parse(e.body);var n,t=re(e.header("content-type")||"");return Promise.reject(new l(t))},function(e){return Promise.reject(new l(ae(e)))});return d.addPromise(g,function(){v.cancel&&v.cancel()}),d.resultPromise}return e.fetchJSON=function(e){return v(s+e,null)},e.fetchFlagSettings=function(e,n){var t,r,o,i="";return c?(r=[s,"/sdk/evalx/",u,"/user"].join(""),o=JSON.stringify(e)):(t=O(JSON.stringify(e)),r=[s,"/sdk/evalx/",u,"/users/",t].join("")),n&&(i="h="+n),f&&(i=i+(i?"&":"")+"withReasons=true"),r=r+(i?"?":"")+i,d.debug(Pe(r)),v(r,o)},e}function Je(o,i){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new u(fe()));var r=P(e);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(o?o.get("ld:$anonUserId").catch(function(){return null}):Promise.resolve(null)).then(function(e){if(e)return r.key=e,r;var n,t=G();return r.key=t,(n=t,o?o.set("ld:$anonUserId",n).catch(function(){i.warn("localStorage is unavailable, so anonymous user ID cannot be cached")}):Promise.resolve()).then(function(){return r})}):Promise.reject(new u(ve()))},e}var ze={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},streaming:{type:"boolean"},sendLDHeaders:{default:!0},requestHeaderTransform:{type:"function"},inlineUsersInEvents:{default:!1},allowFrequentDuplicateEvents:{default:!1},sendEventsOnlyForVariation:{default:!1},useReport:{default:!1},evaluationReasons:{default:!1},eventCapacity:{default:100,minimum:1},flushInterval:{default:2e3,minimum:2e3},samplingInterval:{default:0,minimum:0},streamReconnectDelay:{default:1e3,minimum:0},allAttributesPrivate:{default:!1},privateAttributeNames:{default:[]},bootstrap:{type:"string|object"},diagnosticRecordingInterval:{default:9e5,minimum:2e3},diagnosticOptOut:{default:!1},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"},autoAliasingOptOut:{default:!1}};function Me(n,t,r,o){var a=A({logger:{default:o}},ze,r),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){I(function(){t&&t.maybeReportError(new c(e))})}var s,l,f,d,v=A({},n||{});return d=v,Object.keys(i).forEach(function(e){if(void 0!==d[e]){var n=i[e];o&&o.warn(me(e,n)),n&&(void 0===d[n]&&(d[n]=d[e]),delete d[e])}}),f=A({},v),Object.keys(a).forEach(function(e){void 0!==f[e]&&null!==f[e]||(f[e]=a[e]&&a[e].default)}),s=v=f,l=A({},s),Object.keys(s).forEach(function(e){var n=s[e];if(null!=n){var t=a[e];if(void 0===t)u(we(e));else{var r=t.type||g(t.default);if("any"!==r){var o=r.split("|"),i=g(n);o.indexOf(i)<0?"boolean"===r?(l[e]=!!n,u(Se(e,i))):(u(De(e,r,i)),l[e]=t.default):"number"===i&&void 0!==t.minimum&&n<t.minimum&&(u(Oe(e,n,t.minimum)),l[e]=t.minimum)}}}}),l;function g(n){if(null===n)return"any";if(void 0!==n){if(Array.isArray(n))return"array";var t=e(n);return"boolean"===t||"string"===t||"number"===t||"function"===t?t:"object"}}}var Ke=Object.freeze({__proto__:null,baseOptionDefs:ze,validate:Me}).baseOptionDefs,He=function(e){var n={diagnosticId:G()};return e&&(n.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),n},Be=function(e){var n,t,r,o;function i(e){n=e,r=t=0,o=[]}return i(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:o}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,o=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};o.push(r)},reset:i}},$e=function(o,e,n,t,i,a){var u,s,c=!!o.diagnosticUseCombinedEvent,l="ld:"+t+":$diagnostics",f=i.eventsUrl+"/events/diagnostic/"+t,d=i.diagnosticRecordingInterval,v=e,g=!!i.streaming,p={};function m(){return{sdk:function(){var e=r({},o.diagnosticSdkData);return i.wrapperName&&(e.wrapperName=i.wrapperName),i.wrapperVersion&&(e.wrapperVersion=i.wrapperVersion),e}(),configuration:(e={customBaseURI:i.baseUrl!==Ke.baseUrl.default,customStreamURI:i.streamUrl!==Ke.streamUrl.default,customEventsURI:i.eventsUrl!==Ke.eventsUrl.default,eventsCapacity:i.eventCapacity,eventsFlushIntervalMillis:i.flushInterval,reconnectTimeMillis:i.streamReconnectDelay,streamingDisabled:!g,allAttributesPrivate:!!i.allAttributesPrivate,inlineUsersInEvents:!!i.inlineUsersInEvents,diagnosticRecordingIntervalMillis:i.diagnosticRecordingInterval,usingSecureMode:!!i.hash,bootstrapMode:!!i.bootstrap,fetchGoalsDisabled:!i.fetchGoals,allowFrequentDuplicateEvents:!!i.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!i.sendEventsOnlyForVariation,autoAliasingOptOut:!!i.autoAliasingOptOut},e),platform:o.diagnosticPlatformData};var e}function h(e){i.logger&&i.logger.debug(Le.debugPostingDiagnosticEvent(e)),n.sendEvents(e,f,!0).then(function(){}).catch(function(){})}function y(){var e,n;h((e=(new Date).getTime(),n=r({kind:c?"diagnostic-combined":"diagnostic",id:a,creationDate:e},v.getProps()),c&&(n=r({},n,{},m())),v.reset(e),n)),s=setTimeout(y,d),u=(new Date).getTime(),c&&function(){if(o.localStorage){var e=r({},v.getProps());o.localStorage.set(l,JSON.stringify(e),function(){})}}()}return p.start=function(){c?function(t){if(!o.localStorage)return t(!1);o.localStorage.get(l).then(function(e){if(e)try{var n=JSON.parse(e);v.setProps(n),u=n.dataSinceDate}catch(e){}t(!0)}).catch(function(){t(!1)})}(function(e){if(e){var n=(u||0)+d,t=(new Date).getTime();n<=t?y():s=setTimeout(y,n-t)}else 0===Math.floor(4*Math.random())?y():s=setTimeout(y,d)}):(h(r({kind:"diagnostic-init",id:a,creationDate:v.getProps().dataSinceDate},m())),s=setTimeout(y,d))},p.stop=function(){s&&clearTimeout(s)},p.setStreaming=function(e){g=e},p};function Ge(e,n){var i,a=["debug","info","warn","error"];i=null!=n?""===n?"":n+" ":"LD: ";var u=0;e&&(u="none"===e?100:a.indexOf(e));var t={};function r(e,n,t){if(u<=e&&console){var r=console[n];if(r){var o=e<a.length?a[e]:"?";r.call(console,i+"["+o+"] "+t)}}}return t.debug=function(e){return r(0,"log",e)},t.info=function(e){return r(1,"info",e)},t.warn=function(e){return r(2,"warn",e)},t.error=function(e){return r(3,"error",e)},t}function Xe(n,t,i,u,c){var d,v,g,p,m,h,y=i&&i.logger?i.logger:c&&c.logger&&c.logger.default||Ge("warn"),w=Ae(y),b=xe(w),k=Me(i,w,c,y),E=k.sendEvents,S=n,O=k.hash,D=X(u,S,k),R=k.sendEvents&&!k.diagnosticOptOut,L=R?He(S):null,N=R?Be((new Date).getTime()):null,C=R?$e(u,N,D,S,k,L):null,F=Ve(u,k,S,N),_=k.eventProcessor||function(e,n,t,r,i,a){var u,s=3<arguments.length&&void 0!==r?r:null,c=4<arguments.length&&void 0!==i?i:null,l={},d=(5<arguments.length&&void 0!==a?a:null)||X(e,t,n),v=n.eventsUrl+"/events/bulk/"+t,g=W(),p=Q(n),m=n.inlineUsersInEvents,h=n.samplingInterval,y=n.eventCapacity,w=n.flushInterval,b=n.logger,k=[],E=0,S=!1,O=!1;function P(){return 0===h||0===Math.floor(Math.random()*h)}function D(e){k.length<y?(k.push(e),O=!1):(O||(O=!0,b.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")),s&&s.incrementDroppedEvents())}return l.enqueue=function(e){if(!S){var n=!1,t=!1;if(g.summarizeEvent(e),"feature"===e.kind?P()&&(n=!!e.trackEvents,t=function(e){return!!e.debugEventsUntilDate&&e.debugEventsUntilDate>E&&e.debugEventsUntilDate>(new Date).getTime()}(e)):n=P(),n&&D(function(e){var n=A({},e);return"alias"===e.kind||(m||"identify"===e.kind?n.user=p.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate)),n}(e)),t){var r=A({},e,{kind:"debug"});r.user=p.filterUser(r.user),delete r.trackEvents,delete r.debugEventsUntilDate,D(r)}}},l.flush=function(){if(S)return Promise.resolve();var e=k,n=g.getSummary();return g.clearSummary(),n&&(n.kind="summary",e.push(n)),s&&s.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(k=[],b.debug(Ce(e.length)),d.sendEvents(e,v).then(function(e){e&&(e.serverTime&&(E=e.serverTime),f(e.status)||(S=!0),400<=e.status&&I(function(){c.maybeReportError(new o(pe(e.status,"event posting","some events were dropped")))}))}))},l.start=function(){u=setTimeout(function e(){l.flush(),u=setTimeout(e,w)},w)},l.stop=function(){clearTimeout(u)},l}(u,k,S,N,w,D),z=_e(u,k,S),M={},J={},V=k.streaming,K=!1,G=!1,H=!0,$=k.stateProvider,B=(m=function(e,n){var t;t=e,$||t&&Z({kind:"identify",key:t.key,user:t,creationDate:(new Date).getTime()}),!k.autoAliasingOptOut&&n&&n.anonymous&&e&&!e.anonymous&&oe(e,n)},{setUser:function(e){var n=h&&P(h);(h=q(e))&&m&&m(P(h),n)},getUser:function(){return h?P(h):null}}),Y=Je(u.localStorage,y);function Z(e){if(S&&!($&&$.enqueueEvent&&$.enqueueEvent(e))){if("alias"!==e.kind){if(!e.user)return void(H&&(y.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"),H=!1));H=!1}!E||G||u.isDoNotTrack()||(y.debug(Fe(e.kind)),_.enqueue(e))}}function ee(e,n,t,r){var o=B.getUser(),i=new Date,a=n?n.value:null;if(!k.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(o&&o.key?o.key:"")+e,s=M[u];if(s&&i-s<3e5)return;M[u]=i}var c={kind:"feature",key:e,user:o,value:a,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()};o&&o.anonymous&&(c.contextKind=re(o));var l=J[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),Z(c)}function ne(e,n,t,r){var o;if(J&&x(J,e)&&J[e]&&!J[e].deleted){var i=J[e];o=te(i),null!==i.value&&void 0!==i.value||(o.value=n)}else o={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&ee(e,o,n,r),o}function te(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function re(e){return e.anonymous?"anonymousUser":"user"}function oe(e,n){$||e&&n&&Z({kind:"alias",key:e.key,contextKind:re(e),previousKey:n.key,previousContextKind:re(n),creationDate:(new Date).getTime()})}function ie(){v=!0,B.getUser()&&F.connect(B.getUser(),O,{ping:function(){y.debug("received ping message from stream");var n=B.getUser();z.fetchFlagSettings(n,O).then(function(e){U(n,B.getUser())&&se(e||{})}).catch(function(e){w.maybeReportError(new l(le(e)))})},put:function(e){var n=JSON.parse(e.data);y.debug("received streaming update for all flags"),se(n)},patch:function(e){var n=JSON.parse(e.data),t=J[n.key];if(!t||!t.version||!n.version||t.version<n.version){y.debug(je(n.key));var r={},o=A({},n);delete o.key;var i=te(J[n.key]=o);r[n.key]=t?{previous:t.value,current:i}:{current:i},fe(r)}else y.debug(Re(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!J[n.key]||J[n.key].version<n.version){y.debug(Te(n.key));var t={};J[n.key]&&!J[n.key].deleted&&(t[n.key]={previous:J[n.key].value}),J[n.key]={version:n.version,deleted:!0},fe(t)}else y.debug(Ne(n.key))}})}function ae(){v&&(F.disconnect(),v=!1)}function se(e){var n={};if(!e)return Promise.resolve();for(var t in J)x(J,t)&&J[t]&&(e[t]&&!U(e[t].value,J[t].value)?n[t]={previous:J[t].value,current:te(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:J[t].value}));for(var o in e)x(e,o)&&e[o]&&(!J[o]||J[o].deleted)&&(n[o]={current:te(e[o])});return J=r({},e),fe(n).catch(function(){})}function fe(o){var e=Object.keys(o);if(0<e.length){var i={};e.forEach(function(e){var n=o[e].current,t=n?n.value:void 0,r=o[e].previous;w.emit("change:"+e,t,r),i[e]=n?{current:t,previous:r}:{previous:r}}),w.emit("change",i),w.emit("internal-change",J),k.sendEventsOnlyForVariation||$||e.forEach(function(e){ee(e,o[e].current)})}return d&&p?p.saveFlags(J).catch(function(){return null}):Promise.resolve()}function ve(){var e=V||g&&void 0===V;e&&!v?ie():!e&&v&&ae(),C&&C.setStreaming(e)}function ge(e){return"change"===e||"change:"===e.substr(0,"change".length+1)}if(u.localStorage&&(p=new qe(u.localStorage,S,O,B,y)),"string"==typeof k.bootstrap&&"LOCALSTORAGE"===k.bootstrap.toUpperCase()&&(p?d=!0:y.warn("localStorage is unavailable")),"object"===e(k.bootstrap)&&(J=function(t){var e=Object.keys(t),r=t.$flagsState;!r&&e.length&&y.warn(de()),!1===t.$valid&&y.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var o={};return e.forEach(function(e){if("$flagsState"!==e&&"$valid"!==e){var n={value:t[e]};r&&r[e]?n=A(n,r[e]):n.version=0,o[e]=n}}),o}(k.bootstrap)),$){var me=$.getInitialState();me?he(me):$.on("init",he),$.on("update",function(e){e.user&&B.setUser(e.user),e.flags&&se(e.flags)})}else(n?Y.validateUser(t).then(function(n){return B.setUser(n),"object"===e(k.bootstrap)?ye():d?p.loadFlags().catch(function(){return null}).then(function(e){return null==e?(J={},z.fetchFlagSettings(B.getUser(),O).then(function(e){return se(e||{})}).then(ye).catch(function(e){we(new l(le(e)))})):(J=e,I(ye),z.fetchFlagSettings(B.getUser(),O).then(function(e){return se(e)}).catch(function(e){return w.maybeReportError(e)}))}):z.fetchFlagSettings(B.getUser(),O).then(function(e){J=e||{},ye()}).catch(function(e){J={},we(e)})}):Promise.reject(new a(ce()))).catch(we);function he(e){S=e.environment,B.setUser(e.user),J=r({},e.flags),I(ye)}function ye(){y.info("LaunchDarkly client initialized"),K=!0,ve(),b.signalSuccess()}function we(e){b.signalFailure(e)}return{client:{waitForInitialization:function(){return b.getInitializationPromise()},waitUntilReady:function(){return b.getReadyPromise()},identify:function(e,r,n){return G?j(Promise.resolve({}),n):$?(y.warn("identify() has no effect here; it must be called on the main client instance"),j(Promise.resolve(T(J)),n)):j((d&&p?p.clearFlags():Promise.resolve()).then(function(){return Y.validateUser(e)}).then(function(t){return z.fetchFlagSettings(t,r).then(function(e){var n=T(e);return B.setUser(t),O=r,e?se(e).then(function(){return n}):n})}).then(function(e){return v&&ie(),e}).catch(function(e){return w.maybeReportError(e),Promise.reject(e)}),n)},getUser:function(){return B.getUser()},variation:function(e,n){return ne(e,n,!0,!1).value},variationDetail:function(e,n){return ne(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){u.customEventFilter&&!u.customEventFilter(e)&&y.warn(ue(e));var r=B.getUser(),o={kind:"custom",key:e,user:r,url:u.getCurrentUrl(),creationDate:(new Date).getTime()};r&&r.anonymous&&(o.contextKind=re(r)),null!=n&&(o.data=n),null!=t&&(o.metricValue=t),Z(o)}else w.maybeReportError(new s(ue(e)))},alias:oe,on:function(e,n,t){ge(e)?(g=!0,K&&ve(),w.on(e,n,t)):w.on.apply(w,arguments)},off:function(e){if(w.off.apply(w,arguments),ge(e)){var n=!1;w.getEvents().forEach(function(e){ge(e)&&0<w.getEventListenerCount(e)&&(n=!0)}),n||(g=!1,v&&void 0===V&&ae())}},setStreaming:function(e){var n=null===e?void 0:e;n!==V&&(V=n,ve())},flush:function(e){return j(E?_.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!J)return e;for(var n in J)x(J,n)&&(e[n]=ne(n,null,!k.sendEventsOnlyForVariation).value);return e},close:function(e){if(G)return j(Promise.resolve(),e);function n(){G=!0,J={}}return j(Promise.resolve().then(function(){if(ae(),C&&C.stop(),E)return _.stop(),_.flush()}).then(n).catch(n),e)}},options:k,emitter:w,ident:B,logger:y,requestor:z,start:function(){E&&(C&&C.start(),_.start())},enqueueEvent:Z,getFlagsInternal:function(){return J},getEnvironmentId:function(){return S},internalChangeEventName:"internal-change"}}function _defineProperty(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function ownKeys(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),t.push.apply(t,r)}return t}function _objectSpread2(n){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(t),!0).forEach(function(e){_defineProperty(n,e,t[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(t,e))})}return n}function isSyncXhrSupported(){var e=window.navigator&&window.navigator.userAgent;if(e){var n=e.match(/Chrom(e|ium)\/([0-9]+)\./);if(n)return parseInt(n[2],10)<73}return!0}var emptyResult={promise:Promise.resolve({status:200,header:function(){return null},body:null})};function newHttpRequest(e,n,t,r,o){if(o&&!isSyncXhrSupported())return emptyResult;var i=new window.XMLHttpRequest;for(var a in i.open(e,n,!o),t||{})Object.prototype.hasOwnProperty.call(t,a)&&i.setRequestHeader(a,t[a]);if(o)return i.send(r),emptyResult;var u;return{promise:new Promise(function(e,n){i.addEventListener("load",function(){u||e({status:i.status,header:function(e){return i.getResponseHeader(e)},body:i.responseText})}),i.addEventListener("error",function(){u||n(new Error)}),i.send(r)}),cancel:function(){u=!0,i.abort()}}}function makeBrowserPlatform(e){var n,i={synchronousFlush:!1};if(window.XMLHttpRequest){var a=e&&e.disableSyncEventPost;i.httpRequest=function(e,n,t,r){var o=i.synchronousFlush&!a;return i.synchronousFlush=!1,newHttpRequest(e,n,t,r,o)}}i.httpAllowsPost=function(){return void 0===n&&(n=!!window.XMLHttpRequest&&"withCredentials"in new window.XMLHttpRequest),n},i.httpFallbackPing=function(e){(new window.Image).src=e};var r,t=e&&e.eventUrlTransformer;i.getCurrentUrl=function(){return t?t(window.location.href):window.location.href},i.isDoNotTrack=function(){var e;return 1===(e=window.navigator&&void 0!==window.navigator.doNotTrack?window.navigator.doNotTrack:window.navigator&&void 0!==window.navigator.msDoNotTrack?window.navigator.msDoNotTrack:window.doNotTrack)||!0===e||"1"===e||"yes"===e};try{window.localStorage&&(i.localStorage={get:function(n){return new Promise(function(e){e(window.localStorage.getItem(n))})},set:function(n,t){return new Promise(function(e){window.localStorage.setItem(n,t),e()})},clear:function(n){return new Promise(function(e){window.localStorage.removeItem(n),e()})}})}catch(e){i.localStorage=null}var o=e&&e.useReport;if(r=o&&"function"==typeof window.EventSourcePolyfill&&window.EventSourcePolyfill.supportedOptions&&window.EventSourcePolyfill.supportedOptions.method?(i.eventSourceAllowsReport=!0,window.EventSourcePolyfill):(i.eventSourceAllowsReport=!1,window.EventSource),window.EventSource){i.eventSourceFactory=function(e,n){var t=_objectSpread2(_objectSpread2({},{heartbeatTimeout:3e5,silentTimeout:3e5,skipDefaultHeaders:!0}),n);return new r(e,t)},i.eventSourceIsActive=function(e){return e.readyState===window.EventSource.OPEN||e.readyState===window.EventSource.CONNECTING}}return i.userAgent="JSClient",i.version="2.20.0",i.diagnosticSdkData={name:"js-client-sdk",version:"2.20.0"},i.diagnosticPlatformData={name:"JS"},i.diagnosticUseCombinedEvent=!0,i}var matchOperatorsRe=/[|\\{}()[\]^$+*?.]/g,escapeStringRegexp=function(e){if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(matchOperatorsRe,"\\$&")};function doesUrlMatch(e,n,t,r){var o,i,a=(("substring"===e.kind||"regex"===e.kind)&&r.includes("/")?n:n.replace(r,"")).replace(t,"");switch(e.kind){case"exact":i=n,o=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"canonical":i=a,o=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"substring":i=a,o=new RegExp(".*"+escapeStringRegexp(e.substring)+".*$");break;case"regex":i=a,o=new RegExp(e.pattern);break;default:return!1}return o.test(i)}function findGoalsForClick(e,n){for(var t=[],r=0;r<n.length;r++)for(var o=e.target,i=n[r],a=i.selector,u=document.querySelectorAll(a);o&&0<u.length;){for(var s=0;s<u.length;s++)o===u[s]&&t.push(i);o=o.parentNode}return t}function GoalTracker(e,r){for(var n={},t=null,o=[],i=0;i<e.length;i++)for(var a=e[i],u=a.urls||[],s=0;s<u.length;s++)if(doesUrlMatch(u[s],window.location.href,window.location.search,window.location.hash)){"pageview"===a.kind?r("pageview",a):(o.push(a),r("click_pageview",a));break}return 0<o.length&&(t=function(e){for(var n=findGoalsForClick(e,o),t=0;t<n.length;t++)r("click",n[t])},document.addEventListener("click",t)),n.dispose=function(){document.removeEventListener("click",t)},n}var locationWatcherInterval=300;function GoalManager(o,n){var t,r;function i(){r&&r.dispose(),t&&t.length&&(r=GoalTracker(t,a))}function a(e,n){var t=o.ident.getUser(),r={kind:e,key:n.key,data:null,url:window.location.href,user:t,creationDate:(new Date).getTime()};return t&&t.anonymous&&(r.contextKind="anonymousUser"),"click"===e&&(r.selector=n.selector),o.enqueueEvent(r)}function u(e,n){var t,r=window.location.href;function o(){(t=window.location.href)!==r&&(r=t,n())}!function e(n,t){n(),setTimeout(function(){e(n,t)},t)}(o,e),window.history&&window.history.pushState?window.addEventListener("popstate",o):window.addEventListener("hashchange",o)}return o.requestor.fetchJSON("/sdk/goals/"+o.getEnvironmentId()).then(function(e){e&&0<e.length&&(r=GoalTracker(t=e,a),u(locationWatcherInterval,i)),n()}).catch(function(e){o.emitter.maybeReportError(new v.LDUnexpectedResponseError((e&&e.message,e.message))),n()}),{}}var goalsEvent="goalsReady",extraOptionDefs={fetchGoals:{default:!0},hash:{type:"string"},eventProcessor:{type:"object"},eventUrlTransformer:{type:"function"},disableSyncEventPost:{default:!1}};function initialize(e,n){var t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},r=makeBrowserPlatform(t),o=Xe(e,n,t,r,extraOptionDefs),i=o.client,a=o.options,u=o.emitter,s=new Promise(function(e){var n=u.on(goalsEvent,function(){u.off(goalsEvent,n),e()})});i.waitUntilGoalsReady=function(){return s},a.fetchGoals?GoalManager(o,function(){return u.emit(goalsEvent)}):u.emit(goalsEvent),"complete"!==document.readyState?window.addEventListener("load",o.start):o.start();function c(){r.synchronousFlush=!0,i.flush().catch(function(){}),r.synchronousFlush=!1}return window.addEventListener("beforeunload",c),window.addEventListener("unload",c),i}var createConsoleLogger=Ge,version="2.20.0";function deprecatedInitialize(e,n){var t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return console&&console.warn&&console.warn(Le.deprecated("default export","named LDClient export")),initialize(e,n,t)}var index={initialize:deprecatedInitialize,version:version};exports.createConsoleLogger=createConsoleLogger,exports.default=index,exports.initialize=initialize,exports.version=version;
1
+ "use strict";function e(n){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(n)}function n(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function t(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),t.push.apply(t,r)}return t}function r(r){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?t(o,!0).forEach(function(e){n(r,e,o[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):t(o).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))})}return r}function i(e){return function(e){if(Array.isArray(e)){for(var n=0,t=new Array(e.length);n<e.length;n++)t[n]=e[n];return t}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function o(e){function n(e,n){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=n}return(n.prototype=new Error).name=e,n.prototype.constructor=n}Object.defineProperty(exports,"__esModule",{value:!0});var a=o("LaunchDarklyUnexpectedResponseError"),u=o("LaunchDarklyInvalidEnvironmentIdError"),s=o("LaunchDarklyInvalidUserError"),c=o("LaunchDarklyInvalidEventKeyError"),l=o("LaunchDarklyInvalidArgumentError"),f=o("LaunchDarklyFlagFetchError"),v=o("LaunchDarklyInvalidDataError");function d(e){return!(400<=e&&e<500)||400===e||408===e||429===e}for(var g=Object.freeze({__proto__:null,LDUnexpectedResponseError:a,LDInvalidEnvironmentIdError:u,LDInvalidUserError:s,LDInvalidEventKeyError:c,LDInvalidArgumentError:l,LDFlagFetchError:f,LDInvalidDataError:v,isHttpErrorRecoverable:d}),p=function(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(E(e,i,a<i+16383?a:i+16383));return 1==r?(n=e[t-1],o.push(m[n>>2]+m[n<<4&63]+"==")):2==r&&(n=(e[t-2]<<8)+e[t-1],o.push(m[n>>10]+m[n>>4&63]+m[n<<2&63]+"=")),o.join("")},m=[],y=[],h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",b=0,k=h.length;b<k;++b)m[b]=h[b],y[h.charCodeAt(b)]=b;function E(e,n,t){for(var r,o,i=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),i.push(m[(o=r)>>18&63]+m[o>>12&63]+m[o>>6&63]+m[63&o]);return i.join("")}y["-".charCodeAt(0)]=62,y["_".charCodeAt(0)]=63;var w=Array.isArray,D=Object.keys,O=Object.prototype.hasOwnProperty,P=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function S(e){var n=unescape(encodeURIComponent(e));return p(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function U(e){return S(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function I(e){return JSON.parse(JSON.stringify(e))}function j(e,n){return function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,o,i,a=w(n),u=w(t);if(a&&u){if((o=n.length)!=t.length)return!1;for(r=o;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var s=n instanceof Date,c=t instanceof Date;if(s!=c)return!1;if(s&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var d=D(n);if((o=d.length)!==D(t).length)return!1;for(r=o;0!=r--;)if(!O.call(t,d[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=d[r]],t[i]))return!1;return!0}return n!=n&&t!=t}(e,n)}function R(e){setTimeout(e,0)}function T(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function L(e){var n={};for(var t in e)V(e,t)&&(n[t]={value:e[t],version:0});return n}function F(e){var n={};for(var t in e)V(e,t)&&(n[t]=e[t].value);return n}function N(e,n){for(var t,r=n.slice(0),o=[],i=e;0<r.length;){for(t=[];0<i;){var a=r.shift();if(!a)break;(i-=U(JSON.stringify(a)).length)<0&&0<t.length?r.unshift(a):t.push(a)}i=e,o.push(t)}return o}function A(e){var n=e.version||"3.5.1";return e.userAgent+"/"+n}function C(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":A(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function x(e,n){return n&&n.requestHeaderTransform?n.requestHeaderTransform(r({},e)):e}function q(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return r({},e,{},n)},{})}function V(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function _(e){if(!e)return e;var n;for(var t in P){var o=P[t],i=e[o];void 0!==i&&"string"!=typeof i&&((n=n||r({},e))[o]=String(i))}return n||e}for(var z=Object.freeze({__proto__:null,btoa:S,base64URLEncode:U,clone:I,deepEquals:j,onNextTick:R,wrapPromiseCallback:T,transformValuesToVersionedValues:L,transformVersionedValuesToValues:F,chunkUserEventsForUrl:N,getLDUserAgentString:A,getLDHeaders:C,transformHeaders:x,extend:q,objectHasOwnProperty:V,sanitizeUser:_}),J=function(e,n){return function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}(n={exports:{}}),n.exports}(),M=[],K=0;K<256;++K)M[K]=(K+256).toString(16).substr(1);var H,B,$=function(e,n){var t=n||0,r=M;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")},G=0,X=0,W=function(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||H,a=void 0!==e.clockseq?e.clockseq:B;if(null==i||null==a){var u=J();null==i&&(i=H=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=B=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:X+1,l=s-G+(c-X)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||G<s)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");G=s,B=a;var f=(1e4*(268435455&(s+=122192928e5))+(X=c))%4294967296;o[r++]=f>>>24&255,o[r++]=f>>>16&255,o[r++]=f>>>8&255,o[r++]=255&f;var d=s/4294967296*1e4&268435455;o[r++]=d>>>8&255,o[r++]=255&d,o[r++]=d>>>24&15|16,o[r++]=d>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var v=0;v<6;++v)o[r+v]=i[v];return n||$(o)};function Q(u,e,s){var t="/a/"+e+".gif",c=q({"Content-Type":"application/json"},C(u,s)),l=u.httpFallbackPing,f={sendChunk:function(e,r,o,n){var i=JSON.stringify(e),a=o?null:W();return n?function n(t){var e=o?c:q({},c,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":a});return u.httpRequest("POST",r,x(e,s),i).promise.then(function(e){if(e)return 400<=e.status&&d(e.status)&&t?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)}).catch(function(){return t?n(!1):Promise.reject()})}(!0).catch(function(){}):(l&&l(r+t+"?d="+U(i)),Promise.resolve())},sendEvents:function(e,n,t){if(!u.httpRequest)return Promise.resolve();var r,o=u.httpAllowsPost();r=o?[e]:N(2e3-n.length,e);for(var i=[],a=0;a<r.length;a++)i.push(f.sendChunk(r[a],n,t,o));return Promise.all(i)}};return f}function Y(){var e={},a=0,u=0,s={};return e.summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=s[n];t?t.count=t.count+1:s[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>u&&(u=e.creationDate)}},e.getSummary=function(){var e={},n=!0;for(var t in s){var r=s[t],o=e[r.key];o||(o={default:r.default,counters:[]},e[r.key]=o);var i={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),n=!1}return n?null:{startDate:a,endDate:u,features:e}},e.clearSummary=function(){u=a=0,s={}},e}function Z(e){var n={},s=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},f={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;function n(o,i){return Object.keys(o).reduce(function(e,n){var t,r=e;return i(n)&&(l[t=n]||!s&&-1===a.indexOf(t)&&-1===c.indexOf(t)?r[0][n]=o[n]:r[1][n]=!0),r},[{},{}])}var a=e.privateAttributeNames||[],t=n(e,function(e){return f[e]}),r=t[0],o=t[1];if(e.custom){var i=n(e.custom,function(){return!0});r.custom=i[0],o=q({},o,i[1])}var u=Object.keys(o);return u.length&&(u.sort(),r.privateAttrs=u),r},n}function ee(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var ne=function(){return"LaunchDarkly client initialized"},te=" Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initializing-the-client for instructions on SDK initialization.",re=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},ie=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"},oe=function(e){return'Expected application/json content type but got "'+e+'"'},ae=function(e){return"local storage is unavailable: "+ee(e)},ue=function(e){return"network error"+(e?" ("+e+")":"")},se=function(e){return'Custom event "'+e+'" does not exist'},ce=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+te},le=function(){return"No environment/client-side ID was specified."+te},fe=function(e){return"Error fetching flag settings: "+ee(e)},ve=function(){return"No user specified."+te},de=function(){return"Invalid user specified."+te},ge=function(){return"Invalid data received from LaunchDarkly; connection may have been interrupted"},pe=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+te},me=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},ye=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},he=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(d(e)?t:"giving up permanently")},be=function(){return"Cannot make HTTP requests in this environment."+te},ke=function(){return"identify() has no effect here; it must be called on the main client instance"},Ee=function(){return"Closing stream connection"},we=function(e){return"Opening stream connection to "+e},De=function(e,n){return"Error on stream connection: "+ee(e)+", will continue retrying every "+n+" milliseconds."},Oe=function(e){return'Ignoring unknown config option "'+e+'"'},Pe=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},Se=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},Ue=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},Ie=function(e){return"polling for feature flags at "+e},je=function(){return"received ping message from stream"},Re=function(){return"received streaming update for all flags"},Te=function(e){return'received streaming update for flag "'+e+'"'},Le=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},Fe=function(e){return'received streaming deletion for flag "'+e+'"'},Ne=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},Ae=function(e){return'enqueueing "'+e+'" event'},Ce=function(e){return"sending "+e+" events"},xe=Object.freeze({__proto__:null,clientInitialized:ne,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:re,eventWithoutUser:ie,invalidContentType:oe,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:ae,networkError:ue,unknownCustomEventKey:se,environmentNotFound:ce,environmentNotSpecified:le,errorFetchingFlags:fe,userNotSpecified:ve,invalidUser:de,invalidData:ge,bootstrapOldFormat:pe,bootstrapInvalid:me,deprecated:ye,httpErrorMessage:he,httpUnavailable:be,identifyDisabled:ke,streamClosing:Ee,streamConnecting:we,streamError:De,unknownOption:Oe,wrongOptionType:Pe,wrongOptionTypeBoolean:Se,optionBelowMinimum:Ue,debugPolling:Ie,debugStreamPing:je,debugStreamPut:Re,debugStreamPatch:Te,debugStreamPatchIgnored:Le,debugStreamDelete:Fe,debugStreamDeleteIgnored:Ne,debugEnqueueingEvent:Ae,debugPostingEvents:Ce,debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"}});function qe(n){var e={},o={};return e.on=function(e,n,t){o[e]=o[e]||[],o[e]=o[e].concat({handler:n,context:t})},e.off=function(e,n,t){if(o[e])for(var r=0;r<o[e].length;r++)o[e][r].handler===n&&o[e][r].context===t&&(o[e]=o[e].slice(0,r).concat(o[e].slice(r+1)))},e.emit=function(e){if(o[e])for(var n=o[e].slice(0),t=0;t<n.length;t++)n[t].handler.apply(n[t].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(o)},e.getEventListenerCount=function(e){return o[e]?o[e].length:0},e.maybeReportError=function(e){e&&(o.error?this.emit("error",e):(n||console).error(e.message))},e}var Ve=function(r){var n=!1,t=!1,o=null,e=null,i=new Promise(function(n){r.on("ready",function e(){r.off("ready",e),n()})}).catch(function(){});return{getInitializationPromise:function(){return e||(n?Promise.resolve():t?Promise.reject(o):e=new Promise(function(n,t){r.on("initialized",function e(){r.off("initialized",e),n()}),r.on("failed",function e(n){r.off("failed",e),t(n)})}))},getReadyPromise:function(){return i},signalSuccess:function(){n||t||(n=!0,r.emit("initialized"),r.emit("ready"))},signalFailure:function(e){n||t||(t=!0,o=e,r.emit("failed",e),r.emit("ready")),r.maybeReportError(e)}}};function _e(t,r,o,i){var a={};function u(){var e="",n=i.getUser();return n&&(e=o||S(JSON.stringify(n))),"ld:"+r+":"+e}return a.loadFlags=function(){return t.get(u()).then(function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var t=n.$schema;void 0===t||t<1?n=L(n):delete n.$schema}return n}catch(e){return a.clearFlags().then(function(){return null})}})},a.saveFlags=function(e){var n=q({},e,{$schema:1});return t.set(u(),JSON.stringify(n))},a.clearFlags=function(){return t.clear(u())},a}function ze(o,i,a,n){var u,s=i.streamUrl,c=i.logger,e={},l=s+"/eval/"+a,f=i.useReport,d=i.evaluationReasons,t=i.streamReconnectDelay,v=C(o,i),g=!1,p=null,m=null,h=null,y=null,w=null;function b(e){g||(c.warn(De(e,t)),g=!0),S(!1),E(),k(t)}function k(e){m||(e?m=setTimeout(r,e):r())}function r(){var e;m=null;var n="",t={headers:v,readTimeoutMillis:3e5};if(o.eventSourceFactory){for(var r in null!=y&&(n="h="+y),f?o.eventSourceAllowsReport?(e=l,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(h)):(e=s+"/ping/"+a,n=""):e=l+"/"+U(JSON.stringify(h)),t.headers=x(t.headers,i),d&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,E(),c.info(we(e)),u=(new Date).getTime(),p=o.eventSourceFactory(e,t),w)V(w,r)&&p.addEventListener(r,w[r]);p.onerror=b}}function E(){p&&(c.info("Closing stream connection"),p.close(),p=null)}function S(e){u&&n&&n.recordStreamInit(u,!e,(new Date).getTime()-u),u=null}return e.connect=function(e,n,t){h=e,y=n,w={};function r(n){w[n]=function(e){S(!(g=!1)),t[n]&&t[n](e)}}for(var o in t||{})r(o);k()},e.disconnect=function(){clearTimeout(m),m=null,E()},e.isConnected=function(){return!!(p&&o.eventSourceIsActive&&o.eventSourceIsActive(p))},e}function Je(p,m,a){var s=m.baseUrl,c=m.useReport,l=m.evaluationReasons,d=m.logger,e={},h={};function v(e,n){if(!p.httpRequest)return new Promise(function(e,n){n(new f(be()))});var t=n?"REPORT":"GET",r=C(p,m);n&&(r["Content-Type"]="application/json");var o,i,a,s,c,l,d=h[e];d||(o=function(){delete h[e]},(l={addPromise:function(n,e){i=n,a&&a(),a=e,n.then(function(e){i===n&&(s(e),o())},function(e){i===n&&(c(e),o())})}}).resultPromise=new Promise(function(e,n){s=e,c=n}),d=l,h[e]=d);var v=p.httpRequest(t,e,x(r,m),n),g=v.promise.then(function(e){if(200!==e.status)return Promise.reject(404===(n=e).status?new u(ce()):new f(fe(n.statusText||String(n.status))));if(e.header("content-type")&&"application/json"===e.header("content-type").substring(0,"application/json".length))return JSON.parse(e.body);var n,t=oe(e.header("content-type")||"");return Promise.reject(new f(t))},function(e){return Promise.reject(new f(ue(e)))});return d.addPromise(g,function(){v.cancel&&v.cancel()}),d.resultPromise}return e.fetchJSON=function(e){return v(s+e,null)},e.fetchFlagSettings=function(e,n){var t,r,o,i="";return c?(r=[s,"/sdk/evalx/",a,"/user"].join(""),o=JSON.stringify(e)):(t=U(JSON.stringify(e)),r=[s,"/sdk/evalx/",a,"/users/",t].join("")),n&&(i="h="+n),l&&(i=i+(i?"&":"")+"withReasons=true"),r=r+(i?"?":"")+i,d.debug(Ie(r)),v(r,o)},e}function Me(o){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new s(ve()));var r=I(e);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?o.get("ld:$anonUserId").then(function(e){if(e)return r.key=e,r;var n,t=W();return r.key=t,(n=t,o.set("ld:$anonUserId",n)).then(function(){return r})}):Promise.reject(new s(de()))},e}var Ke=["debug","info","warn","error","none"];function He(e,u){if(e&&e.destination&&"function"!=typeof e.destination)throw new Error("destination for basicLogger was set to a non-function");function n(n){return function(e){console&&console[n]&&console[n].call(console,e)}}var s=e&&e.destination?[e.destination,e.destination,e.destination,e.destination]:[n("log"),n("info"),n("warn"),n("error")],c=!(!e||!e.destination),l=e&&void 0!==e.prefix&&null!==e.prefix?e.prefix:"[LaunchDarkly] ",r=1;if(e&&e.level)for(var t=0;t<Ke.length;t++)Ke[t]===e.level&&(r=t);for(var o={},a=function(e){var n=Ke[e];if("none"!==n)if(e<r)o[n]=function(){};else{var t=e;o[n]=function(){!function(e,n,t){if(!(t.length<1)){var r,o=c?n+": "+l:l;if(1!==t.length&&u){var a=i(t);a[0]=o+a[0],r=u.apply(void 0,i(a))}else r=o+t[0];try{s[e](r)}catch(e){console&&console.log&&console.log("[LaunchDarkly] Configured logger's "+n+" method threw an exception: "+e)}}}(t,n,arguments)}}},f=0;f<Ke.length;f++)a(f);return o}function Be(e,n){return He({level:e,prefix:n})}var $e={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},streaming:{type:"boolean"},sendLDHeaders:{default:!0},requestHeaderTransform:{type:"function"},inlineUsersInEvents:{default:!1},allowFrequentDuplicateEvents:{default:!1},sendEventsOnlyForVariation:{default:!1},useReport:{default:!1},evaluationReasons:{default:!1},eventCapacity:{default:100,minimum:1},flushInterval:{default:2e3,minimum:2e3},samplingInterval:{default:0,minimum:0},streamReconnectDelay:{default:1e3,minimum:0},allAttributesPrivate:{default:!1},privateAttributeNames:{default:[]},bootstrap:{type:"string|object"},diagnosticRecordingInterval:{default:9e5,minimum:2e3},diagnosticOptOut:{default:!1},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"},autoAliasingOptOut:{default:!1}};function Ge(n,t,r,o){var a=q({logger:{default:o}},$e,r),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){R(function(){t&&t.maybeReportError(new l(e))})}var s,c,f,d,v,g=q({},n||{});return v=g,Object.keys(i).forEach(function(e){if(void 0!==v[e]){var n=i[e];o&&o.warn(ye(e,n)),n&&(void 0===v[n]&&(v[n]=v[e]),delete v[e])}}),s=(d=q({},g),Object.keys(a).forEach(function(e){void 0!==d[e]&&null!==d[e]||(d[e]=a[e]&&a[e].default)}),c=g=d,f=q({},c),Object.keys(c).forEach(function(e){var n=c[e];if(null!=n){var t=a[e];if(void 0===t)u(Oe(e));else{var r=t.type||p(t.default);if("any"!==r){var o=r.split("|"),i=p(n);o.indexOf(i)<0?"boolean"===r?(f[e]=!!n,u(Se(e,i))):(u(Pe(e,r,i)),f[e]=t.default):"number"===i&&void 0!==t.minimum&&n<t.minimum&&(u(Ue(e,n,t.minimum)),f[e]=t.minimum)}}}}),g=f).logger,Ke.forEach(function(e){if("none"!==e&&(!s[e]||"function"!=typeof s[e]))throw new Error("Provided logger instance must support logger."+e+"(...) method")}),g;function p(n){if(null===n)return"any";if(void 0!==n){if(Array.isArray(n))return"array";var t=e(n);return"boolean"===t||"string"===t||"number"===t||"function"===t?t:"object"}}}var Xe=Object.freeze({__proto__:null,baseOptionDefs:$e,validate:Ge}).baseOptionDefs,We=function(e){var n={diagnosticId:W()};return e&&(n.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),n},Qe=function(e){var n,t,r,o;function i(e){n=e,r=t=0,o=[]}return i(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:o}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,o=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};o.push(r)},reset:i}},Ye=function(n,o,e,t,i,a,u){var s,c,l=!!n.diagnosticUseCombinedEvent,f="ld:"+i+":$diagnostics",d=a.eventsUrl+"/events/diagnostic/"+i,v=a.diagnosticRecordingInterval,g=e,p=!!a.streaming,m={};function h(){return{sdk:function(){var e=r({},n.diagnosticSdkData);return a.wrapperName&&(e.wrapperName=a.wrapperName),a.wrapperVersion&&(e.wrapperVersion=a.wrapperVersion),e}(),configuration:(e={customBaseURI:a.baseUrl!==Xe.baseUrl.default,customStreamURI:a.streamUrl!==Xe.streamUrl.default,customEventsURI:a.eventsUrl!==Xe.eventsUrl.default,eventsCapacity:a.eventCapacity,eventsFlushIntervalMillis:a.flushInterval,reconnectTimeMillis:a.streamReconnectDelay,streamingDisabled:!p,allAttributesPrivate:!!a.allAttributesPrivate,inlineUsersInEvents:!!a.inlineUsersInEvents,diagnosticRecordingIntervalMillis:a.diagnosticRecordingInterval,usingSecureMode:!!a.hash,bootstrapMode:!!a.bootstrap,fetchGoalsDisabled:!a.fetchGoals,allowFrequentDuplicateEvents:!!a.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!a.sendEventsOnlyForVariation,autoAliasingOptOut:!!a.autoAliasingOptOut},e),platform:n.diagnosticPlatformData};var e}function y(e){a.logger&&a.logger.debug(xe.debugPostingDiagnosticEvent(e)),t.sendEvents(e,d,!0).then(function(){}).catch(function(){})}function w(){var e,n;y((e=(new Date).getTime(),n=r({kind:l?"diagnostic-combined":"diagnostic",id:u,creationDate:e},g.getProps()),l&&(n=r({},n,{},h())),g.reset(e),n)),c=setTimeout(w,v),s=(new Date).getTime(),l&&function(){if(o.isEnabled()){var e=r({},g.getProps());o.set(f,JSON.stringify(e))}}()}return m.start=function(){l?function(t){if(!o.isEnabled())return t(!1);o.get(f).then(function(e){if(e)try{var n=JSON.parse(e);g.setProps(n),s=n.dataSinceDate}catch(e){}t(!0)}).catch(function(){t(!1)})}(function(e){if(e){var n=(s||0)+v,t=(new Date).getTime();n<=t?w():c=setTimeout(w,n-t)}else 0===Math.floor(4*Math.random())?w():c=setTimeout(w,v)}):(y(r({kind:"diagnostic-init",id:u,creationDate:g.getProps().dataSinceDate},h())),c=setTimeout(w,v))},m.stop=function(){c&&clearTimeout(c)},m.setStreaming=function(e){p=e},m};function Ze(n,t,o,i,s){var l,g,p,m,h,y,w,b,k,E=o&&o.logger?o.logger:s&&s.logger&&s.logger.default||Be("warn"),S=qe(E),D=Ve(S),O=Ge(o,S,s,E),P=O.sendEvents,U=n,L=O.hash,x=(y=i.localStorage,w=E,k=!(b={}),b.isEnabled=function(){return!!y},b.get=function(e){return new Promise(function(n){y?y.get(e).then(n).catch(function(e){ie(e),n(void 0)}):n(void 0)})},b.set=function(e,t){return new Promise(function(n){y?y.set(e,t).then(function(){return n(!0)}).catch(function(e){ie(e),n(!1)}):n(!1)})},b.clear=function(e){return new Promise(function(n){y?y.clear(e).then(function(){return n(!0)}).catch(function(e){ie(e),n(!1)}):n(!1)})},b),C=Q(i,U,O),N=O.sendEvents&&!O.diagnosticOptOut,A=N?We(U):null,z=N?Qe((new Date).getTime()):null,K=N?Ye(i,x,z,C,U,O,A):null,M=ze(i,O,U,z),H=O.eventProcessor||function(e,n,t,r,o,i){var u,s=3<arguments.length&&void 0!==r?r:null,c=4<arguments.length&&void 0!==o?o:null,l={},f=(5<arguments.length&&void 0!==i?i:null)||Q(e,t,n),v=n.eventsUrl+"/events/bulk/"+t,g=Y(),p=Z(n),m=n.inlineUsersInEvents,h=n.samplingInterval,y=n.eventCapacity,w=n.flushInterval,b=n.logger,k=[],E=0,S=!1,D=!1;function O(){return 0===h||0===Math.floor(Math.random()*h)}function P(e){k.length<y?(k.push(e),D=!1):(D||(D=!0,b.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")),s&&s.incrementDroppedEvents())}return l.enqueue=function(e){if(!S){var n=!1,t=!1;if(g.summarizeEvent(e),"feature"===e.kind?O()&&(n=!!e.trackEvents,t=function(e){return!!e.debugEventsUntilDate&&e.debugEventsUntilDate>E&&e.debugEventsUntilDate>(new Date).getTime()}(e)):n=O(),n&&P(function(e){var n=q({},e);return"alias"===e.kind||(m||"identify"===e.kind?n.user=p.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate)),n}(e)),t){var r=q({},e,{kind:"debug"});r.user=p.filterUser(r.user),delete r.trackEvents,delete r.debugEventsUntilDate,P(r)}}},l.flush=function(){if(S)return Promise.resolve();var e=k,n=g.getSummary();return g.clearSummary(),n&&(n.kind="summary",e.push(n)),s&&s.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(k=[],b.debug(Ce(e.length)),f.sendEvents(e,v).then(function(e){e&&(e.serverTime&&(E=e.serverTime),d(e.status)||(S=!0),400<=e.status&&R(function(){c.maybeReportError(new a(he(e.status,"event posting","some events were dropped")))}))}))},l.start=function(){u=setTimeout(function e(){l.flush(),u=setTimeout(e,w)},w)},l.stop=function(){clearTimeout(u)},l}(i,O,U,z,S,C),J=Je(i,O,U),B={},G={},$=O.streaming,X=!1,W=!1,ee=!0,ne=O.stateProvider,te=(m=function(e,n){var t;t=e,ne||t&&ue({kind:"identify",key:t.key,user:t,creationDate:(new Date).getTime()}),!O.autoAliasingOptOut&&n&&n.anonymous&&e&&!e.anonymous&&me(e,n)},{setUser:function(e){var n=h&&I(h);(h=_(e))&&m&&m(I(h),n)},getUser:function(){return h?I(h):null}}),re=Me(x),oe=x.isEnabled()?new _e(x,U,L,te,E):null;function ie(e){k||(k=!0,w.warn(ae(e)))}function ue(e){if(U&&!(ne&&ne.enqueueEvent&&ne.enqueueEvent(e))){if("alias"!==e.kind){if(!e.user)return void(ee&&(E.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"),ee=!1));ee=!1}!P||W||i.isDoNotTrack()||(E.debug(Ae(e.kind)),H.enqueue(e))}}function ce(e,n,t,r){var o=te.getUser(),i=new Date,a=n?n.value:null;if(!O.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(o&&o.key?o.key:"")+e,s=B[u];if(s&&i-s<3e5)return;B[u]=i}var c={kind:"feature",key:e,user:o,value:a,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()};o&&o.anonymous&&(c.contextKind=ge(o));var l=G[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),ue(c)}function de(e,n,t,r){var o;if(G&&V(G,e)&&G[e]&&!G[e].deleted){var i=G[e];o=ve(i),null!==i.value&&void 0!==i.value||(o.value=n)}else o={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&ce(e,o,n,r),o}function ve(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function ge(e){return e.anonymous?"anonymousUser":"user"}function me(e,n){ne||e&&n&&ue({kind:"alias",key:e.key,contextKind:ge(e),previousKey:n.key,previousContextKind:ge(n),creationDate:(new Date).getTime()})}function ye(){if(g=!0,te.getUser()){var a=function(e){try{return JSON.parse(e)}catch(e){return void S.maybeReportError(new v("Invalid data received from LaunchDarkly; connection may have been interrupted"))}};M.connect(te.getUser(),L,{ping:function(){E.debug("received ping message from stream");var n=te.getUser();J.fetchFlagSettings(n,L).then(function(e){j(n,te.getUser())&&be(e||{})}).catch(function(e){S.maybeReportError(new f(fe(e)))})},put:function(e){var n=a(e.data);n&&(E.debug("received streaming update for all flags"),be(n))},patch:function(e){var n=a(e.data);if(n){var t=G[n.key];if(!t||!t.version||!n.version||t.version<n.version){E.debug(Te(n.key));var r={},o=q({},n);delete o.key;var i=ve(G[n.key]=o);r[n.key]=t?{previous:t.value,current:i}:{current:i},ke(r)}else E.debug(Le(n.key))}},delete:function(e){var n=a(e.data);if(n)if(!G[n.key]||G[n.key].version<n.version){E.debug(Fe(n.key));var t={};G[n.key]&&!G[n.key].deleted&&(t[n.key]={previous:G[n.key].value}),G[n.key]={version:n.version,deleted:!0},ke(t)}else E.debug(Ne(n.key))}})}}function we(){g&&(M.disconnect(),g=!1)}function be(e){var n={};if(!e)return Promise.resolve();for(var t in G)V(G,t)&&G[t]&&(e[t]&&!j(e[t].value,G[t].value)?n[t]={previous:G[t].value,current:ve(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:G[t].value}));for(var o in e)V(e,o)&&e[o]&&(!G[o]||G[o].deleted)&&(n[o]={current:ve(e[o])});return G=r({},e),ke(n).catch(function(){})}function ke(o){var e=Object.keys(o);if(0<e.length){var i={};e.forEach(function(e){var n=o[e].current,t=n?n.value:void 0,r=o[e].previous;S.emit("change:"+e,t,r),i[e]=n?{current:t,previous:r}:{previous:r}}),S.emit("change",i),S.emit("internal-change",G),O.sendEventsOnlyForVariation||ne||e.forEach(function(e){ce(e,o[e].current)})}return l&&oe?oe.saveFlags(G):Promise.resolve()}function Ee(){var e=$||p&&void 0===$;e&&!g?ye():!e&&g&&we(),K&&K.setStreaming(e)}function Se(e){return"change"===e||"change:"===e.substr(0,"change".length+1)}if("string"==typeof O.bootstrap&&"LOCALSTORAGE"===O.bootstrap.toUpperCase()&&(oe?l=!0:E.warn(ae())),"object"===e(O.bootstrap)&&(G=function(t){var e=Object.keys(t),r=t.$flagsState;!r&&e.length&&E.warn(pe()),!1===t.$valid&&E.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var o={};return e.forEach(function(e){if("$flagsState"!==e&&"$valid"!==e){var n={value:t[e]};r&&r[e]?n=q(n,r[e]):n.version=0,o[e]=n}}),o}(O.bootstrap)),ne){var De=ne.getInitialState();De?Oe(De):ne.on("init",Oe),ne.on("update",function(e){e.user&&te.setUser(e.user),e.flags&&be(e.flags)})}else(n?re.validateUser(t).then(function(n){return te.setUser(n),"object"===e(O.bootstrap)?Pe():l?oe.loadFlags().then(function(e){return null==e?(G={},J.fetchFlagSettings(te.getUser(),L).then(function(e){return be(e||{})}).then(Pe).catch(function(e){Re(new f(fe(e)))})):(G=e,R(Pe),J.fetchFlagSettings(te.getUser(),L).then(function(e){return be(e)}).catch(function(e){return S.maybeReportError(e)}))}):J.fetchFlagSettings(te.getUser(),L).then(function(e){G=e||{},Pe()}).catch(function(e){G={},Re(e)})}):Promise.reject(new u(le()))).catch(Re);function Oe(e){U=e.environment,te.setUser(e.user),G=r({},e.flags),R(Pe)}function Pe(){E.info("LaunchDarkly client initialized"),X=!0,Ee(),D.signalSuccess()}function Re(e){D.signalFailure(e)}return{client:{waitForInitialization:function(){return D.getInitializationPromise()},waitUntilReady:function(){return D.getReadyPromise()},identify:function(e,r,n){return W?T(Promise.resolve({}),n):ne?(E.warn("identify() has no effect here; it must be called on the main client instance"),T(Promise.resolve(F(G)),n)):T((l&&oe?oe.clearFlags():Promise.resolve()).then(function(){return re.validateUser(e)}).then(function(t){return J.fetchFlagSettings(t,r).then(function(e){var n=F(e);return te.setUser(t),L=r,e?be(e).then(function(){return n}):n})}).then(function(e){return g&&ye(),e}).catch(function(e){return S.maybeReportError(e),Promise.reject(e)}),n)},getUser:function(){return te.getUser()},variation:function(e,n){return de(e,n,!0,!1).value},variationDetail:function(e,n){return de(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){i.customEventFilter&&!i.customEventFilter(e)&&E.warn(se(e));var r=te.getUser(),o={kind:"custom",key:e,user:r,url:i.getCurrentUrl(),creationDate:(new Date).getTime()};r&&r.anonymous&&(o.contextKind=ge(r)),null!=n&&(o.data=n),null!=t&&(o.metricValue=t),ue(o)}else S.maybeReportError(new c(se(e)))},alias:me,on:function(e,n,t){Se(e)?(p=!0,X&&Ee(),S.on(e,n,t)):S.on.apply(S,arguments)},off:function(e){if(S.off.apply(S,arguments),Se(e)){var n=!1;S.getEvents().forEach(function(e){Se(e)&&0<S.getEventListenerCount(e)&&(n=!0)}),n||(p=!1,g&&void 0===$&&we())}},setStreaming:function(e){var n=null===e?void 0:e;n!==$&&($=n,Ee())},flush:function(e){return T(P?H.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!G)return e;for(var n in G)V(G,n)&&(e[n]=de(n,null,!O.sendEventsOnlyForVariation).value);return e},close:function(e){if(W)return T(Promise.resolve(),e);function n(){W=!0,G={}}return T(Promise.resolve().then(function(){if(we(),K&&K.stop(),P)return H.stop(),H.flush()}).then(n).catch(n),e)}},options:O,emitter:S,ident:te,logger:E,requestor:J,start:function(){P&&(K&&K.start(),H.start())},enqueueEvent:ue,getFlagsInternal:function(){return G},getEnvironmentId:function(){return U},internalChangeEventName:"internal-change"}}var en="3.5.1",ldclientCommon_es=Object.freeze({__proto__:null,commonBasicLogger:He,createConsoleLogger:Be,errors:g,initialize:Ze,messages:xe,utils:z,version:en});function _defineProperty(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function ownKeys(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),t.push.apply(t,r)}return t}function _objectSpread2(n){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(t),!0).forEach(function(e){_defineProperty(n,e,t[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(t,e))})}return n}var commonBasicLogger=ldclientCommon_es.commonBasicLogger;function basicLogger(e){return commonBasicLogger(_objectSpread2({destination:console.log},e))}var basicLogger_1={basicLogger:basicLogger},basicLogger_2=basicLogger_1.basicLogger;function isSyncXhrSupported(){var e=window.navigator&&window.navigator.userAgent;if(e){var n=e.match(/Chrom(e|ium)\/([0-9]+)\./);if(n)return parseInt(n[2],10)<73}return!0}var emptyResult={promise:Promise.resolve({status:200,header:function(){return null},body:null})};function newHttpRequest(e,n,t,r,o){if(o&&!isSyncXhrSupported())return emptyResult;var i=new window.XMLHttpRequest;for(var a in i.open(e,n,!o),t||{})Object.prototype.hasOwnProperty.call(t,a)&&i.setRequestHeader(a,t[a]);if(o)return i.send(r),emptyResult;var u;return{promise:new Promise(function(e,n){i.addEventListener("load",function(){u||e({status:i.status,header:function(e){return i.getResponseHeader(e)},body:i.responseText})}),i.addEventListener("error",function(){u||n(new Error)}),i.send(r)}),cancel:function(){u=!0,i.abort()}}}function makeBrowserPlatform(e){var n,i={synchronousFlush:!1};if(window.XMLHttpRequest){var a=e&&e.disableSyncEventPost;i.httpRequest=function(e,n,t,r){var o=i.synchronousFlush&!a;return i.synchronousFlush=!1,newHttpRequest(e,n,t,r,o)}}i.httpAllowsPost=function(){return void 0===n&&(n=!!window.XMLHttpRequest&&"withCredentials"in new window.XMLHttpRequest),n},i.httpFallbackPing=function(e){(new window.Image).src=e};var r,t=e&&e.eventUrlTransformer;i.getCurrentUrl=function(){return t?t(window.location.href):window.location.href},i.isDoNotTrack=function(){var e;return 1===(e=window.navigator&&void 0!==window.navigator.doNotTrack?window.navigator.doNotTrack:window.navigator&&void 0!==window.navigator.msDoNotTrack?window.navigator.msDoNotTrack:window.doNotTrack)||!0===e||"1"===e||"yes"===e};try{window.localStorage&&(i.localStorage={get:function(n){return new Promise(function(e){e(window.localStorage.getItem(n))})},set:function(n,t){return new Promise(function(e){window.localStorage.setItem(n,t),e()})},clear:function(n){return new Promise(function(e){window.localStorage.removeItem(n),e()})}})}catch(e){i.localStorage=null}var o=e&&e.useReport;if(r=o&&"function"==typeof window.EventSourcePolyfill&&window.EventSourcePolyfill.supportedOptions&&window.EventSourcePolyfill.supportedOptions.method?(i.eventSourceAllowsReport=!0,window.EventSourcePolyfill):(i.eventSourceAllowsReport=!1,window.EventSource),window.EventSource){i.eventSourceFactory=function(e,n){var t=_objectSpread2(_objectSpread2({},{heartbeatTimeout:3e5,silentTimeout:3e5,skipDefaultHeaders:!0}),n);return new r(e,t)},i.eventSourceIsActive=function(e){return e.readyState===window.EventSource.OPEN||e.readyState===window.EventSource.CONNECTING}}return i.userAgent="JSClient",i.version="2.21.0",i.diagnosticSdkData={name:"js-client-sdk",version:"2.21.0"},i.diagnosticPlatformData={name:"JS"},i.diagnosticUseCombinedEvent=!0,i}var matchOperatorsRe=/[|\\{}()[\]^$+*?.]/g,escapeStringRegexp=function(e){if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(matchOperatorsRe,"\\$&")};function doesUrlMatch(e,n,t,r){var o,i,a=(("substring"===e.kind||"regex"===e.kind)&&r.includes("/")?n:n.replace(r,"")).replace(t,"");switch(e.kind){case"exact":i=n,o=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"canonical":i=a,o=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"substring":i=a,o=new RegExp(".*"+escapeStringRegexp(e.substring)+".*$");break;case"regex":i=a,o=new RegExp(e.pattern);break;default:return!1}return o.test(i)}function findGoalsForClick(e,n){for(var t=[],r=0;r<n.length;r++)for(var o=e.target,i=n[r],a=i.selector,u=document.querySelectorAll(a);o&&0<u.length;){for(var s=0;s<u.length;s++)o===u[s]&&t.push(i);o=o.parentNode}return t}function GoalTracker(e,r){for(var n={},t=null,o=[],i=0;i<e.length;i++)for(var a=e[i],u=a.urls||[],s=0;s<u.length;s++)if(doesUrlMatch(u[s],window.location.href,window.location.search,window.location.hash)){"pageview"===a.kind?r("pageview",a):(o.push(a),r("click_pageview",a));break}return 0<o.length&&(t=function(e){for(var n=findGoalsForClick(e,o),t=0;t<n.length;t++)r("click",n[t])},document.addEventListener("click",t)),n.dispose=function(){document.removeEventListener("click",t)},n}var locationWatcherInterval=300;function GoalManager(o,n){var t,r;function i(){r&&r.dispose(),t&&t.length&&(r=GoalTracker(t,a))}function a(e,n){var t=o.ident.getUser(),r={kind:e,key:n.key,data:null,url:window.location.href,user:t,creationDate:(new Date).getTime()};return t&&t.anonymous&&(r.contextKind="anonymousUser"),"click"===e&&(r.selector=n.selector),o.enqueueEvent(r)}function u(e,n){var t,r=window.location.href;function o(){(t=window.location.href)!==r&&(r=t,n())}!function e(n,t){n(),setTimeout(function(){e(n,t)},t)}(o,e),window.history&&window.history.pushState?window.addEventListener("popstate",o):window.addEventListener("hashchange",o)}return o.requestor.fetchJSON("/sdk/goals/"+o.getEnvironmentId()).then(function(e){e&&0<e.length&&(r=GoalTracker(t=e,a),u(locationWatcherInterval,i)),n()}).catch(function(e){o.emitter.maybeReportError(new g.LDUnexpectedResponseError((e&&e.message,e.message))),n()}),{}}var goalsEvent="goalsReady",extraOptionDefs={fetchGoals:{default:!0},hash:{type:"string"},eventProcessor:{type:"object"},eventUrlTransformer:{type:"function"},disableSyncEventPost:{default:!1}};function initialize(e,n){var t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},r=makeBrowserPlatform(t),o=Ze(e,n,t,r,extraOptionDefs),i=o.client,a=o.options,u=o.emitter,s=new Promise(function(e){var n=u.on(goalsEvent,function(){u.off(goalsEvent,n),e()})});i.waitUntilGoalsReady=function(){return s},a.fetchGoals?GoalManager(o,function(){return u.emit(goalsEvent)}):u.emit(goalsEvent),"complete"!==document.readyState?window.addEventListener("load",o.start):o.start();function c(){r.synchronousFlush=!0,i.flush().catch(function(){}),r.synchronousFlush=!1}return window.addEventListener("beforeunload",c),window.addEventListener("unload",c),i}var basicLogger$1=basicLogger_2,createConsoleLogger=Be,version="2.21.0";function deprecatedInitialize(e,n){var t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return console&&console.warn&&console.warn(xe.deprecated("default export","named LDClient export")),initialize(e,n,t)}var index={initialize:deprecatedInitialize,version:version};exports.basicLogger=basicLogger$1,exports.createConsoleLogger=createConsoleLogger,exports.default=index,exports.initialize=initialize,exports.version=version;
2
2
  //# sourceMappingURL=ldclient.cjs.js.map