launchdarkly-js-client-sdk 2.23.0 → 2.24.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.
@@ -1,2 +1,2 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).LDClient={})}(this,(function(e){"use strict";function n(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function t(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(n){o(e,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))}))}return e}function r(e){return(r="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})(e)}function o(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function i(e){return function(e){if(Array.isArray(e))return a(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,n){if(e){if("string"==typeof e)return a(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?a(e,n):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function u(e){function n(e,n){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=n}return n.prototype=new Error,n.prototype.name=e,n.prototype.constructor=n,n}var s=u("LaunchDarklyUnexpectedResponseError"),c=u("LaunchDarklyInvalidEnvironmentIdError"),l=u("LaunchDarklyInvalidUserError"),f=u("LaunchDarklyInvalidEventKeyError"),d=u("LaunchDarklyInvalidArgumentError"),v=u("LaunchDarklyFlagFetchError"),g=u("LaunchDarklyInvalidDataError");function p(e){return!(e>=400&&e<500)||400===e||408===e||429===e}for(var m=Object.freeze({__proto__:null,LDUnexpectedResponseError:s,LDInvalidEnvironmentIdError:c,LDInvalidUserError:l,LDInvalidEventKeyError:f,LDInvalidArgumentError:d,LDFlagFetchError:v,LDInvalidDataError:g,isHttpErrorRecoverable:p}),h=[],y=[],w="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",b=0,k=w.length;b<k;++b)h[b]=w[b],y[w.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(h[(o=r)>>18&63]+h[o>>12&63]+h[o>>6&63]+h[63&o]);return i.join("")}y["-".charCodeAt(0)]=62,y["_".charCodeAt(0)]=63;var D=Array.isArray,O=Object.keys,S=Object.prototype.hasOwnProperty,P=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function U(e,n){return(e.endsWith("/")?e.substring(0,e.length-1):e)+(n.startsWith("/")?"":"/")+n}function j(e){return 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,i+16383>a?a:i+16383));return 1===r?(n=e[t-1],o.push(h[n>>2]+h[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(h[n>>10]+h[n>>4&63]+h[n<<2&63]+"=")),o.join("")}(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(unescape(encodeURIComponent(e))))}function I(e){return j(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function T(e){return JSON.parse(JSON.stringify(e))}function R(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=D(n),u=D(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=O(n);if((o=d.length)!==O(t).length)return!1;for(r=o;0!=r--;)if(!S.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 L(e){setTimeout(e,0)}function x(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 C(e){var n={};for(var t in e)_(e,t)&&(n[t]={value:e[t],version:0});return n}function N(e){var n={};for(var t in e)_(e,t)&&(n[t]=e[t].value);return n}function A(e,n){for(var t,r=n.slice(0),o=[],i=e;r.length>0;){for(t=[];i>0;){var a=r.shift();if(!a)break;(i-=I(JSON.stringify(a)).length)<0&&t.length>0?r.unshift(a):t.push(a)}i=e,o.push(t)}return o}function F(e){var n=e.version||"3.7.0";return e.userAgent+"/"+n}function q(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return n.reduce((function(e,n){return t(t({},e),n)}),{})}function _(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function V(e){if(!e)return e;var n;for(var r in P){var o=P[r],i=e[o];void 0!==i&&"string"!=typeof i&&((n=n||t({},e))[o]=String(i))}return n||e}for(var z=Object.freeze({__proto__:null,appendUrlPath:U,btoa:j,base64URLEncode:I,clone:T,deepEquals:R,onNextTick:L,wrapPromiseCallback:x,transformValuesToVersionedValues:C,transformVersionedValuesToValues:N,chunkUserEventsForUrl:A,getLDUserAgentString:F,extend:q,objectHasOwnProperty:_,sanitizeUser:V}),M=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=[],$=0;$<256;++$)J[$]=($+256).toString(16).substr(1);var H,K,B=0,G=0,X=function(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||H,a=void 0!==e.clockseq?e.clockseq:K;if(null==i||null==a){var u=M();null==i&&(i=H=[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:G+1,l=s-B+(c-G)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>B)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");B=s,G=c,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||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("")}(o)},W=["debug","info","warn","error","none"];function Q(e,n){if(e&&e.destination&&"function"!=typeof e.destination)throw new Error("destination for basicLogger was set to a non-function");function t(e){return function(n){console&&console[e]&&console[e].call(console,n)}}var r=e&&e.destination?[e.destination,e.destination,e.destination,e.destination]:[t("log"),t("info"),t("warn"),t("error")],o=!(!e||!e.destination),a=e&&void 0!==e.prefix&&null!==e.prefix?e.prefix:"[LaunchDarkly] ",u=1;if(e&&e.level)for(var s=0;s<W.length;s++)W[s]===e.level&&(u=s);function c(e,t,u){if(!(u.length<1)){var s,c=o?t+": "+a:a;if(1!==u.length&&n){var l=i(u);l[0]=c+l[0],s=n.apply(void 0,i(l))}else s=c+u[0];try{r[e](s)}catch(e){console&&console.log&&console.log("[LaunchDarkly] Configured logger's "+t+" method threw an exception: "+e)}}}for(var l={},f=function(e){var n=W[e];if("none"!==n)if(e<u)l[n]=function(){};else{var t=e;l[n]=function(){c(t,n,arguments)}}},d=0;d<W.length;d++)f(d);return l}function Y(e,n){return Q({level:e,prefix:n})}function Z(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var ee=" Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initializing-the-client for instructions on SDK initialization.",ne=function(e){return'Expected application/json content type but got "'+e+'"'},te=function(e){return"local storage is unavailable: "+Z(e)},re=function(e){return"network error"+(e?" ("+e+")":"")},oe=function(e){return'Custom event "'+e+'" does not exist'},ie=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+ee},ae=function(){return"No environment/client-side ID was specified."+ee},ue=function(e){return"Error fetching flag settings: "+Z(e)},se=function(){return"No user specified."+ee},ce=function(){return"Invalid user specified."+ee},le=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+ee},fe=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},de=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(p(e)?t:"giving up permanently")},ve=function(){return"Cannot make HTTP requests in this environment."+ee},ge=function(e){return"Opening stream connection to "+e},pe=function(e,n){return"Error on stream connection: "+Z(e)+", will continue retrying every "+n+" milliseconds."},me=function(e){return'Ignoring unknown config option "'+e+'"'},he=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},ye=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},we=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},be=function(e){return"polling for feature flags at "+e},ke=function(e){return'received streaming update for flag "'+e+'"'},Ee=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},De=function(e){return'received streaming deletion for flag "'+e+'"'},Oe=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},Se=function(e){return'enqueueing "'+e+'" event'},Pe=function(e){return"sending "+e+" events"},Ue=function(e){return'Config option "'.concat(e,'" must only contain letters, numbers, ., _ or -.')},je=Object.freeze({__proto__:null,clientInitialized:function(){return"LaunchDarkly client initialized"},clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},eventWithoutUser:function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"},invalidContentType:ne,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:te,networkError:re,unknownCustomEventKey:oe,environmentNotFound:ie,environmentNotSpecified:ae,errorFetchingFlags:ue,userNotSpecified:se,invalidUser:ce,invalidData:function(){return"Invalid data received from LaunchDarkly; connection may have been interrupted"},bootstrapOldFormat:le,bootstrapInvalid:function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated:fe,httpErrorMessage:de,httpUnavailable:ve,identifyDisabled:function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing:function(){return"Closing stream connection"},streamConnecting:ge,streamError:pe,unknownOption:me,wrongOptionType:he,wrongOptionTypeBoolean:ye,optionBelowMinimum:we,debugPolling:be,debugStreamPing:function(){return"received ping message from stream"},debugStreamPut:function(){return"received streaming update for all flags"},debugStreamPatch:ke,debugStreamPatchIgnored:Ee,debugStreamDelete:De,debugStreamDeleteIgnored:Oe,debugEnqueueingEvent:Se,debugPostingEvents:Pe,debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"},invalidTagValue:Ue}),Ie={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},application:{validator:function(e,n,t,r){var o={};return t.id&&(o.id=Re("".concat(e,".id"),n,t.id,r)),t.version&&(o.version=Re("".concat(e,".version"),n,t.version,r)),o}}},Te=/^(\w|\.|-)+$/;function Re(e,n,t,r){if("string"==typeof t&&t.match(Te))return t;r.warn(Ue(e))}function Le(e,n,t,o){var i=q({logger:{default:o}},Ie,t),a={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null,allowFrequentDuplicateEvents:void 0};function u(e){L((function(){n&&n.maybeReportError(new d(e))}))}var s=q({},e||{});return function(e){var n=e;Object.keys(a).forEach((function(e){if(void 0!==n[e]){var t=a[e];o&&o.warn(fe(e,t)),t&&(void 0===n[t]&&(n[t]=n[e]),delete n[e])}}))}(s),function(e){W.forEach((function(n){if("none"!==n&&(!e[n]||"function"!=typeof e[n]))throw new Error("Provided logger instance must support logger."+n+"(...) method")}))}((s=function(e){var n=q({},e),t=function(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var n=r(e);return"boolean"===n||"string"===n||"number"===n||"function"===n?n:"object"}};return Object.keys(e).forEach((function(r){var a=e[r];if(null!=a){var s=i[r];if(void 0===s)u(me(r));else{var c=s.type||t(s.default),l=s.validator;if(l){var f=l(r,e,e[r],o);void 0!==f?n[r]=f:delete n[r]}else if("any"!==c){var d=c.split("|"),v=t(a);d.indexOf(v)<0?"boolean"===c?(n[r]=!!a,u(ye(r,v))):(u(he(r,c,v)),n[r]=s.default):"number"===v&&void 0!==s.minimum&&a<s.minimum&&(u(we(r,a,s.minimum)),n[r]=s.minimum)}}}})),n}(s=function(e){var n=q({},e);return Object.keys(i).forEach((function(e){void 0!==n[e]&&null!==n[e]||(n[e]=i[e]&&i[e].default)})),n}(s))).logger),s}function xe(e){var n={};return e&&(e.application&&void 0!==e.application.id&&null!==e.application.id&&(n["application-id"]=[e.application.id]),e.application&&void 0!==e.application.version&&null!==e.application.id&&(n["application-version"]=[e.application.version])),n}function Ce(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":F(e)};n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName);var r=xe(n),o=Object.keys(r);return o.length&&(t["x-launchdarkly-tags"]=o.sort().flatMap((function(e){return Array.isArray(r[e])?r[e].sort().map((function(n){return"".concat(e,"/").concat(n)})):["".concat(e,"/").concat(r[e])]})).join(" ")),t}function Ne(e,n){return n&&n.requestHeaderTransform?n.requestHeaderTransform(t({},e)):e}function Ae(e,n,t){var r="/a/"+n+".gif",o=q({"Content-Type":"application/json"},Ce(e,t)),i=e.httpFallbackPing,a={sendChunk:function(n,a,u,s){var c=JSON.stringify(n),l=u?null:X();return s?function n(r){var i=u?o:q({},o,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":l});return e.httpRequest("POST",a,Ne(i,t),c).promise.then((function(e){if(e)return e.status>=400&&p(e.status)&&r?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 r?n(!1):Promise.reject()}))}(!0).catch((function(){})):(i&&i(a+r+"?d="+I(c)),Promise.resolve())},sendEvents:function(n,t,r){if(!e.httpRequest)return Promise.resolve();var o,i=e.httpAllowsPost();o=i?[n]:A(2e3-t.length,n);for(var u=[],s=0;s<o.length;s++)u.push(a.sendChunk(o[s],t,r,i));return Promise.all(u)}};return a}function Fe(){var e={},n=0,t=0,r={};return e.summarizeEvent=function(e){if("feature"===e.kind){var o=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),i=r[o];i?i.count=i.count+1:r[o]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===n||e.creationDate<n)&&(n=e.creationDate),e.creationDate>t&&(t=e.creationDate)}},e.getSummary=function(){var e={},o=!0;for(var i in r){var a=r[i],u=e[a.key];u||(u={default:a.default,counters:[]},e[a.key]=u);var s={value:a.value,count:a.count};void 0!==a.variation&&null!==a.variation&&(s.variation=a.variation),a.version?s.version=a.version:s.unknown=!0,u.counters.push(s),o=!1}return o?null:{startDate:n,endDate:t,features:e}},e.clearSummary=function(){n=0,t=0,r={}},e}function qe(e){var n={},t=e.allAttributesPrivate,r=e.privateAttributeNames||[],o={key:!0,custom:!0,anonymous:!0},i={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;var n=e.privateAttributeNames||[],a=function(e,i){return Object.keys(e).reduce((function(a,u){var s=a;return i(u)&&(function(e){return!o[e]&&(t||-1!==n.indexOf(e)||-1!==r.indexOf(e))}(u)?s[1][u]=!0:s[0][u]=e[u]),s}),[{},{}])},u=a(e,(function(e){return i[e]})),s=u[0],c=u[1];if(e.custom){var l=a(e.custom,(function(){return!0}));s.custom=l[0],c=q({},c,l[1])}var f=Object.keys(c);return f.length&&(f.sort(),s.privateAttrs=f),s},n}function _e(e,n,t,r){var o={};function i(){var e="",o=r.getUser();return o&&(e=t||j(JSON.stringify(o))),"ld:"+n+":"+e}return o.loadFlags=function(){return e.get(i()).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=C(n):delete n.$schema}return n}catch(e){return o.clearFlags().then((function(){return null}))}}))},o.saveFlags=function(n){var t=q({},n,{$schema:1});return e.set(i(),JSON.stringify(t))},o.clearFlags=function(){return e.clear(i())},o}function Ve(e,n,t,r){var o,i=n.streamUrl,a=n.logger,u={},s=U(i,"/eval/"+t),c=n.useReport,l=n.evaluationReasons,f=n.streamReconnectDelay,d=Ce(e,n),v=!1,g=null,p=null,m=null,h=null,y=null;function w(e){v||(a.warn(pe(e,f)),v=!0),D(!1),E(),b(f)}function b(e){p||(e?p=setTimeout(k,e):k())}function k(){var r;p=null;var u="",f={headers:d,readTimeoutMillis:3e5};if(e.eventSourceFactory){for(var v in null!=h&&(u="h="+h),c?e.eventSourceAllowsReport?(r=s,f.method="REPORT",f.headers["Content-Type"]="application/json",f.body=JSON.stringify(m)):(r=U(i,"/ping/"+t),u=""):r=s+"/"+I(JSON.stringify(m)),f.headers=Ne(f.headers,n),l&&(u=u+(u?"&":"")+"withReasons=true"),r=r+(u?"?":"")+u,E(),a.info(ge(r)),o=(new Date).getTime(),g=e.eventSourceFactory(r,f),y)_(y,v)&&g.addEventListener(v,y[v]);g.onerror=w}}function E(){g&&(a.info("Closing stream connection"),g.close(),g=null)}function D(e){o&&r&&r.recordStreamInit(o,!e,(new Date).getTime()-o),o=null}return u.connect=function(e,n,t){m=e,h=n,y={};var r=function(e){y[e]=function(n){v=!1,D(!0),t[e]&&t[e](n)}};for(var o in t||{})r(o);b()},u.disconnect=function(){clearTimeout(p),p=null,E()},u.isConnected=function(){return!!(g&&e.eventSourceIsActive&&e.eventSourceIsActive(g))},u}function ze(e,n,t){var r=n.baseUrl,o=n.useReport,i=n.evaluationReasons,a=n.logger,u={},s={};function l(t,r){if(!e.httpRequest)return new Promise((function(e,n){n(new v(ve()))}));var o=r?"REPORT":"GET",i=Ce(e,n);r&&(i["Content-Type"]="application/json");var a=s[t];a||(a=function(e){var n,t,r,o,i={addPromise:function(i,a){n=i,t&&t(),t=a,i.then((function(t){n===i&&(r(t),e&&e())}),(function(t){n===i&&(o(t),e&&e())}))}};return i.resultPromise=new Promise((function(e,n){r=e,o=n})),i}((function(){delete s[t]})),s[t]=a);var u=e.httpRequest(o,t,Ne(i,n),r),l=u.promise.then((function(e){if(200===e.status){if(e.header("content-type")&&"application/json"===e.header("content-type").substring(0,"application/json".length))return JSON.parse(e.body);var n=ne(e.header("content-type")||"");return Promise.reject(new v(n))}return Promise.reject(function(e){return 404===e.status?new c(ie()):new v(ue(e.statusText||String(e.status)))}(e))}),(function(e){return Promise.reject(new v(re(e)))}));return a.addPromise(l,(function(){u.cancel&&u.cancel()})),a.resultPromise}return u.fetchJSON=function(e){return l(U(r,e),null)},u.fetchFlagSettings=function(e,n){var u,s,c,f="";return o?(s=[r,"/sdk/evalx/",t,"/user"].join(""),c=JSON.stringify(e)):(u=I(JSON.stringify(e)),s=[r,"/sdk/evalx/",t,"/users/",u].join("")),n&&(f="h="+n),i&&(f=f+(f?"&":"")+"withReasons=true"),s=s+(f?"?":"")+f,a.debug(be(s)),l(s,c)},u}function Me(e){var n={validateUser:function(n){if(!n)return Promise.reject(new l(se()));var t=T(n);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?e.get("ld:$anonUserId").then((function(n){if(n)return t.key=n,t;var r=X();return t.key=r,function(n){return e.set("ld:$anonUserId",n)}(r).then((function(){return t}))})):Promise.reject(new l(ce()))}};return n}var Je=Object.freeze({__proto__:null,baseOptionDefs:Ie,validate:Le,getTags:xe}).baseOptionDefs,$e=z.appendUrlPath,He=function(e){var n={diagnosticId:X()};return e&&(n.sdkKeySuffix=e.length>6?e.substring(e.length-6):e),n};function Ke(e,n,o,i,a){var u,l,d,m=o&&o.logger?o.logger:a&&a.logger&&a.logger.default||Y("warn"),h=function(e){var n={},t={};return n.on=function(e,n,r){t[e]=t[e]||[],t[e]=t[e].concat({handler:n,context:r})},n.off=function(e,n,r){if(t[e])for(var o=0;o<t[e].length;o++)t[e][o].handler===n&&t[e][o].context===r&&(t[e]=t[e].slice(0,o).concat(t[e].slice(o+1)))},n.emit=function(e){if(t[e])for(var n=t[e].slice(0),r=0;r<n.length;r++)n[r].handler.apply(n[r].context,Array.prototype.slice.call(arguments,1))},n.getEvents=function(){return Object.keys(t)},n.getEventListenerCount=function(e){return t[e]?t[e].length:0},n.maybeReportError=function(n){n&&(t.error?this.emit("error",n):(e||console).error(n.message))},n}(m),y=function(e){var n=!1,t=!1,r=null,o=null,i=new Promise((function(n){e.on("ready",(function t(){e.off("ready",t),n()}))})).catch((function(){}));return{getInitializationPromise:function(){return o||(n?Promise.resolve():t?Promise.reject(r):o=new Promise((function(n,t){e.on("initialized",(function t(){e.off("initialized",t),n()})),e.on("failed",(function n(r){e.off("failed",n),t(r)}))})))},getReadyPromise:function(){return i},signalSuccess:function(){n||t||(n=!0,e.emit("initialized"),e.emit("ready"))},signalFailure:function(o){n||t||(t=!0,r=o,e.emit("failed",o),e.emit("ready")),e.maybeReportError(o)}}}(h),w=Le(o,h,a,m),b=w.sendEvents,k=e,E=w.hash,D=function(e,n){var t={},r=!1,o=function(e){r||(r=!0,n.warn(te(e)))};return t.isEnabled=function(){return!!e},t.get=function(n){return new Promise((function(t){e?e.get(n).then(t).catch((function(e){o(e),t(void 0)})):t(void 0)}))},t.set=function(n,t){return new Promise((function(r){e?e.set(n,t).then((function(){return r(!0)})).catch((function(e){o(e),r(!1)})):r(!1)}))},t.clear=function(n){return new Promise((function(t){e?e.clear(n).then((function(){return t(!0)})).catch((function(e){o(e),t(!1)})):t(!1)}))},t}(i.localStorage,m),O=Ae(i,k,w),S=w.sendEvents&&!w.diagnosticOptOut,P=S?He(k):null,j=S?function(e){var n,t,r,o;function i(e){n=e,t=0,r=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}}((new Date).getTime()):null,I=S?function(e,n,r,o,i,a,u){var s,c,l=!!e.diagnosticUseCombinedEvent,f="ld:"+i+":$diagnostics",d=$e(a.eventsUrl,"/events/diagnostic/"+i),v=a.diagnosticRecordingInterval,g=r,p=!!a.streaming,m={};function h(){return{sdk:b(),configuration:(n={customBaseURI:a.baseUrl!==Je.baseUrl.default,customStreamURI:a.streamUrl!==Je.streamUrl.default,customEventsURI:a.eventsUrl!==Je.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,sendEventsOnlyForVariation:!!a.sendEventsOnlyForVariation,autoAliasingOptOut:!!a.autoAliasingOptOut},n),platform:e.diagnosticPlatformData};var n}function y(e){a.logger&&a.logger.debug(je.debugPostingDiagnosticEvent(e)),o.sendEvents(e,d,!0).then((function(){})).catch((function(){}))}function w(){var e,r;y((e=(new Date).getTime(),r=t({kind:l?"diagnostic-combined":"diagnostic",id:u,creationDate:e},g.getProps()),l&&(r=t(t({},r),h())),g.reset(e),r)),c=setTimeout(w,v),s=(new Date).getTime(),l&&function(){if(n.isEnabled()){var e=t({},g.getProps());n.set(f,JSON.stringify(e))}}()}function b(){var n=t({},e.diagnosticSdkData);return a.wrapperName&&(n.wrapperName=a.wrapperName),a.wrapperVersion&&(n.wrapperVersion=a.wrapperVersion),n}return m.start=function(){l?function(e){if(!n.isEnabled())return e(!1);n.get(f).then((function(n){if(n)try{var t=JSON.parse(n);g.setProps(t),s=t.dataSinceDate}catch(e){}e(!0)})).catch((function(){e(!1)}))}((function(e){if(e){var n=(s||0)+v,t=(new Date).getTime();t>=n?w():c=setTimeout(w,n-t)}else 0===Math.floor(4*Math.random())?w():c=setTimeout(w,v)})):(y(t({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}(i,D,j,O,k,w,P):null,C=Ve(i,w,k,j),A=w.eventProcessor||function(e,n,t){var r,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,u={},c=a||Ae(e,t,n),l=U(n.eventsUrl,"/events/bulk/"+t),f=Fe(),d=qe(n),v=n.inlineUsersInEvents,g=n.samplingInterval,m=n.eventCapacity,h=n.flushInterval,y=n.logger,w=[],b=0,k=!1,E=!1;function D(){return 0===g||0===Math.floor(Math.random()*g)}function O(e){return!!e.debugEventsUntilDate&&e.debugEventsUntilDate>b&&e.debugEventsUntilDate>(new Date).getTime()}function S(e){var n=q({},e);return"alias"===e.kind||(v||"identify"===e.kind?n.user=d.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate)),n}function P(e){w.length<m?(w.push(e),E=!1):(E||(E=!0,y.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")),o&&o.incrementDroppedEvents())}return u.enqueue=function(e){if(!k){var n=!1,t=!1;if(f.summarizeEvent(e),"feature"===e.kind?D()&&(n=!!e.trackEvents,t=O(e)):n=D(),n&&P(S(e)),t){var r=q({},e,{kind:"debug"});r.user=d.filterUser(r.user),delete r.trackEvents,delete r.debugEventsUntilDate,P(r)}}},u.flush=function(){if(k)return Promise.resolve();var e=w,n=f.getSummary();return f.clearSummary(),n&&(n.kind="summary",e.push(n)),o&&o.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(w=[],y.debug(Pe(e.length)),c.sendEvents(e,l).then((function(e){e&&(e.serverTime&&(b=e.serverTime),p(e.status)||(k=!0),e.status>=400&&L((function(){i.maybeReportError(new s(de(e.status,"event posting","some events were dropped")))})))})))},u.start=function(){r=setTimeout((function e(){u.flush(),r=setTimeout(e,h)}),h)},u.stop=function(){clearTimeout(r)},u}(i,w,k,j,h,O),F=ze(i,w,k),z={},M=w.streaming,J=!1,$=!1,H=!0,K=w.stateProvider,B=function(e,n){var t,r={setUser:function(e){var r=t&&T(t);(t=V(e))&&n&&n(T(t),r)},getUser:function(){return t?T(t):null}};return r}(0,(function(e,n){(function(e){K||e&&W({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})})(e),!w.autoAliasingOptOut&&n&&n.anonymous&&e&&!e.anonymous&&re(e,n)})),G=Me(D),X=D.isEnabled()?new _e(D,k,E,B):null;function W(e){if(k&&!(K&&K.enqueueEvent&&K.enqueueEvent(e))){if("alias"!==e.kind){if(!e.user)return void(H&&(m.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"),H=!1));H=!1}!b||$||i.isDoNotTrack()||(m.debug(Se(e.kind)),A.enqueue(e))}}function Q(e,n,t,r){var o=B.getUser(),i=new Date,a={kind:"feature",key:e,user:o,value:n?n.value:null,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()};o&&o.anonymous&&(a.contextKind=ne(o));var u=z[e];u&&(a.version=u.flagVersion?u.flagVersion:u.version,a.trackEvents=u.trackEvents,a.debugEventsUntilDate=u.debugEventsUntilDate),(r||u&&u.trackReason)&&n&&(a.reason=n.reason),W(a)}function Z(e,n,t,r){var o;if(z&&_(z,e)&&z[e]&&!z[e].deleted){var i=z[e];o=ee(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&&Q(e,o,n,r),o}function ee(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function ne(e){return e.anonymous?"anonymousUser":"user"}function re(e,n){K||e&&n&&W({kind:"alias",key:e.key,contextKind:ne(e),previousKey:n.key,previousContextKind:ne(n),creationDate:(new Date).getTime()})}function ie(){if(l=!0,B.getUser()){var e=function(e){try{return JSON.parse(e)}catch(e){return void h.maybeReportError(new g("Invalid data received from LaunchDarkly; connection may have been interrupted"))}};C.connect(B.getUser(),E,{ping:function(){m.debug("received ping message from stream");var e=B.getUser();F.fetchFlagSettings(e,E).then((function(n){R(e,B.getUser())&&ce(n||{})})).catch((function(e){h.maybeReportError(new v(ue(e)))}))},put:function(n){var t=e(n.data);t&&(m.debug("received streaming update for all flags"),ce(t))},patch:function(n){var t=e(n.data);if(t){var r=z[t.key];if(!r||!r.version||!t.version||r.version<t.version){m.debug(ke(t.key));var o={},i=q({},t);delete i.key,z[t.key]=i;var a=ee(i);o[t.key]=r?{previous:r.value,current:a}:{current:a},fe(o)}else m.debug(Ee(t.key))}},delete:function(n){var t=e(n.data);if(t)if(!z[t.key]||z[t.key].version<t.version){m.debug(De(t.key));var r={};z[t.key]&&!z[t.key].deleted&&(r[t.key]={previous:z[t.key].value}),z[t.key]={version:t.version,deleted:!0},fe(r)}else m.debug(Oe(t.key))}})}}function se(){l&&(C.disconnect(),l=!1)}function ce(e){var n={};if(!e)return Promise.resolve();for(var r in z)_(z,r)&&z[r]&&(e[r]&&!R(e[r].value,z[r].value)?n[r]={previous:z[r].value,current:ee(e[r])}:e[r]&&!e[r].deleted||(n[r]={previous:z[r].value}));for(var o in e)_(e,o)&&e[o]&&(!z[o]||z[o].deleted)&&(n[o]={current:ee(e[o])});return z=t({},e),fe(n).catch((function(){}))}function fe(e){var n=Object.keys(e);if(n.length>0){var t={};n.forEach((function(n){var r=e[n].current,o=r?r.value:void 0,i=e[n].previous;h.emit("change:"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}})),h.emit("change",t),h.emit("internal-change",z),w.sendEventsOnlyForVariation||K||n.forEach((function(n){Q(n,e[n].current)}))}return u&&X?X.saveFlags(z):Promise.resolve()}function ve(){var e=M||d&&void 0===M;e&&!l?ie():!e&&l&&se(),I&&I.setStreaming(e)}function ge(e){return"change"===e||"change:"===e.substr(0,"change".length+1)}if("string"==typeof w.bootstrap&&"LOCALSTORAGE"===w.bootstrap.toUpperCase()&&(X?u=!0:m.warn(te())),"object"===r(w.bootstrap)&&(z=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&m.warn(le()),!1===e.$valid&&m.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var r={};return n.forEach((function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};t&&t[n]?o=q(o,t[n]):o.version=0,r[n]=o}})),r}(w.bootstrap)),K){var pe=K.getInitialState();pe?me(pe):K.on("init",me),K.on("update",(function(e){e.user&&B.setUser(e.user),e.flags&&ce(e.flags)}))}else(e?G.validateUser(n).then((function(e){return B.setUser(e),"object"===r(w.bootstrap)?he():u?X.loadFlags().then((function(e){return null==e?(z={},F.fetchFlagSettings(B.getUser(),E).then((function(e){return ce(e||{})})).then(he).catch((function(e){ye(new v(ue(e)))}))):(z=e,L(he),F.fetchFlagSettings(B.getUser(),E).then((function(e){return ce(e)})).catch((function(e){return h.maybeReportError(e)})))})):F.fetchFlagSettings(B.getUser(),E).then((function(e){z=e||{},he()})).catch((function(e){z={},ye(e)}))})):Promise.reject(new c(ae()))).catch(ye);function me(e){k=e.environment,B.setUser(e.user),z=t({},e.flags),L(he)}function he(){m.info("LaunchDarkly client initialized"),J=!0,ve(),y.signalSuccess()}function ye(e){y.signalFailure(e)}return{client:{waitForInitialization:function(){return y.getInitializationPromise()},waitUntilReady:function(){return y.getReadyPromise()},identify:function(e,n,t){return $?x(Promise.resolve({}),t):K?(m.warn("identify() has no effect here; it must be called on the main client instance"),x(Promise.resolve(N(z)),t)):x((u&&X?X.clearFlags():Promise.resolve()).then((function(){return G.validateUser(e)})).then((function(e){return F.fetchFlagSettings(e,n).then((function(t){var r=N(t);return B.setUser(e),E=n,t?ce(t).then((function(){return r})):r}))})).then((function(e){return l&&ie(),e})).catch((function(e){return h.maybeReportError(e),Promise.reject(e)})),t)},getUser:function(){return B.getUser()},variation:function(e,n){return Z(e,n,!0,!1).value},variationDetail:function(e,n){return Z(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){i.customEventFilter&&!i.customEventFilter(e)&&m.warn(oe(e));var r=B.getUser(),o={kind:"custom",key:e,user:r,url:i.getCurrentUrl(),creationDate:(new Date).getTime()};r&&r.anonymous&&(o.contextKind=ne(r)),null!=n&&(o.data=n),null!=t&&(o.metricValue=t),W(o)}else h.maybeReportError(new f(oe(e)))},alias:re,on:function(e,n,t){ge(e)?(d=!0,J&&ve(),h.on(e,n,t)):h.on.apply(h,arguments)},off:function(e){if(h.off.apply(h,arguments),ge(e)){var n=!1;h.getEvents().forEach((function(e){ge(e)&&h.getEventListenerCount(e)>0&&(n=!0)})),n||(d=!1,l&&void 0===M&&se())}},setStreaming:function(e){var n=null===e?void 0:e;n!==M&&(M=n,ve())},flush:function(e){return x(b?A.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!z)return e;for(var n in z)_(z,n)&&!z[n].deleted&&(e[n]=Z(n,null,!w.sendEventsOnlyForVariation).value);return e},close:function(e){if($)return x(Promise.resolve(),e);var n=function(){$=!0,z={}};return x(Promise.resolve().then((function(){if(se(),I&&I.stop(),b)return A.stop(),A.flush()})).then(n).catch(n),e)}},options:w,emitter:h,ident:B,logger:m,requestor:F,start:function(){b&&(I&&I.start(),A.start())},enqueueEvent:W,getFlagsInternal:function(){return z},getEnvironmentId:function(){return k},internalChangeEventName:"internal-change"}}function Be(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function Ge(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?Be(Object(t),!0).forEach((function(n){Xe(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):Be(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function Xe(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}var We=Object.freeze({__proto__:null,commonBasicLogger:Q,createConsoleLogger:Y,get errors(){return m},initialize:Ke,messages:je,utils:z,version:"3.7.0"}).commonBasicLogger;var Qe=function(e){return We(Ge({destination:console.log},e))};var Ye={promise:Promise.resolve({status:200,header:function(){return null},body:null})};function Ze(e,n,t,r,o){if(o&&!function(){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}())return Ye;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),Ye;var u,s=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)}));return{promise:s,cancel:function(){u=!0,i.abort()}}}function en(e){var n,t={synchronousFlush:!1};if(window.XMLHttpRequest){var r=e&&e.disableSyncEventPost;t.httpRequest=function(e,n,o,i){var a=t.synchronousFlush&!r;return t.synchronousFlush=!1,Ze(e,n,o,i,a)}}t.httpAllowsPost=function(){return void 0===n&&(n=!!window.XMLHttpRequest&&"withCredentials"in new window.XMLHttpRequest),n},t.httpFallbackPing=function(e){(new window.Image).src=e};var o,i=e&&e.eventUrlTransformer;t.getCurrentUrl=function(){return i?i(window.location.href):window.location.href},t.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&&(t.localStorage={get:function(e){return new Promise((function(n){n(window.localStorage.getItem(e))}))},set:function(e,n){return new Promise((function(t){window.localStorage.setItem(e,n),t()}))},clear:function(e){return new Promise((function(n){window.localStorage.removeItem(e),n()}))}})}catch(e){t.localStorage=null}if(e&&e.useReport&&"function"==typeof window.EventSourcePolyfill&&window.EventSourcePolyfill.supportedOptions&&window.EventSourcePolyfill.supportedOptions.method?(t.eventSourceAllowsReport=!0,o=window.EventSourcePolyfill):(t.eventSourceAllowsReport=!1,o=window.EventSource),window.EventSource){var a=3e5;t.eventSourceFactory=function(e,n){var t=Ge(Ge({},{heartbeatTimeout:a,silentTimeout:a,skipDefaultHeaders:!0}),n);return new o(e,t)},t.eventSourceIsActive=function(e){return e.readyState===window.EventSource.OPEN||e.readyState===window.EventSource.CONNECTING}}return t.userAgent="JSClient",t.version="2.23.0",t.diagnosticSdkData={name:"js-client-sdk",version:"2.23.0"},t.diagnosticPlatformData={name:"JS"},t.diagnosticUseCombinedEvent=!0,t}var nn=e=>{if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")};function tn(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("^"+nn(e.url)+"/?$");break;case"canonical":i=a,o=new RegExp("^"+nn(e.url)+"/?$");break;case"substring":i=a,o=new RegExp(".*"+nn(e.substring)+".*$");break;case"regex":i=a,o=new RegExp(e.pattern);break;default:return!1}return o.test(i)}function rn(e,n){for(var t={},r=null,o=[],i=0;i<e.length;i++)for(var a=e[i],u=a.urls||[],s=0;s<u.length;s++)if(tn(u[s],window.location.href,window.location.search,window.location.hash)){"pageview"===a.kind?n("pageview",a):(o.push(a),n("click_pageview",a));break}return o.length>0&&(r=function(e){for(var t=function(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&&u.length>0;){for(var s=0;s<u.length;s++)o===u[s]&&t.push(i);o=o.parentNode}return t}(e,o),r=0;r<t.length;r++)n("click",t[r])},document.addEventListener("click",r)),t.dispose=function(){document.removeEventListener("click",r)},t}function on(e,n){var t,r;function o(){r&&r.dispose(),t&&t.length&&(r=rn(t,i))}function i(n,t){var r=e.ident.getUser(),o={kind:n,key:t.key,data:null,url:window.location.href,user:r,creationDate:(new Date).getTime()};return r&&r.anonymous&&(o.contextKind="anonymousUser"),"click"===n&&(o.selector=t.selector),e.enqueueEvent(o)}return e.requestor.fetchJSON("/sdk/goals/"+e.getEnvironmentId()).then((function(e){e&&e.length>0&&(r=rn(t=e,i),function(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)}(300,o)),n()})).catch((function(t){e.emitter.maybeReportError(new m.LDUnexpectedResponseError((t&&t.message,t.message))),n()})),{}}var an="goalsReady",un={fetchGoals:{default:!0},hash:{type:"string"},eventProcessor:{type:"object"},eventUrlTransformer:{type:"function"},disableSyncEventPost:{default:!1}};function sn(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=en(t),o=Ke(e,n,t,r,un),i=o.client,a=o.options,u=o.emitter,s=new Promise((function(e){var n=u.on(an,(function(){u.off(an,n),e()}))}));i.waitUntilGoalsReady=function(){return s},a.fetchGoals?on(o,(function(){return u.emit(an)})):u.emit(an),"complete"!==document.readyState?window.addEventListener("load",o.start):o.start();var c=function(){r.synchronousFlush=!0,i.flush().catch((function(){})),r.synchronousFlush=!1};return window.addEventListener("beforeunload",c),window.addEventListener("unload",c),i}var cn=Qe,ln=Y,fn="2.23.0";var dn={initialize:function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return console&&console.warn&&console.warn(je.deprecated("default export","named LDClient export")),sn(e,n,t)},version:fn};e.basicLogger=cn,e.createConsoleLogger=ln,e.default=dn,e.initialize=sn,e.version=fn,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).LDClient={})}(this,(function(e){"use strict";function n(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function t(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(n){o(e,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))}))}return e}function r(e){return(r="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})(e)}function o(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function i(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var r,o,i=[],a=!0,u=!1;try{for(t=t.call(e);!(a=(r=t.next()).done)&&(i.push(r.value),!n||i.length!==n);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==t.return||t.return()}finally{if(u)throw o}}return i}}(e,n)||u(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e){return function(e){if(Array.isArray(e))return c(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||u(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,n){if(e){if("string"==typeof e)return c(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?c(e,n):void 0}}function c(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function s(e){function n(e,n){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=n}return n.prototype=new Error,n.prototype.name=e,n.prototype.constructor=n,n}var l=s("LaunchDarklyUnexpectedResponseError"),f=s("LaunchDarklyInvalidEnvironmentIdError"),d=s("LaunchDarklyInvalidUserError"),v=s("LaunchDarklyInvalidEventKeyError"),g=s("LaunchDarklyInvalidArgumentError"),p=s("LaunchDarklyFlagFetchError"),m=s("LaunchDarklyInvalidDataError");function h(e){return!(e>=400&&e<500)||400===e||408===e||429===e}for(var y=Object.freeze({__proto__:null,LDUnexpectedResponseError:l,LDInvalidEnvironmentIdError:f,LDInvalidUserError:d,LDInvalidEventKeyError:v,LDInvalidArgumentError:g,LDFlagFetchError:p,LDInvalidDataError:m,isHttpErrorRecoverable:h}),w=[],b=[],k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",E=0,D=k.length;E<D;++E)w[E]=k[E],b[k.charCodeAt(E)]=E;function O(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(w[(o=r)>>18&63]+w[o>>12&63]+w[o>>6&63]+w[63&o]);return i.join("")}b["-".charCodeAt(0)]=62,b["_".charCodeAt(0)]=63;var S=Array.isArray,P=Object.keys,U=Object.prototype.hasOwnProperty,I=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function j(e,n){return(e.endsWith("/")?e.substring(0,e.length-1):e)+(n.startsWith("/")?"":"/")+n}function T(e){return function(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(O(e,i,i+16383>a?a:i+16383));return 1===r?(n=e[t-1],o.push(w[n>>2]+w[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(w[n>>10]+w[n>>4&63]+w[n<<2&63]+"=")),o.join("")}(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(unescape(encodeURIComponent(e))))}function R(e){return T(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function C(e){return JSON.parse(JSON.stringify(e))}function L(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=S(n),u=S(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 c=n instanceof Date,s=t instanceof Date;if(c!=s)return!1;if(c&&s)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=P(n);if((o=d.length)!==P(t).length)return!1;for(r=o;0!=r--;)if(!U.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 x(e){setTimeout(e,0)}function A(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 F(e){var n={};for(var t in e)z(e,t)&&(n[t]={value:e[t],version:0});return n}function N(e){var n={};for(var t in e)z(e,t)&&(n[t]=e[t].value);return n}function q(e,n){for(var t,r=n.slice(0),o=[],i=e;r.length>0;){for(t=[];i>0;){var a=r.shift();if(!a)break;(i-=R(JSON.stringify(a)).length)<0&&t.length>0?r.unshift(a):t.push(a)}i=e,o.push(t)}return o}function _(e){var n=e.version||"3.8.1";return e.userAgent+"/"+n}function V(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return n.reduce((function(e,n){return t(t({},e),n)}),{})}function z(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function M(e){if(!e)return e;var n;for(var r in I){var o=I[r],i=e[o];void 0!==i&&"string"!=typeof i&&((n=n||t({},e))[o]=String(i))}return n||e}for(var J=Object.freeze({__proto__:null,appendUrlPath:j,btoa:T,base64URLEncode:R,clone:C,deepEquals:L,onNextTick:x,wrapPromiseCallback:A,transformValuesToVersionedValues:F,transformVersionedValuesToValues:N,chunkUserEventsForUrl:q,getLDUserAgentString:_,extend:V,objectHasOwnProperty:z,sanitizeUser:M}),$=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}(),H=[],K=0;K<256;++K)H[K]=(K+256).toString(16).substr(1);var B,G,X=0,W=0,Q=function(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||B,a=void 0!==e.clockseq?e.clockseq:G;if(null==i||null==a){var u=$();null==i&&(i=B=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=G=16383&(u[6]<<8|u[7]))}var c=void 0!==e.msecs?e.msecs:(new Date).getTime(),s=void 0!==e.nsecs?e.nsecs:W+1,l=c-X+(s-W)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||c>X)&&void 0===e.nsecs&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");X=c,W=s,G=a;var f=(1e4*(268435455&(c+=122192928e5))+s)%4294967296;o[r++]=f>>>24&255,o[r++]=f>>>16&255,o[r++]=f>>>8&255,o[r++]=255&f;var d=c/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||function(e,n){var t=n||0,r=H;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("")}(o)},Y=["debug","info","warn","error","none"];function Z(e,n){if(e&&e.destination&&"function"!=typeof e.destination)throw new Error("destination for basicLogger was set to a non-function");function t(e){return function(n){console&&console[e]&&console[e].call(console,n)}}var r=e&&e.destination?[e.destination,e.destination,e.destination,e.destination]:[t("log"),t("info"),t("warn"),t("error")],o=!(!e||!e.destination),i=e&&void 0!==e.prefix&&null!==e.prefix?e.prefix:"[LaunchDarkly] ",u=1;if(e&&e.level)for(var c=0;c<Y.length;c++)Y[c]===e.level&&(u=c);function s(e,t,u){if(!(u.length<1)){var c,s=o?t+": "+i:i;if(1!==u.length&&n){var l=a(u);l[0]=s+l[0],c=n.apply(void 0,a(l))}else c=s+u[0];try{r[e](c)}catch(e){console&&console.log&&console.log("[LaunchDarkly] Configured logger's "+t+" method threw an exception: "+e)}}}for(var l={},f=function(e){var n=Y[e];if("none"!==n)if(e<u)l[n]=function(){};else{var t=e;l[n]=function(){s(t,n,arguments)}}},d=0;d<Y.length;d++)f(d);return l}function ee(e,n){return Z({level:e,prefix:n})}function ne(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var te=" Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initializing-the-client for instructions on SDK initialization.",re=function(e){return'Expected application/json content type but got "'+e+'"'},oe=function(e){return"local storage is unavailable: "+ne(e)},ie=function(e){return"network error"+(e?" ("+e+")":"")},ae=function(e){return'Custom event "'+e+'" does not exist'},ue=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+te},ce=function(){return"No environment/client-side ID was specified."+te},se=function(e){return"Error fetching flag settings: "+ne(e)},le=function(){return"No user specified."+te},fe=function(){return"Invalid user specified."+te},de=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+te},ve=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},ge=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(h(e)?t:"giving up permanently")},pe=function(){return"Cannot make HTTP requests in this environment."+te},me=function(e){return"Opening stream connection to "+e},he=function(e,n){return"Error on stream connection: "+ne(e)+", will continue retrying every "+n+" milliseconds."},ye=function(e){return'Ignoring unknown config option "'+e+'"'},we=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},be=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},ke=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},Ee=function(e){return"polling for feature flags at "+e},De=function(e){return'received streaming update for flag "'+e+'"'},Oe=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},Se=function(e){return'received streaming deletion for flag "'+e+'"'},Pe=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},Ue=function(e){return'enqueueing "'+e+'" event'},Ie=function(e){return"sending "+e+" events"},je=function(e){return'Config option "'.concat(e,'" must only contain letters, numbers, ., _ or -.')},Te=function(e,n){return'an inspector: "'.concat(n,'" of an invalid type (').concat(e,") was configured")},Re=function(e,n){return'an inspector: "'.concat(n,'" of type: "').concat(e,'" generated an exception')},Ce=function(e){return'Value of "'.concat(e,'" was longer than 64 characters and was discarded.')},Le=Object.freeze({__proto__:null,clientInitialized:function(){return"LaunchDarkly client initialized"},clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},eventWithoutUser:function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"},invalidContentType:re,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:oe,networkError:ie,unknownCustomEventKey:ae,environmentNotFound:ue,environmentNotSpecified:ce,errorFetchingFlags:se,userNotSpecified:le,invalidUser:fe,invalidData:function(){return"Invalid data received from LaunchDarkly; connection may have been interrupted"},bootstrapOldFormat:de,bootstrapInvalid:function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated:ve,httpErrorMessage:ge,httpUnavailable:pe,identifyDisabled:function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing:function(){return"Closing stream connection"},streamConnecting:me,streamError:he,unknownOption:ye,wrongOptionType:we,wrongOptionTypeBoolean:be,optionBelowMinimum:ke,debugPolling:Ee,debugStreamPing:function(){return"received ping message from stream"},debugStreamPut:function(){return"received streaming update for all flags"},debugStreamPatch:De,debugStreamPatchIgnored:Oe,debugStreamDelete:Se,debugStreamDeleteIgnored:Pe,debugEnqueueingEvent:Ue,debugPostingEvents:Ie,debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"},invalidTagValue:je,invalidInspector:Te,inspectorMethodError:Re,tagValueTooLong:Ce}),xe={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},application:{validator:function(e,n,t){var r={};return n.id&&(r.id=Fe("".concat(e,".id"),n.id,t)),n.version&&(r.version=Fe("".concat(e,".version"),n.version,t)),r}},inspectors:{default:[]}},Ae=/^(\w|\.|-)+$/;function Fe(e,n,t){if("string"==typeof n&&n.match(Ae)){if(!(n.length>64))return n;t.warn(Ce(e))}else t.warn(je(e))}function Ne(e,n,t,o){var i=V({logger:{default:o}},xe,t),a={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null,allowFrequentDuplicateEvents:void 0};function u(e){x((function(){n&&n.maybeReportError(new g(e))}))}var c=V({},e||{});return function(e){var n=e;Object.keys(a).forEach((function(e){if(void 0!==n[e]){var t=a[e];o&&o.warn(ve(e,t)),t&&(void 0===n[t]&&(n[t]=n[e]),delete n[e])}}))}(c),function(e){Y.forEach((function(n){if("none"!==n&&(!e[n]||"function"!=typeof e[n]))throw new Error("Provided logger instance must support logger."+n+"(...) method")}))}((c=function(e){var n=V({},e),t=function(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var n=r(e);return"boolean"===n||"string"===n||"number"===n||"function"===n?n:"object"}};return Object.keys(e).forEach((function(r){var a=e[r];if(null!=a){var c=i[r];if(void 0===c)u(ye(r));else{var s=c.type||t(c.default),l=c.validator;if(l){var f=l(r,e[r],o);void 0!==f?n[r]=f:delete n[r]}else if("any"!==s){var d=s.split("|"),v=t(a);d.indexOf(v)<0?"boolean"===s?(n[r]=!!a,u(be(r,v))):(u(we(r,s,v)),n[r]=c.default):"number"===v&&void 0!==c.minimum&&a<c.minimum&&(u(ke(r,a,c.minimum)),n[r]=c.minimum)}}}})),n}(c=function(e){var n=V({},e);return Object.keys(i).forEach((function(e){void 0!==n[e]&&null!==n[e]||(n[e]=i[e]&&i[e].default)})),n}(c))).logger),c}function qe(e){var n={};return e&&(e.application&&void 0!==e.application.id&&null!==e.application.id&&(n["application-id"]=[e.application.id]),e.application&&void 0!==e.application.version&&null!==e.application.id&&(n["application-version"]=[e.application.version])),n}function _e(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":_(e)};n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName);var r=qe(n),o=Object.keys(r);return o.length&&(t["x-launchdarkly-tags"]=o.sort().flatMap((function(e){return Array.isArray(r[e])?r[e].sort().map((function(n){return"".concat(e,"/").concat(n)})):["".concat(e,"/").concat(r[e])]})).join(" ")),t}function Ve(e,n){return n&&n.requestHeaderTransform?n.requestHeaderTransform(t({},e)):e}function ze(e,n,t){var r="/a/"+n+".gif",o=V({"Content-Type":"application/json"},_e(e,t)),i=e.httpFallbackPing,a={sendChunk:function(n,a,u,c){var s=JSON.stringify(n),l=u?null:Q();return c?function n(r){var i=u?o:V({},o,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":l});return e.httpRequest("POST",a,Ve(i,t),s).promise.then((function(e){if(e)return e.status>=400&&h(e.status)&&r?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 r?n(!1):Promise.reject()}))}(!0).catch((function(){})):(i&&i(a+r+"?d="+R(s)),Promise.resolve())},sendEvents:function(n,t,r){if(!e.httpRequest)return Promise.resolve();var o,i=e.httpAllowsPost();o=i?[n]:q(2e3-t.length,n);for(var u=[],c=0;c<o.length;c++)u.push(a.sendChunk(o[c],t,r,i));return Promise.all(u)}};return a}function Me(){var e={},n=0,t=0,r={};return e.summarizeEvent=function(e){if("feature"===e.kind){var o=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),i=r[o];i?i.count=i.count+1:r[o]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===n||e.creationDate<n)&&(n=e.creationDate),e.creationDate>t&&(t=e.creationDate)}},e.getSummary=function(){var e={},o=!0;for(var i in r){var a=r[i],u=e[a.key];u||(u={default:a.default,counters:[]},e[a.key]=u);var c={value:a.value,count:a.count};void 0!==a.variation&&null!==a.variation&&(c.variation=a.variation),a.version?c.version=a.version:c.unknown=!0,u.counters.push(c),o=!1}return o?null:{startDate:n,endDate:t,features:e}},e.clearSummary=function(){n=0,t=0,r={}},e}function Je(e){var n={},t=e.allAttributesPrivate,r=e.privateAttributeNames||[],o={key:!0,custom:!0,anonymous:!0},i={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;var n=e.privateAttributeNames||[],a=function(e,i){return Object.keys(e).reduce((function(a,u){var c=a;return i(u)&&(function(e){return!o[e]&&(t||-1!==n.indexOf(e)||-1!==r.indexOf(e))}(u)?c[1][u]=!0:c[0][u]=e[u]),c}),[{},{}])},u=a(e,(function(e){return i[e]})),c=u[0],s=u[1];if(e.custom){var l=a(e.custom,(function(){return!0}));c.custom=l[0],s=V({},s,l[1])}var f=Object.keys(s);return f.length&&(f.sort(),c.privateAttrs=f),c},n}function $e(e,n,t,r){var o={};function i(){var e="",o=r.getUser();return o&&(e=t||T(JSON.stringify(o))),"ld:"+n+":"+e}return o.loadFlags=function(){return e.get(i()).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=F(n):delete n.$schema}return n}catch(e){return o.clearFlags().then((function(){return null}))}}))},o.saveFlags=function(n){var t=V({},n,{$schema:1});return e.set(i(),JSON.stringify(t))},o.clearFlags=function(){return e.clear(i())},o}function He(e,n,t,r){var o,i=n.streamUrl,a=n.logger,u={},c=j(i,"/eval/"+t),s=n.useReport,l=n.evaluationReasons,f=n.streamReconnectDelay,d=_e(e,n),v=!1,g=null,p=null,m=null,h=null,y=null;function w(e){v||(a.warn(he(e,f)),v=!0),D(!1),E(),b(f)}function b(e){p||(e?p=setTimeout(k,e):k())}function k(){var r;p=null;var u="",f={headers:d,readTimeoutMillis:3e5};if(e.eventSourceFactory){for(var v in null!=h&&(u="h="+h),s?e.eventSourceAllowsReport?(r=c,f.method="REPORT",f.headers["Content-Type"]="application/json",f.body=JSON.stringify(m)):(r=j(i,"/ping/"+t),u=""):r=c+"/"+R(JSON.stringify(m)),f.headers=Ve(f.headers,n),l&&(u=u+(u?"&":"")+"withReasons=true"),r=r+(u?"?":"")+u,E(),a.info(me(r)),o=(new Date).getTime(),g=e.eventSourceFactory(r,f),y)z(y,v)&&g.addEventListener(v,y[v]);g.onerror=w}}function E(){g&&(a.info("Closing stream connection"),g.close(),g=null)}function D(e){o&&r&&r.recordStreamInit(o,!e,(new Date).getTime()-o),o=null}return u.connect=function(e,n,t){m=e,h=n,y={};var r=function(e){y[e]=function(n){v=!1,D(!0),t[e]&&t[e](n)}};for(var o in t||{})r(o);b()},u.disconnect=function(){clearTimeout(p),p=null,E()},u.isConnected=function(){return!!(g&&e.eventSourceIsActive&&e.eventSourceIsActive(g))},u}function Ke(e,n,t){var r=n.baseUrl,o=n.useReport,i=n.evaluationReasons,a=n.logger,u={},c={};function s(t,r){if(!e.httpRequest)return new Promise((function(e,n){n(new p(pe()))}));var o=r?"REPORT":"GET",i=_e(e,n);r&&(i["Content-Type"]="application/json");var a=c[t];a||(a=function(e){var n,t,r,o,i={addPromise:function(i,a){n=i,t&&t(),t=a,i.then((function(t){n===i&&(r(t),e&&e())}),(function(t){n===i&&(o(t),e&&e())}))}};return i.resultPromise=new Promise((function(e,n){r=e,o=n})),i}((function(){delete c[t]})),c[t]=a);var u=e.httpRequest(o,t,Ve(i,n),r),s=u.promise.then((function(e){if(200===e.status){if(e.header("content-type")&&"application/json"===e.header("content-type").substring(0,"application/json".length))return JSON.parse(e.body);var n=re(e.header("content-type")||"");return Promise.reject(new p(n))}return Promise.reject(function(e){return 404===e.status?new f(ue()):new p(se(e.statusText||String(e.status)))}(e))}),(function(e){return Promise.reject(new p(ie(e)))}));return a.addPromise(s,(function(){u.cancel&&u.cancel()})),a.resultPromise}return u.fetchJSON=function(e){return s(j(r,e),null)},u.fetchFlagSettings=function(e,n){var u,c,l,f="";return o?(c=[r,"/sdk/evalx/",t,"/user"].join(""),l=JSON.stringify(e)):(u=R(JSON.stringify(e)),c=[r,"/sdk/evalx/",t,"/users/",u].join("")),n&&(f="h="+n),i&&(f=f+(f?"&":"")+"withReasons=true"),c=c+(f?"?":"")+f,a.debug(Ee(c)),s(c,l)},u}function Be(e){var n={validateUser:function(n){if(!n)return Promise.reject(new d(le()));var t=C(n);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?e.get("ld:$anonUserId").then((function(n){if(n)return t.key=n,t;var r=Q();return t.key=r,function(n){return e.set("ld:$anonUserId",n)}(r).then((function(){return t}))})):Promise.reject(new d(fe()))}};return n}var Ge=Object.freeze({__proto__:null,baseOptionDefs:xe,validate:Ne,getTags:qe}).baseOptionDefs,Xe=J.appendUrlPath,We=function(e){var n={diagnosticId:Q()};return e&&(n.sdkKeySuffix=e.length>6?e.substring(e.length-6):e),n},Qe={flagUsed:"flag-used",flagDetailsChanged:"flag-details-changed",flagDetailChanged:"flag-detail-changed",clientIdentityChanged:"client-identity-changed"};function Ye(e,n){var t,r={},i=(o(t={},Qe.flagUsed,[]),o(t,Qe.flagDetailsChanged,[]),o(t,Qe.flagDetailChanged,[]),o(t,Qe.clientIdentityChanged,[]),t);return(null==e?void 0:e.map((function(e){return function(e,n){var t=!1,r={type:e.type,name:e.name,method:function(){try{e.method.apply(e,arguments)}catch(e){t||(t=!0,n.warn(Re(r.type,r.name)))}}};return r}(e,n)}))).forEach((function(e){Object.prototype.hasOwnProperty.call(i,e.type)?i[e.type].push(e):n.warn(Te(e.type,e.name))})),r.hasListeners=function(e){var n;return null===(n=i[e])||void 0===n?void 0:n.length},r.onFlagUsed=function(e,n,t){i[Qe.flagUsed].length&&x((function(){i[Qe.flagUsed].forEach((function(r){return r.method(e,n,t)}))}))},r.onFlags=function(e){i[Qe.flagDetailsChanged].length&&x((function(){i[Qe.flagDetailsChanged].forEach((function(n){return n.method(e)}))}))},r.onFlagChanged=function(e,n){i[Qe.flagDetailChanged].length&&x((function(){i[Qe.flagDetailChanged].forEach((function(t){return t.method(e,n)}))}))},r.onIdentityChanged=function(e){i[Qe.clientIdentityChanged].length&&x((function(){i[Qe.clientIdentityChanged].forEach((function(n){return n.method(e)}))}))},r}function Ze(e,n,o,a,u){var c,s,d,g=o&&o.logger?o.logger:u&&u.logger&&u.logger.default||ee("warn"),y=function(e){var n={},t={};return n.on=function(e,n,r){t[e]=t[e]||[],t[e]=t[e].concat({handler:n,context:r})},n.off=function(e,n,r){if(t[e])for(var o=0;o<t[e].length;o++)t[e][o].handler===n&&t[e][o].context===r&&(t[e]=t[e].slice(0,o).concat(t[e].slice(o+1)))},n.emit=function(e){if(t[e])for(var n=t[e].slice(0),r=0;r<n.length;r++)n[r].handler.apply(n[r].context,Array.prototype.slice.call(arguments,1))},n.getEvents=function(){return Object.keys(t)},n.getEventListenerCount=function(e){return t[e]?t[e].length:0},n.maybeReportError=function(n){n&&(t.error?this.emit("error",n):(e||console).error(n.message))},n}(g),w=function(e){var n=!1,t=!1,r=null,o=null,i=new Promise((function(n){e.on("ready",(function t(){e.off("ready",t),n()}))})).catch((function(){}));return{getInitializationPromise:function(){return o||(n?Promise.resolve():t?Promise.reject(r):o=new Promise((function(n,t){e.on("initialized",(function t(){e.off("initialized",t),n()})),e.on("failed",(function n(r){e.off("failed",n),t(r)}))})))},getReadyPromise:function(){return i},signalSuccess:function(){n||t||(n=!0,e.emit("initialized"),e.emit("ready"))},signalFailure:function(o){n||t||(t=!0,r=o,e.emit("failed",o),e.emit("ready")),e.maybeReportError(o)}}}(y),b=Ne(o,y,u,g),k=Ye(b.inspectors,g),E=b.sendEvents,D=e,O=b.hash,S=function(e,n){var t={},r=!1,o=function(e){r||(r=!0,n.warn(oe(e)))};return t.isEnabled=function(){return!!e},t.get=function(n){return new Promise((function(t){e?e.get(n).then(t).catch((function(e){o(e),t(void 0)})):t(void 0)}))},t.set=function(n,t){return new Promise((function(r){e?e.set(n,t).then((function(){return r(!0)})).catch((function(e){o(e),r(!1)})):r(!1)}))},t.clear=function(n){return new Promise((function(t){e?e.clear(n).then((function(){return t(!0)})).catch((function(e){o(e),t(!1)})):t(!1)}))},t}(a.localStorage,g),P=ze(a,D,b),U=b.sendEvents&&!b.diagnosticOptOut,I=U?We(D):null,T=U?function(e){var n,t,r,o;function i(e){n=e,t=0,r=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}}((new Date).getTime()):null,R=U?function(e,n,r,o,i,a,u){var c,s,l=!!e.diagnosticUseCombinedEvent,f="ld:"+i+":$diagnostics",d=Xe(a.eventsUrl,"/events/diagnostic/"+i),v=a.diagnosticRecordingInterval,g=r,p=!!a.streaming,m={};function h(){return{sdk:b(),configuration:(n={customBaseURI:a.baseUrl!==Ge.baseUrl.default,customStreamURI:a.streamUrl!==Ge.streamUrl.default,customEventsURI:a.eventsUrl!==Ge.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,sendEventsOnlyForVariation:!!a.sendEventsOnlyForVariation,autoAliasingOptOut:!!a.autoAliasingOptOut},n),platform:e.diagnosticPlatformData};var n}function y(e){a.logger&&a.logger.debug(Le.debugPostingDiagnosticEvent(e)),o.sendEvents(e,d,!0).then((function(){})).catch((function(){}))}function w(){var e,r;y((e=(new Date).getTime(),r=t({kind:l?"diagnostic-combined":"diagnostic",id:u,creationDate:e},g.getProps()),l&&(r=t(t({},r),h())),g.reset(e),r)),s=setTimeout(w,v),c=(new Date).getTime(),l&&function(){if(n.isEnabled()){var e=t({},g.getProps());n.set(f,JSON.stringify(e))}}()}function b(){var n=t({},e.diagnosticSdkData);return a.wrapperName&&(n.wrapperName=a.wrapperName),a.wrapperVersion&&(n.wrapperVersion=a.wrapperVersion),n}return m.start=function(){l?function(e){if(!n.isEnabled())return e(!1);n.get(f).then((function(n){if(n)try{var t=JSON.parse(n);g.setProps(t),c=t.dataSinceDate}catch(e){}e(!0)})).catch((function(){e(!1)}))}((function(e){if(e){var n=(c||0)+v,t=(new Date).getTime();t>=n?w():s=setTimeout(w,n-t)}else 0===Math.floor(4*Math.random())?w():s=setTimeout(w,v)})):(y(t({kind:"diagnostic-init",id:u,creationDate:g.getProps().dataSinceDate},h())),s=setTimeout(w,v))},m.stop=function(){s&&clearTimeout(s)},m.setStreaming=function(e){p=e},m}(a,S,T,P,D,b,I):null,F=He(a,b,D,T),q=b.eventProcessor||function(e,n,t){var r,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,u={},c=a||ze(e,t,n),s=j(n.eventsUrl,"/events/bulk/"+t),f=Me(),d=Je(n),v=n.inlineUsersInEvents,g=n.samplingInterval,p=n.eventCapacity,m=n.flushInterval,y=n.logger,w=[],b=0,k=!1,E=!1;function D(){return 0===g||0===Math.floor(Math.random()*g)}function O(e){return!!e.debugEventsUntilDate&&e.debugEventsUntilDate>b&&e.debugEventsUntilDate>(new Date).getTime()}function S(e){var n=V({},e);return"alias"===e.kind||(v||"identify"===e.kind?n.user=d.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate)),n}function P(e){w.length<p?(w.push(e),E=!1):(E||(E=!0,y.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")),o&&o.incrementDroppedEvents())}return u.enqueue=function(e){if(!k){var n=!1,t=!1;if(f.summarizeEvent(e),"feature"===e.kind?D()&&(n=!!e.trackEvents,t=O(e)):n=D(),n&&P(S(e)),t){var r=V({},e,{kind:"debug"});r.user=d.filterUser(r.user),delete r.trackEvents,delete r.debugEventsUntilDate,P(r)}}},u.flush=function(){if(k)return Promise.resolve();var e=w,n=f.getSummary();return f.clearSummary(),n&&(n.kind="summary",e.push(n)),o&&o.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(w=[],y.debug(Ie(e.length)),c.sendEvents(e,s).then((function(e){e&&(e.serverTime&&(b=e.serverTime),h(e.status)||(k=!0),e.status>=400&&x((function(){i.maybeReportError(new l(ge(e.status,"event posting","some events were dropped")))})))})))},u.start=function(){r=setTimeout((function e(){u.flush(),r=setTimeout(e,m)}),m)},u.stop=function(){clearTimeout(r)},u}(a,b,D,T,y,P),_=Ke(a,b,D),J={},$=b.streaming,H=!1,K=!1,B=!0,G=b.stateProvider,X=function(e,n){var t,r={setUser:function(e){var r=t&&C(t);(t=M(e))&&n&&n(C(t),r)},getUser:function(){return t?C(t):null}};return r}(0,(function(e,n){(function(e){G||e&&Y({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})})(e),!b.autoAliasingOptOut&&n&&n.anonymous&&e&&!e.anonymous&&le(e,n),k.hasListeners(Qe.clientIdentityChanged)&&k.onIdentityChanged(X.getUser())})),W=Be(S),Q=S.isEnabled()?new $e(S,D,O,X):null;function Y(e){if(D&&!(G&&G.enqueueEvent&&G.enqueueEvent(e))){if("alias"!==e.kind){if(!e.user)return void(B&&(g.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"),B=!1));B=!1}!E||K||a.isDoNotTrack()||(g.debug(Ue(e.kind)),q.enqueue(e))}}function Z(e,n){k.hasListeners(Qe.flagDetailChanged)&&k.onFlagChanged(e.key,ie(n))}function ne(){k.hasListeners(Qe.flagDetailsChanged)&&k.onFlags(Object.entries(J).map((function(e){var n=i(e,2);return{key:n[0],detail:ie(n[1])}})).reduce((function(e,n){return e[n.key]=n.detail,e}),{}))}function te(e,n,t,r){var o=X.getUser(),i=new Date,a={kind:"feature",key:e,user:o,value:n?n.value:null,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()};o&&o.anonymous&&(a.contextKind=ue(o));var u=J[e];u&&(a.version=u.flagVersion?u.flagVersion:u.version,a.trackEvents=u.trackEvents,a.debugEventsUntilDate=u.debugEventsUntilDate),(r||u&&u.trackReason)&&n&&(a.reason=n.reason),Y(a)}function re(e,n,t,r,o){var i;if(J&&z(J,e)&&J[e]&&!J[e].deleted){var a=J[e];i=ie(a),null!==a.value&&void 0!==a.value||(i.value=n)}else i={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&te(e,i,n,r),o||function(e,n){k.hasListeners(Qe.flagUsed)&&k.onFlagUsed(e,n,X.getUser())}(e,i),i}function ie(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function ue(e){return e.anonymous?"anonymousUser":"user"}function le(e,n){G||e&&n&&Y({kind:"alias",key:e.key,contextKind:ue(e),previousKey:n.key,previousContextKind:ue(n),creationDate:(new Date).getTime()})}function fe(){if(s=!0,X.getUser()){var e=function(e){try{return JSON.parse(e)}catch(e){return void y.maybeReportError(new m("Invalid data received from LaunchDarkly; connection may have been interrupted"))}};F.connect(X.getUser(),O,{ping:function(){g.debug("received ping message from stream");var e=X.getUser();_.fetchFlagSettings(e,O).then((function(n){L(e,X.getUser())&&pe(n||{})})).catch((function(e){y.maybeReportError(new p(se(e)))}))},put:function(n){var t=e(n.data);t&&(g.debug("received streaming update for all flags"),pe(t))},patch:function(n){var t=e(n.data);if(t){var r=J[t.key];if(!r||!r.version||!t.version||r.version<t.version){g.debug(De(t.key));var o={},i=V({},t);delete i.key,J[t.key]=i;var a=ie(i);o[t.key]=r?{previous:r.value,current:a}:{current:a},me(o),Z(t,i)}else g.debug(Oe(t.key))}},delete:function(n){var t=e(n.data);if(t)if(!J[t.key]||J[t.key].version<t.version){g.debug(Se(t.key));var r={};J[t.key]&&!J[t.key].deleted&&(r[t.key]={previous:J[t.key].value}),J[t.key]={version:t.version,deleted:!0},Z(t,J[t.key]),me(r)}else g.debug(Pe(t.key))}})}}function ve(){s&&(F.disconnect(),s=!1)}function pe(e){var n={};if(!e)return Promise.resolve();for(var r in J)z(J,r)&&J[r]&&(e[r]&&!L(e[r].value,J[r].value)?n[r]={previous:J[r].value,current:ie(e[r])}:e[r]&&!e[r].deleted||(n[r]={previous:J[r].value}));for(var o in e)z(e,o)&&e[o]&&(!J[o]||J[o].deleted)&&(n[o]={current:ie(e[o])});return J=t({},e),ne(),me(n).catch((function(){}))}function me(e){var n=Object.keys(e);if(n.length>0){var t={};n.forEach((function(n){var r=e[n].current,o=r?r.value:void 0,i=e[n].previous;y.emit("change:"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}})),y.emit("change",t),y.emit("internal-change",J),b.sendEventsOnlyForVariation||G||n.forEach((function(n){te(n,e[n].current)}))}return c&&Q?Q.saveFlags(J):Promise.resolve()}function he(){var e=$||d&&void 0===$;e&&!s?fe():!e&&s&&ve(),R&&R.setStreaming(e)}function ye(e){return"change"===e||"change:"===e.substr(0,"change".length+1)}if("string"==typeof b.bootstrap&&"LOCALSTORAGE"===b.bootstrap.toUpperCase()&&(Q?c=!0:g.warn(oe())),"object"===r(b.bootstrap)&&(J=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&g.warn(de()),!1===e.$valid&&g.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var r={};return n.forEach((function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};t&&t[n]?o=V(o,t[n]):o.version=0,r[n]=o}})),r}(b.bootstrap)),G){var we=G.getInitialState();we?be(we):G.on("init",be),G.on("update",(function(e){e.user&&X.setUser(e.user),e.flags&&pe(e.flags)}))}else(e?W.validateUser(n).then((function(e){return X.setUser(e),"object"===r(b.bootstrap)?ke():c?Q.loadFlags().then((function(e){return null==e?(J={},_.fetchFlagSettings(X.getUser(),O).then((function(e){return pe(e||{})})).then(ke).catch((function(e){Ee(new p(se(e)))}))):(J=e,x(ke),_.fetchFlagSettings(X.getUser(),O).then((function(e){return pe(e)})).catch((function(e){return y.maybeReportError(e)})))})):_.fetchFlagSettings(X.getUser(),O).then((function(e){J=e||{},ne(),ke()})).catch((function(e){J={},Ee(e)}))})):Promise.reject(new f(ce()))).catch(Ee);function be(e){D=e.environment,X.setUser(e.user),J=t({},e.flags),x(ke)}function ke(){g.info("LaunchDarkly client initialized"),H=!0,he(),w.signalSuccess()}function Ee(e){w.signalFailure(e)}return{client:{waitForInitialization:function(){return w.getInitializationPromise()},waitUntilReady:function(){return w.getReadyPromise()},identify:function(e,n,t){return K?A(Promise.resolve({}),t):G?(g.warn("identify() has no effect here; it must be called on the main client instance"),A(Promise.resolve(N(J)),t)):A((c&&Q?Q.clearFlags():Promise.resolve()).then((function(){return W.validateUser(e)})).then((function(e){return _.fetchFlagSettings(e,n).then((function(t){var r=N(t);return X.setUser(e),O=n,t?pe(t).then((function(){return r})):r}))})).then((function(e){return s&&fe(),e})).catch((function(e){return y.maybeReportError(e),Promise.reject(e)})),t)},getUser:function(){return X.getUser()},variation:function(e,n){return re(e,n,!0,!1,!1).value},variationDetail:function(e,n){return re(e,n,!0,!0,!1)},track:function(e,n,t){if("string"==typeof e){a.customEventFilter&&!a.customEventFilter(e)&&g.warn(ae(e));var r=X.getUser(),o={kind:"custom",key:e,user:r,url:a.getCurrentUrl(),creationDate:(new Date).getTime()};r&&r.anonymous&&(o.contextKind=ue(r)),null!=n&&(o.data=n),null!=t&&(o.metricValue=t),Y(o)}else y.maybeReportError(new v(ae(e)))},alias:le,on:function(e,n,t){ye(e)?(d=!0,H&&he(),y.on(e,n,t)):y.on.apply(y,arguments)},off:function(e){if(y.off.apply(y,arguments),ye(e)){var n=!1;y.getEvents().forEach((function(e){ye(e)&&y.getEventListenerCount(e)>0&&(n=!0)})),n||(d=!1,s&&void 0===$&&ve())}},setStreaming:function(e){var n=null===e?void 0:e;n!==$&&($=n,he())},flush:function(e){return A(E?q.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!J)return e;for(var n in J)z(J,n)&&!J[n].deleted&&(e[n]=re(n,null,!b.sendEventsOnlyForVariation,!1,!0).value);return e},close:function(e){if(K)return A(Promise.resolve(),e);var n=function(){K=!0,J={}};return A(Promise.resolve().then((function(){if(ve(),R&&R.stop(),E)return q.stop(),q.flush()})).then(n).catch(n),e)}},options:b,emitter:y,ident:X,logger:g,requestor:_,start:function(){E&&(R&&R.start(),q.start())},enqueueEvent:Y,getFlagsInternal:function(){return J},getEnvironmentId:function(){return D},internalChangeEventName:"internal-change"}}Object.freeze(Qe);function en(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function nn(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?en(Object(t),!0).forEach((function(n){tn(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):en(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function tn(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}var rn=Object.freeze({__proto__:null,commonBasicLogger:Z,createConsoleLogger:ee,get errors(){return y},initialize:Ze,messages:Le,utils:J,version:"3.8.1"}).commonBasicLogger;var on=function(e){return rn(nn({destination:console.log},e))};var an={promise:Promise.resolve({status:200,header:function(){return null},body:null})};function un(e,n,t,r,o){if(o&&!function(){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}())return an;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),an;var u,c=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)}));return{promise:c,cancel:function(){u=!0,i.abort()}}}function cn(e){var n,t={synchronousFlush:!1};if(window.XMLHttpRequest){var r=e&&e.disableSyncEventPost;t.httpRequest=function(e,n,o,i){var a=t.synchronousFlush&!r;return t.synchronousFlush=!1,un(e,n,o,i,a)}}t.httpAllowsPost=function(){return void 0===n&&(n=!!window.XMLHttpRequest&&"withCredentials"in new window.XMLHttpRequest),n},t.httpFallbackPing=function(e){(new window.Image).src=e};var o,i=e&&e.eventUrlTransformer;t.getCurrentUrl=function(){return i?i(window.location.href):window.location.href},t.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&&(t.localStorage={get:function(e){return new Promise((function(n){n(window.localStorage.getItem(e))}))},set:function(e,n){return new Promise((function(t){window.localStorage.setItem(e,n),t()}))},clear:function(e){return new Promise((function(n){window.localStorage.removeItem(e),n()}))}})}catch(e){t.localStorage=null}if(e&&e.useReport&&"function"==typeof window.EventSourcePolyfill&&window.EventSourcePolyfill.supportedOptions&&window.EventSourcePolyfill.supportedOptions.method?(t.eventSourceAllowsReport=!0,o=window.EventSourcePolyfill):(t.eventSourceAllowsReport=!1,o=window.EventSource),window.EventSource){var a=3e5;t.eventSourceFactory=function(e,n){var t=nn(nn({},{heartbeatTimeout:a,silentTimeout:a,skipDefaultHeaders:!0}),n);return new o(e,t)},t.eventSourceIsActive=function(e){return e.readyState===window.EventSource.OPEN||e.readyState===window.EventSource.CONNECTING}}return t.userAgent="JSClient",t.version="2.24.0",t.diagnosticSdkData={name:"js-client-sdk",version:"2.24.0"},t.diagnosticPlatformData={name:"JS"},t.diagnosticUseCombinedEvent=!0,t}var sn=e=>{if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")};function ln(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("^"+sn(e.url)+"/?$");break;case"canonical":i=a,o=new RegExp("^"+sn(e.url)+"/?$");break;case"substring":i=a,o=new RegExp(".*"+sn(e.substring)+".*$");break;case"regex":i=a,o=new RegExp(e.pattern);break;default:return!1}return o.test(i)}function fn(e,n){for(var t={},r=null,o=[],i=0;i<e.length;i++)for(var a=e[i],u=a.urls||[],c=0;c<u.length;c++)if(ln(u[c],window.location.href,window.location.search,window.location.hash)){"pageview"===a.kind?n("pageview",a):(o.push(a),n("click_pageview",a));break}return o.length>0&&(r=function(e){for(var t=function(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&&u.length>0;){for(var c=0;c<u.length;c++)o===u[c]&&t.push(i);o=o.parentNode}return t}(e,o),r=0;r<t.length;r++)n("click",t[r])},document.addEventListener("click",r)),t.dispose=function(){document.removeEventListener("click",r)},t}function dn(e,n){var t,r;function o(){r&&r.dispose(),t&&t.length&&(r=fn(t,i))}function i(n,t){var r=e.ident.getUser(),o={kind:n,key:t.key,data:null,url:window.location.href,user:r,creationDate:(new Date).getTime()};return r&&r.anonymous&&(o.contextKind="anonymousUser"),"click"===n&&(o.selector=t.selector),e.enqueueEvent(o)}return e.requestor.fetchJSON("/sdk/goals/"+e.getEnvironmentId()).then((function(e){e&&e.length>0&&(r=fn(t=e,i),function(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)}(300,o)),n()})).catch((function(t){e.emitter.maybeReportError(new y.LDUnexpectedResponseError((t&&t.message,t.message))),n()})),{}}var vn="goalsReady",gn={fetchGoals:{default:!0},hash:{type:"string"},eventProcessor:{type:"object"},eventUrlTransformer:{type:"function"},disableSyncEventPost:{default:!1}};function pn(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=cn(t),o=Ze(e,n,t,r,gn),i=o.client,a=o.options,u=o.emitter,c=new Promise((function(e){var n=u.on(vn,(function(){u.off(vn,n),e()}))}));i.waitUntilGoalsReady=function(){return c},a.fetchGoals?dn(o,(function(){return u.emit(vn)})):u.emit(vn),"complete"!==document.readyState?window.addEventListener("load",o.start):o.start();var s=function(){r.synchronousFlush=!0,i.flush().catch((function(){})),r.synchronousFlush=!1};return window.addEventListener("beforeunload",s),window.addEventListener("unload",s),i}var mn=on,hn=ee,yn="2.24.0";var wn={initialize:function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return console&&console.warn&&console.warn(Le.deprecated("default export","named LDClient export")),pn(e,n,t)},version:yn};e.basicLogger=mn,e.createConsoleLogger=hn,e.default=wn,e.initialize=pn,e.version=yn,Object.defineProperty(e,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=ldclient.min.js.map