launchdarkly-js-sdk-common
Advanced tools
Comparing version 2.10.3 to 2.10.4
@@ -1,2 +0,2 @@ | ||
"use strict";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}Object.defineProperty(exports,"__esModule",{value:!0});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,r){for(var t,o=[],a=n;a<r;a+=3)t=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(tripletToBase64(t));return o.join("")}function fromByteArray(e){for(var n,r=e.length,t=r%3,o=[],a=0,i=r-t;a<i;a+=16383)o.push(encodeChunk(e,a,a+16383>i?i:a+16383));return 1===t?(n=e[r-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2===t&&(n=(e[r-2]<<8)+e[r-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"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,r){if(n===r)return!0;if(n&&r&&"object"==(void 0===n?"undefined":_typeof(n))&&"object"==(void 0===r?"undefined":_typeof(r))){var t,o,a,i=isArray(n),u=isArray(r);if(i&&u){if((o=n.length)!=r.length)return!1;for(t=o;0!=t--;)if(!e(n[t],r[t]))return!1;return!0}if(i!=u)return!1;var s=n instanceof Date,l=r instanceof Date;if(s!=l)return!1;if(s&&l)return n.getTime()==r.getTime();var c=n instanceof RegExp,v=r instanceof RegExp;if(c!=v)return!1;if(c&&v)return n.toString()==r.toString();var f=keyList(n);if((o=f.length)!==keyList(r).length)return!1;for(t=o;0!=t--;)if(!hasProp.call(r,f[t]))return!1;for(t=o;0!=t--;)if(!e(n[a=f[t]],r[a]))return!1;return!0}return n!=n&&r!=r},_extends=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}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=[],r=0;r<e.length;r++)n.push(e.charCodeAt(r));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 r=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:r}function transformValuesToVersionedValues(e){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]={value:e[r],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r].value);return n}function chunkUserEventsForUrl(e,n){for(var r=n.slice(0),t=[],o=e,a=void 0;r.length>0;){for(a=[];o>0;){var i=r.shift();if(!i)break;(o-=base64URLEncode(JSON.stringify(i)).length)<0&&a.length>0?r.unshift(i):a.push(i)}o=e,t.push(a)}return t}function getLDUserAgentString(e){var n=e.version||"2.10.3";return e.userAgent+"/"+n}function getLDHeaders(e){return{"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)}}function extend(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];return n.reduce(function(e,n){return _extends({},e,n)},{})}function sanitizeUser(e){if(!e)return e;var n=void 0;for(var r in userAttrsToStringify){var t=userAttrsToStringify[r],o=e[t];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[t]=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,r,t){var o=n+"/events/bulk/"+r,a=n+"/a/"+r+".gif",i={};function u(e){(new window.Image).src=e}function s(n,r){var i=t||u,s=JSON.stringify(n);return r?function n(r){var t=extend({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},getLDHeaders(e));return e.httpRequest("POST",o,t,s).promise.then(function(e){if(e)return e.status>=400&&isHttpErrorRecoverable(e.status)&&r?n(!1):function(e){var n={status:e.status},r=e.header("date");if(r){var t=Date.parse(r);t&&(n.serverTime=t)}return n}(e)}).catch(function(){return r?n(!1):Promise.reject()})}(!0).catch(function(){}):(i(a+"?d="+base64URLEncode(s)),Promise.resolve())}return i.sendEvents=function(r){if(!e.httpRequest)return Promise.resolve();var t=e.httpAllowsPost(),o=void 0;o=t?[r]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,r);for(var a=[],i=0;i<o.length;i++)a.push(s(o[i],t));return Promise.all(a)},i}function EventSummarizer(){var e={},n=0,r=0,t={};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:""),a=t[o];a?a.count=a.count+1:t[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>r&&(r=e.creationDate)}},e.getSummary=function(){var e={},o=!0;for(var a in t){var i=t[a],u=e[i.key];u||(u={default:i.default,counters:[]},e[i.key]=u);var s={value:i.value,count:i.count};void 0!==i.variation&&null!==i.variation&&(s.variation=i.variation),i.version?s.version=i.version:s.unknown=!0,u.counters.push(s),o=!1}return o?null:{startDate:n,endDate:r,features:e}},e.clearSummary=function(){n=0,r=0,t={}},e}function UserFilter(e){var n={},r=e.allAttributesPrivate,t=e.privateAttributeNames||[],o={key:!0,custom:!0,anonymous:!0},a={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||[],i=function(e,a){return Object.keys(e).reduce(function(i,u){var s=i;return a(u)&&(!function(e){return!o[e]&&(r||-1!==n.indexOf(e)||-1!==t.indexOf(e))}(u)?s[0][u]=e[u]:s[1][u]=!0),s},[{},{}])},u=i(e,function(e){return a[e]}),s=u[0],l=u[1];if(e.custom){var c=i(e.custom,function(){return!0});s.custom=c[0],l=extend({},l,c[1])}var v=Object.keys(l);return v.length&&(v.sort(),s.privateAttrs=v),s},n}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: http://docs.launchdarkly.com/docs/running-an-ab-test#include-the-client-side-snippet"},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."+docLink},environmentNotSpecified=function(){return"No environment specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+(e.message||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,r){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?r:"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"},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,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,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents});function EventProcessor(e,n,r,t){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,i={},u=a||EventSender(e,n.eventsUrl,r),s=EventSummarizer(),l=UserFilter(n),c=n.inlineUsersInEvents,v=n.samplingInterval,f=n.flushInterval,d=[],g=0,m=!1,p=void 0;function y(){return 0===v||0===Math.floor(Math.random()*v)}return i.enqueue=function(e){if(!m){var n,r=!1,t=!1;if(s.summarizeEvent(e),"feature"===e.kind?y()&&(r=!!e.trackEvents,t=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>g&&n.debugEventsUntilDate>(new Date).getTime()):r=y(),r&&d.push(function(e){var n=extend({},e);return c||"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)),t){var o=extend({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,d.push(o)}}},i.flush=function(){if(m)return Promise.resolve();var e=d,n=s.getSummary();return s.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(d=[],t.debug(debugPostingEvents(e.length)),u.sendEvents(e).then(function(e){e&&(e.serverTime&&(g=e.serverTime),isHttpErrorRecoverable(e.status)||(m=!0),e.status>=400&&onNextTick(function(){o.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},i.start=function(){p=setTimeout(function e(){i.flush(),p=setTimeout(e,f)},f)},i.stop=function(){clearTimeout(p)},i}function EventEmitter(e){var n={},r={};return n.on=function(e,n,t){r[e]=r[e]||[],r[e]=r[e].concat({handler:n,context:t})},n.off=function(e,n,t){if(r[e])for(var o=0;o<r[e].length;o++)r[e][o].handler===n&&r[e][o].context===t&&(r[e]=r[e].slice(0,o).concat(r[e].slice(o+1)))},n.emit=function(e){if(r[e])for(var n=0;n<r[e].length;n++)r[e][n].handler.apply(r[e][n].context,Array.prototype.slice.call(arguments,1))},n.getEvents=function(){return Object.keys(r)},n.getEventListenerCount=function(e){return r[e]?r[e].length:0},n.maybeReportError=function(n){n&&(r["error"]?this.emit("error",n):(e||console).error(n.message))},n}function Store(e,n,r,t,o){var a={};function i(){var e="",o=t.getUser();return o&&(e=r||btoa(JSON.stringify(o))),"ld:"+n+":"+e}return a.loadFlags=function(){return e.get(i()).then(function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var r=n.$schema;void 0===r||r<1?n=transformValuesToVersionedValues(n):delete n.$schema}return n}catch(e){return a.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a.saveFlags=function(n){var r=extend({},n,{$schema:1});return e.set(i(),JSON.stringify(r)).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a.clearFlags=function(){return e.clear(i()).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a}function Stream(e,n,r,t){var o=n.streamUrl,a={},i=o+"/eval/"+r,u=n.useReport,s=n.evaluationReasons,l=n.streamReconnectDelay,c=null,v=null,f=null,d=null;function g(){y(),m(l)}function m(e){v||(e?v=setTimeout(p,e):p())}function p(){var n=void 0,a="",l={};if(e.eventSourceFactory){for(var v in null!=t&&(a="h="+t),u?e.eventSourceAllowsReport?(n=i,l.method="REPORT",l.headers={"Content-Type":"application/json"},l.body=JSON.stringify(f)):(n=o+"/ping/"+r,a=""):n=i+"/"+base64URLEncode(JSON.stringify(f)),s&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,y(),c=e.eventSourceFactory(n,l),d)d.hasOwnProperty(v)&&c.addEventListener(v,d[v]);c.onerror=g}}function y(){c&&(c.close(),c=null)}return a.connect=function(e,n){f=e,d=n,m()},a.disconnect=function(){clearTimeout(v),v=null,y()},a.isConnected=function(){return c&&e.eventSourceIsActive&&e.eventSourceIsActive(c)},a}function promiseCoalescer(e){var n=void 0,r=void 0,t=void 0,o=void 0,a={addPromise:function(a,i){n=a,r&&r(),r=i,a.then(function(r){n===a&&(t(r),e&&e())},function(r){n===a&&(o(r),e&&e())})}};return a.resultPromise=new Promise(function(e,n){t=e,o=n}),a}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,r,t){var o=n.baseUrl,a=n.useReport,i=n.evaluationReasons,u=n.sendLDHeaders,s={},l={};function c(n,r){if(!e.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var t=r?"REPORT":"GET",o=u?getLDHeaders(e):{};r&&(o["Content-Type"]="application/json");var a=l[n];a||(a=promiseCoalescer(function(){delete l[n]}),l[n]=a);var i=e.httpRequest(t,n,o,r),s=i.promise.then(function(e){return 200===e.status&&e.header("content-type")&&0===e.header("content-type").lastIndexOf(json)?JSON.parse(e.body):Promise.reject(getResponseError(e))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return a.addPromise(s,function(){i.cancel&&i.cancel()}),a.resultPromise}return s.fetchFlagSettings=function(e,n){var u=void 0,s=void 0,l="",v=void 0;return a?(s=[o,"/sdk/evalx/",r,"/user"].join(""),v=JSON.stringify(e)):(u=base64URLEncode(JSON.stringify(e)),s=[o,"/sdk/evalx/",r,"/users/",u].join("")),n&&(l="h="+n),i&&(l=l+(l?"&":"")+"withReasons=true"),s=s+(l?"?":"")+l,t.debug(debugPolling(s)),c(s,v)},s.fetchGoals=function(){return c([o,"/sdk/goals/",r].join(""),null)},s}function Identity(e,n){var r={},t=void 0;return r.setUser=function(e){(t=sanitizeUser(e))&&n&&n(clone(t))},r.getUser=function(){return t?clone(t):null},e&&r.setUser(e),r}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 r=new Uint8Array(16);e.exports=function(){return n(r),r}}else{var t=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),t[n]=e>>>((3&n)<<3)&255;return t}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var r=n||0,t=byteToHex;return[t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]]].join("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,r){var t=n&&r||0,o=n||[],a=(e=e||{}).node||_nodeId,i=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==a||null==i){var u=rngBrowser();null==a&&(a=_nodeId=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==i&&(i=_clockseq=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),l=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,c=s-_lastMSecs+(l-_lastNSecs)/1e4;if(c<0&&void 0===e.clockseq&&(i=i+1&16383),(c<0||s>_lastMSecs)&&void 0===e.nsecs&&(l=0),l>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=s,_lastNSecs=l,_clockseq=i;var v=(1e4*(268435455&(s+=122192928e5))+l)%4294967296;o[t++]=v>>>24&255,o[t++]=v>>>16&255,o[t++]=v>>>8&255,o[t++]=255&v;var f=s/4294967296*1e4&268435455;o[t++]=f>>>8&255,o[t++]=255&f,o[t++]=f>>>24&15|16,o[t++]=f>>>16&255,o[t++]=i>>>8|128,o[t++]=255&i;for(var d=0;d<6;++d)o[t+d]=a[d];return n||bytesToUuid_1(o)}var v1_1=v1,ldUserIdKey="ld:$anonUserId";function UserValidator(e,n){var r={};return r.validateUser=function(r){if(!r)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var t=clone(r);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?(e?e.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(r){if(r)return t.key=r,t;var o=v1_1();return t.key=o,function(r){return e?e.set(ldUserIdKey,r).catch(function(){n.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(o).then(function(){return t})}):Promise.reject(new LDInvalidUserError(invalidUser()))},r}function validate(e,n,r,t){var o=extend({},{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:[]},r),a={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames"};function i(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var u=extend({},e||{});return function(e){var n=e;Object.keys(a).forEach(function(e){if(void 0!==n[e]){var r=a[e];t.warn(deprecated(e,r)),void 0===n[r]&&(n[r]=n[e]),delete n[e]}})}(u),u=function(e,n){var r=extend({},e);return Object.keys(n).forEach(function(e){void 0!==r[e]&&null!==r[e]||(r[e]=n[e])}),r}(u,o),(isNaN(u.flushInterval)||u.flushInterval<2e3)&&(u.flushInterval=2e3,i("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(u.samplingInterval)||u.samplingInterval<0)&&(u.samplingInterval=0,i("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 r={};function t(e,r,t){e>=n&&r(t)}return r.debug=function(e){return t(0,console.log,e)},r.info=function(e){return t(1,console.info,e)},r.warn=function(e){return t(2,console.warn,e)},r.error=function(e){return t(3,console.error,e)},r}var _typeof$1="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},readyEvent="ready",successEvent="initialized",failedEvent="failed",changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,r,t,o){var a=function(){if(r&&r.logger)return r.logger;return o&&o.logger||createConsoleLogger("warn")}(),i=EventEmitter(a),u=validate(r,i,o,a),s=u.hash,l=u.sendEvents,c=e,v=Stream(t,u,c,s),f=u.eventProcessor||EventProcessor(t,u,c,a,i),d=Requestor(t,u,c,a),g={},m={},p=void 0,y=void 0,h=u.streaming,E=void 0,b=!1,k=!1,S=!0,U=u.stateProvider,D=Identity(null,function(e){if(U)return;e&&w({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),P=UserValidator(t.localStorage,a),L=void 0;function w(e){c&&(U&&U.enqueueEvent&&U.enqueueEvent(e)||(e.user?(S=!1,!l||k||t.isDoNotTrack()||(a.debug(debugEnqueueingEvent(e.kind)),f.enqueue(e))):S&&(a.warn(eventWithoutUser()),S=!1)))}function I(e,n,r){var t=D.getUser(),o=new Date,a=n?n.value:null;if(!u.allowFrequentDuplicateEvents){var i=JSON.stringify(a)+(t&&t.key?t.key:"")+e,s=g[i];if(s&&o-s<3e5)return;g[i]=o}var l={kind:"feature",key:e,user:t,value:a,variation:n?n.variationIndex:null,default:r,creationDate:o.getTime(),reason:n?n.reason:null},c=m[e];c&&(l.version=c.flagVersion?c.flagVersion:c.version,l.trackEvents=c.trackEvents,l.debugEventsUntilDate=c.debugEventsUntilDate),w(l)}function F(e,n,r){var t=void 0;if(m&&m.hasOwnProperty(e)&&m[e]&&!m[e].deleted){var o=m[e];t=R(o),null!==o.value&&void 0!==o.value||(t.value=n)}else t={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return r&&I(e,t,n),t}function R(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function T(){y=!0,D.getUser()&&v.connect(D.getUser(),{ping:function(){a.debug(debugStreamPing()),d.fetchFlagSettings(D.getUser(),s,function(e,n){e&&i.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e))),O(n)})},put:function(e){var n=JSON.parse(e.data);a.debug(debugStreamPut()),O(n)},patch:function(e){var n=JSON.parse(e.data),r=m[n.key];if(!r||!r.version||!n.version||r.version<n.version){a.debug(debugStreamPatch(n.key));var t={},o=extend({},n);delete o.key,m[n.key]=o;var i=R(o);t[n.key]=r?{previous:r.value,current:i}:{current:i},x(t)}else a.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!m[n.key]||m[n.key].version<n.version){a.debug(debugStreamDelete(n.key));var r={};m[n.key]&&!m[n.key].deleted&&(r[n.key]={previous:m[n.key].value}),m[n.key]={version:n.version,deleted:!0},x(r)}else a.debug(debugStreamDeleteIgnored(n.key))}})}function N(){y&&(v.disconnect(),y=!1)}function O(e){var n={};if(!e)return Promise.resolve();for(var r in m)m.hasOwnProperty(r)&&m[r]&&(e[r]&&!deepEquals(e[r].value,m[r].value)?n[r]={previous:m[r].value,current:R(e[r])}:e[r]&&!e[r].deleted||(n[r]={previous:m[r].value}));for(var t in e)e.hasOwnProperty(t)&&e[t]&&(!m[t]||m[t].deleted)&&(n[t]={current:R(e[t])});return m=e,x(n).catch(function(){})}function x(e){var n=Object.keys(e);if(n.length>0){var r={};n.forEach(function(n){var t=e[n].current,o=t?t.value:void 0,a=e[n].previous;i.emit(changeEvent+":"+n,o,a),r[n]=t?{current:o,previous:a}:{previous:a}}),i.emit(changeEvent,r),i.emit(internalChangeEvent,m),u.sendEventsOnlyForVariation||U||n.forEach(function(n){I(n,e[n].current)})}return p&&L?L.saveFlags(m).catch(function(){return null}):Promise.resolve()}function C(){var e=h||E&&void 0===h;e&&!y?T():!e&&y&&N()}function A(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}t.localStorage&&(L=new Store(t.localStorage,c,s,D,a));var j=new Promise(function(e){var n=i.on(readyEvent,function(){i.off(readyEvent,n),e()})}),_=new Promise(function(e,n){var r=i.on(successEvent,function(){i.off(successEvent,r),e()}),t=i.on(failedEvent,function(e){i.off(failedEvent,t),n(e)})});if("string"==typeof u.bootstrap&&"LOCALSTORAGE"===u.bootstrap.toUpperCase()&&(L?p=!0:a.warn(localStorageUnavailable())),U){var V=U.getInitialState();V?q(V):U.on("init",q),U.on("update",function(e){e.user&&D.setUser(e.user);e.flags&&O(e.flags)})}else(function(){if(!e)return Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()));return P.validateUser(n).then(function(e){return D.setUser(e),"object"===_typeof$1(u.bootstrap)?(m=function(e){var n=Object.keys(e),r=e.$flagsState;!r&&n.length&&a.warn(bootstrapOldFormat()),!1===e.$valid&&a.warn(bootstrapInvalid());var t={};return n.forEach(function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};r&&r[n]?o=extend(o,r[n]):o.version=0,t[n]=o}}),t}(u.bootstrap),z()):p?L.loadFlags().catch(function(){return null}).then(function(e){return null==e?(m={},d.fetchFlagSettings(D.getUser(),s).then(function(e){return O(e||{})}).then(z).catch(function(e){var n=new LDFlagFetchError(errorFetchingFlags(e));K(n)})):(m=e,onNextTick(z),d.fetchFlagSettings(D.getUser(),s).then(function(e){return O(e)}).catch(function(e){return i.maybeReportError(e)}))}):d.fetchFlagSettings(D.getUser(),s).then(function(e){m=e||{},z()}).catch(function(e){m={},K(e)})})})().catch(function(e){return i.maybeReportError(e)});function q(e){c=e.environment,D.setUser(e.user),m=e.flags,onNextTick(z)}function z(){a.info(clientInitialized()),b=!0,C(),i.emit(readyEvent),i.emit(successEvent)}function K(e){i.maybeReportError(e),i.emit(failedEvent,e),i.emit(readyEvent)}return{client:{waitForInitialization:function(){return _},waitUntilReady:function(){return j},identify:function(e,n,r){return k?wrapPromiseCallback(Promise.resolve({}),r):U?(a.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(m)),r)):wrapPromiseCallback((p&&L?L.clearFlags():Promise.resolve()).then(function(){return P.validateUser(e)}).then(function(e){return D.setUser(e)}).then(function(){return d.fetchFlagSettings(D.getUser(),n)}).then(function(e){var n=transformVersionedValuesToValues(e);return e?O(e).then(function(){return n}):n}).then(function(e){return y&&T(),e}).catch(function(e){return i.maybeReportError(e),Promise.reject(e)}),r)},getUser:function(){return D.getUser()},variation:function(e,n){return F(e,n,!0).value},variationDetail:function(e,n){return F(e,n,!0)},track:function(e,n){"string"==typeof e?(t.customEventFilter&&!t.customEventFilter(e)&&a.warn(unknownCustomEventKey(e)),w({kind:"custom",key:e,data:n,user:D.getUser(),url:t.getCurrentUrl(),creationDate:(new Date).getTime()})):i.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,r){A(e)?(E=!0,b&&C(),i.on(e,n,r)):i.on.apply(i,arguments)},off:function(e){if(i.off.apply(i,arguments),A(e)){var n=!1;i.getEvents().forEach(function(e){A(e)&&i.getEventListenerCount(e)>0&&(n=!0)}),n||(E=!1,y&&void 0===h&&N())}},setStreaming:function(e){var n=null===e?void 0:e;n!==h&&(h=n,C())},flush:function(e){return wrapPromiseCallback(l?f.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!m)return e;for(var n in m)m.hasOwnProperty(n)&&(e[n]=F(n,null,!u.sendEventsOnlyForVariation).value);return e},close:function(e){if(k)return wrapPromiseCallback(Promise.resolve(),e);var n=function(){k=!0,m={}};return wrapPromiseCallback(Promise.resolve().then(function(){if(N(),l)return f.stop(),f.flush()}).then(n).catch(n),e)}},options:u,emitter:i,ident:D,logger:a,requestor:d,start:function(){l&&f.start()},enqueueEvent:w,getFlagsInternal:function(){return m},internalChangeEventName:internalChangeEvent}}var version="2.10.3";exports.initialize=initialize,exports.version=version,exports.createConsoleLogger=createConsoleLogger,exports.errors=errors,exports.messages=messages,exports.utils=utils; | ||
"use strict";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}Object.defineProperty(exports,"__esModule",{value:!0});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,r){for(var t,o=[],a=n;a<r;a+=3)t=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(tripletToBase64(t));return o.join("")}function fromByteArray(e){for(var n,r=e.length,t=r%3,o=[],a=0,i=r-t;a<i;a+=16383)o.push(encodeChunk(e,a,a+16383>i?i:a+16383));return 1===t?(n=e[r-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2===t&&(n=(e[r-2]<<8)+e[r-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"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,r){if(n===r)return!0;if(n&&r&&"object"==(void 0===n?"undefined":_typeof(n))&&"object"==(void 0===r?"undefined":_typeof(r))){var t,o,a,i=isArray(n),u=isArray(r);if(i&&u){if((o=n.length)!=r.length)return!1;for(t=o;0!=t--;)if(!e(n[t],r[t]))return!1;return!0}if(i!=u)return!1;var s=n instanceof Date,l=r instanceof Date;if(s!=l)return!1;if(s&&l)return n.getTime()==r.getTime();var c=n instanceof RegExp,v=r instanceof RegExp;if(c!=v)return!1;if(c&&v)return n.toString()==r.toString();var f=keyList(n);if((o=f.length)!==keyList(r).length)return!1;for(t=o;0!=t--;)if(!hasProp.call(r,f[t]))return!1;for(t=o;0!=t--;)if(!e(n[a=f[t]],r[a]))return!1;return!0}return n!=n&&r!=r},_extends=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}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=[],r=0;r<e.length;r++)n.push(e.charCodeAt(r));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 r=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:r}function transformValuesToVersionedValues(e){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]={value:e[r],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r].value);return n}function chunkUserEventsForUrl(e,n){for(var r=n.slice(0),t=[],o=e,a=void 0;r.length>0;){for(a=[];o>0;){var i=r.shift();if(!i)break;(o-=base64URLEncode(JSON.stringify(i)).length)<0&&a.length>0?r.unshift(i):a.push(i)}o=e,t.push(a)}return t}function getLDUserAgentString(e){var n=e.version||"2.10.4";return e.userAgent+"/"+n}function getLDHeaders(e){return{"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)}}function extend(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];return n.reduce(function(e,n){return _extends({},e,n)},{})}function sanitizeUser(e){if(!e)return e;var n=void 0;for(var r in userAttrsToStringify){var t=userAttrsToStringify[r],o=e[t];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[t]=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,r,t){var o=n+"/events/bulk/"+r,a=n+"/a/"+r+".gif",i={};function u(e){(new window.Image).src=e}function s(n,r){var i=t||u,s=JSON.stringify(n);return r?function n(r){var t=extend({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},getLDHeaders(e));return e.httpRequest("POST",o,t,s).promise.then(function(e){if(e)return e.status>=400&&isHttpErrorRecoverable(e.status)&&r?n(!1):function(e){var n={status:e.status},r=e.header("date");if(r){var t=Date.parse(r);t&&(n.serverTime=t)}return n}(e)}).catch(function(){return r?n(!1):Promise.reject()})}(!0).catch(function(){}):(i(a+"?d="+base64URLEncode(s)),Promise.resolve())}return i.sendEvents=function(r){if(!e.httpRequest)return Promise.resolve();var t=e.httpAllowsPost(),o=void 0;o=t?[r]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,r);for(var a=[],i=0;i<o.length;i++)a.push(s(o[i],t));return Promise.all(a)},i}function EventSummarizer(){var e={},n=0,r=0,t={};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:""),a=t[o];a?a.count=a.count+1:t[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>r&&(r=e.creationDate)}},e.getSummary=function(){var e={},o=!0;for(var a in t){var i=t[a],u=e[i.key];u||(u={default:i.default,counters:[]},e[i.key]=u);var s={value:i.value,count:i.count};void 0!==i.variation&&null!==i.variation&&(s.variation=i.variation),i.version?s.version=i.version:s.unknown=!0,u.counters.push(s),o=!1}return o?null:{startDate:n,endDate:r,features:e}},e.clearSummary=function(){n=0,r=0,t={}},e}function UserFilter(e){var n={},r=e.allAttributesPrivate,t=e.privateAttributeNames||[],o={key:!0,custom:!0,anonymous:!0},a={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||[],i=function(e,a){return Object.keys(e).reduce(function(i,u){var s=i;return a(u)&&(!function(e){return!o[e]&&(r||-1!==n.indexOf(e)||-1!==t.indexOf(e))}(u)?s[0][u]=e[u]:s[1][u]=!0),s},[{},{}])},u=i(e,function(e){return a[e]}),s=u[0],l=u[1];if(e.custom){var c=i(e.custom,function(){return!0});s.custom=c[0],l=extend({},l,c[1])}var v=Object.keys(l);return v.length&&(v.sort(),s.privateAttrs=v),s},n}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: http://docs.launchdarkly.com/docs/running-an-ab-test#include-the-client-side-snippet"},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."+docLink},environmentNotSpecified=function(){return"No environment specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+(e.message||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,r){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?r:"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"},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,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,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents});function EventProcessor(e,n,r,t){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,i={},u=a||EventSender(e,n.eventsUrl,r),s=EventSummarizer(),l=UserFilter(n),c=n.inlineUsersInEvents,v=n.samplingInterval,f=n.flushInterval,d=[],g=0,m=!1,p=void 0;function y(){return 0===v||0===Math.floor(Math.random()*v)}return i.enqueue=function(e){if(!m){var n,r=!1,t=!1;if(s.summarizeEvent(e),"feature"===e.kind?y()&&(r=!!e.trackEvents,t=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>g&&n.debugEventsUntilDate>(new Date).getTime()):r=y(),r&&d.push(function(e){var n=extend({},e);return c||"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)),t){var o=extend({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,d.push(o)}}},i.flush=function(){if(m)return Promise.resolve();var e=d,n=s.getSummary();return s.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(d=[],t.debug(debugPostingEvents(e.length)),u.sendEvents(e).then(function(e){e&&(e.serverTime&&(g=e.serverTime),isHttpErrorRecoverable(e.status)||(m=!0),e.status>=400&&onNextTick(function(){o.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},i.start=function(){p=setTimeout(function e(){i.flush(),p=setTimeout(e,f)},f)},i.stop=function(){clearTimeout(p)},i}function EventEmitter(e){var n={},r={};return n.on=function(e,n,t){r[e]=r[e]||[],r[e]=r[e].concat({handler:n,context:t})},n.off=function(e,n,t){if(r[e])for(var o=0;o<r[e].length;o++)r[e][o].handler===n&&r[e][o].context===t&&(r[e]=r[e].slice(0,o).concat(r[e].slice(o+1)))},n.emit=function(e){if(r[e])for(var n=0;n<r[e].length;n++)r[e][n].handler.apply(r[e][n].context,Array.prototype.slice.call(arguments,1))},n.getEvents=function(){return Object.keys(r)},n.getEventListenerCount=function(e){return r[e]?r[e].length:0},n.maybeReportError=function(n){n&&(r["error"]?this.emit("error",n):(e||console).error(n.message))},n}function Store(e,n,r,t,o){var a={};function i(){var e="",o=t.getUser();return o&&(e=r||btoa(JSON.stringify(o))),"ld:"+n+":"+e}return a.loadFlags=function(){return e.get(i()).then(function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var r=n.$schema;void 0===r||r<1?n=transformValuesToVersionedValues(n):delete n.$schema}return n}catch(e){return a.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a.saveFlags=function(n){var r=extend({},n,{$schema:1});return e.set(i(),JSON.stringify(r)).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a.clearFlags=function(){return e.clear(i()).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a}function Stream(e,n,r,t){var o=n.streamUrl,a={},i=o+"/eval/"+r,u=n.useReport,s=n.evaluationReasons,l=n.streamReconnectDelay,c=null,v=null,f=null,d=null;function g(){y(),m(l)}function m(e){v||(e?v=setTimeout(p,e):p())}function p(){var n=void 0,a="",l={};if(e.eventSourceFactory){for(var v in null!=t&&(a="h="+t),u?e.eventSourceAllowsReport?(n=i,l.method="REPORT",l.headers={"Content-Type":"application/json"},l.body=JSON.stringify(f)):(n=o+"/ping/"+r,a=""):n=i+"/"+base64URLEncode(JSON.stringify(f)),s&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,y(),c=e.eventSourceFactory(n,l),d)d.hasOwnProperty(v)&&c.addEventListener(v,d[v]);c.onerror=g}}function y(){c&&(c.close(),c=null)}return a.connect=function(e,n){f=e,d=n,m()},a.disconnect=function(){clearTimeout(v),v=null,y()},a.isConnected=function(){return c&&e.eventSourceIsActive&&e.eventSourceIsActive(c)},a}function promiseCoalescer(e){var n=void 0,r=void 0,t=void 0,o=void 0,a={addPromise:function(a,i){n=a,r&&r(),r=i,a.then(function(r){n===a&&(t(r),e&&e())},function(r){n===a&&(o(r),e&&e())})}};return a.resultPromise=new Promise(function(e,n){t=e,o=n}),a}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,r,t){var o=n.baseUrl,a=n.useReport,i=n.evaluationReasons,u=n.sendLDHeaders,s={},l={};function c(n,r){if(!e.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var t=r?"REPORT":"GET",o=u?getLDHeaders(e):{};r&&(o["Content-Type"]="application/json");var a=l[n];a||(a=promiseCoalescer(function(){delete l[n]}),l[n]=a);var i=e.httpRequest(t,n,o,r),s=i.promise.then(function(e){return 200===e.status&&e.header("content-type")&&0===e.header("content-type").lastIndexOf(json)?JSON.parse(e.body):Promise.reject(getResponseError(e))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return a.addPromise(s,function(){i.cancel&&i.cancel()}),a.resultPromise}return s.fetchFlagSettings=function(e,n){var u=void 0,s=void 0,l="",v=void 0;return a?(s=[o,"/sdk/evalx/",r,"/user"].join(""),v=JSON.stringify(e)):(u=base64URLEncode(JSON.stringify(e)),s=[o,"/sdk/evalx/",r,"/users/",u].join("")),n&&(l="h="+n),i&&(l=l+(l?"&":"")+"withReasons=true"),s=s+(l?"?":"")+l,t.debug(debugPolling(s)),c(s,v)},s.fetchGoals=function(){return c([o,"/sdk/goals/",r].join(""),null)},s}function Identity(e,n){var r={},t=void 0;return r.setUser=function(e){(t=sanitizeUser(e))&&n&&n(clone(t))},r.getUser=function(){return t?clone(t):null},e&&r.setUser(e),r}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 r=new Uint8Array(16);e.exports=function(){return n(r),r}}else{var t=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),t[n]=e>>>((3&n)<<3)&255;return t}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var r=n||0,t=byteToHex;return[t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]]].join("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,r){var t=n&&r||0,o=n||[],a=(e=e||{}).node||_nodeId,i=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==a||null==i){var u=rngBrowser();null==a&&(a=_nodeId=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==i&&(i=_clockseq=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),l=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,c=s-_lastMSecs+(l-_lastNSecs)/1e4;if(c<0&&void 0===e.clockseq&&(i=i+1&16383),(c<0||s>_lastMSecs)&&void 0===e.nsecs&&(l=0),l>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=s,_lastNSecs=l,_clockseq=i;var v=(1e4*(268435455&(s+=122192928e5))+l)%4294967296;o[t++]=v>>>24&255,o[t++]=v>>>16&255,o[t++]=v>>>8&255,o[t++]=255&v;var f=s/4294967296*1e4&268435455;o[t++]=f>>>8&255,o[t++]=255&f,o[t++]=f>>>24&15|16,o[t++]=f>>>16&255,o[t++]=i>>>8|128,o[t++]=255&i;for(var d=0;d<6;++d)o[t+d]=a[d];return n||bytesToUuid_1(o)}var v1_1=v1,ldUserIdKey="ld:$anonUserId";function UserValidator(e,n){var r={};return r.validateUser=function(r){if(!r)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var t=clone(r);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?(e?e.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(r){if(r)return t.key=r,t;var o=v1_1();return t.key=o,function(r){return e?e.set(ldUserIdKey,r).catch(function(){n.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(o).then(function(){return t})}):Promise.reject(new LDInvalidUserError(invalidUser()))},r}function validate(e,n,r,t){var o=extend({},{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:[]},r),a={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames"};function i(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var u=extend({},e||{});return function(e){var n=e;Object.keys(a).forEach(function(e){if(void 0!==n[e]){var r=a[e];t.warn(deprecated(e,r)),void 0===n[r]&&(n[r]=n[e]),delete n[e]}})}(u),u=function(e,n){var r=extend({},e);return Object.keys(n).forEach(function(e){void 0!==r[e]&&null!==r[e]||(r[e]=n[e])}),r}(u,o),(isNaN(u.flushInterval)||u.flushInterval<2e3)&&(u.flushInterval=2e3,i("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(u.samplingInterval)||u.samplingInterval<0)&&(u.samplingInterval=0,i("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 r={};function t(e,r,t){e>=n&&r(t)}return r.debug=function(e){return t(0,console.log,e)},r.info=function(e){return t(1,console.info,e)},r.warn=function(e){return t(2,console.warn,e)},r.error=function(e){return t(3,console.error,e)},r}var _typeof$1="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},readyEvent="ready",successEvent="initialized",failedEvent="failed",changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,r,t,o){var a=function(){if(r&&r.logger)return r.logger;return o&&o.logger||createConsoleLogger("warn")}(),i=EventEmitter(a),u=validate(r,i,o,a),s=u.hash,l=u.sendEvents,c=e,v=Stream(t,u,c,s),f=u.eventProcessor||EventProcessor(t,u,c,a,i),d=Requestor(t,u,c,a),g={},m={},p=void 0,y=void 0,h=u.streaming,E=void 0,b=!1,k=!1,S=!0,U=u.stateProvider,D=Identity(null,function(e){if(U)return;e&&w({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),P=UserValidator(t.localStorage,a),L=void 0;function w(e){c&&(U&&U.enqueueEvent&&U.enqueueEvent(e)||(e.user?(S=!1,!l||k||t.isDoNotTrack()||(a.debug(debugEnqueueingEvent(e.kind)),f.enqueue(e))):S&&(a.warn(eventWithoutUser()),S=!1)))}function I(e,n,r){var t=D.getUser(),o=new Date,a=n?n.value:null;if(!u.allowFrequentDuplicateEvents){var i=JSON.stringify(a)+(t&&t.key?t.key:"")+e,s=g[i];if(s&&o-s<3e5)return;g[i]=o}var l={kind:"feature",key:e,user:t,value:a,variation:n?n.variationIndex:null,default:r,creationDate:o.getTime(),reason:n?n.reason:null},c=m[e];c&&(l.version=c.flagVersion?c.flagVersion:c.version,l.trackEvents=c.trackEvents,l.debugEventsUntilDate=c.debugEventsUntilDate),w(l)}function F(e,n,r){var t=void 0;if(m&&m.hasOwnProperty(e)&&m[e]&&!m[e].deleted){var o=m[e];t=R(o),null!==o.value&&void 0!==o.value||(t.value=n)}else t={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return r&&I(e,t,n),t}function R(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function T(){y=!0,D.getUser()&&v.connect(D.getUser(),{ping:function(){a.debug(debugStreamPing()),d.fetchFlagSettings(D.getUser(),s).then(function(e){return O(e||{})}).catch(function(e){i.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var n=JSON.parse(e.data);a.debug(debugStreamPut()),O(n)},patch:function(e){var n=JSON.parse(e.data),r=m[n.key];if(!r||!r.version||!n.version||r.version<n.version){a.debug(debugStreamPatch(n.key));var t={},o=extend({},n);delete o.key,m[n.key]=o;var i=R(o);t[n.key]=r?{previous:r.value,current:i}:{current:i},x(t)}else a.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!m[n.key]||m[n.key].version<n.version){a.debug(debugStreamDelete(n.key));var r={};m[n.key]&&!m[n.key].deleted&&(r[n.key]={previous:m[n.key].value}),m[n.key]={version:n.version,deleted:!0},x(r)}else a.debug(debugStreamDeleteIgnored(n.key))}})}function N(){y&&(v.disconnect(),y=!1)}function O(e){var n={};if(!e)return Promise.resolve();for(var r in m)m.hasOwnProperty(r)&&m[r]&&(e[r]&&!deepEquals(e[r].value,m[r].value)?n[r]={previous:m[r].value,current:R(e[r])}:e[r]&&!e[r].deleted||(n[r]={previous:m[r].value}));for(var t in e)e.hasOwnProperty(t)&&e[t]&&(!m[t]||m[t].deleted)&&(n[t]={current:R(e[t])});return m=e,x(n).catch(function(){})}function x(e){var n=Object.keys(e);if(n.length>0){var r={};n.forEach(function(n){var t=e[n].current,o=t?t.value:void 0,a=e[n].previous;i.emit(changeEvent+":"+n,o,a),r[n]=t?{current:o,previous:a}:{previous:a}}),i.emit(changeEvent,r),i.emit(internalChangeEvent,m),u.sendEventsOnlyForVariation||U||n.forEach(function(n){I(n,e[n].current)})}return p&&L?L.saveFlags(m).catch(function(){return null}):Promise.resolve()}function C(){var e=h||E&&void 0===h;e&&!y?T():!e&&y&&N()}function A(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}t.localStorage&&(L=new Store(t.localStorage,c,s,D,a));var j=new Promise(function(e){var n=i.on(readyEvent,function(){i.off(readyEvent,n),e()})}),_=new Promise(function(e,n){var r=i.on(successEvent,function(){i.off(successEvent,r),e()}),t=i.on(failedEvent,function(e){i.off(failedEvent,t),n(e)})});if("string"==typeof u.bootstrap&&"LOCALSTORAGE"===u.bootstrap.toUpperCase()&&(L?p=!0:a.warn(localStorageUnavailable())),U){var V=U.getInitialState();V?q(V):U.on("init",q),U.on("update",function(e){e.user&&D.setUser(e.user);e.flags&&O(e.flags)})}else(function(){if(!e)return Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()));return P.validateUser(n).then(function(e){return D.setUser(e),"object"===_typeof$1(u.bootstrap)?(m=function(e){var n=Object.keys(e),r=e.$flagsState;!r&&n.length&&a.warn(bootstrapOldFormat()),!1===e.$valid&&a.warn(bootstrapInvalid());var t={};return n.forEach(function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};r&&r[n]?o=extend(o,r[n]):o.version=0,t[n]=o}}),t}(u.bootstrap),z()):p?L.loadFlags().catch(function(){return null}).then(function(e){return null==e?(m={},d.fetchFlagSettings(D.getUser(),s).then(function(e){return O(e||{})}).then(z).catch(function(e){var n=new LDFlagFetchError(errorFetchingFlags(e));K(n)})):(m=e,onNextTick(z),d.fetchFlagSettings(D.getUser(),s).then(function(e){return O(e)}).catch(function(e){return i.maybeReportError(e)}))}):d.fetchFlagSettings(D.getUser(),s).then(function(e){m=e||{},z()}).catch(function(e){m={},K(e)})})})().catch(function(e){return i.maybeReportError(e)});function q(e){c=e.environment,D.setUser(e.user),m=e.flags,onNextTick(z)}function z(){a.info(clientInitialized()),b=!0,C(),i.emit(readyEvent),i.emit(successEvent)}function K(e){i.maybeReportError(e),i.emit(failedEvent,e),i.emit(readyEvent)}return{client:{waitForInitialization:function(){return _},waitUntilReady:function(){return j},identify:function(e,n,r){return k?wrapPromiseCallback(Promise.resolve({}),r):U?(a.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(m)),r)):wrapPromiseCallback((p&&L?L.clearFlags():Promise.resolve()).then(function(){return P.validateUser(e)}).then(function(e){return D.setUser(e)}).then(function(){return d.fetchFlagSettings(D.getUser(),n)}).then(function(e){var n=transformVersionedValuesToValues(e);return e?O(e).then(function(){return n}):n}).then(function(e){return y&&T(),e}).catch(function(e){return i.maybeReportError(e),Promise.reject(e)}),r)},getUser:function(){return D.getUser()},variation:function(e,n){return F(e,n,!0).value},variationDetail:function(e,n){return F(e,n,!0)},track:function(e,n){"string"==typeof e?(t.customEventFilter&&!t.customEventFilter(e)&&a.warn(unknownCustomEventKey(e)),w({kind:"custom",key:e,data:n,user:D.getUser(),url:t.getCurrentUrl(),creationDate:(new Date).getTime()})):i.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,r){A(e)?(E=!0,b&&C(),i.on(e,n,r)):i.on.apply(i,arguments)},off:function(e){if(i.off.apply(i,arguments),A(e)){var n=!1;i.getEvents().forEach(function(e){A(e)&&i.getEventListenerCount(e)>0&&(n=!0)}),n||(E=!1,y&&void 0===h&&N())}},setStreaming:function(e){var n=null===e?void 0:e;n!==h&&(h=n,C())},flush:function(e){return wrapPromiseCallback(l?f.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!m)return e;for(var n in m)m.hasOwnProperty(n)&&(e[n]=F(n,null,!u.sendEventsOnlyForVariation).value);return e},close:function(e){if(k)return wrapPromiseCallback(Promise.resolve(),e);var n=function(){k=!0,m={}};return wrapPromiseCallback(Promise.resolve().then(function(){if(N(),l)return f.stop(),f.flush()}).then(n).catch(n),e)}},options:u,emitter:i,ident:D,logger:a,requestor:d,start:function(){l&&f.start()},enqueueEvent:w,getFlagsInternal:function(){return m},internalChangeEventName:internalChangeEvent}}var version="2.10.4";exports.initialize=initialize,exports.version=version,exports.createConsoleLogger=createConsoleLogger,exports.errors=errors,exports.messages=messages,exports.utils=utils; | ||
//# sourceMappingURL=ldclient-common.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
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,r){for(var t,o=[],a=n;a<r;a+=3)t=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(tripletToBase64(t));return o.join("")}function fromByteArray(e){for(var n,r=e.length,t=r%3,o=[],a=0,i=r-t;a<i;a+=16383)o.push(encodeChunk(e,a,a+16383>i?i:a+16383));return 1===t?(n=e[r-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2===t&&(n=(e[r-2]<<8)+e[r-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"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,r){if(n===r)return!0;if(n&&r&&"object"==(void 0===n?"undefined":_typeof(n))&&"object"==(void 0===r?"undefined":_typeof(r))){var t,o,a,i=isArray(n),u=isArray(r);if(i&&u){if((o=n.length)!=r.length)return!1;for(t=o;0!=t--;)if(!e(n[t],r[t]))return!1;return!0}if(i!=u)return!1;var s=n instanceof Date,l=r instanceof Date;if(s!=l)return!1;if(s&&l)return n.getTime()==r.getTime();var c=n instanceof RegExp,v=r instanceof RegExp;if(c!=v)return!1;if(c&&v)return n.toString()==r.toString();var f=keyList(n);if((o=f.length)!==keyList(r).length)return!1;for(t=o;0!=t--;)if(!hasProp.call(r,f[t]))return!1;for(t=o;0!=t--;)if(!e(n[a=f[t]],r[a]))return!1;return!0}return n!=n&&r!=r},_extends=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}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=[],r=0;r<e.length;r++)n.push(e.charCodeAt(r));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 r=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:r}function transformValuesToVersionedValues(e){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]={value:e[r],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r].value);return n}function chunkUserEventsForUrl(e,n){for(var r=n.slice(0),t=[],o=e,a=void 0;r.length>0;){for(a=[];o>0;){var i=r.shift();if(!i)break;(o-=base64URLEncode(JSON.stringify(i)).length)<0&&a.length>0?r.unshift(i):a.push(i)}o=e,t.push(a)}return t}function getLDUserAgentString(e){var n=e.version||"2.10.3";return e.userAgent+"/"+n}function getLDHeaders(e){return{"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)}}function extend(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];return n.reduce(function(e,n){return _extends({},e,n)},{})}function sanitizeUser(e){if(!e)return e;var n=void 0;for(var r in userAttrsToStringify){var t=userAttrsToStringify[r],o=e[t];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[t]=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,r,t){var o=n+"/events/bulk/"+r,a=n+"/a/"+r+".gif",i={};function u(e){(new window.Image).src=e}function s(n,r){var i=t||u,s=JSON.stringify(n);return r?function n(r){var t=extend({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},getLDHeaders(e));return e.httpRequest("POST",o,t,s).promise.then(function(e){if(e)return e.status>=400&&isHttpErrorRecoverable(e.status)&&r?n(!1):function(e){var n={status:e.status},r=e.header("date");if(r){var t=Date.parse(r);t&&(n.serverTime=t)}return n}(e)}).catch(function(){return r?n(!1):Promise.reject()})}(!0).catch(function(){}):(i(a+"?d="+base64URLEncode(s)),Promise.resolve())}return i.sendEvents=function(r){if(!e.httpRequest)return Promise.resolve();var t=e.httpAllowsPost(),o=void 0;o=t?[r]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,r);for(var a=[],i=0;i<o.length;i++)a.push(s(o[i],t));return Promise.all(a)},i}function EventSummarizer(){var e={},n=0,r=0,t={};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:""),a=t[o];a?a.count=a.count+1:t[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>r&&(r=e.creationDate)}},e.getSummary=function(){var e={},o=!0;for(var a in t){var i=t[a],u=e[i.key];u||(u={default:i.default,counters:[]},e[i.key]=u);var s={value:i.value,count:i.count};void 0!==i.variation&&null!==i.variation&&(s.variation=i.variation),i.version?s.version=i.version:s.unknown=!0,u.counters.push(s),o=!1}return o?null:{startDate:n,endDate:r,features:e}},e.clearSummary=function(){n=0,r=0,t={}},e}function UserFilter(e){var n={},r=e.allAttributesPrivate,t=e.privateAttributeNames||[],o={key:!0,custom:!0,anonymous:!0},a={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||[],i=function(e,a){return Object.keys(e).reduce(function(i,u){var s=i;return a(u)&&(!function(e){return!o[e]&&(r||-1!==n.indexOf(e)||-1!==t.indexOf(e))}(u)?s[0][u]=e[u]:s[1][u]=!0),s},[{},{}])},u=i(e,function(e){return a[e]}),s=u[0],l=u[1];if(e.custom){var c=i(e.custom,function(){return!0});s.custom=c[0],l=extend({},l,c[1])}var v=Object.keys(l);return v.length&&(v.sort(),s.privateAttrs=v),s},n}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: http://docs.launchdarkly.com/docs/running-an-ab-test#include-the-client-side-snippet"},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."+docLink},environmentNotSpecified=function(){return"No environment specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+(e.message||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,r){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?r:"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"},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,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,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents});function EventProcessor(e,n,r,t){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,i={},u=a||EventSender(e,n.eventsUrl,r),s=EventSummarizer(),l=UserFilter(n),c=n.inlineUsersInEvents,v=n.samplingInterval,f=n.flushInterval,d=[],g=0,m=!1,p=void 0;function y(){return 0===v||0===Math.floor(Math.random()*v)}return i.enqueue=function(e){if(!m){var n,r=!1,t=!1;if(s.summarizeEvent(e),"feature"===e.kind?y()&&(r=!!e.trackEvents,t=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>g&&n.debugEventsUntilDate>(new Date).getTime()):r=y(),r&&d.push(function(e){var n=extend({},e);return c||"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)),t){var o=extend({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,d.push(o)}}},i.flush=function(){if(m)return Promise.resolve();var e=d,n=s.getSummary();return s.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(d=[],t.debug(debugPostingEvents(e.length)),u.sendEvents(e).then(function(e){e&&(e.serverTime&&(g=e.serverTime),isHttpErrorRecoverable(e.status)||(m=!0),e.status>=400&&onNextTick(function(){o.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},i.start=function(){p=setTimeout(function e(){i.flush(),p=setTimeout(e,f)},f)},i.stop=function(){clearTimeout(p)},i}function EventEmitter(e){var n={},r={};return n.on=function(e,n,t){r[e]=r[e]||[],r[e]=r[e].concat({handler:n,context:t})},n.off=function(e,n,t){if(r[e])for(var o=0;o<r[e].length;o++)r[e][o].handler===n&&r[e][o].context===t&&(r[e]=r[e].slice(0,o).concat(r[e].slice(o+1)))},n.emit=function(e){if(r[e])for(var n=0;n<r[e].length;n++)r[e][n].handler.apply(r[e][n].context,Array.prototype.slice.call(arguments,1))},n.getEvents=function(){return Object.keys(r)},n.getEventListenerCount=function(e){return r[e]?r[e].length:0},n.maybeReportError=function(n){n&&(r["error"]?this.emit("error",n):(e||console).error(n.message))},n}function Store(e,n,r,t,o){var a={};function i(){var e="",o=t.getUser();return o&&(e=r||btoa(JSON.stringify(o))),"ld:"+n+":"+e}return a.loadFlags=function(){return e.get(i()).then(function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var r=n.$schema;void 0===r||r<1?n=transformValuesToVersionedValues(n):delete n.$schema}return n}catch(e){return a.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a.saveFlags=function(n){var r=extend({},n,{$schema:1});return e.set(i(),JSON.stringify(r)).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a.clearFlags=function(){return e.clear(i()).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a}function Stream(e,n,r,t){var o=n.streamUrl,a={},i=o+"/eval/"+r,u=n.useReport,s=n.evaluationReasons,l=n.streamReconnectDelay,c=null,v=null,f=null,d=null;function g(){y(),m(l)}function m(e){v||(e?v=setTimeout(p,e):p())}function p(){var n=void 0,a="",l={};if(e.eventSourceFactory){for(var v in null!=t&&(a="h="+t),u?e.eventSourceAllowsReport?(n=i,l.method="REPORT",l.headers={"Content-Type":"application/json"},l.body=JSON.stringify(f)):(n=o+"/ping/"+r,a=""):n=i+"/"+base64URLEncode(JSON.stringify(f)),s&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,y(),c=e.eventSourceFactory(n,l),d)d.hasOwnProperty(v)&&c.addEventListener(v,d[v]);c.onerror=g}}function y(){c&&(c.close(),c=null)}return a.connect=function(e,n){f=e,d=n,m()},a.disconnect=function(){clearTimeout(v),v=null,y()},a.isConnected=function(){return c&&e.eventSourceIsActive&&e.eventSourceIsActive(c)},a}function promiseCoalescer(e){var n=void 0,r=void 0,t=void 0,o=void 0,a={addPromise:function(a,i){n=a,r&&r(),r=i,a.then(function(r){n===a&&(t(r),e&&e())},function(r){n===a&&(o(r),e&&e())})}};return a.resultPromise=new Promise(function(e,n){t=e,o=n}),a}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,r,t){var o=n.baseUrl,a=n.useReport,i=n.evaluationReasons,u=n.sendLDHeaders,s={},l={};function c(n,r){if(!e.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var t=r?"REPORT":"GET",o=u?getLDHeaders(e):{};r&&(o["Content-Type"]="application/json");var a=l[n];a||(a=promiseCoalescer(function(){delete l[n]}),l[n]=a);var i=e.httpRequest(t,n,o,r),s=i.promise.then(function(e){return 200===e.status&&e.header("content-type")&&0===e.header("content-type").lastIndexOf(json)?JSON.parse(e.body):Promise.reject(getResponseError(e))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return a.addPromise(s,function(){i.cancel&&i.cancel()}),a.resultPromise}return s.fetchFlagSettings=function(e,n){var u=void 0,s=void 0,l="",v=void 0;return a?(s=[o,"/sdk/evalx/",r,"/user"].join(""),v=JSON.stringify(e)):(u=base64URLEncode(JSON.stringify(e)),s=[o,"/sdk/evalx/",r,"/users/",u].join("")),n&&(l="h="+n),i&&(l=l+(l?"&":"")+"withReasons=true"),s=s+(l?"?":"")+l,t.debug(debugPolling(s)),c(s,v)},s.fetchGoals=function(){return c([o,"/sdk/goals/",r].join(""),null)},s}function Identity(e,n){var r={},t=void 0;return r.setUser=function(e){(t=sanitizeUser(e))&&n&&n(clone(t))},r.getUser=function(){return t?clone(t):null},e&&r.setUser(e),r}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 r=new Uint8Array(16);e.exports=function(){return n(r),r}}else{var t=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),t[n]=e>>>((3&n)<<3)&255;return t}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var r=n||0,t=byteToHex;return[t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]]].join("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,r){var t=n&&r||0,o=n||[],a=(e=e||{}).node||_nodeId,i=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==a||null==i){var u=rngBrowser();null==a&&(a=_nodeId=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==i&&(i=_clockseq=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),l=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,c=s-_lastMSecs+(l-_lastNSecs)/1e4;if(c<0&&void 0===e.clockseq&&(i=i+1&16383),(c<0||s>_lastMSecs)&&void 0===e.nsecs&&(l=0),l>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=s,_lastNSecs=l,_clockseq=i;var v=(1e4*(268435455&(s+=122192928e5))+l)%4294967296;o[t++]=v>>>24&255,o[t++]=v>>>16&255,o[t++]=v>>>8&255,o[t++]=255&v;var f=s/4294967296*1e4&268435455;o[t++]=f>>>8&255,o[t++]=255&f,o[t++]=f>>>24&15|16,o[t++]=f>>>16&255,o[t++]=i>>>8|128,o[t++]=255&i;for(var d=0;d<6;++d)o[t+d]=a[d];return n||bytesToUuid_1(o)}var v1_1=v1,ldUserIdKey="ld:$anonUserId";function UserValidator(e,n){var r={};return r.validateUser=function(r){if(!r)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var t=clone(r);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?(e?e.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(r){if(r)return t.key=r,t;var o=v1_1();return t.key=o,function(r){return e?e.set(ldUserIdKey,r).catch(function(){n.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(o).then(function(){return t})}):Promise.reject(new LDInvalidUserError(invalidUser()))},r}function validate(e,n,r,t){var o=extend({},{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:[]},r),a={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames"};function i(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var u=extend({},e||{});return function(e){var n=e;Object.keys(a).forEach(function(e){if(void 0!==n[e]){var r=a[e];t.warn(deprecated(e,r)),void 0===n[r]&&(n[r]=n[e]),delete n[e]}})}(u),u=function(e,n){var r=extend({},e);return Object.keys(n).forEach(function(e){void 0!==r[e]&&null!==r[e]||(r[e]=n[e])}),r}(u,o),(isNaN(u.flushInterval)||u.flushInterval<2e3)&&(u.flushInterval=2e3,i("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(u.samplingInterval)||u.samplingInterval<0)&&(u.samplingInterval=0,i("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 r={};function t(e,r,t){e>=n&&r(t)}return r.debug=function(e){return t(0,console.log,e)},r.info=function(e){return t(1,console.info,e)},r.warn=function(e){return t(2,console.warn,e)},r.error=function(e){return t(3,console.error,e)},r}var _typeof$1="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},readyEvent="ready",successEvent="initialized",failedEvent="failed",changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,r,t,o){var a=function(){if(r&&r.logger)return r.logger;return o&&o.logger||createConsoleLogger("warn")}(),i=EventEmitter(a),u=validate(r,i,o,a),s=u.hash,l=u.sendEvents,c=e,v=Stream(t,u,c,s),f=u.eventProcessor||EventProcessor(t,u,c,a,i),d=Requestor(t,u,c,a),g={},m={},p=void 0,y=void 0,h=u.streaming,E=void 0,b=!1,k=!1,S=!0,U=u.stateProvider,D=Identity(null,function(e){if(U)return;e&&L({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),P=UserValidator(t.localStorage,a),w=void 0;function L(e){c&&(U&&U.enqueueEvent&&U.enqueueEvent(e)||(e.user?(S=!1,!l||k||t.isDoNotTrack()||(a.debug(debugEnqueueingEvent(e.kind)),f.enqueue(e))):S&&(a.warn(eventWithoutUser()),S=!1)))}function I(e,n,r){var t=D.getUser(),o=new Date,a=n?n.value:null;if(!u.allowFrequentDuplicateEvents){var i=JSON.stringify(a)+(t&&t.key?t.key:"")+e,s=g[i];if(s&&o-s<3e5)return;g[i]=o}var l={kind:"feature",key:e,user:t,value:a,variation:n?n.variationIndex:null,default:r,creationDate:o.getTime(),reason:n?n.reason:null},c=m[e];c&&(l.version=c.flagVersion?c.flagVersion:c.version,l.trackEvents=c.trackEvents,l.debugEventsUntilDate=c.debugEventsUntilDate),L(l)}function F(e,n,r){var t=void 0;if(m&&m.hasOwnProperty(e)&&m[e]&&!m[e].deleted){var o=m[e];t=R(o),null!==o.value&&void 0!==o.value||(t.value=n)}else t={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return r&&I(e,t,n),t}function R(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function T(){y=!0,D.getUser()&&v.connect(D.getUser(),{ping:function(){a.debug(debugStreamPing()),d.fetchFlagSettings(D.getUser(),s,function(e,n){e&&i.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e))),O(n)})},put:function(e){var n=JSON.parse(e.data);a.debug(debugStreamPut()),O(n)},patch:function(e){var n=JSON.parse(e.data),r=m[n.key];if(!r||!r.version||!n.version||r.version<n.version){a.debug(debugStreamPatch(n.key));var t={},o=extend({},n);delete o.key,m[n.key]=o;var i=R(o);t[n.key]=r?{previous:r.value,current:i}:{current:i},C(t)}else a.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!m[n.key]||m[n.key].version<n.version){a.debug(debugStreamDelete(n.key));var r={};m[n.key]&&!m[n.key].deleted&&(r[n.key]={previous:m[n.key].value}),m[n.key]={version:n.version,deleted:!0},C(r)}else a.debug(debugStreamDeleteIgnored(n.key))}})}function N(){y&&(v.disconnect(),y=!1)}function O(e){var n={};if(!e)return Promise.resolve();for(var r in m)m.hasOwnProperty(r)&&m[r]&&(e[r]&&!deepEquals(e[r].value,m[r].value)?n[r]={previous:m[r].value,current:R(e[r])}:e[r]&&!e[r].deleted||(n[r]={previous:m[r].value}));for(var t in e)e.hasOwnProperty(t)&&e[t]&&(!m[t]||m[t].deleted)&&(n[t]={current:R(e[t])});return m=e,C(n).catch(function(){})}function C(e){var n=Object.keys(e);if(n.length>0){var r={};n.forEach(function(n){var t=e[n].current,o=t?t.value:void 0,a=e[n].previous;i.emit(changeEvent+":"+n,o,a),r[n]=t?{current:o,previous:a}:{previous:a}}),i.emit(changeEvent,r),i.emit(internalChangeEvent,m),u.sendEventsOnlyForVariation||U||n.forEach(function(n){I(n,e[n].current)})}return p&&w?w.saveFlags(m).catch(function(){return null}):Promise.resolve()}function x(){var e=h||E&&void 0===h;e&&!y?T():!e&&y&&N()}function A(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}t.localStorage&&(w=new Store(t.localStorage,c,s,D,a));var j=new Promise(function(e){var n=i.on(readyEvent,function(){i.off(readyEvent,n),e()})}),_=new Promise(function(e,n){var r=i.on(successEvent,function(){i.off(successEvent,r),e()}),t=i.on(failedEvent,function(e){i.off(failedEvent,t),n(e)})});if("string"==typeof u.bootstrap&&"LOCALSTORAGE"===u.bootstrap.toUpperCase()&&(w?p=!0:a.warn(localStorageUnavailable())),U){var V=U.getInitialState();V?q(V):U.on("init",q),U.on("update",function(e){e.user&&D.setUser(e.user);e.flags&&O(e.flags)})}else(function(){if(!e)return Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()));return P.validateUser(n).then(function(e){return D.setUser(e),"object"===_typeof$1(u.bootstrap)?(m=function(e){var n=Object.keys(e),r=e.$flagsState;!r&&n.length&&a.warn(bootstrapOldFormat()),!1===e.$valid&&a.warn(bootstrapInvalid());var t={};return n.forEach(function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};r&&r[n]?o=extend(o,r[n]):o.version=0,t[n]=o}}),t}(u.bootstrap),z()):p?w.loadFlags().catch(function(){return null}).then(function(e){return null==e?(m={},d.fetchFlagSettings(D.getUser(),s).then(function(e){return O(e||{})}).then(z).catch(function(e){var n=new LDFlagFetchError(errorFetchingFlags(e));K(n)})):(m=e,onNextTick(z),d.fetchFlagSettings(D.getUser(),s).then(function(e){return O(e)}).catch(function(e){return i.maybeReportError(e)}))}):d.fetchFlagSettings(D.getUser(),s).then(function(e){m=e||{},z()}).catch(function(e){m={},K(e)})})})().catch(function(e){return i.maybeReportError(e)});function q(e){c=e.environment,D.setUser(e.user),m=e.flags,onNextTick(z)}function z(){a.info(clientInitialized()),b=!0,x(),i.emit(readyEvent),i.emit(successEvent)}function K(e){i.maybeReportError(e),i.emit(failedEvent,e),i.emit(readyEvent)}return{client:{waitForInitialization:function(){return _},waitUntilReady:function(){return j},identify:function(e,n,r){return k?wrapPromiseCallback(Promise.resolve({}),r):U?(a.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(m)),r)):wrapPromiseCallback((p&&w?w.clearFlags():Promise.resolve()).then(function(){return P.validateUser(e)}).then(function(e){return D.setUser(e)}).then(function(){return d.fetchFlagSettings(D.getUser(),n)}).then(function(e){var n=transformVersionedValuesToValues(e);return e?O(e).then(function(){return n}):n}).then(function(e){return y&&T(),e}).catch(function(e){return i.maybeReportError(e),Promise.reject(e)}),r)},getUser:function(){return D.getUser()},variation:function(e,n){return F(e,n,!0).value},variationDetail:function(e,n){return F(e,n,!0)},track:function(e,n){"string"==typeof e?(t.customEventFilter&&!t.customEventFilter(e)&&a.warn(unknownCustomEventKey(e)),L({kind:"custom",key:e,data:n,user:D.getUser(),url:t.getCurrentUrl(),creationDate:(new Date).getTime()})):i.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,r){A(e)?(E=!0,b&&x(),i.on(e,n,r)):i.on.apply(i,arguments)},off:function(e){if(i.off.apply(i,arguments),A(e)){var n=!1;i.getEvents().forEach(function(e){A(e)&&i.getEventListenerCount(e)>0&&(n=!0)}),n||(E=!1,y&&void 0===h&&N())}},setStreaming:function(e){var n=null===e?void 0:e;n!==h&&(h=n,x())},flush:function(e){return wrapPromiseCallback(l?f.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!m)return e;for(var n in m)m.hasOwnProperty(n)&&(e[n]=F(n,null,!u.sendEventsOnlyForVariation).value);return e},close:function(e){if(k)return wrapPromiseCallback(Promise.resolve(),e);var n=function(){k=!0,m={}};return wrapPromiseCallback(Promise.resolve().then(function(){if(N(),l)return f.stop(),f.flush()}).then(n).catch(n),e)}},options:u,emitter:i,ident:D,logger:a,requestor:d,start:function(){l&&f.start()},enqueueEvent:L,getFlagsInternal:function(){return m},internalChangeEventName:internalChangeEvent}}var version="2.10.3";export{initialize,version,createConsoleLogger,errors,messages,utils}; | ||
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,r){for(var t,o=[],a=n;a<r;a+=3)t=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(tripletToBase64(t));return o.join("")}function fromByteArray(e){for(var n,r=e.length,t=r%3,o=[],a=0,i=r-t;a<i;a+=16383)o.push(encodeChunk(e,a,a+16383>i?i:a+16383));return 1===t?(n=e[r-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2===t&&(n=(e[r-2]<<8)+e[r-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"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,r){if(n===r)return!0;if(n&&r&&"object"==(void 0===n?"undefined":_typeof(n))&&"object"==(void 0===r?"undefined":_typeof(r))){var t,o,a,i=isArray(n),u=isArray(r);if(i&&u){if((o=n.length)!=r.length)return!1;for(t=o;0!=t--;)if(!e(n[t],r[t]))return!1;return!0}if(i!=u)return!1;var s=n instanceof Date,l=r instanceof Date;if(s!=l)return!1;if(s&&l)return n.getTime()==r.getTime();var c=n instanceof RegExp,v=r instanceof RegExp;if(c!=v)return!1;if(c&&v)return n.toString()==r.toString();var f=keyList(n);if((o=f.length)!==keyList(r).length)return!1;for(t=o;0!=t--;)if(!hasProp.call(r,f[t]))return!1;for(t=o;0!=t--;)if(!e(n[a=f[t]],r[a]))return!1;return!0}return n!=n&&r!=r},_extends=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}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=[],r=0;r<e.length;r++)n.push(e.charCodeAt(r));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 r=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:r}function transformValuesToVersionedValues(e){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]={value:e[r],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r].value);return n}function chunkUserEventsForUrl(e,n){for(var r=n.slice(0),t=[],o=e,a=void 0;r.length>0;){for(a=[];o>0;){var i=r.shift();if(!i)break;(o-=base64URLEncode(JSON.stringify(i)).length)<0&&a.length>0?r.unshift(i):a.push(i)}o=e,t.push(a)}return t}function getLDUserAgentString(e){var n=e.version||"2.10.4";return e.userAgent+"/"+n}function getLDHeaders(e){return{"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)}}function extend(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];return n.reduce(function(e,n){return _extends({},e,n)},{})}function sanitizeUser(e){if(!e)return e;var n=void 0;for(var r in userAttrsToStringify){var t=userAttrsToStringify[r],o=e[t];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[t]=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,r,t){var o=n+"/events/bulk/"+r,a=n+"/a/"+r+".gif",i={};function u(e){(new window.Image).src=e}function s(n,r){var i=t||u,s=JSON.stringify(n);return r?function n(r){var t=extend({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},getLDHeaders(e));return e.httpRequest("POST",o,t,s).promise.then(function(e){if(e)return e.status>=400&&isHttpErrorRecoverable(e.status)&&r?n(!1):function(e){var n={status:e.status},r=e.header("date");if(r){var t=Date.parse(r);t&&(n.serverTime=t)}return n}(e)}).catch(function(){return r?n(!1):Promise.reject()})}(!0).catch(function(){}):(i(a+"?d="+base64URLEncode(s)),Promise.resolve())}return i.sendEvents=function(r){if(!e.httpRequest)return Promise.resolve();var t=e.httpAllowsPost(),o=void 0;o=t?[r]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,r);for(var a=[],i=0;i<o.length;i++)a.push(s(o[i],t));return Promise.all(a)},i}function EventSummarizer(){var e={},n=0,r=0,t={};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:""),a=t[o];a?a.count=a.count+1:t[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>r&&(r=e.creationDate)}},e.getSummary=function(){var e={},o=!0;for(var a in t){var i=t[a],u=e[i.key];u||(u={default:i.default,counters:[]},e[i.key]=u);var s={value:i.value,count:i.count};void 0!==i.variation&&null!==i.variation&&(s.variation=i.variation),i.version?s.version=i.version:s.unknown=!0,u.counters.push(s),o=!1}return o?null:{startDate:n,endDate:r,features:e}},e.clearSummary=function(){n=0,r=0,t={}},e}function UserFilter(e){var n={},r=e.allAttributesPrivate,t=e.privateAttributeNames||[],o={key:!0,custom:!0,anonymous:!0},a={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||[],i=function(e,a){return Object.keys(e).reduce(function(i,u){var s=i;return a(u)&&(!function(e){return!o[e]&&(r||-1!==n.indexOf(e)||-1!==t.indexOf(e))}(u)?s[0][u]=e[u]:s[1][u]=!0),s},[{},{}])},u=i(e,function(e){return a[e]}),s=u[0],l=u[1];if(e.custom){var c=i(e.custom,function(){return!0});s.custom=c[0],l=extend({},l,c[1])}var v=Object.keys(l);return v.length&&(v.sort(),s.privateAttrs=v),s},n}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: http://docs.launchdarkly.com/docs/running-an-ab-test#include-the-client-side-snippet"},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."+docLink},environmentNotSpecified=function(){return"No environment specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+(e.message||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,r){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?r:"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"},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,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,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents});function EventProcessor(e,n,r,t){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,i={},u=a||EventSender(e,n.eventsUrl,r),s=EventSummarizer(),l=UserFilter(n),c=n.inlineUsersInEvents,v=n.samplingInterval,f=n.flushInterval,d=[],g=0,m=!1,p=void 0;function y(){return 0===v||0===Math.floor(Math.random()*v)}return i.enqueue=function(e){if(!m){var n,r=!1,t=!1;if(s.summarizeEvent(e),"feature"===e.kind?y()&&(r=!!e.trackEvents,t=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>g&&n.debugEventsUntilDate>(new Date).getTime()):r=y(),r&&d.push(function(e){var n=extend({},e);return c||"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)),t){var o=extend({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,d.push(o)}}},i.flush=function(){if(m)return Promise.resolve();var e=d,n=s.getSummary();return s.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(d=[],t.debug(debugPostingEvents(e.length)),u.sendEvents(e).then(function(e){e&&(e.serverTime&&(g=e.serverTime),isHttpErrorRecoverable(e.status)||(m=!0),e.status>=400&&onNextTick(function(){o.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},i.start=function(){p=setTimeout(function e(){i.flush(),p=setTimeout(e,f)},f)},i.stop=function(){clearTimeout(p)},i}function EventEmitter(e){var n={},r={};return n.on=function(e,n,t){r[e]=r[e]||[],r[e]=r[e].concat({handler:n,context:t})},n.off=function(e,n,t){if(r[e])for(var o=0;o<r[e].length;o++)r[e][o].handler===n&&r[e][o].context===t&&(r[e]=r[e].slice(0,o).concat(r[e].slice(o+1)))},n.emit=function(e){if(r[e])for(var n=0;n<r[e].length;n++)r[e][n].handler.apply(r[e][n].context,Array.prototype.slice.call(arguments,1))},n.getEvents=function(){return Object.keys(r)},n.getEventListenerCount=function(e){return r[e]?r[e].length:0},n.maybeReportError=function(n){n&&(r["error"]?this.emit("error",n):(e||console).error(n.message))},n}function Store(e,n,r,t,o){var a={};function i(){var e="",o=t.getUser();return o&&(e=r||btoa(JSON.stringify(o))),"ld:"+n+":"+e}return a.loadFlags=function(){return e.get(i()).then(function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var r=n.$schema;void 0===r||r<1?n=transformValuesToVersionedValues(n):delete n.$schema}return n}catch(e){return a.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a.saveFlags=function(n){var r=extend({},n,{$schema:1});return e.set(i(),JSON.stringify(r)).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a.clearFlags=function(){return e.clear(i()).catch(function(e){return o.warn(localStorageUnavailable()),Promise.reject(e)})},a}function Stream(e,n,r,t){var o=n.streamUrl,a={},i=o+"/eval/"+r,u=n.useReport,s=n.evaluationReasons,l=n.streamReconnectDelay,c=null,v=null,f=null,d=null;function g(){y(),m(l)}function m(e){v||(e?v=setTimeout(p,e):p())}function p(){var n=void 0,a="",l={};if(e.eventSourceFactory){for(var v in null!=t&&(a="h="+t),u?e.eventSourceAllowsReport?(n=i,l.method="REPORT",l.headers={"Content-Type":"application/json"},l.body=JSON.stringify(f)):(n=o+"/ping/"+r,a=""):n=i+"/"+base64URLEncode(JSON.stringify(f)),s&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,y(),c=e.eventSourceFactory(n,l),d)d.hasOwnProperty(v)&&c.addEventListener(v,d[v]);c.onerror=g}}function y(){c&&(c.close(),c=null)}return a.connect=function(e,n){f=e,d=n,m()},a.disconnect=function(){clearTimeout(v),v=null,y()},a.isConnected=function(){return c&&e.eventSourceIsActive&&e.eventSourceIsActive(c)},a}function promiseCoalescer(e){var n=void 0,r=void 0,t=void 0,o=void 0,a={addPromise:function(a,i){n=a,r&&r(),r=i,a.then(function(r){n===a&&(t(r),e&&e())},function(r){n===a&&(o(r),e&&e())})}};return a.resultPromise=new Promise(function(e,n){t=e,o=n}),a}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,r,t){var o=n.baseUrl,a=n.useReport,i=n.evaluationReasons,u=n.sendLDHeaders,s={},l={};function c(n,r){if(!e.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var t=r?"REPORT":"GET",o=u?getLDHeaders(e):{};r&&(o["Content-Type"]="application/json");var a=l[n];a||(a=promiseCoalescer(function(){delete l[n]}),l[n]=a);var i=e.httpRequest(t,n,o,r),s=i.promise.then(function(e){return 200===e.status&&e.header("content-type")&&0===e.header("content-type").lastIndexOf(json)?JSON.parse(e.body):Promise.reject(getResponseError(e))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return a.addPromise(s,function(){i.cancel&&i.cancel()}),a.resultPromise}return s.fetchFlagSettings=function(e,n){var u=void 0,s=void 0,l="",v=void 0;return a?(s=[o,"/sdk/evalx/",r,"/user"].join(""),v=JSON.stringify(e)):(u=base64URLEncode(JSON.stringify(e)),s=[o,"/sdk/evalx/",r,"/users/",u].join("")),n&&(l="h="+n),i&&(l=l+(l?"&":"")+"withReasons=true"),s=s+(l?"?":"")+l,t.debug(debugPolling(s)),c(s,v)},s.fetchGoals=function(){return c([o,"/sdk/goals/",r].join(""),null)},s}function Identity(e,n){var r={},t=void 0;return r.setUser=function(e){(t=sanitizeUser(e))&&n&&n(clone(t))},r.getUser=function(){return t?clone(t):null},e&&r.setUser(e),r}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 r=new Uint8Array(16);e.exports=function(){return n(r),r}}else{var t=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),t[n]=e>>>((3&n)<<3)&255;return t}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var r=n||0,t=byteToHex;return[t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],"-",t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]],t[e[r++]]].join("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,r){var t=n&&r||0,o=n||[],a=(e=e||{}).node||_nodeId,i=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==a||null==i){var u=rngBrowser();null==a&&(a=_nodeId=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==i&&(i=_clockseq=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),l=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,c=s-_lastMSecs+(l-_lastNSecs)/1e4;if(c<0&&void 0===e.clockseq&&(i=i+1&16383),(c<0||s>_lastMSecs)&&void 0===e.nsecs&&(l=0),l>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=s,_lastNSecs=l,_clockseq=i;var v=(1e4*(268435455&(s+=122192928e5))+l)%4294967296;o[t++]=v>>>24&255,o[t++]=v>>>16&255,o[t++]=v>>>8&255,o[t++]=255&v;var f=s/4294967296*1e4&268435455;o[t++]=f>>>8&255,o[t++]=255&f,o[t++]=f>>>24&15|16,o[t++]=f>>>16&255,o[t++]=i>>>8|128,o[t++]=255&i;for(var d=0;d<6;++d)o[t+d]=a[d];return n||bytesToUuid_1(o)}var v1_1=v1,ldUserIdKey="ld:$anonUserId";function UserValidator(e,n){var r={};return r.validateUser=function(r){if(!r)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var t=clone(r);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?(e?e.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(r){if(r)return t.key=r,t;var o=v1_1();return t.key=o,function(r){return e?e.set(ldUserIdKey,r).catch(function(){n.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(o).then(function(){return t})}):Promise.reject(new LDInvalidUserError(invalidUser()))},r}function validate(e,n,r,t){var o=extend({},{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:[]},r),a={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames"};function i(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var u=extend({},e||{});return function(e){var n=e;Object.keys(a).forEach(function(e){if(void 0!==n[e]){var r=a[e];t.warn(deprecated(e,r)),void 0===n[r]&&(n[r]=n[e]),delete n[e]}})}(u),u=function(e,n){var r=extend({},e);return Object.keys(n).forEach(function(e){void 0!==r[e]&&null!==r[e]||(r[e]=n[e])}),r}(u,o),(isNaN(u.flushInterval)||u.flushInterval<2e3)&&(u.flushInterval=2e3,i("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(u.samplingInterval)||u.samplingInterval<0)&&(u.samplingInterval=0,i("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 r={};function t(e,r,t){e>=n&&r(t)}return r.debug=function(e){return t(0,console.log,e)},r.info=function(e){return t(1,console.info,e)},r.warn=function(e){return t(2,console.warn,e)},r.error=function(e){return t(3,console.error,e)},r}var _typeof$1="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},readyEvent="ready",successEvent="initialized",failedEvent="failed",changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,r,t,o){var a=function(){if(r&&r.logger)return r.logger;return o&&o.logger||createConsoleLogger("warn")}(),i=EventEmitter(a),u=validate(r,i,o,a),s=u.hash,l=u.sendEvents,c=e,v=Stream(t,u,c,s),f=u.eventProcessor||EventProcessor(t,u,c,a,i),d=Requestor(t,u,c,a),g={},m={},p=void 0,y=void 0,h=u.streaming,E=void 0,b=!1,k=!1,S=!0,U=u.stateProvider,D=Identity(null,function(e){if(U)return;e&&L({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),P=UserValidator(t.localStorage,a),w=void 0;function L(e){c&&(U&&U.enqueueEvent&&U.enqueueEvent(e)||(e.user?(S=!1,!l||k||t.isDoNotTrack()||(a.debug(debugEnqueueingEvent(e.kind)),f.enqueue(e))):S&&(a.warn(eventWithoutUser()),S=!1)))}function I(e,n,r){var t=D.getUser(),o=new Date,a=n?n.value:null;if(!u.allowFrequentDuplicateEvents){var i=JSON.stringify(a)+(t&&t.key?t.key:"")+e,s=g[i];if(s&&o-s<3e5)return;g[i]=o}var l={kind:"feature",key:e,user:t,value:a,variation:n?n.variationIndex:null,default:r,creationDate:o.getTime(),reason:n?n.reason:null},c=m[e];c&&(l.version=c.flagVersion?c.flagVersion:c.version,l.trackEvents=c.trackEvents,l.debugEventsUntilDate=c.debugEventsUntilDate),L(l)}function F(e,n,r){var t=void 0;if(m&&m.hasOwnProperty(e)&&m[e]&&!m[e].deleted){var o=m[e];t=R(o),null!==o.value&&void 0!==o.value||(t.value=n)}else t={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return r&&I(e,t,n),t}function R(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function T(){y=!0,D.getUser()&&v.connect(D.getUser(),{ping:function(){a.debug(debugStreamPing()),d.fetchFlagSettings(D.getUser(),s).then(function(e){return O(e||{})}).catch(function(e){i.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var n=JSON.parse(e.data);a.debug(debugStreamPut()),O(n)},patch:function(e){var n=JSON.parse(e.data),r=m[n.key];if(!r||!r.version||!n.version||r.version<n.version){a.debug(debugStreamPatch(n.key));var t={},o=extend({},n);delete o.key,m[n.key]=o;var i=R(o);t[n.key]=r?{previous:r.value,current:i}:{current:i},C(t)}else a.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!m[n.key]||m[n.key].version<n.version){a.debug(debugStreamDelete(n.key));var r={};m[n.key]&&!m[n.key].deleted&&(r[n.key]={previous:m[n.key].value}),m[n.key]={version:n.version,deleted:!0},C(r)}else a.debug(debugStreamDeleteIgnored(n.key))}})}function N(){y&&(v.disconnect(),y=!1)}function O(e){var n={};if(!e)return Promise.resolve();for(var r in m)m.hasOwnProperty(r)&&m[r]&&(e[r]&&!deepEquals(e[r].value,m[r].value)?n[r]={previous:m[r].value,current:R(e[r])}:e[r]&&!e[r].deleted||(n[r]={previous:m[r].value}));for(var t in e)e.hasOwnProperty(t)&&e[t]&&(!m[t]||m[t].deleted)&&(n[t]={current:R(e[t])});return m=e,C(n).catch(function(){})}function C(e){var n=Object.keys(e);if(n.length>0){var r={};n.forEach(function(n){var t=e[n].current,o=t?t.value:void 0,a=e[n].previous;i.emit(changeEvent+":"+n,o,a),r[n]=t?{current:o,previous:a}:{previous:a}}),i.emit(changeEvent,r),i.emit(internalChangeEvent,m),u.sendEventsOnlyForVariation||U||n.forEach(function(n){I(n,e[n].current)})}return p&&w?w.saveFlags(m).catch(function(){return null}):Promise.resolve()}function x(){var e=h||E&&void 0===h;e&&!y?T():!e&&y&&N()}function A(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}t.localStorage&&(w=new Store(t.localStorage,c,s,D,a));var j=new Promise(function(e){var n=i.on(readyEvent,function(){i.off(readyEvent,n),e()})}),_=new Promise(function(e,n){var r=i.on(successEvent,function(){i.off(successEvent,r),e()}),t=i.on(failedEvent,function(e){i.off(failedEvent,t),n(e)})});if("string"==typeof u.bootstrap&&"LOCALSTORAGE"===u.bootstrap.toUpperCase()&&(w?p=!0:a.warn(localStorageUnavailable())),U){var V=U.getInitialState();V?q(V):U.on("init",q),U.on("update",function(e){e.user&&D.setUser(e.user);e.flags&&O(e.flags)})}else(function(){if(!e)return Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()));return P.validateUser(n).then(function(e){return D.setUser(e),"object"===_typeof$1(u.bootstrap)?(m=function(e){var n=Object.keys(e),r=e.$flagsState;!r&&n.length&&a.warn(bootstrapOldFormat()),!1===e.$valid&&a.warn(bootstrapInvalid());var t={};return n.forEach(function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};r&&r[n]?o=extend(o,r[n]):o.version=0,t[n]=o}}),t}(u.bootstrap),z()):p?w.loadFlags().catch(function(){return null}).then(function(e){return null==e?(m={},d.fetchFlagSettings(D.getUser(),s).then(function(e){return O(e||{})}).then(z).catch(function(e){var n=new LDFlagFetchError(errorFetchingFlags(e));K(n)})):(m=e,onNextTick(z),d.fetchFlagSettings(D.getUser(),s).then(function(e){return O(e)}).catch(function(e){return i.maybeReportError(e)}))}):d.fetchFlagSettings(D.getUser(),s).then(function(e){m=e||{},z()}).catch(function(e){m={},K(e)})})})().catch(function(e){return i.maybeReportError(e)});function q(e){c=e.environment,D.setUser(e.user),m=e.flags,onNextTick(z)}function z(){a.info(clientInitialized()),b=!0,x(),i.emit(readyEvent),i.emit(successEvent)}function K(e){i.maybeReportError(e),i.emit(failedEvent,e),i.emit(readyEvent)}return{client:{waitForInitialization:function(){return _},waitUntilReady:function(){return j},identify:function(e,n,r){return k?wrapPromiseCallback(Promise.resolve({}),r):U?(a.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(m)),r)):wrapPromiseCallback((p&&w?w.clearFlags():Promise.resolve()).then(function(){return P.validateUser(e)}).then(function(e){return D.setUser(e)}).then(function(){return d.fetchFlagSettings(D.getUser(),n)}).then(function(e){var n=transformVersionedValuesToValues(e);return e?O(e).then(function(){return n}):n}).then(function(e){return y&&T(),e}).catch(function(e){return i.maybeReportError(e),Promise.reject(e)}),r)},getUser:function(){return D.getUser()},variation:function(e,n){return F(e,n,!0).value},variationDetail:function(e,n){return F(e,n,!0)},track:function(e,n){"string"==typeof e?(t.customEventFilter&&!t.customEventFilter(e)&&a.warn(unknownCustomEventKey(e)),L({kind:"custom",key:e,data:n,user:D.getUser(),url:t.getCurrentUrl(),creationDate:(new Date).getTime()})):i.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,r){A(e)?(E=!0,b&&x(),i.on(e,n,r)):i.on.apply(i,arguments)},off:function(e){if(i.off.apply(i,arguments),A(e)){var n=!1;i.getEvents().forEach(function(e){A(e)&&i.getEventListenerCount(e)>0&&(n=!0)}),n||(E=!1,y&&void 0===h&&N())}},setStreaming:function(e){var n=null===e?void 0:e;n!==h&&(h=n,x())},flush:function(e){return wrapPromiseCallback(l?f.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!m)return e;for(var n in m)m.hasOwnProperty(n)&&(e[n]=F(n,null,!u.sendEventsOnlyForVariation).value);return e},close:function(e){if(k)return wrapPromiseCallback(Promise.resolve(),e);var n=function(){k=!0,m={}};return wrapPromiseCallback(Promise.resolve().then(function(){if(N(),l)return f.stop(),f.flush()}).then(n).catch(n),e)}},options:u,emitter:i,ident:D,logger:a,requestor:d,start:function(){l&&f.start()},enqueueEvent:L,getFlagsInternal:function(){return m},internalChangeEventName:internalChangeEvent}}var version="2.10.4";export{initialize,version,createConsoleLogger,errors,messages,utils}; | ||
//# sourceMappingURL=ldclient-common.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-Common"]={})}(this,function(e){"use strict";function n(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 t=n("LaunchDarklyUnexpectedResponseError"),r=n("LaunchDarklyInvalidEnvironmentIdError"),o=n("LaunchDarklyInvalidUserError"),i=n("LaunchDarklyInvalidEventKeyError"),a=n("LaunchDarklyInvalidArgumentError"),u=n("LaunchDarklyFlagFetchError");function s(e){return!(e>=400&&e<500)||(400===e||408===e||429===e)}for(var c=Object.freeze({LDUnexpectedResponseError:t,LDInvalidEnvironmentIdError:r,LDInvalidUserError:o,LDInvalidEventKeyError:i,LDInvalidArgumentError:a,LDFlagFetchError:u,isHttpErrorRecoverable:s}),l=function(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(p(e,i,i+16383>a?a:i+16383));1===r?(n=e[t-1],o.push(f[n>>2]+f[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(f[n>>10]+f[n>>4&63]+f[n<<2&63]+"="));return o.join("")},f=[],v=[],d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",g=0,m=d.length;g<m;++g)f[g]=d[g],v[d.charCodeAt(g)]=g;function p(e,n,t){for(var r,o,i=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),i.push(f[(o=r)>>18&63]+f[o>>12&63]+f[o>>6&63]+f[63&o]);return i.join("")}v["-".charCodeAt(0)]=62,v["_".charCodeAt(0)]=63;var h="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},y=Array.isArray,b=Object.keys,k=Object.prototype.hasOwnProperty,E=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==(void 0===n?"undefined":h(n))&&"object"==(void 0===t?"undefined":h(t))){var r,o,i,a=y(n),u=y(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=b(n);if((o=v.length)!==b(t).length)return!1;for(r=o;0!=r--;)if(!k.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},S=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},w=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function P(e){var n=unescape(encodeURIComponent(e));return l(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function D(e){return P(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function U(e){return JSON.parse(JSON.stringify(e))}function O(e,n){return E(e,n)}function R(e){setTimeout(e,0)}function j(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function I(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function N(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function F(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-=D(JSON.stringify(a)).length)<0&&i.length>0?t.unshift(a):i.push(a)}o=e,r.push(i)}return r}function T(e){var n=e.version||"2.10.3";return e.userAgent+"/"+n}function L(e){return{"X-LaunchDarkly-User-Agent":T(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 S({},e,n)},{})}function x(e){if(!e)return e;var n=void 0;for(var t in w){var r=w[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[r]=String(o))}return n||e}var C=Object.freeze({btoa:P,base64URLEncode:D,clone:U,deepEquals:O,onNextTick:R,wrapPromiseCallback:j,transformValuesToVersionedValues:I,transformVersionedValuesToValues:N,chunkUserEventsForUrl:F,getLDUserAgentString:T,getLDHeaders:L,extend:A,sanitizeUser:x}),q=2e3;function J(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 c(n,t){var a=r||u,c=JSON.stringify(n);return t?function n(t){var r=A({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},L(e));return e.httpRequest("POST",o,r,c).promise.then(function(e){if(e)return e.status>=400&&s(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="+D(c)),Promise.resolve())}return a.sendEvents=function(t){if(!e.httpRequest)return Promise.resolve();var r=e.httpAllowsPost(),o=void 0;o=r?[t]:F(q-n.length,t);for(var i=[],a=0;a<o.length;a++)i.push(c(o[a],r));return Promise.all(i)},a}function V(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[0][u]=e[u]:s[1][u]=!0),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}var z=function(){return"LaunchDarkly client initialized"},_=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",K=function(){return"Be sure to call `identify` in the LaunchDarkly client: http://docs.launchdarkly.com/docs/running-an-ab-test#include-the-client-side-snippet"},M=function(){return"localStorage is unavailable"},$=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},H=function(e){return"network error"+(e?" ("+e+")":"")},G=function(e){return'Custom event "'+e+'" does not exist'},X=function(){return"environment not found."+_},B=function(){return"No environment specified."+_},W=function(e){return"Error fetching flag settings: "+(e.message||e)},Q=function(){return"No user specified."+_},Y=function(){return"Invalid user specified."+_},Z=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+_},ee=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},ne=function(e,n){return'[LaunchDarkly] "'+e+'" is deprecated, please use "'+n+'"'},te=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(s(e)?t:"giving up permanently")},re=function(){return"Cannot make HTTP requests in this environment."+_},oe=function(){return"identify() has no effect here; it must be called on the main client instance"},ie=function(e){return"polling for feature flags at "+e},ae=function(){return"received ping message from stream"},ue=function(){return"received streaming update for all flags"},se=function(e){return'received streaming update for flag "'+e+'"'},ce=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},le=function(e){return'received streaming deletion for flag "'+e+'"'},fe=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},ve=function(e){return'enqueueing "'+e+'" event'},de=function(e){return"sending "+e+" events"},ge=Object.freeze({clientInitialized:z,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventWithoutUser:K,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:M,localStorageUnavailableForUserId:$,networkError:H,unknownCustomEventKey:G,environmentNotFound:X,environmentNotSpecified:B,errorFetchingFlags:W,userNotSpecified:Q,invalidUser:Y,bootstrapOldFormat:Z,bootstrapInvalid:ee,deprecated:ne,httpErrorMessage:te,httpUnavailable:re,identifyDisabled:oe,debugPolling:ie,debugStreamPing:ae,debugStreamPut:ue,debugStreamPatch:se,debugStreamPatchIgnored:ce,debugStreamDelete:le,debugStreamDeleteIgnored:fe,debugEnqueueingEvent:ve,debugPostingEvents:de});function me(e,n,r,o){var i,a,u,c,l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,f=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,v={},d=f||J(e,n.eventsUrl,r),g=(a=0,u=0,c={},(i={}).summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=c[n];t?t.count=t.count+1:c[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>u&&(u=e.creationDate)}},i.getSummary=function(){var e={},n=!0;for(var t in c){var r=c[t],o=e[r.key];o||(o={default:r.default,counters:[]},e[r.key]=o);var i={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),n=!1}return n?null:{startDate:a,endDate:u,features:e}},i.clearSummary=function(){a=0,u=0,c={}},i),m=V(n),p=n.inlineUsersInEvents,h=n.samplingInterval,y=n.flushInterval,b=[],k=0,E=!1,S=void 0;function w(){return 0===h||0===Math.floor(Math.random()*h)}return v.enqueue=function(e){if(!E){var n,t=!1,r=!1;if(g.summarizeEvent(e),"feature"===e.kind?w()&&(t=!!e.trackEvents,r=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>k&&n.debugEventsUntilDate>(new Date).getTime()):t=w(),t&&b.push(function(e){var n=A({},e);return p||"identify"===e.kind?n.user=m.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,b.push(o)}}},v.flush=function(){if(E)return Promise.resolve();var e=b,n=g.getSummary();return g.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(b=[],o.debug(de(e.length)),d.sendEvents(e).then(function(e){e&&(e.serverTime&&(k=e.serverTime),s(e.status)||(E=!0),e.status>=400&&R(function(){l.maybeReportError(new t(te(e.status,"event posting","some events were dropped")))}))}))},v.start=function(){S=setTimeout(function e(){v.flush(),S=setTimeout(e,y)},y)},v.stop=function(){clearTimeout(S)},v}function pe(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}var he="application/json";function ye(e,n,t,o){var i=n.baseUrl,a=n.useReport,s=n.evaluationReasons,c=n.sendLDHeaders,l={},f={};function v(n,t){if(!e.httpRequest)return new Promise(function(e,n){n(new u(re()))});var o=t?"REPORT":"GET",i=c?L(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 s=e.httpRequest(o,n,i,t),l=s.promise.then(function(e){return 200===e.status&&e.header("content-type")&&0===e.header("content-type").lastIndexOf(he)?JSON.parse(e.body):Promise.reject(function(e){return 404===e.status?new r(X()):new u(W(e.statusText||String(e.status)))}(e))},function(e){return Promise.reject(new u(H(e)))});return a.addPromise(l,function(){s.cancel&&s.cancel()}),a.resultPromise}return l.fetchFlagSettings=function(e,n){var r=void 0,u=void 0,c="",l=void 0;return a?(u=[i,"/sdk/evalx/",t,"/user"].join(""),l=JSON.stringify(e)):(r=D(JSON.stringify(e)),u=[i,"/sdk/evalx/",t,"/users/",r].join("")),n&&(c="h="+n),s&&(c=c+(c?"&":"")+"withReasons=true"),u=u+(c?"?":"")+c,o.debug(ie(u)),v(u,l)},l.fetchGoals=function(){return v([i,"/sdk/goals/",t].join(""),null)},l}for(var be,ke=(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}}}(be={exports:{}},be.exports),be.exports),Ee=[],Se=0;Se<256;++Se)Ee[Se]=(Se+256).toString(16).substr(1);var we,Pe,De=function(e,n){var t=n||0,r=Ee;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("")},Ue=0,Oe=0;var Re=function(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||we,a=void 0!==e.clockseq?e.clockseq:Pe;if(null==i||null==a){var u=ke();null==i&&(i=we=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=Pe=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:Oe+1,l=s-Ue+(c-Oe)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>Ue)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Ue=s,Oe=c,Pe=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||De(o)},je="ld:$anonUserId";function Ie(e,n){var t={};return t.validateUser=function(t){if(!t)return Promise.reject(new o(Q()));var r=U(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get(je).catch(function(){return null}):Promise.resolve(null)).then(function(t){if(t)return r.key=t,r;var o=Re();return r.key=o,function(t){return e?e.set(je,t).catch(function(){n.warn($())}):Promise.resolve()}(o).then(function(){return r})}):Promise.reject(new o(Y()))},t}function Ne(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 Fe="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},Te="ready",Le="initialized",Ae="failed",xe="change",Ce="internal-change";e.initialize=function(e,n,t,o,s){var c=t&&t.logger?t.logger:s&&s.logger||Ne("warn"),l=pe(c),f=function(e,n,t,r){var o=A({},{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 u(e){R(function(){n&&n.maybeReportError(new a(e))})}var s=A({},e||{});return function(e){var n=e;Object.keys(i).forEach(function(e){if(void 0!==n[e]){var t=i[e];r.warn(ne(e,t)),void 0===n[t]&&(n[t]=n[e]),delete n[e]}})}(s),s=function(e,n){var t=A({},e);return Object.keys(n).forEach(function(e){void 0!==t[e]&&null!==t[e]||(t[e]=n[e])}),t}(s,o),(isNaN(s.flushInterval)||s.flushInterval<2e3)&&(s.flushInterval=2e3,u("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(s.samplingInterval)||s.samplingInterval<0)&&(s.samplingInterval=0,u("Invalid sampling interval configured. Sampling interval must be an integer >= 0.")),s}(t,l,s,c),v=f.hash,d=f.sendEvents,g=e,m=function(e,n,t,r){var o=n.streamUrl,i={},a=o+"/eval/"+t,u=n.useReport,s=n.evaluationReasons,c=n.streamReconnectDelay,l=null,f=null,v=null,d=null;function g(){h(),m(c)}function m(e){f||(e?f=setTimeout(p,e):p())}function p(){var n=void 0,i="",c={};if(e.eventSourceFactory){for(var f in null!=r&&(i="h="+r),u?e.eventSourceAllowsReport?(n=a,c.method="REPORT",c.headers={"Content-Type":"application/json"},c.body=JSON.stringify(v)):(n=o+"/ping/"+t,i=""):n=a+"/"+D(JSON.stringify(v)),s&&(i=i+(i?"&":"")+"withReasons=true"),n=n+(i?"?":"")+i,h(),l=e.eventSourceFactory(n,c),d)d.hasOwnProperty(f)&&l.addEventListener(f,d[f]);l.onerror=g}}function h(){l&&(l.close(),l=null)}return i.connect=function(e,n){v=e,d=n,m()},i.disconnect=function(){clearTimeout(f),f=null,h()},i.isConnected=function(){return l&&e.eventSourceIsActive&&e.eventSourceIsActive(l)},i}(o,f,g,v),p=f.eventProcessor||me(o,f,g,c,l),h=ye(o,f,g,c),y={},b={},k=void 0,E=void 0,S=f.streaming,w=void 0,F=!1,T=!1,L=!0,C=f.stateProvider,q=function(e,n){var t={},r=void 0;return t.setUser=function(e){(r=x(e))&&n&&n(U(r))},t.getUser=function(){return r?U(r):null},e&&t.setUser(e),t}(null,function(e){C||e&&_({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),J=Ie(o.localStorage,c),V=void 0;function _(e){g&&(C&&C.enqueueEvent&&C.enqueueEvent(e)||(e.user?(L=!1,!d||T||o.isDoNotTrack()||(c.debug(ve(e.kind)),p.enqueue(e))):L&&(c.warn(K()),L=!1)))}function $(e,n,t){var r=q.getUser(),o=new Date,i=n?n.value:null;if(!f.allowFrequentDuplicateEvents){var a=JSON.stringify(i)+(r&&r.key?r.key:"")+e,u=y[a];if(u&&o-u<3e5)return;y[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),_(s)}function H(e,n,t){var r=void 0;if(b&&b.hasOwnProperty(e)&&b[e]&&!b[e].deleted){var o=b[e];r=X(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&&$(e,r,n),r}function X(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function Q(){E=!0,q.getUser()&&m.connect(q.getUser(),{ping:function(){c.debug(ae()),h.fetchFlagSettings(q.getUser(),v,function(e,n){e&&l.maybeReportError(new u(W(e))),te(n)})},put:function(e){var n=JSON.parse(e.data);c.debug(ue()),te(n)},patch:function(e){var n=JSON.parse(e.data),t=b[n.key];if(!t||!t.version||!n.version||t.version<n.version){c.debug(se(n.key));var r={},o=A({},n);delete o.key,b[n.key]=o;var i=X(o);r[n.key]=t?{previous:t.value,current:i}:{current:i},re(r)}else c.debug(ce(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!b[n.key]||b[n.key].version<n.version){c.debug(le(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},re(t)}else c.debug(fe(n.key))}})}function Y(){E&&(m.disconnect(),E=!1)}function te(e){var n={};if(!e)return Promise.resolve();for(var t in b)b.hasOwnProperty(t)&&b[t]&&(e[t]&&!O(e[t].value,b[t].value)?n[t]={previous:b[t].value,current:X(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:X(e[r])});return b=e,re(n).catch(function(){})}function re(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;l.emit(xe+":"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}}),l.emit(xe,t),l.emit(Ce,b),f.sendEventsOnlyForVariation||C||n.forEach(function(n){$(n,e[n].current)})}return k&&V?V.saveFlags(b).catch(function(){return null}):Promise.resolve()}function ie(){var e=S||w&&void 0===S;e&&!E?Q():!e&&E&&Y()}function de(e){return e===xe||e.substr(0,xe.length+1)===xe+":"}o.localStorage&&(V=new function(e,n,t,r,o){var i={};function a(){var e="",o=r.getUser();return o&&(e=t||P(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=I(n):delete n.$schema}return n}catch(e){return i.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(M()),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(M()),Promise.reject(e)})},i.clearFlags=function(){return e.clear(a()).catch(function(e){return o.warn(M()),Promise.reject(e)})},i}(o.localStorage,g,v,q,c));var ge=new Promise(function(e){var n=l.on(Te,function(){l.off(Te,n),e()})}),he=new Promise(function(e,n){var t=l.on(Le,function(){l.off(Le,t),e()}),r=l.on(Ae,function(e){l.off(Ae,r),n(e)})});if("string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(V?k=!0:c.warn(M())),C){var be=C.getInitialState();be?ke(be):C.on("init",ke),C.on("update",function(e){e.user&&q.setUser(e.user),e.flags&&te(e.flags)})}else(e?J.validateUser(n).then(function(e){return q.setUser(e),"object"===Fe(f.bootstrap)?(b=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&c.warn(Z()),!1===e.$valid&&c.warn(ee());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}(f.bootstrap),Ee()):k?V.loadFlags().catch(function(){return null}).then(function(e){return null==e?(b={},h.fetchFlagSettings(q.getUser(),v).then(function(e){return te(e||{})}).then(Ee).catch(function(e){var n=new u(W(e));Se(n)})):(b=e,R(Ee),h.fetchFlagSettings(q.getUser(),v).then(function(e){return te(e)}).catch(function(e){return l.maybeReportError(e)}))}):h.fetchFlagSettings(q.getUser(),v).then(function(e){b=e||{},Ee()}).catch(function(e){b={},Se(e)})}):Promise.reject(new r(B()))).catch(function(e){return l.maybeReportError(e)});function ke(e){g=e.environment,q.setUser(e.user),b=e.flags,R(Ee)}function Ee(){c.info(z()),F=!0,ie(),l.emit(Te),l.emit(Le)}function Se(e){l.maybeReportError(e),l.emit(Ae,e),l.emit(Te)}return{client:{waitForInitialization:function(){return he},waitUntilReady:function(){return ge},identify:function(e,n,t){return T?j(Promise.resolve({}),t):C?(c.warn(oe()),j(Promise.resolve(N(b)),t)):j((k&&V?V.clearFlags():Promise.resolve()).then(function(){return J.validateUser(e)}).then(function(e){return q.setUser(e)}).then(function(){return h.fetchFlagSettings(q.getUser(),n)}).then(function(e){var n=N(e);return e?te(e).then(function(){return n}):n}).then(function(e){return E&&Q(),e}).catch(function(e){return l.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return q.getUser()},variation:function(e,n){return H(e,n,!0).value},variationDetail:function(e,n){return H(e,n,!0)},track:function(e,n){"string"==typeof e?(o.customEventFilter&&!o.customEventFilter(e)&&c.warn(G(e)),_({kind:"custom",key:e,data:n,user:q.getUser(),url:o.getCurrentUrl(),creationDate:(new Date).getTime()})):l.maybeReportError(new i(G(e)))},on:function(e,n,t){de(e)?(w=!0,F&&ie(),l.on(e,n,t)):l.on.apply(l,arguments)},off:function(e){if(l.off.apply(l,arguments),de(e)){var n=!1;l.getEvents().forEach(function(e){de(e)&&l.getEventListenerCount(e)>0&&(n=!0)}),n||(w=!1,E&&void 0===S&&Y())}},setStreaming:function(e){var n=null===e?void 0:e;n!==S&&(S=n,ie())},flush:function(e){return j(d?p.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!b)return e;for(var n in b)b.hasOwnProperty(n)&&(e[n]=H(n,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(T)return j(Promise.resolve(),e);var n=function(){T=!0,b={}};return j(Promise.resolve().then(function(){if(Y(),d)return p.stop(),p.flush()}).then(n).catch(n),e)}},options:f,emitter:l,ident:q,logger:c,requestor:h,start:function(){d&&p.start()},enqueueEvent:_,getFlagsInternal:function(){return b},internalChangeEventName:Ce}},e.version="2.10.3",e.createConsoleLogger=Ne,e.errors=c,e.messages=ge,e.utils=C,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-Common"]={})}(this,function(e){"use strict";function n(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 t=n("LaunchDarklyUnexpectedResponseError"),r=n("LaunchDarklyInvalidEnvironmentIdError"),o=n("LaunchDarklyInvalidUserError"),i=n("LaunchDarklyInvalidEventKeyError"),a=n("LaunchDarklyInvalidArgumentError"),u=n("LaunchDarklyFlagFetchError");function s(e){return!(e>=400&&e<500)||(400===e||408===e||429===e)}for(var c=Object.freeze({LDUnexpectedResponseError:t,LDInvalidEnvironmentIdError:r,LDInvalidUserError:o,LDInvalidEventKeyError:i,LDInvalidArgumentError:a,LDFlagFetchError:u,isHttpErrorRecoverable:s}),l=function(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(p(e,i,i+16383>a?a:i+16383));1===r?(n=e[t-1],o.push(f[n>>2]+f[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(f[n>>10]+f[n>>4&63]+f[n<<2&63]+"="));return o.join("")},f=[],v=[],d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",g=0,m=d.length;g<m;++g)f[g]=d[g],v[d.charCodeAt(g)]=g;function p(e,n,t){for(var r,o,i=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),i.push(f[(o=r)>>18&63]+f[o>>12&63]+f[o>>6&63]+f[63&o]);return i.join("")}v["-".charCodeAt(0)]=62,v["_".charCodeAt(0)]=63;var h="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},y=Array.isArray,b=Object.keys,k=Object.prototype.hasOwnProperty,E=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==(void 0===n?"undefined":h(n))&&"object"==(void 0===t?"undefined":h(t))){var r,o,i,a=y(n),u=y(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=b(n);if((o=v.length)!==b(t).length)return!1;for(r=o;0!=r--;)if(!k.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},S=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},w=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function P(e){var n=unescape(encodeURIComponent(e));return l(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function D(e){return P(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function U(e){return JSON.parse(JSON.stringify(e))}function O(e,n){return E(e,n)}function R(e){setTimeout(e,0)}function j(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function I(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function N(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function F(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-=D(JSON.stringify(a)).length)<0&&i.length>0?t.unshift(a):i.push(a)}o=e,r.push(i)}return r}function T(e){var n=e.version||"2.10.4";return e.userAgent+"/"+n}function L(e){return{"X-LaunchDarkly-User-Agent":T(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 S({},e,n)},{})}function x(e){if(!e)return e;var n=void 0;for(var t in w){var r=w[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||Object.assign({},e))[r]=String(o))}return n||e}var C=Object.freeze({btoa:P,base64URLEncode:D,clone:U,deepEquals:O,onNextTick:R,wrapPromiseCallback:j,transformValuesToVersionedValues:I,transformVersionedValuesToValues:N,chunkUserEventsForUrl:F,getLDUserAgentString:T,getLDHeaders:L,extend:A,sanitizeUser:x}),q=2e3;function J(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 c(n,t){var a=r||u,c=JSON.stringify(n);return t?function n(t){var r=A({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},L(e));return e.httpRequest("POST",o,r,c).promise.then(function(e){if(e)return e.status>=400&&s(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="+D(c)),Promise.resolve())}return a.sendEvents=function(t){if(!e.httpRequest)return Promise.resolve();var r=e.httpAllowsPost(),o=void 0;o=r?[t]:F(q-n.length,t);for(var i=[],a=0;a<o.length;a++)i.push(c(o[a],r));return Promise.all(i)},a}function V(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[0][u]=e[u]:s[1][u]=!0),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}var z=function(){return"LaunchDarkly client initialized"},_=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",K=function(){return"Be sure to call `identify` in the LaunchDarkly client: http://docs.launchdarkly.com/docs/running-an-ab-test#include-the-client-side-snippet"},M=function(){return"localStorage is unavailable"},$=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},H=function(e){return"network error"+(e?" ("+e+")":"")},G=function(e){return'Custom event "'+e+'" does not exist'},X=function(){return"environment not found."+_},B=function(){return"No environment specified."+_},W=function(e){return"Error fetching flag settings: "+(e.message||e)},Q=function(){return"No user specified."+_},Y=function(){return"Invalid user specified."+_},Z=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+_},ee=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},ne=function(e,n){return'[LaunchDarkly] "'+e+'" is deprecated, please use "'+n+'"'},te=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(s(e)?t:"giving up permanently")},re=function(){return"Cannot make HTTP requests in this environment."+_},oe=function(){return"identify() has no effect here; it must be called on the main client instance"},ie=function(e){return"polling for feature flags at "+e},ae=function(){return"received ping message from stream"},ue=function(){return"received streaming update for all flags"},se=function(e){return'received streaming update for flag "'+e+'"'},ce=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},le=function(e){return'received streaming deletion for flag "'+e+'"'},fe=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},ve=function(e){return'enqueueing "'+e+'" event'},de=function(e){return"sending "+e+" events"},ge=Object.freeze({clientInitialized:z,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventWithoutUser:K,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:M,localStorageUnavailableForUserId:$,networkError:H,unknownCustomEventKey:G,environmentNotFound:X,environmentNotSpecified:B,errorFetchingFlags:W,userNotSpecified:Q,invalidUser:Y,bootstrapOldFormat:Z,bootstrapInvalid:ee,deprecated:ne,httpErrorMessage:te,httpUnavailable:re,identifyDisabled:oe,debugPolling:ie,debugStreamPing:ae,debugStreamPut:ue,debugStreamPatch:se,debugStreamPatchIgnored:ce,debugStreamDelete:le,debugStreamDeleteIgnored:fe,debugEnqueueingEvent:ve,debugPostingEvents:de});function me(e,n,r,o){var i,a,u,c,l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,f=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,v={},d=f||J(e,n.eventsUrl,r),g=(a=0,u=0,c={},(i={}).summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=c[n];t?t.count=t.count+1:c[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>u&&(u=e.creationDate)}},i.getSummary=function(){var e={},n=!0;for(var t in c){var r=c[t],o=e[r.key];o||(o={default:r.default,counters:[]},e[r.key]=o);var i={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),n=!1}return n?null:{startDate:a,endDate:u,features:e}},i.clearSummary=function(){a=0,u=0,c={}},i),m=V(n),p=n.inlineUsersInEvents,h=n.samplingInterval,y=n.flushInterval,b=[],k=0,E=!1,S=void 0;function w(){return 0===h||0===Math.floor(Math.random()*h)}return v.enqueue=function(e){if(!E){var n,t=!1,r=!1;if(g.summarizeEvent(e),"feature"===e.kind?w()&&(t=!!e.trackEvents,r=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>k&&n.debugEventsUntilDate>(new Date).getTime()):t=w(),t&&b.push(function(e){var n=A({},e);return p||"identify"===e.kind?n.user=m.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,b.push(o)}}},v.flush=function(){if(E)return Promise.resolve();var e=b,n=g.getSummary();return g.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(b=[],o.debug(de(e.length)),d.sendEvents(e).then(function(e){e&&(e.serverTime&&(k=e.serverTime),s(e.status)||(E=!0),e.status>=400&&R(function(){l.maybeReportError(new t(te(e.status,"event posting","some events were dropped")))}))}))},v.start=function(){S=setTimeout(function e(){v.flush(),S=setTimeout(e,y)},y)},v.stop=function(){clearTimeout(S)},v}function pe(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}var he="application/json";function ye(e,n,t,o){var i=n.baseUrl,a=n.useReport,s=n.evaluationReasons,c=n.sendLDHeaders,l={},f={};function v(n,t){if(!e.httpRequest)return new Promise(function(e,n){n(new u(re()))});var o=t?"REPORT":"GET",i=c?L(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 s=e.httpRequest(o,n,i,t),l=s.promise.then(function(e){return 200===e.status&&e.header("content-type")&&0===e.header("content-type").lastIndexOf(he)?JSON.parse(e.body):Promise.reject(function(e){return 404===e.status?new r(X()):new u(W(e.statusText||String(e.status)))}(e))},function(e){return Promise.reject(new u(H(e)))});return a.addPromise(l,function(){s.cancel&&s.cancel()}),a.resultPromise}return l.fetchFlagSettings=function(e,n){var r=void 0,u=void 0,c="",l=void 0;return a?(u=[i,"/sdk/evalx/",t,"/user"].join(""),l=JSON.stringify(e)):(r=D(JSON.stringify(e)),u=[i,"/sdk/evalx/",t,"/users/",r].join("")),n&&(c="h="+n),s&&(c=c+(c?"&":"")+"withReasons=true"),u=u+(c?"?":"")+c,o.debug(ie(u)),v(u,l)},l.fetchGoals=function(){return v([i,"/sdk/goals/",t].join(""),null)},l}for(var be,ke=(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}}}(be={exports:{}},be.exports),be.exports),Ee=[],Se=0;Se<256;++Se)Ee[Se]=(Se+256).toString(16).substr(1);var we,Pe,De=function(e,n){var t=n||0,r=Ee;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("")},Ue=0,Oe=0;var Re=function(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||we,a=void 0!==e.clockseq?e.clockseq:Pe;if(null==i||null==a){var u=ke();null==i&&(i=we=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=Pe=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:Oe+1,l=s-Ue+(c-Oe)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>Ue)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Ue=s,Oe=c,Pe=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||De(o)},je="ld:$anonUserId";function Ie(e,n){var t={};return t.validateUser=function(t){if(!t)return Promise.reject(new o(Q()));var r=U(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get(je).catch(function(){return null}):Promise.resolve(null)).then(function(t){if(t)return r.key=t,r;var o=Re();return r.key=o,function(t){return e?e.set(je,t).catch(function(){n.warn($())}):Promise.resolve()}(o).then(function(){return r})}):Promise.reject(new o(Y()))},t}function Ne(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 Fe="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},Te="ready",Le="initialized",Ae="failed",xe="change",Ce="internal-change";e.initialize=function(e,n,t,o,s){var c=t&&t.logger?t.logger:s&&s.logger||Ne("warn"),l=pe(c),f=function(e,n,t,r){var o=A({},{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 u(e){R(function(){n&&n.maybeReportError(new a(e))})}var s=A({},e||{});return function(e){var n=e;Object.keys(i).forEach(function(e){if(void 0!==n[e]){var t=i[e];r.warn(ne(e,t)),void 0===n[t]&&(n[t]=n[e]),delete n[e]}})}(s),s=function(e,n){var t=A({},e);return Object.keys(n).forEach(function(e){void 0!==t[e]&&null!==t[e]||(t[e]=n[e])}),t}(s,o),(isNaN(s.flushInterval)||s.flushInterval<2e3)&&(s.flushInterval=2e3,u("Invalid flush interval configured. Must be an integer >= 2000 (milliseconds).")),(isNaN(s.samplingInterval)||s.samplingInterval<0)&&(s.samplingInterval=0,u("Invalid sampling interval configured. Sampling interval must be an integer >= 0.")),s}(t,l,s,c),v=f.hash,d=f.sendEvents,g=e,m=function(e,n,t,r){var o=n.streamUrl,i={},a=o+"/eval/"+t,u=n.useReport,s=n.evaluationReasons,c=n.streamReconnectDelay,l=null,f=null,v=null,d=null;function g(){h(),m(c)}function m(e){f||(e?f=setTimeout(p,e):p())}function p(){var n=void 0,i="",c={};if(e.eventSourceFactory){for(var f in null!=r&&(i="h="+r),u?e.eventSourceAllowsReport?(n=a,c.method="REPORT",c.headers={"Content-Type":"application/json"},c.body=JSON.stringify(v)):(n=o+"/ping/"+t,i=""):n=a+"/"+D(JSON.stringify(v)),s&&(i=i+(i?"&":"")+"withReasons=true"),n=n+(i?"?":"")+i,h(),l=e.eventSourceFactory(n,c),d)d.hasOwnProperty(f)&&l.addEventListener(f,d[f]);l.onerror=g}}function h(){l&&(l.close(),l=null)}return i.connect=function(e,n){v=e,d=n,m()},i.disconnect=function(){clearTimeout(f),f=null,h()},i.isConnected=function(){return l&&e.eventSourceIsActive&&e.eventSourceIsActive(l)},i}(o,f,g,v),p=f.eventProcessor||me(o,f,g,c,l),h=ye(o,f,g,c),y={},b={},k=void 0,E=void 0,S=f.streaming,w=void 0,F=!1,T=!1,L=!0,C=f.stateProvider,q=function(e,n){var t={},r=void 0;return t.setUser=function(e){(r=x(e))&&n&&n(U(r))},t.getUser=function(){return r?U(r):null},e&&t.setUser(e),t}(null,function(e){C||e&&_({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),J=Ie(o.localStorage,c),V=void 0;function _(e){g&&(C&&C.enqueueEvent&&C.enqueueEvent(e)||(e.user?(L=!1,!d||T||o.isDoNotTrack()||(c.debug(ve(e.kind)),p.enqueue(e))):L&&(c.warn(K()),L=!1)))}function $(e,n,t){var r=q.getUser(),o=new Date,i=n?n.value:null;if(!f.allowFrequentDuplicateEvents){var a=JSON.stringify(i)+(r&&r.key?r.key:"")+e,u=y[a];if(u&&o-u<3e5)return;y[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),_(s)}function H(e,n,t){var r=void 0;if(b&&b.hasOwnProperty(e)&&b[e]&&!b[e].deleted){var o=b[e];r=X(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&&$(e,r,n),r}function X(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function Q(){E=!0,q.getUser()&&m.connect(q.getUser(),{ping:function(){c.debug(ae()),h.fetchFlagSettings(q.getUser(),v).then(function(e){return te(e||{})}).catch(function(e){l.maybeReportError(new u(W(e)))})},put:function(e){var n=JSON.parse(e.data);c.debug(ue()),te(n)},patch:function(e){var n=JSON.parse(e.data),t=b[n.key];if(!t||!t.version||!n.version||t.version<n.version){c.debug(se(n.key));var r={},o=A({},n);delete o.key,b[n.key]=o;var i=X(o);r[n.key]=t?{previous:t.value,current:i}:{current:i},re(r)}else c.debug(ce(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!b[n.key]||b[n.key].version<n.version){c.debug(le(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},re(t)}else c.debug(fe(n.key))}})}function Y(){E&&(m.disconnect(),E=!1)}function te(e){var n={};if(!e)return Promise.resolve();for(var t in b)b.hasOwnProperty(t)&&b[t]&&(e[t]&&!O(e[t].value,b[t].value)?n[t]={previous:b[t].value,current:X(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:X(e[r])});return b=e,re(n).catch(function(){})}function re(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;l.emit(xe+":"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}}),l.emit(xe,t),l.emit(Ce,b),f.sendEventsOnlyForVariation||C||n.forEach(function(n){$(n,e[n].current)})}return k&&V?V.saveFlags(b).catch(function(){return null}):Promise.resolve()}function ie(){var e=S||w&&void 0===S;e&&!E?Q():!e&&E&&Y()}function de(e){return e===xe||e.substr(0,xe.length+1)===xe+":"}o.localStorage&&(V=new function(e,n,t,r,o){var i={};function a(){var e="",o=r.getUser();return o&&(e=t||P(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=I(n):delete n.$schema}return n}catch(e){return i.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return o.warn(M()),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(M()),Promise.reject(e)})},i.clearFlags=function(){return e.clear(a()).catch(function(e){return o.warn(M()),Promise.reject(e)})},i}(o.localStorage,g,v,q,c));var ge=new Promise(function(e){var n=l.on(Te,function(){l.off(Te,n),e()})}),he=new Promise(function(e,n){var t=l.on(Le,function(){l.off(Le,t),e()}),r=l.on(Ae,function(e){l.off(Ae,r),n(e)})});if("string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(V?k=!0:c.warn(M())),C){var be=C.getInitialState();be?ke(be):C.on("init",ke),C.on("update",function(e){e.user&&q.setUser(e.user),e.flags&&te(e.flags)})}else(e?J.validateUser(n).then(function(e){return q.setUser(e),"object"===Fe(f.bootstrap)?(b=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&c.warn(Z()),!1===e.$valid&&c.warn(ee());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}(f.bootstrap),Ee()):k?V.loadFlags().catch(function(){return null}).then(function(e){return null==e?(b={},h.fetchFlagSettings(q.getUser(),v).then(function(e){return te(e||{})}).then(Ee).catch(function(e){var n=new u(W(e));Se(n)})):(b=e,R(Ee),h.fetchFlagSettings(q.getUser(),v).then(function(e){return te(e)}).catch(function(e){return l.maybeReportError(e)}))}):h.fetchFlagSettings(q.getUser(),v).then(function(e){b=e||{},Ee()}).catch(function(e){b={},Se(e)})}):Promise.reject(new r(B()))).catch(function(e){return l.maybeReportError(e)});function ke(e){g=e.environment,q.setUser(e.user),b=e.flags,R(Ee)}function Ee(){c.info(z()),F=!0,ie(),l.emit(Te),l.emit(Le)}function Se(e){l.maybeReportError(e),l.emit(Ae,e),l.emit(Te)}return{client:{waitForInitialization:function(){return he},waitUntilReady:function(){return ge},identify:function(e,n,t){return T?j(Promise.resolve({}),t):C?(c.warn(oe()),j(Promise.resolve(N(b)),t)):j((k&&V?V.clearFlags():Promise.resolve()).then(function(){return J.validateUser(e)}).then(function(e){return q.setUser(e)}).then(function(){return h.fetchFlagSettings(q.getUser(),n)}).then(function(e){var n=N(e);return e?te(e).then(function(){return n}):n}).then(function(e){return E&&Q(),e}).catch(function(e){return l.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return q.getUser()},variation:function(e,n){return H(e,n,!0).value},variationDetail:function(e,n){return H(e,n,!0)},track:function(e,n){"string"==typeof e?(o.customEventFilter&&!o.customEventFilter(e)&&c.warn(G(e)),_({kind:"custom",key:e,data:n,user:q.getUser(),url:o.getCurrentUrl(),creationDate:(new Date).getTime()})):l.maybeReportError(new i(G(e)))},on:function(e,n,t){de(e)?(w=!0,F&&ie(),l.on(e,n,t)):l.on.apply(l,arguments)},off:function(e){if(l.off.apply(l,arguments),de(e)){var n=!1;l.getEvents().forEach(function(e){de(e)&&l.getEventListenerCount(e)>0&&(n=!0)}),n||(w=!1,E&&void 0===S&&Y())}},setStreaming:function(e){var n=null===e?void 0:e;n!==S&&(S=n,ie())},flush:function(e){return j(d?p.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!b)return e;for(var n in b)b.hasOwnProperty(n)&&(e[n]=H(n,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(T)return j(Promise.resolve(),e);var n=function(){T=!0,b={}};return j(Promise.resolve().then(function(){if(Y(),d)return p.stop(),p.flush()}).then(n).catch(n),e)}},options:f,emitter:l,ident:q,logger:c,requestor:h,start:function(){d&&p.start()},enqueueEvent:_,getFlagsInternal:function(){return b},internalChangeEventName:Ce}},e.version="2.10.4",e.createConsoleLogger=Ne,e.errors=c,e.messages=ge,e.utils=C,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=ldclient-common.min.js.map |
{ | ||
"name": "launchdarkly-js-sdk-common", | ||
"version": "2.10.3", | ||
"version": "2.10.4", | ||
"description": "LaunchDarkly SDK for JavaScript - common code", | ||
@@ -19,2 +19,3 @@ "author": "LaunchDarkly <team@launchdarkly.com>", | ||
"module": "dist/ldclient-common.es.js", | ||
"unpkg": "dist/ldclient-common.min.js", | ||
"scripts": { | ||
@@ -21,0 +22,0 @@ "lint": "eslint --format 'node_modules/eslint-formatter-pretty' --ignore-path ../../.eslintignore", |
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
423344