launchdarkly-js-sdk-common 3.4.0-alpha.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,30 @@
2
2
 
3
3
  All notable changes to the `launchdarkly-js-sdk-common` package will be documented in this file. Changes that affect the dependent SDKs such as `launchdarkly-js-client-sdk` should also be logged in those projects, in the next release that uses the updated version of this package. This project adheres to [Semantic Versioning](http://semver.org).
4
4
 
5
+ ## [4.0.0] - 2022-01-14
6
+ ### Changed:
7
+ - Updated `uuid` package to 8.x.
8
+ - In TypeScript, the property `LDEvaluationDetail.reason` is now nullable, which correctly reflects the fact that evaluation reasons may not always be available.
9
+
10
+ ### Removed:
11
+ - Removed the type `NonNullableLDEvaluationReason`, which was a side effect of the `LDEvaluationDetail.reason` being incorrectly defined before.
12
+ - Removed all types, properties, and functions that were deprecated as of the last 3.x release.
13
+
14
+ ## [3.5.0] - 2022-01-14
15
+ ### Added:
16
+ - New configurable logger factory `commonBasicLogger` and `BasicLoggerOptions`. The `commonBasicLogger` method is not intended to be exported directly in the SDKs, but wrapped to provide platform-specific behavior.
17
+
18
+ ### Fixed:
19
+ - Any exceptions thrown by the platform-specific local storage implementation (for instance, if we are in a browser and `window.localstorage` is available but disabled) are now consistently caught, and will only be logged the first time to avoid repetitive logging.
20
+
21
+ ## [3.4.0] - 2021-10-15
22
+ ### Added:
23
+ - Added LDOptionsBase.requestHeaderTransform allowing custom headers to be added to all requests.
24
+
25
+ ## [3.3.4] - 2021-10-15
26
+ ### Fixed:
27
+ - Reverted change to `uuid` dependency while working on some compatibility issues.
28
+
5
29
  ## [3.3.3] - 2021-08-23
6
30
  ### Fixed:
7
31
  - Updated `uuid` dependency to 8.x to remove deprecated usage. ([#46](https://github.com/launchdarkly/js-sdk-common/issues/46))
@@ -1,2 +1,2 @@
1
- "use strict";function _typeof(e){return(_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})(e)}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ownKeys(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function _objectSpread2(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(n,!0).forEach(function(e){_defineProperty(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ownKeys(n).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function createCustomError(e){function t(e,t){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=t}return(t.prototype=new Error).name=e,t.prototype.constructor=t}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!(400<=e&&e<500)||(400===e||408===e||429===e)}for(var errors=Object.freeze({__proto__:null,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,t,n){for(var r,o=[],i=t;i<n;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var t,n=e.length,r=n%3,o=[],i=16383,a=0,s=n-r;a<s;a+=i)o.push(encodeChunk(e,a,s<a+i?s:a+i));return 1==r?(t=e[n-1],o.push(lookup[t>>2]+lookup[t<<4&63]+"==")):2==r&&(t=(e[n-2]<<8)+e[n-1],o.push(lookup[t>>10]+lookup[t>>4&63]+lookup[t<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){var r,o,i,a=isArray(t),s=isArray(n);if(a&&s){if((o=t.length)!=n.length)return!1;for(r=o;0!=r--;)if(!e(t[r],n[r]))return!1;return!0}if(a!=s)return!1;var u=t instanceof Date,c=n instanceof Date;if(u!=c)return!1;if(u&&c)return t.getTime()==n.getTime();var l=t instanceof RegExp,d=n instanceof RegExp;if(l!=d)return!1;if(l&&d)return t.toString()==n.toString();var f=keyList(t);if((o=f.length)!==keyList(n).length)return!1;for(r=o;0!=r--;)if(!hasProp.call(n,f[r]))return!1;for(r=o;0!=r--;)if(!e(t[i=f[r]],n[i]))return!1;return!0}return t!=t&&n!=n},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function btoa(e){var t=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(t))}function stringToBytes(e){for(var t=[],n=0;n<e.length;n++)t.push(e.charCodeAt(n));return t}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,t){return fastDeepEqual(e,t)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(e,t){var n=e.then(function(e){return t&&setTimeout(function(){t(null,e)},0),e},function(e){if(!t)return Promise.reject(e);setTimeout(function(){t(e,null)},0)});return t?void 0:n}function transformValuesToVersionedValues(e){var t={};for(var n in e)objectHasOwnProperty(e,n)&&(t[n]={value:e[n],version:0});return t}function transformVersionedValuesToValues(e){var t={};for(var n in e)objectHasOwnProperty(e,n)&&(t[n]=e[n].value);return t}function chunkUserEventsForUrl(e,t){for(var n,r=t.slice(0),o=[],i=e;0<r.length;){for(n=[];0<i;){var a=r.shift();if(!a)break;(i-=base64URLEncode(JSON.stringify(a)).length)<0&&0<n.length?r.unshift(a):n.push(a)}i=e,o.push(n)}return o}function getLDUserAgentString(e){var t=e.version||"3.4.0-alpha.1";return e.userAgent+"/"+t}function getLDHeaders(e,t){if(t&&!t.sendLDHeaders)return{};var n={"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)};return t&&t.wrapperName&&(n["X-LaunchDarkly-Wrapper"]=t.wrapperVersion?t.wrapperName+"/"+t.wrapperVersion:t.wrapperName),n}function transformHeaders(e,t){return t&&t.requestHeaderTransform?t.requestHeaderTransform(_objectSpread2({},e)):e}function extend(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.reduce(function(e,t){return _objectSpread2({},e,{},t)},{})}function objectHasOwnProperty(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function sanitizeUser(e){if(!e)return e;var t;for(var n in userAttrsToStringify){var r=userAttrsToStringify[n],o=e[r];void 0!==o&&"string"!=typeof o&&((t=t||_objectSpread2({},e))[r]=String(o))}return t||e}var utils=Object.freeze({__proto__:null,btoa:btoa,base64URLEncode:base64URLEncode,clone:clone,deepEquals:deepEquals,onNextTick:onNextTick,wrapPromiseCallback:wrapPromiseCallback,transformValuesToVersionedValues:transformValuesToVersionedValues,transformVersionedValuesToValues:transformVersionedValuesToValues,chunkUserEventsForUrl:chunkUserEventsForUrl,getLDUserAgentString:getLDUserAgentString,getLDHeaders:getLDHeaders,transformHeaders:transformHeaders,extend:extend,objectHasOwnProperty:objectHasOwnProperty,sanitizeUser:sanitizeUser}),_require=require("uuid"),uuidv1=_require.v1,MAX_URL_LENGTH=2e3;function EventSender(s,e,u){var n="/a/"+e+".gif",c=extend({"Content-Type":"application/json"},getLDHeaders(s,u)),l=s.httpFallbackPing,d={};return d.sendChunk=function(e,r,o,t){var i=JSON.stringify(e),a=o?null:uuidv1();return t?function t(n){var e=o?c:extend({},c,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":a});return s.httpRequest("POST",r,transformHeaders(e,u),i).promise.then(function(e){if(e)return 400<=e.status&&isHttpErrorRecoverable(e.status)&&n?t(!1):function(e){var t={status:e.status},n=e.header("date");if(n){var r=Date.parse(n);r&&(t.serverTime=r)}return t}(e)}).catch(function(){return n?t(!1):Promise.reject()})}(!0).catch(function(){}):(l&&l(r+n+"?d="+base64URLEncode(i)),Promise.resolve())},d.sendEvents=function(e,t,n){if(!s.httpRequest)return Promise.resolve();var r,o=s.httpAllowsPost();r=o?[e]:chunkUserEventsForUrl(MAX_URL_LENGTH-t.length,e);for(var i=[],a=0;a<r.length;a++)i.push(d.sendChunk(r[a],t,n,o));return Promise.all(i)},d}function EventSummarizer(){var e={},a=0,s=0,u={};return e.summarizeEvent=function(e){if("feature"===e.kind){var t=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),n=u[t];n?n.count=n.count+1:u[t]={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>s&&(s=e.creationDate)}},e.getSummary=function(){var e={},t=!0;for(var n in u){var r=u[n],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),t=!1}return t?null:{startDate:a,endDate:s,features:e}},e.clearSummary=function(){s=a=0,u={}},e}function UserFilter(e){var t={},u=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},d={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return t.filterUser=function(e){if(!e)return null;function t(r,o){return Object.keys(r).reduce(function(e,t){var n=e;return o(t)&&(!function(e){return!l[e]&&(u||-1!==i.indexOf(e)||-1!==c.indexOf(e))}(t)?n[0][t]=r[t]:n[1][t]=!0),n},[{},{}])}var i=e.privateAttributeNames||[],n=t(e,function(e){return d[e]}),r=n[0],o=n[1];if(e.custom){var a=t(e.custom,function(){return!0});r.custom=a[0],o=extend({},o,a[1])}var s=Object.keys(o);return s.length&&(s.sort(),r.privateAttrs=s),r},t}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initializing-the-client for instructions on SDK initialization.",clientNotReady=function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},eventWithoutUser=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"},invalidContentType=function(e){return'Expected application/json content type but got "'+e+'"'},invalidKey=function(){return"Event key must be a string"},localStorageUnavailable=function(){return"localStorage is unavailable"},localStorageUnavailableForUserId=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},networkError=function(e){return"network error"+(e?" ("+e+")":"")},unknownCustomEventKey=function(e){return'Custom event "'+e+'" does not exist'},environmentNotFound=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+docLink},environmentNotSpecified=function(){return"No environment/client-side ID was specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+errorString(e)},userNotSpecified=function(){return"No user specified."+docLink},invalidUser=function(){return"Invalid user specified."+docLink},bootstrapOldFormat=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+docLink},bootstrapInvalid=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated=function(e,t){return t?'"'+e+'" is deprecated, please use "'+t+'"':'"'+e+'" is deprecated'},httpErrorMessage=function(e,t,n){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+t+" - "+(isHttpErrorRecoverable(e)?n:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e,t){return"Error on stream connection: "+errorString(e)+", will continue retrying every "+t+" milliseconds."},unknownOption=function(e){return'Ignoring unknown config option "'+e+'"'},wrongOptionType=function(e,t,n){return'Config option "'+e+'" should be of type '+t+", got "+n+", using default value"},wrongOptionTypeBoolean=function(e,t){return'Config option "'+e+'" should be a boolean, got '+t+", converting to boolean"},optionBelowMinimum=function(e,t,n){return'Config option "'+e+'" was set to '+t+", changing to minimum value of "+n},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"},debugPostingDiagnosticEvent=function(e){return"sending diagnostic event ("+e.kind+")"},messages=Object.freeze({__proto__:null,clientInitialized:clientInitialized,clientNotReady:clientNotReady,eventCapacityExceeded:eventCapacityExceeded,eventWithoutUser:eventWithoutUser,invalidContentType:invalidContentType,invalidKey:invalidKey,localStorageUnavailable:localStorageUnavailable,localStorageUnavailableForUserId:localStorageUnavailableForUserId,networkError:networkError,unknownCustomEventKey:unknownCustomEventKey,environmentNotFound:environmentNotFound,environmentNotSpecified:environmentNotSpecified,errorFetchingFlags:errorFetchingFlags,userNotSpecified:userNotSpecified,invalidUser:invalidUser,bootstrapOldFormat:bootstrapOldFormat,bootstrapInvalid:bootstrapInvalid,deprecated:deprecated,httpErrorMessage:httpErrorMessage,httpUnavailable:httpUnavailable,identifyDisabled:identifyDisabled,streamClosing:streamClosing,streamConnecting:streamConnecting,streamError:streamError,unknownOption:unknownOption,wrongOptionType:wrongOptionType,wrongOptionTypeBoolean:wrongOptionTypeBoolean,optionBelowMinimum:optionBelowMinimum,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents,debugPostingDiagnosticEvent:debugPostingDiagnosticEvent});function EventProcessor(e,t,n){var r,o=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null,i=4<arguments.length&&void 0!==arguments[4]?arguments[4]:null,a={},s=(5<arguments.length&&void 0!==arguments[5]?arguments[5]:null)||EventSender(e,n,t),u=t.eventsUrl+"/events/bulk/"+n,c=EventSummarizer(),l=UserFilter(t),d=t.inlineUsersInEvents,f=t.samplingInterval,v=t.eventCapacity,g=t.flushInterval,m=t.logger,p=[],y=0,h=!1,b=!1;function E(){return 0===f||0===Math.floor(Math.random()*f)}function k(e){p.length<v?(p.push(e),b=!1):(b||(b=!0,m.warn(eventCapacityExceeded())),o&&o.incrementDroppedEvents())}return a.enqueue=function(e){if(!h){var t=!1,n=!1;if(c.summarizeEvent(e),"feature"===e.kind?E()&&(t=!!e.trackEvents,n=function(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>y&&e.debugEventsUntilDate>(new Date).getTime())}(e)):t=E(),t&&k(function(e){var t=extend({},e);return"alias"===e.kind||(d||"identify"===e.kind?t.user=l.filterUser(e.user):(t.userKey=e.user.key,delete t.user),"feature"===e.kind&&(delete t.trackEvents,delete t.debugEventsUntilDate)),t}(e)),n){var r=extend({},e,{kind:"debug"});r.user=l.filterUser(r.user),delete r.trackEvents,delete r.debugEventsUntilDate,k(r)}}},a.flush=function(){if(h)return Promise.resolve();var e=p,t=c.getSummary();return c.clearSummary(),t&&(t.kind="summary",e.push(t)),o&&o.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(p=[],m.debug(debugPostingEvents(e.length)),s.sendEvents(e,u).then(function(e){e&&(e.serverTime&&(y=e.serverTime),isHttpErrorRecoverable(e.status)||(h=!0),400<=e.status&&onNextTick(function(){i.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},a.start=function(){r=setTimeout(function e(){a.flush(),r=setTimeout(e,g)},g)},a.stop=function(){clearTimeout(r)},a}function EventEmitter(t){var e={},o={};return e.on=function(e,t,n){o[e]=o[e]||[],o[e]=o[e].concat({handler:t,context:n})},e.off=function(e,t,n){if(o[e])for(var r=0;r<o[e].length;r++)o[e][r].handler===t&&o[e][r].context===n&&(o[e]=o[e].slice(0,r).concat(o[e].slice(r+1)))},e.emit=function(e){if(o[e])for(var t=o[e].slice(0),n=0;n<t.length;n++)t[n].handler.apply(t[n].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(o)},e.getEventListenerCount=function(e){return o[e]?o[e].length:0},e.maybeReportError=function(e){e&&(!function(e){return!!o[e]}("error")?(t||console).error(e.message):this.emit("error",e))},e}var readyEvent="ready",successEvent="initialized",failureEvent="failed";function InitializationStateTracker(r){var t=!1,n=!1,o=null,e=null,i=new Promise(function(t){r.on(readyEvent,function e(){r.off(readyEvent,e),t()})}).catch(function(){});return{getInitializationPromise:function(){return e||(t?Promise.resolve():n?Promise.reject(o):e=new Promise(function(t,n){r.on(successEvent,function e(){r.off(successEvent,e),t()}),r.on(failureEvent,function e(t){r.off(failureEvent,e),n(t)})}))},getReadyPromise:function(){return i},signalSuccess:function(){t||n||(t=!0,r.emit(successEvent),r.emit(readyEvent))},signalFailure:function(e){t||n||(n=!0,o=e,r.emit(failureEvent,e),r.emit(readyEvent)),r.maybeReportError(e)}}}var InitializationState=InitializationStateTracker;function Store(n,r,o,i,a){var s={};function u(){var e="",t=i.getUser();return t&&(e=o||btoa(JSON.stringify(t))),"ld:"+r+":"+e}return s.loadFlags=function(){return n.get(u()).then(function(e){if(null==e)return null;try{var t=JSON.parse(e);if(t){var n=t.$schema;void 0===n||n<1?t=transformValuesToVersionedValues(t):delete t.$schema}return t}catch(e){return s.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},s.saveFlags=function(e){var t=extend({},e,{$schema:1});return n.set(u(),JSON.stringify(t)).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},s.clearFlags=function(){return n.clear(u()).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},s}var streamReadTimeoutMillis=3e5;function Stream(o,i,a,t){var s,u=i.streamUrl,c=i.logger,e={},l=u+"/eval/"+a,d=i.useReport,f=i.evaluationReasons,n=i.streamReconnectDelay,v=getLDHeaders(o,i),g=!1,m=null,p=null,y=null,h=null,b=null;function E(e){g||(c.warn(streamError(e,n)),g=!0),D(!1),S(),k(n)}function k(e){p||(e?p=setTimeout(r,e):r())}function r(){var e;p=null;var t="",n={headers:v,readTimeoutMillis:streamReadTimeoutMillis};if(o.eventSourceFactory){for(var r in null!=h&&(t="h="+h),d?o.eventSourceAllowsReport?(e=l,n.method="REPORT",n.headers["Content-Type"]="application/json",n.body=JSON.stringify(y)):(e=u+"/ping/"+a,t=""):e=l+"/"+base64URLEncode(JSON.stringify(y)),n.headers=transformHeaders(n.headers,i),f&&(t=t+(t?"&":"")+"withReasons=true"),e=e+(t?"?":"")+t,S(),c.info(streamConnecting(e)),s=(new Date).getTime(),m=o.eventSourceFactory(e,n),b)objectHasOwnProperty(b,r)&&m.addEventListener(r,b[r]);m.onerror=E}}function S(){m&&(c.info(streamClosing()),m.close(),m=null)}function D(e){s&&t&&t.recordStreamInit(s,!e,(new Date).getTime()-s),s=null}return e.connect=function(e,t,n){y=e,h=t,b={};function r(t){b[t]=function(e){D(!(g=!1)),n[t]&&n[t](e)}}for(var o in n||{})r(o);k()},e.disconnect=function(){clearTimeout(p),p=null,S()},e.isConnected=function(){return!!(m&&o.eventSourceIsActive&&o.eventSourceIsActive(m))},e}function promiseCoalescer(n){var r,o,i,a,e={addPromise:function(t,e){r=t,o&&o(),o=e,t.then(function(e){r===t&&(i(e),n&&n())},function(e){r===t&&(a(e),n&&n())})}};return e.resultPromise=new Promise(function(e,t){i=e,a=t}),e}var jsonContentType="application/json";function getResponseError(e){return 404===e.status?new LDInvalidEnvironmentIdError(environmentNotFound()):new LDFlagFetchError(errorFetchingFlags(e.statusText||String(e.status)))}function Requestor(s,u,a){var c=u.baseUrl,l=u.useReport,d=u.evaluationReasons,f=u.logger,e={},v={};function g(e,t){if(!s.httpRequest)return new Promise(function(e,t){t(new LDFlagFetchError(httpUnavailable()))});var n=t?"REPORT":"GET",r=getLDHeaders(s,u);t&&(r["Content-Type"]=jsonContentType);var o=v[e];o||(o=promiseCoalescer(function(){delete v[e]}),v[e]=o);var i=s.httpRequest(n,e,transformHeaders(r,u),t),a=i.promise.then(function(e){if(200!==e.status)return Promise.reject(getResponseError(e));if(e.header("content-type")&&e.header("content-type").substring(0,jsonContentType.length)===jsonContentType)return JSON.parse(e.body);var t=invalidContentType(e.header("content-type")||"");return Promise.reject(new LDFlagFetchError(t))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return o.addPromise(a,function(){i.cancel&&i.cancel()}),o.resultPromise}return e.fetchJSON=function(e){return g(c+e,null)},e.fetchFlagSettings=function(e,t){var n,r,o,i="";return l?(r=[c,"/sdk/evalx/",a,"/user"].join(""),o=JSON.stringify(e)):(n=base64URLEncode(JSON.stringify(e)),r=[c,"/sdk/evalx/",a,"/users/",n].join("")),t&&(i="h="+t),d&&(i=i+(i?"&":"")+"withReasons=true"),r=r+(i?"?":"")+i,f.debug(debugPolling(r)),g(r,o)},e}function Identity(e,n){var r,t={};return t.setUser=function(e){var t=r&&clone(r);(r=sanitizeUser(e))&&n&&n(clone(r),t)},t.getUser=function(){return r?clone(r):null},e&&t.setUser(e),t}var _require$1=require("uuid"),uuidv1$1=_require$1.v1,ldUserIdKey="ld:$anonUserId";function UserValidator(r,o){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var n=clone(e);return null!==n.key&&void 0!==n.key?(n.key=n.key.toString(),Promise.resolve(n)):n.anonymous?(r?r.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(e){if(e)return n.key=e,n;var t=uuidv1$1();return function(e){return r?r.set(ldUserIdKey,e).catch(function(){o.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(n.key=t).then(function(){return n})}):Promise.reject(new LDInvalidUserError(invalidUser()))},e}var baseOptionDefs={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},streaming:{type:"boolean"},sendLDHeaders:{default:!0},requestHeaderTransform:{type:"function"},inlineUsersInEvents:{default:!1},allowFrequentDuplicateEvents:{default:!1},sendEventsOnlyForVariation:{default:!1},useReport:{default:!1},evaluationReasons:{default:!1},eventCapacity:{default:100,minimum:1},flushInterval:{default:2e3,minimum:2e3},samplingInterval:{default:0,minimum:0},streamReconnectDelay:{default:1e3,minimum:0},allAttributesPrivate:{default:!1},privateAttributeNames:{default:[]},bootstrap:{type:"string|object"},diagnosticRecordingInterval:{default:9e5,minimum:2e3},diagnosticOptOut:{default:!1},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"},autoAliasingOptOut:{default:!1}};function validate(e,t,n,r){var a=extend({logger:{default:r}},baseOptionDefs,n),o={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function s(e){onNextTick(function(){t&&t.maybeReportError(new LDInvalidArgumentError(e))})}var i,u,c,l,d=extend({},e||{});function f(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var t=_typeof(e);return"boolean"===t||"string"===t||"number"===t||"function"===t?t:"object"}}return i=d,Object.keys(o).forEach(function(e){if(void 0!==i[e]){var t=o[e];r&&r.warn(deprecated(e,t)),t&&(void 0===i[t]&&(i[t]=i[e]),delete i[e])}}),u=extend({},d),Object.keys(a).forEach(function(e){void 0!==u[e]&&null!==u[e]||(u[e]=a[e]&&a[e].default)}),l=extend({},c=d=u),Object.keys(c).forEach(function(e){var t=c[e];if(null!=t){var n=a[e];if(void 0===n)s(unknownOption(e));else{var r=n.type||f(n.default);if("any"!==r){var o=r.split("|"),i=f(t);o.indexOf(i)<0?"boolean"===r?(l[e]=!!t,s(wrongOptionTypeBoolean(e,i))):(s(wrongOptionType(e,r,i)),l[e]=n.default):"number"===i&&void 0!==n.minimum&&t<n.minimum&&(s(optionBelowMinimum(e,t,n.minimum)),l[e]=n.minimum)}}}}),d=l}var getRandomValues,configuration=Object.freeze({__proto__:null,baseOptionDefs:baseOptionDefs,validate:validate}),rnds8=new Uint8Array(16);function rng(){if(!getRandomValues&&!(getRandomValues="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return getRandomValues(rnds8)}var REGEX=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function validate$1(e){return"string"==typeof e&&REGEX.test(e)}for(var _nodeId,_clockseq,byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex.push((i$1+256).toString(16).substr(1));function stringify(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,n=(byteToHex[e[t+0]]+byteToHex[e[t+1]]+byteToHex[e[t+2]]+byteToHex[e[t+3]]+"-"+byteToHex[e[t+4]]+byteToHex[e[t+5]]+"-"+byteToHex[e[t+6]]+byteToHex[e[t+7]]+"-"+byteToHex[e[t+8]]+byteToHex[e[t+9]]+"-"+byteToHex[e[t+10]]+byteToHex[e[t+11]]+byteToHex[e[t+12]]+byteToHex[e[t+13]]+byteToHex[e[t+14]]+byteToHex[e[t+15]]).toLowerCase();if(!validate$1(n))throw TypeError("Stringified UUID is invalid");return n}var _lastMSecs=0,_lastNSecs=0;function v1(e,t,n){var r=t&&n||0,o=t||new Array(16),i=(e=e||{}).node||_nodeId,a=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==i||null==a){var s=e.random||(e.rng||rng)();null==i&&(i=_nodeId=[1|s[0],s[1],s[2],s[3],s[4],s[5]]),null==a&&(a=_clockseq=16383&(s[6]<<8|s[7]))}var u=void 0!==e.msecs?e.msecs:Date.now(),c=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,l=u-_lastMSecs+(c-_lastNSecs)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||_lastMSecs<u)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=u,_clockseq=a;var d=(1e4*(268435455&(u+=122192928e5))+(_lastNSecs=c))%4294967296;o[r++]=d>>>24&255,o[r++]=d>>>16&255,o[r++]=d>>>8&255,o[r++]=255&d;var f=u/4294967296*1e4&268435455;o[r++]=f>>>8&255,o[r++]=255&f,o[r++]=f>>>24&15|16,o[r++]=f>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var v=0;v<6;++v)o[r+v]=i[v];return t||stringify(o)}function parse(e){if(!validate$1(e))throw TypeError("Invalid UUID");var t,n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n}function stringToBytes$1(e){e=unescape(encodeURIComponent(e));for(var t=[],n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}var DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function v35(e,a,s){function t(e,t,n,r){if("string"==typeof e&&(e=stringToBytes$1(e)),"string"==typeof t&&(t=parse(t)),16!==t.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var o=new Uint8Array(16+e.length);if(o.set(t),o.set(e,t.length),(o=s(o))[6]=15&o[6]|a,o[8]=63&o[8]|128,n){r=r||0;for(var i=0;i<16;++i)n[r+i]=o[i];return n}return stringify(o)}try{t.name=e}catch(e){}return t.DNS=DNS,t.URL=URL,t}function md5(e){if("string"==typeof e){var t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(var n=0;n<t.length;++n)e[n]=t.charCodeAt(n)}return md5ToHexEncodedArray(wordsToMd5(bytesToWords(e),8*e.length))}function md5ToHexEncodedArray(e){for(var t=[],n=32*e.length,r="0123456789abcdef",o=0;o<n;o+=8){var i=e[o>>5]>>>o%32&255,a=parseInt(r.charAt(i>>>4&15)+r.charAt(15&i),16);t.push(a)}return t}function getOutputLength(e){return 14+(e+64>>>9<<4)+1}function wordsToMd5(e,t){e[t>>5]|=128<<t%32,e[getOutputLength(t)-1]=t;for(var n=1732584193,r=-271733879,o=-1732584194,i=271733878,a=0;a<e.length;a+=16){var s=n,u=r,c=o,l=i;r=md5ii(r=md5ii(r=md5ii(r=md5ii(r=md5hh(r=md5hh(r=md5hh(r=md5hh(r=md5gg(r=md5gg(r=md5gg(r=md5gg(r=md5ff(r=md5ff(r=md5ff(r=md5ff(r,o=md5ff(o,i=md5ff(i,n=md5ff(n,r,o,i,e[a],7,-680876936),r,o,e[a+1],12,-389564586),n,r,e[a+2],17,606105819),i,n,e[a+3],22,-1044525330),o=md5ff(o,i=md5ff(i,n=md5ff(n,r,o,i,e[a+4],7,-176418897),r,o,e[a+5],12,1200080426),n,r,e[a+6],17,-1473231341),i,n,e[a+7],22,-45705983),o=md5ff(o,i=md5ff(i,n=md5ff(n,r,o,i,e[a+8],7,1770035416),r,o,e[a+9],12,-1958414417),n,r,e[a+10],17,-42063),i,n,e[a+11],22,-1990404162),o=md5ff(o,i=md5ff(i,n=md5ff(n,r,o,i,e[a+12],7,1804603682),r,o,e[a+13],12,-40341101),n,r,e[a+14],17,-1502002290),i,n,e[a+15],22,1236535329),o=md5gg(o,i=md5gg(i,n=md5gg(n,r,o,i,e[a+1],5,-165796510),r,o,e[a+6],9,-1069501632),n,r,e[a+11],14,643717713),i,n,e[a],20,-373897302),o=md5gg(o,i=md5gg(i,n=md5gg(n,r,o,i,e[a+5],5,-701558691),r,o,e[a+10],9,38016083),n,r,e[a+15],14,-660478335),i,n,e[a+4],20,-405537848),o=md5gg(o,i=md5gg(i,n=md5gg(n,r,o,i,e[a+9],5,568446438),r,o,e[a+14],9,-1019803690),n,r,e[a+3],14,-187363961),i,n,e[a+8],20,1163531501),o=md5gg(o,i=md5gg(i,n=md5gg(n,r,o,i,e[a+13],5,-1444681467),r,o,e[a+2],9,-51403784),n,r,e[a+7],14,1735328473),i,n,e[a+12],20,-1926607734),o=md5hh(o,i=md5hh(i,n=md5hh(n,r,o,i,e[a+5],4,-378558),r,o,e[a+8],11,-2022574463),n,r,e[a+11],16,1839030562),i,n,e[a+14],23,-35309556),o=md5hh(o,i=md5hh(i,n=md5hh(n,r,o,i,e[a+1],4,-1530992060),r,o,e[a+4],11,1272893353),n,r,e[a+7],16,-155497632),i,n,e[a+10],23,-1094730640),o=md5hh(o,i=md5hh(i,n=md5hh(n,r,o,i,e[a+13],4,681279174),r,o,e[a],11,-358537222),n,r,e[a+3],16,-722521979),i,n,e[a+6],23,76029189),o=md5hh(o,i=md5hh(i,n=md5hh(n,r,o,i,e[a+9],4,-640364487),r,o,e[a+12],11,-421815835),n,r,e[a+15],16,530742520),i,n,e[a+2],23,-995338651),o=md5ii(o,i=md5ii(i,n=md5ii(n,r,o,i,e[a],6,-198630844),r,o,e[a+7],10,1126891415),n,r,e[a+14],15,-1416354905),i,n,e[a+5],21,-57434055),o=md5ii(o,i=md5ii(i,n=md5ii(n,r,o,i,e[a+12],6,1700485571),r,o,e[a+3],10,-1894986606),n,r,e[a+10],15,-1051523),i,n,e[a+1],21,-2054922799),o=md5ii(o,i=md5ii(i,n=md5ii(n,r,o,i,e[a+8],6,1873313359),r,o,e[a+15],10,-30611744),n,r,e[a+6],15,-1560198380),i,n,e[a+13],21,1309151649),o=md5ii(o,i=md5ii(i,n=md5ii(n,r,o,i,e[a+4],6,-145523070),r,o,e[a+11],10,-1120210379),n,r,e[a+2],15,718787259),i,n,e[a+9],21,-343485551),n=safeAdd(n,s),r=safeAdd(r,u),o=safeAdd(o,c),i=safeAdd(i,l)}return[n,r,o,i]}function bytesToWords(e){if(0===e.length)return[];for(var t=8*e.length,n=new Uint32Array(getOutputLength(t)),r=0;r<t;r+=8)n[r>>5]|=(255&e[r/8])<<r%32;return n}function safeAdd(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function bitRotateLeft(e,t){return e<<t|e>>>32-t}function md5cmn(e,t,n,r,o,i){return safeAdd(bitRotateLeft(safeAdd(safeAdd(t,e),safeAdd(r,i)),o),n)}function md5ff(e,t,n,r,o,i,a){return md5cmn(t&n|~t&r,e,t,o,i,a)}function md5gg(e,t,n,r,o,i,a){return md5cmn(t&r|n&~r,e,t,o,i,a)}function md5hh(e,t,n,r,o,i,a){return md5cmn(t^n^r,e,t,o,i,a)}function md5ii(e,t,n,r,o,i,a){return md5cmn(n^(t|~r),e,t,o,i,a)}var v3=v35("v3",48,md5);function v4(e,t,n){var r=(e=e||{}).random||(e.rng||rng)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=r[o];return t}return stringify(r)}function f(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:return t^n^r;case 2:return t&n^t&r^n&r;case 3:return t^n^r}}function ROTL(e,t){return e<<t|e>>>32-t}function sha1(e){var t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){var r=unescape(encodeURIComponent(e));e=[];for(var o=0;o<r.length;++o)e.push(r.charCodeAt(o))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var i=e.length/4+2,a=Math.ceil(i/16),s=new Array(a),u=0;u<a;++u){for(var c=new Uint32Array(16),l=0;l<16;++l)c[l]=e[64*u+4*l]<<24|e[64*u+4*l+1]<<16|e[64*u+4*l+2]<<8|e[64*u+4*l+3];s[u]=c}s[a-1][14]=8*(e.length-1)/Math.pow(2,32),s[a-1][14]=Math.floor(s[a-1][14]),s[a-1][15]=8*(e.length-1)&4294967295;for(var d=0;d<a;++d){for(var v=new Uint32Array(80),g=0;g<16;++g)v[g]=s[d][g];for(var m=16;m<80;++m)v[m]=ROTL(v[m-3]^v[m-8]^v[m-14]^v[m-16],1);for(var p=n[0],y=n[1],h=n[2],b=n[3],E=n[4],k=0;k<80;++k){var S=Math.floor(k/20),D=ROTL(p,5)+f(S,y,h,b)+E+t[S]+v[k]>>>0;E=b,b=h,h=ROTL(y,30)>>>0,y=p,p=D}n[0]=n[0]+p>>>0,n[1]=n[1]+y>>>0,n[2]=n[2]+h>>>0,n[3]=n[3]+b>>>0,n[4]=n[4]+E>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]}var v5=v35("v5",80,sha1),nil="00000000-0000-0000-0000-000000000000";function version(e){if(!validate$1(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)}var esmBrowser=Object.freeze({__proto__:null,v1:v1,v3:v3,v4:v4,v5:v5,NIL:nil,version:version,validate:validate$1,stringify:stringify,parse:parse}),uuidv1$2=esmBrowser.v1,baseOptionDefs$1=configuration.baseOptionDefs;function DiagnosticId(e){var t={diagnosticId:uuidv1$2()};return e&&(t.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),t}function DiagnosticsAccumulator(e){var t,n,r,o;function i(e){t=e,r=n=0,o=[]}return i(e),{getProps:function(){return{dataSinceDate:t,droppedEvents:n,eventsInLastBatch:r,streamInits:o}},setProps:function(e){t=e.dataSinceDate,n=e.droppedEvents||0,r=e.eventsInLastBatch||0,o=e.streamInits||[]},incrementDroppedEvents:function(){n++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,t,n){var r={timestamp:e,failed:t,durationMillis:n};o.push(r)},reset:i}}function DiagnosticsManager(t,e,n,r,o,i){var a,s,u=!!t.diagnosticUseCombinedEvent,c="ld:"+r+":$diagnostics",l=o.eventsUrl+"/events/diagnostic/"+r,d=o.diagnosticRecordingInterval,f=e,v=!!o.streaming,g={};function m(){return{sdk:function(){var e=_objectSpread2({},t.diagnosticSdkData);o.wrapperName&&(e.wrapperName=o.wrapperName);o.wrapperVersion&&(e.wrapperVersion=o.wrapperVersion);return e}(),configuration:{customBaseURI:o.baseUrl!==baseOptionDefs$1.baseUrl.default,customStreamURI:o.streamUrl!==baseOptionDefs$1.streamUrl.default,customEventsURI:o.eventsUrl!==baseOptionDefs$1.eventsUrl.default,eventsCapacity:o.eventCapacity,eventsFlushIntervalMillis:o.flushInterval,reconnectTimeMillis:o.streamReconnectDelay,streamingDisabled:!v,allAttributesPrivate:!!o.allAttributesPrivate,inlineUsersInEvents:!!o.inlineUsersInEvents,diagnosticRecordingIntervalMillis:o.diagnosticRecordingInterval,usingSecureMode:!!o.hash,bootstrapMode:!!o.bootstrap,fetchGoalsDisabled:!o.fetchGoals,allowFrequentDuplicateEvents:!!o.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!o.sendEventsOnlyForVariation,autoAliasingOptOut:!!o.autoAliasingOptOut},platform:t.diagnosticPlatformData}}function p(e){o.logger&&o.logger.debug(messages.debugPostingDiagnosticEvent(e)),n.sendEvents(e,l,!0).then(function(){}).catch(function(){})}function y(){p(function(){var e=(new Date).getTime(),t=_objectSpread2({kind:u?"diagnostic-combined":"diagnostic",id:i,creationDate:e},f.getProps());return u&&(t=_objectSpread2({},t,{},m())),f.reset(e),t}()),s=setTimeout(y,d),a=(new Date).getTime(),u&&function(){if(t.localStorage){var e=_objectSpread2({},f.getProps());t.localStorage.set(c,JSON.stringify(e),function(){})}}()}return g.start=function(){u?function(n){if(!t.localStorage)return n(!1);t.localStorage.get(c).then(function(e){if(e)try{var t=JSON.parse(e);f.setProps(t),a=t.dataSinceDate}catch(e){}n(!0)}).catch(function(){n(!1)})}(function(e){if(e){var t=(a||0)+d,n=(new Date).getTime();t<=n?y():s=setTimeout(y,t-n)}else 0===Math.floor(4*Math.random())?y():s=setTimeout(y,d)}):(p(_objectSpread2({kind:"diagnostic-init",id:i,creationDate:f.getProps().dataSinceDate},m())),s=setTimeout(y,d))},g.stop=function(){s&&clearTimeout(s)},g.setStreaming=function(e){v=e},g}var diagnosticEvents={DiagnosticId:DiagnosticId,DiagnosticsAccumulator:DiagnosticsAccumulator,DiagnosticsManager:DiagnosticsManager},diagnosticEvents_1=diagnosticEvents.DiagnosticId,diagnosticEvents_2=diagnosticEvents.DiagnosticsAccumulator,diagnosticEvents_3=diagnosticEvents.DiagnosticsManager;function createConsoleLogger(e,t){var i,a=["debug","info","warn","error"];i=null!=t?""===t?"":t+" ":"LD: ";var s=0;e&&(s="none"===e?100:a.indexOf(e));var n={};function r(e,t,n){if(s<=e&&console){var r=console[t];if(r){var o=e<a.length?a[e]:"?";r.call(console,i+"["+o+"] "+n)}}}return n.debug=function(e){return r(0,"log",e)},n.info=function(e){return r(1,"info",e)},n.warn=function(e){return r(2,"warn",e)},n.error=function(e){return r(3,"error",e)},n}var changeEvent="change",internalChangeEvent="internal-change";function initialize(e,t,n,i,r){var a,o,s,u,c=function(){if(n&&n.logger)return n.logger;return r&&r.logger&&r.logger.default||createConsoleLogger("warn")}(),l=EventEmitter(c),d=InitializationState(l),f=validate(n,l,r,c),v=f.sendEvents,g=e,m=f.hash,p=EventSender(i,g,f),y=f.sendEvents&&!f.diagnosticOptOut,h=y?diagnosticEvents_1(g):null,b=y?diagnosticEvents_2((new Date).getTime()):null,E=y?diagnosticEvents_3(i,b,p,g,f,h):null,k=Stream(i,f,g,b),S=f.eventProcessor||EventProcessor(i,f,g,b,l,p),D=Requestor(i,f,g),w={},U={},P=f.streaming,T=!1,I=!1,O=!0,L=f.stateProvider,R=Identity(null,function(e,t){(function(e){if(L)return;e&&A({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})})(e),!f.autoAliasingOptOut&&t&&t.anonymous&&e&&!e.anonymous&&N(e,t)}),C=UserValidator(i.localStorage,c);function A(e){if(g&&!(L&&L.enqueueEvent&&L.enqueueEvent(e))){if("alias"!==e.kind){if(!e.user)return void(O&&(c.warn(eventWithoutUser()),O=!1));O=!1}!v||I||i.isDoNotTrack()||(c.debug(debugEnqueueingEvent(e.kind)),S.enqueue(e))}}function F(e,t,n,r){var o=R.getUser(),i=new Date,a=t?t.value:null;if(!f.allowFrequentDuplicateEvents){var s=JSON.stringify(a)+(o&&o.key?o.key:"")+e,u=w[s];if(u&&i-u<3e5)return;w[s]=i}var c={kind:"feature",key:e,user:o,value:a,variation:t?t.variationIndex:null,default:n,creationDate:i.getTime()};o&&o.anonymous&&(c.contextKind=_(o));var l=U[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&t&&(c.reason=t.reason),A(c)}function j(e,t,n,r){var o;if(U&&objectHasOwnProperty(U,e)&&U[e]&&!U[e].deleted){var i=U[e];o=x(i),null!==i.value&&void 0!==i.value||(o.value=t)}else o={value:t,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return n&&F(e,o,t,r),o}function x(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function _(e){return e.anonymous?"anonymousUser":"user"}function N(e,t){L||e&&t&&A({kind:"alias",key:e.key,contextKind:_(e),previousKey:t.key,previousContextKind:_(t),creationDate:(new Date).getTime()})}function H(){o=!0,R.getUser()&&k.connect(R.getUser(),m,{ping:function(){c.debug(debugStreamPing());var t=R.getUser();D.fetchFlagSettings(t,m).then(function(e){deepEquals(t,R.getUser())&&q(e||{})}).catch(function(e){l.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var t=JSON.parse(e.data);c.debug(debugStreamPut()),q(t)},patch:function(e){var t=JSON.parse(e.data),n=U[t.key];if(!n||!n.version||!t.version||n.version<t.version){c.debug(debugStreamPatch(t.key));var r={},o=extend({},t);delete o.key;var i=x(U[t.key]=o);r[t.key]=n?{previous:n.value,current:i}:{current:i},M(r)}else c.debug(debugStreamPatchIgnored(t.key))},delete:function(e){var t=JSON.parse(e.data);if(!U[t.key]||U[t.key].version<t.version){c.debug(debugStreamDelete(t.key));var n={};U[t.key]&&!U[t.key].deleted&&(n[t.key]={previous:U[t.key].value}),U[t.key]={version:t.version,deleted:!0},M(n)}else c.debug(debugStreamDeleteIgnored(t.key))}})}function V(){o&&(k.disconnect(),o=!1)}function q(e){var t={};if(!e)return Promise.resolve();for(var n in U)objectHasOwnProperty(U,n)&&U[n]&&(e[n]&&!deepEquals(e[n].value,U[n].value)?t[n]={previous:U[n].value,current:x(e[n])}:e[n]&&!e[n].deleted||(t[n]={previous:U[n].value}));for(var r in e)objectHasOwnProperty(e,r)&&e[r]&&(!U[r]||U[r].deleted)&&(t[r]={current:x(e[r])});return U=_objectSpread2({},e),M(t).catch(function(){})}function M(o){var e=Object.keys(o);if(0<e.length){var i={};e.forEach(function(e){var t=o[e].current,n=t?t.value:void 0,r=o[e].previous;l.emit(changeEvent+":"+e,n,r),i[e]=t?{current:n,previous:r}:{previous:r}}),l.emit(changeEvent,i),l.emit(internalChangeEvent,U),f.sendEventsOnlyForVariation||L||e.forEach(function(e){F(e,o[e].current)})}return a&&u?u.saveFlags(U).catch(function(){return null}):Promise.resolve()}function z(){var e=P||s&&void 0===P;e&&!o?H():!e&&o&&V(),E&&E.setStreaming(e)}function $(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}if(i.localStorage&&(u=new Store(i.localStorage,g,m,R,c)),"string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(u?a=!0:c.warn(localStorageUnavailable())),"object"===_typeof(f.bootstrap)&&(U=function(n){var e=Object.keys(n),r="$flagsState",o=n[r];!o&&e.length&&c.warn(bootstrapOldFormat()),!1===n.$valid&&c.warn(bootstrapInvalid());var i={};return e.forEach(function(e){if(e!==r&&"$valid"!==e){var t={value:n[e]};o&&o[e]?t=extend(t,o[e]):t.version=0,i[e]=t}}),i}(f.bootstrap)),L){var K=L.getInitialState();K?B(K):L.on("init",B),L.on("update",function(e){e.user&&R.setUser(e.user);e.flags&&q(e.flags)})}else(e?C.validateUser(t).then(function(e){return R.setUser(e),"object"===_typeof(f.bootstrap)?J():a?u.loadFlags().catch(function(){return null}).then(function(e){return null==e?(U={},D.fetchFlagSettings(R.getUser(),m).then(function(e){return q(e||{})}).then(J).catch(function(e){G(new LDFlagFetchError(errorFetchingFlags(e)))})):(U=e,onNextTick(J),D.fetchFlagSettings(R.getUser(),m).then(function(e){return q(e)}).catch(function(e){return l.maybeReportError(e)}))}):D.fetchFlagSettings(R.getUser(),m).then(function(e){U=e||{},J()}).catch(function(e){U={},G(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(G);function B(e){g=e.environment,R.setUser(e.user),U=_objectSpread2({},e.flags),onNextTick(J)}function J(){c.info(clientInitialized()),T=!0,z(),d.signalSuccess()}function G(e){d.signalFailure(e)}return{client:{waitForInitialization:function(){return d.getInitializationPromise()},waitUntilReady:function(){return d.getReadyPromise()},identify:function(e,r,t){return I?wrapPromiseCallback(Promise.resolve({}),t):L?(c.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(U)),t)):wrapPromiseCallback((a&&u?u.clearFlags():Promise.resolve()).then(function(){return C.validateUser(e)}).then(function(n){return D.fetchFlagSettings(n,r).then(function(e){var t=transformVersionedValuesToValues(e);return R.setUser(n),m=r,e?q(e).then(function(){return t}):t})}).then(function(e){return o&&H(),e}).catch(function(e){return l.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return R.getUser()},variation:function(e,t){return j(e,t,!0,!1).value},variationDetail:function(e,t){return j(e,t,!0,!0)},track:function(e,t,n){if("string"==typeof e){i.customEventFilter&&!i.customEventFilter(e)&&c.warn(unknownCustomEventKey(e));var r=R.getUser(),o={kind:"custom",key:e,user:r,url:i.getCurrentUrl(),creationDate:(new Date).getTime()};r&&r.anonymous&&(o.contextKind=_(r)),null!=t&&(o.data=t),null!=n&&(o.metricValue=n),A(o)}else l.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},alias:N,on:function(e,t,n){$(e)?(s=!0,T&&z(),l.on(e,t,n)):l.on.apply(l,arguments)},off:function(e){if(l.off.apply(l,arguments),$(e)){var t=!1;l.getEvents().forEach(function(e){$(e)&&0<l.getEventListenerCount(e)&&(t=!0)}),t||(s=!1,o&&void 0===P&&V())}},setStreaming:function(e){var t=null===e?void 0:e;t!==P&&(P=t,z())},flush:function(e){return wrapPromiseCallback(v?S.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!U)return e;for(var t in U)objectHasOwnProperty(U,t)&&(e[t]=j(t,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(I)return wrapPromiseCallback(Promise.resolve(),e);function t(){I=!0,U={}}return wrapPromiseCallback(Promise.resolve().then(function(){if(V(),E&&E.stop(),v)return S.stop(),S.flush()}).then(t).catch(t),e)}},options:f,emitter:l,ident:R,logger:c,requestor:D,start:function(){v&&(E&&E.start(),S.start())},enqueueEvent:A,getFlagsInternal:function(){return U},getEnvironmentId:function(){return g},internalChangeEventName:internalChangeEvent}}var version$1="3.4.0-alpha.1";exports.createConsoleLogger=createConsoleLogger,exports.errors=errors,exports.initialize=initialize,exports.messages=messages,exports.utils=utils,exports.version=version$1;
1
+ "use strict";function ownKeys(t,e){var n,r=Object.keys(t);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(t),e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)),r}function _objectSpread2(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(n),!0).forEach(function(e){_defineProperty(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function _typeof(e){return(_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})(e)}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Map"===(n="Object"===n&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function createCustomError(e){function t(e,t){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=t}return(t.prototype=new Error).name=e,t.prototype.constructor=t}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!(400<=e&&e<500)||(400===e||408===e||429===e)}for(var errors=Object.freeze({__proto__:null,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,t,n){for(var r,o=[],i=t;i<n;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var t,n=e.length,r=n%3,o=[],i=16383,a=0,s=n-r;a<s;a+=i)o.push(encodeChunk(e,a,s<a+i?s:a+i));return 1==r?(t=e[n-1],o.push(lookup[t>>2]+lookup[t<<4&63]+"==")):2==r&&(t=(e[n-2]<<8)+e[n-1],o.push(lookup[t>>10]+lookup[t>>4&63]+lookup[t<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){var r,o,i=isArray(t),a=isArray(n);if(i&&a){if((s=t.length)!=n.length)return!1;for(r=s;0!=r--;)if(!e(t[r],n[r]))return!1;return!0}if(i!=a)return!1;i=t instanceof Date,a=n instanceof Date;if(i!=a)return!1;if(i&&a)return t.getTime()==n.getTime();i=t instanceof RegExp,a=n instanceof RegExp;if(i!=a)return!1;if(i&&a)return t.toString()==n.toString();var s,u=keyList(t);if((s=u.length)!==keyList(n).length)return!1;for(r=s;0!=r--;)if(!hasProp.call(n,u[r]))return!1;for(r=s;0!=r--;)if(!e(t[o=u[r]],n[o]))return!1;return!0}return t!=t&&n!=n},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function btoa(e){e=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(e))}function stringToBytes(e){for(var t=[],n=0;n<e.length;n++)t.push(e.charCodeAt(n));return t}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,t){return fastDeepEqual(e,t)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(e,t){e=e.then(function(e){return t&&setTimeout(function(){t(null,e)},0),e},function(e){return t?void setTimeout(function(){t(e,null)},0):Promise.reject(e)});return t?void 0:e}function transformValuesToVersionedValues(e){var t,n={};for(t in e)objectHasOwnProperty(e,t)&&(n[t]={value:e[t],version:0});return n}function transformVersionedValuesToValues(e){var t,n={};for(t in e)objectHasOwnProperty(e,t)&&(n[t]=e[t].value);return n}function chunkUserEventsForUrl(e,t){for(var n,r=t.slice(0),o=[],i=e;0<r.length;){for(n=[];0<i;){var a=r.shift();if(!a)break;(i-=base64URLEncode(JSON.stringify(a)).length)<0&&0<n.length?r.unshift(a):n.push(a)}i=e,o.push(n)}return o}function getLDUserAgentString(e){var t=e.version||"4.0.0";return e.userAgent+"/"+t}function getLDHeaders(e,t){if(t&&!t.sendLDHeaders)return{};e={"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)};return t&&t.wrapperName&&(e["X-LaunchDarkly-Wrapper"]=t.wrapperVersion?t.wrapperName+"/"+t.wrapperVersion:t.wrapperName),e}function transformHeaders(e,t){return t&&t.requestHeaderTransform?t.requestHeaderTransform(_objectSpread2({},e)):e}function extend(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.reduce(function(e,t){return _objectSpread2(_objectSpread2({},e),t)},{})}function objectHasOwnProperty(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function sanitizeUser(e){if(!e)return e;var t,n;for(n in userAttrsToStringify){var r=userAttrsToStringify[n],o=e[r];void 0!==o&&"string"!=typeof o&&((t=t||_objectSpread2({},e))[r]=String(o))}return t||e}var utils=Object.freeze({__proto__:null,btoa:btoa,base64URLEncode:base64URLEncode,clone:clone,deepEquals:deepEquals,onNextTick:onNextTick,wrapPromiseCallback:wrapPromiseCallback,transformValuesToVersionedValues:transformValuesToVersionedValues,transformVersionedValuesToValues:transformVersionedValuesToValues,chunkUserEventsForUrl:chunkUserEventsForUrl,getLDUserAgentString:getLDUserAgentString,getLDHeaders:getLDHeaders,transformHeaders:transformHeaders,extend:extend,objectHasOwnProperty:objectHasOwnProperty,sanitizeUser:sanitizeUser}),_require=require("uuid"),uuidv1=_require.v1,MAX_URL_LENGTH=2e3;function EventSender(s,e,u){var c="/a/"+e+".gif",l=extend({"Content-Type":"application/json"},getLDHeaders(s,u)),d=s.httpFallbackPing,f={};return f.sendChunk=function(e,t,r,n){var o=JSON.stringify(e),i=r?null:uuidv1();function a(n){var e=r?l:extend({},l,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":i});return s.httpRequest("POST",t,transformHeaders(e,u),o).promise.then(function(e){var t;if(e)return 400<=e.status&&isHttpErrorRecoverable(e.status)&&n?a(!1):(e={status:(t=e).status},!(t=t.header("date"))||(t=Date.parse(t))&&(e.serverTime=t),e)}).catch(function(){return n?a(!1):Promise.reject()})}return n?a(!0).catch(function(){}):(d&&d(t+c+"?d="+base64URLEncode(o)),Promise.resolve())},f.sendEvents=function(e,t,n){if(!s.httpRequest)return Promise.resolve();for(var r=s.httpAllowsPost(),o=r?[e]:chunkUserEventsForUrl(MAX_URL_LENGTH-t.length,e),i=[],a=0;a<o.length;a++)i.push(f.sendChunk(o[a],t,n,r));return Promise.all(i)},f}function EventSummarizer(){var e={},a=0,s=0,u={};return e.summarizeEvent=function(e){var t,n;"feature"===e.kind&&(t=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),(n=u[t])?n.count=n.count+1:u[t]={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>s&&(s=e.creationDate))},e.getSummary=function(){var e,t={},n=!0;for(e in u){var r=u[e],o=t[r.key];o||(o={default:r.default,counters:[]},t[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:s,features:t}},e.clearSummary=function(){s=a=0,u={}},e}function UserFilter(e){var t={},a=e.allAttributesPrivate,s=e.privateAttributeNames||[],u={key:!0,custom:!0,anonymous:!0},c={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return t.filterUser=function(e){if(!e)return null;function t(n,r){return Object.keys(n).reduce(function(e,t){return r(t)&&(o(t)?e[1][t]=!0:e[0][t]=n[t]),e},[{},{}])}var n=e.privateAttributeNames||[],o=function(e){return!u[e]&&(a||-1!==n.indexOf(e)||-1!==s.indexOf(e))},r=t(e,function(e){return c[e]}),i=r[0],r=r[1];e.custom&&(e=t(e.custom,function(){return 1}),i.custom=e[0],r=extend({},r,e[1]));r=Object.keys(r);return r.length&&(r.sort(),i.privateAttrs=r),i},t}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initializing-the-client for instructions on SDK initialization.",clientNotReady=function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},eventWithoutUser=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"},invalidContentType=function(e){return'Expected application/json content type but got "'+e+'"'},invalidKey=function(){return"Event key must be a string"},localStorageUnavailable=function(e){return"local storage is unavailable: "+errorString(e)},networkError=function(e){return"network error"+(e?" ("+e+")":"")},unknownCustomEventKey=function(e){return'Custom event "'+e+'" does not exist'},environmentNotFound=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+docLink},environmentNotSpecified=function(){return"No environment/client-side ID was specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+errorString(e)},userNotSpecified=function(){return"No user specified."+docLink},invalidUser=function(){return"Invalid user specified."+docLink},bootstrapOldFormat=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+docLink},bootstrapInvalid=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated=function(e,t){return t?'"'+e+'" is deprecated, please use "'+t+'"':'"'+e+'" is deprecated'},httpErrorMessage=function(e,t,n){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+t+" - "+(isHttpErrorRecoverable(e)?n:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e,t){return"Error on stream connection: "+errorString(e)+", will continue retrying every "+t+" milliseconds."},unknownOption=function(e){return'Ignoring unknown config option "'+e+'"'},wrongOptionType=function(e,t,n){return'Config option "'+e+'" should be of type '+t+", got "+n+", using default value"},wrongOptionTypeBoolean=function(e,t){return'Config option "'+e+'" should be a boolean, got '+t+", converting to boolean"},optionBelowMinimum=function(e,t,n){return'Config option "'+e+'" was set to '+t+", changing to minimum value of "+n},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"},debugPostingDiagnosticEvent=function(e){return"sending diagnostic event ("+e.kind+")"},messages=Object.freeze({__proto__:null,clientInitialized:clientInitialized,clientNotReady:clientNotReady,eventCapacityExceeded:eventCapacityExceeded,eventWithoutUser:eventWithoutUser,invalidContentType:invalidContentType,invalidKey:invalidKey,localStorageUnavailable:localStorageUnavailable,networkError:networkError,unknownCustomEventKey:unknownCustomEventKey,environmentNotFound:environmentNotFound,environmentNotSpecified:environmentNotSpecified,errorFetchingFlags:errorFetchingFlags,userNotSpecified:userNotSpecified,invalidUser:invalidUser,bootstrapOldFormat:bootstrapOldFormat,bootstrapInvalid:bootstrapInvalid,deprecated:deprecated,httpErrorMessage:httpErrorMessage,httpUnavailable:httpUnavailable,identifyDisabled:identifyDisabled,streamClosing:streamClosing,streamConnecting:streamConnecting,streamError:streamError,unknownOption:unknownOption,wrongOptionType:wrongOptionType,wrongOptionTypeBoolean:wrongOptionTypeBoolean,optionBelowMinimum:optionBelowMinimum,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents,debugPostingDiagnosticEvent:debugPostingDiagnosticEvent});function EventProcessor(e,t,n){var r,o=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null,i=4<arguments.length&&void 0!==arguments[4]?arguments[4]:null,a={},s=(5<arguments.length&&void 0!==arguments[5]?arguments[5]:null)||EventSender(e,n,t),u=t.eventsUrl+"/events/bulk/"+n,c=EventSummarizer(),l=UserFilter(t),d=t.inlineUsersInEvents,f=t.samplingInterval,v=t.eventCapacity,g=t.flushInterval,m=t.logger,p=[],y=0,h=!1,b=!1;function E(){return 0===f||0===Math.floor(Math.random()*f)}function k(e){p.length<v?(p.push(e),b=!1):(b||(b=!0,m.warn(eventCapacityExceeded())),o&&o.incrementDroppedEvents())}return a.enqueue=function(e){var t,n,r;h||(t=r=!1,c.summarizeEvent(e),"feature"===e.kind?E()&&(r=!!e.trackEvents,t=!!(n=e).debugEventsUntilDate&&(n.debugEventsUntilDate>y&&n.debugEventsUntilDate>(new Date).getTime())):r=E(),r&&k((r=extend({},n=e),"alias"===n.kind||(d||"identify"===n.kind?r.user=l.filterUser(n.user):(r.userKey=n.user.key,delete r.user),"feature"===n.kind&&(delete r.trackEvents,delete r.debugEventsUntilDate)),r)),t&&((e=extend({},e,{kind:"debug"})).user=l.filterUser(e.user),delete e.trackEvents,delete e.debugEventsUntilDate,k(e)))},a.flush=function(){if(h)return Promise.resolve();var e=p,t=c.getSummary();return c.clearSummary(),t&&(t.kind="summary",e.push(t)),o&&o.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(p=[],m.debug(debugPostingEvents(e.length)),s.sendEvents(e,u).then(function(e){e&&(e.serverTime&&(y=e.serverTime),isHttpErrorRecoverable(e.status)||(h=!0),400<=e.status&&onNextTick(function(){i.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},a.start=function(){r=setTimeout(function e(){a.flush(),r=setTimeout(e,g)},g)},a.stop=function(){clearTimeout(r)},a}function EventEmitter(t){var e={},o={};return e.on=function(e,t,n){o[e]=o[e]||[],o[e]=o[e].concat({handler:t,context:n})},e.off=function(e,t,n){if(o[e])for(var r=0;r<o[e].length;r++)o[e][r].handler===t&&o[e][r].context===n&&(o[e]=o[e].slice(0,r).concat(o[e].slice(r+1)))},e.emit=function(e){if(o[e])for(var t=o[e].slice(0),n=0;n<t.length;n++)t[n].handler.apply(t[n].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(o)},e.getEventListenerCount=function(e){return o[e]?o[e].length:0},e.maybeReportError=function(e){e&&(o["error"]?this.emit("error",e):(t||console).error(e.message))},e}var readyEvent="ready",successEvent="initialized",failureEvent="failed";function InitializationStateTracker(o){var t=!1,n=!1,r=null,e=null,i=new Promise(function(t){o.on(readyEvent,function e(){o.off(readyEvent,e),t()})}).catch(function(){});return{getInitializationPromise:function(){return e||(t?Promise.resolve():n?Promise.reject(r):e=new Promise(function(t,n){function r(e){o.off(failureEvent,r),n(e)}o.on(successEvent,function e(){o.off(successEvent,e),t()}),o.on(failureEvent,r)}))},getReadyPromise:function(){return i},signalSuccess:function(){t||n||(t=!0,o.emit(successEvent),o.emit(readyEvent))},signalFailure:function(e){t||n||(n=!0,r=e,o.emit(failureEvent,e),o.emit(readyEvent)),o.maybeReportError(e)}}}var InitializationState=InitializationStateTracker;function PersistentFlagStore(t,n,r,o){var i={};function a(){var e="",t=o.getUser();return t&&(e=r||btoa(JSON.stringify(t))),"ld:"+n+":"+e}return i.loadFlags=function(){return t.get(a()).then(function(e){if(null==e)return null;try{var t,n=JSON.parse(e);return n&&(void 0===(t=n.$schema)||t<1?n=transformValuesToVersionedValues(n):delete n.$schema),n}catch(e){return i.clearFlags().then(function(){return null})}})},i.saveFlags=function(e){e=extend({},e,{$schema:1});return t.set(a(),JSON.stringify(e))},i.clearFlags=function(){return t.clear(a())},i}function PersistentStorage(r,t){function o(e){n||(n=!0,t.warn(localStorageUnavailable(e)))}var e={},n=!1;return e.isEnabled=function(){return!!r},e.get=function(e){return new Promise(function(t){r?r.get(e).then(t).catch(function(e){o(e),t(void 0)}):t(void 0)})},e.set=function(e,n){return new Promise(function(t){r?r.set(e,n).then(function(){return t(!0)}).catch(function(e){o(e),t(!1)}):t(!1)})},e.clear=function(e){return new Promise(function(t){r?r.clear(e).then(function(){return t(!0)}).catch(function(e){o(e),t(!1)}):t(!1)})},e}var streamReadTimeoutMillis=3e5;function Stream(o,i,a,t){var s,u=i.streamUrl,c=i.logger,e={},l=u+"/eval/"+a,d=i.useReport,f=i.evaluationReasons,n=i.streamReconnectDelay,v=getLDHeaders(o,i),g=!1,m=null,p=null,y=null,h=null,b=null;function E(e){g||(c.warn(streamError(e,n)),g=!0),D(!1),S(),k(n)}function k(e){p||(e?p=setTimeout(r,e):r())}function r(){var e;p=null;var t="",n={headers:v,readTimeoutMillis:streamReadTimeoutMillis};if(o.eventSourceFactory){for(var r in null!=h&&(t="h="+h),d?o.eventSourceAllowsReport?(e=l,n.method="REPORT",n.headers["Content-Type"]="application/json",n.body=JSON.stringify(y)):(e=u+"/ping/"+a,t=""):e=l+"/"+base64URLEncode(JSON.stringify(y)),n.headers=transformHeaders(n.headers,i),e=e+((t=f?t+(t?"&":"")+"withReasons=true":t)?"?":"")+t,S(),c.info(streamConnecting(e)),s=(new Date).getTime(),m=o.eventSourceFactory(e,n),b)objectHasOwnProperty(b,r)&&m.addEventListener(r,b[r]);m.onerror=E}}function S(){m&&(c.info(streamClosing()),m.close(),m=null)}function D(e){s&&t&&t.recordStreamInit(s,!e,(new Date).getTime()-s),s=null}return e.connect=function(e,t,n){y=e,h=t,b={};for(var r in n||{})!function(t){b[t]=function(e){D(!(g=!1)),n[t]&&n[t](e)}}(r);k()},e.disconnect=function(){clearTimeout(p),p=null,S()},e.isConnected=function(){return!!(m&&o.eventSourceIsActive&&o.eventSourceIsActive(m))},e}function promiseCoalescer(n){var r,o,i,a,e={addPromise:function(t,e){r=t,o&&o(),o=e,t.then(function(e){r===t&&(i(e),n&&n())},function(e){r===t&&(a(e),n&&n())})}};return e.resultPromise=new Promise(function(e,t){i=e,a=t}),e}var jsonContentType="application/json";function getResponseError(e){return 404===e.status?new LDInvalidEnvironmentIdError(environmentNotFound()):new LDFlagFetchError(errorFetchingFlags(e.statusText||String(e.status)))}function Requestor(a,s,i){var u=s.baseUrl,c=s.useReport,l=s.evaluationReasons,d=s.logger,e={},f={};function v(e,t){if(!a.httpRequest)return new Promise(function(e,t){t(new LDFlagFetchError(httpUnavailable()))});var n=t?"REPORT":"GET",r=getLDHeaders(a,s);t&&(r["Content-Type"]=jsonContentType);var o=f[e];o||(o=promiseCoalescer(function(){delete f[e]}),f[e]=o);var i=a.httpRequest(n,e,transformHeaders(r,s),t),t=i.promise.then(function(e){if(200!==e.status)return Promise.reject(getResponseError(e));if(e.header("content-type")&&e.header("content-type").substring(0,jsonContentType.length)===jsonContentType)return JSON.parse(e.body);e=invalidContentType(e.header("content-type")||"");return Promise.reject(new LDFlagFetchError(e))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return o.addPromise(t,function(){i.cancel&&i.cancel()}),o.resultPromise}return e.fetchJSON=function(e){return v(u+e,null)},e.fetchFlagSettings=function(e,t){var n,r,o="";return c?(n=[u,"/sdk/evalx/",i,"/user"].join(""),r=JSON.stringify(e)):(e=base64URLEncode(JSON.stringify(e)),n=[u,"/sdk/evalx/",i,"/users/",e].join("")),t&&(o="h="+t),d.debug(debugPolling(n=n+((o=l?o+(o?"&":"")+"withReasons=true":o)?"?":"")+o)),v(n,r)},e}function Identity(e,n){var r,t={setUser:function(e){var t=r&&clone(r);(r=sanitizeUser(e))&&n&&n(clone(r),t)},getUser:function(){return r?clone(r):null}};return e&&t.setUser(e),t}var _require$1=require("uuid"),uuidv1$1=_require$1.v1,ldUserIdKey="ld:$anonUserId";function UserValidator(n){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var t=clone(e);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?n.get(ldUserIdKey).then(function(e){if(e)return t.key=e,t;e=uuidv1$1();return t.key=e,n.set(ldUserIdKey,e).then(function(){return t})}):Promise.reject(new LDInvalidUserError(invalidUser()))},e}var logLevels=["debug","info","warn","error","none"];function commonBasicLogger(e,i){if(e&&e.destination&&"function"!=typeof e.destination)throw new Error("destination for basicLogger was set to a non-function");function t(t){return function(e){console&&console[t]&&console[t].call(console,e)}}var a=e&&e.destination?[e.destination,e.destination,e.destination,e.destination]:[t("log"),t("info"),t("warn"),t("error")],s=!(!e||!e.destination),u=e&&void 0!==e.prefix&&null!==e.prefix?e.prefix:"[LaunchDarkly] ",r=1;if(e&&e.level)for(var n=0;n<logLevels.length;n++)logLevels[n]===e.level&&(r=n);for(var o={},c=function(e){var t,n=logLevels[e];"none"!==n&&(e<r?o[n]=function(){}:(t=e,o[n]=function(){!function(e,t,n){if(!(n.length<1)){var r,o=s?t+": "+u:u,n=1!==n.length&&i?((r=_toConsumableArray(n))[0]=o+r[0],i.apply(void 0,_toConsumableArray(r))):o+n[0];try{a[e](n)}catch(e){console&&console.log&&console.log("[LaunchDarkly] Configured logger's "+t+" method threw an exception: "+e)}}}(t,n,arguments)}))},l=0;l<logLevels.length;l++)c(l);return o}function validateLogger(t){logLevels.forEach(function(e){if("none"!==e&&(!t[e]||"function"!=typeof t[e]))throw new Error("Provided logger instance must support logger."+e+"(...) method")})}var baseOptionDefs={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},streaming:{type:"boolean"},sendLDHeaders:{default:!0},requestHeaderTransform:{type:"function"},inlineUsersInEvents:{default:!1},allowFrequentDuplicateEvents:{default:!1},sendEventsOnlyForVariation:{default:!1},useReport:{default:!1},evaluationReasons:{default:!1},eventCapacity:{default:100,minimum:1},flushInterval:{default:2e3,minimum:2e3},samplingInterval:{default:0,minimum:0},streamReconnectDelay:{default:1e3,minimum:0},allAttributesPrivate:{default:!1},privateAttributeNames:{default:[]},bootstrap:{type:"string|object"},diagnosticRecordingInterval:{default:9e5,minimum:2e3},diagnosticOptOut:{default:!1},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"},autoAliasingOptOut:{default:!1}};function validate(e,t,n,r){var a=extend({logger:{default:r}},baseOptionDefs,n),o={};function s(e){onNextTick(function(){t&&t.maybeReportError(new LDInvalidArgumentError(e))})}var i,u,c,l,e=extend({},e||{});function d(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";e=_typeof(e);return"boolean"===e||"string"===e||"number"===e||"function"===e?e:"object"}}return i=e,Object.keys(o).forEach(function(e){var t;void 0!==i[e]&&(t=o[e],r&&r.warn(deprecated(e,t)),t&&(void 0===i[t]&&(i[t]=i[e]),delete i[e]))}),u=extend({},e),Object.keys(a).forEach(function(e){void 0!==u[e]&&null!==u[e]||(u[e]=a[e]&&a[e].default)}),l=extend({},c=e=u),Object.keys(c).forEach(function(e){var t,n,r,o,i=c[e];null!=i&&(void 0===(t=a[e])?s(unknownOption(e)):"any"!==(n=t.type||d(t.default))&&(r=n.split("|"),o=d(i),r.indexOf(o)<0?"boolean"===n?(l[e]=!!i,s(wrongOptionTypeBoolean(e,o))):(s(wrongOptionType(e,n,o)),l[e]=t.default):"number"===o&&void 0!==t.minimum&&i<t.minimum&&(s(optionBelowMinimum(e,i,t.minimum)),l[e]=t.minimum)))}),validateLogger((e=l).logger),e}var getRandomValues,configuration=Object.freeze({__proto__:null,baseOptionDefs:baseOptionDefs,validate:validate}),rnds8=new Uint8Array(16);function rng(){if(!getRandomValues&&!(getRandomValues="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return getRandomValues(rnds8)}var REGEX=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function validate$1(e){return"string"==typeof e&&REGEX.test(e)}for(var _nodeId,_clockseq,byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex.push((i$1+256).toString(16).substr(1));function stringify(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,t=(byteToHex[e[t+0]]+byteToHex[e[t+1]]+byteToHex[e[t+2]]+byteToHex[e[t+3]]+"-"+byteToHex[e[t+4]]+byteToHex[e[t+5]]+"-"+byteToHex[e[t+6]]+byteToHex[e[t+7]]+"-"+byteToHex[e[t+8]]+byteToHex[e[t+9]]+"-"+byteToHex[e[t+10]]+byteToHex[e[t+11]]+byteToHex[e[t+12]]+byteToHex[e[t+13]]+byteToHex[e[t+14]]+byteToHex[e[t+15]]).toLowerCase();if(!validate$1(t))throw TypeError("Stringified UUID is invalid");return t}var _lastMSecs=0,_lastNSecs=0;function v1(e,t,n){var r=t&&n||0,o=t||new Array(16),i=(e=e||{}).node||_nodeId,a=void 0!==e.clockseq?e.clockseq:_clockseq;null!=i&&null!=a||(u=e.random||(e.rng||rng)(),null==i&&(i=_nodeId=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=_clockseq=16383&(u[6]<<8|u[7])));var s=void 0!==e.msecs?e.msecs:Date.now(),n=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,u=s-_lastMSecs+(n-_lastNSecs)/1e4;if(u<0&&void 0===e.clockseq&&(a=a+1&16383),1e4<=(n=(u<0||_lastMSecs<s)&&void 0===e.nsecs?0:n))throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=s,_clockseq=a;n=(1e4*(268435455&(s+=122192928e5))+(_lastNSecs=n))%4294967296;o[r++]=n>>>24&255,o[r++]=n>>>16&255,o[r++]=n>>>8&255,o[r++]=255&n;s=s/4294967296*1e4&268435455;o[r++]=s>>>8&255,o[r++]=255&s,o[r++]=s>>>24&15|16,o[r++]=s>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var c=0;c<6;++c)o[r+c]=i[c];return t||stringify(o)}function parse(e){if(!validate$1(e))throw TypeError("Invalid UUID");var t,n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n}function stringToBytes$1(e){e=unescape(encodeURIComponent(e));for(var t=[],n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}var DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function v35(e,a,s){function t(e,t,n,r){if("string"==typeof e&&(e=stringToBytes$1(e)),16!==(t="string"==typeof t?parse(t):t).length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var o=new Uint8Array(16+e.length);if(o.set(t),o.set(e,t.length),(o=s(o))[6]=15&o[6]|a,o[8]=63&o[8]|128,n){r=r||0;for(var i=0;i<16;++i)n[r+i]=o[i];return n}return stringify(o)}try{t.name=e}catch(e){}return t.DNS=DNS,t.URL=URL,t}function md5(e){if("string"==typeof e){var t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(var n=0;n<t.length;++n)e[n]=t.charCodeAt(n)}return md5ToHexEncodedArray(wordsToMd5(bytesToWords(e),8*e.length))}function md5ToHexEncodedArray(e){for(var t=[],n=32*e.length,r="0123456789abcdef",o=0;o<n;o+=8){var i=e[o>>5]>>>o%32&255,i=parseInt(r.charAt(i>>>4&15)+r.charAt(15&i),16);t.push(i)}return t}function getOutputLength(e){return 14+(e+64>>>9<<4)+1}function wordsToMd5(e,t){e[t>>5]|=128<<t%32,e[getOutputLength(t)-1]=t;for(var n=1732584193,r=-271733879,o=-1732584194,i=271733878,a=0;a<e.length;a+=16){var s=n,u=r,c=o,l=i,n=md5ff(n,r,o,i,e[a],7,-680876936),i=md5ff(i,n,r,o,e[a+1],12,-389564586),o=md5ff(o,i,n,r,e[a+2],17,606105819),r=md5ff(r,o,i,n,e[a+3],22,-1044525330);n=md5ff(n,r,o,i,e[a+4],7,-176418897),i=md5ff(i,n,r,o,e[a+5],12,1200080426),o=md5ff(o,i,n,r,e[a+6],17,-1473231341),r=md5ff(r,o,i,n,e[a+7],22,-45705983),n=md5ff(n,r,o,i,e[a+8],7,1770035416),i=md5ff(i,n,r,o,e[a+9],12,-1958414417),o=md5ff(o,i,n,r,e[a+10],17,-42063),r=md5ff(r,o,i,n,e[a+11],22,-1990404162),n=md5ff(n,r,o,i,e[a+12],7,1804603682),i=md5ff(i,n,r,o,e[a+13],12,-40341101),o=md5ff(o,i,n,r,e[a+14],17,-1502002290),n=md5gg(n,r=md5ff(r,o,i,n,e[a+15],22,1236535329),o,i,e[a+1],5,-165796510),i=md5gg(i,n,r,o,e[a+6],9,-1069501632),o=md5gg(o,i,n,r,e[a+11],14,643717713),r=md5gg(r,o,i,n,e[a],20,-373897302),n=md5gg(n,r,o,i,e[a+5],5,-701558691),i=md5gg(i,n,r,o,e[a+10],9,38016083),o=md5gg(o,i,n,r,e[a+15],14,-660478335),r=md5gg(r,o,i,n,e[a+4],20,-405537848),n=md5gg(n,r,o,i,e[a+9],5,568446438),i=md5gg(i,n,r,o,e[a+14],9,-1019803690),o=md5gg(o,i,n,r,e[a+3],14,-187363961),r=md5gg(r,o,i,n,e[a+8],20,1163531501),n=md5gg(n,r,o,i,e[a+13],5,-1444681467),i=md5gg(i,n,r,o,e[a+2],9,-51403784),o=md5gg(o,i,n,r,e[a+7],14,1735328473),n=md5hh(n,r=md5gg(r,o,i,n,e[a+12],20,-1926607734),o,i,e[a+5],4,-378558),i=md5hh(i,n,r,o,e[a+8],11,-2022574463),o=md5hh(o,i,n,r,e[a+11],16,1839030562),r=md5hh(r,o,i,n,e[a+14],23,-35309556),n=md5hh(n,r,o,i,e[a+1],4,-1530992060),i=md5hh(i,n,r,o,e[a+4],11,1272893353),o=md5hh(o,i,n,r,e[a+7],16,-155497632),r=md5hh(r,o,i,n,e[a+10],23,-1094730640),n=md5hh(n,r,o,i,e[a+13],4,681279174),i=md5hh(i,n,r,o,e[a],11,-358537222),o=md5hh(o,i,n,r,e[a+3],16,-722521979),r=md5hh(r,o,i,n,e[a+6],23,76029189),n=md5hh(n,r,o,i,e[a+9],4,-640364487),i=md5hh(i,n,r,o,e[a+12],11,-421815835),o=md5hh(o,i,n,r,e[a+15],16,530742520),n=md5ii(n,r=md5hh(r,o,i,n,e[a+2],23,-995338651),o,i,e[a],6,-198630844),i=md5ii(i,n,r,o,e[a+7],10,1126891415),o=md5ii(o,i,n,r,e[a+14],15,-1416354905),r=md5ii(r,o,i,n,e[a+5],21,-57434055),n=md5ii(n,r,o,i,e[a+12],6,1700485571),i=md5ii(i,n,r,o,e[a+3],10,-1894986606),o=md5ii(o,i,n,r,e[a+10],15,-1051523),r=md5ii(r,o,i,n,e[a+1],21,-2054922799),n=md5ii(n,r,o,i,e[a+8],6,1873313359),i=md5ii(i,n,r,o,e[a+15],10,-30611744),o=md5ii(o,i,n,r,e[a+6],15,-1560198380),r=md5ii(r,o,i,n,e[a+13],21,1309151649),n=md5ii(n,r,o,i,e[a+4],6,-145523070),i=md5ii(i,n,r,o,e[a+11],10,-1120210379),o=md5ii(o,i,n,r,e[a+2],15,718787259),r=md5ii(r,o,i,n,e[a+9],21,-343485551),n=safeAdd(n,s),r=safeAdd(r,u),o=safeAdd(o,c),i=safeAdd(i,l)}return[n,r,o,i]}function bytesToWords(e){if(0===e.length)return[];for(var t=8*e.length,n=new Uint32Array(getOutputLength(t)),r=0;r<t;r+=8)n[r>>5]|=(255&e[r/8])<<r%32;return n}function safeAdd(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function bitRotateLeft(e,t){return e<<t|e>>>32-t}function md5cmn(e,t,n,r,o,i){return safeAdd(bitRotateLeft(safeAdd(safeAdd(t,e),safeAdd(r,i)),o),n)}function md5ff(e,t,n,r,o,i,a){return md5cmn(t&n|~t&r,e,t,o,i,a)}function md5gg(e,t,n,r,o,i,a){return md5cmn(t&r|n&~r,e,t,o,i,a)}function md5hh(e,t,n,r,o,i,a){return md5cmn(t^n^r,e,t,o,i,a)}function md5ii(e,t,n,r,o,i,a){return md5cmn(n^(t|~r),e,t,o,i,a)}var v3=v35("v3",48,md5);function v4(e,t,n){var r=(e=e||{}).random||(e.rng||rng)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=r[o];return t}return stringify(r)}function f(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:return t^n^r;case 2:return t&n^t&r^n&r;case 3:return t^n^r}}function ROTL(e,t){return e<<t|e>>>32-t}function sha1(e){var t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){var r=unescape(encodeURIComponent(e));e=[];for(var o=0;o<r.length;++o)e.push(r.charCodeAt(o))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var i=e.length/4+2,a=Math.ceil(i/16),s=new Array(a),u=0;u<a;++u){for(var c=new Uint32Array(16),l=0;l<16;++l)c[l]=e[64*u+4*l]<<24|e[64*u+4*l+1]<<16|e[64*u+4*l+2]<<8|e[64*u+4*l+3];s[u]=c}s[a-1][14]=8*(e.length-1)/Math.pow(2,32),s[a-1][14]=Math.floor(s[a-1][14]),s[a-1][15]=8*(e.length-1)&4294967295;for(var d=0;d<a;++d){for(var v=new Uint32Array(80),g=0;g<16;++g)v[g]=s[d][g];for(var m=16;m<80;++m)v[m]=ROTL(v[m-3]^v[m-8]^v[m-14]^v[m-16],1);for(var p=n[0],y=n[1],h=n[2],b=n[3],E=n[4],k=0;k<80;++k)var S=Math.floor(k/20),S=ROTL(p,5)+f(S,y,h,b)+E+t[S]+v[k]>>>0,E=b,b=h,h=ROTL(y,30)>>>0,y=p,p=S;n[0]=n[0]+p>>>0,n[1]=n[1]+y>>>0,n[2]=n[2]+h>>>0,n[3]=n[3]+b>>>0,n[4]=n[4]+E>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]}var v5=v35("v5",80,sha1),nil="00000000-0000-0000-0000-000000000000";function version(e){if(!validate$1(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)}var esmBrowser=Object.freeze({__proto__:null,v1:v1,v3:v3,v4:v4,v5:v5,NIL:nil,version:version,validate:validate$1,stringify:stringify,parse:parse}),uuidv1$2=esmBrowser.v1,baseOptionDefs$1=configuration.baseOptionDefs;function DiagnosticId(e){var t={diagnosticId:uuidv1$2()};return e&&(t.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),t}function DiagnosticsAccumulator(e){var t,n,r,o;function i(e){t=e,r=n=0,o=[]}return i(e),{getProps:function(){return{dataSinceDate:t,droppedEvents:n,eventsInLastBatch:r,streamInits:o}},setProps:function(e){t=e.dataSinceDate,n=e.droppedEvents||0,r=e.eventsInLastBatch||0,o=e.streamInits||[]},incrementDroppedEvents:function(){n++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,t,n){o.push({timestamp:e,failed:t,durationMillis:n})},reset:i}}function DiagnosticsManager(t,r,e,n,o,i,a){var s,u,c=!!t.diagnosticUseCombinedEvent,l="ld:"+o+":$diagnostics",d=i.eventsUrl+"/events/diagnostic/"+o,f=i.diagnosticRecordingInterval,v=e,g=!!i.streaming,e={};function m(){return{sdk:function(){var e=_objectSpread2({},t.diagnosticSdkData);i.wrapperName&&(e.wrapperName=i.wrapperName);i.wrapperVersion&&(e.wrapperVersion=i.wrapperVersion);return e}(),configuration:{customBaseURI:i.baseUrl!==baseOptionDefs$1.baseUrl.default,customStreamURI:i.streamUrl!==baseOptionDefs$1.streamUrl.default,customEventsURI:i.eventsUrl!==baseOptionDefs$1.eventsUrl.default,eventsCapacity:i.eventCapacity,eventsFlushIntervalMillis:i.flushInterval,reconnectTimeMillis:i.streamReconnectDelay,streamingDisabled:!g,allAttributesPrivate:!!i.allAttributesPrivate,inlineUsersInEvents:!!i.inlineUsersInEvents,diagnosticRecordingIntervalMillis:i.diagnosticRecordingInterval,usingSecureMode:!!i.hash,bootstrapMode:!!i.bootstrap,fetchGoalsDisabled:!i.fetchGoals,allowFrequentDuplicateEvents:!!i.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!i.sendEventsOnlyForVariation,autoAliasingOptOut:!!i.autoAliasingOptOut},platform:t.diagnosticPlatformData}}function p(e){i.logger&&i.logger.debug(messages.debugPostingDiagnosticEvent(e)),n.sendEvents(e,d,!0).then(function(){}).catch(function(){})}function y(){var e,t;p((e=(new Date).getTime(),t=_objectSpread2({kind:c?"diagnostic-combined":"diagnostic",id:a,creationDate:e},v.getProps()),c&&(t=_objectSpread2(_objectSpread2({},t),m())),v.reset(e),t)),u=setTimeout(y,f),s=(new Date).getTime(),c&&r.isEnabled()&&(t=_objectSpread2({},v.getProps()),r.set(l,JSON.stringify(t)))}return e.start=function(){c?function(n){if(!r.isEnabled())return n(!1);r.get(l).then(function(e){if(e)try{var t=JSON.parse(e);v.setProps(t),s=t.dataSinceDate}catch(e){}n(!0)}).catch(function(){n(!1)})}(function(e){var t;e?(t=(s||0)+f)<=(e=(new Date).getTime())?y():u=setTimeout(y,t-e):0===Math.floor(4*Math.random())?y():u=setTimeout(y,f)}):(p(_objectSpread2({kind:"diagnostic-init",id:a,creationDate:v.getProps().dataSinceDate},m())),u=setTimeout(y,f))},e.stop=function(){u&&clearTimeout(u)},e.setStreaming=function(e){g=e},e}var diagnosticEvents={DiagnosticId:DiagnosticId,DiagnosticsAccumulator:DiagnosticsAccumulator,DiagnosticsManager:DiagnosticsManager},diagnosticEvents_1=diagnosticEvents.DiagnosticId,diagnosticEvents_2=diagnosticEvents.DiagnosticsAccumulator,diagnosticEvents_3=diagnosticEvents.DiagnosticsManager,changeEvent="change",internalChangeEvent="internal-change";function initialize(e,t,n,i,r){var a,o,s,u=function(){if(n&&n.logger)return n.logger;return r&&r.logger&&r.logger.default||commonBasicLogger("warn")}(),c=EventEmitter(u),l=InitializationState(c),d=validate(n,c,r,u),f=d.sendEvents,v=e,g=d.hash,m=PersistentStorage(i.localStorage,u),p=EventSender(i,v,d),y=d.sendEvents&&!d.diagnosticOptOut,h=y?diagnosticEvents_1(v):null,b=y?diagnosticEvents_2((new Date).getTime()):null,E=y?diagnosticEvents_3(i,m,b,p,v,d,h):null,k=Stream(i,d,v,b),S=d.eventProcessor||EventProcessor(i,d,v,b,c,p),D=Requestor(i,d,v),w={},U={},T=d.streaming,P=!1,O=!1,I=!0,L=d.stateProvider,A=Identity(null,function(e,t){(function(e){L||e&&_({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})})(e),!d.autoAliasingOptOut&&t&&t.anonymous&&e&&!e.anonymous&&H(e,t)}),R=UserValidator(m),C=m.isEnabled()?new PersistentFlagStore(m,v,g,A,u):null;function _(e){if(v&&!(L&&L.enqueueEvent&&L.enqueueEvent(e))){if("alias"!==e.kind){if(!e.user)return void(I&&(u.warn(eventWithoutUser()),I=!1));I=!1}!f||O||i.isDoNotTrack()||(u.debug(debugEnqueueingEvent(e.kind)),S.enqueue(e))}}function j(e,t,n,r){var o=A.getUser(),i=new Date,a=t?t.value:null;if(!d.allowFrequentDuplicateEvents){var s=JSON.stringify(a)+(o&&o.key?o.key:"")+e,u=w[s];if(u&&i-u<3e5)return;w[s]=i}i={kind:"feature",key:e,user:o,value:a,variation:t?t.variationIndex:null,default:n,creationDate:i.getTime()};o&&o.anonymous&&(i.contextKind=N(o));e=U[e];e&&(i.version=e.flagVersion||e.version,i.trackEvents=e.trackEvents,i.debugEventsUntilDate=e.debugEventsUntilDate),(r||e&&e.trackReason)&&t&&(i.reason=t.reason),_(i)}function x(e,t,n,r){var o,i;return U&&objectHasOwnProperty(U,e)&&U[e]&&!U[e].deleted?(i=F(o=U[e]),null!==o.value&&void 0!==o.value||(i.value=t)):i={value:t,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}},n&&j(e,i,t,r),i}function F(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function N(e){return e.anonymous?"anonymousUser":"user"}function H(e,t){L||e&&t&&_({kind:"alias",key:e.key,contextKind:N(e),previousKey:t.key,previousContextKind:N(t),creationDate:(new Date).getTime()})}function V(){o=!0,A.getUser()&&k.connect(A.getUser(),g,{ping:function(){u.debug(debugStreamPing());var t=A.getUser();D.fetchFlagSettings(t,g).then(function(e){deepEquals(t,A.getUser())&&M(e||{})}).catch(function(e){c.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){e=JSON.parse(e.data);u.debug(debugStreamPut()),M(e)},patch:function(e){var t,n=JSON.parse(e.data),r=U[n.key];!r||!r.version||!n.version||r.version<n.version?(u.debug(debugStreamPatch(n.key)),t={},delete(e=extend({},n)).key,e=F(U[n.key]=e),t[n.key]=r?{previous:r.value,current:e}:{current:e},z(t)):u.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var t=JSON.parse(e.data);!U[t.key]||U[t.key].version<t.version?(u.debug(debugStreamDelete(t.key)),e={},U[t.key]&&!U[t.key].deleted&&(e[t.key]={previous:U[t.key].value}),U[t.key]={version:t.version,deleted:!0},z(e)):u.debug(debugStreamDeleteIgnored(t.key))}})}function q(){o&&(k.disconnect(),o=!1)}function M(e){var t,n,r={};if(!e)return Promise.resolve();for(t in U)objectHasOwnProperty(U,t)&&U[t]&&(e[t]&&!deepEquals(e[t].value,U[t].value)?r[t]={previous:U[t].value,current:F(e[t])}:e[t]&&!e[t].deleted||(r[t]={previous:U[t].value}));for(n in e)objectHasOwnProperty(e,n)&&e[n]&&(!U[n]||U[n].deleted)&&(r[n]={current:F(e[n])});return U=_objectSpread2({},e),z(r).catch(function(){})}function z(o){var i,e=Object.keys(o);return 0<e.length&&(i={},e.forEach(function(e){var t=o[e].current,n=t?t.value:void 0,r=o[e].previous;c.emit(changeEvent+":"+e,n,r),i[e]=t?{current:n,previous:r}:{previous:r}}),c.emit(changeEvent,i),c.emit(internalChangeEvent,U),d.sendEventsOnlyForVariation||L||e.forEach(function(e){j(e,o[e].current)})),a&&C?C.saveFlags(U):Promise.resolve()}function $(){var e=T||s&&void 0===T;e&&!o?V():!e&&o&&q(),E&&E.setStreaming(e)}function B(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}function K(e){v=e.environment,A.setUser(e.user),U=_objectSpread2({},e.flags),onNextTick(J)}function J(){u.info(clientInitialized()),P=!0,$(),l.signalSuccess()}function G(e){l.signalFailure(e)}return"string"==typeof d.bootstrap&&"LOCALSTORAGE"===d.bootstrap.toUpperCase()&&(C?a=!0:u.warn(localStorageUnavailable())),"object"===_typeof(d.bootstrap)&&(U=function(n){var e=Object.keys(n),r="$flagsState",o=n[r];!o&&e.length&&u.warn(bootstrapOldFormat()),!1===n.$valid&&u.warn(bootstrapInvalid());var i={};return e.forEach(function(e){var t;e!==r&&"$valid"!==e&&(t={value:n[e]},o&&o[e]?t=extend(t,o[e]):t.version=0,i[e]=t)}),i}(d.bootstrap)),L?((m=L.getInitialState())?K(m):L.on("init",K),L.on("update",function(e){e.user&&A.setUser(e.user);e.flags&&M(e.flags)})):(e?R.validateUser(t).then(function(e){return A.setUser(e),"object"===_typeof(d.bootstrap)?J():a?C.loadFlags().then(function(e){return null==e?(U={},D.fetchFlagSettings(A.getUser(),g).then(function(e){return M(e||{})}).then(J).catch(function(e){G(new LDFlagFetchError(errorFetchingFlags(e)))})):(U=e,onNextTick(J),D.fetchFlagSettings(A.getUser(),g).then(M).catch(function(e){return c.maybeReportError(e)}))}):D.fetchFlagSettings(A.getUser(),g).then(function(e){U=e||{},J()}).catch(function(e){U={},G(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(G),{client:{waitForInitialization:function(){return l.getInitializationPromise()},waitUntilReady:function(){return l.getReadyPromise()},identify:function(e,r,t){return O?wrapPromiseCallback(Promise.resolve({}),t):L?(u.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(U)),t)):wrapPromiseCallback((a&&C?C.clearFlags():Promise.resolve()).then(function(){return R.validateUser(e)}).then(function(n){return D.fetchFlagSettings(n,r).then(function(e){var t=transformVersionedValuesToValues(e);return A.setUser(n),g=r,e?M(e).then(function(){return t}):t})}).then(function(e){return o&&V(),e}).catch(function(e){return c.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return A.getUser()},variation:function(e,t){return x(e,t,!0,!1).value},variationDetail:function(e,t){return x(e,t,!0,!0)},track:function(e,t,n){var r,o;"string"==typeof e?(i.customEventFilter&&!i.customEventFilter(e)&&u.warn(unknownCustomEventKey(e)),o={kind:"custom",key:e,user:r=A.getUser(),url:i.getCurrentUrl(),creationDate:(new Date).getTime()},r&&r.anonymous&&(o.contextKind=N(r)),null!=t&&(o.data=t),null!=n&&(o.metricValue=n),_(o)):c.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},alias:H,on:function(e,t,n){B(e)?(s=!0,P&&$(),c.on(e,t,n)):c.on.apply(c,arguments)},off:function(e){var t;c.off.apply(c,arguments),B(e)&&(t=!1,c.getEvents().forEach(function(e){B(e)&&0<c.getEventListenerCount(e)&&(t=!0)}),t||(s=!1,o&&void 0===T&&q()))},setStreaming:function(e){(e=null===e?void 0:e)!==T&&(T=e,$())},flush:function(e){return wrapPromiseCallback(f?S.flush():Promise.resolve(),e)},allFlags:function(){var e,t={};if(!U)return t;for(e in U)objectHasOwnProperty(U,e)&&(t[e]=x(e,null,!d.sendEventsOnlyForVariation).value);return t},close:function(e){return wrapPromiseCallback(O?Promise.resolve():Promise.resolve().then(function(){if(q(),E&&E.stop(),f)return S.stop(),S.flush()}).then(t).catch(t),e);function t(){O=!0,U={}}}},options:d,emitter:c,ident:A,logger:u,requestor:D,start:function(){f&&(E&&E.start(),S.start())},enqueueEvent:_,getFlagsInternal:function(){return U},getEnvironmentId:function(){return v},internalChangeEventName:internalChangeEvent}}var version$1="4.0.0";exports.commonBasicLogger=commonBasicLogger,exports.errors=errors,exports.initialize=initialize,exports.messages=messages,exports.utils=utils,exports.version=version$1;
2
2
  //# sourceMappingURL=ldclient-common.cjs.js.map