launchdarkly-js-sdk-common
Advanced tools
Comparing version 3.2.2 to 3.2.3
@@ -5,2 +5,7 @@ # Change log | ||
## [3.2.3] - 2020-03-06 | ||
### Fixed: | ||
- At client initialization time, if the initial flag polling request failed, it would cause an unhandled promise rejection unless the application had called `waitForInitialization()` and provided an error handler for the promise that was returned by that method. While that is correct behavior if the application did call `waitForInitialization()` (any promise that might be rejected should have an error handler attached), it is highly undesirable if the application did not call `waitForInitialization()` at all-- which is not mandatory, since the application could use events instead, or `waitUntilReady()`, or might simply not care about waiting for initialization. This has been fixed so that no such promise is created until the first time the application calls `waitForInitialization()`; subsequent calls to the same method will return the same promise (since initialization can only happen once). | ||
- A bug in the event emitter made its behavior unpredictable if an event handler called `on` or `off` while handling an event. This has been fixed so that all event handlers that were defined _at the time the event was fired_ will be called; any changes made will not take effect until the next event. | ||
## [3.2.2] - 2020-02-13 | ||
@@ -7,0 +12,0 @@ ### Fixed: |
@@ -1,2 +0,2 @@ | ||
"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,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function ownKeys(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),t.push.apply(t,r)}return t}function _objectSpread2(n){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(t,!0).forEach(function(e){_defineProperty(n,e,t[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):ownKeys(t).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(t,e))})}return n}function createCustomError(e){function n(e,n){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=n}return(n.prototype=new Error).name=e,n.prototype.constructor=n}Object.defineProperty(exports,"__esModule",{value:!0});var LDUnexpectedResponseError=createCustomError("LaunchDarklyUnexpectedResponseError"),LDInvalidEnvironmentIdError=createCustomError("LaunchDarklyInvalidEnvironmentIdError"),LDInvalidUserError=createCustomError("LaunchDarklyInvalidUserError"),LDInvalidEventKeyError=createCustomError("LaunchDarklyInvalidEventKeyError"),LDInvalidArgumentError=createCustomError("LaunchDarklyInvalidArgumentError"),LDFlagFetchError=createCustomError("LaunchDarklyFlagFetchError");function isHttpErrorRecoverable(e){return!(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,n,t){for(var r,o=[],i=n;i<t;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var n,t=e.length,r=t%3,o=[],i=16383,a=0,s=t-r;a<s;a+=i)o.push(encodeChunk(e,a,s<a+i?s:a+i));return 1==r?(n=e[t-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2==r&&(n=(e[t-2]<<8)+e[t-1],o.push(lookup[n>>10]+lookup[n>>4&63]+lookup[n<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,o,i,a=isArray(n),s=isArray(t);if(a&&s){if((o=n.length)!=t.length)return!1;for(r=o;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=s)return!1;var u=n instanceof Date,c=t instanceof Date;if(u!=c)return!1;if(u&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var d=keyList(n);if((o=d.length)!==keyList(t).length)return!1;for(r=o;0!=r--;)if(!hasProp.call(t,d[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=d[r]],t[i]))return!1;return!0}return n!=n&&t!=t},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function btoa(e){var n=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(n))}function stringToBytes(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,n){return fastDeepEqual(e,n)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function transformValuesToVersionedValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function chunkUserEventsForUrl(e,n){for(var t,r=n.slice(0),o=[],i=e;0<r.length;){for(t=[];0<i;){var a=r.shift();if(!a)break;(i-=base64URLEncode(JSON.stringify(a)).length)<0&&0<t.length?r.unshift(a):t.push(a)}i=e,o.push(t)}return o}function getLDUserAgentString(e){var n=e.version||"3.2.2";return e.userAgent+"/"+n}function getLDHeaders(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function extend(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return _objectSpread2({},e,{},n)},{})}function sanitizeUser(e){if(!e)return e;var n;for(var t in userAttrsToStringify){var r=userAttrsToStringify[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||_objectSpread2({},e))[r]=String(o))}return n||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,extend:extend,sanitizeUser:sanitizeUser});function createCommonjsModule(e,n){return e(n={exports:{}},n.exports),n.exports}for(var rngBrowser=createCommonjsModule(function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var t=n||0,r=byteToHex;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||_nodeId,a=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==i||null==a){var s=rngBrowser();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:(new Date).getTime(),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 f=(1e4*(268435455&(u+=122192928e5))+(_lastNSecs=c))%4294967296;o[r++]=f>>>24&255,o[r++]=f>>>16&255,o[r++]=f>>>8&255,o[r++]=255&f;var d=u/4294967296*1e4&268435455;o[r++]=d>>>8&255,o[r++]=255&d,o[r++]=d>>>24&15|16,o[r++]=d>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var v=0;v<6;++v)o[r+v]=i[v];return n||bytesToUuid_1(o)}var v1_1=v1,MAX_URL_LENGTH=2e3;function EventSender(s,e,n){var t="/a/"+e+".gif",u=extend({"Content-Type":"application/json"},getLDHeaders(s,n)),c=s.httpFallbackPing,l={};return l.sendChunk=function(e,r,o,n){var i=JSON.stringify(e),a=o?null:v1_1();return n?function n(t){var e=o?u:extend({},u,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":a});return s.httpRequest("POST",r,e,i).promise.then(function(e){if(e)return 400<=e.status&&isHttpErrorRecoverable(e.status)&&t?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)}).catch(function(){return t?n(!1):Promise.reject()})}(!0).catch(function(){}):(c&&c(r+t+"?d="+base64URLEncode(i)),Promise.resolve())},l.sendEvents=function(e,n,t){if(!s.httpRequest)return Promise.resolve();var r,o=s.httpAllowsPost();r=o?[e]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,e);for(var i=[],a=0;a<r.length;a++)i.push(l.sendChunk(r[a],n,t,o));return Promise.all(i)},l}function EventSummarizer(){var e={},a=0,s=0,u={};return e.summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=u[n];t?t.count=t.count+1:u[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>s&&(s=e.creationDate)}},e.getSummary=function(){var e={},n=!0;for(var t in u){var r=u[t],o=e[r.key];o||(o={default:r.default,counters:[]},e[r.key]=o);var i={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),n=!1}return n?null:{startDate:a,endDate:s,features:e}},e.clearSummary=function(){s=a=0,u={}},e}function UserFilter(e){var n={},u=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},f={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;function n(r,o){return Object.keys(r).reduce(function(e,n){var t=e;return o(n)&&(!function(e){return!l[e]&&(u||-1!==i.indexOf(e)||-1!==c.indexOf(e))}(n)?t[0][n]=r[n]:t[1][n]=!0),t},[{},{}])}var i=e.privateAttributeNames||[],t=n(e,function(e){return f[e]}),r=t[0],o=t[1];if(e.custom){var a=n(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},n}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",clientNotReady=function(){return"LaunchDarkly client is not ready"},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/docs/js-sdk-reference#section-analytics-events"},invalidContentType=function(e){return'Expected application/json content type but got "'+e+'"'},invalidKey=function(){return"Event key must be a string"},localStorageUnavailable=function(){return"localStorage is unavailable"},localStorageUnavailableForUserId=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},networkError=function(e){return"network error"+(e?" ("+e+")":"")},unknownCustomEventKey=function(e){return'Custom event "'+e+'" does not exist'},environmentNotFound=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+docLink},environmentNotSpecified=function(){return"No environment/client-side ID was specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+errorString(e)},userNotSpecified=function(){return"No user specified."+docLink},invalidUser=function(){return"Invalid user specified."+docLink},bootstrapOldFormat=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+docLink},bootstrapInvalid=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},httpErrorMessage=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?t:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e,n){return"Error on stream connection: "+errorString(e)+", will continue retrying every "+n+" milliseconds."},unknownOption=function(e){return'Ignoring unknown config option "'+e+'"'},wrongOptionType=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},wrongOptionTypeBoolean=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},optionBelowMinimum=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},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,n,t){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,t,n),u=n.eventsUrl+"/events/bulk/"+t,c=EventSummarizer(),l=UserFilter(n),f=n.inlineUsersInEvents,d=n.samplingInterval,v=n.eventCapacity,g=n.flushInterval,p=n.logger,m=[],y=0,h=!1,b=!1;function E(){return 0===d||0===Math.floor(Math.random()*d)}function k(e){m.length<v?(m.push(e),b=!1):(b||(b=!0,p.warn(eventCapacityExceeded())),o&&o.incrementDroppedEvents())}return a.enqueue=function(e){if(!h){var n=!1,t=!1;if(c.summarizeEvent(e),"feature"===e.kind?E()&&(n=!!e.trackEvents,t=function(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>y&&e.debugEventsUntilDate>(new Date).getTime())}(e)):n=E(),n&&k(function(e){var n=extend({},e);return f||"identify"===e.kind?n.user=l.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),t){var r=extend({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,k(r)}}},a.flush=function(){if(h)return Promise.resolve();var e=m,n=c.getSummary();return c.clearSummary(),n&&(n.kind="summary",e.push(n)),o&&o.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(m=[],p.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(n){var e={},o={};return e.on=function(e,n,t){o[e]=o[e]||[],o[e]=o[e].concat({handler:n,context:t})},e.off=function(e,n,t){if(o[e])for(var r=0;r<o[e].length;r++)o[e][r].handler===n&&o[e][r].context===t&&(o[e]=o[e].slice(0,r).concat(o[e].slice(r+1)))},e.emit=function(e){if(o[e])for(var n=0;n<o[e].length;n++)o[e][n].handler.apply(o[e][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")?(n||console).error(e.message):this.emit("error",e))},e}function Store(t,r,o,i,a){var s={};function u(){var e="",n=i.getUser();return n&&(e=o||btoa(JSON.stringify(n))),"ld:"+r+":"+e}return s.loadFlags=function(){return t.get(u()).then(function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var t=n.$schema;void 0===t||t<1?n=transformValuesToVersionedValues(n):delete n.$schema}return n}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 n=extend({},e,{$schema:1});return t.set(u(),JSON.stringify(n)).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},s.clearFlags=function(){return t.clear(u()).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},s}function Stream(o,e,i,n){var a,s=e.streamUrl,u=e.logger,t={},c=s+"/eval/"+i,l=e.useReport,f=e.evaluationReasons,r=e.streamReconnectDelay,d=getLDHeaders(o,e),v=!1,g=null,p=null,m=null,y=null,h=null;function b(e){v||(u.warn(streamError(e,r)),v=!0),S(!1),D(),E(r)}function E(e){p||(e?p=setTimeout(k,e):k())}function k(){var e;p=null;var n="",t={headers:d};if(o.eventSourceFactory){for(var r in null!=y&&(n="h="+y),l?o.eventSourceAllowsReport?(e=c,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(m)):(e=s+"/ping/"+i,n=""):e=c+"/"+base64URLEncode(JSON.stringify(m)),f&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,D(),u.info(streamConnecting(e)),a=(new Date).getTime(),g=o.eventSourceFactory(e,t),h)h.hasOwnProperty(r)&&g.addEventListener(r,h[r]);g.onerror=b}}function D(){g&&(u.info(streamClosing()),g.close(),g=null)}function S(e){a&&n&&n.recordStreamInit(a,!e,(new Date).getTime()-a),a=null}return t.connect=function(e,n,t){m=e,y=n,h={};function r(n){h[n]=function(e){S(!(v=!1)),t[n]&&t[n](e)}}for(var o in t||{})r(o);E()},t.disconnect=function(){clearTimeout(p),p=null,D()},t.isConnected=function(){return!!(g&&o.eventSourceIsActive&&o.eventSourceIsActive(g))},t}function promiseCoalescer(t){var r,o,i,a,e={addPromise:function(n,e){r=n,o&&o(),o=e,n.then(function(e){r===n&&(i(e),t&&t())},function(e){r===n&&(a(e),t&&t())})}};return e.resultPromise=new Promise(function(e,n){i=e,a=n}),e}var json="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,f=u.evaluationReasons,d=u.logger,e={},v={};function g(e,n){if(!s.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var t=n?"REPORT":"GET",r=getLDHeaders(s,u);n&&(r["Content-Type"]="application/json");var o=v[e];o||(o=promiseCoalescer(function(){delete v[e]}),v[e]=o);var i=s.httpRequest(t,e,r,n),a=i.promise.then(function(e){if(200!==e.status)return Promise.reject(getResponseError(e));if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(json))return JSON.parse(e.body);var n=invalidContentType(e.header("content-type")||"");return Promise.reject(new LDFlagFetchError(n))},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,n){var t,r,o,i="";return l?(r=[c,"/sdk/evalx/",a,"/user"].join(""),o=JSON.stringify(e)):(t=base64URLEncode(JSON.stringify(e)),r=[c,"/sdk/evalx/",a,"/users/",t].join("")),n&&(i="h="+n),f&&(i=i+(i?"&":"")+"withReasons=true"),r=r+(i?"?":"")+i,d.debug(debugPolling(r)),g(r,o)},e}function Identity(e,n){var t,r={};return r.setUser=function(e){(t=sanitizeUser(e))&&n&&n(clone(t))},r.getUser=function(){return t?clone(t):null},e&&r.setUser(e),r}var ldUserIdKey="ld:$anonUserId";function UserValidator(r,o){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?(r?r.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(e){if(e)return t.key=e,t;var n=v1_1();return function(e){return r?r.set(ldUserIdKey,e).catch(function(){o.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(t.key=n).then(function(){return t})}):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},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"}};function validate(e,n,t,r){var a=extend({logger:{default:r}},baseOptionDefs,t),o={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function s(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var i,u,c,l,f=extend({},e||{});function d(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var n=_typeof(e);return"boolean"===n||"string"===n||"number"===n||"function"===n?n:"object"}}return i=f,Object.keys(o).forEach(function(e){if(void 0!==i[e]){var n=o[e];r&&r.warn(deprecated(e,n)),n&&(void 0===i[n]&&(i[n]=i[e]),delete i[e])}}),u=extend({},f),Object.keys(a).forEach(function(e){void 0!==u[e]&&null!==u[e]||(u[e]=a[e]&&a[e].default)}),l=extend({},c=f=u),Object.keys(c).forEach(function(e){var n=c[e];if(null!=n){var t=a[e];if(void 0===t)s(unknownOption(e));else{var r=t.type||d(t.default);if("any"!==r){var o=r.split("|"),i=d(n);o.indexOf(i)<0?"boolean"===r?(l[e]=!!n,s(wrongOptionTypeBoolean(e,i))):(s(wrongOptionType(e,r,i)),l[e]=t.default):"number"===i&&void 0!==t.minimum&&n<t.minimum&&(s(optionBelowMinimum(e,n,t.minimum)),l[e]=t.minimum)}}}}),f=l}var configuration=Object.freeze({__proto__:null,baseOptionDefs:baseOptionDefs,validate:validate}),baseOptionDefs$1=configuration.baseOptionDefs;function DiagnosticId(e){var n={diagnosticId:v1_1()};return e&&(n.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),n}function DiagnosticsAccumulator(e){var n,t,r,o;function i(e){n=e,r=t=0,o=[]}return i(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:o}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,o=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};o.push(r)},reset:i}}function DiagnosticsManager(n,e,t,r,o,i){var a,s,u=!!n.diagnosticUseCombinedEvent,c="ld:"+r+":$diagnostics",l=o.eventsUrl+"/events/diagnostic/"+r,f=o.diagnosticRecordingInterval,d=e,v=!!o.streaming,g={};function p(){return{sdk:function(){var e=_objectSpread2({},n.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},platform:n.diagnosticPlatformData}}function m(e){o.logger&&o.logger.debug(messages.debugPostingDiagnosticEvent(e)),t.sendEvents(e,l,!0).then(function(){}).catch(function(){})}function y(){m(function(){var e=(new Date).getTime(),n=_objectSpread2({kind:u?"diagnostic-combined":"diagnostic",id:i,creationDate:e},d.getProps());return u&&(n=_objectSpread2({},n,{},p())),d.reset(e),n}()),s=setTimeout(y,f),a=(new Date).getTime(),u&&function(){if(n.localStorage){var e=_objectSpread2({},d.getProps());n.localStorage.set(c,JSON.stringify(e),function(){})}}()}return g.start=function(){u?function(t){if(!n.localStorage)return t(!1);n.localStorage.get(c).then(function(e){if(e)try{var n=JSON.parse(e);d.setProps(n),a=n.dataSinceDate}catch(e){}t(!0)}).catch(function(){t(!1)})}(function(e){if(e){var n=(a||0)+f,t=(new Date).getTime();n<=t?y():s=setTimeout(y,n-t)}else 0===Math.floor(4*Math.random())?y():s=setTimeout(y,f)}):(m(_objectSpread2({kind:"diagnostic-init",id:i,creationDate:d.getProps().dataSinceDate},p())),s=setTimeout(y,f))},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,n){var o,i=["debug","info","warn","error"];o=null!=n?""===n?"":n+" ":"LD: ";var a=0;e&&(a="none"===e?100:i.indexOf(e));var t={};function r(e,n,t){if(a<=e){var r=e<i.length?i[e]:"?";n(o+"["+r+"] "+t)}}return t.debug=function(e){return r(0,console.log,e)},t.info=function(e){return r(1,console.info,e)},t.warn=function(e){return r(2,console.warn,e)},t.error=function(e){return r(3,console.error,e)},t}var readyEvent="ready",successEvent="initialized",failedEvent="failed",changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,t,o,r){var a=function(){if(t&&t.logger)return t.logger;return r&&r.logger&&r.logger.default||createConsoleLogger("warn")}(),s=EventEmitter(a),f=validate(t,s,r,a),i=f.sendEvents,u=e,c=f.hash,l=EventSender(o,u,f),d=f.sendEvents&&!f.diagnosticOptOut,v=d?diagnosticEvents_1(u):null,g=d?diagnosticEvents_2((new Date).getTime()):null,p=d?diagnosticEvents_3(o,g,l,u,f,v):null;p&&p.start();var m,y,h,b,E=Stream(o,f,u,g),k=f.eventProcessor||EventProcessor(o,f,u,g,s,l),D=Requestor(o,f,u),S={},w={},U=f.streaming,P=!1,O=!1,I=!0,L=f.stateProvider,T=Identity(null,function(e){if(L)return;e&&F({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),C=UserValidator(o.localStorage,a);function F(e){u&&(L&&L.enqueueEvent&&L.enqueueEvent(e)||(e.user?(I=!1,!i||O||o.isDoNotTrack()||(a.debug(debugEnqueueingEvent(e.kind)),k.enqueue(e))):I&&(a.warn(eventWithoutUser()),I=!1)))}function R(e,n,t,r){var o=T.getUser(),i=new Date,a=n?n.value:null;if(!f.allowFrequentDuplicateEvents){var s=JSON.stringify(a)+(o&&o.key?o.key:"")+e,u=S[s];if(u&&i-u<3e5)return;S[s]=i}var c={kind:"feature",key:e,user:o,value:a,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()},l=w[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),F(c)}function _(e,n,t,r){var o;if(w&&w.hasOwnProperty(e)&&w[e]&&!w[e].deleted){var i=w[e];o=j(i),null!==i.value&&void 0!==i.value||(o.value=n)}else o={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&R(e,o,n,r),o}function j(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function N(){y=!0,T.getUser()&&E.connect(T.getUser(),c,{ping:function(){a.debug(debugStreamPing()),D.fetchFlagSettings(T.getUser(),c).then(function(e){return A(e||{})}).catch(function(e){s.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var n=JSON.parse(e.data);a.debug(debugStreamPut()),A(n)},patch:function(e){var n=JSON.parse(e.data),t=w[n.key];if(!t||!t.version||!n.version||t.version<n.version){a.debug(debugStreamPatch(n.key));var r={},o=extend({},n);delete o.key;var i=j(w[n.key]=o);r[n.key]=t?{previous:t.value,current:i}:{current:i},V(r)}else a.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!w[n.key]||w[n.key].version<n.version){a.debug(debugStreamDelete(n.key));var t={};w[n.key]&&!w[n.key].deleted&&(t[n.key]={previous:w[n.key].value}),w[n.key]={version:n.version,deleted:!0},V(t)}else a.debug(debugStreamDeleteIgnored(n.key))}})}function x(){y&&(E.disconnect(),y=!1)}function A(e){var n={};if(!e)return Promise.resolve();for(var t in w)w.hasOwnProperty(t)&&w[t]&&(e[t]&&!deepEquals(e[t].value,w[t].value)?n[t]={previous:w[t].value,current:j(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:w[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!w[r]||w[r].deleted)&&(n[r]={current:j(e[r])});return w=_objectSpread2({},e),V(n).catch(function(){})}function V(o){var e=Object.keys(o);if(0<e.length){var i={};e.forEach(function(e){var n=o[e].current,t=n?n.value:void 0,r=o[e].previous;s.emit(changeEvent+":"+e,t,r),i[e]=n?{current:t,previous:r}:{previous:r}}),s.emit(changeEvent,i),s.emit(internalChangeEvent,w),f.sendEventsOnlyForVariation||L||e.forEach(function(e){R(e,o[e].current)})}return m&&b?b.saveFlags(w).catch(function(){return null}):Promise.resolve()}function q(){var e=U||h&&void 0===U;e&&!y?N():!e&&y&&x(),p&&p.setStreaming(e)}function M(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}o.localStorage&&(b=new Store(o.localStorage,u,c,T,a));var z=new Promise(function(e){var n=s.on(readyEvent,function(){s.off(readyEvent,n),e()})}),B=new Promise(function(e,n){var t=s.on(successEvent,function(){s.off(successEvent,t),e()}),r=s.on(failedEvent,function(e){s.off(failedEvent,r),n(e)})});if("string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(b?m=!0:a.warn(localStorageUnavailable())),"object"===_typeof(f.bootstrap)&&(w=function(t){var e=Object.keys(t),r="$flagsState",o=t[r];!o&&e.length&&a.warn(bootstrapOldFormat()),!1===t.$valid&&a.warn(bootstrapInvalid());var i={};return e.forEach(function(e){if(e!==r&&"$valid"!==e){var n={value:t[e]};o&&o[e]?n=extend(n,o[e]):n.version=0,i[e]=n}}),i}(f.bootstrap)),L){var K=L.getInitialState();K?H(K):L.on("init",H),L.on("update",function(e){e.user&&T.setUser(e.user);e.flags&&A(e.flags)})}else(e?C.validateUser(n).then(function(e){return T.setUser(e),"object"===_typeof(f.bootstrap)?J():m?b.loadFlags().catch(function(){return null}).then(function(e){return null==e?(w={},D.fetchFlagSettings(T.getUser(),c).then(function(e){return A(e||{})}).then(J).catch(function(e){$(new LDFlagFetchError(errorFetchingFlags(e)))})):(w=e,onNextTick(J),D.fetchFlagSettings(T.getUser(),c).then(function(e){return A(e)}).catch(function(e){return s.maybeReportError(e)}))}):D.fetchFlagSettings(T.getUser(),c).then(function(e){w=e||{},J()}).catch(function(e){w={},$(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(function(e){return s.maybeReportError(e)});function H(e){u=e.environment,T.setUser(e.user),w=_objectSpread2({},e.flags),onNextTick(J)}function J(){a.info(clientInitialized()),P=!0,q(),s.emit(readyEvent),s.emit(successEvent)}function $(e){s.maybeReportError(e),s.emit(failedEvent,e),s.emit(readyEvent)}return{client:{waitForInitialization:function(){return B},waitUntilReady:function(){return z},identify:function(e,r,n){return O?wrapPromiseCallback(Promise.resolve({}),n):L?(a.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(w)),n)):wrapPromiseCallback((m&&b?b.clearFlags():Promise.resolve()).then(function(){return C.validateUser(e)}).then(function(t){return D.fetchFlagSettings(t,r).then(function(e){var n=transformVersionedValuesToValues(e);return T.setUser(t),c=r,e?A(e).then(function(){return n}):n})}).then(function(e){return y&&N(),e}).catch(function(e){return s.maybeReportError(e),Promise.reject(e)}),n)},getUser:function(){return T.getUser()},variation:function(e,n){return _(e,n,!0,!1).value},variationDetail:function(e,n){return _(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){o.customEventFilter&&!o.customEventFilter(e)&&a.warn(unknownCustomEventKey(e));var r={kind:"custom",key:e,user:T.getUser(),url:o.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),F(r)}else s.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,t){M(e)?(h=!0,P&&q(),s.on(e,n,t)):s.on.apply(s,arguments)},off:function(e){if(s.off.apply(s,arguments),M(e)){var n=!1;s.getEvents().forEach(function(e){M(e)&&0<s.getEventListenerCount(e)&&(n=!0)}),n||(h=!1,y&&void 0===U&&x())}},setStreaming:function(e){var n=null===e?void 0:e;n!==U&&(U=n,q())},flush:function(e){return wrapPromiseCallback(i?k.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!w)return e;for(var n in w)w.hasOwnProperty(n)&&(e[n]=_(n,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(O)return wrapPromiseCallback(Promise.resolve(),e);function n(){O=!0,w={}}return wrapPromiseCallback(Promise.resolve().then(function(){if(x(),p&&p.stop(),i)return k.stop(),k.flush()}).then(n).catch(n),e)}},options:f,emitter:s,ident:T,logger:a,requestor:D,start:function(){i&&(p&&p.start(),k.start())},enqueueEvent:F,getFlagsInternal:function(){return w},getEnvironmentId:function(){return u},internalChangeEventName:internalChangeEvent}}var version="3.2.2";exports.createConsoleLogger=createConsoleLogger,exports.errors=errors,exports.initialize=initialize,exports.messages=messages,exports.utils=utils,exports.version=version; | ||
"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,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function ownKeys(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),t.push.apply(t,r)}return t}function _objectSpread2(n){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(t,!0).forEach(function(e){_defineProperty(n,e,t[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):ownKeys(t).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(t,e))})}return n}function createCustomError(e){function n(e,n){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=n}return(n.prototype=new Error).name=e,n.prototype.constructor=n}Object.defineProperty(exports,"__esModule",{value:!0});var LDUnexpectedResponseError=createCustomError("LaunchDarklyUnexpectedResponseError"),LDInvalidEnvironmentIdError=createCustomError("LaunchDarklyInvalidEnvironmentIdError"),LDInvalidUserError=createCustomError("LaunchDarklyInvalidUserError"),LDInvalidEventKeyError=createCustomError("LaunchDarklyInvalidEventKeyError"),LDInvalidArgumentError=createCustomError("LaunchDarklyInvalidArgumentError"),LDFlagFetchError=createCustomError("LaunchDarklyFlagFetchError");function isHttpErrorRecoverable(e){return!(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,n,t){for(var r,o=[],i=n;i<t;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var n,t=e.length,r=t%3,o=[],i=16383,a=0,s=t-r;a<s;a+=i)o.push(encodeChunk(e,a,s<a+i?s:a+i));return 1==r?(n=e[t-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2==r&&(n=(e[t-2]<<8)+e[t-1],o.push(lookup[n>>10]+lookup[n>>4&63]+lookup[n<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,o,i,a=isArray(n),s=isArray(t);if(a&&s){if((o=n.length)!=t.length)return!1;for(r=o;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=s)return!1;var u=n instanceof Date,c=t instanceof Date;if(u!=c)return!1;if(u&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var d=keyList(n);if((o=d.length)!==keyList(t).length)return!1;for(r=o;0!=r--;)if(!hasProp.call(t,d[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=d[r]],t[i]))return!1;return!0}return n!=n&&t!=t},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function btoa(e){var n=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(n))}function stringToBytes(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,n){return fastDeepEqual(e,n)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function transformValuesToVersionedValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function chunkUserEventsForUrl(e,n){for(var t,r=n.slice(0),o=[],i=e;0<r.length;){for(t=[];0<i;){var a=r.shift();if(!a)break;(i-=base64URLEncode(JSON.stringify(a)).length)<0&&0<t.length?r.unshift(a):t.push(a)}i=e,o.push(t)}return o}function getLDUserAgentString(e){var n=e.version||"3.2.3";return e.userAgent+"/"+n}function getLDHeaders(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function extend(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return _objectSpread2({},e,{},n)},{})}function sanitizeUser(e){if(!e)return e;var n;for(var t in userAttrsToStringify){var r=userAttrsToStringify[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||_objectSpread2({},e))[r]=String(o))}return n||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,extend:extend,sanitizeUser:sanitizeUser});function createCommonjsModule(e,n){return e(n={exports:{}},n.exports),n.exports}for(var rngBrowser=createCommonjsModule(function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var t=n||0,r=byteToHex;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||_nodeId,a=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==i||null==a){var s=rngBrowser();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:(new Date).getTime(),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 f=(1e4*(268435455&(u+=122192928e5))+(_lastNSecs=c))%4294967296;o[r++]=f>>>24&255,o[r++]=f>>>16&255,o[r++]=f>>>8&255,o[r++]=255&f;var d=u/4294967296*1e4&268435455;o[r++]=d>>>8&255,o[r++]=255&d,o[r++]=d>>>24&15|16,o[r++]=d>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var v=0;v<6;++v)o[r+v]=i[v];return n||bytesToUuid_1(o)}var v1_1=v1,MAX_URL_LENGTH=2e3;function EventSender(s,e,n){var t="/a/"+e+".gif",u=extend({"Content-Type":"application/json"},getLDHeaders(s,n)),c=s.httpFallbackPing,l={};return l.sendChunk=function(e,r,o,n){var i=JSON.stringify(e),a=o?null:v1_1();return n?function n(t){var e=o?u:extend({},u,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":a});return s.httpRequest("POST",r,e,i).promise.then(function(e){if(e)return 400<=e.status&&isHttpErrorRecoverable(e.status)&&t?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)}).catch(function(){return t?n(!1):Promise.reject()})}(!0).catch(function(){}):(c&&c(r+t+"?d="+base64URLEncode(i)),Promise.resolve())},l.sendEvents=function(e,n,t){if(!s.httpRequest)return Promise.resolve();var r,o=s.httpAllowsPost();r=o?[e]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,e);for(var i=[],a=0;a<r.length;a++)i.push(l.sendChunk(r[a],n,t,o));return Promise.all(i)},l}function EventSummarizer(){var e={},a=0,s=0,u={};return e.summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=u[n];t?t.count=t.count+1:u[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>s&&(s=e.creationDate)}},e.getSummary=function(){var e={},n=!0;for(var t in u){var r=u[t],o=e[r.key];o||(o={default:r.default,counters:[]},e[r.key]=o);var i={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),n=!1}return n?null:{startDate:a,endDate:s,features:e}},e.clearSummary=function(){s=a=0,u={}},e}function UserFilter(e){var n={},u=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},f={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;function n(r,o){return Object.keys(r).reduce(function(e,n){var t=e;return o(n)&&(!function(e){return!l[e]&&(u||-1!==i.indexOf(e)||-1!==c.indexOf(e))}(n)?t[0][n]=r[n]:t[1][n]=!0),t},[{},{}])}var i=e.privateAttributeNames||[],t=n(e,function(e){return f[e]}),r=t[0],o=t[1];if(e.custom){var a=n(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},n}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",clientNotReady=function(){return"LaunchDarkly client is not ready"},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/docs/js-sdk-reference#section-analytics-events"},invalidContentType=function(e){return'Expected application/json content type but got "'+e+'"'},invalidKey=function(){return"Event key must be a string"},localStorageUnavailable=function(){return"localStorage is unavailable"},localStorageUnavailableForUserId=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},networkError=function(e){return"network error"+(e?" ("+e+")":"")},unknownCustomEventKey=function(e){return'Custom event "'+e+'" does not exist'},environmentNotFound=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+docLink},environmentNotSpecified=function(){return"No environment/client-side ID was specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+errorString(e)},userNotSpecified=function(){return"No user specified."+docLink},invalidUser=function(){return"Invalid user specified."+docLink},bootstrapOldFormat=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+docLink},bootstrapInvalid=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},httpErrorMessage=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?t:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e,n){return"Error on stream connection: "+errorString(e)+", will continue retrying every "+n+" milliseconds."},unknownOption=function(e){return'Ignoring unknown config option "'+e+'"'},wrongOptionType=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},wrongOptionTypeBoolean=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},optionBelowMinimum=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},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,n,t){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,t,n),u=n.eventsUrl+"/events/bulk/"+t,c=EventSummarizer(),l=UserFilter(n),f=n.inlineUsersInEvents,d=n.samplingInterval,v=n.eventCapacity,g=n.flushInterval,p=n.logger,m=[],y=0,h=!1,b=!1;function E(){return 0===d||0===Math.floor(Math.random()*d)}function k(e){m.length<v?(m.push(e),b=!1):(b||(b=!0,p.warn(eventCapacityExceeded())),o&&o.incrementDroppedEvents())}return a.enqueue=function(e){if(!h){var n=!1,t=!1;if(c.summarizeEvent(e),"feature"===e.kind?E()&&(n=!!e.trackEvents,t=function(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>y&&e.debugEventsUntilDate>(new Date).getTime())}(e)):n=E(),n&&k(function(e){var n=extend({},e);return f||"identify"===e.kind?n.user=l.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),t){var r=extend({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,k(r)}}},a.flush=function(){if(h)return Promise.resolve();var e=m,n=c.getSummary();return c.clearSummary(),n&&(n.kind="summary",e.push(n)),o&&o.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(m=[],p.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(n){var e={},o={};return e.on=function(e,n,t){o[e]=o[e]||[],o[e]=o[e].concat({handler:n,context:t})},e.off=function(e,n,t){if(o[e])for(var r=0;r<o[e].length;r++)o[e][r].handler===n&&o[e][r].context===t&&(o[e]=o[e].slice(0,r).concat(o[e].slice(r+1)))},e.emit=function(e){if(o[e])for(var n=o[e].slice(0),t=0;t<n.length;t++)n[t].handler.apply(n[t].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(o)},e.getEventListenerCount=function(e){return o[e]?o[e].length:0},e.maybeReportError=function(e){e&&(!function(e){return!!o[e]}("error")?(n||console).error(e.message):this.emit("error",e))},e}var readyEvent="ready",successEvent="initialized",failureEvent="failed";function InitializationStateTracker(r){var n=!1,t=!1,o=null,e=null,i=new Promise(function(n){r.on(readyEvent,function e(){r.off(readyEvent,e),n()})}).catch(function(){});return{getInitializationPromise:function(){return e||(n?Promise.resolve():t?Promise.reject(o):e=new Promise(function(n,t){r.on(successEvent,function e(){r.off(successEvent,e),n()}),r.on(failureEvent,function e(n){r.off(failureEvent,e),t(n)})}))},getReadyPromise:function(){return i},signalSuccess:function(){n||t||(n=!0,r.emit(successEvent),r.emit(readyEvent))},signalFailure:function(e){n||t||(t=!0,o=e,r.emit(failureEvent,e),r.emit(readyEvent)),r.maybeReportError(e)}}}var InitializationState=InitializationStateTracker;function Store(t,r,o,i,a){var s={};function u(){var e="",n=i.getUser();return n&&(e=o||btoa(JSON.stringify(n))),"ld:"+r+":"+e}return s.loadFlags=function(){return t.get(u()).then(function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var t=n.$schema;void 0===t||t<1?n=transformValuesToVersionedValues(n):delete n.$schema}return n}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 n=extend({},e,{$schema:1});return t.set(u(),JSON.stringify(n)).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},s.clearFlags=function(){return t.clear(u()).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},s}function Stream(o,e,i,n){var a,s=e.streamUrl,u=e.logger,t={},c=s+"/eval/"+i,l=e.useReport,f=e.evaluationReasons,r=e.streamReconnectDelay,d=getLDHeaders(o,e),v=!1,g=null,p=null,m=null,y=null,h=null;function b(e){v||(u.warn(streamError(e,r)),v=!0),D(!1),S(),E(r)}function E(e){p||(e?p=setTimeout(k,e):k())}function k(){var e;p=null;var n="",t={headers:d};if(o.eventSourceFactory){for(var r in null!=y&&(n="h="+y),l?o.eventSourceAllowsReport?(e=c,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(m)):(e=s+"/ping/"+i,n=""):e=c+"/"+base64URLEncode(JSON.stringify(m)),f&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,S(),u.info(streamConnecting(e)),a=(new Date).getTime(),g=o.eventSourceFactory(e,t),h)h.hasOwnProperty(r)&&g.addEventListener(r,h[r]);g.onerror=b}}function S(){g&&(u.info(streamClosing()),g.close(),g=null)}function D(e){a&&n&&n.recordStreamInit(a,!e,(new Date).getTime()-a),a=null}return t.connect=function(e,n,t){m=e,y=n,h={};function r(n){h[n]=function(e){D(!(v=!1)),t[n]&&t[n](e)}}for(var o in t||{})r(o);E()},t.disconnect=function(){clearTimeout(p),p=null,S()},t.isConnected=function(){return!!(g&&o.eventSourceIsActive&&o.eventSourceIsActive(g))},t}function promiseCoalescer(t){var r,o,i,a,e={addPromise:function(n,e){r=n,o&&o(),o=e,n.then(function(e){r===n&&(i(e),t&&t())},function(e){r===n&&(a(e),t&&t())})}};return e.resultPromise=new Promise(function(e,n){i=e,a=n}),e}var json="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,f=u.evaluationReasons,d=u.logger,e={},v={};function g(e,n){if(!s.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var t=n?"REPORT":"GET",r=getLDHeaders(s,u);n&&(r["Content-Type"]="application/json");var o=v[e];o||(o=promiseCoalescer(function(){delete v[e]}),v[e]=o);var i=s.httpRequest(t,e,r,n),a=i.promise.then(function(e){if(200!==e.status)return Promise.reject(getResponseError(e));if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(json))return JSON.parse(e.body);var n=invalidContentType(e.header("content-type")||"");return Promise.reject(new LDFlagFetchError(n))},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,n){var t,r,o,i="";return l?(r=[c,"/sdk/evalx/",a,"/user"].join(""),o=JSON.stringify(e)):(t=base64URLEncode(JSON.stringify(e)),r=[c,"/sdk/evalx/",a,"/users/",t].join("")),n&&(i="h="+n),f&&(i=i+(i?"&":"")+"withReasons=true"),r=r+(i?"?":"")+i,d.debug(debugPolling(r)),g(r,o)},e}function Identity(e,n){var t,r={};return r.setUser=function(e){(t=sanitizeUser(e))&&n&&n(clone(t))},r.getUser=function(){return t?clone(t):null},e&&r.setUser(e),r}var ldUserIdKey="ld:$anonUserId";function UserValidator(r,o){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?(r?r.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(e){if(e)return t.key=e,t;var n=v1_1();return function(e){return r?r.set(ldUserIdKey,e).catch(function(){o.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(t.key=n).then(function(){return t})}):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},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"}};function validate(e,n,t,r){var a=extend({logger:{default:r}},baseOptionDefs,t),o={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function s(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var i,u,c,l,f=extend({},e||{});function d(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var n=_typeof(e);return"boolean"===n||"string"===n||"number"===n||"function"===n?n:"object"}}return i=f,Object.keys(o).forEach(function(e){if(void 0!==i[e]){var n=o[e];r&&r.warn(deprecated(e,n)),n&&(void 0===i[n]&&(i[n]=i[e]),delete i[e])}}),u=extend({},f),Object.keys(a).forEach(function(e){void 0!==u[e]&&null!==u[e]||(u[e]=a[e]&&a[e].default)}),l=extend({},c=f=u),Object.keys(c).forEach(function(e){var n=c[e];if(null!=n){var t=a[e];if(void 0===t)s(unknownOption(e));else{var r=t.type||d(t.default);if("any"!==r){var o=r.split("|"),i=d(n);o.indexOf(i)<0?"boolean"===r?(l[e]=!!n,s(wrongOptionTypeBoolean(e,i))):(s(wrongOptionType(e,r,i)),l[e]=t.default):"number"===i&&void 0!==t.minimum&&n<t.minimum&&(s(optionBelowMinimum(e,n,t.minimum)),l[e]=t.minimum)}}}}),f=l}var configuration=Object.freeze({__proto__:null,baseOptionDefs:baseOptionDefs,validate:validate}),baseOptionDefs$1=configuration.baseOptionDefs;function DiagnosticId(e){var n={diagnosticId:v1_1()};return e&&(n.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),n}function DiagnosticsAccumulator(e){var n,t,r,o;function i(e){n=e,r=t=0,o=[]}return i(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:o}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,o=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};o.push(r)},reset:i}}function DiagnosticsManager(n,e,t,r,o,i){var a,s,u=!!n.diagnosticUseCombinedEvent,c="ld:"+r+":$diagnostics",l=o.eventsUrl+"/events/diagnostic/"+r,f=o.diagnosticRecordingInterval,d=e,v=!!o.streaming,g={};function p(){return{sdk:function(){var e=_objectSpread2({},n.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},platform:n.diagnosticPlatformData}}function m(e){o.logger&&o.logger.debug(messages.debugPostingDiagnosticEvent(e)),t.sendEvents(e,l,!0).then(function(){}).catch(function(){})}function y(){m(function(){var e=(new Date).getTime(),n=_objectSpread2({kind:u?"diagnostic-combined":"diagnostic",id:i,creationDate:e},d.getProps());return u&&(n=_objectSpread2({},n,{},p())),d.reset(e),n}()),s=setTimeout(y,f),a=(new Date).getTime(),u&&function(){if(n.localStorage){var e=_objectSpread2({},d.getProps());n.localStorage.set(c,JSON.stringify(e),function(){})}}()}return g.start=function(){u?function(t){if(!n.localStorage)return t(!1);n.localStorage.get(c).then(function(e){if(e)try{var n=JSON.parse(e);d.setProps(n),a=n.dataSinceDate}catch(e){}t(!0)}).catch(function(){t(!1)})}(function(e){if(e){var n=(a||0)+f,t=(new Date).getTime();n<=t?y():s=setTimeout(y,n-t)}else 0===Math.floor(4*Math.random())?y():s=setTimeout(y,f)}):(m(_objectSpread2({kind:"diagnostic-init",id:i,creationDate:d.getProps().dataSinceDate},p())),s=setTimeout(y,f))},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,n){var o,i=["debug","info","warn","error"];o=null!=n?""===n?"":n+" ":"LD: ";var a=0;e&&(a="none"===e?100:i.indexOf(e));var t={};function r(e,n,t){if(a<=e){var r=e<i.length?i[e]:"?";n(o+"["+r+"] "+t)}}return t.debug=function(e){return r(0,console.log,e)},t.info=function(e){return r(1,console.info,e)},t.warn=function(e){return r(2,console.warn,e)},t.error=function(e){return r(3,console.error,e)},t}var changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,t,o,r){var a=function(){if(t&&t.logger)return t.logger;return r&&r.logger&&r.logger.default||createConsoleLogger("warn")}(),s=EventEmitter(a),i=InitializationState(s),f=validate(t,s,r,a),u=f.sendEvents,c=e,l=f.hash,d=EventSender(o,c,f),v=f.sendEvents&&!f.diagnosticOptOut,g=v?diagnosticEvents_1(c):null,p=v?diagnosticEvents_2((new Date).getTime()):null,m=v?diagnosticEvents_3(o,p,d,c,f,g):null;m&&m.start();var y,h,b,E,k=Stream(o,f,c,p),S=f.eventProcessor||EventProcessor(o,f,c,p,s,d),D=Requestor(o,f,c),w={},U={},P=f.streaming,I=!1,O=!1,L=!0,T=f.stateProvider,F=Identity(null,function(e){if(T)return;e&&R({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),C=UserValidator(o.localStorage,a);function R(e){c&&(T&&T.enqueueEvent&&T.enqueueEvent(e)||(e.user?(L=!1,!u||O||o.isDoNotTrack()||(a.debug(debugEnqueueingEvent(e.kind)),S.enqueue(e))):L&&(a.warn(eventWithoutUser()),L=!1)))}function _(e,n,t,r){var o=F.getUser(),i=new Date,a=n?n.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:n?n.variationIndex:null,default:t,creationDate:i.getTime()},l=U[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),R(c)}function j(e,n,t,r){var o;if(U&&U.hasOwnProperty(e)&&U[e]&&!U[e].deleted){var i=U[e];o=N(i),null!==i.value&&void 0!==i.value||(o.value=n)}else o={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&_(e,o,n,r),o}function N(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function x(){h=!0,F.getUser()&&k.connect(F.getUser(),l,{ping:function(){a.debug(debugStreamPing()),D.fetchFlagSettings(F.getUser(),l).then(function(e){return V(e||{})}).catch(function(e){s.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var n=JSON.parse(e.data);a.debug(debugStreamPut()),V(n)},patch:function(e){var n=JSON.parse(e.data),t=U[n.key];if(!t||!t.version||!n.version||t.version<n.version){a.debug(debugStreamPatch(n.key));var r={},o=extend({},n);delete o.key;var i=N(U[n.key]=o);r[n.key]=t?{previous:t.value,current:i}:{current:i},q(r)}else a.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!U[n.key]||U[n.key].version<n.version){a.debug(debugStreamDelete(n.key));var t={};U[n.key]&&!U[n.key].deleted&&(t[n.key]={previous:U[n.key].value}),U[n.key]={version:n.version,deleted:!0},q(t)}else a.debug(debugStreamDeleteIgnored(n.key))}})}function A(){h&&(k.disconnect(),h=!1)}function V(e){var n={};if(!e)return Promise.resolve();for(var t in U)U.hasOwnProperty(t)&&U[t]&&(e[t]&&!deepEquals(e[t].value,U[t].value)?n[t]={previous:U[t].value,current:N(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:U[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!U[r]||U[r].deleted)&&(n[r]={current:N(e[r])});return U=_objectSpread2({},e),q(n).catch(function(){})}function q(o){var e=Object.keys(o);if(0<e.length){var i={};e.forEach(function(e){var n=o[e].current,t=n?n.value:void 0,r=o[e].previous;s.emit(changeEvent+":"+e,t,r),i[e]=n?{current:t,previous:r}:{previous:r}}),s.emit(changeEvent,i),s.emit(internalChangeEvent,U),f.sendEventsOnlyForVariation||T||e.forEach(function(e){_(e,o[e].current)})}return y&&E?E.saveFlags(U).catch(function(){return null}):Promise.resolve()}function M(){var e=P||b&&void 0===P;e&&!h?x():!e&&h&&A(),m&&m.setStreaming(e)}function z(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}if(o.localStorage&&(E=new Store(o.localStorage,c,l,F,a)),"string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(E?y=!0:a.warn(localStorageUnavailable())),"object"===_typeof(f.bootstrap)&&(U=function(t){var e=Object.keys(t),r="$flagsState",o=t[r];!o&&e.length&&a.warn(bootstrapOldFormat()),!1===t.$valid&&a.warn(bootstrapInvalid());var i={};return e.forEach(function(e){if(e!==r&&"$valid"!==e){var n={value:t[e]};o&&o[e]?n=extend(n,o[e]):n.version=0,i[e]=n}}),i}(f.bootstrap)),T){var B=T.getInitialState();B?K(B):T.on("init",K),T.on("update",function(e){e.user&&F.setUser(e.user);e.flags&&V(e.flags)})}else(e?C.validateUser(n).then(function(e){return F.setUser(e),"object"===_typeof(f.bootstrap)?H():y?E.loadFlags().catch(function(){return null}).then(function(e){return null==e?(U={},D.fetchFlagSettings(F.getUser(),l).then(function(e){return V(e||{})}).then(H).catch(function(e){J(new LDFlagFetchError(errorFetchingFlags(e)))})):(U=e,onNextTick(H),D.fetchFlagSettings(F.getUser(),l).then(function(e){return V(e)}).catch(function(e){return s.maybeReportError(e)}))}):D.fetchFlagSettings(F.getUser(),l).then(function(e){U=e||{},H()}).catch(function(e){U={},J(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(J);function K(e){c=e.environment,F.setUser(e.user),U=_objectSpread2({},e.flags),onNextTick(H)}function H(){a.info(clientInitialized()),I=!0,M(),i.signalSuccess()}function J(e){i.signalFailure(e)}return{client:{waitForInitialization:function(){return i.getInitializationPromise()},waitUntilReady:function(){return i.getReadyPromise()},identify:function(e,r,n){return O?wrapPromiseCallback(Promise.resolve({}),n):T?(a.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(U)),n)):wrapPromiseCallback((y&&E?E.clearFlags():Promise.resolve()).then(function(){return C.validateUser(e)}).then(function(t){return D.fetchFlagSettings(t,r).then(function(e){var n=transformVersionedValuesToValues(e);return F.setUser(t),l=r,e?V(e).then(function(){return n}):n})}).then(function(e){return h&&x(),e}).catch(function(e){return s.maybeReportError(e),Promise.reject(e)}),n)},getUser:function(){return F.getUser()},variation:function(e,n){return j(e,n,!0,!1).value},variationDetail:function(e,n){return j(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){o.customEventFilter&&!o.customEventFilter(e)&&a.warn(unknownCustomEventKey(e));var r={kind:"custom",key:e,user:F.getUser(),url:o.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),R(r)}else s.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,t){z(e)?(b=!0,I&&M(),s.on(e,n,t)):s.on.apply(s,arguments)},off:function(e){if(s.off.apply(s,arguments),z(e)){var n=!1;s.getEvents().forEach(function(e){z(e)&&0<s.getEventListenerCount(e)&&(n=!0)}),n||(b=!1,h&&void 0===P&&A())}},setStreaming:function(e){var n=null===e?void 0:e;n!==P&&(P=n,M())},flush:function(e){return wrapPromiseCallback(u?S.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!U)return e;for(var n in U)U.hasOwnProperty(n)&&(e[n]=j(n,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(O)return wrapPromiseCallback(Promise.resolve(),e);function n(){O=!0,U={}}return wrapPromiseCallback(Promise.resolve().then(function(){if(A(),m&&m.stop(),u)return S.stop(),S.flush()}).then(n).catch(n),e)}},options:f,emitter:s,ident:F,logger:a,requestor:D,start:function(){u&&(m&&m.start(),S.start())},enqueueEvent:R,getFlagsInternal:function(){return U},getEnvironmentId:function(){return c},internalChangeEventName:internalChangeEvent}}var version="3.2.3";exports.createConsoleLogger=createConsoleLogger,exports.errors=errors,exports.initialize=initialize,exports.messages=messages,exports.utils=utils,exports.version=version; | ||
//# sourceMappingURL=ldclient-common.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
function e(n){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(n)}function n(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function t(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function r(e){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?t(i,!0).forEach((function(t){n(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):t(i).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(i,n))}))}return e}function i(e){function n(e,n){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=n}return n.prototype=new Error,n.prototype.name=e,n.prototype.constructor=n,n}var o=i("LaunchDarklyUnexpectedResponseError"),a=i("LaunchDarklyInvalidEnvironmentIdError"),u=i("LaunchDarklyInvalidUserError"),s=i("LaunchDarklyInvalidEventKeyError"),c=i("LaunchDarklyInvalidArgumentError"),l=i("LaunchDarklyFlagFetchError");function f(e){return!(e>=400&&e<500)||(400===e||408===e||429===e)}for(var v=Object.freeze({__proto__:null,LDUnexpectedResponseError:o,LDInvalidEnvironmentIdError:a,LDInvalidUserError:u,LDInvalidEventKeyError:s,LDInvalidArgumentError:c,LDFlagFetchError:l,isHttpErrorRecoverable:f}),d=function(e){for(var n,t=e.length,r=t%3,i=[],o=0,a=t-r;o<a;o+=16383)i.push(b(e,o,o+16383>a?a:o+16383));1===r?(n=e[t-1],i.push(g[n>>2]+g[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],i.push(g[n>>10]+g[n>>4&63]+g[n<<2&63]+"="));return i.join("")},g=[],p=[],m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,y=m.length;h<y;++h)g[h]=m[h],p[m.charCodeAt(h)]=h;function b(e,n,t){for(var r,i,o=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(g[(i=r)>>18&63]+g[i>>12&63]+g[i>>6&63]+g[63&i]);return o.join("")}p["-".charCodeAt(0)]=62,p["_".charCodeAt(0)]=63;var k=Array.isArray,E=Object.keys,w=Object.prototype.hasOwnProperty,D=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function S(e){var n=unescape(encodeURIComponent(e));return d(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function O(e){return S(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function P(e){return JSON.parse(JSON.stringify(e))}function U(e,n){return function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,i,o,a=k(n),u=k(t);if(a&&u){if((i=n.length)!=t.length)return!1;for(r=i;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var s=n instanceof Date,c=t instanceof Date;if(s!=c)return!1;if(s&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var v=E(n);if((i=v.length)!==E(t).length)return!1;for(r=i;0!=r--;)if(!w.call(t,v[r]))return!1;for(r=i;0!=r--;)if(!e(n[o=v[r]],t[o]))return!1;return!0}return n!=n&&t!=t}(e,n)}function I(e){setTimeout(e,0)}function j(e,n){var t=e.then((function(e){return n&&setTimeout((function(){n(null,e)}),0),e}),(function(e){if(!n)return Promise.reject(e);setTimeout((function(){n(e,null)}),0)}));return n?void 0:t}function R(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function T(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function N(e,n){for(var t,r=n.slice(0),i=[],o=e;r.length>0;){for(t=[];o>0;){var a=r.shift();if(!a)break;(o-=O(JSON.stringify(a)).length)<0&&t.length>0?r.unshift(a):t.push(a)}o=e,i.push(t)}return i}function F(e){var n=e.version||"3.2.2";return e.userAgent+"/"+n}function C(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":F(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function L(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce((function(e,n){return r({},e,{},n)}),{})}function A(e){if(!e)return e;var n;for(var t in D){var i=D[t],o=e[i];void 0!==o&&"string"!=typeof o&&((n=n||r({},e))[i]=String(o))}return n||e}var x=Object.freeze({__proto__:null,btoa:S,base64URLEncode:O,clone:P,deepEquals:U,onNextTick:I,wrapPromiseCallback:j,transformValuesToVersionedValues:R,transformVersionedValuesToValues:T,chunkUserEventsForUrl:N,getLDUserAgentString:F,getLDHeaders:C,extend:L,sanitizeUser:A});for(var V=function(e,n){return e(n={exports:{}},n.exports),n.exports}((function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}})),q=[],_=0;_<256;++_)q[_]=(_+256).toString(16).substr(1);var J,z,M=function(e,n){var t=n||0,r=q;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")},B=0,K=0;var $=function(e,n,t){var r=n&&t||0,i=n||[],o=(e=e||{}).node||J,a=void 0!==e.clockseq?e.clockseq:z;if(null==o||null==a){var u=V();null==o&&(o=J=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=z=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:K+1,l=s-B+(c-K)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>B)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");B=s,K=c,z=a;var f=(1e4*(268435455&(s+=122192928e5))+c)%4294967296;i[r++]=f>>>24&255,i[r++]=f>>>16&255,i[r++]=f>>>8&255,i[r++]=255&f;var v=s/4294967296*1e4&268435455;i[r++]=v>>>8&255,i[r++]=255&v,i[r++]=v>>>24&15|16,i[r++]=v>>>16&255,i[r++]=a>>>8|128,i[r++]=255&a;for(var d=0;d<6;++d)i[r+d]=o[d];return n||M(i)};function G(e,n,t){var r="/a/"+n+".gif",i=L({"Content-Type":"application/json"},C(e,t)),o=e.httpFallbackPing,a={};return a.sendChunk=function(n,t,a,u){var s=JSON.stringify(n),c=a?null:$();return u?function n(r){var o=a?i:L({},i,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":c});return e.httpRequest("POST",t,o,s).promise.then((function(e){if(e)return e.status>=400&&f(e.status)&&r?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)})).catch((function(){return r?n(!1):Promise.reject()}))}(!0).catch((function(){})):(o&&o(t+r+"?d="+O(s)),Promise.resolve())},a.sendEvents=function(n,t,r){if(!e.httpRequest)return Promise.resolve();var i,o=e.httpAllowsPost();i=o?[n]:N(2e3-t.length,n);for(var u=[],s=0;s<i.length;s++)u.push(a.sendChunk(i[s],t,r,o));return Promise.all(u)},a}function H(){var e={},n=0,t=0,r={};return e.summarizeEvent=function(e){if("feature"===e.kind){var i=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),o=r[i];o?o.count=o.count+1:r[i]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===n||e.creationDate<n)&&(n=e.creationDate),e.creationDate>t&&(t=e.creationDate)}},e.getSummary=function(){var e={},i=!0;for(var o in r){var a=r[o],u=e[a.key];u||(u={default:a.default,counters:[]},e[a.key]=u);var s={value:a.value,count:a.count};void 0!==a.variation&&null!==a.variation&&(s.variation=a.variation),a.version?s.version=a.version:s.unknown=!0,u.counters.push(s),i=!1}return i?null:{startDate:n,endDate:t,features:e}},e.clearSummary=function(){n=0,t=0,r={}},e}function X(e){var n={},t=e.allAttributesPrivate,r=e.privateAttributeNames||[],i={key:!0,custom:!0,anonymous:!0},o={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;var n=e.privateAttributeNames||[],a=function(e,o){return Object.keys(e).reduce((function(a,u){var s=a;return o(u)&&(!function(e){return!i[e]&&(t||-1!==n.indexOf(e)||-1!==r.indexOf(e))}(u)?s[0][u]=e[u]:s[1][u]=!0),s}),[{},{}])},u=a(e,(function(e){return o[e]})),s=u[0],c=u[1];if(e.custom){var l=a(e.custom,(function(){return!0}));s.custom=l[0],c=L({},c,l[1])}var f=Object.keys(c);return f.length&&(f.sort(),s.privateAttrs=f),s},n}function W(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var Q=function(){return"LaunchDarkly client initialized"},Y=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",Z=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},ee=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"},ne=function(e){return'Expected application/json content type but got "'+e+'"'},te=function(){return"localStorage is unavailable"},re=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},ie=function(e){return"network error"+(e?" ("+e+")":"")},oe=function(e){return'Custom event "'+e+'" does not exist'},ae=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+Y},ue=function(){return"No environment/client-side ID was specified."+Y},se=function(e){return"Error fetching flag settings: "+W(e)},ce=function(){return"No user specified."+Y},le=function(){return"Invalid user specified."+Y},fe=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+Y},ve=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},de=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},ge=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(f(e)?t:"giving up permanently")},pe=function(){return"Cannot make HTTP requests in this environment."+Y},me=function(){return"identify() has no effect here; it must be called on the main client instance"},he=function(){return"Closing stream connection"},ye=function(e){return"Opening stream connection to "+e},be=function(e,n){return"Error on stream connection: "+W(e)+", will continue retrying every "+n+" milliseconds."},ke=function(e){return'Ignoring unknown config option "'+e+'"'},Ee=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},we=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},De=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},Se=function(e){return"polling for feature flags at "+e},Oe=function(){return"received ping message from stream"},Pe=function(){return"received streaming update for all flags"},Ue=function(e){return'received streaming update for flag "'+e+'"'},Ie=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},je=function(e){return'received streaming deletion for flag "'+e+'"'},Re=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},Te=function(e){return'enqueueing "'+e+'" event'},Ne=function(e){return"sending "+e+" events"},Fe=Object.freeze({__proto__:null,clientInitialized:Q,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:Z,eventWithoutUser:ee,invalidContentType:ne,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:te,localStorageUnavailableForUserId:re,networkError:ie,unknownCustomEventKey:oe,environmentNotFound:ae,environmentNotSpecified:ue,errorFetchingFlags:se,userNotSpecified:ce,invalidUser:le,bootstrapOldFormat:fe,bootstrapInvalid:ve,deprecated:de,httpErrorMessage:ge,httpUnavailable:pe,identifyDisabled:me,streamClosing:he,streamConnecting:ye,streamError:be,unknownOption:ke,wrongOptionType:Ee,wrongOptionTypeBoolean:we,optionBelowMinimum:De,debugPolling:Se,debugStreamPing:Oe,debugStreamPut:Pe,debugStreamPatch:Ue,debugStreamPatchIgnored:Ie,debugStreamDelete:je,debugStreamDeleteIgnored:Re,debugEnqueueingEvent:Te,debugPostingEvents:Ne,debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"}});function Ce(e){var n={},t={};return n.on=function(e,n,r){t[e]=t[e]||[],t[e]=t[e].concat({handler:n,context:r})},n.off=function(e,n,r){if(t[e])for(var i=0;i<t[e].length;i++)t[e][i].handler===n&&t[e][i].context===r&&(t[e]=t[e].slice(0,i).concat(t[e].slice(i+1)))},n.emit=function(e){if(t[e])for(var n=0;n<t[e].length;n++)t[e][n].handler.apply(t[e][n].context,Array.prototype.slice.call(arguments,1))},n.getEvents=function(){return Object.keys(t)},n.getEventListenerCount=function(e){return t[e]?t[e].length:0},n.maybeReportError=function(n){n&&(t["error"]?this.emit("error",n):(e||console).error(n.message))},n}function Le(e,n,t,r,i){var o={};function a(){var e="",i=r.getUser();return i&&(e=t||S(JSON.stringify(i))),"ld:"+n+":"+e}return o.loadFlags=function(){return e.get(a()).then((function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var t=n.$schema;void 0===t||t<1?n=R(n):delete n.$schema}return n}catch(e){return o.clearFlags().then((function(){return Promise.reject(e)}))}})).catch((function(e){return i.warn("localStorage is unavailable"),Promise.reject(e)}))},o.saveFlags=function(n){var t=L({},n,{$schema:1});return e.set(a(),JSON.stringify(t)).catch((function(e){return i.warn("localStorage is unavailable"),Promise.reject(e)}))},o.clearFlags=function(){return e.clear(a()).catch((function(e){return i.warn("localStorage is unavailable"),Promise.reject(e)}))},o}function Ae(e,n,t,r){var i,o=n.streamUrl,a=n.logger,u={},s=o+"/eval/"+t,c=n.useReport,l=n.evaluationReasons,f=n.streamReconnectDelay,v=C(e,n),d=!1,g=null,p=null,m=null,h=null,y=null;function b(e){d||(a.warn(be(e,f)),d=!0),D(!1),w(),k(f)}function k(e){p||(e?p=setTimeout(E,e):E())}function E(){var n;p=null;var r="",u={headers:v};if(e.eventSourceFactory){for(var f in null!=h&&(r="h="+h),c?e.eventSourceAllowsReport?(n=s,u.method="REPORT",u.headers["Content-Type"]="application/json",u.body=JSON.stringify(m)):(n=o+"/ping/"+t,r=""):n=s+"/"+O(JSON.stringify(m)),l&&(r=r+(r?"&":"")+"withReasons=true"),n=n+(r?"?":"")+r,w(),a.info(ye(n)),i=(new Date).getTime(),g=e.eventSourceFactory(n,u),y)y.hasOwnProperty(f)&&g.addEventListener(f,y[f]);g.onerror=b}}function w(){g&&(a.info("Closing stream connection"),g.close(),g=null)}function D(e){i&&r&&r.recordStreamInit(i,!e,(new Date).getTime()-i),i=null}return u.connect=function(e,n,t){m=e,h=n,y={};var r=function(e){y[e]=function(n){d=!1,D(!0),t[e]&&t[e](n)}};for(var i in t||{})r(i);k()},u.disconnect=function(){clearTimeout(p),p=null,w()},u.isConnected=function(){return!!(g&&e.eventSourceIsActive&&e.eventSourceIsActive(g))},u}function xe(e,n,t){var r=n.baseUrl,i=n.useReport,o=n.evaluationReasons,u=n.logger,s={},c={};function f(t,r){if(!e.httpRequest)return new Promise((function(e,n){n(new l(pe()))}));var i=r?"REPORT":"GET",o=C(e,n);r&&(o["Content-Type"]="application/json");var u=c[t];u||(u=function(e){var n,t,r,i,o={addPromise:function(o,a){n=o,t&&t(),t=a,o.then((function(t){n===o&&(r(t),e&&e())}),(function(t){n===o&&(i(t),e&&e())}))}};return o.resultPromise=new Promise((function(e,n){r=e,i=n})),o}((function(){delete c[t]})),c[t]=u);var s=e.httpRequest(i,t,o,r),f=s.promise.then((function(e){if(200===e.status){if(e.header("content-type")&&0===e.header("content-type").lastIndexOf("application/json"))return JSON.parse(e.body);var n=ne(e.header("content-type")||"");return Promise.reject(new l(n))}return Promise.reject(function(e){return 404===e.status?new a(ae()):new l(se(e.statusText||String(e.status)))}(e))}),(function(e){return Promise.reject(new l(ie(e)))}));return u.addPromise(f,(function(){s.cancel&&s.cancel()})),u.resultPromise}return s.fetchJSON=function(e){return f(r+e,null)},s.fetchFlagSettings=function(e,n){var a,s,c,l="";return i?(s=[r,"/sdk/evalx/",t,"/user"].join(""),c=JSON.stringify(e)):(a=O(JSON.stringify(e)),s=[r,"/sdk/evalx/",t,"/users/",a].join("")),n&&(l="h="+n),o&&(l=l+(l?"&":"")+"withReasons=true"),s=s+(l?"?":"")+l,u.debug(Se(s)),f(s,c)},s}function Ve(e,n){var t={};return t.validateUser=function(t){if(!t)return Promise.reject(new u(ce()));var r=P(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get("ld:$anonUserId").catch((function(){return null})):Promise.resolve(null)).then((function(t){if(t)return r.key=t,r;var i=$();return r.key=i,function(t){return e?e.set("ld:$anonUserId",t).catch((function(){n.warn("localStorage is unavailable, so anonymous user ID cannot be cached")})):Promise.resolve()}(i).then((function(){return r}))})):Promise.reject(new u(le()))},t}var qe={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},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"}};function _e(n,t,r,i){var o=L({logger:{default:i}},qe,r),a={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){I((function(){t&&t.maybeReportError(new c(e))}))}var s=L({},n||{});return function(e){var n=e;Object.keys(a).forEach((function(e){if(void 0!==n[e]){var t=a[e];i&&i.warn(de(e,t)),t&&(void 0===n[t]&&(n[t]=n[e]),delete n[e])}}))}(s),s=function(n){var t=L({},n),r=function(n){if(null===n)return"any";if(void 0!==n){if(Array.isArray(n))return"array";var t=e(n);return"boolean"===t||"string"===t||"number"===t||"function"===t?t:"object"}};return Object.keys(n).forEach((function(e){var i=n[e];if(null!=i){var a=o[e];if(void 0===a)u(ke(e));else{var s=a.type||r(a.default);if("any"!==s){var c=s.split("|"),l=r(i);c.indexOf(l)<0?"boolean"===s?(t[e]=!!i,u(we(e,l))):(u(Ee(e,s,l)),t[e]=a.default):"number"===l&&void 0!==a.minimum&&i<a.minimum&&(u(De(e,i,a.minimum)),t[e]=a.minimum)}}}})),t}(s=function(e){var n=L({},e);return Object.keys(o).forEach((function(e){void 0!==n[e]&&null!==n[e]||(n[e]=o[e]&&o[e].default)})),n}(s))}var Je=Object.freeze({__proto__:null,baseOptionDefs:qe,validate:_e}).baseOptionDefs;var ze=function(e){var n={diagnosticId:$()};return e&&(n.sdkKeySuffix=e.length>6?e.substring(e.length-6):e),n},Me=function(e){var n,t,r,i;function o(e){n=e,t=0,r=0,i=[]}return o(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:i}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,i=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};i.push(r)},reset:o}},Be=function(e,n,t,i,o,a){var u,s,c=!!e.diagnosticUseCombinedEvent,l="ld:"+i+":$diagnostics",f=o.eventsUrl+"/events/diagnostic/"+i,v=o.diagnosticRecordingInterval,d=n,g=!!o.streaming,p={};function m(){return{sdk:b(),configuration:(n={customBaseURI:o.baseUrl!==Je.baseUrl.default,customStreamURI:o.streamUrl!==Je.streamUrl.default,customEventsURI:o.eventsUrl!==Je.eventsUrl.default,eventsCapacity:o.eventCapacity,eventsFlushIntervalMillis:o.flushInterval,reconnectTimeMillis:o.streamReconnectDelay,streamingDisabled:!g,allAttributesPrivate:!!o.allAttributesPrivate,inlineUsersInEvents:!!o.inlineUsersInEvents,diagnosticRecordingIntervalMillis:o.diagnosticRecordingInterval,usingSecureMode:!!o.hash,bootstrapMode:!!o.bootstrap,fetchGoalsDisabled:!o.fetchGoals,allowFrequentDuplicateEvents:!!o.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!o.sendEventsOnlyForVariation},n),platform:e.diagnosticPlatformData};var n}function h(e){o.logger&&o.logger.debug(Fe.debugPostingDiagnosticEvent(e)),t.sendEvents(e,f,!0).then((function(){})).catch((function(){}))}function y(){var n,t;h((n=(new Date).getTime(),t=r({kind:c?"diagnostic-combined":"diagnostic",id:a,creationDate:n},d.getProps()),c&&(t=r({},t,{},m())),d.reset(n),t)),s=setTimeout(y,v),u=(new Date).getTime(),c&&function(){if(e.localStorage){var n=r({},d.getProps());e.localStorage.set(l,JSON.stringify(n),(function(){}))}}()}function b(){var n=r({},e.diagnosticSdkData);return o.wrapperName&&(n.wrapperName=o.wrapperName),o.wrapperVersion&&(n.wrapperVersion=o.wrapperVersion),n}return p.start=function(){c?function(n){if(!e.localStorage)return n(!1);e.localStorage.get(l).then((function(e){if(e)try{var t=JSON.parse(e);d.setProps(t),u=t.dataSinceDate}catch(e){}n(!0)})).catch((function(){n(!1)}))}((function(e){if(e){var n=(u||0)+v,t=(new Date).getTime();t>=n?y():s=setTimeout(y,n-t)}else 0===Math.floor(4*Math.random())?y():s=setTimeout(y,v)})):(h(r({kind:"diagnostic-init",id:a,creationDate:d.getProps().dataSinceDate},m())),s=setTimeout(y,v))},p.stop=function(){s&&clearTimeout(s)},p.setStreaming=function(e){g=e},p};function Ke(e,n){var t,r=["debug","info","warn","error"];t=null!=n?""===n?"":n+" ":"LD: ";var i=0;e&&(i="none"===e?100:r.indexOf(e));var o={};function a(e,n,o){if(e>=i){var a=e<r.length?r[e]:"?";n(t+"["+a+"] "+o)}}return o.debug=function(e){return a(0,console.log,e)},o.info=function(e){return a(1,console.info,e)},o.warn=function(e){return a(2,console.warn,e)},o.error=function(e){return a(3,console.error,e)},o}function $e(n,t,i,u,c){var v=function(){if(i&&i.logger)return i.logger;return c&&c.logger&&c.logger.default||Ke("warn")}(),d=Ce(v),g=_e(i,d,c,v),p=g.sendEvents,m=n,h=g.hash,y=G(u,m,g),b=g.sendEvents&&!g.diagnosticOptOut,k=b?ze(m):null,E=b?Me((new Date).getTime()):null,w=b?Be(u,E,y,m,g,k):null;w&&w.start();var D,S,O,R,N=Ae(u,g,m,E),F=g.eventProcessor||function(e,n,t){var r,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,u=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,s={},c=u||G(e,t,n),l=n.eventsUrl+"/events/bulk/"+t,v=H(),d=X(n),g=n.inlineUsersInEvents,p=n.samplingInterval,m=n.eventCapacity,h=n.flushInterval,y=n.logger,b=[],k=0,E=!1,w=!1;function D(){return 0===p||0===Math.floor(Math.random()*p)}function S(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>k&&e.debugEventsUntilDate>(new Date).getTime())}function O(e){var n=L({},e);return g||"identify"===e.kind?n.user=d.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}function P(e){b.length<m?(b.push(e),w=!1):(w||(w=!0,y.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")),i&&i.incrementDroppedEvents())}return s.enqueue=function(e){if(!E){var n=!1,t=!1;if(v.summarizeEvent(e),"feature"===e.kind?D()&&(n=!!e.trackEvents,t=S(e)):n=D(),n&&P(O(e)),t){var r=L({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,P(r)}}},s.flush=function(){if(E)return Promise.resolve();var e=b,n=v.getSummary();return v.clearSummary(),n&&(n.kind="summary",e.push(n)),i&&i.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(b=[],y.debug(Ne(e.length)),c.sendEvents(e,l).then((function(e){e&&(e.serverTime&&(k=e.serverTime),f(e.status)||(E=!0),e.status>=400&&I((function(){a.maybeReportError(new o(ge(e.status,"event posting","some events were dropped")))})))})))},s.start=function(){r=setTimeout((function e(){s.flush(),r=setTimeout(e,h)}),h)},s.stop=function(){clearTimeout(r)},s}(u,g,m,E,d,y),C=xe(u,g,m),x={},V={},q=g.streaming,_=!1,J=!1,z=!0,M=g.stateProvider,B=function(e,n){var t,r={};return r.setUser=function(e){(t=A(e))&&n&&n(P(t))},r.getUser=function(){return t?P(t):null},e&&r.setUser(e),r}(null,(function(e){if(M)return;e&&$({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})})),K=Ve(u.localStorage,v);function $(e){m&&(M&&M.enqueueEvent&&M.enqueueEvent(e)||(e.user?(z=!1,!p||J||u.isDoNotTrack()||(v.debug(Te(e.kind)),F.enqueue(e))):z&&(v.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"),z=!1)))}function W(e,n,t,r){var i=B.getUser(),o=new Date,a=n?n.value:null;if(!g.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(i&&i.key?i.key:"")+e,s=x[u];if(s&&o-s<3e5)return;x[u]=o}var c={kind:"feature",key:e,user:i,value:a,variation:n?n.variationIndex:null,default:t,creationDate:o.getTime()},l=V[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),$(c)}function Q(e,n,t,r){var i;if(V&&V.hasOwnProperty(e)&&V[e]&&!V[e].deleted){var o=V[e];i=Y(o),null!==o.value&&void 0!==o.value||(i.value=n)}else i={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&W(e,i,n,r),i}function Y(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function Z(){S=!0,B.getUser()&&N.connect(B.getUser(),h,{ping:function(){v.debug("received ping message from stream"),C.fetchFlagSettings(B.getUser(),h).then((function(e){return ne(e||{})})).catch((function(e){d.maybeReportError(new l(se(e)))}))},put:function(e){var n=JSON.parse(e.data);v.debug("received streaming update for all flags"),ne(n)},patch:function(e){var n=JSON.parse(e.data),t=V[n.key];if(!t||!t.version||!n.version||t.version<n.version){v.debug(Ue(n.key));var r={},i=L({},n);delete i.key,V[n.key]=i;var o=Y(i);r[n.key]=t?{previous:t.value,current:o}:{current:o},te(r)}else v.debug(Ie(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!V[n.key]||V[n.key].version<n.version){v.debug(je(n.key));var t={};V[n.key]&&!V[n.key].deleted&&(t[n.key]={previous:V[n.key].value}),V[n.key]={version:n.version,deleted:!0},te(t)}else v.debug(Re(n.key))}})}function ee(){S&&(N.disconnect(),S=!1)}function ne(e){var n={};if(!e)return Promise.resolve();for(var t in V)V.hasOwnProperty(t)&&V[t]&&(e[t]&&!U(e[t].value,V[t].value)?n[t]={previous:V[t].value,current:Y(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:V[t].value}));for(var i in e)e.hasOwnProperty(i)&&e[i]&&(!V[i]||V[i].deleted)&&(n[i]={current:Y(e[i])});return V=r({},e),te(n).catch((function(){}))}function te(e){var n=Object.keys(e);if(n.length>0){var t={};n.forEach((function(n){var r=e[n].current,i=r?r.value:void 0,o=e[n].previous;d.emit("change:"+n,i,o),t[n]=r?{current:i,previous:o}:{previous:o}})),d.emit("change",t),d.emit("internal-change",V),g.sendEventsOnlyForVariation||M||n.forEach((function(n){W(n,e[n].current)}))}return D&&R?R.saveFlags(V).catch((function(){return null})):Promise.resolve()}function re(){var e=q||O&&void 0===q;e&&!S?Z():!e&&S&&ee(),w&&w.setStreaming(e)}function ie(e){return"change"===e||"change:"===e.substr(0,"change".length+1)}u.localStorage&&(R=new Le(u.localStorage,m,h,B,v));var ae=new Promise((function(e){var n=d.on("ready",(function(){d.off("ready",n),e()}))})),ce=new Promise((function(e,n){var t=d.on("initialized",(function(){d.off("initialized",t),e()})),r=d.on("failed",(function(e){d.off("failed",r),n(e)}))}));if("string"==typeof g.bootstrap&&"LOCALSTORAGE"===g.bootstrap.toUpperCase()&&(R?D=!0:v.warn("localStorage is unavailable")),"object"===e(g.bootstrap)&&(V=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&v.warn(fe()),!1===e.$valid&&v.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var r={};return n.forEach((function(n){if("$flagsState"!==n&&"$valid"!==n){var i={value:e[n]};t&&t[n]?i=L(i,t[n]):i.version=0,r[n]=i}})),r}(g.bootstrap)),M){var le=M.getInitialState();le?ve(le):M.on("init",ve),M.on("update",(function(e){e.user&&B.setUser(e.user);e.flags&&ne(e.flags)}))}else(function(){if(!n)return Promise.reject(new a(ue()));return K.validateUser(t).then((function(n){return B.setUser(n),"object"===e(g.bootstrap)?de():D?R.loadFlags().catch((function(){return null})).then((function(e){return null==e?(V={},C.fetchFlagSettings(B.getUser(),h).then((function(e){return ne(e||{})})).then(de).catch((function(e){pe(new l(se(e)))}))):(V=e,I(de),C.fetchFlagSettings(B.getUser(),h).then((function(e){return ne(e)})).catch((function(e){return d.maybeReportError(e)})))})):C.fetchFlagSettings(B.getUser(),h).then((function(e){V=e||{},de()})).catch((function(e){V={},pe(e)}))}))})().catch((function(e){return d.maybeReportError(e)}));function ve(e){m=e.environment,B.setUser(e.user),V=r({},e.flags),I(de)}function de(){v.info("LaunchDarkly client initialized"),_=!0,re(),d.emit("ready"),d.emit("initialized")}function pe(e){d.maybeReportError(e),d.emit("failed",e),d.emit("ready")}return{client:{waitForInitialization:function(){return ce},waitUntilReady:function(){return ae},identify:function(e,n,t){return J?j(Promise.resolve({}),t):M?(v.warn("identify() has no effect here; it must be called on the main client instance"),j(Promise.resolve(T(V)),t)):j((D&&R?R.clearFlags():Promise.resolve()).then((function(){return K.validateUser(e)})).then((function(e){return C.fetchFlagSettings(e,n).then((function(t){var r=T(t);return B.setUser(e),h=n,t?ne(t).then((function(){return r})):r}))})).then((function(e){return S&&Z(),e})).catch((function(e){return d.maybeReportError(e),Promise.reject(e)})),t)},getUser:function(){return B.getUser()},variation:function(e,n){return Q(e,n,!0,!1).value},variationDetail:function(e,n){return Q(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){u.customEventFilter&&!u.customEventFilter(e)&&v.warn(oe(e));var r={kind:"custom",key:e,user:B.getUser(),url:u.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),$(r)}else d.maybeReportError(new s(oe(e)))},on:function(e,n,t){ie(e)?(O=!0,_&&re(),d.on(e,n,t)):d.on.apply(d,arguments)},off:function(e){if(d.off.apply(d,arguments),ie(e)){var n=!1;d.getEvents().forEach((function(e){ie(e)&&d.getEventListenerCount(e)>0&&(n=!0)})),n||(O=!1,S&&void 0===q&&ee())}},setStreaming:function(e){var n=null===e?void 0:e;n!==q&&(q=n,re())},flush:function(e){return j(p?F.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!V)return e;for(var n in V)V.hasOwnProperty(n)&&(e[n]=Q(n,null,!g.sendEventsOnlyForVariation).value);return e},close:function(e){if(J)return j(Promise.resolve(),e);var n=function(){J=!0,V={}};return j(Promise.resolve().then((function(){if(ee(),w&&w.stop(),p)return F.stop(),F.flush()})).then(n).catch(n),e)}},options:g,emitter:d,ident:B,logger:v,requestor:C,start:function(){p&&(w&&w.start(),F.start())},enqueueEvent:$,getFlagsInternal:function(){return V},getEnvironmentId:function(){return m},internalChangeEventName:"internal-change"}}var Ge="3.2.2";export{Ke as createConsoleLogger,v as errors,$e as initialize,Fe as messages,x as utils,Ge as version}; | ||
function e(n){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(n)}function n(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function t(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function r(e){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?t(i,!0).forEach((function(t){n(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):t(i).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(i,n))}))}return e}function i(e){function n(e,n){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=n}return n.prototype=new Error,n.prototype.name=e,n.prototype.constructor=n,n}var o=i("LaunchDarklyUnexpectedResponseError"),a=i("LaunchDarklyInvalidEnvironmentIdError"),u=i("LaunchDarklyInvalidUserError"),s=i("LaunchDarklyInvalidEventKeyError"),c=i("LaunchDarklyInvalidArgumentError"),l=i("LaunchDarklyFlagFetchError");function f(e){return!(e>=400&&e<500)||(400===e||408===e||429===e)}for(var v=Object.freeze({__proto__:null,LDUnexpectedResponseError:o,LDInvalidEnvironmentIdError:a,LDInvalidUserError:u,LDInvalidEventKeyError:s,LDInvalidArgumentError:c,LDFlagFetchError:l,isHttpErrorRecoverable:f}),d=function(e){for(var n,t=e.length,r=t%3,i=[],o=0,a=t-r;o<a;o+=16383)i.push(b(e,o,o+16383>a?a:o+16383));1===r?(n=e[t-1],i.push(g[n>>2]+g[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],i.push(g[n>>10]+g[n>>4&63]+g[n<<2&63]+"="));return i.join("")},g=[],p=[],m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,y=m.length;h<y;++h)g[h]=m[h],p[m.charCodeAt(h)]=h;function b(e,n,t){for(var r,i,o=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(g[(i=r)>>18&63]+g[i>>12&63]+g[i>>6&63]+g[63&i]);return o.join("")}p["-".charCodeAt(0)]=62,p["_".charCodeAt(0)]=63;var k=Array.isArray,E=Object.keys,w=Object.prototype.hasOwnProperty,D=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function S(e){var n=unescape(encodeURIComponent(e));return d(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function P(e){return S(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function O(e){return JSON.parse(JSON.stringify(e))}function U(e,n){return function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,i,o,a=k(n),u=k(t);if(a&&u){if((i=n.length)!=t.length)return!1;for(r=i;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var s=n instanceof Date,c=t instanceof Date;if(s!=c)return!1;if(s&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var v=E(n);if((i=v.length)!==E(t).length)return!1;for(r=i;0!=r--;)if(!w.call(t,v[r]))return!1;for(r=i;0!=r--;)if(!e(n[o=v[r]],t[o]))return!1;return!0}return n!=n&&t!=t}(e,n)}function I(e){setTimeout(e,0)}function j(e,n){var t=e.then((function(e){return n&&setTimeout((function(){n(null,e)}),0),e}),(function(e){if(!n)return Promise.reject(e);setTimeout((function(){n(e,null)}),0)}));return n?void 0:t}function R(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function T(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function N(e,n){for(var t,r=n.slice(0),i=[],o=e;r.length>0;){for(t=[];o>0;){var a=r.shift();if(!a)break;(o-=P(JSON.stringify(a)).length)<0&&t.length>0?r.unshift(a):t.push(a)}o=e,i.push(t)}return i}function F(e){var n=e.version||"3.2.3";return e.userAgent+"/"+n}function C(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":F(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function L(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce((function(e,n){return r({},e,{},n)}),{})}function A(e){if(!e)return e;var n;for(var t in D){var i=D[t],o=e[i];void 0!==o&&"string"!=typeof o&&((n=n||r({},e))[i]=String(o))}return n||e}var x=Object.freeze({__proto__:null,btoa:S,base64URLEncode:P,clone:O,deepEquals:U,onNextTick:I,wrapPromiseCallback:j,transformValuesToVersionedValues:R,transformVersionedValuesToValues:T,chunkUserEventsForUrl:N,getLDUserAgentString:F,getLDHeaders:C,extend:L,sanitizeUser:A});for(var V=function(e,n){return e(n={exports:{}},n.exports),n.exports}((function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}})),q=[],_=0;_<256;++_)q[_]=(_+256).toString(16).substr(1);var J,z,M=function(e,n){var t=n||0,r=q;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")},B=0,K=0;var $=function(e,n,t){var r=n&&t||0,i=n||[],o=(e=e||{}).node||J,a=void 0!==e.clockseq?e.clockseq:z;if(null==o||null==a){var u=V();null==o&&(o=J=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=z=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:K+1,l=s-B+(c-K)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>B)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");B=s,K=c,z=a;var f=(1e4*(268435455&(s+=122192928e5))+c)%4294967296;i[r++]=f>>>24&255,i[r++]=f>>>16&255,i[r++]=f>>>8&255,i[r++]=255&f;var v=s/4294967296*1e4&268435455;i[r++]=v>>>8&255,i[r++]=255&v,i[r++]=v>>>24&15|16,i[r++]=v>>>16&255,i[r++]=a>>>8|128,i[r++]=255&a;for(var d=0;d<6;++d)i[r+d]=o[d];return n||M(i)};function G(e,n,t){var r="/a/"+n+".gif",i=L({"Content-Type":"application/json"},C(e,t)),o=e.httpFallbackPing,a={};return a.sendChunk=function(n,t,a,u){var s=JSON.stringify(n),c=a?null:$();return u?function n(r){var o=a?i:L({},i,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":c});return e.httpRequest("POST",t,o,s).promise.then((function(e){if(e)return e.status>=400&&f(e.status)&&r?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)})).catch((function(){return r?n(!1):Promise.reject()}))}(!0).catch((function(){})):(o&&o(t+r+"?d="+P(s)),Promise.resolve())},a.sendEvents=function(n,t,r){if(!e.httpRequest)return Promise.resolve();var i,o=e.httpAllowsPost();i=o?[n]:N(2e3-t.length,n);for(var u=[],s=0;s<i.length;s++)u.push(a.sendChunk(i[s],t,r,o));return Promise.all(u)},a}function H(){var e={},n=0,t=0,r={};return e.summarizeEvent=function(e){if("feature"===e.kind){var i=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),o=r[i];o?o.count=o.count+1:r[i]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===n||e.creationDate<n)&&(n=e.creationDate),e.creationDate>t&&(t=e.creationDate)}},e.getSummary=function(){var e={},i=!0;for(var o in r){var a=r[o],u=e[a.key];u||(u={default:a.default,counters:[]},e[a.key]=u);var s={value:a.value,count:a.count};void 0!==a.variation&&null!==a.variation&&(s.variation=a.variation),a.version?s.version=a.version:s.unknown=!0,u.counters.push(s),i=!1}return i?null:{startDate:n,endDate:t,features:e}},e.clearSummary=function(){n=0,t=0,r={}},e}function X(e){var n={},t=e.allAttributesPrivate,r=e.privateAttributeNames||[],i={key:!0,custom:!0,anonymous:!0},o={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;var n=e.privateAttributeNames||[],a=function(e,o){return Object.keys(e).reduce((function(a,u){var s=a;return o(u)&&(!function(e){return!i[e]&&(t||-1!==n.indexOf(e)||-1!==r.indexOf(e))}(u)?s[0][u]=e[u]:s[1][u]=!0),s}),[{},{}])},u=a(e,(function(e){return o[e]})),s=u[0],c=u[1];if(e.custom){var l=a(e.custom,(function(){return!0}));s.custom=l[0],c=L({},c,l[1])}var f=Object.keys(c);return f.length&&(f.sort(),s.privateAttrs=f),s},n}function W(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var Q=function(){return"LaunchDarkly client initialized"},Y=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",Z=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},ee=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"},ne=function(e){return'Expected application/json content type but got "'+e+'"'},te=function(){return"localStorage is unavailable"},re=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},ie=function(e){return"network error"+(e?" ("+e+")":"")},oe=function(e){return'Custom event "'+e+'" does not exist'},ae=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+Y},ue=function(){return"No environment/client-side ID was specified."+Y},se=function(e){return"Error fetching flag settings: "+W(e)},ce=function(){return"No user specified."+Y},le=function(){return"Invalid user specified."+Y},fe=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+Y},ve=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},de=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},ge=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(f(e)?t:"giving up permanently")},pe=function(){return"Cannot make HTTP requests in this environment."+Y},me=function(){return"identify() has no effect here; it must be called on the main client instance"},he=function(){return"Closing stream connection"},ye=function(e){return"Opening stream connection to "+e},be=function(e,n){return"Error on stream connection: "+W(e)+", will continue retrying every "+n+" milliseconds."},ke=function(e){return'Ignoring unknown config option "'+e+'"'},Ee=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},we=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},De=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},Se=function(e){return"polling for feature flags at "+e},Pe=function(){return"received ping message from stream"},Oe=function(){return"received streaming update for all flags"},Ue=function(e){return'received streaming update for flag "'+e+'"'},Ie=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},je=function(e){return'received streaming deletion for flag "'+e+'"'},Re=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},Te=function(e){return'enqueueing "'+e+'" event'},Ne=function(e){return"sending "+e+" events"},Fe=Object.freeze({__proto__:null,clientInitialized:Q,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:Z,eventWithoutUser:ee,invalidContentType:ne,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:te,localStorageUnavailableForUserId:re,networkError:ie,unknownCustomEventKey:oe,environmentNotFound:ae,environmentNotSpecified:ue,errorFetchingFlags:se,userNotSpecified:ce,invalidUser:le,bootstrapOldFormat:fe,bootstrapInvalid:ve,deprecated:de,httpErrorMessage:ge,httpUnavailable:pe,identifyDisabled:me,streamClosing:he,streamConnecting:ye,streamError:be,unknownOption:ke,wrongOptionType:Ee,wrongOptionTypeBoolean:we,optionBelowMinimum:De,debugPolling:Se,debugStreamPing:Pe,debugStreamPut:Oe,debugStreamPatch:Ue,debugStreamPatchIgnored:Ie,debugStreamDelete:je,debugStreamDeleteIgnored:Re,debugEnqueueingEvent:Te,debugPostingEvents:Ne,debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"}});function Ce(e){var n={},t={};return n.on=function(e,n,r){t[e]=t[e]||[],t[e]=t[e].concat({handler:n,context:r})},n.off=function(e,n,r){if(t[e])for(var i=0;i<t[e].length;i++)t[e][i].handler===n&&t[e][i].context===r&&(t[e]=t[e].slice(0,i).concat(t[e].slice(i+1)))},n.emit=function(e){if(t[e])for(var n=t[e].slice(0),r=0;r<n.length;r++)n[r].handler.apply(n[r].context,Array.prototype.slice.call(arguments,1))},n.getEvents=function(){return Object.keys(t)},n.getEventListenerCount=function(e){return t[e]?t[e].length:0},n.maybeReportError=function(n){n&&(t["error"]?this.emit("error",n):(e||console).error(n.message))},n}var Le=function(e){var n=!1,t=!1,r=null,i=null,o=new Promise((function(n){e.on("ready",(function t(){e.off("ready",t),n()}))})).catch((function(){}));return{getInitializationPromise:function(){return i||(n?Promise.resolve():t?Promise.reject(r):i=new Promise((function(n,t){e.on("initialized",(function t(){e.off("initialized",t),n()})),e.on("failed",(function n(r){e.off("failed",n),t(r)}))})))},getReadyPromise:function(){return o},signalSuccess:function(){n||t||(n=!0,e.emit("initialized"),e.emit("ready"))},signalFailure:function(i){n||t||(t=!0,r=i,e.emit("failed",i),e.emit("ready")),e.maybeReportError(i)}}};function Ae(e,n,t,r,i){var o={};function a(){var e="",i=r.getUser();return i&&(e=t||S(JSON.stringify(i))),"ld:"+n+":"+e}return o.loadFlags=function(){return e.get(a()).then((function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var t=n.$schema;void 0===t||t<1?n=R(n):delete n.$schema}return n}catch(e){return o.clearFlags().then((function(){return Promise.reject(e)}))}})).catch((function(e){return i.warn("localStorage is unavailable"),Promise.reject(e)}))},o.saveFlags=function(n){var t=L({},n,{$schema:1});return e.set(a(),JSON.stringify(t)).catch((function(e){return i.warn("localStorage is unavailable"),Promise.reject(e)}))},o.clearFlags=function(){return e.clear(a()).catch((function(e){return i.warn("localStorage is unavailable"),Promise.reject(e)}))},o}function xe(e,n,t,r){var i,o=n.streamUrl,a=n.logger,u={},s=o+"/eval/"+t,c=n.useReport,l=n.evaluationReasons,f=n.streamReconnectDelay,v=C(e,n),d=!1,g=null,p=null,m=null,h=null,y=null;function b(e){d||(a.warn(be(e,f)),d=!0),D(!1),w(),k(f)}function k(e){p||(e?p=setTimeout(E,e):E())}function E(){var n;p=null;var r="",u={headers:v};if(e.eventSourceFactory){for(var f in null!=h&&(r="h="+h),c?e.eventSourceAllowsReport?(n=s,u.method="REPORT",u.headers["Content-Type"]="application/json",u.body=JSON.stringify(m)):(n=o+"/ping/"+t,r=""):n=s+"/"+P(JSON.stringify(m)),l&&(r=r+(r?"&":"")+"withReasons=true"),n=n+(r?"?":"")+r,w(),a.info(ye(n)),i=(new Date).getTime(),g=e.eventSourceFactory(n,u),y)y.hasOwnProperty(f)&&g.addEventListener(f,y[f]);g.onerror=b}}function w(){g&&(a.info("Closing stream connection"),g.close(),g=null)}function D(e){i&&r&&r.recordStreamInit(i,!e,(new Date).getTime()-i),i=null}return u.connect=function(e,n,t){m=e,h=n,y={};var r=function(e){y[e]=function(n){d=!1,D(!0),t[e]&&t[e](n)}};for(var i in t||{})r(i);k()},u.disconnect=function(){clearTimeout(p),p=null,w()},u.isConnected=function(){return!!(g&&e.eventSourceIsActive&&e.eventSourceIsActive(g))},u}function Ve(e,n,t){var r=n.baseUrl,i=n.useReport,o=n.evaluationReasons,u=n.logger,s={},c={};function f(t,r){if(!e.httpRequest)return new Promise((function(e,n){n(new l(pe()))}));var i=r?"REPORT":"GET",o=C(e,n);r&&(o["Content-Type"]="application/json");var u=c[t];u||(u=function(e){var n,t,r,i,o={addPromise:function(o,a){n=o,t&&t(),t=a,o.then((function(t){n===o&&(r(t),e&&e())}),(function(t){n===o&&(i(t),e&&e())}))}};return o.resultPromise=new Promise((function(e,n){r=e,i=n})),o}((function(){delete c[t]})),c[t]=u);var s=e.httpRequest(i,t,o,r),f=s.promise.then((function(e){if(200===e.status){if(e.header("content-type")&&0===e.header("content-type").lastIndexOf("application/json"))return JSON.parse(e.body);var n=ne(e.header("content-type")||"");return Promise.reject(new l(n))}return Promise.reject(function(e){return 404===e.status?new a(ae()):new l(se(e.statusText||String(e.status)))}(e))}),(function(e){return Promise.reject(new l(ie(e)))}));return u.addPromise(f,(function(){s.cancel&&s.cancel()})),u.resultPromise}return s.fetchJSON=function(e){return f(r+e,null)},s.fetchFlagSettings=function(e,n){var a,s,c,l="";return i?(s=[r,"/sdk/evalx/",t,"/user"].join(""),c=JSON.stringify(e)):(a=P(JSON.stringify(e)),s=[r,"/sdk/evalx/",t,"/users/",a].join("")),n&&(l="h="+n),o&&(l=l+(l?"&":"")+"withReasons=true"),s=s+(l?"?":"")+l,u.debug(Se(s)),f(s,c)},s}function qe(e,n){var t={};return t.validateUser=function(t){if(!t)return Promise.reject(new u(ce()));var r=O(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get("ld:$anonUserId").catch((function(){return null})):Promise.resolve(null)).then((function(t){if(t)return r.key=t,r;var i=$();return r.key=i,function(t){return e?e.set("ld:$anonUserId",t).catch((function(){n.warn("localStorage is unavailable, so anonymous user ID cannot be cached")})):Promise.resolve()}(i).then((function(){return r}))})):Promise.reject(new u(le()))},t}var _e={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},streaming:{type:"boolean"},sendLDHeaders:{default:!0},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"}};function Je(n,t,r,i){var o=L({logger:{default:i}},_e,r),a={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){I((function(){t&&t.maybeReportError(new c(e))}))}var s=L({},n||{});return function(e){var n=e;Object.keys(a).forEach((function(e){if(void 0!==n[e]){var t=a[e];i&&i.warn(de(e,t)),t&&(void 0===n[t]&&(n[t]=n[e]),delete n[e])}}))}(s),s=function(n){var t=L({},n),r=function(n){if(null===n)return"any";if(void 0!==n){if(Array.isArray(n))return"array";var t=e(n);return"boolean"===t||"string"===t||"number"===t||"function"===t?t:"object"}};return Object.keys(n).forEach((function(e){var i=n[e];if(null!=i){var a=o[e];if(void 0===a)u(ke(e));else{var s=a.type||r(a.default);if("any"!==s){var c=s.split("|"),l=r(i);c.indexOf(l)<0?"boolean"===s?(t[e]=!!i,u(we(e,l))):(u(Ee(e,s,l)),t[e]=a.default):"number"===l&&void 0!==a.minimum&&i<a.minimum&&(u(De(e,i,a.minimum)),t[e]=a.minimum)}}}})),t}(s=function(e){var n=L({},e);return Object.keys(o).forEach((function(e){void 0!==n[e]&&null!==n[e]||(n[e]=o[e]&&o[e].default)})),n}(s))}var ze=Object.freeze({__proto__:null,baseOptionDefs:_e,validate:Je}).baseOptionDefs;var Me=function(e){var n={diagnosticId:$()};return e&&(n.sdkKeySuffix=e.length>6?e.substring(e.length-6):e),n},Be=function(e){var n,t,r,i;function o(e){n=e,t=0,r=0,i=[]}return o(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:i}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,i=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};i.push(r)},reset:o}},Ke=function(e,n,t,i,o,a){var u,s,c=!!e.diagnosticUseCombinedEvent,l="ld:"+i+":$diagnostics",f=o.eventsUrl+"/events/diagnostic/"+i,v=o.diagnosticRecordingInterval,d=n,g=!!o.streaming,p={};function m(){return{sdk:b(),configuration:(n={customBaseURI:o.baseUrl!==ze.baseUrl.default,customStreamURI:o.streamUrl!==ze.streamUrl.default,customEventsURI:o.eventsUrl!==ze.eventsUrl.default,eventsCapacity:o.eventCapacity,eventsFlushIntervalMillis:o.flushInterval,reconnectTimeMillis:o.streamReconnectDelay,streamingDisabled:!g,allAttributesPrivate:!!o.allAttributesPrivate,inlineUsersInEvents:!!o.inlineUsersInEvents,diagnosticRecordingIntervalMillis:o.diagnosticRecordingInterval,usingSecureMode:!!o.hash,bootstrapMode:!!o.bootstrap,fetchGoalsDisabled:!o.fetchGoals,allowFrequentDuplicateEvents:!!o.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!o.sendEventsOnlyForVariation},n),platform:e.diagnosticPlatformData};var n}function h(e){o.logger&&o.logger.debug(Fe.debugPostingDiagnosticEvent(e)),t.sendEvents(e,f,!0).then((function(){})).catch((function(){}))}function y(){var n,t;h((n=(new Date).getTime(),t=r({kind:c?"diagnostic-combined":"diagnostic",id:a,creationDate:n},d.getProps()),c&&(t=r({},t,{},m())),d.reset(n),t)),s=setTimeout(y,v),u=(new Date).getTime(),c&&function(){if(e.localStorage){var n=r({},d.getProps());e.localStorage.set(l,JSON.stringify(n),(function(){}))}}()}function b(){var n=r({},e.diagnosticSdkData);return o.wrapperName&&(n.wrapperName=o.wrapperName),o.wrapperVersion&&(n.wrapperVersion=o.wrapperVersion),n}return p.start=function(){c?function(n){if(!e.localStorage)return n(!1);e.localStorage.get(l).then((function(e){if(e)try{var t=JSON.parse(e);d.setProps(t),u=t.dataSinceDate}catch(e){}n(!0)})).catch((function(){n(!1)}))}((function(e){if(e){var n=(u||0)+v,t=(new Date).getTime();t>=n?y():s=setTimeout(y,n-t)}else 0===Math.floor(4*Math.random())?y():s=setTimeout(y,v)})):(h(r({kind:"diagnostic-init",id:a,creationDate:d.getProps().dataSinceDate},m())),s=setTimeout(y,v))},p.stop=function(){s&&clearTimeout(s)},p.setStreaming=function(e){g=e},p};function $e(e,n){var t,r=["debug","info","warn","error"];t=null!=n?""===n?"":n+" ":"LD: ";var i=0;e&&(i="none"===e?100:r.indexOf(e));var o={};function a(e,n,o){if(e>=i){var a=e<r.length?r[e]:"?";n(t+"["+a+"] "+o)}}return o.debug=function(e){return a(0,console.log,e)},o.info=function(e){return a(1,console.info,e)},o.warn=function(e){return a(2,console.warn,e)},o.error=function(e){return a(3,console.error,e)},o}function Ge(n,t,i,u,c){var v=function(){if(i&&i.logger)return i.logger;return c&&c.logger&&c.logger.default||$e("warn")}(),d=Ce(v),g=Le(d),p=Je(i,d,c,v),m=p.sendEvents,h=n,y=p.hash,b=G(u,h,p),k=p.sendEvents&&!p.diagnosticOptOut,E=k?Me(h):null,w=k?Be((new Date).getTime()):null,D=k?Ke(u,w,b,h,p,E):null;D&&D.start();var S,P,R,N,F=xe(u,p,h,w),C=p.eventProcessor||function(e,n,t){var r,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,u=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,s={},c=u||G(e,t,n),l=n.eventsUrl+"/events/bulk/"+t,v=H(),d=X(n),g=n.inlineUsersInEvents,p=n.samplingInterval,m=n.eventCapacity,h=n.flushInterval,y=n.logger,b=[],k=0,E=!1,w=!1;function D(){return 0===p||0===Math.floor(Math.random()*p)}function S(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>k&&e.debugEventsUntilDate>(new Date).getTime())}function P(e){var n=L({},e);return g||"identify"===e.kind?n.user=d.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}function O(e){b.length<m?(b.push(e),w=!1):(w||(w=!0,y.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")),i&&i.incrementDroppedEvents())}return s.enqueue=function(e){if(!E){var n=!1,t=!1;if(v.summarizeEvent(e),"feature"===e.kind?D()&&(n=!!e.trackEvents,t=S(e)):n=D(),n&&O(P(e)),t){var r=L({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,O(r)}}},s.flush=function(){if(E)return Promise.resolve();var e=b,n=v.getSummary();return v.clearSummary(),n&&(n.kind="summary",e.push(n)),i&&i.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(b=[],y.debug(Ne(e.length)),c.sendEvents(e,l).then((function(e){e&&(e.serverTime&&(k=e.serverTime),f(e.status)||(E=!0),e.status>=400&&I((function(){a.maybeReportError(new o(ge(e.status,"event posting","some events were dropped")))})))})))},s.start=function(){r=setTimeout((function e(){s.flush(),r=setTimeout(e,h)}),h)},s.stop=function(){clearTimeout(r)},s}(u,p,h,w,d,b),x=Ve(u,p,h),V={},q={},_=p.streaming,J=!1,z=!1,M=!0,B=p.stateProvider,K=function(e,n){var t,r={};return r.setUser=function(e){(t=A(e))&&n&&n(O(t))},r.getUser=function(){return t?O(t):null},e&&r.setUser(e),r}(null,(function(e){if(B)return;e&&W({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})})),$=qe(u.localStorage,v);function W(e){h&&(B&&B.enqueueEvent&&B.enqueueEvent(e)||(e.user?(M=!1,!m||z||u.isDoNotTrack()||(v.debug(Te(e.kind)),C.enqueue(e))):M&&(v.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"),M=!1)))}function Q(e,n,t,r){var i=K.getUser(),o=new Date,a=n?n.value:null;if(!p.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(i&&i.key?i.key:"")+e,s=V[u];if(s&&o-s<3e5)return;V[u]=o}var c={kind:"feature",key:e,user:i,value:a,variation:n?n.variationIndex:null,default:t,creationDate:o.getTime()},l=q[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),W(c)}function Y(e,n,t,r){var i;if(q&&q.hasOwnProperty(e)&&q[e]&&!q[e].deleted){var o=q[e];i=Z(o),null!==o.value&&void 0!==o.value||(i.value=n)}else i={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&Q(e,i,n,r),i}function Z(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function ee(){P=!0,K.getUser()&&F.connect(K.getUser(),y,{ping:function(){v.debug("received ping message from stream"),x.fetchFlagSettings(K.getUser(),y).then((function(e){return te(e||{})})).catch((function(e){d.maybeReportError(new l(se(e)))}))},put:function(e){var n=JSON.parse(e.data);v.debug("received streaming update for all flags"),te(n)},patch:function(e){var n=JSON.parse(e.data),t=q[n.key];if(!t||!t.version||!n.version||t.version<n.version){v.debug(Ue(n.key));var r={},i=L({},n);delete i.key,q[n.key]=i;var o=Z(i);r[n.key]=t?{previous:t.value,current:o}:{current:o},re(r)}else v.debug(Ie(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!q[n.key]||q[n.key].version<n.version){v.debug(je(n.key));var t={};q[n.key]&&!q[n.key].deleted&&(t[n.key]={previous:q[n.key].value}),q[n.key]={version:n.version,deleted:!0},re(t)}else v.debug(Re(n.key))}})}function ne(){P&&(F.disconnect(),P=!1)}function te(e){var n={};if(!e)return Promise.resolve();for(var t in q)q.hasOwnProperty(t)&&q[t]&&(e[t]&&!U(e[t].value,q[t].value)?n[t]={previous:q[t].value,current:Z(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:q[t].value}));for(var i in e)e.hasOwnProperty(i)&&e[i]&&(!q[i]||q[i].deleted)&&(n[i]={current:Z(e[i])});return q=r({},e),re(n).catch((function(){}))}function re(e){var n=Object.keys(e);if(n.length>0){var t={};n.forEach((function(n){var r=e[n].current,i=r?r.value:void 0,o=e[n].previous;d.emit("change:"+n,i,o),t[n]=r?{current:i,previous:o}:{previous:o}})),d.emit("change",t),d.emit("internal-change",q),p.sendEventsOnlyForVariation||B||n.forEach((function(n){Q(n,e[n].current)}))}return S&&N?N.saveFlags(q).catch((function(){return null})):Promise.resolve()}function ie(){var e=_||R&&void 0===_;e&&!P?ee():!e&&P&&ne(),D&&D.setStreaming(e)}function ae(e){return"change"===e||"change:"===e.substr(0,"change".length+1)}if(u.localStorage&&(N=new Ae(u.localStorage,h,y,K,v)),"string"==typeof p.bootstrap&&"LOCALSTORAGE"===p.bootstrap.toUpperCase()&&(N?S=!0:v.warn("localStorage is unavailable")),"object"===e(p.bootstrap)&&(q=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&v.warn(fe()),!1===e.$valid&&v.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var r={};return n.forEach((function(n){if("$flagsState"!==n&&"$valid"!==n){var i={value:e[n]};t&&t[n]?i=L(i,t[n]):i.version=0,r[n]=i}})),r}(p.bootstrap)),B){var ce=B.getInitialState();ce?le(ce):B.on("init",le),B.on("update",(function(e){e.user&&K.setUser(e.user);e.flags&&te(e.flags)}))}else(function(){if(!n)return Promise.reject(new a(ue()));return $.validateUser(t).then((function(n){return K.setUser(n),"object"===e(p.bootstrap)?ve():S?N.loadFlags().catch((function(){return null})).then((function(e){return null==e?(q={},x.fetchFlagSettings(K.getUser(),y).then((function(e){return te(e||{})})).then(ve).catch((function(e){de(new l(se(e)))}))):(q=e,I(ve),x.fetchFlagSettings(K.getUser(),y).then((function(e){return te(e)})).catch((function(e){return d.maybeReportError(e)})))})):x.fetchFlagSettings(K.getUser(),y).then((function(e){q=e||{},ve()})).catch((function(e){q={},de(e)}))}))})().catch(de);function le(e){h=e.environment,K.setUser(e.user),q=r({},e.flags),I(ve)}function ve(){v.info("LaunchDarkly client initialized"),J=!0,ie(),g.signalSuccess()}function de(e){g.signalFailure(e)}return{client:{waitForInitialization:function(){return g.getInitializationPromise()},waitUntilReady:function(){return g.getReadyPromise()},identify:function(e,n,t){return z?j(Promise.resolve({}),t):B?(v.warn("identify() has no effect here; it must be called on the main client instance"),j(Promise.resolve(T(q)),t)):j((S&&N?N.clearFlags():Promise.resolve()).then((function(){return $.validateUser(e)})).then((function(e){return x.fetchFlagSettings(e,n).then((function(t){var r=T(t);return K.setUser(e),y=n,t?te(t).then((function(){return r})):r}))})).then((function(e){return P&&ee(),e})).catch((function(e){return d.maybeReportError(e),Promise.reject(e)})),t)},getUser:function(){return K.getUser()},variation:function(e,n){return Y(e,n,!0,!1).value},variationDetail:function(e,n){return Y(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){u.customEventFilter&&!u.customEventFilter(e)&&v.warn(oe(e));var r={kind:"custom",key:e,user:K.getUser(),url:u.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),W(r)}else d.maybeReportError(new s(oe(e)))},on:function(e,n,t){ae(e)?(R=!0,J&&ie(),d.on(e,n,t)):d.on.apply(d,arguments)},off:function(e){if(d.off.apply(d,arguments),ae(e)){var n=!1;d.getEvents().forEach((function(e){ae(e)&&d.getEventListenerCount(e)>0&&(n=!0)})),n||(R=!1,P&&void 0===_&&ne())}},setStreaming:function(e){var n=null===e?void 0:e;n!==_&&(_=n,ie())},flush:function(e){return j(m?C.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!q)return e;for(var n in q)q.hasOwnProperty(n)&&(e[n]=Y(n,null,!p.sendEventsOnlyForVariation).value);return e},close:function(e){if(z)return j(Promise.resolve(),e);var n=function(){z=!0,q={}};return j(Promise.resolve().then((function(){if(ne(),D&&D.stop(),m)return C.stop(),C.flush()})).then(n).catch(n),e)}},options:p,emitter:d,ident:K,logger:v,requestor:x,start:function(){m&&(D&&D.start(),C.start())},enqueueEvent:W,getFlagsInternal:function(){return q},getEnvironmentId:function(){return h},internalChangeEventName:"internal-change"}}var He="3.2.3";export{$e as createConsoleLogger,v as errors,Ge as initialize,Fe as messages,x as utils,He as version}; | ||
//# sourceMappingURL=ldclient-common.es.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self)["LDClient-Common"]={})}(this,function(e){"use strict";function H(e){return(H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),t.push.apply(t,r)}return t}function X(i){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?n(o,!0).forEach(function(e){var n,t,r;n=i,r=o[t=e],t in n?Object.defineProperty(n,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):n[t]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(o)):n(o).forEach(function(e){Object.defineProperty(i,e,Object.getOwnPropertyDescriptor(o,e))})}return i}function t(e){function n(e,n){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=n}return(n.prototype=new Error).name=e,n.prototype.constructor=n}var O=t("LaunchDarklyUnexpectedResponseError"),W=t("LaunchDarklyInvalidEnvironmentIdError"),o=t("LaunchDarklyInvalidUserError"),Q=t("LaunchDarklyInvalidEventKeyError"),d=t("LaunchDarklyInvalidArgumentError"),Y=t("LaunchDarklyFlagFetchError");function P(e){return!(400<=e&&e<500)||(400===e||408===e||429===e)}for(var r=Object.freeze({__proto__:null,LDUnexpectedResponseError:O,LDInvalidEnvironmentIdError:W,LDInvalidUserError:o,LDInvalidEventKeyError:Q,LDInvalidArgumentError:d,LDFlagFetchError:Y,isHttpErrorRecoverable:P}),i=function(e){for(var n,t=e.length,r=t%3,i=[],o=0,a=t-r;o<a;o+=16383)i.push(f(e,o,a<o+16383?a:o+16383));1==r?(n=e[t-1],i.push(u[n>>2]+u[n<<4&63]+"==")):2==r&&(n=(e[t-2]<<8)+e[t-1],i.push(u[n>>10]+u[n>>4&63]+u[n<<2&63]+"="));return i.join("")},u=[],a=[],s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=0,l=s.length;c<l;++c)u[c]=s[c],a[s.charCodeAt(c)]=c;function f(e,n,t){for(var r,i,o=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(u[(i=r)>>18&63]+u[i>>12&63]+u[i>>6&63]+u[63&i]);return o.join("")}a["-".charCodeAt(0)]=62,a["_".charCodeAt(0)]=63;var g=Array.isArray,p=Object.keys,m=Object.prototype.hasOwnProperty,v=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,i,o,a=g(n),u=g(t);if(a&&u){if((i=n.length)!=t.length)return!1;for(r=i;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var s=n instanceof Date,c=t instanceof Date;if(s!=c)return!1;if(s&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var v=p(n);if((i=v.length)!==p(t).length)return!1;for(r=i;0!=r--;)if(!m.call(t,v[r]))return!1;for(r=i;0!=r--;)if(!e(n[o=v[r]],t[o]))return!1;return!0}return n!=n&&t!=t},h=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function y(e){var n=unescape(encodeURIComponent(e));return i(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function S(e){return y(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function Z(e){return JSON.parse(JSON.stringify(e))}function ee(e,n){return v(e,n)}function ne(e){setTimeout(e,0)}function te(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function b(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function re(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function k(e,n){for(var t,r=n.slice(0),i=[],o=e;0<r.length;){for(t=[];0<o;){var a=r.shift();if(!a)break;(o-=S(JSON.stringify(a)).length)<0&&0<t.length?r.unshift(a):t.push(a)}o=e,i.push(t)}return i}function E(e){var n=e.version||"3.2.2";return e.userAgent+"/"+n}function U(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":E(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function ie(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return X({},e,{},n)},{})}function oe(e){if(!e)return e;var n;for(var t in h){var r=h[t],i=e[r];void 0!==i&&"string"!=typeof i&&((n=n||X({},e))[r]=String(i))}return n||e}var w=Object.freeze({__proto__:null,btoa:y,base64URLEncode:S,clone:Z,deepEquals:ee,onNextTick:ne,wrapPromiseCallback:te,transformValuesToVersionedValues:b,transformVersionedValuesToValues:re,chunkUserEventsForUrl:k,getLDUserAgentString:E,getLDHeaders:U,extend:ie,sanitizeUser:oe});for(var D,I=(function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}(D={exports:{}},D.exports),D.exports),j=[],R=0;R<256;++R)j[R]=(R+256).toString(16).substr(1);var T,N,F=function(e,n){var t=n||0,r=j;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")},C=0,L=0;var A=function(e,n,t){var r=n&&t||0,i=n||[],o=(e=e||{}).node||T,a=void 0!==e.clockseq?e.clockseq:N;if(null==o||null==a){var u=I();null==o&&(o=T=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=N=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:L+1,l=s-C+(c-L)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||C<s)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");C=s,N=a;var f=(1e4*(268435455&(s+=122192928e5))+(L=c))%4294967296;i[r++]=f>>>24&255,i[r++]=f>>>16&255,i[r++]=f>>>8&255,i[r++]=255&f;var v=s/4294967296*1e4&268435455;i[r++]=v>>>8&255,i[r++]=255&v,i[r++]=v>>>24&15|16,i[r++]=v>>>16&255,i[r++]=a>>>8|128,i[r++]=255&a;for(var d=0;d<6;++d)i[r+d]=o[d];return n||F(i)},x=2e3;function ae(u,e,n){var t="/a/"+e+".gif",s=ie({"Content-Type":"application/json"},U(u,n)),c=u.httpFallbackPing,l={};return l.sendChunk=function(e,r,i,n){var o=JSON.stringify(e),a=i?null:A();return n?function n(t){var e=i?s:ie({},s,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":a});return u.httpRequest("POST",r,e,o).promise.then(function(e){if(e)return 400<=e.status&&P(e.status)&&t?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)}).catch(function(){return t?n(!1):Promise.reject()})}(!0).catch(function(){}):(c&&c(r+t+"?d="+S(o)),Promise.resolve())},l.sendEvents=function(e,n,t){if(!u.httpRequest)return Promise.resolve();var r,i=u.httpAllowsPost();r=i?[e]:k(x-n.length,e);for(var o=[],a=0;a<r.length;a++)o.push(l.sendChunk(r[a],n,t,i));return Promise.all(o)},l}function _(e){var n={},s=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},f={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;function n(r,i){return Object.keys(r).reduce(function(e,n){var t=e;return i(n)&&(!function(e){return!l[e]&&(s||-1!==o.indexOf(e)||-1!==c.indexOf(e))}(n)?t[0][n]=r[n]:t[1][n]=!0),t},[{},{}])}var o=e.privateAttributeNames||[],t=n(e,function(e){return f[e]}),r=t[0],i=t[1];if(e.custom){var a=n(e.custom,function(){return!0});r.custom=a[0],i=ie({},i,a[1])}var u=Object.keys(i);return u.length&&(u.sort(),r.privateAttrs=u),r},n}function V(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}function q(){return"LaunchDarkly client initialized"}function J(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"}function ue(e){return'Custom event "'+e+'" does not exist'}function se(){return"No environment/client-side ID was specified."+$}function ce(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+$}function z(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."}function M(){return"identify() has no effect here; it must be called on the main client instance"}function B(){return"received ping message from stream"}function K(){return"received streaming update for all flags"}function le(e){return'received streaming update for flag "'+e+'"'}function fe(e){return'received streaming update for flag "'+e+'" but ignored due to version check'}function ve(e){return'received streaming deletion for flag "'+e+'"'}function de(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'}function ge(e){return'enqueueing "'+e+'" event'}var $=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",G=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},pe=function(e){return'Expected application/json content type but got "'+e+'"'},me=function(){return"localStorage is unavailable"},he=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},ye=function(e){return"network error"+(e?" ("+e+")":"")},be=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+$},ke=function(e){return"Error fetching flag settings: "+V(e)},Ee=function(){return"No user specified."+$},we=function(){return"Invalid user specified."+$},De=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},Se=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(P(e)?t:"giving up permanently")},Oe=function(){return"Cannot make HTTP requests in this environment."+$},Pe=function(){return"Closing stream connection"},Ue=function(e){return"Opening stream connection to "+e},Ie=function(e,n){return"Error on stream connection: "+V(e)+", will continue retrying every "+n+" milliseconds."},je=function(e){return'Ignoring unknown config option "'+e+'"'},Re=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},Te=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},Ne=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},Fe=function(e){return"polling for feature flags at "+e},Ce=function(e){return"sending "+e+" events"},Le=Object.freeze({__proto__:null,clientInitialized:q,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:G,eventWithoutUser:J,invalidContentType:pe,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:me,localStorageUnavailableForUserId:he,networkError:ye,unknownCustomEventKey:ue,environmentNotFound:be,environmentNotSpecified:se,errorFetchingFlags:ke,userNotSpecified:Ee,invalidUser:we,bootstrapOldFormat:ce,bootstrapInvalid:z,deprecated:De,httpErrorMessage:Se,httpUnavailable:Oe,identifyDisabled:M,streamClosing:Pe,streamConnecting:Ue,streamError:Ie,unknownOption:je,wrongOptionType:Re,wrongOptionTypeBoolean:Te,optionBelowMinimum:Ne,debugPolling:Fe,debugStreamPing:B,debugStreamPut:K,debugStreamPatch:le,debugStreamPatchIgnored:fe,debugStreamDelete:ve,debugStreamDeleteIgnored:de,debugEnqueueingEvent:ge,debugPostingEvents:Ce,debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"}});function Ae(e,n,t,r,i,o){var a,u=3<arguments.length&&void 0!==r?r:null,s=4<arguments.length&&void 0!==i?i:null,c={},l=(5<arguments.length&&void 0!==o?o:null)||ae(e,t,n),f=n.eventsUrl+"/events/bulk/"+t,v=function(){var e={},a=0,u=0,s={};return e.summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=s[n];t?t.count=t.count+1:s[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>u&&(u=e.creationDate)}},e.getSummary=function(){var e={},n=!0;for(var t in s){var r=s[t],i=e[r.key];i||(i={default:r.default,counters:[]},e[r.key]=i);var o={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(o.variation=r.variation),r.version?o.version=r.version:o.unknown=!0,i.counters.push(o),n=!1}return n?null:{startDate:a,endDate:u,features:e}},e.clearSummary=function(){u=a=0,s={}},e}(),d=_(n),g=n.inlineUsersInEvents,p=n.samplingInterval,m=n.eventCapacity,h=n.flushInterval,y=n.logger,b=[],k=0,E=!1,w=!1;function D(){return 0===p||0===Math.floor(Math.random()*p)}function S(e){b.length<m?(b.push(e),w=!1):(w||(w=!0,y.warn(G())),u&&u.incrementDroppedEvents())}return c.enqueue=function(e){if(!E){var n=!1,t=!1;if(v.summarizeEvent(e),"feature"===e.kind?D()&&(n=!!e.trackEvents,t=function(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>k&&e.debugEventsUntilDate>(new Date).getTime())}(e)):n=D(),n&&S(function(e){var n=ie({},e);return g||"identify"===e.kind?n.user=d.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),t){var r=ie({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,S(r)}}},c.flush=function(){if(E)return Promise.resolve();var e=b,n=v.getSummary();return v.clearSummary(),n&&(n.kind="summary",e.push(n)),u&&u.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(b=[],y.debug(Ce(e.length)),l.sendEvents(e,f).then(function(e){e&&(e.serverTime&&(k=e.serverTime),P(e.status)||(E=!0),400<=e.status&&ne(function(){s.maybeReportError(new O(Se(e.status,"event posting","some events were dropped")))}))}))},c.start=function(){a=setTimeout(function e(){c.flush(),a=setTimeout(e,h)},h)},c.stop=function(){clearTimeout(a)},c}function xe(n){var e={},i={};return e.on=function(e,n,t){i[e]=i[e]||[],i[e]=i[e].concat({handler:n,context:t})},e.off=function(e,n,t){if(i[e])for(var r=0;r<i[e].length;r++)i[e][r].handler===n&&i[e][r].context===t&&(i[e]=i[e].slice(0,r).concat(i[e].slice(r+1)))},e.emit=function(e){if(i[e])for(var n=0;n<i[e].length;n++)i[e][n].handler.apply(i[e][n].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(i)},e.getEventListenerCount=function(e){return i[e]?i[e].length:0},e.maybeReportError=function(e){e&&(!function(e){return!!i[e]}("error")?(n||console).error(e.message):this.emit("error",e))},e}function _e(t,r,i,o,a){var u={};function s(){var e="",n=o.getUser();return n&&(e=i||y(JSON.stringify(n))),"ld:"+r+":"+e}return u.loadFlags=function(){return t.get(s()).then(function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var t=n.$schema;void 0===t||t<1?n=b(n):delete n.$schema}return n}catch(e){return u.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return a.warn(me()),Promise.reject(e)})},u.saveFlags=function(e){var n=ie({},e,{$schema:1});return t.set(s(),JSON.stringify(n)).catch(function(e){return a.warn(me()),Promise.reject(e)})},u.clearFlags=function(){return t.clear(s()).catch(function(e){return a.warn(me()),Promise.reject(e)})},u}function Ve(i,e,o,n){var a,u=e.streamUrl,s=e.logger,t={},c=u+"/eval/"+o,l=e.useReport,f=e.evaluationReasons,r=e.streamReconnectDelay,v=U(i,e),d=!1,g=null,p=null,m=null,h=null,y=null;function b(e){d||(s.warn(Ie(e,r)),d=!0),D(!1),w(),k(r)}function k(e){p||(e?p=setTimeout(E,e):E())}function E(){var e;p=null;var n="",t={headers:v};if(i.eventSourceFactory){for(var r in null!=h&&(n="h="+h),l?i.eventSourceAllowsReport?(e=c,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(m)):(e=u+"/ping/"+o,n=""):e=c+"/"+S(JSON.stringify(m)),f&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,w(),s.info(Ue(e)),a=(new Date).getTime(),g=i.eventSourceFactory(e,t),y)y.hasOwnProperty(r)&&g.addEventListener(r,y[r]);g.onerror=b}}function w(){g&&(s.info(Pe()),g.close(),g=null)}function D(e){a&&n&&n.recordStreamInit(a,!e,(new Date).getTime()-a),a=null}return t.connect=function(e,n,t){m=e,h=n,y={};function r(n){y[n]=function(e){D(!(d=!1)),t[n]&&t[n](e)}}for(var i in t||{})r(i);k()},t.disconnect=function(){clearTimeout(p),p=null,w()},t.isConnected=function(){return!!(g&&i.eventSourceIsActive&&i.eventSourceIsActive(g))},t}var qe="application/json";function Je(u,s,a){var c=s.baseUrl,l=s.useReport,f=s.evaluationReasons,v=s.logger,e={},d={};function g(e,n){if(!u.httpRequest)return new Promise(function(e,n){n(new Y(Oe()))});var t=n?"REPORT":"GET",r=U(u,s);n&&(r["Content-Type"]="application/json");var i=d[e];i||(i=function(t){var r,i,o,a,e={addPromise:function(n,e){r=n,i&&i(),i=e,n.then(function(e){r===n&&(o(e),t&&t())},function(e){r===n&&(a(e),t&&t())})}};return e.resultPromise=new Promise(function(e,n){o=e,a=n}),e}(function(){delete d[e]}),d[e]=i);var o=u.httpRequest(t,e,r,n),a=o.promise.then(function(e){if(200!==e.status)return Promise.reject(function(e){return 404===e.status?new W(be()):new Y(ke(e.statusText||String(e.status)))}(e));if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(qe))return JSON.parse(e.body);var n=pe(e.header("content-type")||"");return Promise.reject(new Y(n))},function(e){return Promise.reject(new Y(ye(e)))});return i.addPromise(a,function(){o.cancel&&o.cancel()}),i.resultPromise}return e.fetchJSON=function(e){return g(c+e,null)},e.fetchFlagSettings=function(e,n){var t,r,i,o="";return l?(r=[c,"/sdk/evalx/",a,"/user"].join(""),i=JSON.stringify(e)):(t=S(JSON.stringify(e)),r=[c,"/sdk/evalx/",a,"/users/",t].join("")),n&&(o="h="+n),f&&(o=o+(o?"&":"")+"withReasons=true"),r=r+(o?"?":"")+o,v.debug(Fe(r)),g(r,i)},e}var ze="ld:$anonUserId";function Me(r,i){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new o(Ee()));var t=Z(e);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?(r?r.get(ze).catch(function(){return null}):Promise.resolve(null)).then(function(e){if(e)return t.key=e,t;var n=A();return function(e){return r?r.set(ze,e).catch(function(){i.warn(he())}):Promise.resolve()}(t.key=n).then(function(){return t})}):Promise.reject(new o(we()))},e}var Be={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},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"}};function Ke(e,n,t,r){var a=ie({logger:{default:r}},Be,t),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){ne(function(){n&&n.maybeReportError(new d(e))})}var o,s,c,l,f=ie({},e||{});function v(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var n=H(e);return"boolean"===n||"string"===n||"number"===n||"function"===n?n:"object"}}return o=f,Object.keys(i).forEach(function(e){if(void 0!==o[e]){var n=i[e];r&&r.warn(De(e,n)),n&&(void 0===o[n]&&(o[n]=o[e]),delete o[e])}}),s=ie({},f),Object.keys(a).forEach(function(e){void 0!==s[e]&&null!==s[e]||(s[e]=a[e]&&a[e].default)}),l=ie({},c=f=s),Object.keys(c).forEach(function(e){var n=c[e];if(null!=n){var t=a[e];if(void 0===t)u(je(e));else{var r=t.type||v(t.default);if("any"!==r){var i=r.split("|"),o=v(n);i.indexOf(o)<0?"boolean"===r?(l[e]=!!n,u(Te(e,o))):(u(Re(e,r,o)),l[e]=t.default):"number"===o&&void 0!==t.minimum&&n<t.minimum&&(u(Ne(e,n,t.minimum)),l[e]=t.minimum)}}}}),f=l}var $e=Object.freeze({__proto__:null,baseOptionDefs:Be,validate:Ke}).baseOptionDefs;var Ge=function(e){var n={diagnosticId:A()};return e&&(n.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),n},He=function(e){var n,t,r,i;function o(e){n=e,r=t=0,i=[]}return o(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:i}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,i=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};i.push(r)},reset:o}},Xe=function(n,e,t,r,i,o){var a,u,s=!!n.diagnosticUseCombinedEvent,c="ld:"+r+":$diagnostics",l=i.eventsUrl+"/events/diagnostic/"+r,f=i.diagnosticRecordingInterval,v=e,d=!!i.streaming,g={};function p(){return{sdk:function(){var e=X({},n.diagnosticSdkData);i.wrapperName&&(e.wrapperName=i.wrapperName);i.wrapperVersion&&(e.wrapperVersion=i.wrapperVersion);return e}(),configuration:{customBaseURI:i.baseUrl!==$e.baseUrl.default,customStreamURI:i.streamUrl!==$e.streamUrl.default,customEventsURI:i.eventsUrl!==$e.eventsUrl.default,eventsCapacity:i.eventCapacity,eventsFlushIntervalMillis:i.flushInterval,reconnectTimeMillis:i.streamReconnectDelay,streamingDisabled:!d,allAttributesPrivate:!!i.allAttributesPrivate,inlineUsersInEvents:!!i.inlineUsersInEvents,diagnosticRecordingIntervalMillis:i.diagnosticRecordingInterval,usingSecureMode:!!i.hash,bootstrapMode:!!i.bootstrap,fetchGoalsDisabled:!i.fetchGoals,allowFrequentDuplicateEvents:!!i.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!i.sendEventsOnlyForVariation},platform:n.diagnosticPlatformData}}function m(e){i.logger&&i.logger.debug(Le.debugPostingDiagnosticEvent(e)),t.sendEvents(e,l,!0).then(function(){}).catch(function(){})}function h(){m(function(){var e=(new Date).getTime(),n=X({kind:s?"diagnostic-combined":"diagnostic",id:o,creationDate:e},v.getProps());return s&&(n=X({},n,{},p())),v.reset(e),n}()),u=setTimeout(h,f),a=(new Date).getTime(),s&&function(){if(n.localStorage){var e=X({},v.getProps());n.localStorage.set(c,JSON.stringify(e),function(){})}}()}return g.start=function(){s?function(t){if(!n.localStorage)return t(!1);n.localStorage.get(c).then(function(e){if(e)try{var n=JSON.parse(e);v.setProps(n),a=n.dataSinceDate}catch(e){}t(!0)}).catch(function(){t(!1)})}(function(e){if(e){var n=(a||0)+f,t=(new Date).getTime();n<=t?h():u=setTimeout(h,n-t)}else 0===Math.floor(4*Math.random())?h():u=setTimeout(h,f)}):(m(X({kind:"diagnostic-init",id:o,creationDate:v.getProps().dataSinceDate},p())),u=setTimeout(h,f))},g.stop=function(){u&&clearTimeout(u)},g.setStreaming=function(e){d=e},g};function We(e,n){var i,o=["debug","info","warn","error"];i=null!=n?""===n?"":n+" ":"LD: ";var a=0;e&&(a="none"===e?100:o.indexOf(e));var t={};function r(e,n,t){if(a<=e){var r=e<o.length?o[e]:"?";n(i+"["+r+"] "+t)}}return t.debug=function(e){return r(0,console.log,e)},t.info=function(e){return r(1,console.info,e)},t.warn=function(e){return r(2,console.warn,e)},t.error=function(e){return r(3,console.error,e)},t}var Qe="ready",Ye="initialized",Ze="failed",en="change",nn="internal-change";e.createConsoleLogger=We,e.errors=r,e.initialize=function(e,n,t,i,r){var a=function(){if(t&&t.logger)return t.logger;return r&&r.logger&&r.logger.default||We("warn")}(),u=xe(a),f=Ke(t,u,r,a),o=f.sendEvents,s=e,c=f.hash,l=ae(i,s,f),v=f.sendEvents&&!f.diagnosticOptOut,d=v?Ge(s):null,g=v?He((new Date).getTime()):null,p=v?Xe(i,g,l,s,f,d):null;p&&p.start();var m,h,y,b,k=Ve(i,f,s,g),E=f.eventProcessor||Ae(i,f,s,g,u,l),w=Je(i,f,s),D={},S={},O=f.streaming,P=!1,U=!1,I=!0,j=f.stateProvider,R=function(e,n){var t,r={};return r.setUser=function(e){(t=oe(e))&&n&&n(Z(t))},r.getUser=function(){return t?Z(t):null},e&&r.setUser(e),r}(null,function(e){if(j)return;e&&N({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),T=Me(i.localStorage,a);function N(e){s&&(j&&j.enqueueEvent&&j.enqueueEvent(e)||(e.user?(I=!1,!o||U||i.isDoNotTrack()||(a.debug(ge(e.kind)),E.enqueue(e))):I&&(a.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"),I=!1)))}function F(e,n,t,r){var i=R.getUser(),o=new Date,a=n?n.value:null;if(!f.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(i&&i.key?i.key:"")+e,s=D[u];if(s&&o-s<3e5)return;D[u]=o}var c={kind:"feature",key:e,user:i,value:a,variation:n?n.variationIndex:null,default:t,creationDate:o.getTime()},l=S[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),N(c)}function C(e,n,t,r){var i;if(S&&S.hasOwnProperty(e)&&S[e]&&!S[e].deleted){var o=S[e];i=L(o),null!==o.value&&void 0!==o.value||(i.value=n)}else i={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&F(e,i,n,r),i}function L(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function A(){h=!0,R.getUser()&&k.connect(R.getUser(),c,{ping:function(){a.debug("received ping message from stream"),w.fetchFlagSettings(R.getUser(),c).then(function(e){return _(e||{})}).catch(function(e){u.maybeReportError(new Y(ke(e)))})},put:function(e){var n=JSON.parse(e.data);a.debug("received streaming update for all flags"),_(n)},patch:function(e){var n=JSON.parse(e.data),t=S[n.key];if(!t||!t.version||!n.version||t.version<n.version){a.debug(le(n.key));var r={},i=ie({},n);delete i.key;var o=L(S[n.key]=i);r[n.key]=t?{previous:t.value,current:o}:{current:o},V(r)}else a.debug(fe(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!S[n.key]||S[n.key].version<n.version){a.debug(ve(n.key));var t={};S[n.key]&&!S[n.key].deleted&&(t[n.key]={previous:S[n.key].value}),S[n.key]={version:n.version,deleted:!0},V(t)}else a.debug(de(n.key))}})}function x(){h&&(k.disconnect(),h=!1)}function _(e){var n={};if(!e)return Promise.resolve();for(var t in S)S.hasOwnProperty(t)&&S[t]&&(e[t]&&!ee(e[t].value,S[t].value)?n[t]={previous:S[t].value,current:L(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:S[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!S[r]||S[r].deleted)&&(n[r]={current:L(e[r])});return S=X({},e),V(n).catch(function(){})}function V(i){var e=Object.keys(i);if(0<e.length){var o={};e.forEach(function(e){var n=i[e].current,t=n?n.value:void 0,r=i[e].previous;u.emit(en+":"+e,t,r),o[e]=n?{current:t,previous:r}:{previous:r}}),u.emit(en,o),u.emit(nn,S),f.sendEventsOnlyForVariation||j||e.forEach(function(e){F(e,i[e].current)})}return m&&b?b.saveFlags(S).catch(function(){return null}):Promise.resolve()}function q(){var e=O||y&&void 0===O;e&&!h?A():!e&&h&&x(),p&&p.setStreaming(e)}function J(e){return e===en||e.substr(0,en.length+1)===en+":"}i.localStorage&&(b=new _e(i.localStorage,s,c,R,a));var z=new Promise(function(e){var n=u.on(Qe,function(){u.off(Qe,n),e()})}),M=new Promise(function(e,n){var t=u.on(Ye,function(){u.off(Ye,t),e()}),r=u.on(Ze,function(e){u.off(Ze,r),n(e)})});if("string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(b?m=!0:a.warn(me())),"object"===H(f.bootstrap)&&(S=function(t){var e=Object.keys(t),r="$flagsState",i=t[r];!i&&e.length&&a.warn(ce()),!1===t.$valid&&a.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var o={};return e.forEach(function(e){if(e!==r&&"$valid"!==e){var n={value:t[e]};i&&i[e]?n=ie(n,i[e]):n.version=0,o[e]=n}}),o}(f.bootstrap)),j){var B=j.getInitialState();B?K(B):j.on("init",K),j.on("update",function(e){e.user&&R.setUser(e.user);e.flags&&_(e.flags)})}else(e?T.validateUser(n).then(function(e){return R.setUser(e),"object"===H(f.bootstrap)?$():m?b.loadFlags().catch(function(){return null}).then(function(e){return null==e?(S={},w.fetchFlagSettings(R.getUser(),c).then(function(e){return _(e||{})}).then($).catch(function(e){G(new Y(ke(e)))})):(S=e,ne($),w.fetchFlagSettings(R.getUser(),c).then(function(e){return _(e)}).catch(function(e){return u.maybeReportError(e)}))}):w.fetchFlagSettings(R.getUser(),c).then(function(e){S=e||{},$()}).catch(function(e){S={},G(e)})}):Promise.reject(new W(se()))).catch(function(e){return u.maybeReportError(e)});function K(e){s=e.environment,R.setUser(e.user),S=X({},e.flags),ne($)}function $(){a.info("LaunchDarkly client initialized"),P=!0,q(),u.emit(Qe),u.emit(Ye)}function G(e){u.maybeReportError(e),u.emit(Ze,e),u.emit(Qe)}return{client:{waitForInitialization:function(){return M},waitUntilReady:function(){return z},identify:function(e,r,n){return U?te(Promise.resolve({}),n):j?(a.warn("identify() has no effect here; it must be called on the main client instance"),te(Promise.resolve(re(S)),n)):te((m&&b?b.clearFlags():Promise.resolve()).then(function(){return T.validateUser(e)}).then(function(t){return w.fetchFlagSettings(t,r).then(function(e){var n=re(e);return R.setUser(t),c=r,e?_(e).then(function(){return n}):n})}).then(function(e){return h&&A(),e}).catch(function(e){return u.maybeReportError(e),Promise.reject(e)}),n)},getUser:function(){return R.getUser()},variation:function(e,n){return C(e,n,!0,!1).value},variationDetail:function(e,n){return C(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){i.customEventFilter&&!i.customEventFilter(e)&&a.warn(ue(e));var r={kind:"custom",key:e,user:R.getUser(),url:i.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),N(r)}else u.maybeReportError(new Q(ue(e)))},on:function(e,n,t){J(e)?(y=!0,P&&q(),u.on(e,n,t)):u.on.apply(u,arguments)},off:function(e){if(u.off.apply(u,arguments),J(e)){var n=!1;u.getEvents().forEach(function(e){J(e)&&0<u.getEventListenerCount(e)&&(n=!0)}),n||(y=!1,h&&void 0===O&&x())}},setStreaming:function(e){var n=null===e?void 0:e;n!==O&&(O=n,q())},flush:function(e){return te(o?E.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!S)return e;for(var n in S)S.hasOwnProperty(n)&&(e[n]=C(n,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(U)return te(Promise.resolve(),e);function n(){U=!0,S={}}return te(Promise.resolve().then(function(){if(x(),p&&p.stop(),o)return E.stop(),E.flush()}).then(n).catch(n),e)}},options:f,emitter:u,ident:R,logger:a,requestor:w,start:function(){o&&(p&&p.start(),E.start())},enqueueEvent:N,getFlagsInternal:function(){return S},getEnvironmentId:function(){return s},internalChangeEventName:nn}},e.messages=Le,e.utils=w,e.version="3.2.2",Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self)["LDClient-Common"]={})}(this,function(e){"use strict";function G(e){return(G="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 n(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),t.push.apply(t,r)}return t}function H(i){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?n(o,!0).forEach(function(e){var n,t,r;n=i,r=o[t=e],t in n?Object.defineProperty(n,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):n[t]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(o)):n(o).forEach(function(e){Object.defineProperty(i,e,Object.getOwnPropertyDescriptor(o,e))})}return i}function t(e){function n(e,n){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=n}return(n.prototype=new Error).name=e,n.prototype.constructor=n}var S=t("LaunchDarklyUnexpectedResponseError"),X=t("LaunchDarklyInvalidEnvironmentIdError"),o=t("LaunchDarklyInvalidUserError"),W=t("LaunchDarklyInvalidEventKeyError"),d=t("LaunchDarklyInvalidArgumentError"),Q=t("LaunchDarklyFlagFetchError");function O(e){return!(400<=e&&e<500)||(400===e||408===e||429===e)}for(var r=Object.freeze({__proto__:null,LDUnexpectedResponseError:S,LDInvalidEnvironmentIdError:X,LDInvalidUserError:o,LDInvalidEventKeyError:W,LDInvalidArgumentError:d,LDFlagFetchError:Q,isHttpErrorRecoverable:O}),i=function(e){for(var n,t=e.length,r=t%3,i=[],o=0,a=t-r;o<a;o+=16383)i.push(f(e,o,a<o+16383?a:o+16383));1==r?(n=e[t-1],i.push(u[n>>2]+u[n<<4&63]+"==")):2==r&&(n=(e[t-2]<<8)+e[t-1],i.push(u[n>>10]+u[n>>4&63]+u[n<<2&63]+"="));return i.join("")},u=[],a=[],s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=0,l=s.length;c<l;++c)u[c]=s[c],a[s.charCodeAt(c)]=c;function f(e,n,t){for(var r,i,o=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(u[(i=r)>>18&63]+u[i>>12&63]+u[i>>6&63]+u[63&i]);return o.join("")}a["-".charCodeAt(0)]=62,a["_".charCodeAt(0)]=63;var g=Array.isArray,m=Object.keys,p=Object.prototype.hasOwnProperty,v=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,i,o,a=g(n),u=g(t);if(a&&u){if((i=n.length)!=t.length)return!1;for(r=i;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var s=n instanceof Date,c=t instanceof Date;if(s!=c)return!1;if(s&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var v=m(n);if((i=v.length)!==m(t).length)return!1;for(r=i;0!=r--;)if(!p.call(t,v[r]))return!1;for(r=i;0!=r--;)if(!e(n[o=v[r]],t[o]))return!1;return!0}return n!=n&&t!=t},h=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function y(e){var n=unescape(encodeURIComponent(e));return i(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function P(e){return y(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function Y(e){return JSON.parse(JSON.stringify(e))}function Z(e,n){return v(e,n)}function ee(e){setTimeout(e,0)}function ne(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function b(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function te(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function k(e,n){for(var t,r=n.slice(0),i=[],o=e;0<r.length;){for(t=[];0<o;){var a=r.shift();if(!a)break;(o-=P(JSON.stringify(a)).length)<0&&0<t.length?r.unshift(a):t.push(a)}o=e,i.push(t)}return i}function E(e){var n=e.version||"3.2.3";return e.userAgent+"/"+n}function U(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":E(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function re(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return H({},e,{},n)},{})}function ie(e){if(!e)return e;var n;for(var t in h){var r=h[t],i=e[r];void 0!==i&&"string"!=typeof i&&((n=n||H({},e))[r]=String(i))}return n||e}var w=Object.freeze({__proto__:null,btoa:y,base64URLEncode:P,clone:Y,deepEquals:Z,onNextTick:ee,wrapPromiseCallback:ne,transformValuesToVersionedValues:b,transformVersionedValuesToValues:te,chunkUserEventsForUrl:k,getLDUserAgentString:E,getLDHeaders:U,extend:re,sanitizeUser:ie});for(var D,I=(function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}(D={exports:{}},D.exports),D.exports),j=[],R=0;R<256;++R)j[R]=(R+256).toString(16).substr(1);var T,N,F=function(e,n){var t=n||0,r=j;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")},C=0,L=0;var A=function(e,n,t){var r=n&&t||0,i=n||[],o=(e=e||{}).node||T,a=void 0!==e.clockseq?e.clockseq:N;if(null==o||null==a){var u=I();null==o&&(o=T=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=N=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:L+1,l=s-C+(c-L)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||C<s)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");C=s,N=a;var f=(1e4*(268435455&(s+=122192928e5))+(L=c))%4294967296;i[r++]=f>>>24&255,i[r++]=f>>>16&255,i[r++]=f>>>8&255,i[r++]=255&f;var v=s/4294967296*1e4&268435455;i[r++]=v>>>8&255,i[r++]=255&v,i[r++]=v>>>24&15|16,i[r++]=v>>>16&255,i[r++]=a>>>8|128,i[r++]=255&a;for(var d=0;d<6;++d)i[r+d]=o[d];return n||F(i)},x=2e3;function oe(u,e,n){var t="/a/"+e+".gif",s=re({"Content-Type":"application/json"},U(u,n)),c=u.httpFallbackPing,l={};return l.sendChunk=function(e,r,i,n){var o=JSON.stringify(e),a=i?null:A();return n?function n(t){var e=i?s:re({},s,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":a});return u.httpRequest("POST",r,e,o).promise.then(function(e){if(e)return 400<=e.status&&O(e.status)&&t?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)}).catch(function(){return t?n(!1):Promise.reject()})}(!0).catch(function(){}):(c&&c(r+t+"?d="+P(o)),Promise.resolve())},l.sendEvents=function(e,n,t){if(!u.httpRequest)return Promise.resolve();var r,i=u.httpAllowsPost();r=i?[e]:k(x-n.length,e);for(var o=[],a=0;a<r.length;a++)o.push(l.sendChunk(r[a],n,t,i));return Promise.all(o)},l}function _(e){var n={},s=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},f={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;function n(r,i){return Object.keys(r).reduce(function(e,n){var t=e;return i(n)&&(!function(e){return!l[e]&&(s||-1!==o.indexOf(e)||-1!==c.indexOf(e))}(n)?t[0][n]=r[n]:t[1][n]=!0),t},[{},{}])}var o=e.privateAttributeNames||[],t=n(e,function(e){return f[e]}),r=t[0],i=t[1];if(e.custom){var a=n(e.custom,function(){return!0});r.custom=a[0],i=re({},i,a[1])}var u=Object.keys(i);return u.length&&(u.sort(),r.privateAttrs=u),r},n}function V(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}function q(){return"LaunchDarkly client initialized"}function J(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"}function ae(e){return'Custom event "'+e+'" does not exist'}function ue(){return"No environment/client-side ID was specified."+$}function se(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+$}function z(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."}function M(){return"identify() has no effect here; it must be called on the main client instance"}function B(){return"received ping message from stream"}function K(){return"received streaming update for all flags"}function ce(e){return'received streaming update for flag "'+e+'"'}function le(e){return'received streaming update for flag "'+e+'" but ignored due to version check'}function fe(e){return'received streaming deletion for flag "'+e+'"'}function ve(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'}function de(e){return'enqueueing "'+e+'" event'}var $=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",ge=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},me=function(e){return'Expected application/json content type but got "'+e+'"'},pe=function(){return"localStorage is unavailable"},he=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},ye=function(e){return"network error"+(e?" ("+e+")":"")},be=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+$},ke=function(e){return"Error fetching flag settings: "+V(e)},Ee=function(){return"No user specified."+$},we=function(){return"Invalid user specified."+$},De=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},Pe=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(O(e)?t:"giving up permanently")},Se=function(){return"Cannot make HTTP requests in this environment."+$},Oe=function(){return"Closing stream connection"},Ue=function(e){return"Opening stream connection to "+e},Ie=function(e,n){return"Error on stream connection: "+V(e)+", will continue retrying every "+n+" milliseconds."},je=function(e){return'Ignoring unknown config option "'+e+'"'},Re=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},Te=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},Ne=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},Fe=function(e){return"polling for feature flags at "+e},Ce=function(e){return"sending "+e+" events"},Le=Object.freeze({__proto__:null,clientInitialized:q,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:ge,eventWithoutUser:J,invalidContentType:me,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:pe,localStorageUnavailableForUserId:he,networkError:ye,unknownCustomEventKey:ae,environmentNotFound:be,environmentNotSpecified:ue,errorFetchingFlags:ke,userNotSpecified:Ee,invalidUser:we,bootstrapOldFormat:se,bootstrapInvalid:z,deprecated:De,httpErrorMessage:Pe,httpUnavailable:Se,identifyDisabled:M,streamClosing:Oe,streamConnecting:Ue,streamError:Ie,unknownOption:je,wrongOptionType:Re,wrongOptionTypeBoolean:Te,optionBelowMinimum:Ne,debugPolling:Fe,debugStreamPing:B,debugStreamPut:K,debugStreamPatch:ce,debugStreamPatchIgnored:le,debugStreamDelete:fe,debugStreamDeleteIgnored:ve,debugEnqueueingEvent:de,debugPostingEvents:Ce,debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"}});function Ae(e,n,t,r,i,o){var a,u=3<arguments.length&&void 0!==r?r:null,s=4<arguments.length&&void 0!==i?i:null,c={},l=(5<arguments.length&&void 0!==o?o:null)||oe(e,t,n),f=n.eventsUrl+"/events/bulk/"+t,v=function(){var e={},a=0,u=0,s={};return e.summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=s[n];t?t.count=t.count+1:s[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>u&&(u=e.creationDate)}},e.getSummary=function(){var e={},n=!0;for(var t in s){var r=s[t],i=e[r.key];i||(i={default:r.default,counters:[]},e[r.key]=i);var o={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(o.variation=r.variation),r.version?o.version=r.version:o.unknown=!0,i.counters.push(o),n=!1}return n?null:{startDate:a,endDate:u,features:e}},e.clearSummary=function(){u=a=0,s={}},e}(),d=_(n),g=n.inlineUsersInEvents,m=n.samplingInterval,p=n.eventCapacity,h=n.flushInterval,y=n.logger,b=[],k=0,E=!1,w=!1;function D(){return 0===m||0===Math.floor(Math.random()*m)}function P(e){b.length<p?(b.push(e),w=!1):(w||(w=!0,y.warn(ge())),u&&u.incrementDroppedEvents())}return c.enqueue=function(e){if(!E){var n=!1,t=!1;if(v.summarizeEvent(e),"feature"===e.kind?D()&&(n=!!e.trackEvents,t=function(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>k&&e.debugEventsUntilDate>(new Date).getTime())}(e)):n=D(),n&&P(function(e){var n=re({},e);return g||"identify"===e.kind?n.user=d.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),t){var r=re({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,P(r)}}},c.flush=function(){if(E)return Promise.resolve();var e=b,n=v.getSummary();return v.clearSummary(),n&&(n.kind="summary",e.push(n)),u&&u.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(b=[],y.debug(Ce(e.length)),l.sendEvents(e,f).then(function(e){e&&(e.serverTime&&(k=e.serverTime),O(e.status)||(E=!0),400<=e.status&&ee(function(){s.maybeReportError(new S(Pe(e.status,"event posting","some events were dropped")))}))}))},c.start=function(){a=setTimeout(function e(){c.flush(),a=setTimeout(e,h)},h)},c.stop=function(){clearTimeout(a)},c}function xe(n){var e={},i={};return e.on=function(e,n,t){i[e]=i[e]||[],i[e]=i[e].concat({handler:n,context:t})},e.off=function(e,n,t){if(i[e])for(var r=0;r<i[e].length;r++)i[e][r].handler===n&&i[e][r].context===t&&(i[e]=i[e].slice(0,r).concat(i[e].slice(r+1)))},e.emit=function(e){if(i[e])for(var n=i[e].slice(0),t=0;t<n.length;t++)n[t].handler.apply(n[t].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(i)},e.getEventListenerCount=function(e){return i[e]?i[e].length:0},e.maybeReportError=function(e){e&&(!function(e){return!!i[e]}("error")?(n||console).error(e.message):this.emit("error",e))},e}var _e="ready",Ve="initialized",qe="failed";var Je=function(r){var n=!1,t=!1,i=null,e=null,o=new Promise(function(n){r.on(_e,function e(){r.off(_e,e),n()})}).catch(function(){});return{getInitializationPromise:function(){return e||(n?Promise.resolve():t?Promise.reject(i):e=new Promise(function(n,t){r.on(Ve,function e(){r.off(Ve,e),n()}),r.on(qe,function e(n){r.off(qe,e),t(n)})}))},getReadyPromise:function(){return o},signalSuccess:function(){n||t||(n=!0,r.emit(Ve),r.emit(_e))},signalFailure:function(e){n||t||(t=!0,i=e,r.emit(qe,e),r.emit(_e)),r.maybeReportError(e)}}};function ze(t,r,i,o,a){var u={};function s(){var e="",n=o.getUser();return n&&(e=i||y(JSON.stringify(n))),"ld:"+r+":"+e}return u.loadFlags=function(){return t.get(s()).then(function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var t=n.$schema;void 0===t||t<1?n=b(n):delete n.$schema}return n}catch(e){return u.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return a.warn(pe()),Promise.reject(e)})},u.saveFlags=function(e){var n=re({},e,{$schema:1});return t.set(s(),JSON.stringify(n)).catch(function(e){return a.warn(pe()),Promise.reject(e)})},u.clearFlags=function(){return t.clear(s()).catch(function(e){return a.warn(pe()),Promise.reject(e)})},u}function Me(i,e,o,n){var a,u=e.streamUrl,s=e.logger,t={},c=u+"/eval/"+o,l=e.useReport,f=e.evaluationReasons,r=e.streamReconnectDelay,v=U(i,e),d=!1,g=null,m=null,p=null,h=null,y=null;function b(e){d||(s.warn(Ie(e,r)),d=!0),D(!1),w(),k(r)}function k(e){m||(e?m=setTimeout(E,e):E())}function E(){var e;m=null;var n="",t={headers:v};if(i.eventSourceFactory){for(var r in null!=h&&(n="h="+h),l?i.eventSourceAllowsReport?(e=c,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(p)):(e=u+"/ping/"+o,n=""):e=c+"/"+P(JSON.stringify(p)),f&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,w(),s.info(Ue(e)),a=(new Date).getTime(),g=i.eventSourceFactory(e,t),y)y.hasOwnProperty(r)&&g.addEventListener(r,y[r]);g.onerror=b}}function w(){g&&(s.info(Oe()),g.close(),g=null)}function D(e){a&&n&&n.recordStreamInit(a,!e,(new Date).getTime()-a),a=null}return t.connect=function(e,n,t){p=e,h=n,y={};function r(n){y[n]=function(e){D(!(d=!1)),t[n]&&t[n](e)}}for(var i in t||{})r(i);k()},t.disconnect=function(){clearTimeout(m),m=null,w()},t.isConnected=function(){return!!(g&&i.eventSourceIsActive&&i.eventSourceIsActive(g))},t}var Be="application/json";function Ke(u,s,a){var c=s.baseUrl,l=s.useReport,f=s.evaluationReasons,v=s.logger,e={},d={};function g(e,n){if(!u.httpRequest)return new Promise(function(e,n){n(new Q(Se()))});var t=n?"REPORT":"GET",r=U(u,s);n&&(r["Content-Type"]="application/json");var i=d[e];i||(i=function(t){var r,i,o,a,e={addPromise:function(n,e){r=n,i&&i(),i=e,n.then(function(e){r===n&&(o(e),t&&t())},function(e){r===n&&(a(e),t&&t())})}};return e.resultPromise=new Promise(function(e,n){o=e,a=n}),e}(function(){delete d[e]}),d[e]=i);var o=u.httpRequest(t,e,r,n),a=o.promise.then(function(e){if(200!==e.status)return Promise.reject(function(e){return 404===e.status?new X(be()):new Q(ke(e.statusText||String(e.status)))}(e));if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(Be))return JSON.parse(e.body);var n=me(e.header("content-type")||"");return Promise.reject(new Q(n))},function(e){return Promise.reject(new Q(ye(e)))});return i.addPromise(a,function(){o.cancel&&o.cancel()}),i.resultPromise}return e.fetchJSON=function(e){return g(c+e,null)},e.fetchFlagSettings=function(e,n){var t,r,i,o="";return l?(r=[c,"/sdk/evalx/",a,"/user"].join(""),i=JSON.stringify(e)):(t=P(JSON.stringify(e)),r=[c,"/sdk/evalx/",a,"/users/",t].join("")),n&&(o="h="+n),f&&(o=o+(o?"&":"")+"withReasons=true"),r=r+(o?"?":"")+o,v.debug(Fe(r)),g(r,i)},e}var $e="ld:$anonUserId";function Ge(r,i){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new o(Ee()));var t=Y(e);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?(r?r.get($e).catch(function(){return null}):Promise.resolve(null)).then(function(e){if(e)return t.key=e,t;var n=A();return function(e){return r?r.set($e,e).catch(function(){i.warn(he())}):Promise.resolve()}(t.key=n).then(function(){return t})}):Promise.reject(new o(we()))},e}var He={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},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"}};function Xe(e,n,t,r){var a=re({logger:{default:r}},He,t),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){ee(function(){n&&n.maybeReportError(new d(e))})}var o,s,c,l,f=re({},e||{});function v(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var n=G(e);return"boolean"===n||"string"===n||"number"===n||"function"===n?n:"object"}}return o=f,Object.keys(i).forEach(function(e){if(void 0!==o[e]){var n=i[e];r&&r.warn(De(e,n)),n&&(void 0===o[n]&&(o[n]=o[e]),delete o[e])}}),s=re({},f),Object.keys(a).forEach(function(e){void 0!==s[e]&&null!==s[e]||(s[e]=a[e]&&a[e].default)}),l=re({},c=f=s),Object.keys(c).forEach(function(e){var n=c[e];if(null!=n){var t=a[e];if(void 0===t)u(je(e));else{var r=t.type||v(t.default);if("any"!==r){var i=r.split("|"),o=v(n);i.indexOf(o)<0?"boolean"===r?(l[e]=!!n,u(Te(e,o))):(u(Re(e,r,o)),l[e]=t.default):"number"===o&&void 0!==t.minimum&&n<t.minimum&&(u(Ne(e,n,t.minimum)),l[e]=t.minimum)}}}}),f=l}var We=Object.freeze({__proto__:null,baseOptionDefs:He,validate:Xe}).baseOptionDefs;var Qe=function(e){var n={diagnosticId:A()};return e&&(n.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),n},Ye=function(e){var n,t,r,i;function o(e){n=e,r=t=0,i=[]}return o(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:i}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,i=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};i.push(r)},reset:o}},Ze=function(n,e,t,r,i,o){var a,u,s=!!n.diagnosticUseCombinedEvent,c="ld:"+r+":$diagnostics",l=i.eventsUrl+"/events/diagnostic/"+r,f=i.diagnosticRecordingInterval,v=e,d=!!i.streaming,g={};function m(){return{sdk:function(){var e=H({},n.diagnosticSdkData);i.wrapperName&&(e.wrapperName=i.wrapperName);i.wrapperVersion&&(e.wrapperVersion=i.wrapperVersion);return e}(),configuration:{customBaseURI:i.baseUrl!==We.baseUrl.default,customStreamURI:i.streamUrl!==We.streamUrl.default,customEventsURI:i.eventsUrl!==We.eventsUrl.default,eventsCapacity:i.eventCapacity,eventsFlushIntervalMillis:i.flushInterval,reconnectTimeMillis:i.streamReconnectDelay,streamingDisabled:!d,allAttributesPrivate:!!i.allAttributesPrivate,inlineUsersInEvents:!!i.inlineUsersInEvents,diagnosticRecordingIntervalMillis:i.diagnosticRecordingInterval,usingSecureMode:!!i.hash,bootstrapMode:!!i.bootstrap,fetchGoalsDisabled:!i.fetchGoals,allowFrequentDuplicateEvents:!!i.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!i.sendEventsOnlyForVariation},platform:n.diagnosticPlatformData}}function p(e){i.logger&&i.logger.debug(Le.debugPostingDiagnosticEvent(e)),t.sendEvents(e,l,!0).then(function(){}).catch(function(){})}function h(){p(function(){var e=(new Date).getTime(),n=H({kind:s?"diagnostic-combined":"diagnostic",id:o,creationDate:e},v.getProps());return s&&(n=H({},n,{},m())),v.reset(e),n}()),u=setTimeout(h,f),a=(new Date).getTime(),s&&function(){if(n.localStorage){var e=H({},v.getProps());n.localStorage.set(c,JSON.stringify(e),function(){})}}()}return g.start=function(){s?function(t){if(!n.localStorage)return t(!1);n.localStorage.get(c).then(function(e){if(e)try{var n=JSON.parse(e);v.setProps(n),a=n.dataSinceDate}catch(e){}t(!0)}).catch(function(){t(!1)})}(function(e){if(e){var n=(a||0)+f,t=(new Date).getTime();n<=t?h():u=setTimeout(h,n-t)}else 0===Math.floor(4*Math.random())?h():u=setTimeout(h,f)}):(p(H({kind:"diagnostic-init",id:o,creationDate:v.getProps().dataSinceDate},m())),u=setTimeout(h,f))},g.stop=function(){u&&clearTimeout(u)},g.setStreaming=function(e){d=e},g};function en(e,n){var i,o=["debug","info","warn","error"];i=null!=n?""===n?"":n+" ":"LD: ";var a=0;e&&(a="none"===e?100:o.indexOf(e));var t={};function r(e,n,t){if(a<=e){var r=e<o.length?o[e]:"?";n(i+"["+r+"] "+t)}}return t.debug=function(e){return r(0,console.log,e)},t.info=function(e){return r(1,console.info,e)},t.warn=function(e){return r(2,console.warn,e)},t.error=function(e){return r(3,console.error,e)},t}var nn="change",tn="internal-change";e.createConsoleLogger=en,e.errors=r,e.initialize=function(e,n,t,i,r){var a=function(){if(t&&t.logger)return t.logger;return r&&r.logger&&r.logger.default||en("warn")}(),u=xe(a),o=Je(u),f=Xe(t,u,r,a),s=f.sendEvents,c=e,l=f.hash,v=oe(i,c,f),d=f.sendEvents&&!f.diagnosticOptOut,g=d?Qe(c):null,m=d?Ye((new Date).getTime()):null,p=d?Ze(i,m,v,c,f,g):null;p&&p.start();var h,y,b,k,E=Me(i,f,c,m),w=f.eventProcessor||Ae(i,f,c,m,u,v),D=Ke(i,f,c),P={},S={},O=f.streaming,U=!1,I=!1,j=!0,R=f.stateProvider,T=function(e,n){var t,r={};return r.setUser=function(e){(t=ie(e))&&n&&n(Y(t))},r.getUser=function(){return t?Y(t):null},e&&r.setUser(e),r}(null,function(e){if(R)return;e&&F({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),N=Ge(i.localStorage,a);function F(e){c&&(R&&R.enqueueEvent&&R.enqueueEvent(e)||(e.user?(j=!1,!s||I||i.isDoNotTrack()||(a.debug(de(e.kind)),w.enqueue(e))):j&&(a.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"),j=!1)))}function C(e,n,t,r){var i=T.getUser(),o=new Date,a=n?n.value:null;if(!f.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(i&&i.key?i.key:"")+e,s=P[u];if(s&&o-s<3e5)return;P[u]=o}var c={kind:"feature",key:e,user:i,value:a,variation:n?n.variationIndex:null,default:t,creationDate:o.getTime()},l=S[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),F(c)}function L(e,n,t,r){var i;if(S&&S.hasOwnProperty(e)&&S[e]&&!S[e].deleted){var o=S[e];i=A(o),null!==o.value&&void 0!==o.value||(i.value=n)}else i={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&C(e,i,n,r),i}function A(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function x(){y=!0,T.getUser()&&E.connect(T.getUser(),l,{ping:function(){a.debug("received ping message from stream"),D.fetchFlagSettings(T.getUser(),l).then(function(e){return V(e||{})}).catch(function(e){u.maybeReportError(new Q(ke(e)))})},put:function(e){var n=JSON.parse(e.data);a.debug("received streaming update for all flags"),V(n)},patch:function(e){var n=JSON.parse(e.data),t=S[n.key];if(!t||!t.version||!n.version||t.version<n.version){a.debug(ce(n.key));var r={},i=re({},n);delete i.key;var o=A(S[n.key]=i);r[n.key]=t?{previous:t.value,current:o}:{current:o},q(r)}else a.debug(le(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!S[n.key]||S[n.key].version<n.version){a.debug(fe(n.key));var t={};S[n.key]&&!S[n.key].deleted&&(t[n.key]={previous:S[n.key].value}),S[n.key]={version:n.version,deleted:!0},q(t)}else a.debug(ve(n.key))}})}function _(){y&&(E.disconnect(),y=!1)}function V(e){var n={};if(!e)return Promise.resolve();for(var t in S)S.hasOwnProperty(t)&&S[t]&&(e[t]&&!Z(e[t].value,S[t].value)?n[t]={previous:S[t].value,current:A(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:S[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!S[r]||S[r].deleted)&&(n[r]={current:A(e[r])});return S=H({},e),q(n).catch(function(){})}function q(i){var e=Object.keys(i);if(0<e.length){var o={};e.forEach(function(e){var n=i[e].current,t=n?n.value:void 0,r=i[e].previous;u.emit(nn+":"+e,t,r),o[e]=n?{current:t,previous:r}:{previous:r}}),u.emit(nn,o),u.emit(tn,S),f.sendEventsOnlyForVariation||R||e.forEach(function(e){C(e,i[e].current)})}return h&&k?k.saveFlags(S).catch(function(){return null}):Promise.resolve()}function J(){var e=O||b&&void 0===O;e&&!y?x():!e&&y&&_(),p&&p.setStreaming(e)}function z(e){return e===nn||e.substr(0,nn.length+1)===nn+":"}if(i.localStorage&&(k=new ze(i.localStorage,c,l,T,a)),"string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(k?h=!0:a.warn(pe())),"object"===G(f.bootstrap)&&(S=function(t){var e=Object.keys(t),r="$flagsState",i=t[r];!i&&e.length&&a.warn(se()),!1===t.$valid&&a.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var o={};return e.forEach(function(e){if(e!==r&&"$valid"!==e){var n={value:t[e]};i&&i[e]?n=re(n,i[e]):n.version=0,o[e]=n}}),o}(f.bootstrap)),R){var M=R.getInitialState();M?B(M):R.on("init",B),R.on("update",function(e){e.user&&T.setUser(e.user);e.flags&&V(e.flags)})}else(e?N.validateUser(n).then(function(e){return T.setUser(e),"object"===G(f.bootstrap)?K():h?k.loadFlags().catch(function(){return null}).then(function(e){return null==e?(S={},D.fetchFlagSettings(T.getUser(),l).then(function(e){return V(e||{})}).then(K).catch(function(e){$(new Q(ke(e)))})):(S=e,ee(K),D.fetchFlagSettings(T.getUser(),l).then(function(e){return V(e)}).catch(function(e){return u.maybeReportError(e)}))}):D.fetchFlagSettings(T.getUser(),l).then(function(e){S=e||{},K()}).catch(function(e){S={},$(e)})}):Promise.reject(new X(ue()))).catch($);function B(e){c=e.environment,T.setUser(e.user),S=H({},e.flags),ee(K)}function K(){a.info("LaunchDarkly client initialized"),U=!0,J(),o.signalSuccess()}function $(e){o.signalFailure(e)}return{client:{waitForInitialization:function(){return o.getInitializationPromise()},waitUntilReady:function(){return o.getReadyPromise()},identify:function(e,r,n){return I?ne(Promise.resolve({}),n):R?(a.warn("identify() has no effect here; it must be called on the main client instance"),ne(Promise.resolve(te(S)),n)):ne((h&&k?k.clearFlags():Promise.resolve()).then(function(){return N.validateUser(e)}).then(function(t){return D.fetchFlagSettings(t,r).then(function(e){var n=te(e);return T.setUser(t),l=r,e?V(e).then(function(){return n}):n})}).then(function(e){return y&&x(),e}).catch(function(e){return u.maybeReportError(e),Promise.reject(e)}),n)},getUser:function(){return T.getUser()},variation:function(e,n){return L(e,n,!0,!1).value},variationDetail:function(e,n){return L(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){i.customEventFilter&&!i.customEventFilter(e)&&a.warn(ae(e));var r={kind:"custom",key:e,user:T.getUser(),url:i.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),F(r)}else u.maybeReportError(new W(ae(e)))},on:function(e,n,t){z(e)?(b=!0,U&&J(),u.on(e,n,t)):u.on.apply(u,arguments)},off:function(e){if(u.off.apply(u,arguments),z(e)){var n=!1;u.getEvents().forEach(function(e){z(e)&&0<u.getEventListenerCount(e)&&(n=!0)}),n||(b=!1,y&&void 0===O&&_())}},setStreaming:function(e){var n=null===e?void 0:e;n!==O&&(O=n,J())},flush:function(e){return ne(s?w.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!S)return e;for(var n in S)S.hasOwnProperty(n)&&(e[n]=L(n,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(I)return ne(Promise.resolve(),e);function n(){I=!0,S={}}return ne(Promise.resolve().then(function(){if(_(),p&&p.stop(),s)return w.stop(),w.flush()}).then(n).catch(n),e)}},options:f,emitter:u,ident:T,logger:a,requestor:D,start:function(){s&&(p&&p.start(),w.start())},enqueueEvent:F,getFlagsInternal:function(){return S},getEnvironmentId:function(){return c},internalChangeEventName:tn}},e.messages=Le,e.utils=w,e.version="3.2.3",Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=ldclient-common.min.js.map |
{ | ||
"name": "launchdarkly-js-sdk-common", | ||
"version": "3.2.2", | ||
"version": "3.2.3", | ||
"description": "LaunchDarkly SDK for JavaScript - common code", | ||
@@ -5,0 +5,0 @@ "author": "LaunchDarkly <team@launchdarkly.com>", |
@@ -429,4 +429,16 @@ /** | ||
* The returned Promise will be resolved once the client has either successfully initialized | ||
* or failed to initialize (e.g. due to an invalid environment key or a server error). | ||
* | ||
* or failed to initialize (e.g. due to an invalid environment key or a server error). It will | ||
* never be rejected. | ||
* | ||
* ``` | ||
* // using a Promise then() handler | ||
* client.waitUntilReady().then(() => { | ||
* doSomethingWithClient(); | ||
* }); | ||
* | ||
* // using async/await | ||
* await client.waitUntilReady(); | ||
* doSomethingWithClient(); | ||
* ``` | ||
* | ||
* If you want to distinguish between these success and failure conditions, use | ||
@@ -449,2 +461,24 @@ * [[waitForInitialization]] instead. | ||
* | ||
* ``` | ||
* // using Promise then() and catch() handlers | ||
* client.waitForInitialization().then(() => { | ||
* doSomethingWithSuccessfullyInitializedClient(); | ||
* }).catch(err => { | ||
* doSomethingForFailedStartup(err); | ||
* }); | ||
* | ||
* // using async/await | ||
* try { | ||
* await client.waitForInitialization(); | ||
* doSomethingWithSuccessfullyInitializedClient(); | ||
* } catch (err) { | ||
* doSomethingForFailedStartup(err); | ||
* } | ||
* ``` | ||
* | ||
* It is important that you handle the rejection case; otherwise it will become an unhandled Promise | ||
* rejection, which is a serious error on some platforms. The Promise is not created unless you | ||
* request it, so if you never call `waitForInitialization()` then you do not have to worry about | ||
* unhandled rejections. | ||
* | ||
* Note that you can also use event listeners ([[on]]) for the same purpose: the event `"initialized"` | ||
@@ -451,0 +485,0 @@ * indicates success, and `"failed"` indicates failure. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
559957
1008