launchdarkly-js-client-sdk
Advanced tools
Comparing version 2.13.0 to 2.14.0
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _typeof2="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};function createCustomError(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 LDUnexpectedResponseError=createCustomError("LaunchDarklyUnexpectedResponseError"),LDInvalidEnvironmentIdError=createCustomError("LaunchDarklyInvalidEnvironmentIdError"),LDInvalidUserError=createCustomError("LaunchDarklyInvalidUserError"),LDInvalidEventKeyError=createCustomError("LaunchDarklyInvalidEventKeyError"),LDInvalidArgumentError=createCustomError("LaunchDarklyInvalidArgumentError"),LDFlagFetchError=createCustomError("LaunchDarklyFlagFetchError");function isHttpErrorRecoverable(e){return!(e>=400&&e<500)||400===e||408===e||429===e}for(var errors=Object.freeze({LDUnexpectedResponseError:LDUnexpectedResponseError,LDInvalidEnvironmentIdError:LDInvalidEnvironmentIdError,LDInvalidUserError:LDInvalidUserError,LDInvalidEventKeyError:LDInvalidEventKeyError,LDInvalidArgumentError:LDInvalidArgumentError,LDFlagFetchError:LDFlagFetchError,isHttpErrorRecoverable:isHttpErrorRecoverable}),fromByteArray_1=fromByteArray,lookup=[],revLookup=[],code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;i<len;++i)lookup[i]=code[i],revLookup[code.charCodeAt(i)]=i;function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,n,t){for(var r,o=[],i=n;i<t;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(encodeChunk(e,i,i+16383>a?a:i+16383));return 1===r?(n=e[t-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(lookup[n>>10]+lookup[n>>4&63]+lookup[n<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var _typeof="function"==typeof Symbol&&"symbol"==_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)},isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==(void 0===n?"undefined":_typeof(n))&&"object"==(void 0===t?"undefined":_typeof(t))){var r,o,i,a=isArray(n),u=isArray(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,d=t instanceof RegExp;if(l!=d)return!1;if(l&&d)return n.toString()==t.toString();var v=keyList(n);if((o=v.length)!==keyList(t).length)return!1;for(r=o;0!=r--;)if(!hasProp.call(t,v[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=v[r]],t[i]))return!1;return!0}return n!=n&&t!=t},_extends=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function btoa(e){var n=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(n))}function stringToBytes(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,n){return fastDeepEqual(e,n)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(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 transformValuesToVersionedValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function chunkUserEventsForUrl(e,n){for(var t=n.slice(0),r=[],o=e,i=void 0;t.length>0;){for(i=[];o>0;){var a=t.shift();if(!a)break;(o-=base64URLEncode(JSON.stringify(a)).length)<0&&i.length>0?t.unshift(a):i.push(a)}o=e,r.push(i)}return r}function getLDUserAgentString(e){var n=e.version||"2.13.0";return e.userAgent+"/"+n}function getLDHeaders(e){return{"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)}}function extend(){for(var e=arguments.length,n=Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return _extends({},e,n)},{})}function sanitizeUser(e){if(!e)return e;var n=void 0;for(var t in userAttrsToStringify){var r=userAttrsToStringify[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[r]=String(o))}return n||e}var utils=Object.freeze({btoa:btoa,base64URLEncode:base64URLEncode,clone:clone,deepEquals:deepEquals,onNextTick:onNextTick,wrapPromiseCallback:wrapPromiseCallback,transformValuesToVersionedValues:transformValuesToVersionedValues,transformVersionedValuesToValues:transformVersionedValuesToValues,chunkUserEventsForUrl:chunkUserEventsForUrl,getLDUserAgentString:getLDUserAgentString,getLDHeaders:getLDHeaders,extend:extend,sanitizeUser:sanitizeUser}),MAX_URL_LENGTH=2e3;function EventSender(e,n,t,r){var o=n+"/events/bulk/"+t,i=n+"/a/"+t+".gif",a={};function u(e){(new window.Image).src=e}function s(n,t){var a=r||u,s=JSON.stringify(n);return t?function n(t){var r=extend({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},getLDHeaders(e));return e.httpRequest("POST",o,r,s).promise.then(function(e){if(e)return e.status>=400&&isHttpErrorRecoverable(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(){}):(a(i+"?d="+base64URLEncode(s)),Promise.resolve())}return a.sendEvents=function(t){if(!e.httpRequest)return Promise.resolve();var r,o=e.httpAllowsPost();r=o?[t]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,t);for(var i=[],a=0;a<r.length;a++)i.push(s(r[a],o));return Promise.all(i)},a}function EventSummarizer(){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 UserFilter(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=extend({},c,l[1])}var d=Object.keys(c);return d.length&&(d.sort(),s.privateAttrs=d),s},n}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",clientNotReady=function(){return"LaunchDarkly client is not ready"},eventWithoutUser=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"},invalidContentType=function(e){return'Expected application/json content type but got "'+e+'"'},invalidKey=function(){return"Event key must be a string"},localStorageUnavailable=function(){return"localStorage is unavailable"},localStorageUnavailableForUserId=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},networkError=function(e){return"network error"+(e?" ("+e+")":"")},unknownCustomEventKey=function(e){return'Custom event "'+e+'" does not exist'},environmentNotFound=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+docLink},environmentNotSpecified=function(){return"No environment/client-side ID was specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+errorString(e)},userNotSpecified=function(){return"No user specified."+docLink},invalidUser=function(){return"Invalid user specified."+docLink},bootstrapOldFormat=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+docLink},bootstrapInvalid=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated=function(e,n){return'[LaunchDarkly] "'+e+'" is deprecated, please use "'+n+'"'},httpErrorMessage=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?t:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e){return"Error on stream connection: "+errorString(e)},debugPolling=function(e){return"polling for feature flags at "+e},debugStreamPing=function(){return"received ping message from stream"},debugStreamPut=function(){return"received streaming update for all flags"},debugStreamPatch=function(e){return'received streaming update for flag "'+e+'"'},debugStreamPatchIgnored=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},debugStreamDelete=function(e){return'received streaming deletion for flag "'+e+'"'},debugStreamDeleteIgnored=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},debugEnqueueingEvent=function(e){return'enqueueing "'+e+'" event'},debugPostingEvents=function(e){return"sending "+e+" events"},messages=Object.freeze({clientInitialized:clientInitialized,clientNotReady:clientNotReady,eventWithoutUser:eventWithoutUser,invalidContentType:invalidContentType,invalidKey:invalidKey,localStorageUnavailable:localStorageUnavailable,localStorageUnavailableForUserId:localStorageUnavailableForUserId,networkError:networkError,unknownCustomEventKey:unknownCustomEventKey,environmentNotFound:environmentNotFound,environmentNotSpecified:environmentNotSpecified,errorFetchingFlags:errorFetchingFlags,userNotSpecified:userNotSpecified,invalidUser:invalidUser,bootstrapOldFormat:bootstrapOldFormat,bootstrapInvalid:bootstrapInvalid,deprecated:deprecated,httpErrorMessage:httpErrorMessage,httpUnavailable:httpUnavailable,identifyDisabled:identifyDisabled,streamClosing:streamClosing,streamConnecting:streamConnecting,streamError:streamError,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents});function EventProcessor(e,n,t){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,i={},a=o||EventSender(e,n.eventsUrl,t),u=EventSummarizer(),s=UserFilter(n),c=n.inlineUsersInEvents,l=n.samplingInterval,d=n.flushInterval,v=n.logger,f=[],g=0,p=!1,m=void 0;function y(){return 0===l||0===Math.floor(Math.random()*l)}return i.enqueue=function(e){if(!p){var n,t=!1,r=!1;if(u.summarizeEvent(e),"feature"===e.kind?y()&&(t=!!e.trackEvents,r=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>g&&n.debugEventsUntilDate>(new Date).getTime()):t=y(),t&&f.push(function(e){var n=extend({},e);return c||"identify"===e.kind?n.user=s.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),r){var o=extend({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,f.push(o)}}},i.flush=function(){if(p)return Promise.resolve();var e=f,n=u.getSummary();return u.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(f=[],v.debug(debugPostingEvents(e.length)),a.sendEvents(e).then(function(e){e&&(e.serverTime&&(g=e.serverTime),isHttpErrorRecoverable(e.status)||(p=!0),e.status>=400&&onNextTick(function(){r.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},i.start=function(){m=setTimeout(function e(){i.flush(),m=setTimeout(e,d)},d)},i.stop=function(){clearTimeout(m)},i}function EventEmitter(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=0;n<t[e].length;n++)t[e][n].handler.apply(t[e][n].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}function Store(e,n,t,r,o){var i={};function a(){var e="",o=r.getUser();return o&&(e=t||btoa(JSON.stringify(o))),"ld:"+n+":"+e}return i.loadFlags=function(){return e.get(a()).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=transformValuesToVersionedValues(n):delete n.$schema}return n}catch(e){return i.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i.saveFlags=function(n){var t=extend({},n,{$schema:1});return e.set(a(),JSON.stringify(t)).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i.clearFlags=function(){return e.clear(a()).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i}function Stream(e,n,t,r){var o=n.streamUrl,i=n.logger,a={},u=o+"/eval/"+t,s=n.useReport,c=n.evaluationReasons,l=n.streamReconnectDelay,d=null,v=null,f=null,g=null;function p(e){i.warn(streamError(e)),h(),m(l)}function m(e){v||(e?v=setTimeout(y,e):y())}function y(){v=null;var n=void 0,a="",l={};if(e.eventSourceFactory){for(var m in null!=r&&(a="h="+r),s?e.eventSourceAllowsReport?(n=u,l.method="REPORT",l.headers={"Content-Type":"application/json"},l.body=JSON.stringify(f)):(n=o+"/ping/"+t,a=""):n=u+"/"+base64URLEncode(JSON.stringify(f)),c&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,h(),i.info(streamConnecting(n)),d=e.eventSourceFactory(n,l),g)g.hasOwnProperty(m)&&d.addEventListener(m,g[m]);d.onerror=p}}function h(){d&&(i.info(streamClosing()),d.close(),d=null)}return a.connect=function(e,n){f=e,g=n,m()},a.disconnect=function(){clearTimeout(v),v=null,h()},a.isConnected=function(){return!!(d&&e.eventSourceIsActive&&e.eventSourceIsActive(d))},a}function promiseCoalescer(e){var n=void 0,t=void 0,r=void 0,o=void 0,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}var json="application/json";function getResponseError(e){return 404===e.status?new LDInvalidEnvironmentIdError(environmentNotFound()):new LDFlagFetchError(errorFetchingFlags(e.statusText||String(e.status)))}function Requestor(e,n,t){var r=n.baseUrl,o=n.useReport,i=n.evaluationReasons,a=n.sendLDHeaders,u=n.logger,s={},c={};function l(n,t){if(!e.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var r=t?"REPORT":"GET",o=a?getLDHeaders(e):{};t&&(o["Content-Type"]="application/json");var i=c[n];i||(i=promiseCoalescer(function(){delete c[n]}),c[n]=i);var u=e.httpRequest(r,n,o,t),s=u.promise.then(function(e){if(200===e.status){if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(json))return JSON.parse(e.body);var n=invalidContentType(e.header("content-type")||"");return Promise.reject(new LDFlagFetchError(n))}return Promise.reject(getResponseError(e))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return i.addPromise(s,function(){u.cancel&&u.cancel()}),i.resultPromise}return s.fetchJSON=function(e){return l(r+e,null)},s.fetchFlagSettings=function(e,n){var a=void 0,s=void 0,c="",d=void 0;return o?(s=[r,"/sdk/evalx/",t,"/user"].join(""),d=JSON.stringify(e)):(a=base64URLEncode(JSON.stringify(e)),s=[r,"/sdk/evalx/",t,"/users/",a].join("")),n&&(c="h="+n),i&&(c=c+(c?"&":"")+"withReasons=true"),s=s+(c?"?":"")+c,u.debug(debugPolling(s)),l(s,d)},s}function Identity(e,n){var t={},r=void 0;return t.setUser=function(e){(r=sanitizeUser(e))&&n&&n(clone(r))},t.getUser=function(){return r?clone(r):null},e&&t.setUser(e),t}function createCommonjsModule(e,n){return e(n={exports:{}},n.exports),n.exports}for(var rngBrowser=createCommonjsModule(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}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var t=n||0,r=byteToHex;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("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||_nodeId,a=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==i||null==a){var u=rngBrowser();null==i&&(i=_nodeId=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=_clockseq=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,l=s-_lastMSecs+(c-_lastNSecs)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>_lastMSecs)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=s,_lastNSecs=c,_clockseq=a;var d=(1e4*(268435455&(s+=122192928e5))+c)%4294967296;o[r++]=d>>>24&255,o[r++]=d>>>16&255,o[r++]=d>>>8&255,o[r++]=255&d;var v=s/4294967296*1e4&268435455;o[r++]=v>>>8&255,o[r++]=255&v,o[r++]=v>>>24&15|16,o[r++]=v>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var f=0;f<6;++f)o[r+f]=i[f];return n||bytesToUuid_1(o)}var v1_1=v1,ldUserIdKey="ld:$anonUserId";function UserValidator(e,n){var t={validateUser:function(t){if(!t)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var r=clone(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(t){if(t)return r.key=t,r;var o=v1_1();return r.key=o,function(t){return e?e.set(ldUserIdKey,t).catch(function(){n.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(o).then(function(){return r})}):Promise.reject(new LDInvalidUserError(invalidUser()))}};return t}function validate(e,n,t,r){var o=extend({logger:r},{baseUrl:"https://app.launchdarkly.com",streamUrl:"https://clientstream.launchdarkly.com",eventsUrl:"https://events.launchdarkly.com",sendEvents:!0,sendLDHeaders:!0,inlineUsersInEvents:!1,allowFrequentDuplicateEvents:!1,sendEventsOnlyForVariation:!1,useReport:!1,evaluationReasons:!1,flushInterval:2e3,samplingInterval:0,streamReconnectDelay:1e3,allAttributesPrivate:!1,privateAttributeNames:[]},t),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames"};function a(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var u=extend({},e||{});return function(e){var n=u;Object.keys(i).forEach(function(e){if(void 0!==n[e]){var t=i[e];r.warn(deprecated(e,t)),void 0===n[t]&&(n[t]=n[e]),delete n[e]}})}(),u=function(e,n){var t=extend({},u);return Object.keys(n).forEach(function(e){void 0!==t[e]&&null!==t[e]||(t[e]=n[e])}),t}(0,o),(isNaN(u.flushInterval)||u.flushInterval<2e3)&&(u.flushInterval=2e3,a("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(u.samplingInterval)||u.samplingInterval<0)&&(u.samplingInterval=0,a("Invalid sampling interval configured. Sampling interval must be an integer >= 0.")),u}function createConsoleLogger(e){var n=0;e&&(n="none"===e?100:["debug","info","warn","error"].indexOf(e));var t={};function r(e,t,r){e>=n&&t(r)}return t.debug=function(e){return r(0,console.log,e)},t.info=function(e){return r(1,console.info,e)},t.warn=function(e){return r(2,console.warn,e)},t.error=function(e){return r(3,console.error,e)},t}var _typeof$1="function"==typeof Symbol&&"symbol"==_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)},readyEvent="ready",successEvent="initialized",failedEvent="failed",changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,t,r,o){var i=t&&t.logger?t.logger:o&&o.logger||createConsoleLogger("warn"),a=EventEmitter(i),u=validate(t,a,o,i),s=u.hash,c=u.sendEvents,l=e,d=Stream(r,u,l,s),v=u.eventProcessor||EventProcessor(r,u,l,a),f=Requestor(r,u,l),g={},p={},m=void 0,y=void 0,h=u.streaming,E=void 0,b=!1,w=!1,k=!0,S=u.stateProvider,U=Identity(null,function(e){S||e&&L({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),D=UserValidator(r.localStorage,i),P=void 0;function L(e){l&&(S&&S.enqueueEvent&&S.enqueueEvent(e)||(e.user?(k=!1,!c||w||r.isDoNotTrack()||(i.debug(debugEnqueueingEvent(e.kind)),v.enqueue(e))):k&&(i.warn(eventWithoutUser()),k=!1)))}function I(e,n,t){var r=U.getUser(),o=new Date,i=n?n.value:null;if(!u.allowFrequentDuplicateEvents){var a=JSON.stringify(i)+(r&&r.key?r.key:"")+e,s=g[a];if(s&&o-s<3e5)return;g[a]=o}var c={kind:"feature",key:e,user:r,value:i,variation:n?n.variationIndex:null,default:t,creationDate:o.getTime(),reason:n?n.reason:null},l=p[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),L(c)}function R(e,n,t){var r=void 0;if(p&&p.hasOwnProperty(e)&&p[e]&&!p[e].deleted){var o=p[e];r=T(o),null!==o.value&&void 0!==o.value||(r.value=n)}else r={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&I(e,r,n),r}function T(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function C(){y=!0,U.getUser()&&d.connect(U.getUser(),{ping:function(){i.debug(debugStreamPing()),f.fetchFlagSettings(U.getUser(),s).then(function(e){return x(e||{})}).catch(function(e){a.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var n=JSON.parse(e.data);i.debug(debugStreamPut()),x(n)},patch:function(e){var n=JSON.parse(e.data),t=p[n.key];if(!t||!t.version||!n.version||t.version<n.version){i.debug(debugStreamPatch(n.key));var r={},o=extend({},n);delete o.key,p[n.key]=o;var a=T(o);r[n.key]=t?{previous:t.value,current:a}:{current:a},N(r)}else i.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!p[n.key]||p[n.key].version<n.version){i.debug(debugStreamDelete(n.key));var t={};p[n.key]&&!p[n.key].deleted&&(t[n.key]={previous:p[n.key].value}),p[n.key]={version:n.version,deleted:!0},N(t)}else i.debug(debugStreamDeleteIgnored(n.key))}})}function F(){y&&(d.disconnect(),y=!1)}function x(e){var n={};if(!e)return Promise.resolve();for(var t in p)p.hasOwnProperty(t)&&p[t]&&(e[t]&&!deepEquals(e[t].value,p[t].value)?n[t]={previous:p[t].value,current:T(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:p[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!p[r]||p[r].deleted)&&(n[r]={current:T(e[r])});return p=Object.assign({},e),N(n).catch(function(){})}function N(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;a.emit(changeEvent+":"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}}),a.emit(changeEvent,t),a.emit(internalChangeEvent,p),u.sendEventsOnlyForVariation||S||n.forEach(function(n){I(n,e[n].current)})}return m&&P?P.saveFlags(p).catch(function(){return null}):Promise.resolve()}function O(){var e=h||E&&void 0===h;e&&!y?C():!e&&y&&F()}function A(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}r.localStorage&&(P=new Store(r.localStorage,l,s,U,i));var j=new Promise(function(e){var n=a.on(readyEvent,function(){a.off(readyEvent,n),e()})}),_=new Promise(function(e,n){var t=a.on(successEvent,function(){a.off(successEvent,t),e()}),r=a.on(failedEvent,function(e){a.off(failedEvent,r),n(e)})});if("string"==typeof u.bootstrap&&"LOCALSTORAGE"===u.bootstrap.toUpperCase()&&(P?m=!0:i.warn(localStorageUnavailable())),"object"===_typeof$1(u.bootstrap)&&(p=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&i.warn(bootstrapOldFormat()),!1===e.$valid&&i.warn(bootstrapInvalid());var r={};return n.forEach(function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};t&&t[n]?o=extend(o,t[n]):o.version=0,r[n]=o}}),r}(u.bootstrap)),S){var q=S.getInitialState();q?V(q):S.on("init",V),S.on("update",function(e){e.user&&U.setUser(e.user),e.flags&&x(e.flags)})}else(e?D.validateUser(n).then(function(e){return U.setUser(e),"object"===_typeof$1(u.bootstrap)?z():m?P.loadFlags().catch(function(){return null}).then(function(e){return null==e?(p={},f.fetchFlagSettings(U.getUser(),s).then(function(e){return x(e||{})}).then(z).catch(function(e){H(new LDFlagFetchError(errorFetchingFlags(e)))})):(p=e,onNextTick(z),f.fetchFlagSettings(U.getUser(),s).then(function(e){return x(e)}).catch(function(e){return a.maybeReportError(e)}))}):f.fetchFlagSettings(U.getUser(),s).then(function(e){p=e||{},z()}).catch(function(e){p={},H(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(function(e){return a.maybeReportError(e)});function V(e){l=e.environment,U.setUser(e.user),p=Object.assign({},e.flags),onNextTick(z)}function z(){i.info(clientInitialized()),b=!0,O(),a.emit(readyEvent),a.emit(successEvent)}function H(e){a.maybeReportError(e),a.emit(failedEvent,e),a.emit(readyEvent)}return{client:{waitForInitialization:function(){return _},waitUntilReady:function(){return j},identify:function(e,n,t){return w?wrapPromiseCallback(Promise.resolve({}),t):S?(i.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(p)),t)):wrapPromiseCallback((m&&P?P.clearFlags():Promise.resolve()).then(function(){return D.validateUser(e)}).then(function(e){return U.setUser(e)}).then(function(){return f.fetchFlagSettings(U.getUser(),n)}).then(function(e){var n=transformVersionedValuesToValues(e);return e?x(e).then(function(){return n}):n}).then(function(e){return y&&C(),e}).catch(function(e){return a.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return U.getUser()},variation:function(e,n){return R(e,n,!0).value},variationDetail:function(e,n){return R(e,n,!0)},track:function(e,n){"string"==typeof e?(r.customEventFilter&&!r.customEventFilter(e)&&i.warn(unknownCustomEventKey(e)),L({kind:"custom",key:e,data:n,user:U.getUser(),url:r.getCurrentUrl(),creationDate:(new Date).getTime()})):a.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,t){A(e)?(E=!0,b&&O(),a.on(e,n,t)):a.on.apply(a,arguments)},off:function(e){if(a.off.apply(a,arguments),A(e)){var n=!1;a.getEvents().forEach(function(e){A(e)&&a.getEventListenerCount(e)>0&&(n=!0)}),n||(E=!1,y&&void 0===h&&F())}},setStreaming:function(e){var n=null===e?void 0:e;n!==h&&(h=n,O())},flush:function(e){return wrapPromiseCallback(c?v.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!p)return e;for(var n in p)p.hasOwnProperty(n)&&(e[n]=R(n,null,!u.sendEventsOnlyForVariation).value);return e},close:function(e){if(w)return wrapPromiseCallback(Promise.resolve(),e);var n=function(){w=!0,p={}};return wrapPromiseCallback(Promise.resolve().then(function(){if(F(),c)return v.stop(),v.flush()}).then(n).catch(n),e)}},options:u,emitter:a,ident:U,logger:i,requestor:f,start:function(){c&&v.start()},enqueueEvent:L,getFlagsInternal:function(){return p},getEnvironmentId:function(){return l},internalChangeEventName:internalChangeEvent}}var version="2.13.0";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||{})t.hasOwnProperty(a)&&i.setRequestHeader(a,t[a]);if(o)return i.send(r),emptyResult;var u=void 0;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={pageIsClosing:!1};window.XMLHttpRequest&&(n.httpRequest=function(e,t,r,o){return newHttpRequest(e,t,r,o,n.pageIsClosing)});var t=void 0;n.httpAllowsPost=function(){return void 0===t&&(t=!!window.XMLHttpRequest&&"withCredentials"in new window.XMLHttpRequest),t};var r=e&&e.eventUrlTransformer;n.getCurrentUrl=function(){return r?r(window.location.href):window.location.href},n.isDoNotTrack=function(){var e=void 0;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&&(n.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){n.localStorage=null}var o=void 0;if(e&&e.useReport&&"function"==typeof window.EventSourcePolyfill&&window.EventSourcePolyfill.supportedOptions&&window.EventSourcePolyfill.supportedOptions.method?(n.eventSourceAllowsReport=!0,o=window.EventSourcePolyfill):(n.eventSourceAllowsReport=!1,o=window.EventSource),window.EventSource){n.eventSourceFactory=function(e,n){var t={heartbeatTimeout:3e5,silentTimeout:3e5,skipDefaultHeaders:!0},r=Object.assign({},t,n);return new o(e,r)},n.eventSourceIsActive=function(e){return e.readyState===window.EventSource.OPEN||e.readyState===window.EventSource.CONNECTING}}return n.userAgent="JSClient",n}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=n.replace(t,"").replace(r,""),i=void 0,a=void 0;switch(e.kind){case"exact":a=n,i=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"canonical":a=o,i=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"substring":a=o,i=new RegExp(".*"+escapeStringRegexp(e.substring)+".*$");break;case"regex":a=o,i=new RegExp(e.pattern);break;default:return!1}return i.test(a)}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&&u.length>0;){for(var s=0;s<u.length;s++)o===u[s]&&t.push(i);o=o.parentNode}return t}function GoalTracker(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(doesUrlMatch(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=findGoalsForClick(e,o),r=0;r<t.length;r++)n("click",t[r])},document.addEventListener("click",r)),t.dispose=function(){document.removeEventListener("click",r)},t}var locationWatcherInterval=300;function GoalManager(e,n){var t=void 0,r=void 0,o={};function i(){r&&r.dispose(),t&&t.length&&(r=GoalTracker(t,a))}function a(n,t){var r={kind:n,key:t.key,data:null,url:window.location.href,user:e.ident.getUser(),creationDate:(new Date).getTime()};return"click"===n&&(r.selector=t.selector),e.enqueueEvent(r)}return o.goalKeyExists=function(e){if(!t)return!0;for(var n=0;n<t.length;n++)if("custom"===t[n].kind&&t[n].key===e)return!0;return!1},e.requestor.fetchJSON("/sdk/goals/"+e.getEnvironmentId()).then(function(e){e&&e.length>0&&(r=GoalTracker(t=e,a),function(e,n){var t=window.location.href,r=void 0;function o(){(r=window.location.href)!==t&&(t=r,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)}(locationWatcherInterval,i)),n()}).catch(function(t){e.emitter.maybeReportError(new errors.LDUnexpectedResponseError((t&&t.message,t.message))),n()}),o}var goalsEvent="goalsReady",extraDefaults={fetchGoals:!0};function initialize$1(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=makeBrowserPlatform(t),o=initialize(e,n,t,r,extraDefaults),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()})});if(i.waitUntilGoalsReady=function(){return s},a.fetchGoals){var c=GoalManager(o,function(){return u.emit(goalsEvent)});r.customEventFilter=c.goalKeyExists}else u.emit(goalsEvent);return"complete"!==document.readyState?window.addEventListener("load",o.start):o.start(),window.addEventListener("beforeunload",function(){r.pageIsClosing=!0,i.close()}),i}var createConsoleLogger$1=createConsoleLogger,version$1=version;function deprecatedInitialize(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return console&&console.warn&&console.warn(messages.deprecated("default export","named LDClient export")),initialize$1(e,n,t)}var index={initialize:deprecatedInitialize,version:version$1};exports.initialize=initialize$1,exports.createConsoleLogger=createConsoleLogger$1,exports.version=version$1,exports.default=index; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _typeof2="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};function createCustomError(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 LDUnexpectedResponseError=createCustomError("LaunchDarklyUnexpectedResponseError"),LDInvalidEnvironmentIdError=createCustomError("LaunchDarklyInvalidEnvironmentIdError"),LDInvalidUserError=createCustomError("LaunchDarklyInvalidUserError"),LDInvalidEventKeyError=createCustomError("LaunchDarklyInvalidEventKeyError"),LDInvalidArgumentError=createCustomError("LaunchDarklyInvalidArgumentError"),LDFlagFetchError=createCustomError("LaunchDarklyFlagFetchError");function isHttpErrorRecoverable(e){return!(e>=400&&e<500)||400===e||408===e||429===e}for(var errors=Object.freeze({LDUnexpectedResponseError:LDUnexpectedResponseError,LDInvalidEnvironmentIdError:LDInvalidEnvironmentIdError,LDInvalidUserError:LDInvalidUserError,LDInvalidEventKeyError:LDInvalidEventKeyError,LDInvalidArgumentError:LDInvalidArgumentError,LDFlagFetchError:LDFlagFetchError,isHttpErrorRecoverable:isHttpErrorRecoverable}),fromByteArray_1=fromByteArray,lookup=[],revLookup=[],code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;i<len;++i)lookup[i]=code[i],revLookup[code.charCodeAt(i)]=i;function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,n,t){for(var r,o=[],i=n;i<t;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(encodeChunk(e,i,i+16383>a?a:i+16383));return 1===r?(n=e[t-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(lookup[n>>10]+lookup[n>>4&63]+lookup[n<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var _typeof="function"==typeof Symbol&&"symbol"==_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)},isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==(void 0===n?"undefined":_typeof(n))&&"object"==(void 0===t?"undefined":_typeof(t))){var r,o,i,a=isArray(n),u=isArray(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,d=t instanceof RegExp;if(l!=d)return!1;if(l&&d)return n.toString()==t.toString();var v=keyList(n);if((o=v.length)!==keyList(t).length)return!1;for(r=o;0!=r--;)if(!hasProp.call(t,v[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=v[r]],t[i]))return!1;return!0}return n!=n&&t!=t},_extends=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function btoa(e){var n=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(n))}function stringToBytes(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,n){return fastDeepEqual(e,n)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(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 transformValuesToVersionedValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function chunkUserEventsForUrl(e,n){for(var t=n.slice(0),r=[],o=e,i=void 0;t.length>0;){for(i=[];o>0;){var a=t.shift();if(!a)break;(o-=base64URLEncode(JSON.stringify(a)).length)<0&&i.length>0?t.unshift(a):i.push(a)}o=e,r.push(i)}return r}function getLDUserAgentString(e){var n=e.version||"2.14.0";return e.userAgent+"/"+n}function getLDHeaders(e){return{"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)}}function extend(){for(var e=arguments.length,n=Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return _extends({},e,n)},{})}function sanitizeUser(e){if(!e)return e;var n=void 0;for(var t in userAttrsToStringify){var r=userAttrsToStringify[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[r]=String(o))}return n||e}var utils=Object.freeze({btoa:btoa,base64URLEncode:base64URLEncode,clone:clone,deepEquals:deepEquals,onNextTick:onNextTick,wrapPromiseCallback:wrapPromiseCallback,transformValuesToVersionedValues:transformValuesToVersionedValues,transformVersionedValuesToValues:transformVersionedValuesToValues,chunkUserEventsForUrl:chunkUserEventsForUrl,getLDUserAgentString:getLDUserAgentString,getLDHeaders:getLDHeaders,extend:extend,sanitizeUser:sanitizeUser}),MAX_URL_LENGTH=2e3;function EventSender(e,n,t,r){var o=n+"/events/bulk/"+t,i=n+"/a/"+t+".gif",a={};function u(e){(new window.Image).src=e}function s(n,t){var a=r||u,s=JSON.stringify(n);return t?function n(t){var r=extend({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},getLDHeaders(e));return e.httpRequest("POST",o,r,s).promise.then(function(e){if(e)return e.status>=400&&isHttpErrorRecoverable(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(){}):(a(i+"?d="+base64URLEncode(s)),Promise.resolve())}return a.sendEvents=function(t){if(!e.httpRequest)return Promise.resolve();var r,o=e.httpAllowsPost();r=o?[t]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,t);for(var i=[],a=0;a<r.length;a++)i.push(s(r[a],o));return Promise.all(i)},a}function EventSummarizer(){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 UserFilter(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=extend({},c,l[1])}var d=Object.keys(c);return d.length&&(d.sort(),s.privateAttrs=d),s},n}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",clientNotReady=function(){return"LaunchDarkly client is not ready"},eventWithoutUser=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"},invalidContentType=function(e){return'Expected application/json content type but got "'+e+'"'},invalidKey=function(){return"Event key must be a string"},localStorageUnavailable=function(){return"localStorage is unavailable"},localStorageUnavailableForUserId=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},networkError=function(e){return"network error"+(e?" ("+e+")":"")},unknownCustomEventKey=function(e){return'Custom event "'+e+'" does not exist'},environmentNotFound=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+docLink},environmentNotSpecified=function(){return"No environment/client-side ID was specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+errorString(e)},userNotSpecified=function(){return"No user specified."+docLink},invalidUser=function(){return"Invalid user specified."+docLink},bootstrapOldFormat=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+docLink},bootstrapInvalid=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated=function(e,n){return'[LaunchDarkly] "'+e+'" is deprecated, please use "'+n+'"'},httpErrorMessage=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?t:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e){return"Error on stream connection: "+errorString(e)},debugPolling=function(e){return"polling for feature flags at "+e},debugStreamPing=function(){return"received ping message from stream"},debugStreamPut=function(){return"received streaming update for all flags"},debugStreamPatch=function(e){return'received streaming update for flag "'+e+'"'},debugStreamPatchIgnored=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},debugStreamDelete=function(e){return'received streaming deletion for flag "'+e+'"'},debugStreamDeleteIgnored=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},debugEnqueueingEvent=function(e){return'enqueueing "'+e+'" event'},debugPostingEvents=function(e){return"sending "+e+" events"},messages=Object.freeze({clientInitialized:clientInitialized,clientNotReady:clientNotReady,eventWithoutUser:eventWithoutUser,invalidContentType:invalidContentType,invalidKey:invalidKey,localStorageUnavailable:localStorageUnavailable,localStorageUnavailableForUserId:localStorageUnavailableForUserId,networkError:networkError,unknownCustomEventKey:unknownCustomEventKey,environmentNotFound:environmentNotFound,environmentNotSpecified:environmentNotSpecified,errorFetchingFlags:errorFetchingFlags,userNotSpecified:userNotSpecified,invalidUser:invalidUser,bootstrapOldFormat:bootstrapOldFormat,bootstrapInvalid:bootstrapInvalid,deprecated:deprecated,httpErrorMessage:httpErrorMessage,httpUnavailable:httpUnavailable,identifyDisabled:identifyDisabled,streamClosing:streamClosing,streamConnecting:streamConnecting,streamError:streamError,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents});function EventProcessor(e,n,t){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,i={},a=o||EventSender(e,n.eventsUrl,t),u=EventSummarizer(),s=UserFilter(n),c=n.inlineUsersInEvents,l=n.samplingInterval,d=n.flushInterval,v=n.logger,f=[],g=0,p=!1,m=void 0;function y(){return 0===l||0===Math.floor(Math.random()*l)}return i.enqueue=function(e){if(!p){var n,t=!1,r=!1;if(u.summarizeEvent(e),"feature"===e.kind?y()&&(t=!!e.trackEvents,r=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>g&&n.debugEventsUntilDate>(new Date).getTime()):t=y(),t&&f.push(function(e){var n=extend({},e);return c||"identify"===e.kind?n.user=s.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),r){var o=extend({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,f.push(o)}}},i.flush=function(){if(p)return Promise.resolve();var e=f,n=u.getSummary();return u.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(f=[],v.debug(debugPostingEvents(e.length)),a.sendEvents(e).then(function(e){e&&(e.serverTime&&(g=e.serverTime),isHttpErrorRecoverable(e.status)||(p=!0),e.status>=400&&onNextTick(function(){r.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},i.start=function(){m=setTimeout(function e(){i.flush(),m=setTimeout(e,d)},d)},i.stop=function(){clearTimeout(m)},i}function EventEmitter(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=0;n<t[e].length;n++)t[e][n].handler.apply(t[e][n].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}function Store(e,n,t,r,o){var i={};function a(){var e="",o=r.getUser();return o&&(e=t||btoa(JSON.stringify(o))),"ld:"+n+":"+e}return i.loadFlags=function(){return e.get(a()).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=transformValuesToVersionedValues(n):delete n.$schema}return n}catch(e){return i.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i.saveFlags=function(n){var t=extend({},n,{$schema:1});return e.set(a(),JSON.stringify(t)).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i.clearFlags=function(){return e.clear(a()).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i}function Stream(e,n,t,r){var o=n.streamUrl,i=n.logger,a={},u=o+"/eval/"+t,s=n.useReport,c=n.evaluationReasons,l=n.streamReconnectDelay,d=null,v=null,f=null,g=null;function p(e){i.warn(streamError(e)),h(),m(l)}function m(e){v||(e?v=setTimeout(y,e):y())}function y(){v=null;var n=void 0,a="",l={};if(e.eventSourceFactory){for(var m in null!=r&&(a="h="+r),s?e.eventSourceAllowsReport?(n=u,l.method="REPORT",l.headers={"Content-Type":"application/json"},l.body=JSON.stringify(f)):(n=o+"/ping/"+t,a=""):n=u+"/"+base64URLEncode(JSON.stringify(f)),c&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,h(),i.info(streamConnecting(n)),d=e.eventSourceFactory(n,l),g)g.hasOwnProperty(m)&&d.addEventListener(m,g[m]);d.onerror=p}}function h(){d&&(i.info(streamClosing()),d.close(),d=null)}return a.connect=function(e,n){f=e,g=n,m()},a.disconnect=function(){clearTimeout(v),v=null,h()},a.isConnected=function(){return!!(d&&e.eventSourceIsActive&&e.eventSourceIsActive(d))},a}function promiseCoalescer(e){var n=void 0,t=void 0,r=void 0,o=void 0,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}var json="application/json";function getResponseError(e){return 404===e.status?new LDInvalidEnvironmentIdError(environmentNotFound()):new LDFlagFetchError(errorFetchingFlags(e.statusText||String(e.status)))}function Requestor(e,n,t){var r=n.baseUrl,o=n.useReport,i=n.evaluationReasons,a=n.sendLDHeaders,u=n.logger,s={},c={};function l(n,t){if(!e.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var r=t?"REPORT":"GET",o=a?getLDHeaders(e):{};t&&(o["Content-Type"]="application/json");var i=c[n];i||(i=promiseCoalescer(function(){delete c[n]}),c[n]=i);var u=e.httpRequest(r,n,o,t),s=u.promise.then(function(e){if(200===e.status){if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(json))return JSON.parse(e.body);var n=invalidContentType(e.header("content-type")||"");return Promise.reject(new LDFlagFetchError(n))}return Promise.reject(getResponseError(e))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return i.addPromise(s,function(){u.cancel&&u.cancel()}),i.resultPromise}return s.fetchJSON=function(e){return l(r+e,null)},s.fetchFlagSettings=function(e,n){var a=void 0,s=void 0,c="",d=void 0;return o?(s=[r,"/sdk/evalx/",t,"/user"].join(""),d=JSON.stringify(e)):(a=base64URLEncode(JSON.stringify(e)),s=[r,"/sdk/evalx/",t,"/users/",a].join("")),n&&(c="h="+n),i&&(c=c+(c?"&":"")+"withReasons=true"),s=s+(c?"?":"")+c,u.debug(debugPolling(s)),l(s,d)},s}function Identity(e,n){var t={},r=void 0;return t.setUser=function(e){(r=sanitizeUser(e))&&n&&n(clone(r))},t.getUser=function(){return r?clone(r):null},e&&t.setUser(e),t}function createCommonjsModule(e,n){return e(n={exports:{}},n.exports),n.exports}for(var rngBrowser=createCommonjsModule(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}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var t=n||0,r=byteToHex;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("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||_nodeId,a=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==i||null==a){var u=rngBrowser();null==i&&(i=_nodeId=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=_clockseq=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,l=s-_lastMSecs+(c-_lastNSecs)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>_lastMSecs)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=s,_lastNSecs=c,_clockseq=a;var d=(1e4*(268435455&(s+=122192928e5))+c)%4294967296;o[r++]=d>>>24&255,o[r++]=d>>>16&255,o[r++]=d>>>8&255,o[r++]=255&d;var v=s/4294967296*1e4&268435455;o[r++]=v>>>8&255,o[r++]=255&v,o[r++]=v>>>24&15|16,o[r++]=v>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var f=0;f<6;++f)o[r+f]=i[f];return n||bytesToUuid_1(o)}var v1_1=v1,ldUserIdKey="ld:$anonUserId";function UserValidator(e,n){var t={validateUser:function(t){if(!t)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var r=clone(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(t){if(t)return r.key=t,r;var o=v1_1();return r.key=o,function(t){return e?e.set(ldUserIdKey,t).catch(function(){n.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(o).then(function(){return r})}):Promise.reject(new LDInvalidUserError(invalidUser()))}};return t}function validate(e,n,t,r){var o=extend({logger:r},{baseUrl:"https://app.launchdarkly.com",streamUrl:"https://clientstream.launchdarkly.com",eventsUrl:"https://events.launchdarkly.com",sendEvents:!0,sendLDHeaders:!0,inlineUsersInEvents:!1,allowFrequentDuplicateEvents:!1,sendEventsOnlyForVariation:!1,useReport:!1,evaluationReasons:!1,flushInterval:2e3,samplingInterval:0,streamReconnectDelay:1e3,allAttributesPrivate:!1,privateAttributeNames:[]},t),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames"};function a(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var u=extend({},e||{});return function(e){var n=u;Object.keys(i).forEach(function(e){if(void 0!==n[e]){var t=i[e];r.warn(deprecated(e,t)),void 0===n[t]&&(n[t]=n[e]),delete n[e]}})}(),u=function(e,n){var t=extend({},u);return Object.keys(n).forEach(function(e){void 0!==t[e]&&null!==t[e]||(t[e]=n[e])}),t}(0,o),(isNaN(u.flushInterval)||u.flushInterval<2e3)&&(u.flushInterval=2e3,a("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(u.samplingInterval)||u.samplingInterval<0)&&(u.samplingInterval=0,a("Invalid sampling interval configured. Sampling interval must be an integer >= 0.")),u}function createConsoleLogger(e,n){var t=["debug","info","warn","error"],r=void 0;r=null!=n?""===n?"":n+" ":"LD: ";var o=0;e&&(o="none"===e?100:t.indexOf(e));var i={};function a(e,n,i){if(e>=o){var a=e<t.length?t[e]:"?";n(r+"["+a+"] "+i)}}return i.debug=function(e){return a(0,console.log,e)},i.info=function(e){return a(1,console.info,e)},i.warn=function(e){return a(2,console.warn,e)},i.error=function(e){return a(3,console.error,e)},i}var _typeof$1="function"==typeof Symbol&&"symbol"==_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)},readyEvent="ready",successEvent="initialized",failedEvent="failed",changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,t,r,o){var i=t&&t.logger?t.logger:o&&o.logger||createConsoleLogger("warn"),a=EventEmitter(i),u=validate(t,a,o,i),s=u.hash,c=u.sendEvents,l=e,d=Stream(r,u,l,s),v=u.eventProcessor||EventProcessor(r,u,l,a),f=Requestor(r,u,l),g={},p={},m=void 0,y=void 0,h=u.streaming,E=void 0,b=!1,w=!1,k=!0,S=u.stateProvider,U=Identity(null,function(e){S||e&&L({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),D=UserValidator(r.localStorage,i),P=void 0;function L(e){l&&(S&&S.enqueueEvent&&S.enqueueEvent(e)||(e.user?(k=!1,!c||w||r.isDoNotTrack()||(i.debug(debugEnqueueingEvent(e.kind)),v.enqueue(e))):k&&(i.warn(eventWithoutUser()),k=!1)))}function I(e,n,t,r){var o=U.getUser(),i=new Date,a=n?n.value:null;if(!u.allowFrequentDuplicateEvents){var s=JSON.stringify(a)+(o&&o.key?o.key:"")+e,c=g[s];if(c&&i-c<3e5)return;g[s]=i}var l={kind:"feature",key:e,user:o,value:a,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()},d=p[e];d&&(l.version=d.flagVersion?d.flagVersion:d.version,l.trackEvents=d.trackEvents,l.debugEventsUntilDate=d.debugEventsUntilDate),(r||d&&d.trackReason)&&n&&(l.reason=n.reason),L(l)}function R(e,n,t,r){var o=void 0;if(p&&p.hasOwnProperty(e)&&p[e]&&!p[e].deleted){var i=p[e];o=T(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&&I(e,o,n,r),o}function T(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function C(){y=!0,U.getUser()&&d.connect(U.getUser(),{ping:function(){i.debug(debugStreamPing()),f.fetchFlagSettings(U.getUser(),s).then(function(e){return x(e||{})}).catch(function(e){a.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var n=JSON.parse(e.data);i.debug(debugStreamPut()),x(n)},patch:function(e){var n=JSON.parse(e.data),t=p[n.key];if(!t||!t.version||!n.version||t.version<n.version){i.debug(debugStreamPatch(n.key));var r={},o=extend({},n);delete o.key,p[n.key]=o;var a=T(o);r[n.key]=t?{previous:t.value,current:a}:{current:a},N(r)}else i.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!p[n.key]||p[n.key].version<n.version){i.debug(debugStreamDelete(n.key));var t={};p[n.key]&&!p[n.key].deleted&&(t[n.key]={previous:p[n.key].value}),p[n.key]={version:n.version,deleted:!0},N(t)}else i.debug(debugStreamDeleteIgnored(n.key))}})}function F(){y&&(d.disconnect(),y=!1)}function x(e){var n={};if(!e)return Promise.resolve();for(var t in p)p.hasOwnProperty(t)&&p[t]&&(e[t]&&!deepEquals(e[t].value,p[t].value)?n[t]={previous:p[t].value,current:T(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:p[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!p[r]||p[r].deleted)&&(n[r]={current:T(e[r])});return p=Object.assign({},e),N(n).catch(function(){})}function N(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;a.emit(changeEvent+":"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}}),a.emit(changeEvent,t),a.emit(internalChangeEvent,p),u.sendEventsOnlyForVariation||S||n.forEach(function(n){I(n,e[n].current)})}return m&&P?P.saveFlags(p).catch(function(){return null}):Promise.resolve()}function O(){var e=h||E&&void 0===h;e&&!y?C():!e&&y&&F()}function A(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}r.localStorage&&(P=new Store(r.localStorage,l,s,U,i));var j=new Promise(function(e){var n=a.on(readyEvent,function(){a.off(readyEvent,n),e()})}),_=new Promise(function(e,n){var t=a.on(successEvent,function(){a.off(successEvent,t),e()}),r=a.on(failedEvent,function(e){a.off(failedEvent,r),n(e)})});if("string"==typeof u.bootstrap&&"LOCALSTORAGE"===u.bootstrap.toUpperCase()&&(P?m=!0:i.warn(localStorageUnavailable())),"object"===_typeof$1(u.bootstrap)&&(p=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&i.warn(bootstrapOldFormat()),!1===e.$valid&&i.warn(bootstrapInvalid());var r={};return n.forEach(function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};t&&t[n]?o=extend(o,t[n]):o.version=0,r[n]=o}}),r}(u.bootstrap)),S){var q=S.getInitialState();q?V(q):S.on("init",V),S.on("update",function(e){e.user&&U.setUser(e.user),e.flags&&x(e.flags)})}else(e?D.validateUser(n).then(function(e){return U.setUser(e),"object"===_typeof$1(u.bootstrap)?z():m?P.loadFlags().catch(function(){return null}).then(function(e){return null==e?(p={},f.fetchFlagSettings(U.getUser(),s).then(function(e){return x(e||{})}).then(z).catch(function(e){H(new LDFlagFetchError(errorFetchingFlags(e)))})):(p=e,onNextTick(z),f.fetchFlagSettings(U.getUser(),s).then(function(e){return x(e)}).catch(function(e){return a.maybeReportError(e)}))}):f.fetchFlagSettings(U.getUser(),s).then(function(e){p=e||{},z()}).catch(function(e){p={},H(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(function(e){return a.maybeReportError(e)});function V(e){l=e.environment,U.setUser(e.user),p=Object.assign({},e.flags),onNextTick(z)}function z(){i.info(clientInitialized()),b=!0,O(),a.emit(readyEvent),a.emit(successEvent)}function H(e){a.maybeReportError(e),a.emit(failedEvent,e),a.emit(readyEvent)}return{client:{waitForInitialization:function(){return _},waitUntilReady:function(){return j},identify:function(e,n,t){return w?wrapPromiseCallback(Promise.resolve({}),t):S?(i.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(p)),t)):wrapPromiseCallback((m&&P?P.clearFlags():Promise.resolve()).then(function(){return D.validateUser(e)}).then(function(e){return U.setUser(e)}).then(function(){return f.fetchFlagSettings(U.getUser(),n)}).then(function(e){var n=transformVersionedValuesToValues(e);return e?x(e).then(function(){return n}):n}).then(function(e){return y&&C(),e}).catch(function(e){return a.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return U.getUser()},variation:function(e,n){return R(e,n,!0,!1).value},variationDetail:function(e,n){return R(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){r.customEventFilter&&!r.customEventFilter(e)&&i.warn(unknownCustomEventKey(e));var o={kind:"custom",key:e,user:U.getUser(),url:r.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(o.data=n),null!=t&&(o.metricValue=t),L(o)}else a.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,t){A(e)?(E=!0,b&&O(),a.on(e,n,t)):a.on.apply(a,arguments)},off:function(e){if(a.off.apply(a,arguments),A(e)){var n=!1;a.getEvents().forEach(function(e){A(e)&&a.getEventListenerCount(e)>0&&(n=!0)}),n||(E=!1,y&&void 0===h&&F())}},setStreaming:function(e){var n=null===e?void 0:e;n!==h&&(h=n,O())},flush:function(e){return wrapPromiseCallback(c?v.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!p)return e;for(var n in p)p.hasOwnProperty(n)&&(e[n]=R(n,null,!u.sendEventsOnlyForVariation).value);return e},close:function(e){if(w)return wrapPromiseCallback(Promise.resolve(),e);var n=function(){w=!0,p={}};return wrapPromiseCallback(Promise.resolve().then(function(){if(F(),c)return v.stop(),v.flush()}).then(n).catch(n),e)}},options:u,emitter:a,ident:U,logger:i,requestor:f,start:function(){c&&v.start()},enqueueEvent:L,getFlagsInternal:function(){return p},getEnvironmentId:function(){return l},internalChangeEventName:internalChangeEvent}}var version="2.14.0";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||{})t.hasOwnProperty(a)&&i.setRequestHeader(a,t[a]);if(o)return i.send(r),emptyResult;var u=void 0;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={pageIsClosing:!1};window.XMLHttpRequest&&(n.httpRequest=function(e,t,r,o){return newHttpRequest(e,t,r,o,n.pageIsClosing)});var t=void 0;n.httpAllowsPost=function(){return void 0===t&&(t=!!window.XMLHttpRequest&&"withCredentials"in new window.XMLHttpRequest),t};var r=e&&e.eventUrlTransformer;n.getCurrentUrl=function(){return r?r(window.location.href):window.location.href},n.isDoNotTrack=function(){var e=void 0;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&&(n.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){n.localStorage=null}var o=void 0;if(e&&e.useReport&&"function"==typeof window.EventSourcePolyfill&&window.EventSourcePolyfill.supportedOptions&&window.EventSourcePolyfill.supportedOptions.method?(n.eventSourceAllowsReport=!0,o=window.EventSourcePolyfill):(n.eventSourceAllowsReport=!1,o=window.EventSource),window.EventSource){n.eventSourceFactory=function(e,n){var t={heartbeatTimeout:3e5,silentTimeout:3e5,skipDefaultHeaders:!0},r=Object.assign({},t,n);return new o(e,r)},n.eventSourceIsActive=function(e){return e.readyState===window.EventSource.OPEN||e.readyState===window.EventSource.CONNECTING}}return n.userAgent="JSClient",n}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=n.replace(t,"").replace(r,""),i=void 0,a=void 0;switch(e.kind){case"exact":a=n,i=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"canonical":a=o,i=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"substring":a=o,i=new RegExp(".*"+escapeStringRegexp(e.substring)+".*$");break;case"regex":a=o,i=new RegExp(e.pattern);break;default:return!1}return i.test(a)}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&&u.length>0;){for(var s=0;s<u.length;s++)o===u[s]&&t.push(i);o=o.parentNode}return t}function GoalTracker(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(doesUrlMatch(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=findGoalsForClick(e,o),r=0;r<t.length;r++)n("click",t[r])},document.addEventListener("click",r)),t.dispose=function(){document.removeEventListener("click",r)},t}var locationWatcherInterval=300;function GoalManager(e,n){var t=void 0,r=void 0,o={};function i(){r&&r.dispose(),t&&t.length&&(r=GoalTracker(t,a))}function a(n,t){var r={kind:n,key:t.key,data:null,url:window.location.href,user:e.ident.getUser(),creationDate:(new Date).getTime()};return"click"===n&&(r.selector=t.selector),e.enqueueEvent(r)}return o.goalKeyExists=function(e){if(!t)return!0;for(var n=0;n<t.length;n++)if("custom"===t[n].kind&&t[n].key===e)return!0;return!1},e.requestor.fetchJSON("/sdk/goals/"+e.getEnvironmentId()).then(function(e){e&&e.length>0&&(r=GoalTracker(t=e,a),function(e,n){var t=window.location.href,r=void 0;function o(){(r=window.location.href)!==t&&(t=r,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)}(locationWatcherInterval,i)),n()}).catch(function(t){e.emitter.maybeReportError(new errors.LDUnexpectedResponseError((t&&t.message,t.message))),n()}),o}var goalsEvent="goalsReady",extraDefaults={fetchGoals:!0};function initialize$1(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=makeBrowserPlatform(t),o=initialize(e,n,t,r,extraDefaults),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()})});if(i.waitUntilGoalsReady=function(){return s},a.fetchGoals){var c=GoalManager(o,function(){return u.emit(goalsEvent)});r.customEventFilter=c.goalKeyExists}else u.emit(goalsEvent);return"complete"!==document.readyState?window.addEventListener("load",o.start):o.start(),window.addEventListener("beforeunload",function(){r.pageIsClosing=!0,i.close()}),i}var createConsoleLogger$1=createConsoleLogger,version$1=version;function deprecatedInitialize(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return console&&console.warn&&console.warn(messages.deprecated("default export","named LDClient export")),initialize$1(e,n,t)}var index={initialize:deprecatedInitialize,version:version$1};exports.initialize=initialize$1,exports.createConsoleLogger=createConsoleLogger$1,exports.version=version$1,exports.default=index; | ||
//# sourceMappingURL=ldclient.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
var _typeof2="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};function createCustomError(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 LDUnexpectedResponseError=createCustomError("LaunchDarklyUnexpectedResponseError"),LDInvalidEnvironmentIdError=createCustomError("LaunchDarklyInvalidEnvironmentIdError"),LDInvalidUserError=createCustomError("LaunchDarklyInvalidUserError"),LDInvalidEventKeyError=createCustomError("LaunchDarklyInvalidEventKeyError"),LDInvalidArgumentError=createCustomError("LaunchDarklyInvalidArgumentError"),LDFlagFetchError=createCustomError("LaunchDarklyFlagFetchError");function isHttpErrorRecoverable(e){return!(e>=400&&e<500)||400===e||408===e||429===e}for(var errors=Object.freeze({LDUnexpectedResponseError:LDUnexpectedResponseError,LDInvalidEnvironmentIdError:LDInvalidEnvironmentIdError,LDInvalidUserError:LDInvalidUserError,LDInvalidEventKeyError:LDInvalidEventKeyError,LDInvalidArgumentError:LDInvalidArgumentError,LDFlagFetchError:LDFlagFetchError,isHttpErrorRecoverable:isHttpErrorRecoverable}),fromByteArray_1=fromByteArray,lookup=[],revLookup=[],code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;i<len;++i)lookup[i]=code[i],revLookup[code.charCodeAt(i)]=i;function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,n,t){for(var r,o=[],i=n;i<t;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(encodeChunk(e,i,i+16383>a?a:i+16383));return 1===r?(n=e[t-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(lookup[n>>10]+lookup[n>>4&63]+lookup[n<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var _typeof="function"==typeof Symbol&&"symbol"==_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)},isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==(void 0===n?"undefined":_typeof(n))&&"object"==(void 0===t?"undefined":_typeof(t))){var r,o,i,a=isArray(n),u=isArray(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,d=t instanceof RegExp;if(l!=d)return!1;if(l&&d)return n.toString()==t.toString();var v=keyList(n);if((o=v.length)!==keyList(t).length)return!1;for(r=o;0!=r--;)if(!hasProp.call(t,v[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=v[r]],t[i]))return!1;return!0}return n!=n&&t!=t},_extends=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function btoa(e){var n=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(n))}function stringToBytes(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,n){return fastDeepEqual(e,n)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(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 transformValuesToVersionedValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function chunkUserEventsForUrl(e,n){for(var t=n.slice(0),r=[],o=e,i=void 0;t.length>0;){for(i=[];o>0;){var a=t.shift();if(!a)break;(o-=base64URLEncode(JSON.stringify(a)).length)<0&&i.length>0?t.unshift(a):i.push(a)}o=e,r.push(i)}return r}function getLDUserAgentString(e){var n=e.version||"2.13.0";return e.userAgent+"/"+n}function getLDHeaders(e){return{"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)}}function extend(){for(var e=arguments.length,n=Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return _extends({},e,n)},{})}function sanitizeUser(e){if(!e)return e;var n=void 0;for(var t in userAttrsToStringify){var r=userAttrsToStringify[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[r]=String(o))}return n||e}var utils=Object.freeze({btoa:btoa,base64URLEncode:base64URLEncode,clone:clone,deepEquals:deepEquals,onNextTick:onNextTick,wrapPromiseCallback:wrapPromiseCallback,transformValuesToVersionedValues:transformValuesToVersionedValues,transformVersionedValuesToValues:transformVersionedValuesToValues,chunkUserEventsForUrl:chunkUserEventsForUrl,getLDUserAgentString:getLDUserAgentString,getLDHeaders:getLDHeaders,extend:extend,sanitizeUser:sanitizeUser}),MAX_URL_LENGTH=2e3;function EventSender(e,n,t,r){var o=n+"/events/bulk/"+t,i=n+"/a/"+t+".gif",a={};function u(e){(new window.Image).src=e}function s(n,t){var a=r||u,s=JSON.stringify(n);return t?function n(t){var r=extend({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},getLDHeaders(e));return e.httpRequest("POST",o,r,s).promise.then(function(e){if(e)return e.status>=400&&isHttpErrorRecoverable(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(){}):(a(i+"?d="+base64URLEncode(s)),Promise.resolve())}return a.sendEvents=function(t){if(!e.httpRequest)return Promise.resolve();var r,o=e.httpAllowsPost();r=o?[t]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,t);for(var i=[],a=0;a<r.length;a++)i.push(s(r[a],o));return Promise.all(i)},a}function EventSummarizer(){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 UserFilter(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=extend({},c,l[1])}var d=Object.keys(c);return d.length&&(d.sort(),s.privateAttrs=d),s},n}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",clientNotReady=function(){return"LaunchDarkly client is not ready"},eventWithoutUser=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"},invalidContentType=function(e){return'Expected application/json content type but got "'+e+'"'},invalidKey=function(){return"Event key must be a string"},localStorageUnavailable=function(){return"localStorage is unavailable"},localStorageUnavailableForUserId=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},networkError=function(e){return"network error"+(e?" ("+e+")":"")},unknownCustomEventKey=function(e){return'Custom event "'+e+'" does not exist'},environmentNotFound=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+docLink},environmentNotSpecified=function(){return"No environment/client-side ID was specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+errorString(e)},userNotSpecified=function(){return"No user specified."+docLink},invalidUser=function(){return"Invalid user specified."+docLink},bootstrapOldFormat=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+docLink},bootstrapInvalid=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated=function(e,n){return'[LaunchDarkly] "'+e+'" is deprecated, please use "'+n+'"'},httpErrorMessage=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?t:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e){return"Error on stream connection: "+errorString(e)},debugPolling=function(e){return"polling for feature flags at "+e},debugStreamPing=function(){return"received ping message from stream"},debugStreamPut=function(){return"received streaming update for all flags"},debugStreamPatch=function(e){return'received streaming update for flag "'+e+'"'},debugStreamPatchIgnored=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},debugStreamDelete=function(e){return'received streaming deletion for flag "'+e+'"'},debugStreamDeleteIgnored=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},debugEnqueueingEvent=function(e){return'enqueueing "'+e+'" event'},debugPostingEvents=function(e){return"sending "+e+" events"},messages=Object.freeze({clientInitialized:clientInitialized,clientNotReady:clientNotReady,eventWithoutUser:eventWithoutUser,invalidContentType:invalidContentType,invalidKey:invalidKey,localStorageUnavailable:localStorageUnavailable,localStorageUnavailableForUserId:localStorageUnavailableForUserId,networkError:networkError,unknownCustomEventKey:unknownCustomEventKey,environmentNotFound:environmentNotFound,environmentNotSpecified:environmentNotSpecified,errorFetchingFlags:errorFetchingFlags,userNotSpecified:userNotSpecified,invalidUser:invalidUser,bootstrapOldFormat:bootstrapOldFormat,bootstrapInvalid:bootstrapInvalid,deprecated:deprecated,httpErrorMessage:httpErrorMessage,httpUnavailable:httpUnavailable,identifyDisabled:identifyDisabled,streamClosing:streamClosing,streamConnecting:streamConnecting,streamError:streamError,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents});function EventProcessor(e,n,t){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,i={},a=o||EventSender(e,n.eventsUrl,t),u=EventSummarizer(),s=UserFilter(n),c=n.inlineUsersInEvents,l=n.samplingInterval,d=n.flushInterval,v=n.logger,f=[],g=0,p=!1,m=void 0;function y(){return 0===l||0===Math.floor(Math.random()*l)}return i.enqueue=function(e){if(!p){var n,t=!1,r=!1;if(u.summarizeEvent(e),"feature"===e.kind?y()&&(t=!!e.trackEvents,r=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>g&&n.debugEventsUntilDate>(new Date).getTime()):t=y(),t&&f.push(function(e){var n=extend({},e);return c||"identify"===e.kind?n.user=s.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),r){var o=extend({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,f.push(o)}}},i.flush=function(){if(p)return Promise.resolve();var e=f,n=u.getSummary();return u.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(f=[],v.debug(debugPostingEvents(e.length)),a.sendEvents(e).then(function(e){e&&(e.serverTime&&(g=e.serverTime),isHttpErrorRecoverable(e.status)||(p=!0),e.status>=400&&onNextTick(function(){r.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},i.start=function(){m=setTimeout(function e(){i.flush(),m=setTimeout(e,d)},d)},i.stop=function(){clearTimeout(m)},i}function EventEmitter(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=0;n<t[e].length;n++)t[e][n].handler.apply(t[e][n].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}function Store(e,n,t,r,o){var i={};function a(){var e="",o=r.getUser();return o&&(e=t||btoa(JSON.stringify(o))),"ld:"+n+":"+e}return i.loadFlags=function(){return e.get(a()).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=transformValuesToVersionedValues(n):delete n.$schema}return n}catch(e){return i.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i.saveFlags=function(n){var t=extend({},n,{$schema:1});return e.set(a(),JSON.stringify(t)).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i.clearFlags=function(){return e.clear(a()).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i}function Stream(e,n,t,r){var o=n.streamUrl,i=n.logger,a={},u=o+"/eval/"+t,s=n.useReport,c=n.evaluationReasons,l=n.streamReconnectDelay,d=null,v=null,f=null,g=null;function p(e){i.warn(streamError(e)),h(),m(l)}function m(e){v||(e?v=setTimeout(y,e):y())}function y(){v=null;var n=void 0,a="",l={};if(e.eventSourceFactory){for(var m in null!=r&&(a="h="+r),s?e.eventSourceAllowsReport?(n=u,l.method="REPORT",l.headers={"Content-Type":"application/json"},l.body=JSON.stringify(f)):(n=o+"/ping/"+t,a=""):n=u+"/"+base64URLEncode(JSON.stringify(f)),c&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,h(),i.info(streamConnecting(n)),d=e.eventSourceFactory(n,l),g)g.hasOwnProperty(m)&&d.addEventListener(m,g[m]);d.onerror=p}}function h(){d&&(i.info(streamClosing()),d.close(),d=null)}return a.connect=function(e,n){f=e,g=n,m()},a.disconnect=function(){clearTimeout(v),v=null,h()},a.isConnected=function(){return!!(d&&e.eventSourceIsActive&&e.eventSourceIsActive(d))},a}function promiseCoalescer(e){var n=void 0,t=void 0,r=void 0,o=void 0,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}var json="application/json";function getResponseError(e){return 404===e.status?new LDInvalidEnvironmentIdError(environmentNotFound()):new LDFlagFetchError(errorFetchingFlags(e.statusText||String(e.status)))}function Requestor(e,n,t){var r=n.baseUrl,o=n.useReport,i=n.evaluationReasons,a=n.sendLDHeaders,u=n.logger,s={},c={};function l(n,t){if(!e.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var r=t?"REPORT":"GET",o=a?getLDHeaders(e):{};t&&(o["Content-Type"]="application/json");var i=c[n];i||(i=promiseCoalescer(function(){delete c[n]}),c[n]=i);var u=e.httpRequest(r,n,o,t),s=u.promise.then(function(e){if(200===e.status){if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(json))return JSON.parse(e.body);var n=invalidContentType(e.header("content-type")||"");return Promise.reject(new LDFlagFetchError(n))}return Promise.reject(getResponseError(e))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return i.addPromise(s,function(){u.cancel&&u.cancel()}),i.resultPromise}return s.fetchJSON=function(e){return l(r+e,null)},s.fetchFlagSettings=function(e,n){var a=void 0,s=void 0,c="",d=void 0;return o?(s=[r,"/sdk/evalx/",t,"/user"].join(""),d=JSON.stringify(e)):(a=base64URLEncode(JSON.stringify(e)),s=[r,"/sdk/evalx/",t,"/users/",a].join("")),n&&(c="h="+n),i&&(c=c+(c?"&":"")+"withReasons=true"),s=s+(c?"?":"")+c,u.debug(debugPolling(s)),l(s,d)},s}function Identity(e,n){var t={},r=void 0;return t.setUser=function(e){(r=sanitizeUser(e))&&n&&n(clone(r))},t.getUser=function(){return r?clone(r):null},e&&t.setUser(e),t}function createCommonjsModule(e,n){return e(n={exports:{}},n.exports),n.exports}for(var rngBrowser=createCommonjsModule(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}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var t=n||0,r=byteToHex;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("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||_nodeId,a=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==i||null==a){var u=rngBrowser();null==i&&(i=_nodeId=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=_clockseq=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,l=s-_lastMSecs+(c-_lastNSecs)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>_lastMSecs)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=s,_lastNSecs=c,_clockseq=a;var d=(1e4*(268435455&(s+=122192928e5))+c)%4294967296;o[r++]=d>>>24&255,o[r++]=d>>>16&255,o[r++]=d>>>8&255,o[r++]=255&d;var v=s/4294967296*1e4&268435455;o[r++]=v>>>8&255,o[r++]=255&v,o[r++]=v>>>24&15|16,o[r++]=v>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var f=0;f<6;++f)o[r+f]=i[f];return n||bytesToUuid_1(o)}var v1_1=v1,ldUserIdKey="ld:$anonUserId";function UserValidator(e,n){var t={validateUser:function(t){if(!t)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var r=clone(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(t){if(t)return r.key=t,r;var o=v1_1();return r.key=o,function(t){return e?e.set(ldUserIdKey,t).catch(function(){n.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(o).then(function(){return r})}):Promise.reject(new LDInvalidUserError(invalidUser()))}};return t}function validate(e,n,t,r){var o=extend({logger:r},{baseUrl:"https://app.launchdarkly.com",streamUrl:"https://clientstream.launchdarkly.com",eventsUrl:"https://events.launchdarkly.com",sendEvents:!0,sendLDHeaders:!0,inlineUsersInEvents:!1,allowFrequentDuplicateEvents:!1,sendEventsOnlyForVariation:!1,useReport:!1,evaluationReasons:!1,flushInterval:2e3,samplingInterval:0,streamReconnectDelay:1e3,allAttributesPrivate:!1,privateAttributeNames:[]},t),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames"};function a(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var u=extend({},e||{});return function(e){var n=u;Object.keys(i).forEach(function(e){if(void 0!==n[e]){var t=i[e];r.warn(deprecated(e,t)),void 0===n[t]&&(n[t]=n[e]),delete n[e]}})}(),u=function(e,n){var t=extend({},u);return Object.keys(n).forEach(function(e){void 0!==t[e]&&null!==t[e]||(t[e]=n[e])}),t}(0,o),(isNaN(u.flushInterval)||u.flushInterval<2e3)&&(u.flushInterval=2e3,a("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(u.samplingInterval)||u.samplingInterval<0)&&(u.samplingInterval=0,a("Invalid sampling interval configured. Sampling interval must be an integer >= 0.")),u}function createConsoleLogger(e){var n=0;e&&(n="none"===e?100:["debug","info","warn","error"].indexOf(e));var t={};function r(e,t,r){e>=n&&t(r)}return t.debug=function(e){return r(0,console.log,e)},t.info=function(e){return r(1,console.info,e)},t.warn=function(e){return r(2,console.warn,e)},t.error=function(e){return r(3,console.error,e)},t}var _typeof$1="function"==typeof Symbol&&"symbol"==_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)},readyEvent="ready",successEvent="initialized",failedEvent="failed",changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,t,r,o){var i=t&&t.logger?t.logger:o&&o.logger||createConsoleLogger("warn"),a=EventEmitter(i),u=validate(t,a,o,i),s=u.hash,c=u.sendEvents,l=e,d=Stream(r,u,l,s),v=u.eventProcessor||EventProcessor(r,u,l,a),f=Requestor(r,u,l),g={},p={},m=void 0,y=void 0,h=u.streaming,E=void 0,b=!1,w=!1,k=!0,S=u.stateProvider,U=Identity(null,function(e){S||e&&L({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),D=UserValidator(r.localStorage,i),P=void 0;function L(e){l&&(S&&S.enqueueEvent&&S.enqueueEvent(e)||(e.user?(k=!1,!c||w||r.isDoNotTrack()||(i.debug(debugEnqueueingEvent(e.kind)),v.enqueue(e))):k&&(i.warn(eventWithoutUser()),k=!1)))}function I(e,n,t){var r=U.getUser(),o=new Date,i=n?n.value:null;if(!u.allowFrequentDuplicateEvents){var a=JSON.stringify(i)+(r&&r.key?r.key:"")+e,s=g[a];if(s&&o-s<3e5)return;g[a]=o}var c={kind:"feature",key:e,user:r,value:i,variation:n?n.variationIndex:null,default:t,creationDate:o.getTime(),reason:n?n.reason:null},l=p[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),L(c)}function R(e,n,t){var r=void 0;if(p&&p.hasOwnProperty(e)&&p[e]&&!p[e].deleted){var o=p[e];r=T(o),null!==o.value&&void 0!==o.value||(r.value=n)}else r={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&I(e,r,n),r}function T(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function C(){y=!0,U.getUser()&&d.connect(U.getUser(),{ping:function(){i.debug(debugStreamPing()),f.fetchFlagSettings(U.getUser(),s).then(function(e){return N(e||{})}).catch(function(e){a.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var n=JSON.parse(e.data);i.debug(debugStreamPut()),N(n)},patch:function(e){var n=JSON.parse(e.data),t=p[n.key];if(!t||!t.version||!n.version||t.version<n.version){i.debug(debugStreamPatch(n.key));var r={},o=extend({},n);delete o.key,p[n.key]=o;var a=T(o);r[n.key]=t?{previous:t.value,current:a}:{current:a},x(r)}else i.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!p[n.key]||p[n.key].version<n.version){i.debug(debugStreamDelete(n.key));var t={};p[n.key]&&!p[n.key].deleted&&(t[n.key]={previous:p[n.key].value}),p[n.key]={version:n.version,deleted:!0},x(t)}else i.debug(debugStreamDeleteIgnored(n.key))}})}function F(){y&&(d.disconnect(),y=!1)}function N(e){var n={};if(!e)return Promise.resolve();for(var t in p)p.hasOwnProperty(t)&&p[t]&&(e[t]&&!deepEquals(e[t].value,p[t].value)?n[t]={previous:p[t].value,current:T(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:p[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!p[r]||p[r].deleted)&&(n[r]={current:T(e[r])});return p=Object.assign({},e),x(n).catch(function(){})}function x(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;a.emit(changeEvent+":"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}}),a.emit(changeEvent,t),a.emit(internalChangeEvent,p),u.sendEventsOnlyForVariation||S||n.forEach(function(n){I(n,e[n].current)})}return m&&P?P.saveFlags(p).catch(function(){return null}):Promise.resolve()}function O(){var e=h||E&&void 0===h;e&&!y?C():!e&&y&&F()}function A(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}r.localStorage&&(P=new Store(r.localStorage,l,s,U,i));var j=new Promise(function(e){var n=a.on(readyEvent,function(){a.off(readyEvent,n),e()})}),_=new Promise(function(e,n){var t=a.on(successEvent,function(){a.off(successEvent,t),e()}),r=a.on(failedEvent,function(e){a.off(failedEvent,r),n(e)})});if("string"==typeof u.bootstrap&&"LOCALSTORAGE"===u.bootstrap.toUpperCase()&&(P?m=!0:i.warn(localStorageUnavailable())),"object"===_typeof$1(u.bootstrap)&&(p=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&i.warn(bootstrapOldFormat()),!1===e.$valid&&i.warn(bootstrapInvalid());var r={};return n.forEach(function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};t&&t[n]?o=extend(o,t[n]):o.version=0,r[n]=o}}),r}(u.bootstrap)),S){var q=S.getInitialState();q?V(q):S.on("init",V),S.on("update",function(e){e.user&&U.setUser(e.user),e.flags&&N(e.flags)})}else(e?D.validateUser(n).then(function(e){return U.setUser(e),"object"===_typeof$1(u.bootstrap)?z():m?P.loadFlags().catch(function(){return null}).then(function(e){return null==e?(p={},f.fetchFlagSettings(U.getUser(),s).then(function(e){return N(e||{})}).then(z).catch(function(e){H(new LDFlagFetchError(errorFetchingFlags(e)))})):(p=e,onNextTick(z),f.fetchFlagSettings(U.getUser(),s).then(function(e){return N(e)}).catch(function(e){return a.maybeReportError(e)}))}):f.fetchFlagSettings(U.getUser(),s).then(function(e){p=e||{},z()}).catch(function(e){p={},H(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(function(e){return a.maybeReportError(e)});function V(e){l=e.environment,U.setUser(e.user),p=Object.assign({},e.flags),onNextTick(z)}function z(){i.info(clientInitialized()),b=!0,O(),a.emit(readyEvent),a.emit(successEvent)}function H(e){a.maybeReportError(e),a.emit(failedEvent,e),a.emit(readyEvent)}return{client:{waitForInitialization:function(){return _},waitUntilReady:function(){return j},identify:function(e,n,t){return w?wrapPromiseCallback(Promise.resolve({}),t):S?(i.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(p)),t)):wrapPromiseCallback((m&&P?P.clearFlags():Promise.resolve()).then(function(){return D.validateUser(e)}).then(function(e){return U.setUser(e)}).then(function(){return f.fetchFlagSettings(U.getUser(),n)}).then(function(e){var n=transformVersionedValuesToValues(e);return e?N(e).then(function(){return n}):n}).then(function(e){return y&&C(),e}).catch(function(e){return a.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return U.getUser()},variation:function(e,n){return R(e,n,!0).value},variationDetail:function(e,n){return R(e,n,!0)},track:function(e,n){"string"==typeof e?(r.customEventFilter&&!r.customEventFilter(e)&&i.warn(unknownCustomEventKey(e)),L({kind:"custom",key:e,data:n,user:U.getUser(),url:r.getCurrentUrl(),creationDate:(new Date).getTime()})):a.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,t){A(e)?(E=!0,b&&O(),a.on(e,n,t)):a.on.apply(a,arguments)},off:function(e){if(a.off.apply(a,arguments),A(e)){var n=!1;a.getEvents().forEach(function(e){A(e)&&a.getEventListenerCount(e)>0&&(n=!0)}),n||(E=!1,y&&void 0===h&&F())}},setStreaming:function(e){var n=null===e?void 0:e;n!==h&&(h=n,O())},flush:function(e){return wrapPromiseCallback(c?v.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!p)return e;for(var n in p)p.hasOwnProperty(n)&&(e[n]=R(n,null,!u.sendEventsOnlyForVariation).value);return e},close:function(e){if(w)return wrapPromiseCallback(Promise.resolve(),e);var n=function(){w=!0,p={}};return wrapPromiseCallback(Promise.resolve().then(function(){if(F(),c)return v.stop(),v.flush()}).then(n).catch(n),e)}},options:u,emitter:a,ident:U,logger:i,requestor:f,start:function(){c&&v.start()},enqueueEvent:L,getFlagsInternal:function(){return p},getEnvironmentId:function(){return l},internalChangeEventName:internalChangeEvent}}var version="2.13.0";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||{})t.hasOwnProperty(a)&&i.setRequestHeader(a,t[a]);if(o)return i.send(r),emptyResult;var u=void 0;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={pageIsClosing:!1};window.XMLHttpRequest&&(n.httpRequest=function(e,t,r,o){return newHttpRequest(e,t,r,o,n.pageIsClosing)});var t=void 0;n.httpAllowsPost=function(){return void 0===t&&(t=!!window.XMLHttpRequest&&"withCredentials"in new window.XMLHttpRequest),t};var r=e&&e.eventUrlTransformer;n.getCurrentUrl=function(){return r?r(window.location.href):window.location.href},n.isDoNotTrack=function(){var e=void 0;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&&(n.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){n.localStorage=null}var o=void 0;if(e&&e.useReport&&"function"==typeof window.EventSourcePolyfill&&window.EventSourcePolyfill.supportedOptions&&window.EventSourcePolyfill.supportedOptions.method?(n.eventSourceAllowsReport=!0,o=window.EventSourcePolyfill):(n.eventSourceAllowsReport=!1,o=window.EventSource),window.EventSource){n.eventSourceFactory=function(e,n){var t={heartbeatTimeout:3e5,silentTimeout:3e5,skipDefaultHeaders:!0},r=Object.assign({},t,n);return new o(e,r)},n.eventSourceIsActive=function(e){return e.readyState===window.EventSource.OPEN||e.readyState===window.EventSource.CONNECTING}}return n.userAgent="JSClient",n}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=n.replace(t,"").replace(r,""),i=void 0,a=void 0;switch(e.kind){case"exact":a=n,i=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"canonical":a=o,i=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"substring":a=o,i=new RegExp(".*"+escapeStringRegexp(e.substring)+".*$");break;case"regex":a=o,i=new RegExp(e.pattern);break;default:return!1}return i.test(a)}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&&u.length>0;){for(var s=0;s<u.length;s++)o===u[s]&&t.push(i);o=o.parentNode}return t}function GoalTracker(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(doesUrlMatch(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=findGoalsForClick(e,o),r=0;r<t.length;r++)n("click",t[r])},document.addEventListener("click",r)),t.dispose=function(){document.removeEventListener("click",r)},t}var locationWatcherInterval=300;function GoalManager(e,n){var t=void 0,r=void 0,o={};function i(){r&&r.dispose(),t&&t.length&&(r=GoalTracker(t,a))}function a(n,t){var r={kind:n,key:t.key,data:null,url:window.location.href,user:e.ident.getUser(),creationDate:(new Date).getTime()};return"click"===n&&(r.selector=t.selector),e.enqueueEvent(r)}return o.goalKeyExists=function(e){if(!t)return!0;for(var n=0;n<t.length;n++)if("custom"===t[n].kind&&t[n].key===e)return!0;return!1},e.requestor.fetchJSON("/sdk/goals/"+e.getEnvironmentId()).then(function(e){e&&e.length>0&&(r=GoalTracker(t=e,a),function(e,n){var t=window.location.href,r=void 0;function o(){(r=window.location.href)!==t&&(t=r,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)}(locationWatcherInterval,i)),n()}).catch(function(t){e.emitter.maybeReportError(new errors.LDUnexpectedResponseError((t&&t.message,t.message))),n()}),o}var goalsEvent="goalsReady",extraDefaults={fetchGoals:!0};function initialize$1(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=makeBrowserPlatform(t),o=initialize(e,n,t,r,extraDefaults),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()})});if(i.waitUntilGoalsReady=function(){return s},a.fetchGoals){var c=GoalManager(o,function(){return u.emit(goalsEvent)});r.customEventFilter=c.goalKeyExists}else u.emit(goalsEvent);return"complete"!==document.readyState?window.addEventListener("load",o.start):o.start(),window.addEventListener("beforeunload",function(){r.pageIsClosing=!0,i.close()}),i}var createConsoleLogger$1=createConsoleLogger,version$1=version;function deprecatedInitialize(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return console&&console.warn&&console.warn(messages.deprecated("default export","named LDClient export")),initialize$1(e,n,t)}var index={initialize:deprecatedInitialize,version:version};export default index;export{initialize$1 as initialize,createConsoleLogger$1 as createConsoleLogger,version$1 as version}; | ||
var _typeof2="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};function createCustomError(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 LDUnexpectedResponseError=createCustomError("LaunchDarklyUnexpectedResponseError"),LDInvalidEnvironmentIdError=createCustomError("LaunchDarklyInvalidEnvironmentIdError"),LDInvalidUserError=createCustomError("LaunchDarklyInvalidUserError"),LDInvalidEventKeyError=createCustomError("LaunchDarklyInvalidEventKeyError"),LDInvalidArgumentError=createCustomError("LaunchDarklyInvalidArgumentError"),LDFlagFetchError=createCustomError("LaunchDarklyFlagFetchError");function isHttpErrorRecoverable(e){return!(e>=400&&e<500)||400===e||408===e||429===e}for(var errors=Object.freeze({LDUnexpectedResponseError:LDUnexpectedResponseError,LDInvalidEnvironmentIdError:LDInvalidEnvironmentIdError,LDInvalidUserError:LDInvalidUserError,LDInvalidEventKeyError:LDInvalidEventKeyError,LDInvalidArgumentError:LDInvalidArgumentError,LDFlagFetchError:LDFlagFetchError,isHttpErrorRecoverable:isHttpErrorRecoverable}),fromByteArray_1=fromByteArray,lookup=[],revLookup=[],code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;i<len;++i)lookup[i]=code[i],revLookup[code.charCodeAt(i)]=i;function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,n,t){for(var r,o=[],i=n;i<t;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(encodeChunk(e,i,i+16383>a?a:i+16383));return 1===r?(n=e[t-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(lookup[n>>10]+lookup[n>>4&63]+lookup[n<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var _typeof="function"==typeof Symbol&&"symbol"==_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)},isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==(void 0===n?"undefined":_typeof(n))&&"object"==(void 0===t?"undefined":_typeof(t))){var r,o,i,a=isArray(n),u=isArray(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,v=t instanceof RegExp;if(l!=v)return!1;if(l&&v)return n.toString()==t.toString();var d=keyList(n);if((o=d.length)!==keyList(t).length)return!1;for(r=o;0!=r--;)if(!hasProp.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},_extends=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function btoa(e){var n=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(n))}function stringToBytes(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,n){return fastDeepEqual(e,n)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(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 transformValuesToVersionedValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function chunkUserEventsForUrl(e,n){for(var t=n.slice(0),r=[],o=e,i=void 0;t.length>0;){for(i=[];o>0;){var a=t.shift();if(!a)break;(o-=base64URLEncode(JSON.stringify(a)).length)<0&&i.length>0?t.unshift(a):i.push(a)}o=e,r.push(i)}return r}function getLDUserAgentString(e){var n=e.version||"2.14.0";return e.userAgent+"/"+n}function getLDHeaders(e){return{"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)}}function extend(){for(var e=arguments.length,n=Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return _extends({},e,n)},{})}function sanitizeUser(e){if(!e)return e;var n=void 0;for(var t in userAttrsToStringify){var r=userAttrsToStringify[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[r]=String(o))}return n||e}var utils=Object.freeze({btoa:btoa,base64URLEncode:base64URLEncode,clone:clone,deepEquals:deepEquals,onNextTick:onNextTick,wrapPromiseCallback:wrapPromiseCallback,transformValuesToVersionedValues:transformValuesToVersionedValues,transformVersionedValuesToValues:transformVersionedValuesToValues,chunkUserEventsForUrl:chunkUserEventsForUrl,getLDUserAgentString:getLDUserAgentString,getLDHeaders:getLDHeaders,extend:extend,sanitizeUser:sanitizeUser}),MAX_URL_LENGTH=2e3;function EventSender(e,n,t,r){var o=n+"/events/bulk/"+t,i=n+"/a/"+t+".gif",a={};function u(e){(new window.Image).src=e}function s(n,t){var a=r||u,s=JSON.stringify(n);return t?function n(t){var r=extend({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},getLDHeaders(e));return e.httpRequest("POST",o,r,s).promise.then(function(e){if(e)return e.status>=400&&isHttpErrorRecoverable(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(){}):(a(i+"?d="+base64URLEncode(s)),Promise.resolve())}return a.sendEvents=function(t){if(!e.httpRequest)return Promise.resolve();var r,o=e.httpAllowsPost();r=o?[t]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,t);for(var i=[],a=0;a<r.length;a++)i.push(s(r[a],o));return Promise.all(i)},a}function EventSummarizer(){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 UserFilter(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=extend({},c,l[1])}var v=Object.keys(c);return v.length&&(v.sort(),s.privateAttrs=v),s},n}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",clientNotReady=function(){return"LaunchDarkly client is not ready"},eventWithoutUser=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"},invalidContentType=function(e){return'Expected application/json content type but got "'+e+'"'},invalidKey=function(){return"Event key must be a string"},localStorageUnavailable=function(){return"localStorage is unavailable"},localStorageUnavailableForUserId=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},networkError=function(e){return"network error"+(e?" ("+e+")":"")},unknownCustomEventKey=function(e){return'Custom event "'+e+'" does not exist'},environmentNotFound=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+docLink},environmentNotSpecified=function(){return"No environment/client-side ID was specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+errorString(e)},userNotSpecified=function(){return"No user specified."+docLink},invalidUser=function(){return"Invalid user specified."+docLink},bootstrapOldFormat=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+docLink},bootstrapInvalid=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated=function(e,n){return'[LaunchDarkly] "'+e+'" is deprecated, please use "'+n+'"'},httpErrorMessage=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?t:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e){return"Error on stream connection: "+errorString(e)},debugPolling=function(e){return"polling for feature flags at "+e},debugStreamPing=function(){return"received ping message from stream"},debugStreamPut=function(){return"received streaming update for all flags"},debugStreamPatch=function(e){return'received streaming update for flag "'+e+'"'},debugStreamPatchIgnored=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},debugStreamDelete=function(e){return'received streaming deletion for flag "'+e+'"'},debugStreamDeleteIgnored=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},debugEnqueueingEvent=function(e){return'enqueueing "'+e+'" event'},debugPostingEvents=function(e){return"sending "+e+" events"},messages=Object.freeze({clientInitialized:clientInitialized,clientNotReady:clientNotReady,eventWithoutUser:eventWithoutUser,invalidContentType:invalidContentType,invalidKey:invalidKey,localStorageUnavailable:localStorageUnavailable,localStorageUnavailableForUserId:localStorageUnavailableForUserId,networkError:networkError,unknownCustomEventKey:unknownCustomEventKey,environmentNotFound:environmentNotFound,environmentNotSpecified:environmentNotSpecified,errorFetchingFlags:errorFetchingFlags,userNotSpecified:userNotSpecified,invalidUser:invalidUser,bootstrapOldFormat:bootstrapOldFormat,bootstrapInvalid:bootstrapInvalid,deprecated:deprecated,httpErrorMessage:httpErrorMessage,httpUnavailable:httpUnavailable,identifyDisabled:identifyDisabled,streamClosing:streamClosing,streamConnecting:streamConnecting,streamError:streamError,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents});function EventProcessor(e,n,t){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,i={},a=o||EventSender(e,n.eventsUrl,t),u=EventSummarizer(),s=UserFilter(n),c=n.inlineUsersInEvents,l=n.samplingInterval,v=n.flushInterval,d=n.logger,f=[],g=0,p=!1,m=void 0;function y(){return 0===l||0===Math.floor(Math.random()*l)}return i.enqueue=function(e){if(!p){var n,t=!1,r=!1;if(u.summarizeEvent(e),"feature"===e.kind?y()&&(t=!!e.trackEvents,r=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>g&&n.debugEventsUntilDate>(new Date).getTime()):t=y(),t&&f.push(function(e){var n=extend({},e);return c||"identify"===e.kind?n.user=s.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),r){var o=extend({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,f.push(o)}}},i.flush=function(){if(p)return Promise.resolve();var e=f,n=u.getSummary();return u.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(f=[],d.debug(debugPostingEvents(e.length)),a.sendEvents(e).then(function(e){e&&(e.serverTime&&(g=e.serverTime),isHttpErrorRecoverable(e.status)||(p=!0),e.status>=400&&onNextTick(function(){r.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},i.start=function(){m=setTimeout(function e(){i.flush(),m=setTimeout(e,v)},v)},i.stop=function(){clearTimeout(m)},i}function EventEmitter(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=0;n<t[e].length;n++)t[e][n].handler.apply(t[e][n].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}function Store(e,n,t,r,o){var i={};function a(){var e="",o=r.getUser();return o&&(e=t||btoa(JSON.stringify(o))),"ld:"+n+":"+e}return i.loadFlags=function(){return e.get(a()).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=transformValuesToVersionedValues(n):delete n.$schema}return n}catch(e){return i.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i.saveFlags=function(n){var t=extend({},n,{$schema:1});return e.set(a(),JSON.stringify(t)).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i.clearFlags=function(){return e.clear(a()).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},i}function Stream(e,n,t,r){var o=n.streamUrl,i=n.logger,a={},u=o+"/eval/"+t,s=n.useReport,c=n.evaluationReasons,l=n.streamReconnectDelay,v=null,d=null,f=null,g=null;function p(e){i.warn(streamError(e)),h(),m(l)}function m(e){d||(e?d=setTimeout(y,e):y())}function y(){d=null;var n=void 0,a="",l={};if(e.eventSourceFactory){for(var m in null!=r&&(a="h="+r),s?e.eventSourceAllowsReport?(n=u,l.method="REPORT",l.headers={"Content-Type":"application/json"},l.body=JSON.stringify(f)):(n=o+"/ping/"+t,a=""):n=u+"/"+base64URLEncode(JSON.stringify(f)),c&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,h(),i.info(streamConnecting(n)),v=e.eventSourceFactory(n,l),g)g.hasOwnProperty(m)&&v.addEventListener(m,g[m]);v.onerror=p}}function h(){v&&(i.info(streamClosing()),v.close(),v=null)}return a.connect=function(e,n){f=e,g=n,m()},a.disconnect=function(){clearTimeout(d),d=null,h()},a.isConnected=function(){return!!(v&&e.eventSourceIsActive&&e.eventSourceIsActive(v))},a}function promiseCoalescer(e){var n=void 0,t=void 0,r=void 0,o=void 0,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}var json="application/json";function getResponseError(e){return 404===e.status?new LDInvalidEnvironmentIdError(environmentNotFound()):new LDFlagFetchError(errorFetchingFlags(e.statusText||String(e.status)))}function Requestor(e,n,t){var r=n.baseUrl,o=n.useReport,i=n.evaluationReasons,a=n.sendLDHeaders,u=n.logger,s={},c={};function l(n,t){if(!e.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var r=t?"REPORT":"GET",o=a?getLDHeaders(e):{};t&&(o["Content-Type"]="application/json");var i=c[n];i||(i=promiseCoalescer(function(){delete c[n]}),c[n]=i);var u=e.httpRequest(r,n,o,t),s=u.promise.then(function(e){if(200===e.status){if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(json))return JSON.parse(e.body);var n=invalidContentType(e.header("content-type")||"");return Promise.reject(new LDFlagFetchError(n))}return Promise.reject(getResponseError(e))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return i.addPromise(s,function(){u.cancel&&u.cancel()}),i.resultPromise}return s.fetchJSON=function(e){return l(r+e,null)},s.fetchFlagSettings=function(e,n){var a=void 0,s=void 0,c="",v=void 0;return o?(s=[r,"/sdk/evalx/",t,"/user"].join(""),v=JSON.stringify(e)):(a=base64URLEncode(JSON.stringify(e)),s=[r,"/sdk/evalx/",t,"/users/",a].join("")),n&&(c="h="+n),i&&(c=c+(c?"&":"")+"withReasons=true"),s=s+(c?"?":"")+c,u.debug(debugPolling(s)),l(s,v)},s}function Identity(e,n){var t={},r=void 0;return t.setUser=function(e){(r=sanitizeUser(e))&&n&&n(clone(r))},t.getUser=function(){return r?clone(r):null},e&&t.setUser(e),t}function createCommonjsModule(e,n){return e(n={exports:{}},n.exports),n.exports}for(var rngBrowser=createCommonjsModule(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}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var t=n||0,r=byteToHex;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("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||_nodeId,a=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==i||null==a){var u=rngBrowser();null==i&&(i=_nodeId=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=_clockseq=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,l=s-_lastMSecs+(c-_lastNSecs)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>_lastMSecs)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=s,_lastNSecs=c,_clockseq=a;var v=(1e4*(268435455&(s+=122192928e5))+c)%4294967296;o[r++]=v>>>24&255,o[r++]=v>>>16&255,o[r++]=v>>>8&255,o[r++]=255&v;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 f=0;f<6;++f)o[r+f]=i[f];return n||bytesToUuid_1(o)}var v1_1=v1,ldUserIdKey="ld:$anonUserId";function UserValidator(e,n){var t={validateUser:function(t){if(!t)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var r=clone(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(t){if(t)return r.key=t,r;var o=v1_1();return r.key=o,function(t){return e?e.set(ldUserIdKey,t).catch(function(){n.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(o).then(function(){return r})}):Promise.reject(new LDInvalidUserError(invalidUser()))}};return t}function validate(e,n,t,r){var o=extend({logger:r},{baseUrl:"https://app.launchdarkly.com",streamUrl:"https://clientstream.launchdarkly.com",eventsUrl:"https://events.launchdarkly.com",sendEvents:!0,sendLDHeaders:!0,inlineUsersInEvents:!1,allowFrequentDuplicateEvents:!1,sendEventsOnlyForVariation:!1,useReport:!1,evaluationReasons:!1,flushInterval:2e3,samplingInterval:0,streamReconnectDelay:1e3,allAttributesPrivate:!1,privateAttributeNames:[]},t),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames"};function a(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var u=extend({},e||{});return function(e){var n=u;Object.keys(i).forEach(function(e){if(void 0!==n[e]){var t=i[e];r.warn(deprecated(e,t)),void 0===n[t]&&(n[t]=n[e]),delete n[e]}})}(),u=function(e,n){var t=extend({},u);return Object.keys(n).forEach(function(e){void 0!==t[e]&&null!==t[e]||(t[e]=n[e])}),t}(0,o),(isNaN(u.flushInterval)||u.flushInterval<2e3)&&(u.flushInterval=2e3,a("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(u.samplingInterval)||u.samplingInterval<0)&&(u.samplingInterval=0,a("Invalid sampling interval configured. Sampling interval must be an integer >= 0.")),u}function createConsoleLogger(e,n){var t=["debug","info","warn","error"],r=void 0;r=null!=n?""===n?"":n+" ":"LD: ";var o=0;e&&(o="none"===e?100:t.indexOf(e));var i={};function a(e,n,i){if(e>=o){var a=e<t.length?t[e]:"?";n(r+"["+a+"] "+i)}}return i.debug=function(e){return a(0,console.log,e)},i.info=function(e){return a(1,console.info,e)},i.warn=function(e){return a(2,console.warn,e)},i.error=function(e){return a(3,console.error,e)},i}var _typeof$1="function"==typeof Symbol&&"symbol"==_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)},readyEvent="ready",successEvent="initialized",failedEvent="failed",changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,t,r,o){var i=t&&t.logger?t.logger:o&&o.logger||createConsoleLogger("warn"),a=EventEmitter(i),u=validate(t,a,o,i),s=u.hash,c=u.sendEvents,l=e,v=Stream(r,u,l,s),d=u.eventProcessor||EventProcessor(r,u,l,a),f=Requestor(r,u,l),g={},p={},m=void 0,y=void 0,h=u.streaming,E=void 0,b=!1,w=!1,k=!0,S=u.stateProvider,U=Identity(null,function(e){S||e&&L({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),D=UserValidator(r.localStorage,i),P=void 0;function L(e){l&&(S&&S.enqueueEvent&&S.enqueueEvent(e)||(e.user?(k=!1,!c||w||r.isDoNotTrack()||(i.debug(debugEnqueueingEvent(e.kind)),d.enqueue(e))):k&&(i.warn(eventWithoutUser()),k=!1)))}function I(e,n,t,r){var o=U.getUser(),i=new Date,a=n?n.value:null;if(!u.allowFrequentDuplicateEvents){var s=JSON.stringify(a)+(o&&o.key?o.key:"")+e,c=g[s];if(c&&i-c<3e5)return;g[s]=i}var l={kind:"feature",key:e,user:o,value:a,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()},v=p[e];v&&(l.version=v.flagVersion?v.flagVersion:v.version,l.trackEvents=v.trackEvents,l.debugEventsUntilDate=v.debugEventsUntilDate),(r||v&&v.trackReason)&&n&&(l.reason=n.reason),L(l)}function R(e,n,t,r){var o=void 0;if(p&&p.hasOwnProperty(e)&&p[e]&&!p[e].deleted){var i=p[e];o=T(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&&I(e,o,n,r),o}function T(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function C(){y=!0,U.getUser()&&v.connect(U.getUser(),{ping:function(){i.debug(debugStreamPing()),f.fetchFlagSettings(U.getUser(),s).then(function(e){return N(e||{})}).catch(function(e){a.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var n=JSON.parse(e.data);i.debug(debugStreamPut()),N(n)},patch:function(e){var n=JSON.parse(e.data),t=p[n.key];if(!t||!t.version||!n.version||t.version<n.version){i.debug(debugStreamPatch(n.key));var r={},o=extend({},n);delete o.key,p[n.key]=o;var a=T(o);r[n.key]=t?{previous:t.value,current:a}:{current:a},x(r)}else i.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!p[n.key]||p[n.key].version<n.version){i.debug(debugStreamDelete(n.key));var t={};p[n.key]&&!p[n.key].deleted&&(t[n.key]={previous:p[n.key].value}),p[n.key]={version:n.version,deleted:!0},x(t)}else i.debug(debugStreamDeleteIgnored(n.key))}})}function F(){y&&(v.disconnect(),y=!1)}function N(e){var n={};if(!e)return Promise.resolve();for(var t in p)p.hasOwnProperty(t)&&p[t]&&(e[t]&&!deepEquals(e[t].value,p[t].value)?n[t]={previous:p[t].value,current:T(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:p[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!p[r]||p[r].deleted)&&(n[r]={current:T(e[r])});return p=Object.assign({},e),x(n).catch(function(){})}function x(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;a.emit(changeEvent+":"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}}),a.emit(changeEvent,t),a.emit(internalChangeEvent,p),u.sendEventsOnlyForVariation||S||n.forEach(function(n){I(n,e[n].current)})}return m&&P?P.saveFlags(p).catch(function(){return null}):Promise.resolve()}function O(){var e=h||E&&void 0===h;e&&!y?C():!e&&y&&F()}function A(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}r.localStorage&&(P=new Store(r.localStorage,l,s,U,i));var j=new Promise(function(e){var n=a.on(readyEvent,function(){a.off(readyEvent,n),e()})}),_=new Promise(function(e,n){var t=a.on(successEvent,function(){a.off(successEvent,t),e()}),r=a.on(failedEvent,function(e){a.off(failedEvent,r),n(e)})});if("string"==typeof u.bootstrap&&"LOCALSTORAGE"===u.bootstrap.toUpperCase()&&(P?m=!0:i.warn(localStorageUnavailable())),"object"===_typeof$1(u.bootstrap)&&(p=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&i.warn(bootstrapOldFormat()),!1===e.$valid&&i.warn(bootstrapInvalid());var r={};return n.forEach(function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};t&&t[n]?o=extend(o,t[n]):o.version=0,r[n]=o}}),r}(u.bootstrap)),S){var q=S.getInitialState();q?V(q):S.on("init",V),S.on("update",function(e){e.user&&U.setUser(e.user),e.flags&&N(e.flags)})}else(e?D.validateUser(n).then(function(e){return U.setUser(e),"object"===_typeof$1(u.bootstrap)?z():m?P.loadFlags().catch(function(){return null}).then(function(e){return null==e?(p={},f.fetchFlagSettings(U.getUser(),s).then(function(e){return N(e||{})}).then(z).catch(function(e){H(new LDFlagFetchError(errorFetchingFlags(e)))})):(p=e,onNextTick(z),f.fetchFlagSettings(U.getUser(),s).then(function(e){return N(e)}).catch(function(e){return a.maybeReportError(e)}))}):f.fetchFlagSettings(U.getUser(),s).then(function(e){p=e||{},z()}).catch(function(e){p={},H(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(function(e){return a.maybeReportError(e)});function V(e){l=e.environment,U.setUser(e.user),p=Object.assign({},e.flags),onNextTick(z)}function z(){i.info(clientInitialized()),b=!0,O(),a.emit(readyEvent),a.emit(successEvent)}function H(e){a.maybeReportError(e),a.emit(failedEvent,e),a.emit(readyEvent)}return{client:{waitForInitialization:function(){return _},waitUntilReady:function(){return j},identify:function(e,n,t){return w?wrapPromiseCallback(Promise.resolve({}),t):S?(i.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(p)),t)):wrapPromiseCallback((m&&P?P.clearFlags():Promise.resolve()).then(function(){return D.validateUser(e)}).then(function(e){return U.setUser(e)}).then(function(){return f.fetchFlagSettings(U.getUser(),n)}).then(function(e){var n=transformVersionedValuesToValues(e);return e?N(e).then(function(){return n}):n}).then(function(e){return y&&C(),e}).catch(function(e){return a.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return U.getUser()},variation:function(e,n){return R(e,n,!0,!1).value},variationDetail:function(e,n){return R(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){r.customEventFilter&&!r.customEventFilter(e)&&i.warn(unknownCustomEventKey(e));var o={kind:"custom",key:e,user:U.getUser(),url:r.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(o.data=n),null!=t&&(o.metricValue=t),L(o)}else a.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,t){A(e)?(E=!0,b&&O(),a.on(e,n,t)):a.on.apply(a,arguments)},off:function(e){if(a.off.apply(a,arguments),A(e)){var n=!1;a.getEvents().forEach(function(e){A(e)&&a.getEventListenerCount(e)>0&&(n=!0)}),n||(E=!1,y&&void 0===h&&F())}},setStreaming:function(e){var n=null===e?void 0:e;n!==h&&(h=n,O())},flush:function(e){return wrapPromiseCallback(c?d.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!p)return e;for(var n in p)p.hasOwnProperty(n)&&(e[n]=R(n,null,!u.sendEventsOnlyForVariation).value);return e},close:function(e){if(w)return wrapPromiseCallback(Promise.resolve(),e);var n=function(){w=!0,p={}};return wrapPromiseCallback(Promise.resolve().then(function(){if(F(),c)return d.stop(),d.flush()}).then(n).catch(n),e)}},options:u,emitter:a,ident:U,logger:i,requestor:f,start:function(){c&&d.start()},enqueueEvent:L,getFlagsInternal:function(){return p},getEnvironmentId:function(){return l},internalChangeEventName:internalChangeEvent}}var version="2.14.0";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||{})t.hasOwnProperty(a)&&i.setRequestHeader(a,t[a]);if(o)return i.send(r),emptyResult;var u=void 0;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={pageIsClosing:!1};window.XMLHttpRequest&&(n.httpRequest=function(e,t,r,o){return newHttpRequest(e,t,r,o,n.pageIsClosing)});var t=void 0;n.httpAllowsPost=function(){return void 0===t&&(t=!!window.XMLHttpRequest&&"withCredentials"in new window.XMLHttpRequest),t};var r=e&&e.eventUrlTransformer;n.getCurrentUrl=function(){return r?r(window.location.href):window.location.href},n.isDoNotTrack=function(){var e=void 0;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&&(n.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){n.localStorage=null}var o=void 0;if(e&&e.useReport&&"function"==typeof window.EventSourcePolyfill&&window.EventSourcePolyfill.supportedOptions&&window.EventSourcePolyfill.supportedOptions.method?(n.eventSourceAllowsReport=!0,o=window.EventSourcePolyfill):(n.eventSourceAllowsReport=!1,o=window.EventSource),window.EventSource){n.eventSourceFactory=function(e,n){var t={heartbeatTimeout:3e5,silentTimeout:3e5,skipDefaultHeaders:!0},r=Object.assign({},t,n);return new o(e,r)},n.eventSourceIsActive=function(e){return e.readyState===window.EventSource.OPEN||e.readyState===window.EventSource.CONNECTING}}return n.userAgent="JSClient",n}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=n.replace(t,"").replace(r,""),i=void 0,a=void 0;switch(e.kind){case"exact":a=n,i=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"canonical":a=o,i=new RegExp("^"+escapeStringRegexp(e.url)+"/?$");break;case"substring":a=o,i=new RegExp(".*"+escapeStringRegexp(e.substring)+".*$");break;case"regex":a=o,i=new RegExp(e.pattern);break;default:return!1}return i.test(a)}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&&u.length>0;){for(var s=0;s<u.length;s++)o===u[s]&&t.push(i);o=o.parentNode}return t}function GoalTracker(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(doesUrlMatch(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=findGoalsForClick(e,o),r=0;r<t.length;r++)n("click",t[r])},document.addEventListener("click",r)),t.dispose=function(){document.removeEventListener("click",r)},t}var locationWatcherInterval=300;function GoalManager(e,n){var t=void 0,r=void 0,o={};function i(){r&&r.dispose(),t&&t.length&&(r=GoalTracker(t,a))}function a(n,t){var r={kind:n,key:t.key,data:null,url:window.location.href,user:e.ident.getUser(),creationDate:(new Date).getTime()};return"click"===n&&(r.selector=t.selector),e.enqueueEvent(r)}return o.goalKeyExists=function(e){if(!t)return!0;for(var n=0;n<t.length;n++)if("custom"===t[n].kind&&t[n].key===e)return!0;return!1},e.requestor.fetchJSON("/sdk/goals/"+e.getEnvironmentId()).then(function(e){e&&e.length>0&&(r=GoalTracker(t=e,a),function(e,n){var t=window.location.href,r=void 0;function o(){(r=window.location.href)!==t&&(t=r,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)}(locationWatcherInterval,i)),n()}).catch(function(t){e.emitter.maybeReportError(new errors.LDUnexpectedResponseError((t&&t.message,t.message))),n()}),o}var goalsEvent="goalsReady",extraDefaults={fetchGoals:!0};function initialize$1(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=makeBrowserPlatform(t),o=initialize(e,n,t,r,extraDefaults),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()})});if(i.waitUntilGoalsReady=function(){return s},a.fetchGoals){var c=GoalManager(o,function(){return u.emit(goalsEvent)});r.customEventFilter=c.goalKeyExists}else u.emit(goalsEvent);return"complete"!==document.readyState?window.addEventListener("load",o.start):o.start(),window.addEventListener("beforeunload",function(){r.pageIsClosing=!0,i.close()}),i}var createConsoleLogger$1=createConsoleLogger,version$1=version;function deprecatedInitialize(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return console&&console.warn&&console.warn(messages.deprecated("default export","named LDClient export")),initialize$1(e,n,t)}var index={initialize:deprecatedInitialize,version:version};export default index;export{initialize$1 as initialize,createConsoleLogger$1 as createConsoleLogger,version$1 as version}; | ||
//# sourceMappingURL=ldclient.es.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.LDClient={})}(this,function(e){"use strict";var n="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};function t(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 r=t("LaunchDarklyUnexpectedResponseError"),o=t("LaunchDarklyInvalidEnvironmentIdError"),i=t("LaunchDarklyInvalidUserError"),a=t("LaunchDarklyInvalidEventKeyError"),u=t("LaunchDarklyInvalidArgumentError"),s=t("LaunchDarklyFlagFetchError");function c(e){return!(e>=400&&e<500)||400===e||408===e||429===e}for(var l=Object.freeze({LDUnexpectedResponseError:r,LDInvalidEnvironmentIdError:o,LDInvalidUserError:i,LDInvalidEventKeyError:a,LDInvalidArgumentError:u,LDFlagFetchError:s,isHttpErrorRecoverable:c}),f=function(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(y(e,i,i+16383>a?a:i+16383));return 1===r?(n=e[t-1],o.push(v[n>>2]+v[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(v[n>>10]+v[n>>4&63]+v[n<<2&63]+"=")),o.join("")},v=[],d=[],g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=0,m=g.length;p<m;++p)v[p]=g[p],d[g.charCodeAt(p)]=p;function h(e){return v[e>>18&63]+v[e>>12&63]+v[e>>6&63]+v[63&e]}function y(e,n,t){for(var r,o=[],i=n;i<t;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(h(r));return o.join("")}d["-".charCodeAt(0)]=62,d["_".charCodeAt(0)]=63;var w="function"==typeof Symbol&&"symbol"==n(Symbol.iterator)?function(e){return void 0===e?"undefined":n(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":n(e)},b=Array.isArray,k=Object.keys,E=Object.prototype.hasOwnProperty,S=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==(void 0===n?"undefined":w(n))&&"object"==(void 0===t?"undefined":w(t))){var r,o,i,a=b(n),u=b(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 v=k(n);if((o=v.length)!==k(t).length)return!1;for(r=o;0!=r--;)if(!E.call(t,v[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=v[r]],t[i]))return!1;return!0}return n!=n&&t!=t},P=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},D=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function O(e){var n=unescape(encodeURIComponent(e));return f(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function U(e){return O(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function R(e){return JSON.parse(JSON.stringify(e))}function I(e,n){return S(e,n)}function N(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 j(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function L(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function x(e,n){for(var t=n.slice(0),r=[],o=e,i=void 0;t.length>0;){for(i=[];o>0;){var a=t.shift();if(!a)break;(o-=U(JSON.stringify(a)).length)<0&&i.length>0?t.unshift(a):i.push(a)}o=e,r.push(i)}return r}function C(e){var n=e.version||"2.13.0";return e.userAgent+"/"+n}function F(e){return{"X-LaunchDarkly-User-Agent":C(e)}}function A(){for(var e=arguments.length,n=Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return P({},e,n)},{})}function q(e){if(!e)return e;var n=void 0;for(var t in D){var r=D[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[r]=String(o))}return n||e}Object.freeze({btoa:O,base64URLEncode:U,clone:R,deepEquals:I,onNextTick:N,wrapPromiseCallback:T,transformValuesToVersionedValues:j,transformVersionedValuesToValues:L,chunkUserEventsForUrl:x,getLDUserAgentString:C,getLDHeaders:F,extend:A,sanitizeUser:q});var J=2e3;function z(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var V=function(){return"LaunchDarkly client initialized"},H=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",$=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"},M=function(e){return'Expected application/json content type but got "'+e+'"'},K=function(){return"localStorage is unavailable"},_=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},G=function(e){return"network error"+(e?" ("+e+")":"")},X=function(e){return'Custom event "'+e+'" does not exist'},B=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+H},W=function(){return"No environment/client-side ID was specified."+H},Q=function(e){return"Error fetching flag settings: "+z(e)},Y=function(){return"No user specified."+H},Z=function(){return"Invalid user specified."+H},ee=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+H},ne=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},te=function(e,n){return'[LaunchDarkly] "'+e+'" is deprecated, please use "'+n+'"'},re=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(c(e)?t:"giving up permanently")},oe=function(){return"Cannot make HTTP requests in this environment."+H},ie=function(){return"identify() has no effect here; it must be called on the main client instance"},ae=function(){return"Closing stream connection"},ue=function(e){return"Opening stream connection to "+e},se=function(e){return"Error on stream connection: "+z(e)},ce=function(e){return"polling for feature flags at "+e},le=function(){return"received ping message from stream"},fe=function(){return"received streaming update for all flags"},ve=function(e){return'received streaming update for flag "'+e+'"'},de=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},ge=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'},me=function(e){return'enqueueing "'+e+'" event'},he=function(e){return"sending "+e+" events"},ye=Object.freeze({clientInitialized:V,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventWithoutUser:$,invalidContentType:M,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:K,localStorageUnavailableForUserId:_,networkError:G,unknownCustomEventKey:X,environmentNotFound:B,environmentNotSpecified:W,errorFetchingFlags:Q,userNotSpecified:Y,invalidUser:Z,bootstrapOldFormat:ee,bootstrapInvalid:ne,deprecated:te,httpErrorMessage:re,httpUnavailable:oe,identifyDisabled:ie,streamClosing:ae,streamConnecting:ue,streamError:se,debugPolling:ce,debugStreamPing:le,debugStreamPut:fe,debugStreamPatch:ve,debugStreamPatchIgnored:de,debugStreamDelete:ge,debugStreamDeleteIgnored:pe,debugEnqueueingEvent:me,debugPostingEvents:he});function we(e,n,t){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a={},u=i||function(e,n,t,r){var o=n+"/events/bulk/"+t,i=n+"/a/"+t+".gif",a={};function u(e){(new window.Image).src=e}function s(n,t){var a=r||u,s=JSON.stringify(n);return t?function n(t){var r=A({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},F(e));return e.httpRequest("POST",o,r,s).promise.then(function(e){if(e)return e.status>=400&&c(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(){}):(a(i+"?d="+U(s)),Promise.resolve())}return a.sendEvents=function(t){if(!e.httpRequest)return Promise.resolve();var r,o=e.httpAllowsPost();r=o?[t]:x(J-n.length,t);for(var i=[],a=0;a<r.length;a++)i.push(s(r[a],o));return Promise.all(i)},a}(e,n.eventsUrl,t),s=function(){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}(),l=function(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=A({},c,l[1])}var f=Object.keys(c);return f.length&&(f.sort(),s.privateAttrs=f),s},n}(n),f=n.inlineUsersInEvents,v=n.samplingInterval,d=n.flushInterval,g=n.logger,p=[],m=0,h=!1,y=void 0;function w(){return 0===v||0===Math.floor(Math.random()*v)}return a.enqueue=function(e){if(!h){var n,t=!1,r=!1;if(s.summarizeEvent(e),"feature"===e.kind?w()&&(t=!!e.trackEvents,r=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>m&&n.debugEventsUntilDate>(new Date).getTime()):t=w(),t&&p.push(function(e){var n=A({},e);return f||"identify"===e.kind?n.user=l.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),r){var o=A({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,p.push(o)}}},a.flush=function(){if(h)return Promise.resolve();var e=p,n=s.getSummary();return s.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(p=[],g.debug(he(e.length)),u.sendEvents(e).then(function(e){e&&(e.serverTime&&(m=e.serverTime),c(e.status)||(h=!0),e.status>=400&&N(function(){o.maybeReportError(new r(re(e.status,"event posting","some events were dropped")))}))}))},a.start=function(){y=setTimeout(function e(){a.flush(),y=setTimeout(e,d)},d)},a.stop=function(){clearTimeout(y)},a}var be,ke,Ee="application/json";function Se(e,n,t){var r=n.baseUrl,i=n.useReport,a=n.evaluationReasons,u=n.sendLDHeaders,c=n.logger,l={},f={};function v(n,t){if(!e.httpRequest)return new Promise(function(e,n){n(new s(oe()))});var r=t?"REPORT":"GET",i=u?F(e):{};t&&(i["Content-Type"]="application/json");var a=f[n];a||(a=function(e){var n=void 0,t=void 0,r=void 0,o=void 0,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 f[n]}),f[n]=a);var c=e.httpRequest(r,n,i,t),l=c.promise.then(function(e){if(200===e.status){if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(Ee))return JSON.parse(e.body);var n=M(e.header("content-type")||"");return Promise.reject(new s(n))}return Promise.reject(function(e){return 404===e.status?new o(B()):new s(Q(e.statusText||String(e.status)))}(e))},function(e){return Promise.reject(new s(G(e)))});return a.addPromise(l,function(){c.cancel&&c.cancel()}),a.resultPromise}return l.fetchJSON=function(e){return v(r+e,null)},l.fetchFlagSettings=function(e,n){var o=void 0,u=void 0,s="",l=void 0;return i?(u=[r,"/sdk/evalx/",t,"/user"].join(""),l=JSON.stringify(e)):(o=U(JSON.stringify(e)),u=[r,"/sdk/evalx/",t,"/users/",o].join("")),n&&(s="h="+n),a&&(s=s+(s?"&":"")+"withReasons=true"),u=u+(s?"?":"")+s,c.debug(ce(u)),v(u,l)},l}for(var Pe=(be=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}}},ke=void 0,be(ke={exports:{}},ke.exports),ke.exports),De=[],Oe=0;Oe<256;++Oe)De[Oe]=(Oe+256).toString(16).substr(1);var Ue,Re,Ie=function(e,n){var t=n||0,r=De;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("")},Ne=0,Te=0;var je=function(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||Ue,a=void 0!==e.clockseq?e.clockseq:Re;if(null==i||null==a){var u=Pe();null==i&&(i=Ue=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=Re=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:Te+1,l=s-Ne+(c-Te)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>Ne)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Ne=s,Te=c,Re=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 v=s/4294967296*1e4&268435455;o[r++]=v>>>8&255,o[r++]=255&v,o[r++]=v>>>24&15|16,o[r++]=v>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var d=0;d<6;++d)o[r+d]=i[d];return n||Ie(o)},Le="ld:$anonUserId";function xe(e){var n=0;e&&(n="none"===e?100:["debug","info","warn","error"].indexOf(e));var t={};function r(e,t,r){e>=n&&t(r)}return t.debug=function(e){return r(0,console.log,e)},t.info=function(e){return r(1,console.info,e)},t.warn=function(e){return r(2,console.warn,e)},t.error=function(e){return r(3,console.error,e)},t}var Ce="function"==typeof Symbol&&"symbol"==n(Symbol.iterator)?function(e){return void 0===e?"undefined":n(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":n(e)},Fe="ready",Ae="initialized",qe="failed",Je="change",ze="internal-change";function Ve(e,n,t,r,c){var l=t&&t.logger?t.logger:c&&c.logger||xe("warn"),f=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=0;n<t[e].length;n++)t[e][n].handler.apply(t[e][n].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}(l),v=function(e,n,t,r){var o=A({logger:r},{baseUrl:"https://app.launchdarkly.com",streamUrl:"https://clientstream.launchdarkly.com",eventsUrl:"https://events.launchdarkly.com",sendEvents:!0,sendLDHeaders:!0,inlineUsersInEvents:!1,allowFrequentDuplicateEvents:!1,sendEventsOnlyForVariation:!1,useReport:!1,evaluationReasons:!1,flushInterval:2e3,samplingInterval:0,streamReconnectDelay:1e3,allAttributesPrivate:!1,privateAttributeNames:[]},t),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames"};function a(e){N(function(){n&&n.maybeReportError(new u(e))})}var s=A({},e||{});return function(e){var n=s;Object.keys(i).forEach(function(e){if(void 0!==n[e]){var t=i[e];r.warn(te(e,t)),void 0===n[t]&&(n[t]=n[e]),delete n[e]}})}(),s=function(e,n){var t=A({},s);return Object.keys(n).forEach(function(e){void 0!==t[e]&&null!==t[e]||(t[e]=n[e])}),t}(0,o),(isNaN(s.flushInterval)||s.flushInterval<2e3)&&(s.flushInterval=2e3,a("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(s.samplingInterval)||s.samplingInterval<0)&&(s.samplingInterval=0,a("Invalid sampling interval configured. Sampling interval must be an integer >= 0.")),s}(t,f,c,l),d=v.hash,g=v.sendEvents,p=e,m=function(e,n,t,r){var o=n.streamUrl,i=n.logger,a={},u=o+"/eval/"+t,s=n.useReport,c=n.evaluationReasons,l=n.streamReconnectDelay,f=null,v=null,d=null,g=null;function p(e){i.warn(se(e)),y(),m(l)}function m(e){v||(e?v=setTimeout(h,e):h())}function h(){v=null;var n=void 0,a="",l={};if(e.eventSourceFactory){for(var m in null!=r&&(a="h="+r),s?e.eventSourceAllowsReport?(n=u,l.method="REPORT",l.headers={"Content-Type":"application/json"},l.body=JSON.stringify(d)):(n=o+"/ping/"+t,a=""):n=u+"/"+U(JSON.stringify(d)),c&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,y(),i.info(ue(n)),f=e.eventSourceFactory(n,l),g)g.hasOwnProperty(m)&&f.addEventListener(m,g[m]);f.onerror=p}}function y(){f&&(i.info(ae()),f.close(),f=null)}return a.connect=function(e,n){d=e,g=n,m()},a.disconnect=function(){clearTimeout(v),v=null,y()},a.isConnected=function(){return!!(f&&e.eventSourceIsActive&&e.eventSourceIsActive(f))},a}(r,v,p,d),h=v.eventProcessor||we(r,v,p,f),y=Se(r,v,p),w={},b={},k=void 0,E=void 0,S=v.streaming,P=void 0,D=!1,x=!1,C=!0,F=v.stateProvider,J=function(e,n){var t={},r=void 0;return t.setUser=function(e){(r=q(e))&&n&&n(R(r))},t.getUser=function(){return r?R(r):null},e&&t.setUser(e),t}(null,function(e){F||e&&M({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),z=function(e,n){var t={validateUser:function(t){if(!t)return Promise.reject(new i(Y()));var r=R(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get(Le).catch(function(){return null}):Promise.resolve(null)).then(function(t){if(t)return r.key=t,r;var o=je();return r.key=o,function(t){return e?e.set(Le,t).catch(function(){n.warn(_())}):Promise.resolve()}(o).then(function(){return r})}):Promise.reject(new i(Z()))}};return t}(r.localStorage,l),H=void 0;function M(e){p&&(F&&F.enqueueEvent&&F.enqueueEvent(e)||(e.user?(C=!1,!g||x||r.isDoNotTrack()||(l.debug(me(e.kind)),h.enqueue(e))):C&&(l.warn($()),C=!1)))}function G(e,n,t){var r=J.getUser(),o=new Date,i=n?n.value:null;if(!v.allowFrequentDuplicateEvents){var a=JSON.stringify(i)+(r&&r.key?r.key:"")+e,u=w[a];if(u&&o-u<3e5)return;w[a]=o}var s={kind:"feature",key:e,user:r,value:i,variation:n?n.variationIndex:null,default:t,creationDate:o.getTime(),reason:n?n.reason:null},c=b[e];c&&(s.version=c.flagVersion?c.flagVersion:c.version,s.trackEvents=c.trackEvents,s.debugEventsUntilDate=c.debugEventsUntilDate),M(s)}function B(e,n,t){var r=void 0;if(b&&b.hasOwnProperty(e)&&b[e]&&!b[e].deleted){var o=b[e];r=re(o),null!==o.value&&void 0!==o.value||(r.value=n)}else r={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&G(e,r,n),r}function re(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function oe(){E=!0,J.getUser()&&m.connect(J.getUser(),{ping:function(){l.debug(le()),y.fetchFlagSettings(J.getUser(),d).then(function(e){return he(e||{})}).catch(function(e){f.maybeReportError(new s(Q(e)))})},put:function(e){var n=JSON.parse(e.data);l.debug(fe()),he(n)},patch:function(e){var n=JSON.parse(e.data),t=b[n.key];if(!t||!t.version||!n.version||t.version<n.version){l.debug(ve(n.key));var r={},o=A({},n);delete o.key,b[n.key]=o;var i=re(o);r[n.key]=t?{previous:t.value,current:i}:{current:i},ye(r)}else l.debug(de(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!b[n.key]||b[n.key].version<n.version){l.debug(ge(n.key));var t={};b[n.key]&&!b[n.key].deleted&&(t[n.key]={previous:b[n.key].value}),b[n.key]={version:n.version,deleted:!0},ye(t)}else l.debug(pe(n.key))}})}function ce(){E&&(m.disconnect(),E=!1)}function he(e){var n={};if(!e)return Promise.resolve();for(var t in b)b.hasOwnProperty(t)&&b[t]&&(e[t]&&!I(e[t].value,b[t].value)?n[t]={previous:b[t].value,current:re(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:b[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!b[r]||b[r].deleted)&&(n[r]={current:re(e[r])});return b=Object.assign({},e),ye(n).catch(function(){})}function ye(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;f.emit(Je+":"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}}),f.emit(Je,t),f.emit(ze,b),v.sendEventsOnlyForVariation||F||n.forEach(function(n){G(n,e[n].current)})}return k&&H?H.saveFlags(b).catch(function(){return null}):Promise.resolve()}function be(){var e=S||P&&void 0===S;e&&!E?oe():!e&&E&&ce()}function ke(e){return e===Je||e.substr(0,Je.length+1)===Je+":"}r.localStorage&&(H=new function(e,n,t,r,o){var i={};function a(){var e="",o=r.getUser();return o&&(e=t||O(JSON.stringify(o))),"ld:"+n+":"+e}return i.loadFlags=function(){return e.get(a()).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=j(n):delete n.$schema}return n}catch(e){return i.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(K()),Promise.reject(e)})},i.saveFlags=function(n){var t=A({},n,{$schema:1});return e.set(a(),JSON.stringify(t)).catch(function(e){return o.warn(K()),Promise.reject(e)})},i.clearFlags=function(){return e.clear(a()).catch(function(e){return o.warn(K()),Promise.reject(e)})},i}(r.localStorage,p,d,J,l));var Ee=new Promise(function(e){var n=f.on(Fe,function(){f.off(Fe,n),e()})}),Pe=new Promise(function(e,n){var t=f.on(Ae,function(){f.off(Ae,t),e()}),r=f.on(qe,function(e){f.off(qe,r),n(e)})});if("string"==typeof v.bootstrap&&"LOCALSTORAGE"===v.bootstrap.toUpperCase()&&(H?k=!0:l.warn(K())),"object"===Ce(v.bootstrap)&&(b=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&l.warn(ee()),!1===e.$valid&&l.warn(ne());var r={};return n.forEach(function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};t&&t[n]?o=A(o,t[n]):o.version=0,r[n]=o}}),r}(v.bootstrap)),F){var De=F.getInitialState();De?Oe(De):F.on("init",Oe),F.on("update",function(e){e.user&&J.setUser(e.user),e.flags&&he(e.flags)})}else(e?z.validateUser(n).then(function(e){return J.setUser(e),"object"===Ce(v.bootstrap)?Ue():k?H.loadFlags().catch(function(){return null}).then(function(e){return null==e?(b={},y.fetchFlagSettings(J.getUser(),d).then(function(e){return he(e||{})}).then(Ue).catch(function(e){Re(new s(Q(e)))})):(b=e,N(Ue),y.fetchFlagSettings(J.getUser(),d).then(function(e){return he(e)}).catch(function(e){return f.maybeReportError(e)}))}):y.fetchFlagSettings(J.getUser(),d).then(function(e){b=e||{},Ue()}).catch(function(e){b={},Re(e)})}):Promise.reject(new o(W()))).catch(function(e){return f.maybeReportError(e)});function Oe(e){p=e.environment,J.setUser(e.user),b=Object.assign({},e.flags),N(Ue)}function Ue(){l.info(V()),D=!0,be(),f.emit(Fe),f.emit(Ae)}function Re(e){f.maybeReportError(e),f.emit(qe,e),f.emit(Fe)}return{client:{waitForInitialization:function(){return Pe},waitUntilReady:function(){return Ee},identify:function(e,n,t){return x?T(Promise.resolve({}),t):F?(l.warn(ie()),T(Promise.resolve(L(b)),t)):T((k&&H?H.clearFlags():Promise.resolve()).then(function(){return z.validateUser(e)}).then(function(e){return J.setUser(e)}).then(function(){return y.fetchFlagSettings(J.getUser(),n)}).then(function(e){var n=L(e);return e?he(e).then(function(){return n}):n}).then(function(e){return E&&oe(),e}).catch(function(e){return f.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return J.getUser()},variation:function(e,n){return B(e,n,!0).value},variationDetail:function(e,n){return B(e,n,!0)},track:function(e,n){"string"==typeof e?(r.customEventFilter&&!r.customEventFilter(e)&&l.warn(X(e)),M({kind:"custom",key:e,data:n,user:J.getUser(),url:r.getCurrentUrl(),creationDate:(new Date).getTime()})):f.maybeReportError(new a(X(e)))},on:function(e,n,t){ke(e)?(P=!0,D&&be(),f.on(e,n,t)):f.on.apply(f,arguments)},off:function(e){if(f.off.apply(f,arguments),ke(e)){var n=!1;f.getEvents().forEach(function(e){ke(e)&&f.getEventListenerCount(e)>0&&(n=!0)}),n||(P=!1,E&&void 0===S&&ce())}},setStreaming:function(e){var n=null===e?void 0:e;n!==S&&(S=n,be())},flush:function(e){return T(g?h.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!b)return e;for(var n in b)b.hasOwnProperty(n)&&(e[n]=B(n,null,!v.sendEventsOnlyForVariation).value);return e},close:function(e){if(x)return T(Promise.resolve(),e);var n=function(){x=!0,b={}};return T(Promise.resolve().then(function(){if(ce(),g)return h.stop(),h.flush()}).then(n).catch(n),e)}},options:v,emitter:f,ident:J,logger:l,requestor:y,start:function(){g&&h.start()},enqueueEvent:M,getFlagsInternal:function(){return b},getEnvironmentId:function(){return p},internalChangeEventName:ze}}var He={promise:Promise.resolve({status:200,header:function(){return null},body:null})};function $e(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 He;var i=new window.XMLHttpRequest;for(var a in i.open(e,n,!o),t||{})t.hasOwnProperty(a)&&i.setRequestHeader(a,t[a]);if(o)return i.send(r),He;var u=void 0;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()}}}var Me=/[|\\{}()[\]^$+*?.]/g,Ke=function(e){if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(Me,"\\$&")};function _e(e,n,t,r){var o=n.replace(t,"").replace(r,""),i=void 0,a=void 0;switch(e.kind){case"exact":a=n,i=new RegExp("^"+Ke(e.url)+"/?$");break;case"canonical":a=o,i=new RegExp("^"+Ke(e.url)+"/?$");break;case"substring":a=o,i=new RegExp(".*"+Ke(e.substring)+".*$");break;case"regex":a=o,i=new RegExp(e.pattern);break;default:return!1}return i.test(a)}function Ge(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(_e(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}var Xe=300;function Be(e,n){var t=void 0,r=void 0,o={};function i(){r&&r.dispose(),t&&t.length&&(r=Ge(t,a))}function a(n,t){var r={kind:n,key:t.key,data:null,url:window.location.href,user:e.ident.getUser(),creationDate:(new Date).getTime()};return"click"===n&&(r.selector=t.selector),e.enqueueEvent(r)}return o.goalKeyExists=function(e){if(!t)return!0;for(var n=0;n<t.length;n++)if("custom"===t[n].kind&&t[n].key===e)return!0;return!1},e.requestor.fetchJSON("/sdk/goals/"+e.getEnvironmentId()).then(function(e){e&&e.length>0&&(r=Ge(t=e,a),function(e,n){var t=window.location.href,r=void 0;function o(){(r=window.location.href)!==t&&(t=r,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)}(Xe,i)),n()}).catch(function(t){e.emitter.maybeReportError(new l.LDUnexpectedResponseError((t&&t.message,t.message))),n()}),o}var We="goalsReady",Qe={fetchGoals:!0};function Ye(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=function(e){var n={pageIsClosing:!1};window.XMLHttpRequest&&(n.httpRequest=function(e,t,r,o){return $e(e,t,r,o,n.pageIsClosing)});var t=void 0;n.httpAllowsPost=function(){return void 0===t&&(t=!!window.XMLHttpRequest&&"withCredentials"in new window.XMLHttpRequest),t};var r=e&&e.eventUrlTransformer;n.getCurrentUrl=function(){return r?r(window.location.href):window.location.href},n.isDoNotTrack=function(){var e=void 0;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&&(n.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){n.localStorage=null}var o=void 0;e&&e.useReport&&"function"==typeof window.EventSourcePolyfill&&window.EventSourcePolyfill.supportedOptions&&window.EventSourcePolyfill.supportedOptions.method?(n.eventSourceAllowsReport=!0,o=window.EventSourcePolyfill):(n.eventSourceAllowsReport=!1,o=window.EventSource),window.EventSource&&(n.eventSourceFactory=function(e,n){var t={heartbeatTimeout:3e5,silentTimeout:3e5,skipDefaultHeaders:!0},r=Object.assign({},t,n);return new o(e,r)},n.eventSourceIsActive=function(e){return e.readyState===window.EventSource.OPEN||e.readyState===window.EventSource.CONNECTING});return n.userAgent="JSClient",n}(t),o=Ve(e,n,t,r,Qe),i=o.client,a=o.options,u=o.emitter,s=new Promise(function(e){var n=u.on(We,function(){u.off(We,n),e()})});if(i.waitUntilGoalsReady=function(){return s},a.fetchGoals){var c=Be(o,function(){return u.emit(We)});r.customEventFilter=c.goalKeyExists}else u.emit(We);return"complete"!==document.readyState?window.addEventListener("load",o.start):o.start(),window.addEventListener("beforeunload",function(){r.pageIsClosing=!0,i.close()}),i}var Ze=xe;var en={initialize:function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return console&&console.warn&&console.warn(ye.deprecated("default export","named LDClient export")),Ye(e,n,t)},version:"2.13.0"};e.initialize=Ye,e.createConsoleLogger=Ze,e.version="2.13.0",e.default=en,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.LDClient={})}(this,function(e){"use strict";var n="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};function t(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 r=t("LaunchDarklyUnexpectedResponseError"),o=t("LaunchDarklyInvalidEnvironmentIdError"),i=t("LaunchDarklyInvalidUserError"),a=t("LaunchDarklyInvalidEventKeyError"),u=t("LaunchDarklyInvalidArgumentError"),s=t("LaunchDarklyFlagFetchError");function c(e){return!(e>=400&&e<500)||400===e||408===e||429===e}for(var l=Object.freeze({LDUnexpectedResponseError:r,LDInvalidEnvironmentIdError:o,LDInvalidUserError:i,LDInvalidEventKeyError:a,LDInvalidArgumentError:u,LDFlagFetchError:s,isHttpErrorRecoverable:c}),f=function(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(y(e,i,i+16383>a?a:i+16383));return 1===r?(n=e[t-1],o.push(v[n>>2]+v[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(v[n>>10]+v[n>>4&63]+v[n<<2&63]+"=")),o.join("")},v=[],d=[],g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=0,m=g.length;p<m;++p)v[p]=g[p],d[g.charCodeAt(p)]=p;function h(e){return v[e>>18&63]+v[e>>12&63]+v[e>>6&63]+v[63&e]}function y(e,n,t){for(var r,o=[],i=n;i<t;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(h(r));return o.join("")}d["-".charCodeAt(0)]=62,d["_".charCodeAt(0)]=63;var w="function"==typeof Symbol&&"symbol"==n(Symbol.iterator)?function(e){return void 0===e?"undefined":n(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":n(e)},b=Array.isArray,k=Object.keys,E=Object.prototype.hasOwnProperty,S=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==(void 0===n?"undefined":w(n))&&"object"==(void 0===t?"undefined":w(t))){var r,o,i,a=b(n),u=b(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 v=k(n);if((o=v.length)!==k(t).length)return!1;for(r=o;0!=r--;)if(!E.call(t,v[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=v[r]],t[i]))return!1;return!0}return n!=n&&t!=t},P=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},D=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function O(e){var n=unescape(encodeURIComponent(e));return f(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function U(e){return O(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function R(e){return JSON.parse(JSON.stringify(e))}function I(e,n){return S(e,n)}function N(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 j(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function L(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function x(e,n){for(var t=n.slice(0),r=[],o=e,i=void 0;t.length>0;){for(i=[];o>0;){var a=t.shift();if(!a)break;(o-=U(JSON.stringify(a)).length)<0&&i.length>0?t.unshift(a):i.push(a)}o=e,r.push(i)}return r}function C(e){var n=e.version||"2.14.0";return e.userAgent+"/"+n}function F(e){return{"X-LaunchDarkly-User-Agent":C(e)}}function A(){for(var e=arguments.length,n=Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return P({},e,n)},{})}function q(e){if(!e)return e;var n=void 0;for(var t in D){var r=D[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[r]=String(o))}return n||e}Object.freeze({btoa:O,base64URLEncode:U,clone:R,deepEquals:I,onNextTick:N,wrapPromiseCallback:T,transformValuesToVersionedValues:j,transformVersionedValuesToValues:L,chunkUserEventsForUrl:x,getLDUserAgentString:C,getLDHeaders:F,extend:A,sanitizeUser:q});var J=2e3;function V(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var z=function(){return"LaunchDarkly client initialized"},H=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",$=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"},M=function(e){return'Expected application/json content type but got "'+e+'"'},K=function(){return"localStorage is unavailable"},_=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},G=function(e){return"network error"+(e?" ("+e+")":"")},X=function(e){return'Custom event "'+e+'" does not exist'},B=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+H},W=function(){return"No environment/client-side ID was specified."+H},Q=function(e){return"Error fetching flag settings: "+V(e)},Y=function(){return"No user specified."+H},Z=function(){return"Invalid user specified."+H},ee=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+H},ne=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},te=function(e,n){return'[LaunchDarkly] "'+e+'" is deprecated, please use "'+n+'"'},re=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(c(e)?t:"giving up permanently")},oe=function(){return"Cannot make HTTP requests in this environment."+H},ie=function(){return"identify() has no effect here; it must be called on the main client instance"},ae=function(){return"Closing stream connection"},ue=function(e){return"Opening stream connection to "+e},se=function(e){return"Error on stream connection: "+V(e)},ce=function(e){return"polling for feature flags at "+e},le=function(){return"received ping message from stream"},fe=function(){return"received streaming update for all flags"},ve=function(e){return'received streaming update for flag "'+e+'"'},de=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},ge=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'},me=function(e){return'enqueueing "'+e+'" event'},he=function(e){return"sending "+e+" events"},ye=Object.freeze({clientInitialized:z,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventWithoutUser:$,invalidContentType:M,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:K,localStorageUnavailableForUserId:_,networkError:G,unknownCustomEventKey:X,environmentNotFound:B,environmentNotSpecified:W,errorFetchingFlags:Q,userNotSpecified:Y,invalidUser:Z,bootstrapOldFormat:ee,bootstrapInvalid:ne,deprecated:te,httpErrorMessage:re,httpUnavailable:oe,identifyDisabled:ie,streamClosing:ae,streamConnecting:ue,streamError:se,debugPolling:ce,debugStreamPing:le,debugStreamPut:fe,debugStreamPatch:ve,debugStreamPatchIgnored:de,debugStreamDelete:ge,debugStreamDeleteIgnored:pe,debugEnqueueingEvent:me,debugPostingEvents:he});function we(e,n,t){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a={},u=i||function(e,n,t,r){var o=n+"/events/bulk/"+t,i=n+"/a/"+t+".gif",a={};function u(e){(new window.Image).src=e}function s(n,t){var a=r||u,s=JSON.stringify(n);return t?function n(t){var r=A({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},F(e));return e.httpRequest("POST",o,r,s).promise.then(function(e){if(e)return e.status>=400&&c(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(){}):(a(i+"?d="+U(s)),Promise.resolve())}return a.sendEvents=function(t){if(!e.httpRequest)return Promise.resolve();var r,o=e.httpAllowsPost();r=o?[t]:x(J-n.length,t);for(var i=[],a=0;a<r.length;a++)i.push(s(r[a],o));return Promise.all(i)},a}(e,n.eventsUrl,t),s=function(){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}(),l=function(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=A({},c,l[1])}var f=Object.keys(c);return f.length&&(f.sort(),s.privateAttrs=f),s},n}(n),f=n.inlineUsersInEvents,v=n.samplingInterval,d=n.flushInterval,g=n.logger,p=[],m=0,h=!1,y=void 0;function w(){return 0===v||0===Math.floor(Math.random()*v)}return a.enqueue=function(e){if(!h){var n,t=!1,r=!1;if(s.summarizeEvent(e),"feature"===e.kind?w()&&(t=!!e.trackEvents,r=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>m&&n.debugEventsUntilDate>(new Date).getTime()):t=w(),t&&p.push(function(e){var n=A({},e);return f||"identify"===e.kind?n.user=l.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),r){var o=A({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,p.push(o)}}},a.flush=function(){if(h)return Promise.resolve();var e=p,n=s.getSummary();return s.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(p=[],g.debug(he(e.length)),u.sendEvents(e).then(function(e){e&&(e.serverTime&&(m=e.serverTime),c(e.status)||(h=!0),e.status>=400&&N(function(){o.maybeReportError(new r(re(e.status,"event posting","some events were dropped")))}))}))},a.start=function(){y=setTimeout(function e(){a.flush(),y=setTimeout(e,d)},d)},a.stop=function(){clearTimeout(y)},a}var be,ke,Ee="application/json";function Se(e,n,t){var r=n.baseUrl,i=n.useReport,a=n.evaluationReasons,u=n.sendLDHeaders,c=n.logger,l={},f={};function v(n,t){if(!e.httpRequest)return new Promise(function(e,n){n(new s(oe()))});var r=t?"REPORT":"GET",i=u?F(e):{};t&&(i["Content-Type"]="application/json");var a=f[n];a||(a=function(e){var n=void 0,t=void 0,r=void 0,o=void 0,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 f[n]}),f[n]=a);var c=e.httpRequest(r,n,i,t),l=c.promise.then(function(e){if(200===e.status){if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(Ee))return JSON.parse(e.body);var n=M(e.header("content-type")||"");return Promise.reject(new s(n))}return Promise.reject(function(e){return 404===e.status?new o(B()):new s(Q(e.statusText||String(e.status)))}(e))},function(e){return Promise.reject(new s(G(e)))});return a.addPromise(l,function(){c.cancel&&c.cancel()}),a.resultPromise}return l.fetchJSON=function(e){return v(r+e,null)},l.fetchFlagSettings=function(e,n){var o=void 0,u=void 0,s="",l=void 0;return i?(u=[r,"/sdk/evalx/",t,"/user"].join(""),l=JSON.stringify(e)):(o=U(JSON.stringify(e)),u=[r,"/sdk/evalx/",t,"/users/",o].join("")),n&&(s="h="+n),a&&(s=s+(s?"&":"")+"withReasons=true"),u=u+(s?"?":"")+s,c.debug(ce(u)),v(u,l)},l}for(var Pe=(be=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}}},ke=void 0,be(ke={exports:{}},ke.exports),ke.exports),De=[],Oe=0;Oe<256;++Oe)De[Oe]=(Oe+256).toString(16).substr(1);var Ue,Re,Ie=function(e,n){var t=n||0,r=De;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("")},Ne=0,Te=0;var je=function(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||Ue,a=void 0!==e.clockseq?e.clockseq:Re;if(null==i||null==a){var u=Pe();null==i&&(i=Ue=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=Re=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:Te+1,l=s-Ne+(c-Te)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>Ne)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Ne=s,Te=c,Re=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 v=s/4294967296*1e4&268435455;o[r++]=v>>>8&255,o[r++]=255&v,o[r++]=v>>>24&15|16,o[r++]=v>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var d=0;d<6;++d)o[r+d]=i[d];return n||Ie(o)},Le="ld:$anonUserId";function xe(e,n){var t=["debug","info","warn","error"],r=void 0;r=null!=n?""===n?"":n+" ":"LD: ";var o=0;e&&(o="none"===e?100:t.indexOf(e));var i={};function a(e,n,i){if(e>=o){var a=e<t.length?t[e]:"?";n(r+"["+a+"] "+i)}}return i.debug=function(e){return a(0,console.log,e)},i.info=function(e){return a(1,console.info,e)},i.warn=function(e){return a(2,console.warn,e)},i.error=function(e){return a(3,console.error,e)},i}var Ce="function"==typeof Symbol&&"symbol"==n(Symbol.iterator)?function(e){return void 0===e?"undefined":n(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":n(e)},Fe="ready",Ae="initialized",qe="failed",Je="change",Ve="internal-change";function ze(e,n,t,r,c){var l=t&&t.logger?t.logger:c&&c.logger||xe("warn"),f=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=0;n<t[e].length;n++)t[e][n].handler.apply(t[e][n].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}(l),v=function(e,n,t,r){var o=A({logger:r},{baseUrl:"https://app.launchdarkly.com",streamUrl:"https://clientstream.launchdarkly.com",eventsUrl:"https://events.launchdarkly.com",sendEvents:!0,sendLDHeaders:!0,inlineUsersInEvents:!1,allowFrequentDuplicateEvents:!1,sendEventsOnlyForVariation:!1,useReport:!1,evaluationReasons:!1,flushInterval:2e3,samplingInterval:0,streamReconnectDelay:1e3,allAttributesPrivate:!1,privateAttributeNames:[]},t),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames"};function a(e){N(function(){n&&n.maybeReportError(new u(e))})}var s=A({},e||{});return function(e){var n=s;Object.keys(i).forEach(function(e){if(void 0!==n[e]){var t=i[e];r.warn(te(e,t)),void 0===n[t]&&(n[t]=n[e]),delete n[e]}})}(),s=function(e,n){var t=A({},s);return Object.keys(n).forEach(function(e){void 0!==t[e]&&null!==t[e]||(t[e]=n[e])}),t}(0,o),(isNaN(s.flushInterval)||s.flushInterval<2e3)&&(s.flushInterval=2e3,a("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(s.samplingInterval)||s.samplingInterval<0)&&(s.samplingInterval=0,a("Invalid sampling interval configured. Sampling interval must be an integer >= 0.")),s}(t,f,c,l),d=v.hash,g=v.sendEvents,p=e,m=function(e,n,t,r){var o=n.streamUrl,i=n.logger,a={},u=o+"/eval/"+t,s=n.useReport,c=n.evaluationReasons,l=n.streamReconnectDelay,f=null,v=null,d=null,g=null;function p(e){i.warn(se(e)),y(),m(l)}function m(e){v||(e?v=setTimeout(h,e):h())}function h(){v=null;var n=void 0,a="",l={};if(e.eventSourceFactory){for(var m in null!=r&&(a="h="+r),s?e.eventSourceAllowsReport?(n=u,l.method="REPORT",l.headers={"Content-Type":"application/json"},l.body=JSON.stringify(d)):(n=o+"/ping/"+t,a=""):n=u+"/"+U(JSON.stringify(d)),c&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,y(),i.info(ue(n)),f=e.eventSourceFactory(n,l),g)g.hasOwnProperty(m)&&f.addEventListener(m,g[m]);f.onerror=p}}function y(){f&&(i.info(ae()),f.close(),f=null)}return a.connect=function(e,n){d=e,g=n,m()},a.disconnect=function(){clearTimeout(v),v=null,y()},a.isConnected=function(){return!!(f&&e.eventSourceIsActive&&e.eventSourceIsActive(f))},a}(r,v,p,d),h=v.eventProcessor||we(r,v,p,f),y=Se(r,v,p),w={},b={},k=void 0,E=void 0,S=v.streaming,P=void 0,D=!1,x=!1,C=!0,F=v.stateProvider,J=function(e,n){var t={},r=void 0;return t.setUser=function(e){(r=q(e))&&n&&n(R(r))},t.getUser=function(){return r?R(r):null},e&&t.setUser(e),t}(null,function(e){F||e&&M({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),V=function(e,n){var t={validateUser:function(t){if(!t)return Promise.reject(new i(Y()));var r=R(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get(Le).catch(function(){return null}):Promise.resolve(null)).then(function(t){if(t)return r.key=t,r;var o=je();return r.key=o,function(t){return e?e.set(Le,t).catch(function(){n.warn(_())}):Promise.resolve()}(o).then(function(){return r})}):Promise.reject(new i(Z()))}};return t}(r.localStorage,l),H=void 0;function M(e){p&&(F&&F.enqueueEvent&&F.enqueueEvent(e)||(e.user?(C=!1,!g||x||r.isDoNotTrack()||(l.debug(me(e.kind)),h.enqueue(e))):C&&(l.warn($()),C=!1)))}function G(e,n,t,r){var o=J.getUser(),i=new Date,a=n?n.value:null;if(!v.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(o&&o.key?o.key:"")+e,s=w[u];if(s&&i-s<3e5)return;w[u]=i}var c={kind:"feature",key:e,user:o,value:a,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()},l=b[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),M(c)}function B(e,n,t,r){var o=void 0;if(b&&b.hasOwnProperty(e)&&b[e]&&!b[e].deleted){var i=b[e];o=re(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&&G(e,o,n,r),o}function re(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function oe(){E=!0,J.getUser()&&m.connect(J.getUser(),{ping:function(){l.debug(le()),y.fetchFlagSettings(J.getUser(),d).then(function(e){return he(e||{})}).catch(function(e){f.maybeReportError(new s(Q(e)))})},put:function(e){var n=JSON.parse(e.data);l.debug(fe()),he(n)},patch:function(e){var n=JSON.parse(e.data),t=b[n.key];if(!t||!t.version||!n.version||t.version<n.version){l.debug(ve(n.key));var r={},o=A({},n);delete o.key,b[n.key]=o;var i=re(o);r[n.key]=t?{previous:t.value,current:i}:{current:i},ye(r)}else l.debug(de(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!b[n.key]||b[n.key].version<n.version){l.debug(ge(n.key));var t={};b[n.key]&&!b[n.key].deleted&&(t[n.key]={previous:b[n.key].value}),b[n.key]={version:n.version,deleted:!0},ye(t)}else l.debug(pe(n.key))}})}function ce(){E&&(m.disconnect(),E=!1)}function he(e){var n={};if(!e)return Promise.resolve();for(var t in b)b.hasOwnProperty(t)&&b[t]&&(e[t]&&!I(e[t].value,b[t].value)?n[t]={previous:b[t].value,current:re(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:b[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!b[r]||b[r].deleted)&&(n[r]={current:re(e[r])});return b=Object.assign({},e),ye(n).catch(function(){})}function ye(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;f.emit(Je+":"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}}),f.emit(Je,t),f.emit(Ve,b),v.sendEventsOnlyForVariation||F||n.forEach(function(n){G(n,e[n].current)})}return k&&H?H.saveFlags(b).catch(function(){return null}):Promise.resolve()}function be(){var e=S||P&&void 0===S;e&&!E?oe():!e&&E&&ce()}function ke(e){return e===Je||e.substr(0,Je.length+1)===Je+":"}r.localStorage&&(H=new function(e,n,t,r,o){var i={};function a(){var e="",o=r.getUser();return o&&(e=t||O(JSON.stringify(o))),"ld:"+n+":"+e}return i.loadFlags=function(){return e.get(a()).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=j(n):delete n.$schema}return n}catch(e){return i.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(K()),Promise.reject(e)})},i.saveFlags=function(n){var t=A({},n,{$schema:1});return e.set(a(),JSON.stringify(t)).catch(function(e){return o.warn(K()),Promise.reject(e)})},i.clearFlags=function(){return e.clear(a()).catch(function(e){return o.warn(K()),Promise.reject(e)})},i}(r.localStorage,p,d,J,l));var Ee=new Promise(function(e){var n=f.on(Fe,function(){f.off(Fe,n),e()})}),Pe=new Promise(function(e,n){var t=f.on(Ae,function(){f.off(Ae,t),e()}),r=f.on(qe,function(e){f.off(qe,r),n(e)})});if("string"==typeof v.bootstrap&&"LOCALSTORAGE"===v.bootstrap.toUpperCase()&&(H?k=!0:l.warn(K())),"object"===Ce(v.bootstrap)&&(b=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&l.warn(ee()),!1===e.$valid&&l.warn(ne());var r={};return n.forEach(function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};t&&t[n]?o=A(o,t[n]):o.version=0,r[n]=o}}),r}(v.bootstrap)),F){var De=F.getInitialState();De?Oe(De):F.on("init",Oe),F.on("update",function(e){e.user&&J.setUser(e.user),e.flags&&he(e.flags)})}else(e?V.validateUser(n).then(function(e){return J.setUser(e),"object"===Ce(v.bootstrap)?Ue():k?H.loadFlags().catch(function(){return null}).then(function(e){return null==e?(b={},y.fetchFlagSettings(J.getUser(),d).then(function(e){return he(e||{})}).then(Ue).catch(function(e){Re(new s(Q(e)))})):(b=e,N(Ue),y.fetchFlagSettings(J.getUser(),d).then(function(e){return he(e)}).catch(function(e){return f.maybeReportError(e)}))}):y.fetchFlagSettings(J.getUser(),d).then(function(e){b=e||{},Ue()}).catch(function(e){b={},Re(e)})}):Promise.reject(new o(W()))).catch(function(e){return f.maybeReportError(e)});function Oe(e){p=e.environment,J.setUser(e.user),b=Object.assign({},e.flags),N(Ue)}function Ue(){l.info(z()),D=!0,be(),f.emit(Fe),f.emit(Ae)}function Re(e){f.maybeReportError(e),f.emit(qe,e),f.emit(Fe)}return{client:{waitForInitialization:function(){return Pe},waitUntilReady:function(){return Ee},identify:function(e,n,t){return x?T(Promise.resolve({}),t):F?(l.warn(ie()),T(Promise.resolve(L(b)),t)):T((k&&H?H.clearFlags():Promise.resolve()).then(function(){return V.validateUser(e)}).then(function(e){return J.setUser(e)}).then(function(){return y.fetchFlagSettings(J.getUser(),n)}).then(function(e){var n=L(e);return e?he(e).then(function(){return n}):n}).then(function(e){return E&&oe(),e}).catch(function(e){return f.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return J.getUser()},variation:function(e,n){return B(e,n,!0,!1).value},variationDetail:function(e,n){return B(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){r.customEventFilter&&!r.customEventFilter(e)&&l.warn(X(e));var o={kind:"custom",key:e,user:J.getUser(),url:r.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(o.data=n),null!=t&&(o.metricValue=t),M(o)}else f.maybeReportError(new a(X(e)))},on:function(e,n,t){ke(e)?(P=!0,D&&be(),f.on(e,n,t)):f.on.apply(f,arguments)},off:function(e){if(f.off.apply(f,arguments),ke(e)){var n=!1;f.getEvents().forEach(function(e){ke(e)&&f.getEventListenerCount(e)>0&&(n=!0)}),n||(P=!1,E&&void 0===S&&ce())}},setStreaming:function(e){var n=null===e?void 0:e;n!==S&&(S=n,be())},flush:function(e){return T(g?h.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!b)return e;for(var n in b)b.hasOwnProperty(n)&&(e[n]=B(n,null,!v.sendEventsOnlyForVariation).value);return e},close:function(e){if(x)return T(Promise.resolve(),e);var n=function(){x=!0,b={}};return T(Promise.resolve().then(function(){if(ce(),g)return h.stop(),h.flush()}).then(n).catch(n),e)}},options:v,emitter:f,ident:J,logger:l,requestor:y,start:function(){g&&h.start()},enqueueEvent:M,getFlagsInternal:function(){return b},getEnvironmentId:function(){return p},internalChangeEventName:Ve}}var He={promise:Promise.resolve({status:200,header:function(){return null},body:null})};function $e(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 He;var i=new window.XMLHttpRequest;for(var a in i.open(e,n,!o),t||{})t.hasOwnProperty(a)&&i.setRequestHeader(a,t[a]);if(o)return i.send(r),He;var u=void 0;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()}}}var Me=/[|\\{}()[\]^$+*?.]/g,Ke=function(e){if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(Me,"\\$&")};function _e(e,n,t,r){var o=n.replace(t,"").replace(r,""),i=void 0,a=void 0;switch(e.kind){case"exact":a=n,i=new RegExp("^"+Ke(e.url)+"/?$");break;case"canonical":a=o,i=new RegExp("^"+Ke(e.url)+"/?$");break;case"substring":a=o,i=new RegExp(".*"+Ke(e.substring)+".*$");break;case"regex":a=o,i=new RegExp(e.pattern);break;default:return!1}return i.test(a)}function Ge(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(_e(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}var Xe=300;function Be(e,n){var t=void 0,r=void 0,o={};function i(){r&&r.dispose(),t&&t.length&&(r=Ge(t,a))}function a(n,t){var r={kind:n,key:t.key,data:null,url:window.location.href,user:e.ident.getUser(),creationDate:(new Date).getTime()};return"click"===n&&(r.selector=t.selector),e.enqueueEvent(r)}return o.goalKeyExists=function(e){if(!t)return!0;for(var n=0;n<t.length;n++)if("custom"===t[n].kind&&t[n].key===e)return!0;return!1},e.requestor.fetchJSON("/sdk/goals/"+e.getEnvironmentId()).then(function(e){e&&e.length>0&&(r=Ge(t=e,a),function(e,n){var t=window.location.href,r=void 0;function o(){(r=window.location.href)!==t&&(t=r,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)}(Xe,i)),n()}).catch(function(t){e.emitter.maybeReportError(new l.LDUnexpectedResponseError((t&&t.message,t.message))),n()}),o}var We="goalsReady",Qe={fetchGoals:!0};function Ye(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=function(e){var n={pageIsClosing:!1};window.XMLHttpRequest&&(n.httpRequest=function(e,t,r,o){return $e(e,t,r,o,n.pageIsClosing)});var t=void 0;n.httpAllowsPost=function(){return void 0===t&&(t=!!window.XMLHttpRequest&&"withCredentials"in new window.XMLHttpRequest),t};var r=e&&e.eventUrlTransformer;n.getCurrentUrl=function(){return r?r(window.location.href):window.location.href},n.isDoNotTrack=function(){var e=void 0;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&&(n.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){n.localStorage=null}var o=void 0;e&&e.useReport&&"function"==typeof window.EventSourcePolyfill&&window.EventSourcePolyfill.supportedOptions&&window.EventSourcePolyfill.supportedOptions.method?(n.eventSourceAllowsReport=!0,o=window.EventSourcePolyfill):(n.eventSourceAllowsReport=!1,o=window.EventSource),window.EventSource&&(n.eventSourceFactory=function(e,n){var t={heartbeatTimeout:3e5,silentTimeout:3e5,skipDefaultHeaders:!0},r=Object.assign({},t,n);return new o(e,r)},n.eventSourceIsActive=function(e){return e.readyState===window.EventSource.OPEN||e.readyState===window.EventSource.CONNECTING});return n.userAgent="JSClient",n}(t),o=ze(e,n,t,r,Qe),i=o.client,a=o.options,u=o.emitter,s=new Promise(function(e){var n=u.on(We,function(){u.off(We,n),e()})});if(i.waitUntilGoalsReady=function(){return s},a.fetchGoals){var c=Be(o,function(){return u.emit(We)});r.customEventFilter=c.goalKeyExists}else u.emit(We);return"complete"!==document.readyState?window.addEventListener("load",o.start):o.start(),window.addEventListener("beforeunload",function(){r.pageIsClosing=!0,i.close()}),i}var Ze=xe;var en={initialize:function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return console&&console.warn&&console.warn(ye.deprecated("default export","named LDClient export")),Ye(e,n,t)},version:"2.14.0"};e.initialize=Ye,e.createConsoleLogger=Ze,e.version="2.14.0",e.default=en,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=ldclient.min.js.map |
{ | ||
"name": "launchdarkly-js-client-sdk", | ||
"version": "2.13.0", | ||
"version": "2.14.0", | ||
"description": "LaunchDarkly SDK for JavaScript", | ||
@@ -71,3 +71,3 @@ "author": "LaunchDarkly <team@launchdarkly.com>", | ||
"escape-string-regexp": "1.0.5", | ||
"launchdarkly-js-sdk-common": "^2.13.0" | ||
"launchdarkly-js-sdk-common": "^2.14.0" | ||
}, | ||
@@ -74,0 +74,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
360728
501