launchdarkly-js-sdk-common
Advanced tools
Comparing version 3.1.0-beta3-diag to 3.1.0
@@ -5,2 +5,27 @@ # Change log | ||
## [3.1.0] - 2019-12-13 | ||
### Added: | ||
- Configuration options `wrapperName` and `wrapperVersion`. | ||
- Platform option `httpFallbackPing` (to be used for the browser image mechanism - see below). | ||
### Fixed: | ||
- When calling `identify`, the current user (as reported by `getUser()`) was being updated before the SDK had received the new flag values for that user, causing the client to be temporarily in an inconsistent state where flag evaluations would be associated with the wrong user in analytics events. Now, the current-user state will stay in sync with the flags and change only when they have finished changing. (Thanks, [edvinerikson](https://github.com/launchdarkly/js-sdk-common/pull/3)!) | ||
### Removed: | ||
- Logic for sending a one-way HTTP request in a browser by creating an image has been moved to the browser-specific code (`js-client-sdk`). | ||
## [3.0.0] - 2019-12-13 | ||
### Added: | ||
- Configuration property `eventCapacity`: the maximum number of analytics events (not counting evaluation counters) that can be held at once, to prevent the SDK from consuming unexpected amounts of memory in case an application generates events unusually rapidly. In JavaScript code this would not normally be an issue, since the SDK flushes events every two seconds by default, but you may wish to increase this value if you will intentionally be generating a high volume of custom or identify events. The default value is 100. | ||
### Changed: | ||
- (Breaking change) The `extraDefaults` parameter to the internal common `initialize` method is now `extraOptionDefs` and has a different format, allowing for more flexible validation. | ||
- The SDK now logs a warning if any configuration property has an inappropriate type, such as `baseUri:3` or `sendEvents:"no"`. For boolean properties, the SDK will still interpret the value in terms of truthiness, which was the previous behavior. For all other types, since there's no such commonly accepted way to coerce the type, it will fall back to the default setting for that property; previously, the behavior was undefined but most such mistakes would have caused the SDK to throw an exception at some later point. | ||
- Removed or updated some development dependencies that were causing vulnerability warnings. | ||
### Deprecated: | ||
- The `samplingInterval` configuration property was deprecated in the code in the previous minor version release, and in the changelog, but the deprecation notice was accidentally omitted from the documentation comments. It is hereby deprecated again. | ||
## [2.14.1] - 2019-11-04 | ||
@@ -7,0 +32,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,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ownKeys(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function _objectSpread2(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(n,!0).forEach(function(e){_defineProperty(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ownKeys(n).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function createCustomError(e){function t(e,t){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=t}return(t.prototype=new Error).name=e,t.prototype.constructor=t}Object.defineProperty(exports,"__esModule",{value:!0});var LDUnexpectedResponseError=createCustomError("LaunchDarklyUnexpectedResponseError"),LDInvalidEnvironmentIdError=createCustomError("LaunchDarklyInvalidEnvironmentIdError"),LDInvalidUserError=createCustomError("LaunchDarklyInvalidUserError"),LDInvalidEventKeyError=createCustomError("LaunchDarklyInvalidEventKeyError"),LDInvalidArgumentError=createCustomError("LaunchDarklyInvalidArgumentError"),LDFlagFetchError=createCustomError("LaunchDarklyFlagFetchError");function isHttpErrorRecoverable(e){return!(400<=e&&e<500)||(400===e||408===e||429===e)}for(var errors=Object.freeze({__proto__:null,LDUnexpectedResponseError:LDUnexpectedResponseError,LDInvalidEnvironmentIdError:LDInvalidEnvironmentIdError,LDInvalidUserError:LDInvalidUserError,LDInvalidEventKeyError:LDInvalidEventKeyError,LDInvalidArgumentError:LDInvalidArgumentError,LDFlagFetchError:LDFlagFetchError,isHttpErrorRecoverable:isHttpErrorRecoverable}),fromByteArray_1=fromByteArray,lookup=[],revLookup=[],code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;i<len;++i)lookup[i]=code[i],revLookup[code.charCodeAt(i)]=i;function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,t,n){for(var r,o=[],i=t;i<n;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var t,n=e.length,r=n%3,o=[],i=16383,a=0,s=n-r;a<s;a+=i)o.push(encodeChunk(e,a,s<a+i?s:a+i));return 1==r?(t=e[n-1],o.push(lookup[t>>2]+lookup[t<<4&63]+"==")):2==r&&(t=(e[n-2]<<8)+e[n-1],o.push(lookup[t>>10]+lookup[t>>4&63]+lookup[t<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){var r,o,i,a=isArray(t),s=isArray(n);if(a&&s){if((o=t.length)!=n.length)return!1;for(r=o;0!=r--;)if(!e(t[r],n[r]))return!1;return!0}if(a!=s)return!1;var u=t instanceof Date,c=n instanceof Date;if(u!=c)return!1;if(u&&c)return t.getTime()==n.getTime();var l=t instanceof RegExp,f=n instanceof RegExp;if(l!=f)return!1;if(l&&f)return t.toString()==n.toString();var d=keyList(t);if((o=d.length)!==keyList(n).length)return!1;for(r=o;0!=r--;)if(!hasProp.call(n,d[r]))return!1;for(r=o;0!=r--;)if(!e(t[i=d[r]],n[i]))return!1;return!0}return t!=t&&n!=n},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function btoa(e){var t=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(t))}function stringToBytes(e){for(var t=[],n=0;n<e.length;n++)t.push(e.charCodeAt(n));return t}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,t){return fastDeepEqual(e,t)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(e,t){var n=e.then(function(e){return t&&setTimeout(function(){t(null,e)},0),e},function(e){if(!t)return Promise.reject(e);setTimeout(function(){t(e,null)},0)});return t?void 0:n}function transformValuesToVersionedValues(e){var t={};for(var n in e)e.hasOwnProperty(n)&&(t[n]={value:e[n],version:0});return t}function transformVersionedValuesToValues(e){var t={};for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n].value);return t}function chunkUserEventsForUrl(e,t){for(var n,r=t.slice(0),o=[],i=e;0<r.length;){for(n=[];0<i;){var a=r.shift();if(!a)break;(i-=base64URLEncode(JSON.stringify(a)).length)<0&&0<n.length?r.unshift(a):n.push(a)}i=e,o.push(n)}return o}function getLDUserAgentString(e){var t=e.version||"3.1.0-beta3-diag";return e.userAgent+"/"+t}function getLDHeaders(e,t){if(t&&!t.sendLDHeaders)return{};var n={"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)};return t&&t.wrapperName&&(n["X-LaunchDarkly-Wrapper"]=t.wrapperVersion?t.wrapperName+"/"+t.wrapperVersion:t.wrapperName),n}function extend(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.reduce(function(e,t){return _objectSpread2({},e,{},t)},{})}function sanitizeUser(e){if(!e)return e;var t;for(var n in userAttrsToStringify){var r=userAttrsToStringify[n],o=e[r];void 0!==o&&"string"!=typeof o&&((t=t||_objectSpread2({},e))[r]=String(o))}return t||e}var utils=Object.freeze({__proto__:null,btoa:btoa,base64URLEncode:base64URLEncode,clone:clone,deepEquals:deepEquals,onNextTick:onNextTick,wrapPromiseCallback:wrapPromiseCallback,transformValuesToVersionedValues:transformValuesToVersionedValues,transformVersionedValuesToValues:transformVersionedValuesToValues,chunkUserEventsForUrl:chunkUserEventsForUrl,getLDUserAgentString:getLDUserAgentString,getLDHeaders:getLDHeaders,extend:extend,sanitizeUser:sanitizeUser}),MAX_URL_LENGTH=2e3;function EventSender(a,e,t){var n="/a/"+e+".gif",i=extend({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},getLDHeaders(a,t)),s=a.httpFallbackPing,u={};return u.sendChunk=function(e,r,t){var o=JSON.stringify(e);return t?function t(n){return a.httpRequest("POST",r,i,o).promise.then(function(e){if(e)return 400<=e.status&&isHttpErrorRecoverable(e.status)&&n?t(!1):function(e){var t={status:e.status},n=e.header("date");if(n){var r=Date.parse(n);r&&(t.serverTime=r)}return t}(e)}).catch(function(){return n?t(!1):Promise.reject()})}(!0).catch(function(){}):(s&&s(r+n+"?d="+base64URLEncode(o)),Promise.resolve())},u.sendEvents=function(e,t){if(!a.httpRequest)return Promise.resolve();var n,r=a.httpAllowsPost();n=r?[e]:chunkUserEventsForUrl(MAX_URL_LENGTH-t.length,e);for(var o=[],i=0;i<n.length;i++)o.push(u.sendChunk(n[i],t,r));return Promise.all(o)},u}function EventSummarizer(){var e={},a=0,s=0,u={};return e.summarizeEvent=function(e){if("feature"===e.kind){var t=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),n=u[t];n?n.count=n.count+1:u[t]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>s&&(s=e.creationDate)}},e.getSummary=function(){var e={},t=!0;for(var n in u){var r=u[n],o=e[r.key];o||(o={default:r.default,counters:[]},e[r.key]=o);var i={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),t=!1}return t?null:{startDate:a,endDate:s,features:e}},e.clearSummary=function(){s=a=0,u={}},e}function UserFilter(e){var t={},u=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},f={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return t.filterUser=function(e){if(!e)return null;function t(r,o){return Object.keys(r).reduce(function(e,t){var n=e;return o(t)&&(!function(e){return!l[e]&&(u||-1!==i.indexOf(e)||-1!==c.indexOf(e))}(t)?n[0][t]=r[t]:n[1][t]=!0),n},[{},{}])}var i=e.privateAttributeNames||[],n=t(e,function(e){return f[e]}),r=n[0],o=n[1];if(e.custom){var a=t(e.custom,function(){return!0});r.custom=a[0],o=extend({},o,a[1])}var s=Object.keys(o);return s.length&&(s.sort(),r.privateAttrs=s),r},t}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/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,t){return t?'"'+e+'" is deprecated, please use "'+t+'"':'"'+e+'" is deprecated'},httpErrorMessage=function(e,t,n){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+t+" - "+(isHttpErrorRecoverable(e)?n:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e,t){return"Error on stream connection: "+errorString(e)+", will continue retrying every "+t+" milliseconds."},unknownOption=function(e){return'Ignoring unknown config option "'+e+'"'},wrongOptionType=function(e,t,n){return'Config option "'+e+'" should be of type '+t+", got "+n+", using default value"},wrongOptionTypeBoolean=function(e,t){return'Config option "'+e+'" should be a boolean, got '+t+", converting to boolean"},optionBelowMinimum=function(e,t,n){return'Config option "'+e+'" was set to '+t+", changing to minimum value of "+n},debugPolling=function(e){return"polling for feature flags at "+e},debugStreamPing=function(){return"received ping message from stream"},debugStreamPut=function(){return"received streaming update for all flags"},debugStreamPatch=function(e){return'received streaming update for flag "'+e+'"'},debugStreamPatchIgnored=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},debugStreamDelete=function(e){return'received streaming deletion for flag "'+e+'"'},debugStreamDeleteIgnored=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},debugEnqueueingEvent=function(e){return'enqueueing "'+e+'" event'},debugPostingEvents=function(e){return"sending "+e+" events"},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});function EventProcessor(e,t,n){var r,o=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null,i=4<arguments.length&&void 0!==arguments[4]?arguments[4]:null,a={},s=(5<arguments.length&&void 0!==arguments[5]?arguments[5]:null)||EventSender(e,n,t),u=t.eventsUrl+"/events/bulk/"+n,c=EventSummarizer(),l=UserFilter(t),f=t.inlineUsersInEvents,d=t.samplingInterval,v=t.eventCapacity,g=t.flushInterval,p=t.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 t=!1,n=!1;if(c.summarizeEvent(e),"feature"===e.kind?E()&&(t=!!e.trackEvents,n=function(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>y&&e.debugEventsUntilDate>(new Date).getTime())}(e)):t=E(),t&&k(function(e){var t=extend({},e);return f||"identify"===e.kind?t.user=l.filterUser(e.user):(t.userKey=e.user.key,delete t.user),"feature"===e.kind&&(delete t.trackEvents,delete t.debugEventsUntilDate),t}(e)),n){var r=extend({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,k(r)}}},a.flush=function(){if(h)return Promise.resolve();var e=m,t=c.getSummary();return c.clearSummary(),t&&(t.kind="summary",e.push(t)),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(t){var e={},o={};return e.on=function(e,t,n){o[e]=o[e]||[],o[e]=o[e].concat({handler:t,context:n})},e.off=function(e,t,n){if(o[e])for(var r=0;r<o[e].length;r++)o[e][r].handler===t&&o[e][r].context===n&&(o[e]=o[e].slice(0,r).concat(o[e].slice(r+1)))},e.emit=function(e){if(o[e])for(var t=0;t<o[e].length;t++)o[e][t].handler.apply(o[e][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")?(t||console).error(e.message):this.emit("error",e))},e}function Store(n,r,o,i,a){var s={};function u(){var e="",t=i.getUser();return t&&(e=o||btoa(JSON.stringify(t))),"ld:"+r+":"+e}return s.loadFlags=function(){return n.get(u()).then(function(e){if(null==e)return null;try{var t=JSON.parse(e);if(t){var n=t.$schema;void 0===n||n<1?t=transformValuesToVersionedValues(t):delete t.$schema}return t}catch(e){return s.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},s.saveFlags=function(e){var t=extend({},e,{$schema:1});return n.set(u(),JSON.stringify(t)).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},s.clearFlags=function(){return n.clear(u()).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},s}function Stream(o,e,i,t,a){var s,u=e.streamUrl,c=e.logger,n={},l=u+"/eval/"+i,f=e.useReport,d=e.evaluationReasons,r=e.streamReconnectDelay,v=getLDHeaders(o,e),g=!1,p=null,m=null,y=null,h=null;function b(e){g||(c.warn(streamError(e,r)),g=!0),D(!1),S(),E(r)}function E(e){m||(e?m=setTimeout(k,e):k())}function k(){var e;m=null;var t="",n={headers:v};if(o.eventSourceFactory){for(var r in null!=a&&(t="h="+a),f?o.eventSourceAllowsReport?(e=l,n.method="REPORT",n.headers["Content-Type"]="application/json",n.body=JSON.stringify(y)):(e=u+"/ping/"+i,t=""):e=l+"/"+base64URLEncode(JSON.stringify(y)),d&&(t=t+(t?"&":"")+"withReasons=true"),e=e+(t?"?":"")+t,S(),c.info(streamConnecting(e)),s=(new Date).getTime(),p=o.eventSourceFactory(e,n),h)h.hasOwnProperty(r)&&p.addEventListener(r,h[r]);p.onerror=b}}function S(){p&&(c.info(streamClosing()),p.close(),p=null)}function D(e){s&&t&&t.recordStreamInit(s,!e,(new Date).getTime()-s),s=null}return n.connect=function(e,n){y=e,h={};function t(t){h[t]=function(e){D(!(g=!1)),n[t]&&n[t](e)}}for(var r in n||{})t(r);E()},n.disconnect=function(){clearTimeout(m),m=null,S()},n.isConnected=function(){return!!(p&&o.eventSourceIsActive&&o.eventSourceIsActive(p))},n}function promiseCoalescer(n){var r,o,i,a,e={addPromise:function(t,e){r=t,o&&o(),o=e,t.then(function(e){r===t&&(i(e),n&&n())},function(e){r===t&&(a(e),n&&n())})}};return e.resultPromise=new Promise(function(e,t){i=e,a=t}),e}var 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,t){if(!s.httpRequest)return new Promise(function(e,t){t(new LDFlagFetchError(httpUnavailable()))});var n=t?"REPORT":"GET",r=getLDHeaders(s,u);t&&(r["Content-Type"]="application/json");var o=v[e];o||(o=promiseCoalescer(function(){delete v[e]}),v[e]=o);var i=s.httpRequest(n,e,r,t),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 t=invalidContentType(e.header("content-type")||"");return Promise.reject(new LDFlagFetchError(t))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return o.addPromise(a,function(){i.cancel&&i.cancel()}),o.resultPromise}return e.fetchJSON=function(e){return g(c+e,null)},e.fetchFlagSettings=function(e,t){var n,r,o,i="";return l?(r=[c,"/sdk/evalx/",a,"/user"].join(""),o=JSON.stringify(e)):(n=base64URLEncode(JSON.stringify(e)),r=[c,"/sdk/evalx/",a,"/users/",n].join("")),t&&(i="h="+t),f&&(i=i+(i?"&":"")+"withReasons=true"),r=r+(i?"?":"")+i,d.debug(debugPolling(r)),g(r,o)},e}function Identity(e,t){var n,r={};return r.setUser=function(e){(n=sanitizeUser(e))&&t&&t(clone(n))},r.getUser=function(){return n?clone(n):null},e&&r.setUser(e),r}function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}for(var rngBrowser=createCommonjsModule(function(e){var t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(t){var n=new Uint8Array(16);e.exports=function(){return t(n),n}}else{var r=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),r[t]=e>>>((3&t)<<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,t){var n=t||0,r=byteToHex;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,t,n){var r=t&&n||0,o=t||[],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 t||bytesToUuid_1(o)}var v1_1=v1,ldUserIdKey="ld:$anonUserId";function UserValidator(r,o){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var n=clone(e);return null!==n.key&&void 0!==n.key?(n.key=n.key.toString(),Promise.resolve(n)):n.anonymous?(r?r.get(ldUserIdKey).catch(function(){return null}):Promise.resolve(null)).then(function(e){if(e)return n.key=e,n;var t=v1_1();return function(e){return r?r.set(ldUserIdKey,e).catch(function(){o.warn(localStorageUnavailableForUserId())}):Promise.resolve()}(n.key=t).then(function(){return n})}):Promise.reject(new LDInvalidUserError(invalidUser()))},e}var baseOptionDefs={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},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,t,n,r){var a=extend({logger:{default:r}},baseOptionDefs,n),o={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function s(e){onNextTick(function(){t&&t.maybeReportError(new LDInvalidArgumentError(e))})}var i,u,c,l,f=extend({},e||{});function d(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var t=_typeof(e);return"boolean"===t||"string"===t||"number"===t||"function"===t?t:"object"}}return i=f,Object.keys(o).forEach(function(e){if(void 0!==i[e]){var t=o[e];r&&r.warn(deprecated(e,t)),t&&(void 0===i[t]&&(i[t]=i[e]),delete i[e])}}),u=extend({},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 t=c[e];if(null!=t){var n=a[e];if(void 0===n)s(unknownOption(e));else{var r=n.type||d(n.default);if("any"!==r){var o=r.split("|"),i=d(t);o.indexOf(i)<0?"boolean"===r?(l[e]=!!t,s(wrongOptionTypeBoolean(e,i))):(s(wrongOptionType(e,r,i)),l[e]=n.default):"number"===i&&void 0!==n.minimum&&t<n.minimum&&(s(optionBelowMinimum(e,t,n.minimum)),l[e]=n.minimum)}}}}),f=l}var configuration=Object.freeze({__proto__:null,baseOptionDefs:baseOptionDefs,validate:validate}),baseOptionDefs$1=configuration.baseOptionDefs;function DiagnosticId(e){var t={diagnosticId:v1_1()};return e&&(t.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),t}function DiagnosticsAccumulator(e){var t,n,r,o;function i(e){t=e,r=n=0,o=[]}return i(e),{getProps:function(){return{dataSinceDate:t,droppedEvents:n,eventsInLastBatch:r,streamInits:o}},setProps:function(e){t=e.dataSinceDate,n=e.droppedEvents||0,r=e.eventsInLastBatch||0,o=e.streamInits||[]},incrementDroppedEvents:function(){n++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,t,n){var r={timestamp:e,durationMillis:n};t&&(r.failed=!0),o.push(r)},reset:i}}function DiagnosticsManager(t,e,n,r,o,i){var a,s,u=!!t.diagnosticUseCombinedEvent,c="ld:"+r+":$diagnostics",l=o.eventsUrl+"/events/diagnostic/"+r,f=o.diagnosticRecordingInterval,d=e,v=!!o.streaming,g={};function p(){return{sdk:function(){var e=_objectSpread2({},t.diagnosticSdkData);o.wrapperName&&(e.wrapperName=o.wrapperName);o.wrapperVersion&&(e.wrapperVersion=o.wrapperVersion);return e}(t.diagnosticSdkData),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:t.diagnosticPlatformData}}function m(e){n.sendEvents(e,l).then(function(){}).catch(function(){})}function y(){m(function(){var e=(new Date).getTime(),t=_objectSpread2({kind:u?"diagnostic-combined":"diagnostic",id:i,creationDate:e},d.getProps());return u&&(t=_objectSpread2({},t,{},p())),d.reset(e),t}()),s=setTimeout(y,f),a=(new Date).getTime(),u&&function(){if(t.localStorage){var e=_objectSpread2({},d.getProps());t.localStorage.set(c,JSON.stringify(e),function(){})}}()}return g.start=function(){u?function(n){if(!t.localStorage)return n(!1);t.localStorage.get(c).then(function(e){if(e)try{var t=JSON.parse(e);d.setProps(t),a=t.dataSinceDate}catch(e){}n(!0)}).catch(function(){n(!1)})}(function(e){if(e){var t=(a||0)+f,n=(new Date).getTime();t<=n?y():s=setTimeout(y,t-n)}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,t){var o,i=["debug","info","warn","error"];o=null!=t?""===t?"":t+" ":"LD: ";var a=0;e&&(a="none"===e?100:i.indexOf(e));var n={};function r(e,t,n){if(a<=e){var r=e<i.length?i[e]:"?";t(o+"["+r+"] "+n)}}return n.debug=function(e){return r(0,console.log,e)},n.info=function(e){return r(1,console.info,e)},n.warn=function(e){return r(2,console.warn,e)},n.error=function(e){return r(3,console.error,e)},n}var readyEvent="ready",successEvent="initialized",failedEvent="failed",changeEvent="change",internalChangeEvent="internal-change";function initialize(e,t,n,o,r){var a=function(){if(n&&n.logger)return n.logger;return r&&r.logger&&r.logger.default||createConsoleLogger("warn")}(),s=EventEmitter(a),f=validate(n,s,r,a),i=f.hash,u=f.sendEvents,c=e,l=EventSender(o,c),d=f.sendEvents&&!f.diagnosticOptOut,v=d?diagnosticEvents_1(c):null,g=d?diagnosticEvents_2((new Date).getTime()):null,p=d?diagnosticEvents_3(o,g,l,c,f,v):null;p&&p.start();var m,y,h,b,E=Stream(o,f,c,g,i),k=f.eventProcessor||EventProcessor(o,f,c,g,s,l),S=Requestor(o,f,c),D={},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){c&&(L&&L.enqueueEvent&&L.enqueueEvent(e)||(e.user?(I=!1,!u||O||o.isDoNotTrack()||(a.debug(debugEnqueueingEvent(e.kind)),k.enqueue(e))):I&&(a.warn(eventWithoutUser()),I=!1)))}function R(e,t,n,r){var o=T.getUser(),i=new Date,a=t?t.value:null;if(!f.allowFrequentDuplicateEvents){var s=JSON.stringify(a)+(o&&o.key?o.key:"")+e,u=D[s];if(u&&i-u<3e5)return;D[s]=i}var c={kind:"feature",key:e,user:o,value:a,variation:t?t.variationIndex:null,default:n,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)&&t&&(c.reason=t.reason),F(c)}function _(e,t,n,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=t)}else o={value:t,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return n&&R(e,o,t,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(),{ping:function(){a.debug(debugStreamPing()),S.fetchFlagSettings(T.getUser(),i).then(function(e){return A(e||{})}).catch(function(e){s.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var t=JSON.parse(e.data);a.debug(debugStreamPut()),A(t)},patch:function(e){var t=JSON.parse(e.data),n=w[t.key];if(!n||!n.version||!t.version||n.version<t.version){a.debug(debugStreamPatch(t.key));var r={},o=extend({},t);delete o.key;var i=j(w[t.key]=o);r[t.key]=n?{previous:n.value,current:i}:{current:i},V(r)}else a.debug(debugStreamPatchIgnored(t.key))},delete:function(e){var t=JSON.parse(e.data);if(!w[t.key]||w[t.key].version<t.version){a.debug(debugStreamDelete(t.key));var n={};w[t.key]&&!w[t.key].deleted&&(n[t.key]={previous:w[t.key].value}),w[t.key]={version:t.version,deleted:!0},V(n)}else a.debug(debugStreamDeleteIgnored(t.key))}})}function x(){y&&(E.disconnect(),y=!1)}function A(e){var t={};if(!e)return Promise.resolve();for(var n in w)w.hasOwnProperty(n)&&w[n]&&(e[n]&&!deepEquals(e[n].value,w[n].value)?t[n]={previous:w[n].value,current:j(e[n])}:e[n]&&!e[n].deleted||(t[n]={previous:w[n].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!w[r]||w[r].deleted)&&(t[r]={current:j(e[r])});return w=_objectSpread2({},e),V(t).catch(function(){})}function V(o){var e=Object.keys(o);if(0<e.length){var i={};e.forEach(function(e){var t=o[e].current,n=t?t.value:void 0,r=o[e].previous;s.emit(changeEvent+":"+e,n,r),i[e]=t?{current:n,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,c,i,T,a));var z=new Promise(function(e){var t=s.on(readyEvent,function(){s.off(readyEvent,t),e()})}),B=new Promise(function(e,t){var n=s.on(successEvent,function(){s.off(successEvent,n),e()}),r=s.on(failedEvent,function(e){s.off(failedEvent,r),t(e)})});if("string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(b?m=!0:a.warn(localStorageUnavailable())),"object"===_typeof(f.bootstrap)&&(w=function(n){var e=Object.keys(n),r="$flagsState",o=n[r];!o&&e.length&&a.warn(bootstrapOldFormat()),!1===n.$valid&&a.warn(bootstrapInvalid());var i={};return e.forEach(function(e){if(e!==r&&"$valid"!==e){var t={value:n[e]};o&&o[e]?t=extend(t,o[e]):t.version=0,i[e]=t}}),i}(f.bootstrap)),L){var K=L.getInitialState();K?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(t).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={},S.fetchFlagSettings(T.getUser(),i).then(function(e){return A(e||{})}).then(J).catch(function(e){$(new LDFlagFetchError(errorFetchingFlags(e)))})):(w=e,onNextTick(J),S.fetchFlagSettings(T.getUser(),i).then(function(e){return A(e)}).catch(function(e){return s.maybeReportError(e)}))}):S.fetchFlagSettings(T.getUser(),i).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){c=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,t,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(e){return T.setUser(e)}).then(function(){return S.fetchFlagSettings(T.getUser(),t)}).then(function(e){var t=transformVersionedValuesToValues(e);return e?A(e).then(function(){return t}):t}).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,t){return _(e,t,!0,!1).value},variationDetail:function(e,t){return _(e,t,!0,!0)},track:function(e,t,n){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!=t&&(r.data=t),null!=n&&(r.metricValue=n),F(r)}else s.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,t,n){M(e)?(h=!0,P&&q(),s.on(e,t,n)):s.on.apply(s,arguments)},off:function(e){if(s.off.apply(s,arguments),M(e)){var t=!1;s.getEvents().forEach(function(e){M(e)&&0<s.getEventListenerCount(e)&&(t=!0)}),t||(h=!1,y&&void 0===U&&x())}},setStreaming:function(e){var t=null===e?void 0:e;t!==U&&(U=t,q())},flush:function(e){return wrapPromiseCallback(u?k.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!w)return e;for(var t in w)w.hasOwnProperty(t)&&(e[t]=_(t,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(O)return wrapPromiseCallback(Promise.resolve(),e);function t(){O=!0,w={}}return wrapPromiseCallback(Promise.resolve().then(function(){if(x(),p&&p.stop(),u)return k.stop(),k.flush()}).then(t).catch(t),e)}},options:f,emitter:s,ident:T,logger:a,requestor:S,start:function(){u&&(p&&p.start(),k.start())},enqueueEvent:F,getFlagsInternal:function(){return w},getEnvironmentId:function(){return c},internalChangeEventName:internalChangeEvent}}var version="3.1.0-beta3-diag";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,u=t-r;a<u;a+=i)o.push(encodeChunk(e,a,u<a+i?u: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),u=isArray(t);if(a&&u){if((o=n.length)!=t.length)return!1;for(r=o;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var s=n instanceof Date,c=t instanceof Date;if(s!=c)return!1;if(s&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var v=keyList(n);if((o=v.length)!==keyList(t).length)return!1;for(r=o;0!=r--;)if(!hasProp.call(t,v[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=v[r]],t[i]))return!1;return!0}return n!=n&&t!=t},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.1.0";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}),MAX_URL_LENGTH=2e3;function EventSender(i,a,e,o){var u=a+"/events/bulk/"+e,t=a+"/a/"+e+".gif",s=i.httpFallbackPing,n={};function c(e,n){var r=JSON.stringify(e);return n?function n(t){var e=extend({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},getLDHeaders(i,o));return i.httpRequest("POST",u,e,r).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(){}):(s&&s(t+"?d="+base64URLEncode(r)),Promise.resolve())}return n.sendEvents=function(e){if(!i.httpRequest)return Promise.resolve();var n,t=i.httpAllowsPost();n=t?[e]:chunkUserEventsForUrl(MAX_URL_LENGTH-a.length,e);for(var r=[],o=0;o<n.length;o++)r.push(c(n[o],t));return Promise.all(r)},n}function EventSummarizer(){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],o=e[r.key];o||(o={default:r.default,counters:[]},e[r.key]=o);var i={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),n=!1}return n?null:{startDate:a,endDate:u,features:e}},e.clearSummary=function(){u=a=0,s={}},e}function UserFilter(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,o){return Object.keys(r).reduce(function(e,n){var t=e;return o(n)&&(!function(e){return!l[e]&&(s||-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 u=Object.keys(o);return u.length&&(u.sort(),r.privateAttrs=u),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"},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});function EventProcessor(e,n,t){var r,o=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null,i={},a=(4<arguments.length&&void 0!==arguments[4]?arguments[4]:null)||EventSender(e,n.eventsUrl,t,n),u=EventSummarizer(),s=UserFilter(n),c=n.inlineUsersInEvents,l=n.samplingInterval,f=n.eventCapacity,v=n.flushInterval,d=n.logger,g=[],p=0,m=!1,y=!1;function h(){return 0===l||0===Math.floor(Math.random()*l)}function b(e){g.length<f?(g.push(e),y=!1):y||(y=!0,d.warn(eventCapacityExceeded()))}return i.enqueue=function(e){if(!m){var n=!1,t=!1;if(u.summarizeEvent(e),"feature"===e.kind?h()&&(n=!!e.trackEvents,t=function(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>p&&e.debugEventsUntilDate>(new Date).getTime())}(e)):n=h(),n&&b(function(e){var n=extend({},e);return c||"identify"===e.kind?n.user=s.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),t){var r=extend({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,b(r)}}},i.flush=function(){if(m)return Promise.resolve();var e=g,n=u.getSummary();return u.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(g=[],d.debug(debugPostingEvents(e.length)),a.sendEvents(e).then(function(e){e&&(e.serverTime&&(p=e.serverTime),isHttpErrorRecoverable(e.status)||(m=!0),400<=e.status&&onNextTick(function(){o.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},i.start=function(){r=setTimeout(function e(){i.flush(),r=setTimeout(e,v)},v)},i.stop=function(){clearTimeout(r)},i}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 u={};function s(){var e="",n=i.getUser();return n&&(e=o||btoa(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=transformValuesToVersionedValues(n):delete n.$schema}return n}catch(e){return u.clearFlags().then(function(){return Promise.reject(e)})}}).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},u.saveFlags=function(e){var n=extend({},e,{$schema:1});return t.set(s(),JSON.stringify(n)).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},u.clearFlags=function(){return t.clear(s()).catch(function(e){return a.warn(localStorageUnavailable()),Promise.reject(e)})},u}function Stream(o,e,i,a){var u=e.streamUrl,s=e.logger,n={},c=u+"/eval/"+i,l=e.useReport,f=e.evaluationReasons,t=e.streamReconnectDelay,v=getLDHeaders(o,e),d=!1,g=null,p=null,m=null,y=null;function h(e){d||(s.warn(streamError(e,t)),d=!0),E(),b(t)}function b(e){p||(e?p=setTimeout(r,e):r())}function r(){var e;p=null;var n="",t={headers:v};if(o.eventSourceFactory){for(var r in null!=a&&(n="h="+a),l?o.eventSourceAllowsReport?(e=c,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(m)):(e=u+"/ping/"+i,n=""):e=c+"/"+base64URLEncode(JSON.stringify(m)),f&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,E(),s.info(streamConnecting(e)),g=o.eventSourceFactory(e,t),y)y.hasOwnProperty(r)&&g.addEventListener(r,y[r]);g.onerror=h}}function E(){g&&(s.info(streamClosing()),g.close(),g=null)}return n.connect=function(e,t){m=e,y={};function n(n){y[n]=function(e){d=!1,t[n]&&t[n](e)}}for(var r in t||{})n(r);b()},n.disconnect=function(){clearTimeout(p),p=null,E()},n.isConnected=function(){return!!(g&&o.eventSourceIsActive&&o.eventSourceIsActive(g))},n}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(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 LDFlagFetchError(httpUnavailable()))});var t=n?"REPORT":"GET",r=getLDHeaders(u,s);n&&(r["Content-Type"]="application/json");var o=d[e];o||(o=promiseCoalescer(function(){delete d[e]}),d[e]=o);var i=u.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,v.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}function createCommonjsModule(e,n){return e(n={exports:{}},n.exports),n.exports}for(var rngBrowser=createCommonjsModule(function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var t=n||0,r=byteToHex;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||_nodeId,a=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==i||null==a){var u=rngBrowser();null==i&&(i=_nodeId=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=_clockseq=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,l=s-_lastMSecs+(c-_lastNSecs)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||_lastMSecs<s)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=s,_clockseq=a;var f=(1e4*(268435455&(s+=122192928e5))+(_lastNSecs=c))%4294967296;o[r++]=f>>>24&255,o[r++]=f>>>16&255,o[r++]=f>>>8&255,o[r++]=255&f;var v=s/4294967296*1e4&268435455;o[r++]=v>>>8&255,o[r++]=255&v,o[r++]=v>>>24&15|16,o[r++]=v>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var d=0;d<6;++d)o[r+d]=i[d];return n||bytesToUuid_1(o)}var v1_1=v1,ldUserIdKey="ld:$anonUserId";function UserValidator(r,o){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new LDInvalidUserError(userNotSpecified()));var 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"},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 u(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var i,s,c,l,f=extend({},e||{});function v(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])}}),s=extend({},f),Object.keys(a).forEach(function(e){void 0!==s[e]&&null!==s[e]||(s[e]=a[e]&&a[e].default)}),l=extend({},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(unknownOption(e));else{var r=t.type||v(t.default);if("any"!==r){var o=r.split("|"),i=v(n);o.indexOf(i)<0?"boolean"===r?(l[e]=!!n,u(wrongOptionTypeBoolean(e,i))):(u(wrongOptionType(e,r,i)),l[e]=t.default):"number"===i&&void 0!==t.minimum&&n<t.minimum&&(u(optionBelowMinimum(e,n,t.minimum)),l[e]=t.minimum)}}}}),f=l}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,i,u,s,c=function(){if(t&&t.logger)return t.logger;return r&&r.logger&&r.logger.default||createConsoleLogger("warn")}(),l=EventEmitter(c),f=validate(t,l,r,c),v=f.hash,d=f.sendEvents,g=e,p=Stream(o,f,g,v),m=f.eventProcessor||EventProcessor(o,f,g,l),y=Requestor(o,f,g),h={},b={},E=f.streaming,k=!1,S=!1,w=!0,U=f.stateProvider,D=Identity(null,function(e){if(U)return;e&&L({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),P=UserValidator(o.localStorage,c);function L(e){g&&(U&&U.enqueueEvent&&U.enqueueEvent(e)||(e.user?(w=!1,!d||S||o.isDoNotTrack()||(c.debug(debugEnqueueingEvent(e.kind)),m.enqueue(e))):w&&(c.warn(eventWithoutUser()),w=!1)))}function O(e,n,t,r){var o=D.getUser(),i=new Date,a=n?n.value:null;if(!f.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(o&&o.key?o.key:"")+e,s=h[u];if(s&&i-s<3e5)return;h[u]=i}var c={kind:"feature",key:e,user:o,value:a,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()},l=b[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),L(c)}function I(e,n,t,r){var o;if(b&&b.hasOwnProperty(e)&&b[e]&&!b[e].deleted){var i=b[e];o=C(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&&O(e,o,n,r),o}function C(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function F(){i=!0,D.getUser()&&p.connect(D.getUser(),{ping:function(){c.debug(debugStreamPing()),y.fetchFlagSettings(D.getUser(),v).then(function(e){return R(e||{})}).catch(function(e){l.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var n=JSON.parse(e.data);c.debug(debugStreamPut()),R(n)},patch:function(e){var n=JSON.parse(e.data),t=b[n.key];if(!t||!t.version||!n.version||t.version<n.version){c.debug(debugStreamPatch(n.key));var r={},o=extend({},n);delete o.key;var i=C(b[n.key]=o);r[n.key]=t?{previous:t.value,current:i}:{current:i},j(r)}else c.debug(debugStreamPatchIgnored(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!b[n.key]||b[n.key].version<n.version){c.debug(debugStreamDelete(n.key));var t={};b[n.key]&&!b[n.key].deleted&&(t[n.key]={previous:b[n.key].value}),b[n.key]={version:n.version,deleted:!0},j(t)}else c.debug(debugStreamDeleteIgnored(n.key))}})}function T(){i&&(p.disconnect(),i=!1)}function R(e){var n={};if(!e)return Promise.resolve();for(var t in b)b.hasOwnProperty(t)&&b[t]&&(e[t]&&!deepEquals(e[t].value,b[t].value)?n[t]={previous:b[t].value,current:C(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:b[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!b[r]||b[r].deleted)&&(n[r]={current:C(e[r])});return b=_objectSpread2({},e),j(n).catch(function(){})}function j(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;l.emit(changeEvent+":"+e,t,r),i[e]=n?{current:t,previous:r}:{previous:r}}),l.emit(changeEvent,i),l.emit(internalChangeEvent,b),f.sendEventsOnlyForVariation||U||e.forEach(function(e){O(e,o[e].current)})}return a&&s?s.saveFlags(b).catch(function(){return null}):Promise.resolve()}function x(){var e=E||u&&void 0===E;e&&!i?F():!e&&i&&T()}function N(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}o.localStorage&&(s=new Store(o.localStorage,g,v,D,c));var _=new Promise(function(e){var n=l.on(readyEvent,function(){l.off(readyEvent,n),e()})}),A=new Promise(function(e,n){var t=l.on(successEvent,function(){l.off(successEvent,t),e()}),r=l.on(failedEvent,function(e){l.off(failedEvent,r),n(e)})});if("string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(s?a=!0:c.warn(localStorageUnavailable())),"object"===_typeof(f.bootstrap)&&(b=function(t){var e=Object.keys(t),r="$flagsState",o=t[r];!o&&e.length&&c.warn(bootstrapOldFormat()),!1===t.$valid&&c.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)),U){var V=U.getInitialState();V?q(V):U.on("init",q),U.on("update",function(e){e.user&&D.setUser(e.user);e.flags&&R(e.flags)})}else(e?P.validateUser(n).then(function(e){return D.setUser(e),"object"===_typeof(f.bootstrap)?z():a?s.loadFlags().catch(function(){return null}).then(function(e){return null==e?(b={},y.fetchFlagSettings(D.getUser(),v).then(function(e){return R(e||{})}).then(z).catch(function(e){K(new LDFlagFetchError(errorFetchingFlags(e)))})):(b=e,onNextTick(z),y.fetchFlagSettings(D.getUser(),v).then(function(e){return R(e)}).catch(function(e){return l.maybeReportError(e)}))}):y.fetchFlagSettings(D.getUser(),v).then(function(e){b=e||{},z()}).catch(function(e){b={},K(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(function(e){return l.maybeReportError(e)});function q(e){g=e.environment,D.setUser(e.user),b=_objectSpread2({},e.flags),onNextTick(z)}function z(){c.info(clientInitialized()),k=!0,x(),l.emit(readyEvent),l.emit(successEvent)}function K(e){l.maybeReportError(e),l.emit(failedEvent,e),l.emit(readyEvent)}return{client:{waitForInitialization:function(){return A},waitUntilReady:function(){return _},identify:function(e,n,t){return S?wrapPromiseCallback(Promise.resolve({}),t):U?(c.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(b)),t)):wrapPromiseCallback((a&&s?s.clearFlags():Promise.resolve()).then(function(){return P.validateUser(e)}).then(function(t){return y.fetchFlagSettings(t,n).then(function(e){var n=transformVersionedValuesToValues(e);return D.setUser(t),e?R(e).then(function(){return n}):n})}).then(function(e){return i&&F(),e}).catch(function(e){return l.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return D.getUser()},variation:function(e,n){return I(e,n,!0,!1).value},variationDetail:function(e,n){return I(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){o.customEventFilter&&!o.customEventFilter(e)&&c.warn(unknownCustomEventKey(e));var r={kind:"custom",key:e,user:D.getUser(),url:o.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),L(r)}else l.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},on:function(e,n,t){N(e)?(u=!0,k&&x(),l.on(e,n,t)):l.on.apply(l,arguments)},off:function(e){if(l.off.apply(l,arguments),N(e)){var n=!1;l.getEvents().forEach(function(e){N(e)&&0<l.getEventListenerCount(e)&&(n=!0)}),n||(u=!1,i&&void 0===E&&T())}},setStreaming:function(e){var n=null===e?void 0:e;n!==E&&(E=n,x())},flush:function(e){return wrapPromiseCallback(d?m.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!b)return e;for(var n in b)b.hasOwnProperty(n)&&(e[n]=I(n,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(S)return wrapPromiseCallback(Promise.resolve(),e);function n(){S=!0,b={}}return wrapPromiseCallback(Promise.resolve().then(function(){if(T(),d)return m.stop(),m.flush()}).then(n).catch(n),e)}},options:f,emitter:l,ident:D,logger:c,requestor:y,start:function(){d&&m.start()},enqueueEvent:L,getFlagsInternal:function(){return b},getEnvironmentId:function(){return g},internalChangeEventName:internalChangeEvent}}var version="3.1.0";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=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},S=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function O(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 O(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function U(e){return JSON.parse(JSON.stringify(e))}function I(e,n){return D(e,n)}function j(e){setTimeout(e,0)}function R(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 T(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function N(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function F(e,n){for(var t,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 C(e){var n=e.version||"3.1.0-beta3-diag";return e.userAgent+"/"+n}function L(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":C(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function A(){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 x(e){if(!e)return e;var n;for(var t in S){var i=S[t],o=e[i];void 0!==o&&"string"!=typeof o&&((n=n||r({},e))[i]=String(o))}return n||e}var V=Object.freeze({__proto__:null,btoa:O,base64URLEncode:P,clone:U,deepEquals:I,onNextTick:j,wrapPromiseCallback:R,transformValuesToVersionedValues:T,transformVersionedValuesToValues:N,chunkUserEventsForUrl:F,getLDUserAgentString:C,getLDHeaders:L,extend:A,sanitizeUser:x}),_=2e3;function q(e,n,t){var r="/a/"+n+".gif",i=A({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},L(e,t)),o=e.httpFallbackPing,a={};return a.sendChunk=function(n,t,a){var u=JSON.stringify(n);return a?function n(r){return e.httpRequest("POST",t,i,u).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(u)),Promise.resolve())},a.sendEvents=function(n,t){if(!e.httpRequest)return Promise.resolve();var r,i=e.httpAllowsPost();r=i?[n]:F(_-t.length,n);for(var o=[],u=0;u<r.length;u++)o.push(a.sendChunk(r[u],t,i));return Promise.all(o)},a}function J(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=A({},c,l[1])}var f=Object.keys(c);return f.length&&(f.sort(),s.privateAttrs=f),s},n}function z(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var M=function(){return"LaunchDarkly client initialized"},K=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",B=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},$=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"},G=function(e){return'Expected application/json content type but got "'+e+'"'},H=function(){return"localStorage is unavailable"},X=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},W=function(e){return"network error"+(e?" ("+e+")":"")},Q=function(e){return'Custom event "'+e+'" does not exist'},Y=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+K},Z=function(){return"No environment/client-side ID was specified."+K},ee=function(e){return"Error fetching flag settings: "+z(e)},ne=function(){return"No user specified."+K},te=function(){return"Invalid user specified."+K},re=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+K},ie=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},oe=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},ae=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(f(e)?t:"giving up permanently")},ue=function(){return"Cannot make HTTP requests in this environment."+K},se=function(){return"identify() has no effect here; it must be called on the main client instance"},ce=function(){return"Closing stream connection"},le=function(e){return"Opening stream connection to "+e},fe=function(e,n){return"Error on stream connection: "+z(e)+", will continue retrying every "+n+" milliseconds."},ve=function(e){return'Ignoring unknown config option "'+e+'"'},de=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},ge=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},pe=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},me=function(e){return"polling for feature flags at "+e},he=function(){return"received ping message from stream"},ye=function(){return"received streaming update for all flags"},be=function(e){return'received streaming update for flag "'+e+'"'},ke=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},Ee=function(e){return'received streaming deletion for flag "'+e+'"'},we=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},De=function(e){return'enqueueing "'+e+'" event'},Se=function(e){return"sending "+e+" events"},Oe=Object.freeze({__proto__:null,clientInitialized:M,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:B,eventWithoutUser:$,invalidContentType:G,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:H,localStorageUnavailableForUserId:X,networkError:W,unknownCustomEventKey:Q,environmentNotFound:Y,environmentNotSpecified:Z,errorFetchingFlags:ee,userNotSpecified:ne,invalidUser:te,bootstrapOldFormat:re,bootstrapInvalid:ie,deprecated:oe,httpErrorMessage:ae,httpUnavailable:ue,identifyDisabled:se,streamClosing:ce,streamConnecting:le,streamError:fe,unknownOption:ve,wrongOptionType:de,wrongOptionTypeBoolean:ge,optionBelowMinimum:pe,debugPolling:me,debugStreamPing:he,debugStreamPut:ye,debugStreamPatch:be,debugStreamPatchIgnored:ke,debugStreamDelete:Ee,debugStreamDeleteIgnored:we,debugEnqueueingEvent:De,debugPostingEvents:Se});function Pe(e,n,t){var r,i,a,u,s,c=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,v=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,d={},g=v||q(e,t,n),p=n.eventsUrl+"/events/bulk/"+t,m=(i=0,a=0,u={},(r={}).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===i||e.creationDate<i)&&(i=e.creationDate),e.creationDate>a&&(a=e.creationDate)}},r.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 s={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(s.variation=r.variation),r.version?s.version=r.version:s.unknown=!0,o.counters.push(s),n=!1}return n?null:{startDate:i,endDate:a,features:e}},r.clearSummary=function(){i=0,a=0,u={}},r),h=J(n),y=n.inlineUsersInEvents,b=n.samplingInterval,k=n.eventCapacity,E=n.flushInterval,w=n.logger,D=[],S=0,O=!1,P=!1;function U(){return 0===b||0===Math.floor(Math.random()*b)}function I(e){D.length<k?(D.push(e),P=!1):(P||(P=!0,w.warn(B())),c&&c.incrementDroppedEvents())}return d.enqueue=function(e){if(!O){var n,t=!1,r=!1;if(m.summarizeEvent(e),"feature"===e.kind?U()&&(t=!!e.trackEvents,r=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>S&&n.debugEventsUntilDate>(new Date).getTime()):t=U(),t&&I(function(e){var n=A({},e);return y||"identify"===e.kind?n.user=h.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),r){var i=A({},e,{kind:"debug"});delete i.trackEvents,delete i.debugEventsUntilDate,delete i.variation,I(i)}}},d.flush=function(){if(O)return Promise.resolve();var e=D,n=m.getSummary();return m.clearSummary(),n&&(n.kind="summary",e.push(n)),c&&c.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(D=[],w.debug(Se(e.length)),g.sendEvents(e,p).then((function(e){e&&(e.serverTime&&(S=e.serverTime),f(e.status)||(O=!0),e.status>=400&&j((function(){l.maybeReportError(new o(ae(e.status,"event posting","some events were dropped")))})))})))},d.start=function(){s=setTimeout((function e(){d.flush(),s=setTimeout(e,E)}),E)},d.stop=function(){clearTimeout(s)},d}function Ue(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 Ie(e,n,t,r,i){var o={};function a(){var e="",i=r.getUser();return i&&(e=t||O(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=T(n):delete n.$schema}return n}catch(e){return o.clearFlags().then((function(){return Promise.reject(e)}))}})).catch((function(e){return i.warn(H()),Promise.reject(e)}))},o.saveFlags=function(n){var t=A({},n,{$schema:1});return e.set(a(),JSON.stringify(t)).catch((function(e){return i.warn(H()),Promise.reject(e)}))},o.clearFlags=function(){return e.clear(a()).catch((function(e){return i.warn(H()),Promise.reject(e)}))},o}function je(e,n,t,r,i){var o,a=n.streamUrl,u=n.logger,s={},c=a+"/eval/"+t,l=n.useReport,f=n.evaluationReasons,v=n.streamReconnectDelay,d=L(e,n),g=!1,p=null,m=null,h=null,y=null;function b(e){g||(u.warn(fe(e,v)),g=!0),D(!1),w(),k(v)}function k(e){m||(e?m=setTimeout(E,e):E())}function E(){var n;m=null;var r="",s={headers:d};if(e.eventSourceFactory){for(var v in null!=i&&(r="h="+i),l?e.eventSourceAllowsReport?(n=c,s.method="REPORT",s.headers["Content-Type"]="application/json",s.body=JSON.stringify(h)):(n=a+"/ping/"+t,r=""):n=c+"/"+P(JSON.stringify(h)),f&&(r=r+(r?"&":"")+"withReasons=true"),n=n+(r?"?":"")+r,w(),u.info(le(n)),o=(new Date).getTime(),p=e.eventSourceFactory(n,s),y)y.hasOwnProperty(v)&&p.addEventListener(v,y[v]);p.onerror=b}}function w(){p&&(u.info(ce()),p.close(),p=null)}function D(e){o&&r&&r.recordStreamInit(o,!e,(new Date).getTime()-o),o=null}return s.connect=function(e,n){h=e,y={};var t=function(e){y[e]=function(t){g=!1,D(!0),n[e]&&n[e](t)}};for(var r in n||{})t(r);k()},s.disconnect=function(){clearTimeout(m),m=null,w()},s.isConnected=function(){return!!(p&&e.eventSourceIsActive&&e.eventSourceIsActive(p))},s}var Re="application/json";function Te(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(ue()))}));var i=r?"REPORT":"GET",o=L(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(Re))return JSON.parse(e.body);var n=G(e.header("content-type")||"");return Promise.reject(new l(n))}return Promise.reject(function(e){return 404===e.status?new a(Y()):new l(ee(e.statusText||String(e.status)))}(e))}),(function(e){return Promise.reject(new l(W(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(me(s)),f(s,c)},s}for(var Ne=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}}})),Fe=[],Ce=0;Ce<256;++Ce)Fe[Ce]=(Ce+256).toString(16).substr(1);var Le,Ae,xe=function(e,n){var t=n||0,r=Fe;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("")},Ve=0,_e=0;var qe=function(e,n,t){var r=n&&t||0,i=n||[],o=(e=e||{}).node||Le,a=void 0!==e.clockseq?e.clockseq:Ae;if(null==o||null==a){var u=Ne();null==o&&(o=Le=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=Ae=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:_e+1,l=s-Ve+(c-_e)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||s>Ve)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Ve=s,_e=c,Ae=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||xe(i)},Je="ld:$anonUserId";function ze(e,n){var t={};return t.validateUser=function(t){if(!t)return Promise.reject(new u(ne()));var r=U(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get(Je).catch((function(){return null})):Promise.resolve(null)).then((function(t){if(t)return r.key=t,r;var i=qe();return r.key=i,function(t){return e?e.set(Je,t).catch((function(){n.warn(X())})):Promise.resolve()}(i).then((function(){return r}))})):Promise.reject(new u(te()))},t}var Me={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},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(n,t,r,i){var o=A({logger:{default:i}},Me,r),a={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){j((function(){t&&t.maybeReportError(new c(e))}))}var s=A({},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(oe(e,t)),t&&(void 0===n[t]&&(n[t]=n[e]),delete n[e])}}))}(s),s=function(n){var t=A({},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(ve(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(ge(e,l))):(u(de(e,s,l)),t[e]=a.default):"number"===l&&void 0!==a.minimum&&i<a.minimum&&(u(pe(e,i,a.minimum)),t[e]=a.minimum)}}}})),t}(s=function(e){var n=A({},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 Be=Object.freeze({__proto__:null,baseOptionDefs:Me,validate:Ke}).baseOptionDefs;var $e=function(e){var n={diagnosticId:qe()};return e&&(n.sdkKeySuffix=e.length>6?e.substring(e.length-6):e),n},Ge=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,durationMillis:t};n&&(r.failed=!0),i.push(r)},reset:o}},He=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(e.diagnosticSdkData),configuration:(n={customBaseURI:o.baseUrl!==Be.baseUrl.default,customStreamURI:o.streamUrl!==Be.streamUrl.default,customEventsURI:o.eventsUrl!==Be.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){t.sendEvents(e,f).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 Xe(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}var We="ready",Qe="initialized",Ye="failed",Ze="change",en="internal-change";function nn(n,t,i,o,u){var c=function(){if(i&&i.logger)return i.logger;return u&&u.logger&&u.logger.default||Xe("warn")}(),f=Ue(c),v=Ke(i,f,u,c),d=v.hash,g=v.sendEvents,p=n,m=q(o,p),h=v.sendEvents&&!v.diagnosticOptOut,y=h?$e(p):null,b=h?Ge((new Date).getTime()):null,k=h?He(o,b,m,p,v,y):null;k&&k.start();var E,w,D,S,O=je(o,v,p,b,d),P=v.eventProcessor||Pe(o,v,p,b,f,m),T=Te(o,v,p),F={},C={},L=v.streaming,V=!1,_=!1,J=!0,z=v.stateProvider,K=function(e,n){var t,r={};return r.setUser=function(e){(t=x(e))&&n&&n(U(t))},r.getUser=function(){return t?U(t):null},e&&r.setUser(e),r}(null,(function(e){if(z)return;e&&G({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})})),B=ze(o.localStorage,c);function G(e){p&&(z&&z.enqueueEvent&&z.enqueueEvent(e)||(e.user?(J=!1,!g||_||o.isDoNotTrack()||(c.debug(De(e.kind)),P.enqueue(e))):J&&(c.warn($()),J=!1)))}function X(e,n,t,r){var i=K.getUser(),o=new Date,a=n?n.value:null;if(!v.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(i&&i.key?i.key:"")+e,s=F[u];if(s&&o-s<3e5)return;F[u]=o}var c={kind:"feature",key:e,user:i,value:a,variation:n?n.variationIndex:null,default:t,creationDate:o.getTime()},l=C[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),G(c)}function W(e,n,t,r){var i;if(C&&C.hasOwnProperty(e)&&C[e]&&!C[e].deleted){var o=C[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&&X(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 ne(){w=!0,K.getUser()&&O.connect(K.getUser(),{ping:function(){c.debug(he()),T.fetchFlagSettings(K.getUser(),d).then((function(e){return oe(e||{})})).catch((function(e){f.maybeReportError(new l(ee(e)))}))},put:function(e){var n=JSON.parse(e.data);c.debug(ye()),oe(n)},patch:function(e){var n=JSON.parse(e.data),t=C[n.key];if(!t||!t.version||!n.version||t.version<n.version){c.debug(be(n.key));var r={},i=A({},n);delete i.key,C[n.key]=i;var o=Y(i);r[n.key]=t?{previous:t.value,current:o}:{current:o},ae(r)}else c.debug(ke(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!C[n.key]||C[n.key].version<n.version){c.debug(Ee(n.key));var t={};C[n.key]&&!C[n.key].deleted&&(t[n.key]={previous:C[n.key].value}),C[n.key]={version:n.version,deleted:!0},ae(t)}else c.debug(we(n.key))}})}function te(){w&&(O.disconnect(),w=!1)}function oe(e){var n={};if(!e)return Promise.resolve();for(var t in C)C.hasOwnProperty(t)&&C[t]&&(e[t]&&!I(e[t].value,C[t].value)?n[t]={previous:C[t].value,current:Y(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:C[t].value}));for(var i in e)e.hasOwnProperty(i)&&e[i]&&(!C[i]||C[i].deleted)&&(n[i]={current:Y(e[i])});return C=r({},e),ae(n).catch((function(){}))}function ae(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;f.emit(Ze+":"+n,i,o),t[n]=r?{current:i,previous:o}:{previous:o}})),f.emit(Ze,t),f.emit(en,C),v.sendEventsOnlyForVariation||z||n.forEach((function(n){X(n,e[n].current)}))}return E&&S?S.saveFlags(C).catch((function(){return null})):Promise.resolve()}function ue(){var e=L||D&&void 0===L;e&&!w?ne():!e&&w&&te(),k&&k.setStreaming(e)}function ce(e){return e===Ze||e.substr(0,Ze.length+1)===Ze+":"}o.localStorage&&(S=new Ie(o.localStorage,p,d,K,c));var le=new Promise((function(e){var n=f.on(We,(function(){f.off(We,n),e()}))})),fe=new Promise((function(e,n){var t=f.on(Qe,(function(){f.off(Qe,t),e()})),r=f.on(Ye,(function(e){f.off(Ye,r),n(e)}))}));if("string"==typeof v.bootstrap&&"LOCALSTORAGE"===v.bootstrap.toUpperCase()&&(S?E=!0:c.warn(H())),"object"===e(v.bootstrap)&&(C=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&c.warn(re()),!1===e.$valid&&c.warn(ie());var r={};return n.forEach((function(n){if("$flagsState"!==n&&"$valid"!==n){var i={value:e[n]};t&&t[n]?i=A(i,t[n]):i.version=0,r[n]=i}})),r}(v.bootstrap)),z){var ve=z.getInitialState();ve?de(ve):z.on("init",de),z.on("update",(function(e){e.user&&K.setUser(e.user);e.flags&&oe(e.flags)}))}else(function(){if(!n)return Promise.reject(new a(Z()));return B.validateUser(t).then((function(n){return K.setUser(n),"object"===e(v.bootstrap)?ge():E?S.loadFlags().catch((function(){return null})).then((function(e){return null==e?(C={},T.fetchFlagSettings(K.getUser(),d).then((function(e){return oe(e||{})})).then(ge).catch((function(e){pe(new l(ee(e)))}))):(C=e,j(ge),T.fetchFlagSettings(K.getUser(),d).then((function(e){return oe(e)})).catch((function(e){return f.maybeReportError(e)})))})):T.fetchFlagSettings(K.getUser(),d).then((function(e){C=e||{},ge()})).catch((function(e){C={},pe(e)}))}))})().catch((function(e){return f.maybeReportError(e)}));function de(e){p=e.environment,K.setUser(e.user),C=r({},e.flags),j(ge)}function ge(){c.info(M()),V=!0,ue(),f.emit(We),f.emit(Qe)}function pe(e){f.maybeReportError(e),f.emit(Ye,e),f.emit(We)}return{client:{waitForInitialization:function(){return fe},waitUntilReady:function(){return le},identify:function(e,n,t){return _?R(Promise.resolve({}),t):z?(c.warn(se()),R(Promise.resolve(N(C)),t)):R((E&&S?S.clearFlags():Promise.resolve()).then((function(){return B.validateUser(e)})).then((function(e){return K.setUser(e)})).then((function(){return T.fetchFlagSettings(K.getUser(),n)})).then((function(e){var n=N(e);return e?oe(e).then((function(){return n})):n})).then((function(e){return w&&ne(),e})).catch((function(e){return f.maybeReportError(e),Promise.reject(e)})),t)},getUser:function(){return K.getUser()},variation:function(e,n){return W(e,n,!0,!1).value},variationDetail:function(e,n){return W(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){o.customEventFilter&&!o.customEventFilter(e)&&c.warn(Q(e));var r={kind:"custom",key:e,user:K.getUser(),url:o.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),G(r)}else f.maybeReportError(new s(Q(e)))},on:function(e,n,t){ce(e)?(D=!0,V&&ue(),f.on(e,n,t)):f.on.apply(f,arguments)},off:function(e){if(f.off.apply(f,arguments),ce(e)){var n=!1;f.getEvents().forEach((function(e){ce(e)&&f.getEventListenerCount(e)>0&&(n=!0)})),n||(D=!1,w&&void 0===L&&te())}},setStreaming:function(e){var n=null===e?void 0:e;n!==L&&(L=n,ue())},flush:function(e){return R(g?P.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!C)return e;for(var n in C)C.hasOwnProperty(n)&&(e[n]=W(n,null,!v.sendEventsOnlyForVariation).value);return e},close:function(e){if(_)return R(Promise.resolve(),e);var n=function(){_=!0,C={}};return R(Promise.resolve().then((function(){if(te(),k&&k.stop(),g)return P.stop(),P.flush()})).then(n).catch(n),e)}},options:v,emitter:f,ident:K,logger:c,requestor:T,start:function(){g&&(k&&k.start(),P.start())},enqueueEvent:G,getFlagsInternal:function(){return C},getEnvironmentId:function(){return p},internalChangeEventName:en}}var tn="3.1.0-beta3-diag";export{Xe as createConsoleLogger,v as errors,nn as initialize,Oe as messages,V as utils,tn 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 o=null!=arguments[r]?arguments[r]:{};r%2?t(o,!0).forEach((function(t){n(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):t(o).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(o,n))}))}return e}function o(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 i=o("LaunchDarklyUnexpectedResponseError"),a=o("LaunchDarklyInvalidEnvironmentIdError"),u=o("LaunchDarklyInvalidUserError"),c=o("LaunchDarklyInvalidEventKeyError"),s=o("LaunchDarklyInvalidArgumentError"),l=o("LaunchDarklyFlagFetchError");function f(e){return!(e>=400&&e<500)||(400===e||408===e||429===e)}for(var v=Object.freeze({__proto__:null,LDUnexpectedResponseError:i,LDInvalidEnvironmentIdError:a,LDInvalidUserError:u,LDInvalidEventKeyError:c,LDInvalidArgumentError:s,LDFlagFetchError:l,isHttpErrorRecoverable:f}),d=function(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(b(e,i,i+16383>a?a:i+16383));1===r?(n=e[t-1],o.push(g[n>>2]+g[n<<4&63]+"==")):2===r&&(n=(e[t-2]<<8)+e[t-1],o.push(g[n>>10]+g[n>>4&63]+g[n<<2&63]+"="));return o.join("")},g=[],p=[],m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",y=0,h=m.length;y<h;++y)g[y]=m[y],p[m.charCodeAt(y)]=y;function b(e,n,t){for(var r,o,i=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),i.push(g[(o=r)>>18&63]+g[o>>12&63]+g[o>>6&63]+g[63&o]);return i.join("")}p["-".charCodeAt(0)]=62,p["_".charCodeAt(0)]=63;var k=Array.isArray,E=Object.keys,w=Object.prototype.hasOwnProperty,O=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,o,i,a=k(n),u=k(t);if(a&&u){if((o=n.length)!=t.length)return!1;for(r=o;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var c=n instanceof Date,s=t instanceof Date;if(c!=s)return!1;if(c&&s)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var v=E(n);if((o=v.length)!==E(t).length)return!1;for(r=o;0!=r--;)if(!w.call(t,v[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=v[r]],t[i]))return!1;return!0}return n!=n&&t!=t},P=["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 D(e){return S(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function U(e){return JSON.parse(JSON.stringify(e))}function j(e,n){return O(e,n)}function R(e){setTimeout(e,0)}function N(e,n){var t=e.then((function(e){return n&&setTimeout((function(){n(null,e)}),0),e}),(function(e){if(!n)return Promise.reject(e);setTimeout((function(){n(e,null)}),0)}));return n?void 0:t}function I(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]={value:e[t],version:0});return n}function T(e){var n={};for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t].value);return n}function F(e,n){for(var t,r=n.slice(0),o=[],i=e;r.length>0;){for(t=[];i>0;){var a=r.shift();if(!a)break;(i-=D(JSON.stringify(a)).length)<0&&t.length>0?r.unshift(a):t.push(a)}i=e,o.push(t)}return o}function C(e){var n=e.version||"3.1.0";return e.userAgent+"/"+n}function A(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":C(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 x(e){if(!e)return e;var n;for(var t in P){var o=P[t],i=e[o];void 0!==i&&"string"!=typeof i&&((n=n||r({},e))[o]=String(i))}return n||e}var q=Object.freeze({__proto__:null,btoa:S,base64URLEncode:D,clone:U,deepEquals:j,onNextTick:R,wrapPromiseCallback:N,transformValuesToVersionedValues:I,transformVersionedValuesToValues:T,chunkUserEventsForUrl:F,getLDUserAgentString:C,getLDHeaders:A,extend:L,sanitizeUser:x}),V=2e3;function _(e,n,t,r){var o=n+"/events/bulk/"+t,i=n+"/a/"+t+".gif",a=e.httpFallbackPing,u={};function c(n,t){var u=JSON.stringify(n);return t?function n(t){var i=L({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},A(e,r));return e.httpRequest("POST",o,i,u).promise.then((function(e){if(e)return e.status>=400&&f(e.status)&&t?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)})).catch((function(){return t?n(!1):Promise.reject()}))}(!0).catch((function(){})):(a&&a(i+"?d="+D(u)),Promise.resolve())}return u.sendEvents=function(t){if(!e.httpRequest)return Promise.resolve();var r,o=e.httpAllowsPost();r=o?[t]:F(V-n.length,t);for(var i=[],a=0;a<r.length;a++)i.push(c(r[a],o));return Promise.all(i)},u}function J(e){var n={},t=e.allAttributesPrivate,r=e.privateAttributeNames||[],o={key:!0,custom:!0,anonymous:!0},i={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;var n=e.privateAttributeNames||[],a=function(e,i){return Object.keys(e).reduce((function(a,u){var c=a;return i(u)&&(!function(e){return!o[e]&&(t||-1!==n.indexOf(e)||-1!==r.indexOf(e))}(u)?c[0][u]=e[u]:c[1][u]=!0),c}),[{},{}])},u=a(e,(function(e){return i[e]})),c=u[0],s=u[1];if(e.custom){var l=a(e.custom,(function(){return!0}));c.custom=l[0],s=L({},s,l[1])}var f=Object.keys(s);return f.length&&(f.sort(),c.privateAttrs=f),c},n}function z(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var K=function(){return"LaunchDarkly client initialized"},$=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",M=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},H=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"},B=function(e){return'Expected application/json content type but got "'+e+'"'},G=function(){return"localStorage is unavailable"},X=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},W=function(e){return"network error"+(e?" ("+e+")":"")},Q=function(e){return'Custom event "'+e+'" does not exist'},Y=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+$},Z=function(){return"No environment/client-side ID was specified."+$},ee=function(e){return"Error fetching flag settings: "+z(e)},ne=function(){return"No user specified."+$},te=function(){return"Invalid user specified."+$},re=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+$},oe=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},ie=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},ae=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(f(e)?t:"giving up permanently")},ue=function(){return"Cannot make HTTP requests in this environment."+$},ce=function(){return"identify() has no effect here; it must be called on the main client instance"},se=function(){return"Closing stream connection"},le=function(e){return"Opening stream connection to "+e},fe=function(e,n){return"Error on stream connection: "+z(e)+", will continue retrying every "+n+" milliseconds."},ve=function(e){return'Ignoring unknown config option "'+e+'"'},de=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},ge=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},pe=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},me=function(e){return"polling for feature flags at "+e},ye=function(){return"received ping message from stream"},he=function(){return"received streaming update for all flags"},be=function(e){return'received streaming update for flag "'+e+'"'},ke=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},Ee=function(e){return'received streaming deletion for flag "'+e+'"'},we=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},Oe=function(e){return'enqueueing "'+e+'" event'},Pe=function(e){return"sending "+e+" events"},Se=Object.freeze({__proto__:null,clientInitialized:K,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:M,eventWithoutUser:H,invalidContentType:B,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:G,localStorageUnavailableForUserId:X,networkError:W,unknownCustomEventKey:Q,environmentNotFound:Y,environmentNotSpecified:Z,errorFetchingFlags:ee,userNotSpecified:ne,invalidUser:te,bootstrapOldFormat:re,bootstrapInvalid:oe,deprecated:ie,httpErrorMessage:ae,httpUnavailable:ue,identifyDisabled:ce,streamClosing:se,streamConnecting:le,streamError:fe,unknownOption:ve,wrongOptionType:de,wrongOptionTypeBoolean:ge,optionBelowMinimum:pe,debugPolling:me,debugStreamPing:ye,debugStreamPut:he,debugStreamPatch:be,debugStreamPatchIgnored:ke,debugStreamDelete:Ee,debugStreamDeleteIgnored:we,debugEnqueueingEvent:Oe,debugPostingEvents:Pe});function De(e,n,t){var r,o,a,u,c,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,v={},d=l||_(e,n.eventsUrl,t,n),g=(o=0,a=0,u={},(r={}).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===o||e.creationDate<o)&&(o=e.creationDate),e.creationDate>a&&(a=e.creationDate)}},r.getSummary=function(){var e={},n=!0;for(var t in u){var r=u[t],i=e[r.key];i||(i={default:r.default,counters:[]},e[r.key]=i);var c={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(c.variation=r.variation),r.version?c.version=r.version:c.unknown=!0,i.counters.push(c),n=!1}return n?null:{startDate:o,endDate:a,features:e}},r.clearSummary=function(){o=0,a=0,u={}},r),p=J(n),m=n.inlineUsersInEvents,y=n.samplingInterval,h=n.eventCapacity,b=n.flushInterval,k=n.logger,E=[],w=0,O=!1,P=!1;function S(){return 0===y||0===Math.floor(Math.random()*y)}function D(e){E.length<h?(E.push(e),P=!1):P||(P=!0,k.warn(M()))}return v.enqueue=function(e){if(!O){var n,t=!1,r=!1;if(g.summarizeEvent(e),"feature"===e.kind?S()&&(t=!!e.trackEvents,r=!!(n=e).debugEventsUntilDate&&n.debugEventsUntilDate>w&&n.debugEventsUntilDate>(new Date).getTime()):t=S(),t&&D(function(e){var n=L({},e);return m||"identify"===e.kind?n.user=p.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),r){var o=L({},e,{kind:"debug"});delete o.trackEvents,delete o.debugEventsUntilDate,delete o.variation,D(o)}}},v.flush=function(){if(O)return Promise.resolve();var e=E,n=g.getSummary();return g.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(E=[],k.debug(Pe(e.length)),d.sendEvents(e).then((function(e){e&&(e.serverTime&&(w=e.serverTime),f(e.status)||(O=!0),e.status>=400&&R((function(){s.maybeReportError(new i(ae(e.status,"event posting","some events were dropped")))})))})))},v.start=function(){c=setTimeout((function e(){v.flush(),c=setTimeout(e,b)}),b)},v.stop=function(){clearTimeout(c)},v}function Ue(e){var n={},t={};return n.on=function(e,n,r){t[e]=t[e]||[],t[e]=t[e].concat({handler:n,context:r})},n.off=function(e,n,r){if(t[e])for(var o=0;o<t[e].length;o++)t[e][o].handler===n&&t[e][o].context===r&&(t[e]=t[e].slice(0,o).concat(t[e].slice(o+1)))},n.emit=function(e){if(t[e])for(var n=0;n<t[e].length;n++)t[e][n].handler.apply(t[e][n].context,Array.prototype.slice.call(arguments,1))},n.getEvents=function(){return Object.keys(t)},n.getEventListenerCount=function(e){return t[e]?t[e].length:0},n.maybeReportError=function(n){n&&(t["error"]?this.emit("error",n):(e||console).error(n.message))},n}function je(e,n,t,r,o){var i={};function a(){var e="",o=r.getUser();return o&&(e=t||S(JSON.stringify(o))),"ld:"+n+":"+e}return i.loadFlags=function(){return e.get(a()).then((function(e){if(null==e)return null;try{var n=JSON.parse(e);if(n){var t=n.$schema;void 0===t||t<1?n=I(n):delete n.$schema}return n}catch(e){return i.clearFlags().then((function(){return Promise.reject(e)}))}})).catch((function(e){return o.warn(G()),Promise.reject(e)}))},i.saveFlags=function(n){var t=L({},n,{$schema:1});return e.set(a(),JSON.stringify(t)).catch((function(e){return o.warn(G()),Promise.reject(e)}))},i.clearFlags=function(){return e.clear(a()).catch((function(e){return o.warn(G()),Promise.reject(e)}))},i}var Re="application/json";function Ne(e,n,t){var r=n.baseUrl,o=n.useReport,i=n.evaluationReasons,u=n.logger,c={},s={};function f(t,r){if(!e.httpRequest)return new Promise((function(e,n){n(new l(ue()))}));var o=r?"REPORT":"GET",i=A(e,n);r&&(i["Content-Type"]="application/json");var u=s[t];u||(u=function(e){var n,t,r,o,i={addPromise:function(i,a){n=i,t&&t(),t=a,i.then((function(t){n===i&&(r(t),e&&e())}),(function(t){n===i&&(o(t),e&&e())}))}};return i.resultPromise=new Promise((function(e,n){r=e,o=n})),i}((function(){delete s[t]})),s[t]=u);var c=e.httpRequest(o,t,i,r),f=c.promise.then((function(e){if(200===e.status){if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(Re))return JSON.parse(e.body);var n=B(e.header("content-type")||"");return Promise.reject(new l(n))}return Promise.reject(function(e){return 404===e.status?new a(Y()):new l(ee(e.statusText||String(e.status)))}(e))}),(function(e){return Promise.reject(new l(W(e)))}));return u.addPromise(f,(function(){c.cancel&&c.cancel()})),u.resultPromise}return c.fetchJSON=function(e){return f(r+e,null)},c.fetchFlagSettings=function(e,n){var a,c,s,l="";return o?(c=[r,"/sdk/evalx/",t,"/user"].join(""),s=JSON.stringify(e)):(a=D(JSON.stringify(e)),c=[r,"/sdk/evalx/",t,"/users/",a].join("")),n&&(l="h="+n),i&&(l=l+(l?"&":"")+"withReasons=true"),c=c+(l?"?":"")+l,u.debug(me(c)),f(c,s)},c}for(var Ie=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}}})),Te=[],Fe=0;Fe<256;++Fe)Te[Fe]=(Fe+256).toString(16).substr(1);var Ce,Ae,Le=function(e,n){var t=n||0,r=Te;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("")},xe=0,qe=0;var Ve=function(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||Ce,a=void 0!==e.clockseq?e.clockseq:Ae;if(null==i||null==a){var u=Ie();null==i&&(i=Ce=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=Ae=16383&(u[6]<<8|u[7]))}var c=void 0!==e.msecs?e.msecs:(new Date).getTime(),s=void 0!==e.nsecs?e.nsecs:qe+1,l=c-xe+(s-qe)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||c>xe)&&void 0===e.nsecs&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");xe=c,qe=s,Ae=a;var f=(1e4*(268435455&(c+=122192928e5))+s)%4294967296;o[r++]=f>>>24&255,o[r++]=f>>>16&255,o[r++]=f>>>8&255,o[r++]=255&f;var v=c/4294967296*1e4&268435455;o[r++]=v>>>8&255,o[r++]=255&v,o[r++]=v>>>24&15|16,o[r++]=v>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var d=0;d<6;++d)o[r+d]=i[d];return n||Le(o)},_e="ld:$anonUserId";function Je(e,n){var t={};return t.validateUser=function(t){if(!t)return Promise.reject(new u(ne()));var r=U(t);return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?(e?e.get(_e).catch((function(){return null})):Promise.resolve(null)).then((function(t){if(t)return r.key=t,r;var o=Ve();return r.key=o,function(t){return e?e.set(_e,t).catch((function(){n.warn(X())})):Promise.resolve()}(o).then((function(){return r}))})):Promise.reject(new u(te()))},t}var ze={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"},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"}};function Ke(e,n){var t,r=["debug","info","warn","error"];t=null!=n?""===n?"":n+" ":"LD: ";var o=0;e&&(o="none"===e?100:r.indexOf(e));var i={};function a(e,n,i){if(e>=o){var a=e<r.length?r[e]:"?";n(t+"["+a+"] "+i)}}return i.debug=function(e){return a(0,console.log,e)},i.info=function(e){return a(1,console.info,e)},i.warn=function(e){return a(2,console.warn,e)},i.error=function(e){return a(3,console.error,e)},i}var $e="ready",Me="initialized",He="failed",Be="change",Ge="internal-change";function Xe(n,t,o,i,u){var f,v,d,g,p=function(){if(o&&o.logger)return o.logger;return u&&u.logger&&u.logger.default||Ke("warn")}(),m=Ue(p),y=function(n,t,r,o){var i=L({logger:{default:o}},ze,r),a={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){R((function(){t&&t.maybeReportError(new s(e))}))}var c=L({},n||{});return function(e){var n=e;Object.keys(a).forEach((function(e){if(void 0!==n[e]){var t=a[e];o&&o.warn(ie(e,t)),t&&(void 0===n[t]&&(n[t]=n[e]),delete n[e])}}))}(c),c=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 o=n[e];if(null!=o){var a=i[e];if(void 0===a)u(ve(e));else{var c=a.type||r(a.default);if("any"!==c){var s=c.split("|"),l=r(o);s.indexOf(l)<0?"boolean"===c?(t[e]=!!o,u(ge(e,l))):(u(de(e,c,l)),t[e]=a.default):"number"===l&&void 0!==a.minimum&&o<a.minimum&&(u(pe(e,o,a.minimum)),t[e]=a.minimum)}}}})),t}(c=function(e){var n=L({},e);return Object.keys(i).forEach((function(e){void 0!==n[e]&&null!==n[e]||(n[e]=i[e]&&i[e].default)})),n}(c))}(o,m,u,p),h=y.hash,b=y.sendEvents,k=n,E=function(e,n,t,r){var o=n.streamUrl,i=n.logger,a={},u=o+"/eval/"+t,c=n.useReport,s=n.evaluationReasons,l=n.streamReconnectDelay,f=A(e,n),v=!1,d=null,g=null,p=null,m=null;function y(e){v||(i.warn(fe(e,l)),v=!0),k(),h(l)}function h(e){g||(e?g=setTimeout(b,e):b())}function b(){var n;g=null;var a="",l={headers:f};if(e.eventSourceFactory){for(var v in null!=r&&(a="h="+r),c?e.eventSourceAllowsReport?(n=u,l.method="REPORT",l.headers["Content-Type"]="application/json",l.body=JSON.stringify(p)):(n=o+"/ping/"+t,a=""):n=u+"/"+D(JSON.stringify(p)),s&&(a=a+(a?"&":"")+"withReasons=true"),n=n+(a?"?":"")+a,k(),i.info(le(n)),d=e.eventSourceFactory(n,l),m)m.hasOwnProperty(v)&&d.addEventListener(v,m[v]);d.onerror=y}}function k(){d&&(i.info(se()),d.close(),d=null)}return a.connect=function(e,n){p=e,m={};var t=function(e){m[e]=function(t){v=!1,n[e]&&n[e](t)}};for(var r in n||{})t(r);h()},a.disconnect=function(){clearTimeout(g),g=null,k()},a.isConnected=function(){return!!(d&&e.eventSourceIsActive&&e.eventSourceIsActive(d))},a}(i,y,k,h),w=y.eventProcessor||De(i,y,k,m),O=Ne(i,y,k),P={},S={},I=y.streaming,F=!1,C=!1,q=!0,V=y.stateProvider,_=function(e,n){var t,r={};return r.setUser=function(e){(t=x(e))&&n&&n(U(t))},r.getUser=function(){return t?U(t):null},e&&r.setUser(e),r}(null,(function(e){if(V)return;e&&z({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})})),J=Je(i.localStorage,p);function z(e){k&&(V&&V.enqueueEvent&&V.enqueueEvent(e)||(e.user?(q=!1,!b||C||i.isDoNotTrack()||(p.debug(Oe(e.kind)),w.enqueue(e))):q&&(p.warn(H()),q=!1)))}function $(e,n,t,r){var o=_.getUser(),i=new Date,a=n?n.value:null;if(!y.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(o&&o.key?o.key:"")+e,c=P[u];if(c&&i-c<3e5)return;P[u]=i}var s={kind:"feature",key:e,user:o,value:a,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()},l=S[e];l&&(s.version=l.flagVersion?l.flagVersion:l.version,s.trackEvents=l.trackEvents,s.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(s.reason=n.reason),z(s)}function M(e,n,t,r){var o;if(S&&S.hasOwnProperty(e)&&S[e]&&!S[e].deleted){var i=S[e];o=B(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 B(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function X(){v=!0,_.getUser()&&E.connect(_.getUser(),{ping:function(){p.debug(ye()),O.fetchFlagSettings(_.getUser(),h).then((function(e){return Y(e||{})})).catch((function(e){m.maybeReportError(new l(ee(e)))}))},put:function(e){var n=JSON.parse(e.data);p.debug(he()),Y(n)},patch:function(e){var n=JSON.parse(e.data),t=S[n.key];if(!t||!t.version||!n.version||t.version<n.version){p.debug(be(n.key));var r={},o=L({},n);delete o.key,S[n.key]=o;var i=B(o);r[n.key]=t?{previous:t.value,current:i}:{current:i},ne(r)}else p.debug(ke(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!S[n.key]||S[n.key].version<n.version){p.debug(Ee(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},ne(t)}else p.debug(we(n.key))}})}function W(){v&&(E.disconnect(),v=!1)}function Y(e){var n={};if(!e)return Promise.resolve();for(var t in S)S.hasOwnProperty(t)&&S[t]&&(e[t]&&!j(e[t].value,S[t].value)?n[t]={previous:S[t].value,current:B(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:S[t].value}));for(var o in e)e.hasOwnProperty(o)&&e[o]&&(!S[o]||S[o].deleted)&&(n[o]={current:B(e[o])});return S=r({},e),ne(n).catch((function(){}))}function ne(e){var n=Object.keys(e);if(n.length>0){var t={};n.forEach((function(n){var r=e[n].current,o=r?r.value:void 0,i=e[n].previous;m.emit(Be+":"+n,o,i),t[n]=r?{current:o,previous:i}:{previous:i}})),m.emit(Be,t),m.emit(Ge,S),y.sendEventsOnlyForVariation||V||n.forEach((function(n){$(n,e[n].current)}))}return f&&g?g.saveFlags(S).catch((function(){return null})):Promise.resolve()}function te(){var e=I||d&&void 0===I;e&&!v?X():!e&&v&&W()}function ae(e){return e===Be||e.substr(0,Be.length+1)===Be+":"}i.localStorage&&(g=new je(i.localStorage,k,h,_,p));var ue=new Promise((function(e){var n=m.on($e,(function(){m.off($e,n),e()}))})),me=new Promise((function(e,n){var t=m.on(Me,(function(){m.off(Me,t),e()})),r=m.on(He,(function(e){m.off(He,r),n(e)}))}));if("string"==typeof y.bootstrap&&"LOCALSTORAGE"===y.bootstrap.toUpperCase()&&(g?f=!0:p.warn(G())),"object"===e(y.bootstrap)&&(S=function(e){var n=Object.keys(e),t=e.$flagsState;!t&&n.length&&p.warn(re()),!1===e.$valid&&p.warn(oe());var r={};return n.forEach((function(n){if("$flagsState"!==n&&"$valid"!==n){var o={value:e[n]};t&&t[n]?o=L(o,t[n]):o.version=0,r[n]=o}})),r}(y.bootstrap)),V){var Pe=V.getInitialState();Pe?Se(Pe):V.on("init",Se),V.on("update",(function(e){e.user&&_.setUser(e.user);e.flags&&Y(e.flags)}))}else(function(){if(!n)return Promise.reject(new a(Z()));return J.validateUser(t).then((function(n){return _.setUser(n),"object"===e(y.bootstrap)?Re():f?g.loadFlags().catch((function(){return null})).then((function(e){return null==e?(S={},O.fetchFlagSettings(_.getUser(),h).then((function(e){return Y(e||{})})).then(Re).catch((function(e){Ie(new l(ee(e)))}))):(S=e,R(Re),O.fetchFlagSettings(_.getUser(),h).then((function(e){return Y(e)})).catch((function(e){return m.maybeReportError(e)})))})):O.fetchFlagSettings(_.getUser(),h).then((function(e){S=e||{},Re()})).catch((function(e){S={},Ie(e)}))}))})().catch((function(e){return m.maybeReportError(e)}));function Se(e){k=e.environment,_.setUser(e.user),S=r({},e.flags),R(Re)}function Re(){p.info(K()),F=!0,te(),m.emit($e),m.emit(Me)}function Ie(e){m.maybeReportError(e),m.emit(He,e),m.emit($e)}return{client:{waitForInitialization:function(){return me},waitUntilReady:function(){return ue},identify:function(e,n,t){return C?N(Promise.resolve({}),t):V?(p.warn(ce()),N(Promise.resolve(T(S)),t)):N((f&&g?g.clearFlags():Promise.resolve()).then((function(){return J.validateUser(e)})).then((function(e){return O.fetchFlagSettings(e,n).then((function(n){var t=T(n);return _.setUser(e),n?Y(n).then((function(){return t})):t}))})).then((function(e){return v&&X(),e})).catch((function(e){return m.maybeReportError(e),Promise.reject(e)})),t)},getUser:function(){return _.getUser()},variation:function(e,n){return M(e,n,!0,!1).value},variationDetail:function(e,n){return M(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){i.customEventFilter&&!i.customEventFilter(e)&&p.warn(Q(e));var r={kind:"custom",key:e,user:_.getUser(),url:i.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),z(r)}else m.maybeReportError(new c(Q(e)))},on:function(e,n,t){ae(e)?(d=!0,F&&te(),m.on(e,n,t)):m.on.apply(m,arguments)},off:function(e){if(m.off.apply(m,arguments),ae(e)){var n=!1;m.getEvents().forEach((function(e){ae(e)&&m.getEventListenerCount(e)>0&&(n=!0)})),n||(d=!1,v&&void 0===I&&W())}},setStreaming:function(e){var n=null===e?void 0:e;n!==I&&(I=n,te())},flush:function(e){return N(b?w.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!S)return e;for(var n in S)S.hasOwnProperty(n)&&(e[n]=M(n,null,!y.sendEventsOnlyForVariation).value);return e},close:function(e){if(C)return N(Promise.resolve(),e);var n=function(){C=!0,S={}};return N(Promise.resolve().then((function(){if(W(),b)return w.stop(),w.flush()})).then(n).catch(n),e)}},options:y,emitter:m,ident:_,logger:p,requestor:O,start:function(){b&&w.start()},enqueueEvent:z,getFlagsInternal:function(){return S},getEnvironmentId:function(){return k},internalChangeEventName:Ge}}var We="3.1.0";export{Ke as createConsoleLogger,v as errors,Xe as initialize,Se as messages,q as utils,We 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.1.0-beta3-diag";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}),D=2e3;function ae(a,e,n){var t="/a/"+e+".gif",o=ie({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},U(a,n)),u=a.httpFallbackPing,s={};return s.sendChunk=function(e,r,n){var i=JSON.stringify(e);return n?function n(t){return a.httpRequest("POST",r,o,i).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(){}):(u&&u(r+t+"?d="+S(i)),Promise.resolve())},s.sendEvents=function(e,n){if(!a.httpRequest)return Promise.resolve();var t,r=a.httpAllowsPost();t=r?[e]:k(D-n.length,e);for(var i=[],o=0;o<t.length;o++)i.push(s.sendChunk(t[o],n,r));return Promise.all(i)},s}function I(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 j(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}function R(){return"LaunchDarkly client initialized"}function T(){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."+A}function ce(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+A}function N(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."}function F(){return"identify() has no effect here; it must be called on the main client instance"}function C(){return"received ping message from stream"}function L(){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 A=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",x=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},_=function(e){return'Expected application/json content type but got "'+e+'"'},pe=function(){return"localStorage is unavailable"},V=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},q=function(e){return"network error"+(e?" ("+e+")":"")},J=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+A},me=function(e){return"Error fetching flag settings: "+j(e)},z=function(){return"No user specified."+A},M=function(){return"Invalid user specified."+A},B=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},K=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(P(e)?t:"giving up permanently")},$=function(){return"Cannot make HTTP requests in this environment."+A},G=function(){return"Closing stream connection"},he=function(e){return"Opening stream connection to "+e},ye=function(e,n){return"Error on stream connection: "+j(e)+", will continue retrying every "+n+" milliseconds."},be=function(e){return'Ignoring unknown config option "'+e+'"'},ke=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},Ee=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},we=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},De=function(e){return"polling for feature flags at "+e},Se=function(e){return"sending "+e+" events"},Oe=Object.freeze({__proto__:null,clientInitialized:R,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:x,eventWithoutUser:T,invalidContentType:_,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:pe,localStorageUnavailableForUserId:V,networkError:q,unknownCustomEventKey:ue,environmentNotFound:J,environmentNotSpecified:se,errorFetchingFlags:me,userNotSpecified:z,invalidUser:M,bootstrapOldFormat:ce,bootstrapInvalid:N,deprecated:B,httpErrorMessage:K,httpUnavailable:$,identifyDisabled:F,streamClosing:G,streamConnecting:he,streamError:ye,unknownOption:be,wrongOptionType:ke,wrongOptionTypeBoolean:Ee,optionBelowMinimum:we,debugPolling:De,debugStreamPing:C,debugStreamPut:L,debugStreamPatch:le,debugStreamPatchIgnored:fe,debugStreamDelete:ve,debugStreamDeleteIgnored:de,debugEnqueueingEvent:ge,debugPostingEvents:Se});function Pe(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=I(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(x())),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(Se(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(K(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 Ue(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 Ie(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=ie({},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 je(i,e,o,n,a){var u,s=e.streamUrl,c=e.logger,t={},l=s+"/eval/"+o,f=e.useReport,v=e.evaluationReasons,r=e.streamReconnectDelay,d=U(i,e),g=!1,p=null,m=null,h=null,y=null;function b(e){g||(c.warn(ye(e,r)),g=!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:d};if(i.eventSourceFactory){for(var r in null!=a&&(n="h="+a),f?i.eventSourceAllowsReport?(e=l,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(h)):(e=s+"/ping/"+o,n=""):e=l+"/"+S(JSON.stringify(h)),v&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,w(),c.info(he(e)),u=(new Date).getTime(),p=i.eventSourceFactory(e,t),y)y.hasOwnProperty(r)&&p.addEventListener(r,y[r]);p.onerror=b}}function w(){p&&(c.info(G()),p.close(),p=null)}function D(e){u&&n&&n.recordStreamInit(u,!e,(new Date).getTime()-u),u=null}return t.connect=function(e,t){h=e,y={};function n(n){y[n]=function(e){D(!(g=!1)),t[n]&&t[n](e)}}for(var r in t||{})n(r);k()},t.disconnect=function(){clearTimeout(m),m=null,w()},t.isConnected=function(){return!!(p&&i.eventSourceIsActive&&i.eventSourceIsActive(p))},t}var Re="application/json";function Te(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($()))});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(J()):new Y(me(e.statusText||String(e.status)))}(e));if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(Re))return JSON.parse(e.body);var n=_(e.header("content-type")||"");return Promise.reject(new Y(n))},function(e){return Promise.reject(new Y(q(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(De(r)),g(r,i)},e}for(var Ne,Fe=(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}}}(Ne={exports:{}},Ne.exports),Ne.exports),Ce=[],Le=0;Le<256;++Le)Ce[Le]=(Le+256).toString(16).substr(1);var Ae,xe,_e=function(e,n){var t=n||0,r=Ce;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("")},Ve=0,qe=0;var Je=function(e,n,t){var r=n&&t||0,i=n||[],o=(e=e||{}).node||Ae,a=void 0!==e.clockseq?e.clockseq:xe;if(null==o||null==a){var u=Fe();null==o&&(o=Ae=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=xe=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:qe+1,l=s-Ve+(c-qe)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||Ve<s)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Ve=s,xe=a;var f=(1e4*(268435455&(s+=122192928e5))+(qe=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||_e(i)},ze="ld:$anonUserId";function Me(r,i){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new o(z()));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=Je();return function(e){return r?r.set(ze,e).catch(function(){i.warn(V())}):Promise.resolve()}(t.key=n).then(function(){return t})}):Promise.reject(new o(M()))},e}var Be={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},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(B(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(be(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(Ee(e,o))):(u(ke(e,r,o)),l[e]=t.default):"number"===o&&void 0!==t.minimum&&n<t.minimum&&(u(we(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:Je()};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,durationMillis:t};n&&(r.failed=!0),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}(n.diagnosticSdkData),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){t.sendEvents(e,l).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=Ue(a),f=Ke(t,u,r,a),o=f.hash,s=f.sendEvents,c=e,l=ae(i,c),v=f.sendEvents&&!f.diagnosticOptOut,d=v?Ge(c):null,g=v?He((new Date).getTime()):null,p=v?Xe(i,g,l,c,f,d):null;p&&p.start();var m,h,y,b,k=je(i,f,c,g,o),E=f.eventProcessor||Pe(i,f,c,g,u,l),w=Te(i,f,c),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){c&&(j&&j.enqueueEvent&&j.enqueueEvent(e)||(e.user?(I=!1,!s||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(),{ping:function(){a.debug("received ping message from stream"),w.fetchFlagSettings(R.getUser(),o).then(function(e){return _(e||{})}).catch(function(e){u.maybeReportError(new Y(me(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 Ie(i.localStorage,c,o,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(pe())),"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(),o).then(function(e){return _(e||{})}).then($).catch(function(e){G(new Y(me(e)))})):(S=e,ne($),w.fetchFlagSettings(R.getUser(),o).then(function(e){return _(e)}).catch(function(e){return u.maybeReportError(e)}))}):w.fetchFlagSettings(R.getUser(),o).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){c=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,n,t){return U?te(Promise.resolve({}),t):j?(a.warn("identify() has no effect here; it must be called on the main client instance"),te(Promise.resolve(re(S)),t)):te((m&&b?b.clearFlags():Promise.resolve()).then(function(){return T.validateUser(e)}).then(function(e){return R.setUser(e)}).then(function(){return w.fetchFlagSettings(R.getUser(),n)}).then(function(e){var n=re(e);return e?_(e).then(function(){return n}):n}).then(function(e){return h&&A(),e}).catch(function(e){return u.maybeReportError(e),Promise.reject(e)}),t)},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(s?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(),s)return E.stop(),E.flush()}).then(n).catch(n),e)}},options:f,emitter:u,ident:R,logger:a,requestor:w,start:function(){s&&(p&&p.start(),E.start())},enqueueEvent:N,getFlagsInternal:function(){return S},getEnvironmentId:function(){return c},internalChangeEventName:nn}},e.messages=Oe,e.utils=w,e.version="3.1.0-beta3-diag",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 K(e){return(K="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 M(o){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?n(i,!0).forEach(function(e){var n,t,r;n=o,r=i[t=e],t in n?Object.defineProperty(n,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):n[t]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(i)):n(i).forEach(function(e){Object.defineProperty(o,e,Object.getOwnPropertyDescriptor(i,e))})}return o}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 w=t("LaunchDarklyUnexpectedResponseError"),$=t("LaunchDarklyInvalidEnvironmentIdError"),i=t("LaunchDarklyInvalidUserError"),H=t("LaunchDarklyInvalidEventKeyError"),d=t("LaunchDarklyInvalidArgumentError"),B=t("LaunchDarklyFlagFetchError");function O(e){return!(400<=e&&e<500)||(400===e||408===e||429===e)}for(var r=Object.freeze({__proto__:null,LDUnexpectedResponseError:w,LDInvalidEnvironmentIdError:$,LDInvalidUserError:i,LDInvalidEventKeyError:H,LDInvalidArgumentError:d,LDFlagFetchError:B,isHttpErrorRecoverable:O}),o=function(e){for(var n,t=e.length,r=t%3,o=[],i=0,a=t-r;i<a;i+=16383)o.push(f(e,i,a<i+16383?a:i+16383));1==r?(n=e[t-1],o.push(u[n>>2]+u[n<<4&63]+"==")):2==r&&(n=(e[t-2]<<8)+e[t-1],o.push(u[n>>10]+u[n>>4&63]+u[n<<2&63]+"="));return o.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,o,i=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),i.push(u[(o=r)>>18&63]+u[o>>12&63]+u[o>>6&63]+u[63&o]);return i.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,o,i,a=g(n),u=g(t);if(a&&u){if((o=n.length)!=t.length)return!1;for(r=o;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var s=n instanceof Date,c=t instanceof Date;if(s!=c)return!1;if(s&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var v=p(n);if((o=v.length)!==p(t).length)return!1;for(r=o;0!=r--;)if(!m.call(t,v[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=v[r]],t[i]))return!1;return!0}return n!=n&&t!=t},y=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function h(e){var n=unescape(encodeURIComponent(e));return o(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function E(e){return h(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function G(e){return JSON.parse(JSON.stringify(e))}function X(e,n){return v(e,n)}function W(e){setTimeout(e,0)}function Q(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 Y(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),o=[],i=e;0<r.length;){for(t=[];0<i;){var a=r.shift();if(!a)break;(i-=E(JSON.stringify(a)).length)<0&&0<t.length?r.unshift(a):t.push(a)}i=e,o.push(t)}return o}function P(e){var n=e.version||"3.1.0";return e.userAgent+"/"+n}function D(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":P(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function Z(){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 M({},e,{},n)},{})}function ee(e){if(!e)return e;var n;for(var t in y){var r=y[t],o=e[r];void 0!==o&&"string"!=typeof o&&((n=n||M({},e))[r]=String(o))}return n||e}var S=Object.freeze({__proto__:null,btoa:h,base64URLEncode:E,clone:G,deepEquals:X,onNextTick:W,wrapPromiseCallback:Q,transformValuesToVersionedValues:b,transformVersionedValuesToValues:Y,chunkUserEventsForUrl:k,getLDUserAgentString:P,getLDHeaders:D,extend:Z,sanitizeUser:ee}),U=2e3;function j(i,a,e,o){var u=a+"/events/bulk/"+e,t=a+"/a/"+e+".gif",s=i.httpFallbackPing,n={};function c(e,n){var r=JSON.stringify(e);return n?function n(t){var e=Z({"Content-Type":"application/json","X-LaunchDarkly-Event-Schema":"3"},D(i,o));return i.httpRequest("POST",u,e,r).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(){}):(s&&s(t+"?d="+E(r)),Promise.resolve())}return n.sendEvents=function(e){if(!i.httpRequest)return Promise.resolve();var n,t=i.httpAllowsPost();n=t?[e]:k(U-a.length,e);for(var r=[],o=0;o<n.length;o++)r.push(c(n[o],t));return Promise.all(r)},n}function R(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,o){return Object.keys(r).reduce(function(e,n){var t=e;return o(n)&&(!function(e){return!l[e]&&(s||-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=Z({},o,a[1])}var u=Object.keys(o);return u.length&&(u.sort(),r.privateAttrs=u),r},n}function N(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}function I(){return"LaunchDarkly client initialized"}function T(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"}function ne(e){return'Custom event "'+e+'" does not exist'}function te(){return"No environment/client-side ID was specified."+A}function re(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+A}function F(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."}function C(){return"identify() has no effect here; it must be called on the main client instance"}function L(){return"received ping message from stream"}function x(){return"received streaming update for all flags"}function oe(e){return'received streaming update for flag "'+e+'"'}function ie(e){return'received streaming update for flag "'+e+'" but ignored due to version check'}function ae(e){return'received streaming deletion for flag "'+e+'"'}function ue(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'}function se(e){return'enqueueing "'+e+'" event'}var A=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",_=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},q=function(e){return'Expected application/json content type but got "'+e+'"'},ce=function(){return"localStorage is unavailable"},V=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},J=function(e){return"network error"+(e?" ("+e+")":"")},z=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+A},le=function(e){return"Error fetching flag settings: "+N(e)},fe=function(){return"No user specified."+A},ve=function(){return"Invalid user specified."+A},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+" - "+(O(e)?t:"giving up permanently")},pe=function(){return"Cannot make HTTP requests in this environment."+A},me=function(){return"Closing stream connection"},ye=function(e){return"Opening stream connection to "+e},he=function(e,n){return"Error on stream connection: "+N(e)+", will continue retrying every "+n+" milliseconds."},be=function(e){return'Ignoring unknown config option "'+e+'"'},ke=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},Ee=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},we=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},Oe=function(e){return"polling for feature flags at "+e},Pe=function(e){return"sending "+e+" events"},De=Object.freeze({__proto__:null,clientInitialized:I,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:_,eventWithoutUser:T,invalidContentType:q,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:ce,localStorageUnavailableForUserId:V,networkError:J,unknownCustomEventKey:ne,environmentNotFound:z,environmentNotSpecified:te,errorFetchingFlags:le,userNotSpecified:fe,invalidUser:ve,bootstrapOldFormat:re,bootstrapInvalid:F,deprecated:de,httpErrorMessage:ge,httpUnavailable:pe,identifyDisabled:C,streamClosing:me,streamConnecting:ye,streamError:he,unknownOption:be,wrongOptionType:ke,wrongOptionTypeBoolean:Ee,optionBelowMinimum:we,debugPolling:Oe,debugStreamPing:L,debugStreamPut:x,debugStreamPatch:oe,debugStreamPatchIgnored:ie,debugStreamDelete:ae,debugStreamDeleteIgnored:ue,debugEnqueueingEvent:se,debugPostingEvents:Pe});function Se(e,n,t,r,o){var i,a=3<arguments.length&&void 0!==r?r:null,u={},s=(4<arguments.length&&void 0!==o?o:null)||j(e,n.eventsUrl,t,n),c=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],o=e[r.key];o||(o={default:r.default,counters:[]},e[r.key]=o);var i={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),n=!1}return n?null:{startDate:a,endDate:u,features:e}},e.clearSummary=function(){u=a=0,s={}},e}(),l=R(n),f=n.inlineUsersInEvents,v=n.samplingInterval,d=n.eventCapacity,g=n.flushInterval,p=n.logger,m=[],y=0,h=!1,b=!1;function k(){return 0===v||0===Math.floor(Math.random()*v)}function E(e){m.length<d?(m.push(e),b=!1):b||(b=!0,p.warn(_()))}return u.enqueue=function(e){if(!h){var n=!1,t=!1;if(c.summarizeEvent(e),"feature"===e.kind?k()&&(n=!!e.trackEvents,t=function(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>y&&e.debugEventsUntilDate>(new Date).getTime())}(e)):n=k(),n&&E(function(e){var n=Z({},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=Z({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,E(r)}}},u.flush=function(){if(h)return Promise.resolve();var e=m,n=c.getSummary();return c.clearSummary(),n&&(n.kind="summary",e.push(n)),0===e.length?Promise.resolve():(m=[],p.debug(Pe(e.length)),s.sendEvents(e).then(function(e){e&&(e.serverTime&&(y=e.serverTime),O(e.status)||(h=!0),400<=e.status&&W(function(){a.maybeReportError(new w(ge(e.status,"event posting","some events were dropped")))}))}))},u.start=function(){i=setTimeout(function e(){u.flush(),i=setTimeout(e,g)},g)},u.stop=function(){clearTimeout(i)},u}function Ue(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 je(t,r,o,i,a){var u={};function s(){var e="",n=i.getUser();return n&&(e=o||h(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(ce()),Promise.reject(e)})},u.saveFlags=function(e){var n=Z({},e,{$schema:1});return t.set(s(),JSON.stringify(n)).catch(function(e){return a.warn(ce()),Promise.reject(e)})},u.clearFlags=function(){return t.clear(s()).catch(function(e){return a.warn(ce()),Promise.reject(e)})},u}function Re(o,e,i,a){var u=e.streamUrl,s=e.logger,n={},c=u+"/eval/"+i,l=e.useReport,f=e.evaluationReasons,t=e.streamReconnectDelay,v=D(o,e),d=!1,g=null,p=null,m=null,y=null;function h(e){d||(s.warn(he(e,t)),d=!0),k(),b(t)}function b(e){p||(e?p=setTimeout(r,e):r())}function r(){var e;p=null;var n="",t={headers:v};if(o.eventSourceFactory){for(var r in null!=a&&(n="h="+a),l?o.eventSourceAllowsReport?(e=c,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(m)):(e=u+"/ping/"+i,n=""):e=c+"/"+E(JSON.stringify(m)),f&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,k(),s.info(ye(e)),g=o.eventSourceFactory(e,t),y)y.hasOwnProperty(r)&&g.addEventListener(r,y[r]);g.onerror=h}}function k(){g&&(s.info(me()),g.close(),g=null)}return n.connect=function(e,t){m=e,y={};function n(n){y[n]=function(e){d=!1,t[n]&&t[n](e)}}for(var r in t||{})n(r);b()},n.disconnect=function(){clearTimeout(p),p=null,k()},n.isConnected=function(){return!!(g&&o.eventSourceIsActive&&o.eventSourceIsActive(g))},n}var Ne="application/json";function Ie(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 B(pe()))});var t=n?"REPORT":"GET",r=D(u,s);n&&(r["Content-Type"]="application/json");var o=d[e];o||(o=function(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}(function(){delete d[e]}),d[e]=o);var i=u.httpRequest(t,e,r,n),a=i.promise.then(function(e){if(200!==e.status)return Promise.reject(function(e){return 404===e.status?new $(z()):new B(le(e.statusText||String(e.status)))}(e));if(e.header("content-type")&&0===e.header("content-type").lastIndexOf(Ne))return JSON.parse(e.body);var n=q(e.header("content-type")||"");return Promise.reject(new B(n))},function(e){return Promise.reject(new B(J(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=E(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,v.debug(Oe(r)),g(r,o)},e}for(var Te,Fe=(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}}}(Te={exports:{}},Te.exports),Te.exports),Ce=[],Le=0;Le<256;++Le)Ce[Le]=(Le+256).toString(16).substr(1);var xe,Ae,_e=function(e,n){var t=n||0,r=Ce;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("")},qe=0,Ve=0;var Je=function(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||xe,a=void 0!==e.clockseq?e.clockseq:Ae;if(null==i||null==a){var u=Fe();null==i&&(i=xe=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=Ae=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:Ve+1,l=s-qe+(c-Ve)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||qe<s)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");qe=s,Ae=a;var f=(1e4*(268435455&(s+=122192928e5))+(Ve=c))%4294967296;o[r++]=f>>>24&255,o[r++]=f>>>16&255,o[r++]=f>>>8&255,o[r++]=255&f;var v=s/4294967296*1e4&268435455;o[r++]=v>>>8&255,o[r++]=255&v,o[r++]=v>>>24&15|16,o[r++]=v>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var d=0;d<6;++d)o[r+d]=i[d];return n||_e(o)},ze="ld:$anonUserId";function Ke(r,o){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new i(fe()));var t=G(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=Je();return function(e){return r?r.set(ze,e).catch(function(){o.warn(V())}):Promise.resolve()}(t.key=n).then(function(){return t})}):Promise.reject(new i(ve()))},e}var Me={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"},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"}};function $e(e,n,t,r){var a=Z({logger:{default:r}},Me,t),o={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){W(function(){n&&n.maybeReportError(new d(e))})}var i,s,c,l,f=Z({},e||{});function v(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var n=K(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(de(e,n)),n&&(void 0===i[n]&&(i[n]=i[e]),delete i[e])}}),s=Z({},f),Object.keys(a).forEach(function(e){void 0!==s[e]&&null!==s[e]||(s[e]=a[e]&&a[e].default)}),l=Z({},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(be(e));else{var r=t.type||v(t.default);if("any"!==r){var o=r.split("|"),i=v(n);o.indexOf(i)<0?"boolean"===r?(l[e]=!!n,u(Ee(e,i))):(u(ke(e,r,i)),l[e]=t.default):"number"===i&&void 0!==t.minimum&&n<t.minimum&&(u(we(e,n,t.minimum)),l[e]=t.minimum)}}}}),f=l}function He(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 Be="ready",Ge="initialized",Xe="failed",We="change",Qe="internal-change";e.createConsoleLogger=He,e.errors=r,e.initialize=function(e,n,t,o,r){var a,i,u,s,c=function(){if(t&&t.logger)return t.logger;return r&&r.logger&&r.logger.default||He("warn")}(),l=Ue(c),f=$e(t,l,r,c),v=f.hash,d=f.sendEvents,g=e,p=Re(o,f,g,v),m=f.eventProcessor||Se(o,f,g,l),y=Ie(o,f,g),h={},b={},k=f.streaming,E=!1,w=!1,O=!0,P=f.stateProvider,D=function(e,n){var t,r={};return r.setUser=function(e){(t=ee(e))&&n&&n(G(t))},r.getUser=function(){return t?G(t):null},e&&r.setUser(e),r}(null,function(e){if(P)return;e&&U({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),S=Ke(o.localStorage,c);function U(e){g&&(P&&P.enqueueEvent&&P.enqueueEvent(e)||(e.user?(O=!1,!d||w||o.isDoNotTrack()||(c.debug(se(e.kind)),m.enqueue(e))):O&&(c.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"),O=!1)))}function j(e,n,t,r){var o=D.getUser(),i=new Date,a=n?n.value:null;if(!f.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(o&&o.key?o.key:"")+e,s=h[u];if(s&&i-s<3e5)return;h[u]=i}var c={kind:"feature",key:e,user:o,value:a,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()},l=b[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),U(c)}function R(e,n,t,r){var o;if(b&&b.hasOwnProperty(e)&&b[e]&&!b[e].deleted){var i=b[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&&j(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 I(){i=!0,D.getUser()&&p.connect(D.getUser(),{ping:function(){c.debug("received ping message from stream"),y.fetchFlagSettings(D.getUser(),v).then(function(e){return F(e||{})}).catch(function(e){l.maybeReportError(new B(le(e)))})},put:function(e){var n=JSON.parse(e.data);c.debug("received streaming update for all flags"),F(n)},patch:function(e){var n=JSON.parse(e.data),t=b[n.key];if(!t||!t.version||!n.version||t.version<n.version){c.debug(oe(n.key));var r={},o=Z({},n);delete o.key;var i=N(b[n.key]=o);r[n.key]=t?{previous:t.value,current:i}:{current:i},C(r)}else c.debug(ie(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!b[n.key]||b[n.key].version<n.version){c.debug(ae(n.key));var t={};b[n.key]&&!b[n.key].deleted&&(t[n.key]={previous:b[n.key].value}),b[n.key]={version:n.version,deleted:!0},C(t)}else c.debug(ue(n.key))}})}function T(){i&&(p.disconnect(),i=!1)}function F(e){var n={};if(!e)return Promise.resolve();for(var t in b)b.hasOwnProperty(t)&&b[t]&&(e[t]&&!X(e[t].value,b[t].value)?n[t]={previous:b[t].value,current:N(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:b[t].value}));for(var r in e)e.hasOwnProperty(r)&&e[r]&&(!b[r]||b[r].deleted)&&(n[r]={current:N(e[r])});return b=M({},e),C(n).catch(function(){})}function C(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;l.emit(We+":"+e,t,r),i[e]=n?{current:t,previous:r}:{previous:r}}),l.emit(We,i),l.emit(Qe,b),f.sendEventsOnlyForVariation||P||e.forEach(function(e){j(e,o[e].current)})}return a&&s?s.saveFlags(b).catch(function(){return null}):Promise.resolve()}function L(){var e=k||u&&void 0===k;e&&!i?I():!e&&i&&T()}function x(e){return e===We||e.substr(0,We.length+1)===We+":"}o.localStorage&&(s=new je(o.localStorage,g,v,D,c));var A=new Promise(function(e){var n=l.on(Be,function(){l.off(Be,n),e()})}),_=new Promise(function(e,n){var t=l.on(Ge,function(){l.off(Ge,t),e()}),r=l.on(Xe,function(e){l.off(Xe,r),n(e)})});if("string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(s?a=!0:c.warn(ce())),"object"===K(f.bootstrap)&&(b=function(t){var e=Object.keys(t),r="$flagsState",o=t[r];!o&&e.length&&c.warn(re()),!1===t.$valid&&c.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var i={};return e.forEach(function(e){if(e!==r&&"$valid"!==e){var n={value:t[e]};o&&o[e]?n=Z(n,o[e]):n.version=0,i[e]=n}}),i}(f.bootstrap)),P){var q=P.getInitialState();q?V(q):P.on("init",V),P.on("update",function(e){e.user&&D.setUser(e.user);e.flags&&F(e.flags)})}else(e?S.validateUser(n).then(function(e){return D.setUser(e),"object"===K(f.bootstrap)?J():a?s.loadFlags().catch(function(){return null}).then(function(e){return null==e?(b={},y.fetchFlagSettings(D.getUser(),v).then(function(e){return F(e||{})}).then(J).catch(function(e){z(new B(le(e)))})):(b=e,W(J),y.fetchFlagSettings(D.getUser(),v).then(function(e){return F(e)}).catch(function(e){return l.maybeReportError(e)}))}):y.fetchFlagSettings(D.getUser(),v).then(function(e){b=e||{},J()}).catch(function(e){b={},z(e)})}):Promise.reject(new $(te()))).catch(function(e){return l.maybeReportError(e)});function V(e){g=e.environment,D.setUser(e.user),b=M({},e.flags),W(J)}function J(){c.info("LaunchDarkly client initialized"),E=!0,L(),l.emit(Be),l.emit(Ge)}function z(e){l.maybeReportError(e),l.emit(Xe,e),l.emit(Be)}return{client:{waitForInitialization:function(){return _},waitUntilReady:function(){return A},identify:function(e,n,t){return w?Q(Promise.resolve({}),t):P?(c.warn("identify() has no effect here; it must be called on the main client instance"),Q(Promise.resolve(Y(b)),t)):Q((a&&s?s.clearFlags():Promise.resolve()).then(function(){return S.validateUser(e)}).then(function(t){return y.fetchFlagSettings(t,n).then(function(e){var n=Y(e);return D.setUser(t),e?F(e).then(function(){return n}):n})}).then(function(e){return i&&I(),e}).catch(function(e){return l.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return D.getUser()},variation:function(e,n){return R(e,n,!0,!1).value},variationDetail:function(e,n){return R(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){o.customEventFilter&&!o.customEventFilter(e)&&c.warn(ne(e));var r={kind:"custom",key:e,user:D.getUser(),url:o.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),U(r)}else l.maybeReportError(new H(ne(e)))},on:function(e,n,t){x(e)?(u=!0,E&&L(),l.on(e,n,t)):l.on.apply(l,arguments)},off:function(e){if(l.off.apply(l,arguments),x(e)){var n=!1;l.getEvents().forEach(function(e){x(e)&&0<l.getEventListenerCount(e)&&(n=!0)}),n||(u=!1,i&&void 0===k&&T())}},setStreaming:function(e){var n=null===e?void 0:e;n!==k&&(k=n,L())},flush:function(e){return Q(d?m.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!b)return e;for(var n in b)b.hasOwnProperty(n)&&(e[n]=R(n,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(w)return Q(Promise.resolve(),e);function n(){w=!0,b={}}return Q(Promise.resolve().then(function(){if(T(),d)return m.stop(),m.flush()}).then(n).catch(n),e)}},options:f,emitter:l,ident:D,logger:c,requestor:y,start:function(){d&&m.start()},enqueueEvent:U,getFlagsInternal:function(){return b},getEnvironmentId:function(){return g},internalChangeEventName:Qe}},e.messages=De,e.utils=S,e.version="3.1.0",Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=ldclient-common.min.js.map |
{ | ||
"name": "launchdarkly-js-sdk-common", | ||
"version": "3.1.0-beta3-diag", | ||
"version": "3.1.0", | ||
"description": "LaunchDarkly SDK for JavaScript - common code", | ||
@@ -5,0 +5,0 @@ "author": "LaunchDarkly <team@launchdarkly.com>", |
@@ -230,21 +230,2 @@ /** | ||
/** | ||
* Set to true to opt out of sending diagnostics data. | ||
* | ||
* Unless `diagnosticOptOut` is set to true, the client will send some diagnostics data to the LaunchDarkly | ||
* servers in order to assist in the development of future SDK improvements. These diagnostics consist of | ||
* an initial payload containing some details of SDK in use, the SDK's configuration, and the platform the | ||
* SDK is being run on, as well as payloads sent periodically with information on irregular occurrences such | ||
* as dropped events. | ||
*/ | ||
diagnosticOptOut?: boolean; | ||
/** | ||
* The interval at which periodic diagnostic data is sent, in milliseconds. | ||
* | ||
* The default is 900000 (every 15 minutes) and the minimum value is 6000. See [[diagnosticOptOut]] | ||
* for more information on the diagnostics data being sent. | ||
*/ | ||
diagnosticRecordingInterval?: number; | ||
/** | ||
* For use by wrapper libraries to set an identifying name for the wrapper being used. | ||
@@ -251,0 +232,0 @@ * |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
481142
908